31#include "llvm/Config/llvm-config.h"
88 cl::desc(
"Number of metadatas above which we emit an index "
89 "to enable lazy-loading"));
92 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
96 cl::desc(
"Write relative block frequency to function summary "));
114 VST_BBENTRY_6_ABBREV,
118 CONSTANTS_INTEGER_ABBREV,
119 CONSTANTS_CE_CAST_Abbrev,
120 CONSTANTS_NULL_Abbrev,
124 FUNCTION_INST_UNOP_ABBREV,
125 FUNCTION_INST_UNOP_FLAGS_ABBREV,
126 FUNCTION_INST_BINOP_ABBREV,
127 FUNCTION_INST_BINOP_FLAGS_ABBREV,
128 FUNCTION_INST_CAST_ABBREV,
129 FUNCTION_INST_CAST_FLAGS_ABBREV,
130 FUNCTION_INST_RET_VOID_ABBREV,
131 FUNCTION_INST_RET_VAL_ABBREV,
132 FUNCTION_INST_UNREACHABLE_ABBREV,
133 FUNCTION_INST_GEP_ABBREV,
134 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
139class BitcodeWriterBase {
150 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
153 void writeModuleVersion();
156void BitcodeWriterBase::writeModuleVersion() {
163class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
177 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
180 unsigned GlobalValueId;
191 bool ShouldPreserveUseListOrder,
193 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
203 for (
const auto &GUIDSummaryLists : *
Index)
205 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
206 if (
auto FS = dyn_cast<FunctionSummary>(
Summary.get()))
211 for (
auto &CallEdge :
FS->calls())
212 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
213 assignValueId(CallEdge.first.getGUID());
217 void writePerModuleGlobalValueSummary();
220 void writePerModuleFunctionSummaryRecord(
222 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
223 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
const Function &
F);
226 unsigned FSModRefsAbbrev,
227 unsigned FSModVTableRefsAbbrev);
230 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
234 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
237 assert(VMI != GUIDToValueIdMap.end() &&
238 "GUID does not have assigned value Id");
244 if (!
VI.haveGVs() || !
VI.getValue())
245 return getValueId(
VI.getGUID());
249 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
253class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
277 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
278 ShouldPreserveUseListOrder,
Index),
279 Buffer(Buffer), GenerateHash(GenerateHash), ModHash(ModHash),
280 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
286 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
290 void writeAttributeGroupTable();
291 void writeAttributeTable();
292 void writeTypeTable();
294 void writeValueSymbolTableForwardDecl();
295 void writeModuleInfo();
300 unsigned createDILocationAbbrev();
303 unsigned createGenericDINodeAbbrev();
371 unsigned createNamedMetadataAbbrev();
373 unsigned createMetadataStringsAbbrev();
378 std::vector<unsigned> *MDAbbrevs =
nullptr,
379 std::vector<uint64_t> *IndexPos =
nullptr);
380 void writeModuleMetadata();
381 void writeFunctionMetadata(
const Function &
F);
382 void writeFunctionMetadataAttachment(
const Function &
F);
385 void writeModuleMetadataKinds();
386 void writeOperandBundleTags();
387 void writeSyncScopeNames();
388 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
389 void writeModuleConstants();
390 bool pushValueAndType(
const Value *V,
unsigned InstID,
392 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
393 void pushValue(
const Value *V,
unsigned InstID,
395 void pushValueSigned(
const Value *V,
unsigned InstID,
397 void writeInstruction(
const Instruction &
I,
unsigned InstID,
400 void writeGlobalValueSymbolTable(
403 void writeUseListBlock(
const Function *
F);
407 void writeBlockInfo();
408 void writeModuleHash(
size_t BlockStartPos);
414 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
418class IndexBitcodeWriter :
public BitcodeWriterBase {
424 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
428 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
433 std::vector<unsigned> StackIdIndices;
436 unsigned GlobalValueId = 0;
448 const std::map<std::string, GVSummaryMapTy>
449 *ModuleToSummariesForIndex =
nullptr)
450 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
451 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
456 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
457 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
460 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
466 for (
auto &CI :
FS->callsites()) {
477 if (CI.StackIdIndices.empty()) {
478 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
481 for (
auto Idx : CI.StackIdIndices)
482 StackIdIndices.push_back(
Idx);
484 for (
auto &AI :
FS->allocs())
485 for (
auto &MIB : AI.MIBs)
486 for (
auto Idx : MIB.StackIdIndices)
487 StackIdIndices.push_back(
Idx);
490 StackIdIndices.erase(
491 std::unique(StackIdIndices.begin(), StackIdIndices.end()),
492 StackIdIndices.end());
496 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
501 template<
typename Functor>
502 void forEachSummary(Functor Callback) {
503 if (ModuleToSummariesForIndex) {
504 for (
auto &M : *ModuleToSummariesForIndex)
505 for (
auto &Summary :
M.second) {
506 Callback(Summary,
false);
510 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
511 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
514 for (
auto &Summaries :
Index)
515 for (
auto &Summary : Summaries.second.SummaryList)
516 Callback({Summaries.first,
Summary.get()},
false);
524 template <
typename Functor>
void forEachModule(Functor Callback) {
525 if (ModuleToSummariesForIndex) {
526 for (
const auto &M : *ModuleToSummariesForIndex) {
527 const auto &MPI =
Index.modulePaths().find(
M.first);
528 if (MPI ==
Index.modulePaths().end()) {
532 assert(ModuleToSummariesForIndex->size() == 1);
542 std::vector<StringRef> ModulePaths;
543 for (
auto &[ModPath,
_] :
Index.modulePaths())
544 ModulePaths.push_back(ModPath);
545 llvm::sort(ModulePaths.begin(), ModulePaths.end());
546 for (
auto &ModPath : ModulePaths)
547 Callback(*
Index.modulePaths().find(ModPath));
555 void writeModStrings();
556 void writeCombinedGlobalValueSummary();
559 auto VMI = GUIDToValueIdMap.find(ValGUID);
560 if (VMI == GUIDToValueIdMap.end())
565 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
599 case Instruction::Add:
601 case Instruction::Sub:
603 case Instruction::Mul:
606 case Instruction::FDiv:
609 case Instruction::FRem:
675 case Attribute::Alignment:
677 case Attribute::AllocAlign:
679 case Attribute::AllocSize:
681 case Attribute::AlwaysInline:
683 case Attribute::Builtin:
685 case Attribute::ByVal:
687 case Attribute::Convergent:
689 case Attribute::InAlloca:
691 case Attribute::Cold:
693 case Attribute::DisableSanitizerInstrumentation:
695 case Attribute::FnRetThunkExtern:
699 case Attribute::ElementType:
701 case Attribute::InlineHint:
703 case Attribute::InReg:
705 case Attribute::JumpTable:
707 case Attribute::MinSize:
709 case Attribute::AllocatedPointer:
711 case Attribute::AllocKind:
713 case Attribute::Memory:
715 case Attribute::NoFPClass:
717 case Attribute::Naked:
719 case Attribute::Nest:
721 case Attribute::NoAlias:
723 case Attribute::NoBuiltin:
725 case Attribute::NoCallback:
727 case Attribute::NoCapture:
729 case Attribute::NoDuplicate:
731 case Attribute::NoFree:
733 case Attribute::NoImplicitFloat:
735 case Attribute::NoInline:
737 case Attribute::NoRecurse:
739 case Attribute::NoMerge:
741 case Attribute::NonLazyBind:
743 case Attribute::NonNull:
745 case Attribute::Dereferenceable:
747 case Attribute::DereferenceableOrNull:
749 case Attribute::NoRedZone:
751 case Attribute::NoReturn:
753 case Attribute::NoSync:
755 case Attribute::NoCfCheck:
757 case Attribute::NoProfile:
759 case Attribute::SkipProfile:
761 case Attribute::NoUnwind:
763 case Attribute::NoSanitizeBounds:
765 case Attribute::NoSanitizeCoverage:
767 case Attribute::NullPointerIsValid:
769 case Attribute::OptimizeForDebugging:
771 case Attribute::OptForFuzzing:
773 case Attribute::OptimizeForSize:
775 case Attribute::OptimizeNone:
777 case Attribute::ReadNone:
779 case Attribute::ReadOnly:
781 case Attribute::Returned:
783 case Attribute::ReturnsTwice:
785 case Attribute::SExt:
787 case Attribute::Speculatable:
789 case Attribute::StackAlignment:
791 case Attribute::StackProtect:
793 case Attribute::StackProtectReq:
795 case Attribute::StackProtectStrong:
797 case Attribute::SafeStack:
799 case Attribute::ShadowCallStack:
801 case Attribute::StrictFP:
803 case Attribute::StructRet:
805 case Attribute::SanitizeAddress:
807 case Attribute::SanitizeHWAddress:
809 case Attribute::SanitizeThread:
811 case Attribute::SanitizeMemory:
813 case Attribute::SpeculativeLoadHardening:
815 case Attribute::SwiftError:
817 case Attribute::SwiftSelf:
819 case Attribute::SwiftAsync:
821 case Attribute::UWTable:
823 case Attribute::VScaleRange:
825 case Attribute::WillReturn:
827 case Attribute::WriteOnly:
829 case Attribute::ZExt:
831 case Attribute::ImmArg:
833 case Attribute::SanitizeMemTag:
835 case Attribute::Preallocated:
837 case Attribute::NoUndef:
839 case Attribute::ByRef:
841 case Attribute::MustProgress:
843 case Attribute::PresplitCoroutine:
845 case Attribute::Writable:
847 case Attribute::CoroDestroyOnlyWhenComplete:
849 case Attribute::DeadOnUnwind:
851 case Attribute::Range:
877 unsigned NumWords =
A.getActiveWords();
878 const uint64_t *RawData =
A.getRawData();
879 for (
unsigned i = 0; i < NumWords; i++)
898void ModuleBitcodeWriter::writeAttributeGroupTable() {
899 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
901 if (AttrGrps.empty())
return;
907 unsigned AttrListIndex = Pair.first;
910 Record.push_back(AttrListIndex);
913 if (Attr.isEnumAttribute()) {
916 }
else if (Attr.isIntAttribute()) {
919 Record.push_back(Attr.getValueAsInt());
920 }
else if (Attr.isStringAttribute()) {
931 }
else if (Attr.isTypeAttribute()) {
932 Type *Ty = Attr.getValueAsType();
933 Record.push_back(Ty ? 6 : 5);
938 assert(Attr.isConstantRangeAttribute());
952void ModuleBitcodeWriter::writeAttributeTable() {
954 if (
Attrs.empty())
return;
960 for (
unsigned i :
AL.indexes()) {
974void ModuleBitcodeWriter::writeTypeTable() {
983 auto Abbv = std::make_shared<BitCodeAbbrev>();
986 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
989 Abbv = std::make_shared<BitCodeAbbrev>();
994 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
997 Abbv = std::make_shared<BitCodeAbbrev>();
1002 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1005 Abbv = std::make_shared<BitCodeAbbrev>();
1009 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1012 Abbv = std::make_shared<BitCodeAbbrev>();
1017 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1020 Abbv = std::make_shared<BitCodeAbbrev>();
1024 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1032 for (
Type *
T : TypeList) {
1033 int AbbrevToUse = 0;
1036 switch (
T->getTypeID()) {
1062 AbbrevToUse = OpaquePtrAbbrev;
1071 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1073 AbbrevToUse = FunctionAbbrev;
1081 for (
Type *ET :
ST->elements())
1084 if (
ST->isLiteral()) {
1086 AbbrevToUse = StructAnonAbbrev;
1088 if (
ST->isOpaque()) {
1092 AbbrevToUse = StructNamedAbbrev;
1096 if (!
ST->getName().empty())
1106 TypeVals.
push_back(AT->getNumElements());
1108 AbbrevToUse = ArrayAbbrev;
1117 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1119 if (isa<ScalableVectorType>(VT))
1129 for (
Type *InnerTy :
TET->type_params())
1131 for (
unsigned IntParam :
TET->int_params())
1140 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1181 RawFlags |= Flags.ReadNone;
1182 RawFlags |= (Flags.ReadOnly << 1);
1183 RawFlags |= (Flags.NoRecurse << 2);
1184 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1185 RawFlags |= (Flags.NoInline << 4);
1186 RawFlags |= (Flags.AlwaysInline << 5);
1187 RawFlags |= (Flags.NoUnwind << 6);
1188 RawFlags |= (Flags.MayThrow << 7);
1189 RawFlags |= (Flags.HasUnknownCall << 8);
1190 RawFlags |= (Flags.MustBeUnreachable << 9);
1199 RawFlags |= Flags.NotEligibleToImport;
1200 RawFlags |= (Flags.Live << 1);
1201 RawFlags |= (Flags.DSOLocal << 2);
1202 RawFlags |= (Flags.CanAutoHide << 3);
1207 RawFlags = (RawFlags << 4) | Flags.Linkage;
1209 RawFlags |= (Flags.Visibility << 8);
1215 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1216 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1258 case GlobalVariable::NotThreadLocal:
return 0;
1259 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1260 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1261 case GlobalVariable::InitialExecTLSModel:
return 3;
1262 case GlobalVariable::LocalExecTLSModel:
return 4;
1268 switch (
C.getSelectionKind()) {
1285 case GlobalValue::UnnamedAddr::None:
return 0;
1286 case GlobalValue::UnnamedAddr::Local:
return 2;
1287 case GlobalValue::UnnamedAddr::Global:
return 1;
1292size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1295 return StrtabBuilder.
add(Str);
1298void ModuleBitcodeWriter::writeComdats() {
1313void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1318 auto Abbv = std::make_shared<BitCodeAbbrev>();
1324 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1340 bool isChar6 =
true;
1341 for (
char C : Str) {
1344 if ((
unsigned char)
C & 128)
1354 "Sanitizer Metadata is too large for naive serialization.");
1357 return Meta.NoAddress | (Meta.NoHWAddress << 1) |
1358 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1364void ModuleBitcodeWriter::writeModuleInfo() {
1366 if (!
M.getTargetTriple().empty())
1369 const std::string &
DL =
M.getDataLayoutStr();
1372 if (!
M.getModuleInlineAsm().empty())
1378 std::map<std::string, unsigned> SectionMap;
1379 std::map<std::string, unsigned> GCMap;
1381 unsigned MaxGlobalType = 0;
1382 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1384 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1387 UpdateMaxAlignment(GV.getAlign());
1388 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1389 if (GV.hasSection()) {
1391 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1395 Entry = SectionMap.size();
1400 UpdateMaxAlignment(
F.getAlign());
1401 if (
F.hasSection()) {
1403 unsigned &Entry = SectionMap[std::string(
F.getSection())];
1407 Entry = SectionMap.size();
1412 unsigned &Entry = GCMap[
F.getGC()];
1416 Entry = GCMap.size();
1422 unsigned SimpleGVarAbbrev = 0;
1423 if (!
M.global_empty()) {
1425 auto Abbv = std::make_shared<BitCodeAbbrev>();
1439 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1443 if (SectionMap.empty())
1449 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1463 auto Abbv = std::make_shared<BitCodeAbbrev>();
1466 Abbv->Add(AbbrevOpToUse);
1467 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1469 for (
const auto P :
M.getSourceFileName())
1479 unsigned AbbrevToUse = 0;
1485 Vals.
push_back(addToStrtab(GV.getName()));
1488 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1492 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1493 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1495 if (GV.isThreadLocal() ||
1497 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1498 GV.isExternallyInitialized() ||
1500 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1501 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1505 Vals.
push_back(GV.isExternallyInitialized());
1513 Vals.
push_back(addToStrtab(GV.getPartition()));
1514 Vals.
push_back(GV.getPartition().size());
1517 GV.getSanitizerMetadata())
1521 AbbrevToUse = SimpleGVarAbbrev;
1541 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1542 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1554 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1558 Vals.
push_back(addToStrtab(
F.getPartition()));
1561 unsigned AbbrevToUse = 0;
1574 Vals.
push_back(
A.getType()->getAddressSpace());
1582 Vals.
push_back(addToStrtab(
A.getPartition()));
1585 unsigned AbbrevToUse = 0;
1597 Vals.
push_back(
I.getType()->getAddressSpace());
1602 Vals.
push_back(addToStrtab(
I.getPartition()));
1608 writeValueSymbolTableForwardDecl();
1614 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1615 if (OBO->hasNoSignedWrap())
1617 if (OBO->hasNoUnsignedWrap())
1619 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1622 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1623 if (PDI->isDisjoint())
1625 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1626 if (FPMO->hasAllowReassoc())
1628 if (FPMO->hasNoNaNs())
1630 if (FPMO->hasNoInfs())
1632 if (FPMO->hasNoSignedZeros())
1634 if (FPMO->hasAllowReciprocal())
1636 if (FPMO->hasAllowContract())
1638 if (FPMO->hasApproxFunc())
1640 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1641 if (NNI->hasNonNeg())
1648void ModuleBitcodeWriter::writeValueAsMetadata(
1658void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1663 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1664 "Unexpected function-local metadata");
1673unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1676 auto Abbv = std::make_shared<BitCodeAbbrev>();
1687void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1691 Abbrev = createDILocationAbbrev();
1693 Record.push_back(
N->isDistinct());
1694 Record.push_back(
N->getLine());
1695 Record.push_back(
N->getColumn());
1698 Record.push_back(
N->isImplicitCode());
1704unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1707 auto Abbv = std::make_shared<BitCodeAbbrev>();
1718void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1722 Abbrev = createGenericDINodeAbbrev();
1724 Record.push_back(
N->isDistinct());
1725 Record.push_back(
N->getTag());
1728 for (
auto &
I :
N->operands())
1735void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1749void ModuleBitcodeWriter::writeDIGenericSubrange(
1762void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1766 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1767 Record.push_back(
N->getValue().getBitWidth());
1775void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1778 Record.push_back(
N->isDistinct());
1779 Record.push_back(
N->getTag());
1781 Record.push_back(
N->getSizeInBits());
1782 Record.push_back(
N->getAlignInBits());
1783 Record.push_back(
N->getEncoding());
1784 Record.push_back(
N->getFlags());
1790void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1793 Record.push_back(
N->isDistinct());
1794 Record.push_back(
N->getTag());
1799 Record.push_back(
N->getSizeInBits());
1800 Record.push_back(
N->getAlignInBits());
1801 Record.push_back(
N->getEncoding());
1807void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1810 Record.push_back(
N->isDistinct());
1811 Record.push_back(
N->getTag());
1814 Record.push_back(
N->getLine());
1817 Record.push_back(
N->getSizeInBits());
1818 Record.push_back(
N->getAlignInBits());
1819 Record.push_back(
N->getOffsetInBits());
1820 Record.push_back(
N->getFlags());
1825 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1826 Record.push_back(*DWARFAddressSpace + 1);
1836void ModuleBitcodeWriter::writeDICompositeType(
1839 const unsigned IsNotUsedInOldTypeRef = 0x2;
1840 Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1841 Record.push_back(
N->getTag());
1844 Record.push_back(
N->getLine());
1847 Record.push_back(
N->getSizeInBits());
1848 Record.push_back(
N->getAlignInBits());
1849 Record.push_back(
N->getOffsetInBits());
1850 Record.push_back(
N->getFlags());
1852 Record.push_back(
N->getRuntimeLang());
1867void ModuleBitcodeWriter::writeDISubroutineType(
1870 const unsigned HasNoOldTypeRefs = 0x2;
1871 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1872 Record.push_back(
N->getFlags());
1880void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
1883 Record.push_back(
N->isDistinct());
1886 if (
N->getRawChecksum()) {
1887 Record.push_back(
N->getRawChecksum()->Kind);
1895 auto Source =
N->getRawSource();
1903void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
1906 assert(
N->isDistinct() &&
"Expected distinct compile units");
1908 Record.push_back(
N->getSourceLanguage());
1911 Record.push_back(
N->isOptimized());
1913 Record.push_back(
N->getRuntimeVersion());
1915 Record.push_back(
N->getEmissionKind());
1921 Record.push_back(
N->getDWOId());
1923 Record.push_back(
N->getSplitDebugInlining());
1924 Record.push_back(
N->getDebugInfoForProfiling());
1925 Record.push_back((
unsigned)
N->getNameTableKind());
1926 Record.push_back(
N->getRangesBaseAddress());
1934void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
1937 const uint64_t HasUnitFlag = 1 << 1;
1938 const uint64_t HasSPFlagsFlag = 1 << 2;
1939 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
1944 Record.push_back(
N->getLine());
1946 Record.push_back(
N->getScopeLine());
1948 Record.push_back(
N->getSPFlags());
1949 Record.push_back(
N->getVirtualIndex());
1950 Record.push_back(
N->getFlags());
1955 Record.push_back(
N->getThisAdjustment());
1967 Record.push_back(
N->isDistinct());
1970 Record.push_back(
N->getLine());
1971 Record.push_back(
N->getColumn());
1977void ModuleBitcodeWriter::writeDILexicalBlockFile(
1980 Record.push_back(
N->isDistinct());
1983 Record.push_back(
N->getDiscriminator());
1989void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
1992 Record.push_back(
N->isDistinct());
1997 Record.push_back(
N->getLineNo());
2003void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2006 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2014void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2017 Record.push_back(
N->isDistinct());
2018 Record.push_back(
N->getMacinfoType());
2019 Record.push_back(
N->getLine());
2027void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2030 Record.push_back(
N->isDistinct());
2031 Record.push_back(
N->getMacinfoType());
2032 Record.push_back(
N->getLine());
2040void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2042 Record.reserve(
N->getArgs().size());
2050void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2053 Record.push_back(
N->isDistinct());
2054 for (
auto &
I :
N->operands())
2056 Record.push_back(
N->getLineNo());
2057 Record.push_back(
N->getIsDecl());
2063void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2067 Record.push_back(
N->isDistinct());
2072void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2075 Record.push_back(
N->isDistinct());
2078 Record.push_back(
N->isDefault());
2084void ModuleBitcodeWriter::writeDITemplateValueParameter(
2087 Record.push_back(
N->isDistinct());
2088 Record.push_back(
N->getTag());
2091 Record.push_back(
N->isDefault());
2098void ModuleBitcodeWriter::writeDIGlobalVariable(
2107 Record.push_back(
N->getLine());
2109 Record.push_back(
N->isLocalToUnit());
2110 Record.push_back(
N->isDefinition());
2113 Record.push_back(
N->getAlignInBits());
2120void ModuleBitcodeWriter::writeDILocalVariable(
2136 const uint64_t HasAlignmentFlag = 1 << 1;
2141 Record.push_back(
N->getLine());
2143 Record.push_back(
N->getArg());
2144 Record.push_back(
N->getFlags());
2145 Record.push_back(
N->getAlignInBits());
2152void ModuleBitcodeWriter::writeDILabel(
2159 Record.push_back(
N->getLine());
2165void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2168 Record.reserve(
N->getElements().size() + 1);
2171 Record.append(
N->elements_begin(),
N->elements_end());
2177void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2180 Record.push_back(
N->isDistinct());
2191 Record.push_back(
N->isDistinct());
2194 Record.push_back(
N->getLine());
2197 Record.push_back(
N->getAttributes());
2204void ModuleBitcodeWriter::writeDIImportedEntity(
2207 Record.push_back(
N->isDistinct());
2208 Record.push_back(
N->getTag());
2211 Record.push_back(
N->getLine());
2220unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2221 auto Abbv = std::make_shared<BitCodeAbbrev>();
2228void ModuleBitcodeWriter::writeNamedMetadata(
2230 if (
M.named_metadata_empty())
2233 unsigned Abbrev = createNamedMetadataAbbrev();
2237 Record.append(Str.bytes_begin(), Str.bytes_end());
2242 for (
const MDNode *
N : NMD.operands())
2249unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2250 auto Abbv = std::make_shared<BitCodeAbbrev>();
2262void ModuleBitcodeWriter::writeMetadataStrings(
2264 if (Strings.empty())
2269 Record.push_back(Strings.size());
2276 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2285 Blob.
append(cast<MDString>(MD)->getString());
2294#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2295#include "llvm/IR/Metadata.def"
2299void ModuleBitcodeWriter::writeMetadataRecords(
2301 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2306#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2307#include "llvm/IR/Metadata.def"
2312 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2313 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2315 switch (
N->getMetadataID()) {
2318#define HANDLE_MDNODE_LEAF(CLASS) \
2319 case Metadata::CLASS##Kind: \
2321 write##CLASS(cast<CLASS>(N), Record, \
2322 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2324 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2326#include "llvm/IR/Metadata.def"
2329 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2333 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2337void ModuleBitcodeWriter::writeModuleMetadata() {
2338 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2346 std::vector<unsigned> MDAbbrevs;
2349 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2350 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2351 createGenericDINodeAbbrev();
2353 auto Abbv = std::make_shared<BitCodeAbbrev>();
2357 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2359 Abbv = std::make_shared<BitCodeAbbrev>();
2363 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2385 std::vector<uint64_t> IndexPos;
2400 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2401 for (
auto &Elt : IndexPos) {
2402 auto EltDelta = Elt - PreviousValue;
2403 PreviousValue = Elt;
2412 writeNamedMetadata(
Record);
2414 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2417 pushGlobalMetadataAttachment(
Record, GO);
2421 if (
F.isDeclaration() &&
F.hasMetadata())
2422 AddDeclAttachedMetadata(
F);
2426 if (GV.hasMetadata())
2427 AddDeclAttachedMetadata(GV);
2432void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2443void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2448 for (
const auto &
I : MDs) {
2454void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2459 if (
F.hasMetadata()) {
2460 pushGlobalMetadataAttachment(
Record,
F);
2471 I.getAllMetadataOtherThanDebugLoc(MDs);
2474 if (MDs.
empty())
continue;
2478 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2479 Record.push_back(MDs[i].first);
2489void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2495 M.getMDKindNames(Names);
2497 if (Names.
empty())
return;
2501 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2502 Record.push_back(MDKindID);
2513void ModuleBitcodeWriter::writeOperandBundleTags() {
2521 M.getOperandBundleTags(Tags);
2530 for (
auto Tag : Tags) {
2540void ModuleBitcodeWriter::writeSyncScopeNames() {
2542 M.getContext().getSyncScopeNames(SSNs);
2549 for (
auto SSN : SSNs) {
2550 Record.append(SSN.begin(), SSN.end());
2558void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2560 if (FirstVal == LastVal)
return;
2564 unsigned AggregateAbbrev = 0;
2565 unsigned String8Abbrev = 0;
2566 unsigned CString7Abbrev = 0;
2567 unsigned CString6Abbrev = 0;
2571 auto Abbv = std::make_shared<BitCodeAbbrev>();
2575 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2578 Abbv = std::make_shared<BitCodeAbbrev>();
2582 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2584 Abbv = std::make_shared<BitCodeAbbrev>();
2588 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2590 Abbv = std::make_shared<BitCodeAbbrev>();
2594 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2600 Type *LastTy =
nullptr;
2601 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2602 const Value *
V = Vals[i].first;
2604 if (
V->getType() != LastTy) {
2605 LastTy =
V->getType();
2608 CONSTANTS_SETTYPE_ABBREV);
2612 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2615 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2616 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2619 const std::string &AsmStr =
IA->getAsmString();
2620 Record.push_back(AsmStr.size());
2621 Record.append(AsmStr.begin(), AsmStr.end());
2624 const std::string &ConstraintStr =
IA->getConstraintString();
2625 Record.push_back(ConstraintStr.size());
2626 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2632 unsigned Code = -1U;
2633 unsigned AbbrevToUse = 0;
2634 if (
C->isNullValue()) {
2636 }
else if (isa<PoisonValue>(
C)) {
2638 }
else if (isa<UndefValue>(
C)) {
2641 if (
IV->getBitWidth() <= 64) {
2645 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2650 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2655 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2659 APInt api = CFP->getValueAPF().bitcastToAPInt();
2661 Record.push_back((p[1] << 48) | (p[0] >> 16));
2662 Record.push_back(p[0] & 0xffffLL);
2664 APInt api = CFP->getValueAPF().bitcastToAPInt();
2669 assert(0 &&
"Unknown FP type!");
2671 }
else if (isa<ConstantDataSequential>(
C) &&
2672 cast<ConstantDataSequential>(
C)->isString()) {
2675 unsigned NumElts = Str->getNumElements();
2677 if (Str->isCString()) {
2682 AbbrevToUse = String8Abbrev;
2686 for (
unsigned i = 0; i != NumElts; ++i) {
2687 unsigned char V = Str->getElementAsInteger(i);
2689 isCStr7 &= (
V & 128) == 0;
2695 AbbrevToUse = CString6Abbrev;
2697 AbbrevToUse = CString7Abbrev;
2699 dyn_cast<ConstantDataSequential>(
C)) {
2701 Type *EltTy = CDS->getElementType();
2702 if (isa<IntegerType>(EltTy)) {
2703 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2704 Record.push_back(CDS->getElementAsInteger(i));
2706 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2708 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2710 }
else if (isa<ConstantAggregate>(
C)) {
2712 for (
const Value *
Op :
C->operands())
2714 AbbrevToUse = AggregateAbbrev;
2715 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2716 switch (
CE->getOpcode()) {
2723 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2725 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2735 case Instruction::FNeg: {
2736 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2745 case Instruction::GetElementPtr: {
2747 const auto *GO = cast<GEPOperator>(
C);
2749 if (std::optional<unsigned>
Idx = GO->getInRangeIndex()) {
2751 Record.push_back((*
Idx << 1) | GO->isInBounds());
2752 }
else if (GO->isInBounds())
2754 for (
unsigned i = 0, e =
CE->getNumOperands(); i != e; ++i) {
2760 case Instruction::ExtractElement:
2767 case Instruction::InsertElement:
2774 case Instruction::ShuffleVector:
2779 if (
C->getType() ==
C->getOperand(0)->getType()) {
2789 case Instruction::ICmp:
2790 case Instruction::FCmp:
2795 Record.push_back(
CE->getPredicate());
2798 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2803 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2807 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
2824void ModuleBitcodeWriter::writeModuleConstants() {
2829 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2830 if (!isa<GlobalValue>(Vals[i].first)) {
2831 writeConstants(i, Vals.size(),
true);
2845bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2850 if (
ValID >= InstID) {
2857void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
2864 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2866 for (
auto &Input : Bundle.Inputs)
2867 pushValueAndType(Input, InstID,
Record);
2876void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2882void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2885 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2890void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2894 unsigned AbbrevToUse = 0;
2896 switch (
I.getOpcode()) {
2900 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2901 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2906 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
2907 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
2911 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
2913 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2914 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2915 pushValue(
I.getOperand(1), InstID, Vals);
2919 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2920 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2925 case Instruction::FNeg: {
2927 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2928 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2932 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
2933 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
2938 case Instruction::GetElementPtr: {
2940 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2941 auto &GEPInst = cast<GetElementPtrInst>(
I);
2944 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
2945 pushValueAndType(
I.getOperand(i), InstID, Vals);
2948 case Instruction::ExtractValue: {
2950 pushValueAndType(
I.getOperand(0), InstID, Vals);
2955 case Instruction::InsertValue: {
2957 pushValueAndType(
I.getOperand(0), InstID, Vals);
2958 pushValueAndType(
I.getOperand(1), InstID, Vals);
2963 case Instruction::Select: {
2965 pushValueAndType(
I.getOperand(1), InstID, Vals);
2966 pushValue(
I.getOperand(2), InstID, Vals);
2967 pushValueAndType(
I.getOperand(0), InstID, Vals);
2973 case Instruction::ExtractElement:
2975 pushValueAndType(
I.getOperand(0), InstID, Vals);
2976 pushValueAndType(
I.getOperand(1), InstID, Vals);
2978 case Instruction::InsertElement:
2980 pushValueAndType(
I.getOperand(0), InstID, Vals);
2981 pushValue(
I.getOperand(1), InstID, Vals);
2982 pushValueAndType(
I.getOperand(2), InstID, Vals);
2984 case Instruction::ShuffleVector:
2986 pushValueAndType(
I.getOperand(0), InstID, Vals);
2987 pushValue(
I.getOperand(1), InstID, Vals);
2988 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
2991 case Instruction::ICmp:
2992 case Instruction::FCmp: {
2995 pushValueAndType(
I.getOperand(0), InstID, Vals);
2996 pushValue(
I.getOperand(1), InstID, Vals);
3004 case Instruction::Ret:
3007 unsigned NumOperands =
I.getNumOperands();
3008 if (NumOperands == 0)
3009 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3010 else if (NumOperands == 1) {
3011 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3012 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3014 for (
unsigned i = 0, e = NumOperands; i !=
e; ++i)
3015 pushValueAndType(
I.getOperand(i), InstID, Vals);
3019 case Instruction::Br:
3030 case Instruction::Switch:
3035 pushValue(
SI.getCondition(), InstID, Vals);
3037 for (
auto Case :
SI.cases()) {
3043 case Instruction::IndirectBr:
3047 pushValue(
I.getOperand(0), InstID, Vals);
3048 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i)
3052 case Instruction::Invoke: {
3058 writeOperandBundles(*II, InstID);
3067 pushValueAndType(Callee, InstID, Vals);
3070 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3071 pushValue(
I.getOperand(i), InstID, Vals);
3074 if (FTy->isVarArg()) {
3075 for (
unsigned i = FTy->getNumParams(), e = II->
arg_size(); i != e; ++i)
3076 pushValueAndType(
I.getOperand(i), InstID, Vals);
3080 case Instruction::Resume:
3082 pushValueAndType(
I.getOperand(0), InstID, Vals);
3084 case Instruction::CleanupRet: {
3086 const auto &CRI = cast<CleanupReturnInst>(
I);
3087 pushValue(CRI.getCleanupPad(), InstID, Vals);
3088 if (CRI.hasUnwindDest())
3092 case Instruction::CatchRet: {
3094 const auto &CRI = cast<CatchReturnInst>(
I);
3095 pushValue(CRI.getCatchPad(), InstID, Vals);
3099 case Instruction::CleanupPad:
3100 case Instruction::CatchPad: {
3101 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3104 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3106 unsigned NumArgOperands = FuncletPad.arg_size();
3108 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3109 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3112 case Instruction::CatchSwitch: {
3114 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3116 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3118 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3120 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3123 if (CatchSwitch.hasUnwindDest())
3127 case Instruction::CallBr: {
3133 writeOperandBundles(*CBI, InstID);
3148 pushValueAndType(Callee, InstID, Vals);
3151 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3152 pushValue(
I.getOperand(i), InstID, Vals);
3155 if (FTy->isVarArg()) {
3156 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3157 pushValueAndType(
I.getOperand(i), InstID, Vals);
3161 case Instruction::Unreachable:
3163 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3166 case Instruction::PHI: {
3167 const PHINode &PN = cast<PHINode>(
I);
3184 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3189 case Instruction::LandingPad: {
3200 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3205 case Instruction::Alloca: {
3213 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3214 Bitfield::set<APV::AlignLower>(
3215 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3216 Bitfield::set<APV::AlignUpper>(
Record,
3217 EncodedAlign >> APV::AlignLower::Bits);
3219 Bitfield::set<APV::ExplicitType>(
Record,
true);
3224 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3229 case Instruction::Load:
3230 if (cast<LoadInst>(
I).isAtomic()) {
3232 pushValueAndType(
I.getOperand(0), InstID, Vals);
3235 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3236 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3240 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3241 if (cast<LoadInst>(
I).isAtomic()) {
3243 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3246 case Instruction::Store:
3247 if (cast<StoreInst>(
I).isAtomic())
3251 pushValueAndType(
I.getOperand(1), InstID, Vals);
3252 pushValueAndType(
I.getOperand(0), InstID, Vals);
3254 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3255 if (cast<StoreInst>(
I).isAtomic()) {
3258 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3261 case Instruction::AtomicCmpXchg:
3263 pushValueAndType(
I.getOperand(0), InstID, Vals);
3264 pushValueAndType(
I.getOperand(1), InstID, Vals);
3265 pushValue(
I.getOperand(2), InstID, Vals);
3266 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3270 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3273 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3276 case Instruction::AtomicRMW:
3278 pushValueAndType(
I.getOperand(0), InstID, Vals);
3279 pushValueAndType(
I.getOperand(1), InstID, Vals);
3282 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3285 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3288 case Instruction::Fence:
3291 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3293 case Instruction::Call: {
3298 writeOperandBundles(CI, InstID);
3318 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3320 if (FTy->getParamType(i)->isLabelTy())
3327 if (FTy->isVarArg()) {
3328 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3333 case Instruction::VAArg:
3336 pushValue(
I.getOperand(0), InstID, Vals);
3339 case Instruction::Freeze:
3341 pushValueAndType(
I.getOperand(0), InstID, Vals);
3351void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3357 VSTOffset -= bitcodeStartBit();
3358 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3362 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3366 auto Abbv = std::make_shared<BitCodeAbbrev>();
3370 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3375 if (
F.isDeclaration())
3382 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3383 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3387 Record[1] = BitcodeIndex / 32 + 1;
3396void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3411 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3417 if (isa<BasicBlock>(
Name.getValue())) {
3420 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3424 AbbrevToUse = VST_ENTRY_6_ABBREV;
3426 AbbrevToUse = VST_ENTRY_7_ABBREV;
3429 for (
const auto P :
Name.getKey())
3433 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3440void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3441 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3443 if (isa<BasicBlock>(Order.V))
3453void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3455 "Expected to be preserving use-list order");
3457 auto hasMore = [&]() {
3473void ModuleBitcodeWriter::writeFunction(
3492 unsigned CstStart, CstEnd;
3494 writeConstants(CstStart, CstEnd,
false);
3497 writeFunctionMetadata(
F);
3500 unsigned InstID = CstEnd;
3502 bool NeedsMetadataAttachment =
F.hasMetadata();
3510 writeInstruction(
I, InstID, Vals);
3512 if (!
I.getType()->isVoidTy())
3516 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3543 auto PushValueOrMetadata = [&Vals, InstID,
3545 assert(RawLocation &&
"RawLocation unexpectedly null in DPValue");
3551 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3565 for (
DbgRecord &DR :
I.DbgMarker->getDbgRecordRange()) {
3566 if (
DPLabel *DPL = dyn_cast<DPLabel>(&DR)) {
3584 DPValue &DPV = cast<DPValue>(DR);
3591 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3613 while (!Worklist.empty()) {
3614 Value *
V = Worklist.pop_back_val();
3615 for (
User *U :
V->users()) {
3616 if (
auto *
I = dyn_cast<Instruction>(U)) {
3620 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3621 Visited.insert(U).second)
3622 Worklist.push_back(U);
3628 if (!BlockAddressUsers.
empty()) {
3637 if (
auto *Symtab =
F.getValueSymbolTable())
3638 writeFunctionLevelValueSymbolTable(*Symtab);
3640 if (NeedsMetadataAttachment)
3641 writeFunctionMetadataAttachment(
F);
3643 writeUseListBlock(&
F);
3649void ModuleBitcodeWriter::writeBlockInfo() {
3656 auto Abbv = std::make_shared<BitCodeAbbrev>();
3667 auto Abbv = std::make_shared<BitCodeAbbrev>();
3677 auto Abbv = std::make_shared<BitCodeAbbrev>();
3687 auto Abbv = std::make_shared<BitCodeAbbrev>();
3693 VST_BBENTRY_6_ABBREV)
3698 auto Abbv = std::make_shared<BitCodeAbbrev>();
3703 CONSTANTS_SETTYPE_ABBREV)
3708 auto Abbv = std::make_shared<BitCodeAbbrev>();
3712 CONSTANTS_INTEGER_ABBREV)
3717 auto Abbv = std::make_shared<BitCodeAbbrev>();
3725 CONSTANTS_CE_CAST_Abbrev)
3729 auto Abbv = std::make_shared<BitCodeAbbrev>();
3732 CONSTANTS_NULL_Abbrev)
3739 auto Abbv = std::make_shared<BitCodeAbbrev>();
3747 FUNCTION_INST_LOAD_ABBREV)
3751 auto Abbv = std::make_shared<BitCodeAbbrev>();
3756 FUNCTION_INST_UNOP_ABBREV)
3760 auto Abbv = std::make_shared<BitCodeAbbrev>();
3766 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3770 auto Abbv = std::make_shared<BitCodeAbbrev>();
3776 FUNCTION_INST_BINOP_ABBREV)
3780 auto Abbv = std::make_shared<BitCodeAbbrev>();
3787 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3791 auto Abbv = std::make_shared<BitCodeAbbrev>();
3798 FUNCTION_INST_CAST_ABBREV)
3802 auto Abbv = std::make_shared<BitCodeAbbrev>();
3810 FUNCTION_INST_CAST_FLAGS_ABBREV)
3815 auto Abbv = std::make_shared<BitCodeAbbrev>();
3818 FUNCTION_INST_RET_VOID_ABBREV)
3822 auto Abbv = std::make_shared<BitCodeAbbrev>();
3826 FUNCTION_INST_RET_VAL_ABBREV)
3830 auto Abbv = std::make_shared<BitCodeAbbrev>();
3833 FUNCTION_INST_UNREACHABLE_ABBREV)
3837 auto Abbv = std::make_shared<BitCodeAbbrev>();
3845 FUNCTION_INST_GEP_ABBREV)
3849 auto Abbv = std::make_shared<BitCodeAbbrev>();
3856 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3864void IndexBitcodeWriter::writeModStrings() {
3870 auto Abbv = std::make_shared<BitCodeAbbrev>();
3875 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3878 Abbv = std::make_shared<BitCodeAbbrev>();
3883 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3886 Abbv = std::make_shared<BitCodeAbbrev>();
3891 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3894 Abbv = std::make_shared<BitCodeAbbrev>();
3901 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3906 const auto &Hash = MPSE.
getValue();
3908 unsigned AbbrevToUse = Abbrev8Bit;
3910 AbbrevToUse = Abbrev6Bit;
3912 AbbrevToUse = Abbrev7Bit;
3914 auto ModuleId = ModuleIdMap.
size();
3915 ModuleIdMap[
Key] = ModuleId;
3924 Vals.
assign(Hash.begin(), Hash.end());
3936template <
typename Fn>
3940 if (!FS->type_tests().empty())
3945 auto WriteVFuncIdVec = [&](
uint64_t Ty,
3950 for (
auto &VF : VFs) {
3951 Record.push_back(VF.GUID);
3952 Record.push_back(VF.Offset);
3958 FS->type_test_assume_vcalls());
3960 FS->type_checked_load_vcalls());
3962 auto WriteConstVCallVec = [&](
uint64_t Ty,
3964 for (
auto &VC : VCs) {
3966 Record.push_back(VC.VFunc.GUID);
3967 Record.push_back(VC.VFunc.Offset);
3974 FS->type_test_assume_const_vcalls());
3976 FS->type_checked_load_const_vcalls());
3980 assert(Range.getLower().getNumWords() == 1);
3981 assert(Range.getUpper().getNumWords() == 1);
3986 if (!FS->paramAccesses().empty()) {
3988 for (
auto &Arg : FS->paramAccesses()) {
3989 size_t UndoSize =
Record.size();
3990 Record.push_back(Arg.ParamNo);
3991 WriteRange(Arg.Use);
3992 Record.push_back(Arg.Calls.size());
3993 for (
auto &Call : Arg.Calls) {
3994 Record.push_back(Call.ParamNo);
3995 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4002 Record.push_back(*ValueID);
4003 WriteRange(Call.Offsets);
4014 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4015 if (!FS->type_tests().empty())
4016 for (
auto &TT : FS->type_tests())
4017 ReferencedTypeIds.insert(TT);
4019 auto GetReferencedTypesFromVFuncIdVec =
4021 for (
auto &VF : VFs)
4022 ReferencedTypeIds.insert(VF.GUID);
4025 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4026 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4028 auto GetReferencedTypesFromConstVCallVec =
4030 for (
auto &VC : VCs)
4031 ReferencedTypeIds.insert(VC.VFunc.GUID);
4034 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4035 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4066 const std::string &Id,
4071 NameVals.
push_back(Summary.TTRes.TheKind);
4072 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4073 NameVals.
push_back(Summary.TTRes.AlignLog2);
4074 NameVals.
push_back(Summary.TTRes.SizeM1);
4075 NameVals.
push_back(Summary.TTRes.BitMask);
4076 NameVals.
push_back(Summary.TTRes.InlineBits);
4078 for (
auto &W : Summary.WPDRes)
4090 for (
auto &
P : Summary) {
4098 unsigned AllocAbbrev,
bool PerModule,
4099 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4100 std::function<
unsigned(
unsigned)> GetStackIndex) {
4103 for (
auto &CI : FS->callsites()) {
4107 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4108 Record.push_back(GetValueID(CI.Callee));
4110 Record.push_back(CI.StackIdIndices.size());
4111 Record.push_back(CI.Clones.size());
4113 for (
auto Id : CI.StackIdIndices)
4114 Record.push_back(GetStackIndex(Id));
4116 for (
auto V : CI.Clones)
4124 for (
auto &AI : FS->allocs()) {
4128 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4130 Record.push_back(AI.MIBs.size());
4131 Record.push_back(AI.Versions.size());
4133 for (
auto &MIB : AI.MIBs) {
4134 Record.push_back((uint8_t)MIB.AllocType);
4135 Record.push_back(MIB.StackIdIndices.size());
4136 for (
auto Id : MIB.StackIdIndices)
4137 Record.push_back(GetStackIndex(Id));
4140 for (
auto V : AI.Versions)
4150void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4152 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4153 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4154 unsigned AllocAbbrev,
const Function &
F) {
4160 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4165 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4167 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4168 [&](
unsigned I) {
return I; });
4170 auto SpecialRefCnts =
FS->specialRefCounts();
4175 NameVals.
push_back(SpecialRefCnts.first);
4176 NameVals.
push_back(SpecialRefCnts.second);
4178 for (
auto &RI :
FS->refs())
4181 const bool UseRelBFRecord =
4184 for (
auto &ECI :
FS->calls()) {
4185 NameVals.
push_back(getValueId(ECI.first));
4193 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4204void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4206 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4207 auto VI =
Index->getValueInfo(
V.getGUID());
4208 if (!VI ||
VI.getSummaryList().empty()) {
4214 auto *
Summary =
VI.getSummaryList()[0].get();
4220 auto VTableFuncs =
VS->vTableFuncs();
4221 if (!VTableFuncs.empty())
4224 unsigned SizeBeforeRefs = NameVals.
size();
4225 for (
auto &RI :
VS->refs())
4231 if (VTableFuncs.empty())
4236 for (
auto &
P : VTableFuncs) {
4242 FSModVTableRefsAbbrev);
4249void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4252 bool IsThinLTO =
true;
4254 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4255 IsThinLTO = MD->getZExtValue();
4267 if (
Index->enableSplitLTOUnit())
4269 if (
Index->hasUnifiedLTO())
4279 for (
const auto &GVI : valueIds()) {
4284 if (!
Index->stackIds().empty()) {
4285 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4290 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4295 auto Abbv = std::make_shared<BitCodeAbbrev>();
4307 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4310 Abbv = std::make_shared<BitCodeAbbrev>();
4322 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4325 Abbv = std::make_shared<BitCodeAbbrev>();
4331 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4334 Abbv = std::make_shared<BitCodeAbbrev>();
4342 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4345 Abbv = std::make_shared<BitCodeAbbrev>();
4350 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4353 Abbv = std::make_shared<BitCodeAbbrev>();
4360 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4362 Abbv = std::make_shared<BitCodeAbbrev>();
4368 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4370 Abbv = std::make_shared<BitCodeAbbrev>();
4375 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4387 if (!VI ||
VI.getSummaryList().empty()) {
4393 auto *
Summary =
VI.getSummaryList()[0].get();
4394 writePerModuleFunctionSummaryRecord(
4395 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4396 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev,
F);
4402 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4403 FSModVTableRefsAbbrev);
4406 auto *Aliasee =
A.getAliaseeObject();
4409 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4422 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4426 TypeIdCompatibleVtableAbbrev);
4430 if (
Index->getBlockCount())
4438void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4447 for (
const auto &GVI : valueIds()) {
4452 if (!StackIdIndices.empty()) {
4453 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4458 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4461 std::vector<uint64_t> StackIds;
4462 for (
auto &
I : StackIdIndices)
4463 StackIds.push_back(
Index.getStackIdAtIndex(
I));
4468 auto Abbv = std::make_shared<BitCodeAbbrev>();
4482 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4485 Abbv = std::make_shared<BitCodeAbbrev>();
4492 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4495 Abbv = std::make_shared<BitCodeAbbrev>();
4501 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4503 Abbv = std::make_shared<BitCodeAbbrev>();
4511 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4513 Abbv = std::make_shared<BitCodeAbbrev>();
4521 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4534 std::set<GlobalValue::GUID> ReferencedTypeIds;
4548 NameVals.
push_back(S.getOriginalName());
4553 std::set<GlobalValue::GUID> DefOrUseGUIDs;
4554 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4557 DefOrUseGUIDs.insert(
I.first);
4559 DefOrUseGUIDs.insert(
VI.getGUID());
4561 auto ValueId = getValueId(
I.first);
4563 SummaryToValueIdMap[S] = *ValueId;
4571 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4578 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4581 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4584 for (
auto &RI :
VS->refs()) {
4585 auto RefValueId = getValueId(RI.getGUID());
4595 MaybeEmitOriginalName(*S);
4599 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
4601 return std::nullopt;
4602 return getValueId(
VI.getGUID());
4605 auto *
FS = cast<FunctionSummary>(S);
4610 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4613 std::optional<unsigned> ValueID = GetValueId(VI);
4627 return std::distance(StackIdIndices.begin(),
Lower);
4632 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4643 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4644 for (
auto &RI :
FS->refs()) {
4645 auto RefValueId = getValueId(RI.getGUID());
4649 if (RI.isReadOnly())
4651 else if (RI.isWriteOnly())
4655 NameVals[6] = Count;
4656 NameVals[7] = RORefCnt;
4657 NameVals[8] = WORefCnt;
4659 for (
auto &EI :
FS->calls()) {
4662 std::optional<unsigned> CallValueId = GetValueId(EI.first);
4671 FSCallsProfileAbbrev);
4673 MaybeEmitOriginalName(*S);
4676 for (
auto *AS : Aliases) {
4677 auto AliasValueId = SummaryToValueIdMap[AS];
4683 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
4690 MaybeEmitOriginalName(*AS);
4692 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
4696 if (!
Index.cfiFunctionDefs().empty()) {
4697 for (
auto &S :
Index.cfiFunctionDefs()) {
4698 if (DefOrUseGUIDs.count(
4704 if (!NameVals.
empty()) {
4710 if (!
Index.cfiFunctionDecls().empty()) {
4711 for (
auto &S :
Index.cfiFunctionDecls()) {
4712 if (DefOrUseGUIDs.count(
4718 if (!NameVals.
empty()) {
4726 for (
auto &
T : ReferencedTypeIds) {
4727 auto TidIter =
Index.typeIds().equal_range(
T);
4728 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4736 if (
Index.getBlockCount())
4749 auto Abbv = std::make_shared<BitCodeAbbrev>();
4753 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4755 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4758 Abbv = std::make_shared<BitCodeAbbrev>();
4761 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4767void ModuleBitcodeWriter::writeModuleHash(
size_t BlockStartPos) {
4773 Buffer.size() - BlockStartPos));
4774 std::array<uint8_t, 20> Hash = Hasher.result();
4775 for (
int Pos = 0; Pos < 20; Pos += 4) {
4788void ModuleBitcodeWriter::write() {
4792 size_t BlockStartPos = Buffer.size();
4794 writeModuleVersion();
4803 writeAttributeGroupTable();
4806 writeAttributeTable();
4815 writeModuleConstants();
4818 writeModuleMetadataKinds();
4821 writeModuleMetadata();
4825 writeUseListBlock(
nullptr);
4827 writeOperandBundleTags();
4828 writeSyncScopeNames();
4833 if (!
F.isDeclaration())
4834 writeFunction(
F, FunctionToBitcodeIndex);
4839 writePerModuleGlobalValueSummary();
4841 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4843 writeModuleHash(BlockStartPos);
4869 unsigned CPUType = ~0U;
4876 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4877 DARWIN_CPU_TYPE_X86 = 7,
4878 DARWIN_CPU_TYPE_ARM = 12,
4879 DARWIN_CPU_TYPE_POWERPC = 18
4884 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4886 CPUType = DARWIN_CPU_TYPE_X86;
4888 CPUType = DARWIN_CPU_TYPE_POWERPC;
4890 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4892 CPUType = DARWIN_CPU_TYPE_ARM;
4896 "Expected header size to be reserved");
4901 unsigned Position = 0;
4909 while (Buffer.
size() & 15)
4916 Stream.
Emit((
unsigned)
'B', 8);
4917 Stream.
Emit((
unsigned)
'C', 8);
4918 Stream.
Emit(0x0, 4);
4919 Stream.
Emit(0xC, 4);
4920 Stream.
Emit(0xE, 4);
4921 Stream.
Emit(0xD, 4);
4934 auto Abbv = std::make_shared<BitCodeAbbrev>();
4937 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
4945 assert(!WroteStrtab && !WroteSymtab);
4951 if (M->getModuleInlineAsm().empty())
4955 const Triple TT(M->getTargetTriple());
4957 if (!
T || !
T->hasMCAsmParser())
4979 std::vector<char> Strtab;
4981 Strtab.resize(StrtabBuilder.
getSize());
4982 StrtabBuilder.
write((uint8_t *)Strtab.data());
4985 {Strtab.data(), Strtab.size()});
4996 bool ShouldPreserveUseListOrder,
5005 assert(M.isMaterialized());
5006 Mods.push_back(
const_cast<Module *
>(&M));
5008 ModuleBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream,
5009 ShouldPreserveUseListOrder,
Index,
5010 GenerateHash, ModHash);
5011 ModuleWriter.write();
5016 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5017 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *
Index,
5018 ModuleToSummariesForIndex);
5019 IndexWriter.write();
5024 bool ShouldPreserveUseListOrder,
5032 Triple TT(M.getTargetTriple());
5033 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
5036 BitcodeWriter Writer(Buffer, dyn_cast<raw_fd_stream>(&Out));
5042 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
5046 if (!Buffer.
empty())
5050void IndexBitcodeWriter::write() {
5053 writeModuleVersion();
5059 writeCombinedGlobalValueSummary();
5070 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5084class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5094 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5096 ModHash(&ModHash) {}
5101 void writeSimplifiedModuleInfo();
5111void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5123 auto Abbv = std::make_shared<BitCodeAbbrev>();
5126 Abbv->Add(AbbrevOpToUse);
5127 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5129 for (
const auto P :
M.getSourceFileName())
5193void ThinLinkBitcodeWriter::write() {
5196 writeModuleVersion();
5198 writeSimplifiedModuleInfo();
5200 writePerModuleGlobalValueSummary();
5217 assert(M.isMaterialized());
5218 Mods.push_back(
const_cast<Module *
>(&M));
5220 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream,
Index,
5222 ThinLinkWriter.write();
5243 switch (
T.getObjectFormat()) {
5245 return "__LLVM,__bitcode";
5268 switch (
T.getObjectFormat()) {
5270 return "__LLVM,__cmdline";
5294 const std::vector<uint8_t> &CmdArgs) {
5300 for (
auto *GV : UsedGlobals) {
5301 if (GV->getName() !=
"llvm.embedded.module" &&
5302 GV->getName() !=
"llvm.cmdline")
5307 Used->eraseFromParent();
5312 Triple T(M.getTargetTriple());
5341 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5342 assert(Old->hasZeroLiveUses() &&
5343 "llvm.embedded.module can only be used once in llvm.compiler.used");
5345 Old->eraseFromParent();
5347 GV->
setName(
"llvm.embedded.module");
5365 assert(Old->hasZeroLiveUses() &&
5366 "llvm.cmdline can only be used once in llvm.compiler.used");
5368 Old->eraseFromParent();
5374 if (UsedArray.
empty())
5382 NewUsed->setSection(
"llvm.metadata");
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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...
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 writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *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 writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
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 unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
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 unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags)
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 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)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
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.
llvm::cl::opt< bool > UseNewDbgInfoFormat
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 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 emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR)
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 writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex)
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdSummary &Summary)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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 the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
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...
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
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),...
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static 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.
@ Min
*p = old <signed v ? old : v
@ 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.
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...
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
BitcodeWriter(SmallVectorImpl< char > &Buffer, raw_fd_stream *FS=nullptr)
Create a BitcodeWriter that writes to Buffer.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
void writeIndex(const ModuleSummaryIndex *Index, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex)
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.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
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 BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
bool isConditional() const
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
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 parameter 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
@ 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 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 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.
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)
Type array for a subprogram.
Records a position in IR for a source label (DILabel).
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIExpression * getExpression() const
DIExpression * getAddressExpression() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAddress() const
DIAssignID * getAssignID() const
DILocalVariable * getVariable() const
This class represents an Operation in the Expression.
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
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
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
@ 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.
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
BasicBlock * getUnwindDest() const
BasicBlock * getNormalDest() 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.
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.
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
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_MMXTyID
MMX vectors (64 bits, X86 specific)
@ 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
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
uint64_t computeBitsRequiredForTypeIndicies() 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.
void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
void takeName(Value *V)
Transfer the name from V to this value.
A raw_ostream of a file for reading/writing/seeking.
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_GLOBAL_VAR_EXPR
@ 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_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_CE_INBOUNDS_GEP
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE_INDEX
@ 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_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_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ 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)
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.
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.
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 are tuples (A,...
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 ...
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...
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
AtomicOrdering
Atomic ordering for LLVM's memory model.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
DWARFExpression::Operation Op
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.
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 Triple, 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