33#include "llvm/Config/llvm-config.h"
95 cl::desc(
"Number of metadatas above which we emit an index "
96 "to enable lazy-loading"));
99 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
103 cl::desc(
"Write relative block frequency to function summary "));
134 VST_BBENTRY_6_ABBREV,
138 CONSTANTS_INTEGER_ABBREV,
139 CONSTANTS_CE_CAST_Abbrev,
140 CONSTANTS_NULL_Abbrev,
144 FUNCTION_INST_STORE_ABBREV,
145 FUNCTION_INST_UNOP_ABBREV,
146 FUNCTION_INST_UNOP_FLAGS_ABBREV,
147 FUNCTION_INST_BINOP_ABBREV,
148 FUNCTION_INST_BINOP_FLAGS_ABBREV,
149 FUNCTION_INST_CAST_ABBREV,
150 FUNCTION_INST_CAST_FLAGS_ABBREV,
151 FUNCTION_INST_RET_VOID_ABBREV,
152 FUNCTION_INST_RET_VAL_ABBREV,
153 FUNCTION_INST_BR_UNCOND_ABBREV,
154 FUNCTION_INST_BR_COND_ABBREV,
155 FUNCTION_INST_UNREACHABLE_ABBREV,
156 FUNCTION_INST_GEP_ABBREV,
157 FUNCTION_INST_CMP_ABBREV,
158 FUNCTION_INST_CMP_FLAGS_ABBREV,
159 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
160 FUNCTION_DEBUG_LOC_ABBREV,
165class BitcodeWriterBase {
176 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
179 void writeModuleVersion();
182void BitcodeWriterBase::writeModuleVersion() {
189class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
203 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
206 unsigned GlobalValueId;
217 bool ShouldPreserveUseListOrder,
219 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
229 for (
const auto &GUIDSummaryLists : *Index)
231 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
232 if (
auto FS = dyn_cast<FunctionSummary>(
Summary.get())) {
237 for (
auto &CallEdge :
FS->calls())
238 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
239 assignValueId(CallEdge.first.getGUID());
245 for (
auto &RefEdge :
FS->refs())
246 if (!RefEdge.haveGVs() || !RefEdge.getValue())
247 assignValueId(RefEdge.getGUID());
252 void writePerModuleGlobalValueSummary();
255 void writePerModuleFunctionSummaryRecord(
257 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
258 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
263 unsigned FSModRefsAbbrev,
264 unsigned FSModVTableRefsAbbrev);
267 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
271 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
274 assert(VMI != GUIDToValueIdMap.end() &&
275 "GUID does not have assigned value Id");
281 if (!
VI.haveGVs() || !
VI.getValue())
282 return getValueId(
VI.getGUID());
286 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
290class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
310 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
311 ShouldPreserveUseListOrder,
Index),
312 GenerateHash(GenerateHash), ModHash(ModHash),
313 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
319 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
323 void writeAttributeGroupTable();
324 void writeAttributeTable();
325 void writeTypeTable();
327 void writeValueSymbolTableForwardDecl();
328 void writeModuleInfo();
333 unsigned createDILocationAbbrev();
336 unsigned createGenericDINodeAbbrev();
409 unsigned createNamedMetadataAbbrev();
411 unsigned createMetadataStringsAbbrev();
416 std::vector<unsigned> *MDAbbrevs =
nullptr,
417 std::vector<uint64_t> *IndexPos =
nullptr);
418 void writeModuleMetadata();
419 void writeFunctionMetadata(
const Function &
F);
420 void writeFunctionMetadataAttachment(
const Function &
F);
423 void writeModuleMetadataKinds();
424 void writeOperandBundleTags();
425 void writeSyncScopeNames();
426 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
427 void writeModuleConstants();
428 bool pushValueAndType(
const Value *V,
unsigned InstID,
430 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
432 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
433 void pushValue(
const Value *V,
unsigned InstID,
435 void pushValueSigned(
const Value *V,
unsigned InstID,
437 void writeInstruction(
const Instruction &
I,
unsigned InstID,
440 void writeGlobalValueSymbolTable(
443 void writeUseListBlock(
const Function *
F);
447 void writeBlockInfo();
454 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
458class IndexBitcodeWriter :
public BitcodeWriterBase {
473 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
477 std::vector<uint64_t> StackIds;
485 unsigned GlobalValueId = 0;
503 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
504 DecSummaries(DecSummaries),
505 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
509 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
514 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
516 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
523 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
524 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
530 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
536 for (
auto &CI :
FS->callsites()) {
547 if (CI.StackIdIndices.empty()) {
548 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
551 for (
auto Idx : CI.StackIdIndices)
552 RecordStackIdReference(
Idx);
555 for (
auto &AI :
FS->allocs())
556 for (
auto &MIB : AI.MIBs)
557 for (
auto Idx : MIB.StackIdIndices)
558 RecordStackIdReference(
Idx);
564 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
569 template<
typename Functor>
570 void forEachSummary(Functor Callback) {
571 if (ModuleToSummariesForIndex) {
572 for (
auto &M : *ModuleToSummariesForIndex)
573 for (
auto &Summary :
M.second) {
574 Callback(Summary,
false);
578 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
579 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
582 for (
auto &Summaries : Index)
583 for (
auto &Summary : Summaries.second.SummaryList)
584 Callback({Summaries.first,
Summary.get()},
false);
592 template <
typename Functor>
void forEachModule(Functor Callback) {
593 if (ModuleToSummariesForIndex) {
594 for (
const auto &M : *ModuleToSummariesForIndex) {
595 const auto &MPI =
Index.modulePaths().find(
M.first);
596 if (MPI ==
Index.modulePaths().end()) {
600 assert(ModuleToSummariesForIndex->size() == 1);
610 std::vector<StringRef> ModulePaths;
611 for (
auto &[ModPath,
_] :
Index.modulePaths())
612 ModulePaths.push_back(ModPath);
614 for (
auto &ModPath : ModulePaths)
615 Callback(*
Index.modulePaths().find(ModPath));
623 void writeModStrings();
624 void writeCombinedGlobalValueSummary();
627 auto VMI = GUIDToValueIdMap.find(ValGUID);
628 if (VMI == GUIDToValueIdMap.end())
633 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
668 case Instruction::Add:
670 case Instruction::Sub:
672 case Instruction::Mul:
675 case Instruction::FDiv:
678 case Instruction::FRem:
752 case Attribute::Alignment:
754 case Attribute::AllocAlign:
756 case Attribute::AllocSize:
758 case Attribute::AlwaysInline:
760 case Attribute::Builtin:
762 case Attribute::ByVal:
764 case Attribute::Convergent:
766 case Attribute::InAlloca:
768 case Attribute::Cold:
770 case Attribute::DisableSanitizerInstrumentation:
772 case Attribute::FnRetThunkExtern:
776 case Attribute::ElementType:
778 case Attribute::HybridPatchable:
780 case Attribute::InlineHint:
782 case Attribute::InReg:
784 case Attribute::JumpTable:
786 case Attribute::MinSize:
788 case Attribute::AllocatedPointer:
790 case Attribute::AllocKind:
792 case Attribute::Memory:
794 case Attribute::NoFPClass:
796 case Attribute::Naked:
798 case Attribute::Nest:
800 case Attribute::NoAlias:
802 case Attribute::NoBuiltin:
804 case Attribute::NoCallback:
806 case Attribute::NoDivergenceSource:
808 case Attribute::NoDuplicate:
810 case Attribute::NoFree:
812 case Attribute::NoImplicitFloat:
814 case Attribute::NoInline:
816 case Attribute::NoRecurse:
818 case Attribute::NoMerge:
820 case Attribute::NonLazyBind:
822 case Attribute::NonNull:
824 case Attribute::Dereferenceable:
826 case Attribute::DereferenceableOrNull:
828 case Attribute::NoRedZone:
830 case Attribute::NoReturn:
832 case Attribute::NoSync:
834 case Attribute::NoCfCheck:
836 case Attribute::NoProfile:
838 case Attribute::SkipProfile:
840 case Attribute::NoUnwind:
842 case Attribute::NoSanitizeBounds:
844 case Attribute::NoSanitizeCoverage:
846 case Attribute::NullPointerIsValid:
848 case Attribute::OptimizeForDebugging:
850 case Attribute::OptForFuzzing:
852 case Attribute::OptimizeForSize:
854 case Attribute::OptimizeNone:
856 case Attribute::ReadNone:
858 case Attribute::ReadOnly:
860 case Attribute::Returned:
862 case Attribute::ReturnsTwice:
864 case Attribute::SExt:
866 case Attribute::Speculatable:
868 case Attribute::StackAlignment:
870 case Attribute::StackProtect:
872 case Attribute::StackProtectReq:
874 case Attribute::StackProtectStrong:
876 case Attribute::SafeStack:
878 case Attribute::ShadowCallStack:
880 case Attribute::StrictFP:
882 case Attribute::StructRet:
884 case Attribute::SanitizeAddress:
886 case Attribute::SanitizeHWAddress:
888 case Attribute::SanitizeThread:
890 case Attribute::SanitizeType:
892 case Attribute::SanitizeMemory:
894 case Attribute::SanitizeNumericalStability:
896 case Attribute::SanitizeRealtime:
898 case Attribute::SanitizeRealtimeBlocking:
900 case Attribute::SpeculativeLoadHardening:
902 case Attribute::SwiftError:
904 case Attribute::SwiftSelf:
906 case Attribute::SwiftAsync:
908 case Attribute::UWTable:
910 case Attribute::VScaleRange:
912 case Attribute::WillReturn:
914 case Attribute::WriteOnly:
916 case Attribute::ZExt:
918 case Attribute::ImmArg:
920 case Attribute::SanitizeMemTag:
922 case Attribute::Preallocated:
924 case Attribute::NoUndef:
926 case Attribute::ByRef:
928 case Attribute::MustProgress:
930 case Attribute::PresplitCoroutine:
932 case Attribute::Writable:
934 case Attribute::CoroDestroyOnlyWhenComplete:
936 case Attribute::CoroElideSafe:
938 case Attribute::DeadOnUnwind:
940 case Attribute::Range:
942 case Attribute::Initializes:
944 case Attribute::NoExt:
946 case Attribute::Captures:
948 case Attribute::DeadOnReturn:
974 unsigned NumWords =
A.getActiveWords();
975 const uint64_t *RawData =
A.getRawData();
976 for (
unsigned i = 0; i < NumWords; i++)
996void ModuleBitcodeWriter::writeAttributeGroupTable() {
997 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
999 if (AttrGrps.empty())
return;
1005 unsigned AttrListIndex = Pair.first;
1008 Record.push_back(AttrListIndex);
1011 if (Attr.isEnumAttribute()) {
1014 }
else if (Attr.isIntAttribute()) {
1018 if (Kind == Attribute::Memory) {
1021 Record.push_back((Version << 56) | Attr.getValueAsInt());
1023 Record.push_back(Attr.getValueAsInt());
1025 }
else if (Attr.isStringAttribute()) {
1027 StringRef Val = Attr.getValueAsString();
1036 }
else if (Attr.isTypeAttribute()) {
1037 Type *Ty = Attr.getValueAsType();
1038 Record.push_back(Ty ? 6 : 5);
1042 }
else if (Attr.isConstantRangeAttribute()) {
1048 assert(Attr.isConstantRangeListAttribute());
1054 for (
auto &CR : Val)
1066void ModuleBitcodeWriter::writeAttributeTable() {
1068 if (
Attrs.empty())
return;
1074 for (
unsigned i :
AL.indexes()) {
1088void ModuleBitcodeWriter::writeTypeTable() {
1097 auto Abbv = std::make_shared<BitCodeAbbrev>();
1100 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1103 Abbv = std::make_shared<BitCodeAbbrev>();
1108 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1111 Abbv = std::make_shared<BitCodeAbbrev>();
1116 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1119 Abbv = std::make_shared<BitCodeAbbrev>();
1123 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1126 Abbv = std::make_shared<BitCodeAbbrev>();
1131 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1134 Abbv = std::make_shared<BitCodeAbbrev>();
1138 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1146 for (
Type *
T : TypeList) {
1147 int AbbrevToUse = 0;
1150 switch (
T->getTypeID()) {
1177 AbbrevToUse = OpaquePtrAbbrev;
1186 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1188 AbbrevToUse = FunctionAbbrev;
1196 for (
Type *ET :
ST->elements())
1199 if (
ST->isLiteral()) {
1201 AbbrevToUse = StructAnonAbbrev;
1203 if (
ST->isOpaque()) {
1207 AbbrevToUse = StructNamedAbbrev;
1211 if (!
ST->getName().empty())
1221 TypeVals.
push_back(AT->getNumElements());
1223 AbbrevToUse = ArrayAbbrev;
1232 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1234 if (isa<ScalableVectorType>(VT))
1244 for (
Type *InnerTy :
TET->type_params())
1254 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1295 RawFlags |= Flags.ReadNone;
1296 RawFlags |= (Flags.ReadOnly << 1);
1297 RawFlags |= (Flags.NoRecurse << 2);
1298 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1299 RawFlags |= (Flags.NoInline << 4);
1300 RawFlags |= (Flags.AlwaysInline << 5);
1301 RawFlags |= (Flags.NoUnwind << 6);
1302 RawFlags |= (Flags.MayThrow << 7);
1303 RawFlags |= (Flags.HasUnknownCall << 8);
1304 RawFlags |= (Flags.MustBeUnreachable << 9);
1311 bool ImportAsDecl =
false) {
1314 RawFlags |= Flags.NotEligibleToImport;
1315 RawFlags |= (Flags.Live << 1);
1316 RawFlags |= (Flags.DSOLocal << 2);
1317 RawFlags |= (Flags.CanAutoHide << 3);
1322 RawFlags = (RawFlags << 4) | Flags.Linkage;
1324 RawFlags |= (Flags.Visibility << 8);
1326 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1327 RawFlags |= (ImportType << 10);
1333 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1334 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1376 case GlobalVariable::NotThreadLocal:
return 0;
1377 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1378 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1379 case GlobalVariable::InitialExecTLSModel:
return 3;
1380 case GlobalVariable::LocalExecTLSModel:
return 4;
1386 switch (
C.getSelectionKind()) {
1403 case GlobalValue::UnnamedAddr::None:
return 0;
1404 case GlobalValue::UnnamedAddr::Local:
return 2;
1405 case GlobalValue::UnnamedAddr::Global:
return 1;
1410size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1413 return StrtabBuilder.
add(Str);
1416void ModuleBitcodeWriter::writeComdats() {
1431void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1436 auto Abbv = std::make_shared<BitCodeAbbrev>();
1442 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1458 bool isChar6 =
true;
1459 for (
char C : Str) {
1462 if ((
unsigned char)
C & 128)
1472 "Sanitizer Metadata is too large for naive serialization.");
1475 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1476 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1482void ModuleBitcodeWriter::writeModuleInfo() {
1484 if (!
M.getTargetTriple().empty())
1486 M.getTargetTriple().str(), 0 );
1487 const std::string &
DL =
M.getDataLayoutStr();
1490 if (!
M.getModuleInlineAsm().empty())
1496 std::map<std::string, unsigned> SectionMap;
1497 std::map<std::string, unsigned> GCMap;
1499 unsigned MaxGlobalType = 0;
1502 MaxGVarAlignment = !MaxGVarAlignment ? *
A : std::max(*MaxGVarAlignment, *
A);
1503 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1504 if (GV.hasSection()) {
1506 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1510 Entry = SectionMap.size();
1515 if (
F.hasSection()) {
1517 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1521 Entry = SectionMap.size();
1526 unsigned &
Entry = GCMap[
F.getGC()];
1530 Entry = GCMap.size();
1536 unsigned SimpleGVarAbbrev = 0;
1537 if (!
M.global_empty()) {
1539 auto Abbv = std::make_shared<BitCodeAbbrev>();
1550 if (!MaxGVarAlignment)
1553 unsigned MaxEncAlignment = getEncodedAlign(MaxGVarAlignment);
1557 if (SectionMap.empty())
1563 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1577 auto Abbv = std::make_shared<BitCodeAbbrev>();
1580 Abbv->Add(AbbrevOpToUse);
1581 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1583 for (
const auto P :
M.getSourceFileName())
1593 unsigned AbbrevToUse = 0;
1599 Vals.
push_back(addToStrtab(GV.getName()));
1602 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1606 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1607 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1609 if (GV.isThreadLocal() ||
1611 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1612 GV.isExternallyInitialized() ||
1614 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1615 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1619 Vals.
push_back(GV.isExternallyInitialized());
1627 Vals.
push_back(addToStrtab(GV.getPartition()));
1628 Vals.
push_back(GV.getPartition().size());
1631 GV.getSanitizerMetadata())
1635 AbbrevToUse = SimpleGVarAbbrev;
1655 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1656 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1668 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1672 Vals.
push_back(addToStrtab(
F.getPartition()));
1675 unsigned AbbrevToUse = 0;
1688 Vals.
push_back(
A.getType()->getAddressSpace());
1696 Vals.
push_back(addToStrtab(
A.getPartition()));
1699 unsigned AbbrevToUse = 0;
1711 Vals.
push_back(
I.getType()->getAddressSpace());
1716 Vals.
push_back(addToStrtab(
I.getPartition()));
1722 writeValueSymbolTableForwardDecl();
1728 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1729 if (OBO->hasNoSignedWrap())
1731 if (OBO->hasNoUnsignedWrap())
1733 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1736 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1737 if (PDI->isDisjoint())
1739 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1740 if (FPMO->hasAllowReassoc())
1742 if (FPMO->hasNoNaNs())
1744 if (FPMO->hasNoInfs())
1746 if (FPMO->hasNoSignedZeros())
1748 if (FPMO->hasAllowReciprocal())
1750 if (FPMO->hasAllowContract())
1752 if (FPMO->hasApproxFunc())
1754 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1755 if (NNI->hasNonNeg())
1757 }
else if (
const auto *TI = dyn_cast<TruncInst>(V)) {
1758 if (TI->hasNoSignedWrap())
1760 if (TI->hasNoUnsignedWrap())
1762 }
else if (
const auto *
GEP = dyn_cast<GEPOperator>(V)) {
1763 if (
GEP->isInBounds())
1765 if (
GEP->hasNoUnsignedSignedWrap())
1767 if (
GEP->hasNoUnsignedWrap())
1769 }
else if (
const auto *ICmp = dyn_cast<ICmpInst>(V)) {
1770 if (ICmp->hasSameSign())
1777void ModuleBitcodeWriter::writeValueAsMetadata(
1787void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1792 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1793 "Unexpected function-local metadata");
1802unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1805 auto Abbv = std::make_shared<BitCodeAbbrev>();
1818void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1822 Abbrev = createDILocationAbbrev();
1824 Record.push_back(
N->isDistinct());
1825 Record.push_back(
N->getLine());
1826 Record.push_back(
N->getColumn());
1829 Record.push_back(
N->isImplicitCode());
1830 Record.push_back(
N->getAtomGroup());
1831 Record.push_back(
N->getAtomRank());
1836unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1839 auto Abbv = std::make_shared<BitCodeAbbrev>();
1850void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1854 Abbrev = createGenericDINodeAbbrev();
1856 Record.push_back(
N->isDistinct());
1857 Record.push_back(
N->getTag());
1860 for (
auto &
I :
N->operands())
1867void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1881void ModuleBitcodeWriter::writeDIGenericSubrange(
1894void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1898 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1899 Record.push_back(
N->getValue().getBitWidth());
1907void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1910 const unsigned SizeIsMetadata = 0x2;
1911 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1912 Record.push_back(
N->getTag());
1915 Record.push_back(
N->getAlignInBits());
1916 Record.push_back(
N->getEncoding());
1917 Record.push_back(
N->getFlags());
1918 Record.push_back(
N->getNumExtraInhabitants());
1924void ModuleBitcodeWriter::writeDIFixedPointType(
1927 const unsigned SizeIsMetadata = 0x2;
1928 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1929 Record.push_back(
N->getTag());
1932 Record.push_back(
N->getAlignInBits());
1933 Record.push_back(
N->getEncoding());
1934 Record.push_back(
N->getFlags());
1935 Record.push_back(
N->getKind());
1936 Record.push_back(
N->getFactorRaw());
1938 auto WriteWideInt = [&](
const APInt &
Value) {
1943 Record.push_back(Encoded);
1947 WriteWideInt(
N->getNumeratorRaw());
1948 WriteWideInt(
N->getDenominatorRaw());
1954void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1957 const unsigned SizeIsMetadata = 0x2;
1958 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1959 Record.push_back(
N->getTag());
1965 Record.push_back(
N->getAlignInBits());
1966 Record.push_back(
N->getEncoding());
1972void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1975 const unsigned SizeIsMetadata = 0x2;
1976 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
1977 Record.push_back(
N->getTag());
1980 Record.push_back(
N->getLine());
1984 Record.push_back(
N->getAlignInBits());
1986 Record.push_back(
N->getFlags());
1991 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1992 Record.push_back(*DWARFAddressSpace + 1);
1998 if (
auto PtrAuthData =
N->getPtrAuthData())
1999 Record.push_back(PtrAuthData->RawData);
2010 const unsigned SizeIsMetadata = 0x2;
2011 Record.push_back(SizeIsMetadata | (
unsigned)
N->isDistinct());
2014 Record.push_back(
N->getLine());
2017 Record.push_back(
N->getAlignInBits());
2018 Record.push_back(
N->getFlags());
2029void ModuleBitcodeWriter::writeDICompositeType(
2032 const unsigned IsNotUsedInOldTypeRef = 0x2;
2033 const unsigned SizeIsMetadata = 0x4;
2034 Record.push_back(SizeIsMetadata | IsNotUsedInOldTypeRef |
2035 (
unsigned)
N->isDistinct());
2036 Record.push_back(
N->getTag());
2039 Record.push_back(
N->getLine());
2043 Record.push_back(
N->getAlignInBits());
2045 Record.push_back(
N->getFlags());
2047 Record.push_back(
N->getRuntimeLang());
2057 Record.push_back(
N->getNumExtraInhabitants());
2067void ModuleBitcodeWriter::writeDISubroutineType(
2070 const unsigned HasNoOldTypeRefs = 0x2;
2071 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
2072 Record.push_back(
N->getFlags());
2080void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
2083 Record.push_back(
N->isDistinct());
2086 if (
N->getRawChecksum()) {
2087 Record.push_back(
N->getRawChecksum()->Kind);
2095 auto Source =
N->getRawSource();
2103void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2106 assert(
N->isDistinct() &&
"Expected distinct compile units");
2108 Record.push_back(
N->getSourceLanguage());
2111 Record.push_back(
N->isOptimized());
2113 Record.push_back(
N->getRuntimeVersion());
2115 Record.push_back(
N->getEmissionKind());
2121 Record.push_back(
N->getDWOId());
2123 Record.push_back(
N->getSplitDebugInlining());
2124 Record.push_back(
N->getDebugInfoForProfiling());
2125 Record.push_back((
unsigned)
N->getNameTableKind());
2126 Record.push_back(
N->getRangesBaseAddress());
2134void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2137 const uint64_t HasUnitFlag = 1 << 1;
2138 const uint64_t HasSPFlagsFlag = 1 << 2;
2139 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2144 Record.push_back(
N->getLine());
2146 Record.push_back(
N->getScopeLine());
2148 Record.push_back(
N->getSPFlags());
2149 Record.push_back(
N->getVirtualIndex());
2150 Record.push_back(
N->getFlags());
2155 Record.push_back(
N->getThisAdjustment());
2159 Record.push_back(
N->getKeyInstructionsEnabled());
2168 Record.push_back(
N->isDistinct());
2171 Record.push_back(
N->getLine());
2172 Record.push_back(
N->getColumn());
2178void ModuleBitcodeWriter::writeDILexicalBlockFile(
2181 Record.push_back(
N->isDistinct());
2184 Record.push_back(
N->getDiscriminator());
2190void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2193 Record.push_back(
N->isDistinct());
2198 Record.push_back(
N->getLineNo());
2204void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2207 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2215void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2218 Record.push_back(
N->isDistinct());
2219 Record.push_back(
N->getMacinfoType());
2220 Record.push_back(
N->getLine());
2228void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2231 Record.push_back(
N->isDistinct());
2232 Record.push_back(
N->getMacinfoType());
2233 Record.push_back(
N->getLine());
2241void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2243 Record.reserve(
N->getArgs().size());
2251void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2254 Record.push_back(
N->isDistinct());
2255 for (
auto &
I :
N->operands())
2257 Record.push_back(
N->getLineNo());
2258 Record.push_back(
N->getIsDecl());
2264void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2268 Record.push_back(
N->isDistinct());
2273void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2276 Record.push_back(
N->isDistinct());
2279 Record.push_back(
N->isDefault());
2285void ModuleBitcodeWriter::writeDITemplateValueParameter(
2288 Record.push_back(
N->isDistinct());
2289 Record.push_back(
N->getTag());
2292 Record.push_back(
N->isDefault());
2299void ModuleBitcodeWriter::writeDIGlobalVariable(
2308 Record.push_back(
N->getLine());
2310 Record.push_back(
N->isLocalToUnit());
2311 Record.push_back(
N->isDefinition());
2314 Record.push_back(
N->getAlignInBits());
2321void ModuleBitcodeWriter::writeDILocalVariable(
2337 const uint64_t HasAlignmentFlag = 1 << 1;
2342 Record.push_back(
N->getLine());
2344 Record.push_back(
N->getArg());
2345 Record.push_back(
N->getFlags());
2346 Record.push_back(
N->getAlignInBits());
2353void ModuleBitcodeWriter::writeDILabel(
2361 Record.push_back(
N->getLine());
2362 Record.push_back(
N->getColumn());
2363 Record.push_back(
N->getCoroSuspendIdx().has_value()
2364 ? (
uint64_t)
N->getCoroSuspendIdx().value()
2365 : std::numeric_limits<uint64_t>::max());
2371void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2374 Record.reserve(
N->getElements().size() + 1);
2377 Record.append(
N->elements_begin(),
N->elements_end());
2383void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2386 Record.push_back(
N->isDistinct());
2397 Record.push_back(
N->isDistinct());
2400 Record.push_back(
N->getLine());
2403 Record.push_back(
N->getAttributes());
2410void ModuleBitcodeWriter::writeDIImportedEntity(
2413 Record.push_back(
N->isDistinct());
2414 Record.push_back(
N->getTag());
2417 Record.push_back(
N->getLine());
2426unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2427 auto Abbv = std::make_shared<BitCodeAbbrev>();
2434void ModuleBitcodeWriter::writeNamedMetadata(
2436 if (
M.named_metadata_empty())
2439 unsigned Abbrev = createNamedMetadataAbbrev();
2443 Record.append(Str.bytes_begin(), Str.bytes_end());
2448 for (
const MDNode *
N : NMD.operands())
2455unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2456 auto Abbv = std::make_shared<BitCodeAbbrev>();
2468void ModuleBitcodeWriter::writeMetadataStrings(
2470 if (Strings.empty())
2475 Record.push_back(Strings.size());
2482 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2491 Blob.
append(cast<MDString>(MD)->getString());
2500#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2501#include "llvm/IR/Metadata.def"
2505void ModuleBitcodeWriter::writeMetadataRecords(
2507 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2512#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2513#include "llvm/IR/Metadata.def"
2518 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2519 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2521 switch (
N->getMetadataID()) {
2524#define HANDLE_MDNODE_LEAF(CLASS) \
2525 case Metadata::CLASS##Kind: \
2527 write##CLASS(cast<CLASS>(N), Record, \
2528 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2530 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2532#include "llvm/IR/Metadata.def"
2535 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2539 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2543void ModuleBitcodeWriter::writeModuleMetadata() {
2544 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2552 std::vector<unsigned> MDAbbrevs;
2555 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2556 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2557 createGenericDINodeAbbrev();
2559 auto Abbv = std::make_shared<BitCodeAbbrev>();
2563 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2565 Abbv = std::make_shared<BitCodeAbbrev>();
2569 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2591 std::vector<uint64_t> IndexPos;
2606 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2607 for (
auto &Elt : IndexPos) {
2608 auto EltDelta = Elt - PreviousValue;
2609 PreviousValue = Elt;
2618 writeNamedMetadata(
Record);
2620 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2623 pushGlobalMetadataAttachment(
Record, GO);
2627 if (
F.isDeclaration() &&
F.hasMetadata())
2628 AddDeclAttachedMetadata(
F);
2632 if (GV.hasMetadata())
2633 AddDeclAttachedMetadata(GV);
2638void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2649void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2654 for (
const auto &
I : MDs) {
2660void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2665 if (
F.hasMetadata()) {
2666 pushGlobalMetadataAttachment(
Record,
F);
2677 I.getAllMetadataOtherThanDebugLoc(MDs);
2680 if (MDs.
empty())
continue;
2684 for (
const auto &[
ID, MD] : MDs) {
2695void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2701 M.getMDKindNames(Names);
2703 if (Names.
empty())
return;
2707 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2708 Record.push_back(MDKindID);
2719void ModuleBitcodeWriter::writeOperandBundleTags() {
2727 M.getOperandBundleTags(Tags);
2736 for (
auto Tag : Tags) {
2746void ModuleBitcodeWriter::writeSyncScopeNames() {
2748 M.getContext().getSyncScopeNames(SSNs);
2755 for (
auto SSN : SSNs) {
2756 Record.append(SSN.begin(), SSN.end());
2764void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2766 if (FirstVal == LastVal)
return;
2770 unsigned AggregateAbbrev = 0;
2771 unsigned String8Abbrev = 0;
2772 unsigned CString7Abbrev = 0;
2773 unsigned CString6Abbrev = 0;
2777 auto Abbv = std::make_shared<BitCodeAbbrev>();
2781 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2784 Abbv = std::make_shared<BitCodeAbbrev>();
2788 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2790 Abbv = std::make_shared<BitCodeAbbrev>();
2794 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2796 Abbv = std::make_shared<BitCodeAbbrev>();
2800 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2806 Type *LastTy =
nullptr;
2807 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2808 const Value *
V = Vals[i].first;
2810 if (
V->getType() != LastTy) {
2811 LastTy =
V->getType();
2814 CONSTANTS_SETTYPE_ABBREV);
2818 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2821 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2822 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2830 StringRef ConstraintStr =
IA->getConstraintString();
2838 unsigned Code = -1U;
2839 unsigned AbbrevToUse = 0;
2840 if (
C->isNullValue()) {
2842 }
else if (isa<PoisonValue>(
C)) {
2844 }
else if (isa<UndefValue>(
C)) {
2847 if (
IV->getBitWidth() <= 64) {
2851 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2856 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2861 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2865 APInt api = CFP->getValueAPF().bitcastToAPInt();
2867 Record.push_back((p[1] << 48) | (p[0] >> 16));
2868 Record.push_back(p[0] & 0xffffLL);
2870 APInt api = CFP->getValueAPF().bitcastToAPInt();
2875 assert(0 &&
"Unknown FP type!");
2877 }
else if (isa<ConstantDataSequential>(
C) &&
2878 cast<ConstantDataSequential>(
C)->isString()) {
2881 uint64_t NumElts = Str->getNumElements();
2883 if (Str->isCString()) {
2888 AbbrevToUse = String8Abbrev;
2892 for (
uint64_t i = 0; i != NumElts; ++i) {
2893 unsigned char V = Str->getElementAsInteger(i);
2895 isCStr7 &= (
V & 128) == 0;
2901 AbbrevToUse = CString6Abbrev;
2903 AbbrevToUse = CString7Abbrev;
2905 dyn_cast<ConstantDataSequential>(
C)) {
2907 Type *EltTy = CDS->getElementType();
2908 if (isa<IntegerType>(EltTy)) {
2909 for (
uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2910 Record.push_back(CDS->getElementAsInteger(i));
2912 for (
uint64_t i = 0, e = CDS->getNumElements(); i != e; ++i)
2914 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2916 }
else if (isa<ConstantAggregate>(
C)) {
2918 for (
const Value *
Op :
C->operands())
2920 AbbrevToUse = AggregateAbbrev;
2921 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2922 switch (
CE->getOpcode()) {
2929 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2931 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2941 case Instruction::FNeg: {
2942 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2951 case Instruction::GetElementPtr: {
2953 const auto *GO = cast<GEPOperator>(
C);
2956 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2960 for (
const Value *
Op :
CE->operands()) {
2966 case Instruction::ExtractElement:
2973 case Instruction::InsertElement:
2980 case Instruction::ShuffleVector:
2985 if (
C->getType() ==
C->getOperand(0)->getType()) {
2996 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
3001 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
3005 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
3009 }
else if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C)) {
3028void ModuleBitcodeWriter::writeModuleConstants() {
3033 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
3034 if (!isa<GlobalValue>(Vals[i].first)) {
3035 writeConstants(i, Vals.size(),
true);
3049bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
3054 if (
ValID >= InstID) {
3061bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
3063 bool IsMetadata =
V->getType()->isMetadataTy();
3066 Metadata *MD = cast<MetadataAsValue>(V)->getMetadata();
3071 return pushValueAndType(V, InstID, Vals);
3074void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
3081 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
3083 for (
auto &Input : Bundle.Inputs)
3084 pushValueOrMetadata(Input, InstID,
Record);
3093void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
3099void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
3102 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
3107void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3111 unsigned AbbrevToUse = 0;
3113 switch (
I.getOpcode()) {
3117 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3118 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3123 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3124 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3128 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
3130 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3131 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3132 pushValue(
I.getOperand(1), InstID, Vals);
3136 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3137 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3142 case Instruction::FNeg: {
3144 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3145 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3149 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3150 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3155 case Instruction::GetElementPtr: {
3157 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3158 auto &GEPInst = cast<GetElementPtrInst>(
I);
3161 for (
const Value *
Op :
I.operands())
3162 pushValueAndType(
Op, InstID, Vals);
3165 case Instruction::ExtractValue: {
3167 pushValueAndType(
I.getOperand(0), InstID, Vals);
3172 case Instruction::InsertValue: {
3174 pushValueAndType(
I.getOperand(0), InstID, Vals);
3175 pushValueAndType(
I.getOperand(1), InstID, Vals);
3180 case Instruction::Select: {
3182 pushValueAndType(
I.getOperand(1), InstID, Vals);
3183 pushValue(
I.getOperand(2), InstID, Vals);
3184 pushValueAndType(
I.getOperand(0), InstID, Vals);
3190 case Instruction::ExtractElement:
3192 pushValueAndType(
I.getOperand(0), InstID, Vals);
3193 pushValueAndType(
I.getOperand(1), InstID, Vals);
3195 case Instruction::InsertElement:
3197 pushValueAndType(
I.getOperand(0), InstID, Vals);
3198 pushValue(
I.getOperand(1), InstID, Vals);
3199 pushValueAndType(
I.getOperand(2), InstID, Vals);
3201 case Instruction::ShuffleVector:
3203 pushValueAndType(
I.getOperand(0), InstID, Vals);
3204 pushValue(
I.getOperand(1), InstID, Vals);
3205 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3208 case Instruction::ICmp:
3209 case Instruction::FCmp: {
3212 AbbrevToUse = FUNCTION_INST_CMP_ABBREV;
3213 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3215 pushValue(
I.getOperand(1), InstID, Vals);
3221 AbbrevToUse = FUNCTION_INST_CMP_FLAGS_ABBREV;
3226 case Instruction::Ret:
3229 unsigned NumOperands =
I.getNumOperands();
3230 if (NumOperands == 0)
3231 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3232 else if (NumOperands == 1) {
3233 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3234 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3236 for (
const Value *
Op :
I.operands())
3237 pushValueAndType(
Op, InstID, Vals);
3241 case Instruction::Br:
3244 AbbrevToUse = FUNCTION_INST_BR_UNCOND_ABBREV;
3247 if (
II.isConditional()) {
3249 pushValue(
II.getCondition(), InstID, Vals);
3250 AbbrevToUse = FUNCTION_INST_BR_COND_ABBREV;
3254 case Instruction::Switch:
3259 pushValue(
SI.getCondition(), InstID, Vals);
3261 for (
auto Case :
SI.cases()) {
3267 case Instruction::IndirectBr:
3271 pushValue(
I.getOperand(0), InstID, Vals);
3276 case Instruction::Invoke: {
3281 if (
II->hasOperandBundles())
3282 writeOperandBundles(*
II, InstID);
3291 pushValueAndType(Callee, InstID, Vals);
3294 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3295 pushValue(
I.getOperand(i), InstID, Vals);
3298 if (FTy->isVarArg()) {
3299 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3300 pushValueAndType(
I.getOperand(i), InstID, Vals);
3304 case Instruction::Resume:
3306 pushValueAndType(
I.getOperand(0), InstID, Vals);
3308 case Instruction::CleanupRet: {
3310 const auto &CRI = cast<CleanupReturnInst>(
I);
3311 pushValue(CRI.getCleanupPad(), InstID, Vals);
3312 if (CRI.hasUnwindDest())
3316 case Instruction::CatchRet: {
3318 const auto &CRI = cast<CatchReturnInst>(
I);
3319 pushValue(CRI.getCatchPad(), InstID, Vals);
3323 case Instruction::CleanupPad:
3324 case Instruction::CatchPad: {
3325 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3328 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3330 unsigned NumArgOperands = FuncletPad.arg_size();
3332 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3333 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3336 case Instruction::CatchSwitch: {
3338 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3340 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3342 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3344 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3347 if (CatchSwitch.hasUnwindDest())
3351 case Instruction::CallBr: {
3357 writeOperandBundles(*CBI, InstID);
3372 pushValueAndType(Callee, InstID, Vals);
3375 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3376 pushValue(
I.getOperand(i), InstID, Vals);
3379 if (FTy->isVarArg()) {
3380 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3381 pushValueAndType(
I.getOperand(i), InstID, Vals);
3385 case Instruction::Unreachable:
3387 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3390 case Instruction::PHI: {
3391 const PHINode &PN = cast<PHINode>(
I);
3408 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3413 case Instruction::LandingPad: {
3424 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3429 case Instruction::Alloca: {
3437 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3438 Bitfield::set<APV::AlignLower>(
3439 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3440 Bitfield::set<APV::AlignUpper>(
Record,
3441 EncodedAlign >> APV::AlignLower::Bits);
3443 Bitfield::set<APV::ExplicitType>(
Record,
true);
3448 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3453 case Instruction::Load:
3454 if (cast<LoadInst>(
I).isAtomic()) {
3456 pushValueAndType(
I.getOperand(0), InstID, Vals);
3459 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3460 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3464 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3465 if (cast<LoadInst>(
I).isAtomic()) {
3467 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3470 case Instruction::Store:
3471 if (cast<StoreInst>(
I).isAtomic()) {
3475 AbbrevToUse = FUNCTION_INST_STORE_ABBREV;
3477 if (pushValueAndType(
I.getOperand(1), InstID, Vals))
3479 if (pushValueAndType(
I.getOperand(0), InstID, Vals))
3482 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3483 if (cast<StoreInst>(
I).isAtomic()) {
3486 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3489 case Instruction::AtomicCmpXchg:
3491 pushValueAndType(
I.getOperand(0), InstID, Vals);
3492 pushValueAndType(
I.getOperand(1), InstID, Vals);
3493 pushValue(
I.getOperand(2), InstID, Vals);
3494 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3498 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3501 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3504 case Instruction::AtomicRMW:
3506 pushValueAndType(
I.getOperand(0), InstID, Vals);
3507 pushValueAndType(
I.getOperand(1), InstID, Vals);
3510 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3513 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3516 case Instruction::Fence:
3519 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3521 case Instruction::Call: {
3526 writeOperandBundles(CI, InstID);
3546 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3550 if (FTy->isVarArg()) {
3551 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3556 case Instruction::VAArg:
3559 pushValue(
I.getOperand(0), InstID, Vals);
3562 case Instruction::Freeze:
3564 pushValueAndType(
I.getOperand(0), InstID, Vals);
3574void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3580 VSTOffset -= bitcodeStartBit();
3581 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3585 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3589 auto Abbv = std::make_shared<BitCodeAbbrev>();
3593 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3598 if (
F.isDeclaration())
3605 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3606 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3610 Record[1] = BitcodeIndex / 32 + 1;
3619void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3634 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3640 if (isa<BasicBlock>(
Name.getValue())) {
3643 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3647 AbbrevToUse = VST_ENTRY_6_ABBREV;
3649 AbbrevToUse = VST_ENTRY_7_ABBREV;
3652 for (
const auto P :
Name.getKey())
3656 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3663void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3664 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3666 if (isa<BasicBlock>(Order.V))
3676void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3678 "Expected to be preserving use-list order");
3680 auto hasMore = [&]() {
3696void ModuleBitcodeWriter::writeFunction(
3715 unsigned CstStart, CstEnd;
3717 writeConstants(CstStart, CstEnd,
false);
3720 writeFunctionMetadata(
F);
3723 unsigned InstID = CstEnd;
3725 bool NeedsMetadataAttachment =
F.hasMetadata();
3733 writeInstruction(
I, InstID, Vals);
3735 if (!
I.getType()->isVoidTy())
3739 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3755 FUNCTION_DEBUG_LOC_ABBREV);
3765 if (
I.hasDbgRecords()) {
3769 auto PushValueOrMetadata = [&Vals, InstID,
3772 "RawLocation unexpectedly null in DbgVariableRecord");
3778 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3792 for (
DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3818 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3840 while (!Worklist.empty()) {
3841 Value *
V = Worklist.pop_back_val();
3842 for (
User *U :
V->users()) {
3843 if (
auto *
I = dyn_cast<Instruction>(U)) {
3847 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3848 Visited.insert(U).second)
3849 Worklist.push_back(U);
3855 if (!BlockAddressUsers.
empty()) {
3864 if (
auto *Symtab =
F.getValueSymbolTable())
3865 writeFunctionLevelValueSymbolTable(*Symtab);
3867 if (NeedsMetadataAttachment)
3868 writeFunctionMetadataAttachment(
F);
3870 writeUseListBlock(&
F);
3876void ModuleBitcodeWriter::writeBlockInfo() {
3889 auto Abbv = std::make_shared<BitCodeAbbrev>();
3900 auto Abbv = std::make_shared<BitCodeAbbrev>();
3910 auto Abbv = std::make_shared<BitCodeAbbrev>();
3920 auto Abbv = std::make_shared<BitCodeAbbrev>();
3926 VST_BBENTRY_6_ABBREV)
3931 auto Abbv = std::make_shared<BitCodeAbbrev>();
3933 Abbv->Add(TypeAbbrevOp);
3935 CONSTANTS_SETTYPE_ABBREV)
3940 auto Abbv = std::make_shared<BitCodeAbbrev>();
3944 CONSTANTS_INTEGER_ABBREV)
3949 auto Abbv = std::make_shared<BitCodeAbbrev>();
3957 CONSTANTS_CE_CAST_Abbrev)
3961 auto Abbv = std::make_shared<BitCodeAbbrev>();
3964 CONSTANTS_NULL_Abbrev)
3971 auto Abbv = std::make_shared<BitCodeAbbrev>();
3973 Abbv->Add(ValAbbrevOp);
3974 Abbv->Add(TypeAbbrevOp);
3978 FUNCTION_INST_LOAD_ABBREV)
3982 auto Abbv = std::make_shared<BitCodeAbbrev>();
3984 Abbv->Add(ValAbbrevOp);
3985 Abbv->Add(ValAbbrevOp);
3989 FUNCTION_INST_STORE_ABBREV)
3993 auto Abbv = std::make_shared<BitCodeAbbrev>();
3995 Abbv->Add(ValAbbrevOp);
3998 FUNCTION_INST_UNOP_ABBREV)
4002 auto Abbv = std::make_shared<BitCodeAbbrev>();
4004 Abbv->Add(ValAbbrevOp);
4008 FUNCTION_INST_UNOP_FLAGS_ABBREV)
4012 auto Abbv = std::make_shared<BitCodeAbbrev>();
4014 Abbv->Add(ValAbbrevOp);
4015 Abbv->Add(ValAbbrevOp);
4018 FUNCTION_INST_BINOP_ABBREV)
4022 auto Abbv = std::make_shared<BitCodeAbbrev>();
4024 Abbv->Add(ValAbbrevOp);
4025 Abbv->Add(ValAbbrevOp);
4029 FUNCTION_INST_BINOP_FLAGS_ABBREV)
4033 auto Abbv = std::make_shared<BitCodeAbbrev>();
4035 Abbv->Add(ValAbbrevOp);
4036 Abbv->Add(TypeAbbrevOp);
4039 FUNCTION_INST_CAST_ABBREV)
4043 auto Abbv = std::make_shared<BitCodeAbbrev>();
4045 Abbv->Add(ValAbbrevOp);
4046 Abbv->Add(TypeAbbrevOp);
4050 FUNCTION_INST_CAST_FLAGS_ABBREV)
4055 auto Abbv = std::make_shared<BitCodeAbbrev>();
4058 FUNCTION_INST_RET_VOID_ABBREV)
4062 auto Abbv = std::make_shared<BitCodeAbbrev>();
4064 Abbv->Add(ValAbbrevOp);
4066 FUNCTION_INST_RET_VAL_ABBREV)
4070 auto Abbv = std::make_shared<BitCodeAbbrev>();
4073 Abbv->Add(ValAbbrevOp);
4075 FUNCTION_INST_BR_UNCOND_ABBREV)
4079 auto Abbv = std::make_shared<BitCodeAbbrev>();
4082 Abbv->Add(ValAbbrevOp);
4083 Abbv->Add(ValAbbrevOp);
4084 Abbv->Add(ValAbbrevOp);
4086 FUNCTION_INST_BR_COND_ABBREV)
4090 auto Abbv = std::make_shared<BitCodeAbbrev>();
4093 FUNCTION_INST_UNREACHABLE_ABBREV)
4097 auto Abbv = std::make_shared<BitCodeAbbrev>();
4100 Abbv->Add(TypeAbbrevOp);
4102 Abbv->Add(ValAbbrevOp);
4104 FUNCTION_INST_GEP_ABBREV)
4108 auto Abbv = std::make_shared<BitCodeAbbrev>();
4110 Abbv->Add(ValAbbrevOp);
4111 Abbv->Add(ValAbbrevOp);
4114 FUNCTION_INST_CMP_ABBREV)
4118 auto Abbv = std::make_shared<BitCodeAbbrev>();
4120 Abbv->Add(ValAbbrevOp);
4121 Abbv->Add(ValAbbrevOp);
4125 FUNCTION_INST_CMP_FLAGS_ABBREV)
4129 auto Abbv = std::make_shared<BitCodeAbbrev>();
4134 Abbv->Add(ValAbbrevOp);
4136 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
4140 auto Abbv = std::make_shared<BitCodeAbbrev>();
4151 FUNCTION_DEBUG_LOC_ABBREV)
4159void IndexBitcodeWriter::writeModStrings() {
4165 auto Abbv = std::make_shared<BitCodeAbbrev>();
4170 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
4173 Abbv = std::make_shared<BitCodeAbbrev>();
4178 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
4181 Abbv = std::make_shared<BitCodeAbbrev>();
4186 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4189 Abbv = std::make_shared<BitCodeAbbrev>();
4196 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4201 const auto &Hash = MPSE.
getValue();
4203 unsigned AbbrevToUse = Abbrev8Bit;
4205 AbbrevToUse = Abbrev6Bit;
4207 AbbrevToUse = Abbrev7Bit;
4209 auto ModuleId = ModuleIdMap.
size();
4210 ModuleIdMap[
Key] = ModuleId;
4219 Vals.
assign(Hash.begin(), Hash.end());
4231template <
typename Fn>
4235 if (!FS->type_tests().empty())
4240 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4245 for (
auto &VF : VFs) {
4246 Record.push_back(VF.GUID);
4247 Record.push_back(VF.Offset);
4253 FS->type_test_assume_vcalls());
4255 FS->type_checked_load_vcalls());
4257 auto WriteConstVCallVec = [&](
uint64_t Ty,
4259 for (
auto &VC : VCs) {
4261 Record.push_back(VC.VFunc.GUID);
4262 Record.push_back(VC.VFunc.Offset);
4269 FS->type_test_assume_const_vcalls());
4271 FS->type_checked_load_const_vcalls());
4281 if (!FS->paramAccesses().empty()) {
4283 for (
auto &Arg : FS->paramAccesses()) {
4284 size_t UndoSize =
Record.size();
4285 Record.push_back(Arg.ParamNo);
4286 WriteRange(Arg.Use);
4287 Record.push_back(Arg.Calls.size());
4288 for (
auto &Call : Arg.Calls) {
4289 Record.push_back(Call.ParamNo);
4290 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4297 Record.push_back(*ValueID);
4298 WriteRange(Call.Offsets);
4309 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4310 if (!FS->type_tests().empty())
4311 for (
auto &TT : FS->type_tests())
4312 ReferencedTypeIds.insert(TT);
4314 auto GetReferencedTypesFromVFuncIdVec =
4316 for (
auto &VF : VFs)
4317 ReferencedTypeIds.insert(VF.GUID);
4320 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4321 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4323 auto GetReferencedTypesFromConstVCallVec =
4325 for (
auto &VC : VCs)
4326 ReferencedTypeIds.insert(VC.VFunc.GUID);
4329 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4330 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4366 NameVals.
push_back(Summary.TTRes.TheKind);
4367 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4368 NameVals.
push_back(Summary.TTRes.AlignLog2);
4369 NameVals.
push_back(Summary.TTRes.SizeM1);
4370 NameVals.
push_back(Summary.TTRes.BitMask);
4371 NameVals.
push_back(Summary.TTRes.InlineBits);
4373 for (
auto &W : Summary.WPDRes)
4385 for (
auto &
P : Summary) {
4401 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4402 for (
auto &AI : FS->allocs()) {
4403 for (
auto &MIB : AI.MIBs) {
4405 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4406 for (
auto Id : MIB.StackIdIndices)
4407 StackIdIndices.
push_back(GetStackIndex(Id));
4409 CallStacks.insert({CallStacks.size(), StackIdIndices});
4422 assert(!CallStacks.empty());
4428 Builder.
build(std::move(CallStacks),
nullptr,
4437 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4438 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4439 std::function<
unsigned(
unsigned)> GetStackIndex,
4440 bool WriteContextSizeInfoIndex,
4445 for (
auto &CI : FS->callsites()) {
4449 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4450 Record.push_back(GetValueID(CI.Callee));
4452 Record.push_back(CI.StackIdIndices.size());
4453 Record.push_back(CI.Clones.size());
4455 for (
auto Id : CI.StackIdIndices)
4456 Record.push_back(GetStackIndex(Id));
4464 for (
auto &AI : FS->allocs()) {
4468 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4469 Record.push_back(AI.MIBs.size());
4471 Record.push_back(AI.Versions.size());
4472 for (
auto &MIB : AI.MIBs) {
4479 assert(CallStackCount <= CallStackPos.
size());
4480 Record.push_back(CallStackPos[CallStackCount++]);
4485 assert(AI.ContextSizeInfos.empty() ||
4486 AI.ContextSizeInfos.size() == AI.MIBs.size());
4488 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4496 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4497 for (
auto &Infos : AI.ContextSizeInfos) {
4498 Record.push_back(Infos.size());
4499 for (
auto [FullStackId, TotalSize] : Infos) {
4506 Record.push_back(TotalSize);
4524void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4526 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4527 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4528 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4536 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4541 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4543 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4544 [&](
unsigned I) {
return I; },
4545 true, CallStackPos, CallStackCount);
4547 auto SpecialRefCnts =
FS->specialRefCounts();
4552 NameVals.
push_back(SpecialRefCnts.first);
4553 NameVals.
push_back(SpecialRefCnts.second);
4555 for (
auto &RI :
FS->refs())
4558 const bool UseRelBFRecord =
4561 for (
auto &ECI :
FS->calls()) {
4562 NameVals.
push_back(getValueId(ECI.first));
4570 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4581void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4583 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4584 auto VI =
Index->getValueInfo(
V.getGUID());
4585 if (!VI ||
VI.getSummaryList().empty()) {
4591 auto *
Summary =
VI.getSummaryList()[0].get();
4597 auto VTableFuncs =
VS->vTableFuncs();
4598 if (!VTableFuncs.empty())
4601 unsigned SizeBeforeRefs = NameVals.
size();
4602 for (
auto &RI :
VS->refs())
4608 if (VTableFuncs.empty())
4613 for (
auto &
P : VTableFuncs) {
4619 FSModVTableRefsAbbrev);
4626void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4629 bool IsThinLTO =
true;
4631 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4632 IsThinLTO = MD->getZExtValue();
4644 if (
Index->enableSplitLTOUnit())
4646 if (
Index->hasUnifiedLTO())
4656 auto Abbv = std::make_shared<BitCodeAbbrev>();
4662 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4664 for (
const auto &GVI : valueIds()) {
4667 static_cast<uint32_t>(GVI.first >> 32),
4672 if (!
Index->stackIds().empty()) {
4673 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4680 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4683 for (
auto Id :
Index->stackIds()) {
4690 unsigned ContextIdAbbvId = 0;
4693 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4705 ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4709 Abbv = std::make_shared<BitCodeAbbrev>();
4721 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4724 Abbv = std::make_shared<BitCodeAbbrev>();
4736 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4739 Abbv = std::make_shared<BitCodeAbbrev>();
4745 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4748 Abbv = std::make_shared<BitCodeAbbrev>();
4756 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4759 Abbv = std::make_shared<BitCodeAbbrev>();
4764 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4767 Abbv = std::make_shared<BitCodeAbbrev>();
4774 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4776 Abbv = std::make_shared<BitCodeAbbrev>();
4782 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4784 Abbv = std::make_shared<BitCodeAbbrev>();
4791 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4793 Abbv = std::make_shared<BitCodeAbbrev>();
4798 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4813 if (!VI ||
VI.getSummaryList().empty()) {
4819 auto *
Summary =
VI.getSummaryList()[0].get();
4822 FS, [](
unsigned I) {
return I; }, CallStacks);
4827 if (!CallStacks.
empty()) {
4845 if (!VI ||
VI.getSummaryList().empty()) {
4851 auto *
Summary =
VI.getSummaryList()[0].get();
4852 writePerModuleFunctionSummaryRecord(
4853 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4854 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
F,
4855 CallStackPos, CallStackCount);
4861 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4862 FSModVTableRefsAbbrev);
4865 auto *Aliasee =
A.getAliaseeObject();
4868 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4881 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4885 TypeIdCompatibleVtableAbbrev);
4889 if (
Index->getBlockCount())
4897void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4906 auto Abbv = std::make_shared<BitCodeAbbrev>();
4912 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4914 for (
const auto &GVI : valueIds()) {
4917 static_cast<uint32_t>(GVI.first >> 32),
4924 if (!StackIds.empty()) {
4925 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4932 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4934 Vals.
reserve(StackIds.size() * 2);
4935 for (
auto Id : StackIds) {
4943 Abbv = std::make_shared<BitCodeAbbrev>();
4957 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4960 Abbv = std::make_shared<BitCodeAbbrev>();
4967 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4970 Abbv = std::make_shared<BitCodeAbbrev>();
4976 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4978 Abbv = std::make_shared<BitCodeAbbrev>();
4986 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4988 Abbv = std::make_shared<BitCodeAbbrev>();
4999 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5002 if (DecSummaries ==
nullptr)
5004 return DecSummaries->count(GVS);
5018 std::set<GlobalValue::GUID> ReferencedTypeIds;
5032 NameVals.
push_back(S.getOriginalName());
5039 Abbv = std::make_shared<BitCodeAbbrev>();
5044 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5052 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5060 auto *
FS = dyn_cast<FunctionSummary>(S);
5071 return StackIdIndicesToIndex[
I];
5077 if (!CallStacks.
empty()) {
5088 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
5091 DefOrUseGUIDs.
insert(
I.first);
5093 DefOrUseGUIDs.
insert(
VI.getGUID());
5095 auto ValueId = getValueId(
I.first);
5097 SummaryToValueIdMap[S] = *ValueId;
5105 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
5112 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
5115 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
5119 for (
auto &RI :
VS->refs()) {
5120 auto RefValueId = getValueId(RI.getGUID());
5130 MaybeEmitOriginalName(*S);
5134 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
5136 return std::nullopt;
5137 return getValueId(
VI.getGUID());
5140 auto *
FS = cast<FunctionSummary>(S);
5145 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
5149 std::optional<unsigned> ValueID = GetValueId(VI);
5164 return StackIdIndicesToIndex[
I];
5166 false, CallStackPos, CallStackCount);
5170 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
5183 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
5184 for (
auto &RI :
FS->refs()) {
5185 auto RefValueId = getValueId(RI.getGUID());
5189 if (RI.isReadOnly())
5191 else if (RI.isWriteOnly())
5195 NameVals[6] = Count;
5196 NameVals[7] = RORefCnt;
5197 NameVals[8] = WORefCnt;
5199 for (
auto &EI :
FS->calls()) {
5202 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5211 FSCallsProfileAbbrev);
5213 MaybeEmitOriginalName(*S);
5216 for (
auto *AS : Aliases) {
5217 auto AliasValueId = SummaryToValueIdMap[AS];
5224 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
5231 MaybeEmitOriginalName(*AS);
5233 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
5240 if (CfiIndex.
empty())
5243 auto Defs = CfiIndex.
forGuid(GUID);
5246 if (Functions.
empty())
5249 for (
const auto &S : Functions) {
5263 for (
auto &
T : ReferencedTypeIds) {
5264 auto TidIter =
Index.typeIds().equal_range(
T);
5265 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5273 if (
Index.getBlockCount())
5286 auto Abbv = std::make_shared<BitCodeAbbrev>();
5290 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5292 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5295 Abbv = std::make_shared<BitCodeAbbrev>();
5298 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5304void ModuleBitcodeWriter::writeModuleHash(
StringRef View) {
5311 std::array<uint8_t, 20> Hash = Hasher.result();
5312 for (
int Pos = 0; Pos < 20; Pos += 4) {
5325void ModuleBitcodeWriter::write() {
5333 writeModuleVersion();
5342 writeAttributeGroupTable();
5345 writeAttributeTable();
5354 writeModuleConstants();
5357 writeModuleMetadataKinds();
5360 writeModuleMetadata();
5364 writeUseListBlock(
nullptr);
5366 writeOperandBundleTags();
5367 writeSyncScopeNames();
5372 if (!
F.isDeclaration())
5373 writeFunction(
F, FunctionToBitcodeIndex);
5378 writePerModuleGlobalValueSummary();
5380 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5408 unsigned CPUType = ~0U;
5415 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5416 DARWIN_CPU_TYPE_X86 = 7,
5417 DARWIN_CPU_TYPE_ARM = 12,
5418 DARWIN_CPU_TYPE_POWERPC = 18
5423 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5425 CPUType = DARWIN_CPU_TYPE_X86;
5427 CPUType = DARWIN_CPU_TYPE_POWERPC;
5429 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5431 CPUType = DARWIN_CPU_TYPE_ARM;
5435 "Expected header size to be reserved");
5440 unsigned Position = 0;
5448 while (Buffer.
size() & 15)
5455 Stream.
Emit((
unsigned)
'B', 8);
5456 Stream.
Emit((
unsigned)
'C', 8);
5457 Stream.
Emit(0x0, 4);
5458 Stream.
Emit(0xC, 4);
5459 Stream.
Emit(0xE, 4);
5460 Stream.
Emit(0xD, 4);
5478 auto Abbv = std::make_shared<BitCodeAbbrev>();
5481 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5489 assert(!WroteStrtab && !WroteSymtab);
5495 if (M->getModuleInlineAsm().empty())
5499 const Triple TT(M->getTargetTriple());
5501 if (!
T || !
T->hasMCAsmParser())
5523 std::vector<char> Strtab;
5525 Strtab.resize(StrtabBuilder.
getSize());
5529 {Strtab.data(), Strtab.size()});
5540 bool ShouldPreserveUseListOrder,
5549 assert(M.isMaterialized());
5550 Mods.push_back(
const_cast<Module *
>(&M));
5552 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5553 ShouldPreserveUseListOrder, Index,
5554 GenerateHash, ModHash);
5555 ModuleWriter.write();
5562 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5563 ModuleToSummariesForIndex);
5564 IndexWriter.write();
5569 bool ShouldPreserveUseListOrder,
5573 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5575 Writer.writeSymtab();
5576 Writer.writeStrtab();
5578 Triple TT(M.getTargetTriple());
5579 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5597void IndexBitcodeWriter::write() {
5600 writeModuleVersion();
5606 writeCombinedGlobalValueSummary();
5623 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5632class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5642 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5644 ModHash(&ModHash) {}
5649 void writeSimplifiedModuleInfo();
5659void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5671 auto Abbv = std::make_shared<BitCodeAbbrev>();
5674 Abbv->Add(AbbrevOpToUse);
5675 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5677 for (
const auto P :
M.getSourceFileName())
5741void ThinLinkBitcodeWriter::write() {
5744 writeModuleVersion();
5746 writeSimplifiedModuleInfo();
5748 writePerModuleGlobalValueSummary();
5765 assert(M.isMaterialized());
5766 Mods.push_back(
const_cast<Module *
>(&M));
5768 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5770 ThinLinkWriter.write();
5791 switch (
T.getObjectFormat()) {
5793 return "__LLVM,__bitcode";
5818 switch (
T.getObjectFormat()) {
5820 return "__LLVM,__cmdline";
5846 const std::vector<uint8_t> &CmdArgs) {
5851 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5853 for (
auto *GV : UsedGlobals) {
5854 if (GV->getName() !=
"llvm.embedded.module" &&
5855 GV->getName() !=
"llvm.cmdline")
5860 Used->eraseFromParent();
5865 Triple T(M.getTargetTriple());
5894 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5895 assert(Old->hasZeroLiveUses() &&
5896 "llvm.embedded.module can only be used once in llvm.compiler.used");
5898 Old->eraseFromParent();
5900 GV->
setName(
"llvm.embedded.module");
5918 assert(Old->hasZeroLiveUses() &&
5919 "llvm.cmdline can only be used once in llvm.compiler.used");
5921 Old->eraseFromParent();
5927 if (UsedArray.
empty())
5935 NewUsed->setSection(
"llvm.metadata");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIFixedPointType(raw_ostream &Out, const DIFixedPointType *N, AsmWriterContext &WriterCtx)
static void writeDISubrangeType(raw_ostream &Out, const DISubrangeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static cl::opt< bool > CombinedIndexMemProfContext("combined-index-memprof-context", cl::Hidden, cl::init(true), cl::desc(""))
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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"))
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 getNumWords() const
Get the number of words.
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.
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
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.
LLVM Basic Block Representation.
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.
The address of a basic block.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
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...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
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.
LLVM_ABI ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
Type array for a subprogram.
This class represents an Operation in the Expression.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LLVM_ABI DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
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.
Generic tagged DWARF-like metadata node.
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.
Function and variable summary information to aid decisions and implementation of importing.
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
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
Global variable summary information to aid decisions and implementation of importing.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
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.
Tracking metadata reference owned by Metadata.
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...
A class that wrap the SHA1 algorithm.
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.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
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 void finalizeInOrder()
Finalize the string table without reording it.
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority=0)
Add a string to the builder.
LLVM_ABI void write(raw_ostream &OS) const
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
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.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
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.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
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
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
ArrayRef< LinearFrameId > getRadixArray() const
llvm::DenseMap< CallStackId, LinearCallStackId > takeCallStackPos()
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.
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.
@ 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_NO_SANITIZE_COVERAGE
@ ATTR_KIND_DEAD_ON_RETURN
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
@ DW_APPLE_ENUM_KIND_invalid
Enum kind for invalid results.
LLVM_ABI Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
LLVM_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.
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,...
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.
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
AtomicOrdering
Atomic ordering for LLVM's memory model.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
DWARFExpression::Operation Op
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
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,...
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
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.
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Structure to hold a use-list order.
ValID - Represents a reference of a definition of some sort with no type.
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