47 cl::desc(
"Number of metadatas above which we emit an index "
48 "to enable lazy-loading"));
60 CONSTANTS_INTEGER_ABBREV,
61 CONSTANTS_CE_CAST_Abbrev,
62 CONSTANTS_NULL_Abbrev,
66 FUNCTION_INST_BINOP_ABBREV,
67 FUNCTION_INST_BINOP_FLAGS_ABBREV,
68 FUNCTION_INST_CAST_ABBREV,
69 FUNCTION_INST_RET_VOID_ABBREV,
70 FUNCTION_INST_RET_VAL_ABBREV,
71 FUNCTION_INST_UNREACHABLE_ABBREV,
72 FUNCTION_INST_GEP_ABBREV,
77 class BitcodeWriterBase {
88 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
92 void writeModuleVersion();
95 void BitcodeWriterBase::writeModuleVersion() {
101 class ModuleBitcodeWriter :
public BitcodeWriterBase {
128 uint64_t BitcodeStartBit;
133 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
136 unsigned GlobalValueId;
140 uint64_t VSTOffsetPlaceholder = 0;
150 : BitcodeWriterBase(Stream, StrtabBuilder), Buffer(Buffer), M(*M),
151 VE(*M, ShouldPreserveUseListOrder), Index(Index),
152 GenerateHash(GenerateHash), ModHash(ModHash),
153 BitcodeStartBit(Stream.GetCurrentBitNo()) {
159 GlobalValueId = VE.getValues().size();
162 for (
const auto &GUIDSummaryLists : *Index)
164 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
165 if (
auto FS = dyn_cast<FunctionSummary>(Summary.get()))
170 for (
auto &CallEdge :
FS->calls())
171 if (!CallEdge.first.getValue())
172 assignValueId(CallEdge.first.getGUID());
179 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
183 void writeAttributeGroupTable();
184 void writeAttributeTable();
185 void writeTypeTable();
187 void writeValueSymbolTableForwardDecl();
188 void writeModuleInfo();
193 unsigned createDILocationAbbrev();
196 unsigned createGenericDINodeAbbrev();
252 unsigned createNamedMetadataAbbrev();
254 unsigned createMetadataStringsAbbrev();
259 std::vector<unsigned> *MDAbbrevs =
nullptr,
260 std::vector<uint64_t> *IndexPos =
nullptr);
261 void writeModuleMetadata();
262 void writeFunctionMetadata(
const Function &
F);
263 void writeFunctionMetadataAttachment(
const Function &
F);
264 void writeGlobalVariableMetadataAttachment(
const GlobalVariable &GV);
267 void writeModuleMetadataKinds();
268 void writeOperandBundleTags();
269 void writeSyncScopeNames();
270 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
271 void writeModuleConstants();
272 bool pushValueAndType(
const Value *V,
unsigned InstID,
275 void pushValue(
const Value *V,
unsigned InstID,
277 void pushValueSigned(
const Value *V,
unsigned InstID,
279 void writeInstruction(
const Instruction &
I,
unsigned InstID,
282 void writeGlobalValueSymbolTable(
285 void writeUseListBlock(
const Function *
F);
289 void writeBlockInfo();
293 unsigned FSCallsAbbrev,
294 unsigned FSCallsProfileAbbrev,
298 unsigned FSModRefsAbbrev);
299 void writePerModuleGlobalValueSummary();
300 void writeModuleHash(
size_t BlockStartPos);
303 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
306 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
309 assert(VMI != GUIDToValueIdMap.end() &&
310 "GUID does not have assigned value Id");
316 return getValueId(VI.
getGUID());
317 return VE.getValueID(VI.
getValue());
319 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
327 class IndexBitcodeWriter :
public BitcodeWriterBase {
333 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
337 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
340 unsigned GlobalValueId = 0;
348 const std::map<std::string, GVSummaryMapTy>
349 *ModuleToSummariesForIndex =
nullptr)
350 : BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
351 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
356 forEachSummary([&](GVInfo
I) {
357 GUIDToValueIdMap[I.first] = ++GlobalValueId;
362 typedef std::pair<GlobalValue::GUID, GlobalValueSummary *> GVInfo;
367 template<
typename Functor>
368 void forEachSummary(Functor Callback) {
369 if (ModuleToSummariesForIndex) {
370 for (
auto &M : *ModuleToSummariesForIndex)
371 for (
auto &Summary : M.second)
374 for (
auto &Summaries : Index)
375 for (
auto &Summary : Summaries.second.SummaryList)
376 Callback({Summaries.first, Summary.get()});
384 template <
typename Functor>
void forEachModule(Functor Callback) {
385 if (ModuleToSummariesForIndex) {
386 for (
const auto &M : *ModuleToSummariesForIndex) {
387 const auto &MPI = Index.modulePaths().find(M.first);
388 if (MPI == Index.modulePaths().end()) {
392 assert(ModuleToSummariesForIndex->size() == 1);
398 for (
const auto &MPSE : Index.modulePaths())
407 void writeModStrings();
408 void writeCombinedGlobalValueSummary();
411 auto VMI = GUIDToValueIdMap.find(ValGUID);
412 if (VMI == GUIDToValueIdMap.end())
416 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
444 case Instruction::Sub:
446 case Instruction::Mul:
449 case Instruction::FDiv:
452 case Instruction::FRem:
498 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
510 case Attribute::Alignment:
512 case Attribute::AllocSize:
514 case Attribute::AlwaysInline:
516 case Attribute::ArgMemOnly:
518 case Attribute::Builtin:
520 case Attribute::ByVal:
524 case Attribute::InAlloca:
528 case Attribute::InaccessibleMemOnly:
530 case Attribute::InaccessibleMemOrArgMemOnly:
532 case Attribute::InlineHint:
534 case Attribute::InReg:
538 case Attribute::MinSize:
540 case Attribute::Naked:
542 case Attribute::Nest:
546 case Attribute::NoBuiltin:
548 case Attribute::NoCapture:
550 case Attribute::NoDuplicate:
552 case Attribute::NoImplicitFloat:
554 case Attribute::NoInline:
556 case Attribute::NoRecurse:
558 case Attribute::NonLazyBind:
560 case Attribute::NonNull:
562 case Attribute::Dereferenceable:
564 case Attribute::DereferenceableOrNull:
566 case Attribute::NoRedZone:
568 case Attribute::NoReturn:
570 case Attribute::NoUnwind:
572 case Attribute::OptimizeForSize:
574 case Attribute::OptimizeNone:
576 case Attribute::ReadNone:
578 case Attribute::ReadOnly:
580 case Attribute::Returned:
582 case Attribute::ReturnsTwice:
584 case Attribute::SExt:
586 case Attribute::Speculatable:
588 case Attribute::StackAlignment:
590 case Attribute::StackProtect:
592 case Attribute::StackProtectReq:
594 case Attribute::StackProtectStrong:
596 case Attribute::SafeStack:
598 case Attribute::StructRet:
600 case Attribute::SanitizeAddress:
602 case Attribute::SanitizeThread:
604 case Attribute::SanitizeMemory:
606 case Attribute::SwiftError:
608 case Attribute::SwiftSelf:
610 case Attribute::UWTable:
612 case Attribute::WriteOnly:
614 case Attribute::ZExt:
625 void ModuleBitcodeWriter::writeAttributeGroupTable() {
626 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
627 VE.getAttributeGroups();
628 if (AttrGrps.empty())
return;
634 unsigned AttrListIndex = Pair.first;
636 Record.
push_back(VE.getAttributeGroupID(Pair));
640 if (Attr.isEnumAttribute()) {
643 }
else if (Attr.isIntAttribute()) {
668 void ModuleBitcodeWriter::writeAttributeTable() {
669 const std::vector<AttributeList> &
Attrs = VE.getAttributeLists();
670 if (Attrs.empty())
return;
675 for (
unsigned i = 0, e = Attrs.size(); i != e; ++i) {
680 Record.
push_back(VE.getAttributeGroupID({i, AS}));
691 void ModuleBitcodeWriter::writeTypeTable() {
697 uint64_t NumBits = VE.computeBitsRequiredForTypeIndicies();
700 auto Abbv = std::make_shared<BitCodeAbbrev>();
704 unsigned PtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
707 Abbv = std::make_shared<BitCodeAbbrev>();
713 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
716 Abbv = std::make_shared<BitCodeAbbrev>();
722 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
725 Abbv = std::make_shared<BitCodeAbbrev>();
729 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
732 Abbv = std::make_shared<BitCodeAbbrev>();
738 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
741 Abbv = std::make_shared<BitCodeAbbrev>();
746 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
754 for (
unsigned i = 0, e = TypeList.size(); i != e; ++i) {
755 Type *
T = TypeList[i];
771 case Type::IntegerTyID:
776 case Type::PointerTyID: {
783 if (AddressSpace == 0) AbbrevToUse = PtrAbbrev;
786 case Type::FunctionTyID: {
792 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i)
794 AbbrevToUse = FunctionAbbrev;
797 case Type::StructTyID: {
808 AbbrevToUse = StructAnonAbbrev;
814 AbbrevToUse = StructNamedAbbrev;
824 case Type::ArrayTyID: {
830 AbbrevToUse = ArrayAbbrev;
833 case Type::VectorTyID: {
844 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
853 case GlobalValue::ExternalLinkage:
855 case GlobalValue::WeakAnyLinkage:
857 case GlobalValue::AppendingLinkage:
859 case GlobalValue::InternalLinkage:
861 case GlobalValue::LinkOnceAnyLinkage:
863 case GlobalValue::ExternalWeakLinkage:
865 case GlobalValue::CommonLinkage:
867 case GlobalValue::PrivateLinkage:
869 case GlobalValue::WeakODRLinkage:
871 case GlobalValue::LinkOnceODRLinkage:
873 case GlobalValue::AvailableExternallyLinkage:
885 uint64_t RawFlags = 0;
888 RawFlags |= (Flags.
Live << 1);
892 RawFlags = (RawFlags << 4) | Flags.
Linkage;
899 case GlobalValue::DefaultVisibility:
return 0;
900 case GlobalValue::HiddenVisibility:
return 1;
901 case GlobalValue::ProtectedVisibility:
return 2;
908 case GlobalValue::DefaultStorageClass:
return 0;
909 case GlobalValue::DLLImportStorageClass:
return 1;
910 case GlobalValue::DLLExportStorageClass:
return 2;
917 case GlobalVariable::NotThreadLocal:
return 0;
918 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
919 case GlobalVariable::LocalDynamicTLSModel:
return 2;
920 case GlobalVariable::InitialExecTLSModel:
return 3;
921 case GlobalVariable::LocalExecTLSModel:
return 4;
930 case Comdat::ExactMatch:
932 case Comdat::Largest:
934 case Comdat::NoDuplicates:
936 case Comdat::SameSize:
945 case GlobalValue::UnnamedAddr::Local:
return 2;
946 case GlobalValue::UnnamedAddr::Global:
return 1;
951 size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
954 return StrtabBuilder.
add(Str);
957 void ModuleBitcodeWriter::writeComdats() {
959 for (
const Comdat *
C : VE.getComdats()) {
972 void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
977 auto Abbv = std::make_shared<BitCodeAbbrev>();
983 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1000 for (
char C : Str) {
1002 isChar6 = BitCodeAbbrevOp::isChar6(
C);
1003 if ((
unsigned char)
C & 128)
1015 void ModuleBitcodeWriter::writeModuleInfo() {
1029 std::map<std::string, unsigned> SectionMap;
1030 std::map<std::string, unsigned> GCMap;
1031 unsigned MaxAlignment = 0;
1032 unsigned MaxGlobalType = 0;
1034 MaxAlignment =
std::max(MaxAlignment, GV.getAlignment());
1035 MaxGlobalType =
std::max(MaxGlobalType, VE.getTypeID(GV.getValueType()));
1036 if (GV.hasSection()) {
1038 unsigned &Entry = SectionMap[GV.getSection()];
1042 Entry = SectionMap.size();
1047 MaxAlignment =
std::max(MaxAlignment,
F.getAlignment());
1048 if (
F.hasSection()) {
1050 unsigned &Entry = SectionMap[
F.getSection()];
1054 Entry = SectionMap.size();
1059 unsigned &Entry = GCMap[
F.getGC()];
1063 Entry = GCMap.size();
1069 unsigned SimpleGVarAbbrev = 0;
1070 if (!M.global_empty()) {
1072 auto Abbv = std::make_shared<BitCodeAbbrev>();
1083 if (MaxAlignment == 0)
1086 unsigned MaxEncAlignment =
Log2_32(MaxAlignment)+1;
1090 if (SectionMap.empty())
1096 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1110 auto Abbv = std::make_shared<BitCodeAbbrev>();
1113 Abbv->Add(AbbrevOpToUse);
1114 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1116 for (
const auto P : M.getSourceFileName())
1126 unsigned AbbrevToUse = 0;
1132 Vals.
push_back(addToStrtab(GV.getName()));
1134 Vals.
push_back(VE.getTypeID(GV.getValueType()));
1135 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1137 (VE.getValueID(GV.getInitializer()) + 1));
1140 Vals.
push_back(GV.hasSection() ? SectionMap[GV.getSection()] : 0);
1141 if (GV.isThreadLocal() ||
1142 GV.getVisibility() != GlobalValue::DefaultVisibility ||
1144 GV.isExternallyInitialized() ||
1145 GV.getDLLStorageClass() != GlobalValue::DefaultStorageClass ||
1147 GV.hasAttributes()) {
1151 Vals.
push_back(GV.isExternallyInitialized());
1153 Vals.
push_back(GV.hasComdat() ? VE.getComdatID(GV.getComdat()) : 0);
1155 auto AL = GV.getAttributesAsList(AttributeList::FunctionIndex);
1156 Vals.
push_back(VE.getAttributeListID(AL));
1158 AbbrevToUse = SimpleGVarAbbrev;
1173 Vals.
push_back(VE.getTypeID(
F.getFunctionType()));
1177 Vals.
push_back(VE.getAttributeListID(
F.getAttributes()));
1179 Vals.
push_back(
F.hasSection() ? SectionMap[
F.getSection()] : 0);
1183 Vals.
push_back(
F.hasPrologueData() ? (VE.getValueID(
F.getPrologueData()) + 1)
1186 Vals.
push_back(
F.hasComdat() ? VE.getComdatID(
F.getComdat()) : 0);
1187 Vals.
push_back(
F.hasPrefixData() ? (VE.getValueID(
F.getPrefixData()) + 1)
1190 F.hasPersonalityFn() ? (VE.getValueID(
F.getPersonalityFn()) + 1) : 0);
1192 unsigned AbbrevToUse = 0;
1203 Vals.
push_back(VE.getTypeID(
A.getValueType()));
1204 Vals.
push_back(
A.getType()->getAddressSpace());
1205 Vals.
push_back(VE.getValueID(
A.getAliasee()));
1211 unsigned AbbrevToUse = 0;
1222 Vals.
push_back(VE.getTypeID(
I.getValueType()));
1223 Vals.
push_back(
I.getType()->getAddressSpace());
1224 Vals.
push_back(VE.getValueID(
I.getResolver()));
1231 writeValueSymbolTableForwardDecl();
1237 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1238 if (OBO->hasNoSignedWrap())
1240 if (OBO->hasNoUnsignedWrap())
1242 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1245 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1246 if (FPMO->hasUnsafeAlgebra())
1247 Flags |= FastMathFlags::UnsafeAlgebra;
1248 if (FPMO->hasNoNaNs())
1249 Flags |= FastMathFlags::NoNaNs;
1250 if (FPMO->hasNoInfs())
1251 Flags |= FastMathFlags::NoInfs;
1252 if (FPMO->hasNoSignedZeros())
1253 Flags |= FastMathFlags::NoSignedZeros;
1254 if (FPMO->hasAllowReciprocal())
1255 Flags |= FastMathFlags::AllowReciprocal;
1256 if (FPMO->hasAllowContract())
1257 Flags |= FastMathFlags::AllowContract;
1263 void ModuleBitcodeWriter::writeValueAsMetadata(
1278 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1279 "Unexpected function-local metadata");
1280 Record.
push_back(VE.getMetadataOrNullID(MD));
1288 unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1291 auto Abbv = std::make_shared<BitCodeAbbrev>();
1305 Abbrev = createDILocationAbbrev();
1310 Record.
push_back(VE.getMetadataID(N->getScope()));
1311 Record.
push_back(VE.getMetadataOrNullID(N->getInlinedAt()));
1317 unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1320 auto Abbv = std::make_shared<BitCodeAbbrev>();
1335 Abbrev = createGenericDINodeAbbrev();
1350 return I < 0 ? ~(U << 1) : U << 1;
1398 Record.
push_back(VE.getMetadataOrNullID(N->getBaseType()));
1403 Record.
push_back(VE.getMetadataOrNullID(N->getExtraData()));
1407 if (
const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
1408 Record.
push_back(*DWARFAddressSpace + 1);
1419 const unsigned IsNotUsedInOldTypeRef = 0x2;
1444 const unsigned HasNoOldTypeRefs = 0x2;
1497 uint64_t HasUnitFlag = 1 << 1;
1500 Record.
push_back(VE.getMetadataOrNullID(N->getRawName()));
1501 Record.
push_back(VE.getMetadataOrNullID(N->getRawLinkageName()));
1504 Record.
push_back(VE.getMetadataOrNullID(N->getType()));
1508 Record.
push_back(VE.getMetadataOrNullID(N->getContainingType()));
1513 Record.
push_back(VE.getMetadataOrNullID(N->getRawUnit()));
1514 Record.
push_back(VE.getMetadataOrNullID(N->getTemplateParams().
get()));
1515 Record.
push_back(VE.getMetadataOrNullID(N->getDeclaration()));
1516 Record.
push_back(VE.getMetadataOrNullID(N->getVariables().
get()));
1517 Record.
push_back(N->getThisAdjustment());
1518 Record.
push_back(VE.getMetadataOrNullID(N->getThrownTypes().
get()));
1624 const uint64_t
Version = 1 << 1;
1658 const uint64_t HasAlignmentFlag = 1 << 1;
1677 const uint64_t Version = 3 << 1;
1727 unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
1728 auto Abbv = std::make_shared<BitCodeAbbrev>();
1735 void ModuleBitcodeWriter::writeNamedMetadata(
1737 if (M.named_metadata_empty())
1740 unsigned Abbrev = createNamedMetadataAbbrev();
1741 for (
const NamedMDNode &NMD : M.named_metadata()) {
1756 unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
1757 auto Abbv = std::make_shared<BitCodeAbbrev>();
1769 void ModuleBitcodeWriter::writeMetadataStrings(
1771 if (Strings.
empty())
1783 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
1792 Blob.
append(cast<MDString>(MD)->getString());
1801 #define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
1802 #include "llvm/IR/Metadata.def"
1806 void ModuleBitcodeWriter::writeMetadataRecords(
1808 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
1813 #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
1814 #include "llvm/IR/Metadata.def"
1819 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
1825 #define HANDLE_MDNODE_LEAF(CLASS) \
1826 case Metadata::CLASS##Kind: \
1828 write##CLASS(cast<CLASS>(N), Record, \
1829 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
1831 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
1833 #include "llvm/IR/Metadata.def"
1836 writeValueAsMetadata(cast<ValueAsMetadata>(MD), Record);
1840 void ModuleBitcodeWriter::writeModuleMetadata() {
1841 if (!VE.hasMDs() && M.named_metadata_empty())
1849 std::vector<unsigned> MDAbbrevs;
1852 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1853 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1854 createGenericDINodeAbbrev();
1856 auto Abbv = std::make_shared<BitCodeAbbrev>();
1860 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1862 Abbv = std::make_shared<BitCodeAbbrev>();
1866 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1869 writeMetadataStrings(VE.getMDStrings(), Record);
1873 if (VE.getNonMDStrings().size() > IndexThreshold) {
1878 uint64_t Vals[] = {0, 0};
1888 std::vector<uint64_t> IndexPos;
1889 IndexPos.reserve(VE.getNonMDStrings().size());
1892 writeMetadataRecords(VE.getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
1894 if (VE.getNonMDStrings().size() > IndexThreshold) {
1903 uint64_t PreviousValue = IndexOffsetRecordBitPos;
1904 for (
auto &Elt : IndexPos) {
1905 auto EltDelta = Elt - PreviousValue;
1906 PreviousValue = Elt;
1915 writeNamedMetadata(Record);
1917 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
1920 pushGlobalMetadataAttachment(Record, GO);
1924 if (
F.isDeclaration() &&
F.hasMetadata())
1925 AddDeclAttachedMetadata(
F);
1929 if (GV.hasMetadata())
1930 AddDeclAttachedMetadata(GV);
1935 void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
1941 writeMetadataStrings(VE.getMDStrings(), Record);
1942 writeMetadataRecords(VE.getNonMDStrings(), Record);
1946 void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
1951 for (
const auto &
I : MDs) {
1953 Record.
push_back(VE.getMetadataID(
I.second));
1957 void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &F) {
1963 pushGlobalMetadataAttachment(Record, F);
1974 I.getAllMetadataOtherThanDebugLoc(MDs);
1977 if (MDs.
empty())
continue;
1981 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
1983 Record.
push_back(VE.getMetadataID(MDs[i].second));
1992 void ModuleBitcodeWriter::writeModuleMetadataKinds() {
1998 M.getMDKindNames(Names);
2000 if (Names.
empty())
return;
2004 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2016 void ModuleBitcodeWriter::writeOperandBundleTags() {
2024 M.getOperandBundleTags(Tags);
2033 for (
auto Tag : Tags) {
2043 void ModuleBitcodeWriter::writeSyncScopeNames() {
2045 M.getContext().getSyncScopeNames(SSNs);
2052 for (
auto SSN : SSNs) {
2053 Record.
append(SSN.begin(), SSN.end());
2062 if ((int64_t)V >= 0)
2068 void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2070 if (FirstVal == LastVal)
return;
2074 unsigned AggregateAbbrev = 0;
2075 unsigned String8Abbrev = 0;
2076 unsigned CString7Abbrev = 0;
2077 unsigned CString6Abbrev = 0;
2081 auto Abbv = std::make_shared<BitCodeAbbrev>();
2085 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2088 Abbv = std::make_shared<BitCodeAbbrev>();
2092 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2094 Abbv = std::make_shared<BitCodeAbbrev>();
2098 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2100 Abbv = std::make_shared<BitCodeAbbrev>();
2104 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2110 Type *LastTy =
nullptr;
2111 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2112 const Value *V = Vals[i].first;
2118 CONSTANTS_SETTYPE_ABBREV);
2122 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2123 Record.
push_back(
unsigned(IA->hasSideEffects()) |
2124 unsigned(IA->isAlignStack()) << 1 |
2125 unsigned(IA->getDialect()&1) << 2);
2128 const std::string &AsmStr = IA->getAsmString();
2130 Record.
append(AsmStr.begin(), AsmStr.end());
2133 const std::string &ConstraintStr = IA->getConstraintString();
2135 Record.
append(ConstraintStr.begin(), ConstraintStr.end());
2141 unsigned Code = -1U;
2142 unsigned AbbrevToUse = 0;
2145 }
else if (isa<UndefValue>(C)) {
2147 }
else if (
const ConstantInt *IV = dyn_cast<ConstantInt>(C)) {
2148 if (IV->getBitWidth() <= 64) {
2149 uint64_t V = IV->getSExtValue();
2152 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2158 unsigned NWords = IV->getValue().getActiveWords();
2159 const uint64_t *RawWords = IV->getValue().getRawData();
2160 for (
unsigned i = 0; i != NWords; ++i) {
2165 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2167 Type *Ty = CFP->getType();
2169 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2173 APInt api = CFP->getValueAPF().bitcastToAPInt();
2175 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2178 APInt api = CFP->getValueAPF().bitcastToAPInt();
2183 assert (0 &&
"Unknown FP type!");
2185 }
else if (isa<ConstantDataSequential>(C) &&
2186 cast<ConstantDataSequential>(C)->isString()) {
2196 AbbrevToUse = String8Abbrev;
2200 for (
unsigned i = 0; i != NumElts; ++i) {
2203 isCStr7 &= (V & 128) == 0;
2205 isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
2209 AbbrevToUse = CString6Abbrev;
2211 AbbrevToUse = CString7Abbrev;
2213 dyn_cast<ConstantDataSequential>(C)) {
2215 Type *EltTy = CDS->getType()->getElementType();
2216 if (isa<IntegerType>(EltTy)) {
2217 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2218 Record.
push_back(CDS->getElementAsInteger(i));
2220 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2222 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2224 }
else if (isa<ConstantAggregate>(C)) {
2228 AbbrevToUse = AggregateAbbrev;
2229 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2230 switch (
CE->getOpcode()) {
2232 if (Instruction::isCast(
CE->getOpcode())) {
2237 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2239 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2249 case Instruction::GetElementPtr: {
2251 const auto *GO = cast<GEPOperator>(
C);
2252 Record.
push_back(VE.getTypeID(GO->getSourceElementType()));
2255 Record.
push_back((*Idx << 1) | GO->isInBounds());
2256 }
else if (GO->isInBounds())
2258 for (
unsigned i = 0, e =
CE->getNumOperands(); i != e; ++i) {
2270 case Instruction::ExtractElement:
2277 case Instruction::InsertElement:
2284 case Instruction::ShuffleVector:
2299 case Instruction::ICmp:
2300 case Instruction::FCmp:
2308 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
2310 Record.
push_back(VE.getTypeID(BA->getFunction()->getType()));
2311 Record.
push_back(VE.getValueID(BA->getFunction()));
2312 Record.
push_back(VE.getGlobalBasicBlockID(BA->getBasicBlock()));
2319 Stream.
EmitRecord(Code, Record, AbbrevToUse);
2326 void ModuleBitcodeWriter::writeModuleConstants() {
2331 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2332 if (!isa<GlobalValue>(Vals[i].first)) {
2333 writeConstants(i, Vals.size(),
true);
2347 bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2349 unsigned ValID = VE.getValueID(V);
2352 if (ValID >= InstID) {
2368 for (
auto &Input : Bundle.Inputs)
2369 pushValueAndType(Input, InstID, Record);
2378 void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2380 unsigned ValID = VE.getValueID(V);
2384 void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2386 unsigned ValID = VE.getValueID(V);
2387 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2392 void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2396 unsigned AbbrevToUse = 0;
2397 VE.setInstructionID(&I);
2400 if (Instruction::isCast(I.
getOpcode())) {
2402 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2403 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2407 assert(isa<BinaryOperator>(I) &&
"Unknown instruction!");
2409 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2410 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2415 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2416 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2422 case Instruction::GetElementPtr: {
2424 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2425 auto &GEPInst = cast<GetElementPtrInst>(
I);
2427 Vals.
push_back(VE.getTypeID(GEPInst.getSourceElementType()));
2429 pushValueAndType(I.
getOperand(i), InstID, Vals);
2432 case Instruction::ExtractValue: {
2434 pushValueAndType(I.
getOperand(0), InstID, Vals);
2436 Vals.
append(EVI->idx_begin(), EVI->idx_end());
2439 case Instruction::InsertValue: {
2441 pushValueAndType(I.
getOperand(0), InstID, Vals);
2442 pushValueAndType(I.
getOperand(1), InstID, Vals);
2444 Vals.
append(IVI->idx_begin(), IVI->idx_end());
2449 pushValueAndType(I.
getOperand(1), InstID, Vals);
2451 pushValueAndType(I.
getOperand(0), InstID, Vals);
2453 case Instruction::ExtractElement:
2455 pushValueAndType(I.
getOperand(0), InstID, Vals);
2456 pushValueAndType(I.
getOperand(1), InstID, Vals);
2458 case Instruction::InsertElement:
2460 pushValueAndType(I.
getOperand(0), InstID, Vals);
2462 pushValueAndType(I.
getOperand(2), InstID, Vals);
2464 case Instruction::ShuffleVector:
2466 pushValueAndType(I.
getOperand(0), InstID, Vals);
2470 case Instruction::ICmp:
2471 case Instruction::FCmp: {
2474 pushValueAndType(I.
getOperand(0), InstID, Vals);
2476 Vals.
push_back(cast<CmpInst>(I).getPredicate());
2487 if (NumOperands == 0)
2488 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
2489 else if (NumOperands == 1) {
2490 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2491 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
2493 for (
unsigned i = 0, e = NumOperands; i != e; ++i)
2494 pushValueAndType(I.
getOperand(i), InstID, Vals);
2498 case Instruction::Br:
2516 for (
auto Case : SI.
cases()) {
2517 Vals.
push_back(VE.getValueID(Case.getCaseValue()));
2518 Vals.
push_back(VE.getValueID(Case.getCaseSuccessor()));
2522 case Instruction::IndirectBr:
2531 case Instruction::Invoke: {
2537 writeOperandBundles(II, InstID);
2546 pushValueAndType(Callee, InstID, Vals);
2549 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i)
2556 pushValueAndType(I.
getOperand(i), InstID, Vals);
2560 case Instruction::Resume:
2562 pushValueAndType(I.
getOperand(0), InstID, Vals);
2564 case Instruction::CleanupRet: {
2566 const auto &CRI = cast<CleanupReturnInst>(
I);
2567 pushValue(CRI.getCleanupPad(), InstID, Vals);
2568 if (CRI.hasUnwindDest())
2569 Vals.
push_back(VE.getValueID(CRI.getUnwindDest()));
2572 case Instruction::CatchRet: {
2574 const auto &CRI = cast<CatchReturnInst>(
I);
2575 pushValue(CRI.getCatchPad(), InstID, Vals);
2576 Vals.
push_back(VE.getValueID(CRI.getSuccessor()));
2579 case Instruction::CleanupPad:
2580 case Instruction::CatchPad: {
2581 const auto &FuncletPad = cast<FuncletPadInst>(
I);
2584 pushValue(FuncletPad.getParentPad(), InstID, Vals);
2586 unsigned NumArgOperands = FuncletPad.getNumArgOperands();
2588 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
2589 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
2592 case Instruction::CatchSwitch: {
2594 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
2596 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
2598 unsigned NumHandlers = CatchSwitch.getNumHandlers();
2600 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
2601 Vals.
push_back(VE.getValueID(CatchPadBB));
2603 if (CatchSwitch.hasUnwindDest())
2604 Vals.
push_back(VE.getValueID(CatchSwitch.getUnwindDest()));
2607 case Instruction::Unreachable:
2609 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
2612 case Instruction::PHI: {
2613 const PHINode &PN = cast<PHINode>(
I);
2625 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
2630 case Instruction::LandingPad: {
2641 pushValueAndType(LP.
getClause(I), InstID, Vals);
2646 case Instruction::Alloca: {
2654 "not enough bits for maximum alignment");
2655 assert(AlignRecord < 1 << 5 &&
"alignment greater than 1 << 64");
2657 AlignRecord |= 1 << 6;
2664 if (cast<LoadInst>(I).
isAtomic()) {
2666 pushValueAndType(I.
getOperand(0), InstID, Vals);
2669 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2670 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
2675 if (cast<LoadInst>(I).
isAtomic()) {
2677 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
2685 pushValueAndType(I.
getOperand(1), InstID, Vals);
2686 pushValueAndType(I.
getOperand(0), InstID, Vals);
2689 if (cast<StoreInst>(I).
isAtomic()) {
2692 getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
2695 case Instruction::AtomicCmpXchg:
2697 pushValueAndType(I.
getOperand(0), InstID, Vals);
2698 pushValueAndType(I.
getOperand(1), InstID, Vals);
2704 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
2709 case Instruction::AtomicRMW:
2711 pushValueAndType(I.
getOperand(0), InstID, Vals);
2718 getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
2720 case Instruction::Fence:
2723 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
2730 writeOperandBundles(&CI, InstID);
2750 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2752 if (FTy->getParamType(i)->isLabelTy())
2759 if (FTy->isVarArg()) {
2766 case Instruction::VAArg:
2780 void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
2786 VSTOffset -= bitcodeStartBit();
2787 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
2791 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
2795 auto Abbv = std::make_shared<BitCodeAbbrev>();
2799 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2804 if (F.isDeclaration())
2807 Record[0] = VE.getValueID(&F);
2811 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
2812 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
2816 Record[1] = BitcodeIndex / 32 + 1;
2825 void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
2840 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2846 if (isa<BasicBlock>(
Name.getValue())) {
2849 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2853 AbbrevToUse = VST_ENTRY_6_ABBREV;
2855 AbbrevToUse = VST_ENTRY_7_ABBREV;
2858 for (
const auto P :
Name.getKey())
2862 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
2869 void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
2870 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
2872 if (isa<BasicBlock>(Order.V))
2878 Record.
push_back(VE.getValueID(Order.V));
2882 void ModuleBitcodeWriter::writeUseListBlock(
const Function *F) {
2883 assert(VE.shouldPreserveUseListOrder() &&
2884 "Expected to be preserving use-list order");
2886 auto hasMore = [&]() {
2887 return !VE.UseListOrders.empty() && VE.UseListOrders.back().F ==
F;
2895 writeUseList(std::move(VE.UseListOrders.back()));
2896 VE.UseListOrders.pop_back();
2902 void ModuleBitcodeWriter::writeFunction(
2910 VE.incorporateFunction(F);
2916 Vals.
push_back(VE.getBasicBlocks().size());
2921 unsigned CstStart, CstEnd;
2922 VE.getFunctionConstantRange(CstStart, CstEnd);
2923 writeConstants(CstStart, CstEnd,
false);
2926 writeFunctionMetadata(F);
2929 unsigned InstID = CstEnd;
2938 writeInstruction(*I, InstID, Vals);
2959 Vals.
push_back(VE.getMetadataOrNullID(DL->getScope()));
2960 Vals.
push_back(VE.getMetadataOrNullID(DL->getInlinedAt()));
2969 writeFunctionLevelValueSymbolTable(*Symtab);
2971 if (NeedsMetadataAttachment)
2972 writeFunctionMetadataAttachment(F);
2973 if (VE.shouldPreserveUseListOrder())
2974 writeUseListBlock(&F);
2980 void ModuleBitcodeWriter::writeBlockInfo() {
2987 auto Abbv = std::make_shared<BitCodeAbbrev>();
2998 auto Abbv = std::make_shared<BitCodeAbbrev>();
3008 auto Abbv = std::make_shared<BitCodeAbbrev>();
3018 auto Abbv = std::make_shared<BitCodeAbbrev>();
3024 VST_BBENTRY_6_ABBREV)
3031 auto Abbv = std::make_shared<BitCodeAbbrev>();
3034 VE.computeBitsRequiredForTypeIndicies()));
3036 CONSTANTS_SETTYPE_ABBREV)
3041 auto Abbv = std::make_shared<BitCodeAbbrev>();
3045 CONSTANTS_INTEGER_ABBREV)
3050 auto Abbv = std::make_shared<BitCodeAbbrev>();
3054 VE.computeBitsRequiredForTypeIndicies()));
3058 CONSTANTS_CE_CAST_Abbrev)
3062 auto Abbv = std::make_shared<BitCodeAbbrev>();
3065 CONSTANTS_NULL_Abbrev)
3072 auto Abbv = std::make_shared<BitCodeAbbrev>();
3076 VE.computeBitsRequiredForTypeIndicies()));
3080 FUNCTION_INST_LOAD_ABBREV)
3084 auto Abbv = std::make_shared<BitCodeAbbrev>();
3090 FUNCTION_INST_BINOP_ABBREV)
3094 auto Abbv = std::make_shared<BitCodeAbbrev>();
3101 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3105 auto Abbv = std::make_shared<BitCodeAbbrev>();
3109 VE.computeBitsRequiredForTypeIndicies()));
3112 FUNCTION_INST_CAST_ABBREV)
3117 auto Abbv = std::make_shared<BitCodeAbbrev>();
3120 FUNCTION_INST_RET_VOID_ABBREV)
3124 auto Abbv = std::make_shared<BitCodeAbbrev>();
3128 FUNCTION_INST_RET_VAL_ABBREV)
3132 auto Abbv = std::make_shared<BitCodeAbbrev>();
3135 FUNCTION_INST_UNREACHABLE_ABBREV)
3139 auto Abbv = std::make_shared<BitCodeAbbrev>();
3147 FUNCTION_INST_GEP_ABBREV)
3156 void IndexBitcodeWriter::writeModStrings() {
3162 auto Abbv = std::make_shared<BitCodeAbbrev>();
3167 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3170 Abbv = std::make_shared<BitCodeAbbrev>();
3175 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3178 Abbv = std::make_shared<BitCodeAbbrev>();
3183 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3186 Abbv = std::make_shared<BitCodeAbbrev>();
3193 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3197 [&](
const StringMapEntry<std::pair<uint64_t, ModuleHash>> &MPSE) {
3199 const auto &
Value = MPSE.getValue();
3201 unsigned AbbrevToUse = Abbrev8Bit;
3203 AbbrevToUse = Abbrev6Bit;
3205 AbbrevToUse = Abbrev7Bit;
3235 auto WriteVFuncIdVec = [&](uint64_t Ty,
3240 for (
auto &VF : VFs) {
3252 auto WriteConstVCallVec = [&](uint64_t Ty,
3254 for (
auto &
VC : VCs) {
3258 Record.
insert(Record.
end(),
VC.Args.begin(),
VC.Args.end());
3270 void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord(
3272 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
3283 for (
auto &RI : FS->
refs())
3284 NameVals.
push_back(VE.getValueID(RI.getValue()));
3287 for (
auto &ECI : FS->
calls()) {
3288 NameVals.
push_back(getValueId(ECI.first));
3290 NameVals.
push_back(static_cast<uint8_t>(ECI.second.Hotness));
3293 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3304 void ModuleBitcodeWriter::writeModuleLevelReferences(
3306 unsigned FSModRefsAbbrev) {
3307 auto VI = Index->getValueInfo(GlobalValue::getGUID(V.
getName()));
3319 unsigned SizeBeforeRefs = NameVals.
size();
3320 for (
auto &RI : VS->
refs())
3321 NameVals.
push_back(VE.getValueID(RI.getValue()));
3338 void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() {
3341 bool IsThinLTO =
true;
3343 mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(
"ThinLTO")))
3344 IsThinLTO = MD->getZExtValue();
3351 if (Index->begin() == Index->end()) {
3356 for (
const auto &GVI : valueIds()) {
3362 auto Abbv = std::make_shared<BitCodeAbbrev>();
3371 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3374 Abbv = std::make_shared<BitCodeAbbrev>();
3383 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3386 Abbv = std::make_shared<BitCodeAbbrev>();
3392 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3395 Abbv = std::make_shared<BitCodeAbbrev>();
3400 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3419 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.getValueID(&F),
3420 FSCallsAbbrev, FSCallsProfileAbbrev,
F);
3426 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev);
3429 auto *Aliasee =
A.getBaseObject();
3430 if (!Aliasee->hasName())
3433 auto AliasId = VE.getValueID(&
A);
3434 auto AliaseeId = VE.getValueID(Aliasee);
3436 auto *Summary = Index->getGlobalValueSummary(
A);
3448 void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
3452 for (
const auto &GVI : valueIds()) {
3458 auto Abbv = std::make_shared<BitCodeAbbrev>();
3468 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3471 Abbv = std::make_shared<BitCodeAbbrev>();
3481 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3484 Abbv = std::make_shared<BitCodeAbbrev>();
3491 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3494 Abbv = std::make_shared<BitCodeAbbrev>();
3500 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3514 if (!GlobalValue::isLocalLinkage(S.linkage()))
3516 NameVals.
push_back(S.getOriginalName());
3521 forEachSummary([&](GVInfo I) {
3525 auto ValueId = getValueId(I.first);
3527 SummaryToValueIdMap[S] = *ValueId;
3529 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
3536 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
3540 for (
auto &RI : VS->
refs()) {
3541 auto RefValueId = getValueId(RI.getGUID());
3551 MaybeEmitOriginalName(*S);
3555 auto *FS = cast<FunctionSummary>(S);
3566 for (
auto &RI : FS->
refs()) {
3567 auto RefValueId = getValueId(RI.getGUID());
3573 NameVals[4] = Count;
3575 bool HasProfileData =
false;
3576 for (
auto &EI : FS->
calls()) {
3582 for (
auto &EI : FS->
calls()) {
3586 auto CallValueId = getValueId(GUID);
3591 GUID = Index.getGUIDFromOriginalID(GUID);
3594 CallValueId = getValueId(GUID);
3600 NameVals.
push_back(static_cast<uint8_t>(EI.second.Hotness));
3603 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3610 MaybeEmitOriginalName(*S);
3613 for (
auto *AS : Aliases) {
3614 auto AliasValueId = SummaryToValueIdMap[AS];
3617 NameVals.
push_back(Index.getModuleId(AS->modulePath()));
3619 auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
3626 MaybeEmitOriginalName(*AS);
3629 if (!Index.cfiFunctionDefs().empty()) {
3630 for (
auto &S : Index.cfiFunctionDefs()) {
3638 if (!Index.cfiFunctionDecls().empty()) {
3639 for (
auto &S : Index.cfiFunctionDecls()) {
3656 auto Abbv = std::make_shared<BitCodeAbbrev>();
3660 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3662 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
3665 Abbv = std::make_shared<BitCodeAbbrev>();
3668 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3674 void ModuleBitcodeWriter::writeModuleHash(
size_t BlockStartPos) {
3680 Buffer.
size() - BlockStartPos));
3682 for (
int Pos = 0; Pos < 20; Pos += 4) {
3700 size_t BlockStartPos = Buffer.
size();
3702 writeModuleVersion();
3708 writeAttributeGroupTable();
3711 writeAttributeTable();
3723 writeModuleConstants();
3726 writeModuleMetadataKinds();
3729 writeModuleMetadata();
3732 if (VE.shouldPreserveUseListOrder())
3733 writeUseListBlock(
nullptr);
3735 writeOperandBundleTags();
3736 writeSyncScopeNames();
3742 writeFunction(*F, FunctionToBitcodeIndex);
3747 writePerModuleGlobalValueSummary();
3749 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
3751 writeModuleHash(BlockStartPos);
3784 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
3785 DARWIN_CPU_TYPE_X86 = 7,
3786 DARWIN_CPU_TYPE_ARM = 12,
3787 DARWIN_CPU_TYPE_POWERPC = 18
3791 if (Arch == Triple::x86_64)
3792 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
3793 else if (Arch == Triple::x86)
3794 CPUType = DARWIN_CPU_TYPE_X86;
3795 else if (Arch == Triple::ppc)
3796 CPUType = DARWIN_CPU_TYPE_POWERPC;
3797 else if (Arch == Triple::ppc64)
3798 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
3799 else if (Arch == Triple::arm || Arch == Triple::thumb)
3800 CPUType = DARWIN_CPU_TYPE_ARM;
3804 "Expected header size to be reserved");
3809 unsigned Position = 0;
3817 while (Buffer.
size() & 15)
3824 Stream.
Emit((
unsigned)
'B', 8);
3825 Stream.
Emit((
unsigned)
'C', 8);
3826 Stream.
Emit(0x0, 4);
3827 Stream.
Emit(0xC, 4);
3828 Stream.
Emit(0xE, 4);
3829 Stream.
Emit(0xD, 4);
3839 void BitcodeWriter::writeBlob(
unsigned Block,
unsigned Record,
StringRef Blob) {
3842 auto Abbv = std::make_shared<BitCodeAbbrev>();
3845 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
3853 assert(!WroteStrtab && !WroteSymtab);
3859 if (M->getModuleInlineAsm().empty())
3863 const Triple TT(M->getTargetTriple());
3865 if (!T || !T->hasMCAsmParser())
3887 std::vector<char> Strtab;
3889 Strtab.resize(StrtabBuilder.
getSize());
3890 StrtabBuilder.
write((uint8_t *)Strtab.data());
3893 {Strtab.data(), Strtab.size()});
3904 bool ShouldPreserveUseListOrder,
3914 Mods.push_back(const_cast<Module *>(M));
3916 ModuleBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream,
3917 ShouldPreserveUseListOrder, Index,
3918 GenerateHash, ModHash);
3919 ModuleWriter.write();
3924 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
3925 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index,
3926 ModuleToSummariesForIndex);
3927 IndexWriter.write();
3933 bool ShouldPreserveUseListOrder,
3942 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
3946 Writer.
writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
3951 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
3961 writeModuleVersion();
3967 writeCombinedGlobalValueSummary();
3978 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
3983 Writer.
writeIndex(&Index, ModuleToSummariesForIndex);
MDString * getRawGetterName() const
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Appends all attachments for the global to MDs, sorting by attachment ID.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
void push_back(const T &Elt)
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
const_iterator end(StringRef path)
Get end iterator over path.
void writeIndex(const ModuleSummaryIndex *Index, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex)
LinkageTypes getLinkage() const
This class provides a symbol table of name/value pairs.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
VisibilityTypes getVisibility() const
*p = old <signed v ? old : v
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
DILocalScope * getScope() const
unsigned getNumOperandBundles() const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, TypePrinting *, SlotTracker *, const Module *)
static uint64_t getOptimizationFlags(const Value *V)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
unsigned Linkage
The linkage type of the associated global value.
DITypeRef getType() const
A Module instance is used to store all the information related to an LLVM module. ...
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
uint32_t getAlignInBits() const
bool getDebugInfoForProfiling() const
Global variable summary information to aid decisions and implementation of importing.
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics with all constant integer arguments.
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
DILocalScope * getScope() const
Get the local scope for this variable.
unsigned getNumOperands() const
MDString * getRawName() const
unsigned getNumOperands() const
Return number of MDNode operands.
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, TypePrinting *, SlotTracker *, const Module *)
UnnamedAddr getUnnamedAddr() const
DIMacroNodeArray getElements() const
This class represents a function call, abstracting a target machine's calling convention.
*p = old <unsigned v ? old : v
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
*p = old >unsigned v ? old : v
const unsigned char * bytes_end() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
void write32le(void *P, uint32_t V)
bool getSplitDebugInlining() const
DITypeRef getBaseType() const
const GlobalValue * getValue() const
The two locations do not alias at all.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
A class that wrap the SHA1 algorithm.
DIScope * getScope() const
std::vector< std::pair< const Value *, unsigned > > ValueList
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
static void writeDILocation(raw_ostream &Out, const DILocation *DL, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
Type * getElementType() const
void reserve(size_type N)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
*p = old >signed v ? old : v
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
unsigned getColumn() const
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...
uint64_t getDWOId() const
MDString * getRawName() const
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
static const uint64_t INDEX_VERSION
StringRef getName() const
Return a constant reference to the value's name.
MDString * getRawName() const
MDString * getRawDirectory() const
element_iterator element_end() const
The address of a basic block.
static uint32_t getAlignment(const MCSectionCOFF &Sec)
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
DIScope * getScope() const
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version...
uint32_t read32be(const void *P)
GVFlags flags()
Get the flags for this GlobalValue (see struct GVFlags).
Class to represent struct types.
ArrayRef< ConstVCall > type_checked_load_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics with ...
MDString * getRawName() const
void BackpatchWord(uint64_t BitNo, unsigned NewWord)
Backpatch a 32-bit word in the output at the given bit offset with the specified value.
unsigned getNumArgOperands() const
Return the number of call arguments.
DINodeArray getElements() const
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
No attributes have been set.
void Emit(uint32_t Val, unsigned NumBits)
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
MDString * getRawFlags() const
bool isMustTailCall() const
Windows NT (Windows on ARM)
element_iterator element_begin() const
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
unsigned getMacinfoType() const
bool getExportSymbols() const
DITypeRefArray getTypeArray() const
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
LLVM_NODISCARD bool empty() const
AtomicOrdering
Atomic ordering for LLVM's memory model.
void assign(size_type NumElts, const T &Elt)
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.
static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *, SlotTracker *, const Module *)
unsigned instCount() const
Get the instruction count recorded for this function.
A constant value that is initialized with an expression using other constant values.
Class to represent function types.
Utility for building string tables with deduplicated suffixes.
ArrayRef< VFuncId > type_checked_load_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics that ...
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
BinOp
This enumeration lists the possible modifications atomicrmw can make.
size_t add(CachedHashStringRef S)
Add a string to the builder.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
const Type::TypeID FloatTyID
Class to represent array types.
BasicBlock * getSuccessor(unsigned i) const
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS)
Write the function type metadata related records that need to appear before a function summary entry ...
TypeID getTypeID() const
Return the type id for the type.
DIScopeRef getScope() const
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
MDString * getRawName() const
bool isNoTailCall() const
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 ...
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
element_iterator elements_begin() const
Structure to hold a use-list order.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Type::subtype_iterator element_iterator
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
DIScopeRef getScope() const
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Type * getElementType() const
size_t size() const
size - Get the array size.
BasicBlock * getNormalDest() const
StringRef modulePath() const
Get the path to the module containing this function.
Class to represent pointers.
DIScope * getScope() const
MDString * getRawChecksum() const
unsigned getNumIncomingValues() const
Return the number of incoming edges.
ArrayRef< VFuncId > type_test_assume_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics that do not have all constant integer arguments.
void append(in_iter S, in_iter E)
Append from an iterator pair.
MDString * getRawName() const
unsigned getRuntimeVersion() const
unsigned getRuntimeLang() const
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
static ChecksumKind getChecksumKind(StringRef CSKindStr)
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.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Type * getParamType(unsigned i) const
Parameter type accessors.
MDString * getRawSplitDebugFilename() const
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
initializer< Ty > init(const Ty &Val)
DITypeRef getType() const
element_iterator elements_end() const
MDString * getRawFilename() const
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool hasMetadata() const
Check if this has any metadata.
MDString * getRawValue() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
void finalizeInOrder()
Finalize the string table without reording it.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
unsigned index_end() const
This is an important base class in LLVM.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isLocalToUnit() const
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
ConstantFP - Floating Point Values [float, double].
static void writeDIModule(raw_ostream &Out, const DIModule *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
unsigned getSourceLanguage() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
A pair of DIGlobalVariable and DIExpression.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
uint64_t getNumElements() const
DIMacroNodeArray getMacros() const
Value * getOperand(unsigned i) const
Metadata * getValue() const
uint32_t getAlignInBits() const
unsigned getEncoding() const
SelectionKind getSelectionKind() const
uint64_t getOffsetInBits() const
unsigned getAttributes() const
bool empty() const
empty - Check if the array is empty.
static unsigned getEncodedCastOpcode(unsigned Opcode)
Sentinal value useful for loops.
Function and variable summary information to aid decisions and implementation of importing.
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
DINodeRef getEntity() const
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool isFP128Ty() const
Return true if this is 'fp128'.
FunctionType * getFunctionType() const
unsigned index_begin() const
Use these to iterate over the valid attribute indices.
static void write(bool isBE, void *P, T V)
Metadata * getRawFile() const
void consumeError(Error Err)
Consume a Error without doing anything.
LLVMContext & getContext() const
All values hold a context through their type.
static bool isAtomic(Instruction *I)
static uint64_t rotateSign(int64_t I)
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags)
OperandBundleUse getOperandBundleAt(unsigned Index) const
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
Triple - Helper class for working with autoconf configuration names.
DITypeRef getType() const
FunctionType * getFunctionType() const
An imported module (C++ using directive or similar).
raw_ostream & write(unsigned char C)
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
void dump() const
Support for debugging, callable in GDB: V->dump()
DIScopeArray getRetainedTypes() const
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Struct that holds a reference to a particular GUID in a global value summary.
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.
bool isConditional() const
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
EmitAbbrev - This emits an abbreviation to the stream.
DIExpression * getExpression() const
ArrayRef< uint64_t > getElements() const
DIImportedEntityArray getImportedEntities() const
const MDOperand & getOperand(unsigned I) const
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
void write(raw_ostream &OS) const
Iterator for intrusive lists based on ilist_node.
BasicBlock * getUnwindDest() const
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
This is the shared class of boolean and integer constants.
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
InstrTy * getInstruction() const
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static Optional< DebugEmissionKind > getEmissionKind(StringRef Str)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool isMaterialized() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
bool hasAttributes() const
Return true if attributes exists in this set.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
ArrayRef< GlobalValue::GUID > type_tests() const
Returns the list of type identifiers used by this function in llvm.type.test intrinsics other than by...
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
MDString * getRawLinkageName() const
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, TypePrinting *, SlotTracker *, const Module *)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
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...
Alias summary information.
static const unsigned BWH_HeaderSize
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
Class to represent vector types.
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
unsigned getDiscriminator() const
DIGlobalVariableExpressionArray getGlobalVariables() const
static bool isWeak(const MCSymbolELF &Sym)
LinkageTypes
An enumeration for the kinds of linkage for global values.
void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
A (clang) module that has been imported by the compile unit.
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
StringRef getName() const
Return the name for this struct type if it has an identity.
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
Generic tagged DWARF-like metadata node.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Value * getCondition() const
iterator insert(iterator I, T &&Elt)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
llvm_unreachable("Unknown RegBank!")
ThreadLocalMode getThreadLocalMode() const
Type array for a subprogram.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static std::vector< std::string > Flags
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
AttributeList getAttributes() const
Return the parameter attributes for this invoke.
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
Value * getCondition() const
bool isX86_FP80Ty() const
Return true if this is x86 long double.
ValID - Represents a reference of a definition of some sort with no type.
BasicBlock * getDefaultDest() const
pointer data()
Return a pointer to the vector's buffer, even if empty().
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
DITemplateParameterArray getTemplateParams() const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
Establish a view to a call site for examination.
AttributeList getAttributes() const
Return the parameter attributes for this call.
uint32_t getOperandBundleTagID(StringRef Tag) const
getOperandBundleTagID - Maps a bundle tag to an integer ID.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool empty() const
Determine if the symbol table is empty.
DIGlobalVariable * getVariable() const
unsigned getNumElements() const
Return the number of elements in the array or vector.
MDString * getRawIdentifier() const
uint64_t getSizeInBits() const
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
op_range operands() const
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Function summary information to aid decisions and implementation of importing.
DITypeRef getVTableHolder() const
GlobalValue::GUID getGUID() const
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
Type * getReturnType() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MDString * getRawName() const
const unsigned char * bytes_begin() const
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
DICompositeTypeArray getEnumTypes() const
const Type::TypeID DoubleTyID
LLVM Value Representation.
DIDerivedType * getStaticDataMemberDeclaration() const
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Lightweight error class with error context and mandatory checking.
DLLStorageClassTypes getDLLStorageClass() const
bool isDefinition() const
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
std::vector< Type * > TypeList
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
std::string Hash(const Unit &U)
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
MDString * getRawName() const
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
int64_t getLowerBound() const
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
MDString * getRawSetterName() const
static bool isVolatile(Instruction *Inst)
void writeStrtab()
Write the bitcode file's string table.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isResolved() const
Check if node is fully resolved.
unsigned getNumArgOperands() const
Return the number of invoke arguments.
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
MDString * getRawProducer() const
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool isVoidTy() const
Return true if this is 'void'.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Basic type, like 'int' or 'float'.
static unsigned getEncodedVisibility(const GlobalValue &GV)