31#include "llvm/Config/llvm-config.h"
91 cl::desc(
"Number of metadatas above which we emit an index "
92 "to enable lazy-loading"));
95 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
99 cl::desc(
"Write relative block frequency to function summary "));
117 VST_BBENTRY_6_ABBREV,
121 CONSTANTS_INTEGER_ABBREV,
122 CONSTANTS_CE_CAST_Abbrev,
123 CONSTANTS_NULL_Abbrev,
127 FUNCTION_INST_UNOP_ABBREV,
128 FUNCTION_INST_UNOP_FLAGS_ABBREV,
129 FUNCTION_INST_BINOP_ABBREV,
130 FUNCTION_INST_BINOP_FLAGS_ABBREV,
131 FUNCTION_INST_CAST_ABBREV,
132 FUNCTION_INST_CAST_FLAGS_ABBREV,
133 FUNCTION_INST_RET_VOID_ABBREV,
134 FUNCTION_INST_RET_VAL_ABBREV,
135 FUNCTION_INST_UNREACHABLE_ABBREV,
136 FUNCTION_INST_GEP_ABBREV,
137 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
142class BitcodeWriterBase {
153 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
156 void writeModuleVersion();
159void BitcodeWriterBase::writeModuleVersion() {
166class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
180 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
183 unsigned GlobalValueId;
194 bool ShouldPreserveUseListOrder,
196 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
206 for (
const auto &GUIDSummaryLists : *Index)
208 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
209 if (
auto FS = dyn_cast<FunctionSummary>(
Summary.get())) {
214 for (
auto &CallEdge :
FS->calls())
215 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
216 assignValueId(CallEdge.first.getGUID());
222 for (
auto &RefEdge :
FS->refs())
223 if (!RefEdge.haveGVs() || !RefEdge.getValue())
224 assignValueId(RefEdge.getGUID());
229 void writePerModuleGlobalValueSummary();
232 void writePerModuleFunctionSummaryRecord(
234 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
235 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
240 unsigned FSModRefsAbbrev,
241 unsigned FSModVTableRefsAbbrev);
244 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
248 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
251 assert(VMI != GUIDToValueIdMap.end() &&
252 "GUID does not have assigned value Id");
258 if (!
VI.haveGVs() || !
VI.getValue())
259 return getValueId(
VI.getGUID());
263 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
267class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
287 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
288 ShouldPreserveUseListOrder,
Index),
289 GenerateHash(GenerateHash), ModHash(ModHash),
290 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
296 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
300 void writeAttributeGroupTable();
301 void writeAttributeTable();
302 void writeTypeTable();
304 void writeValueSymbolTableForwardDecl();
305 void writeModuleInfo();
310 unsigned createDILocationAbbrev();
313 unsigned createGenericDINodeAbbrev();
381 unsigned createNamedMetadataAbbrev();
383 unsigned createMetadataStringsAbbrev();
388 std::vector<unsigned> *MDAbbrevs =
nullptr,
389 std::vector<uint64_t> *IndexPos =
nullptr);
390 void writeModuleMetadata();
391 void writeFunctionMetadata(
const Function &
F);
392 void writeFunctionMetadataAttachment(
const Function &
F);
395 void writeModuleMetadataKinds();
396 void writeOperandBundleTags();
397 void writeSyncScopeNames();
398 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
399 void writeModuleConstants();
400 bool pushValueAndType(
const Value *V,
unsigned InstID,
402 bool pushValueOrMetadata(
const Value *V,
unsigned InstID,
404 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
405 void pushValue(
const Value *V,
unsigned InstID,
407 void pushValueSigned(
const Value *V,
unsigned InstID,
409 void writeInstruction(
const Instruction &
I,
unsigned InstID,
412 void writeGlobalValueSymbolTable(
415 void writeUseListBlock(
const Function *
F);
419 void writeBlockInfo();
426 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
430class IndexBitcodeWriter :
public BitcodeWriterBase {
445 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
449 std::vector<uint64_t> StackIds;
457 unsigned GlobalValueId = 0;
475 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
476 DecSummaries(DecSummaries),
477 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
481 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
486 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
488 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
495 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
496 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
502 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
508 for (
auto &CI :
FS->callsites()) {
519 if (CI.StackIdIndices.empty()) {
520 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
523 for (
auto Idx : CI.StackIdIndices)
524 RecordStackIdReference(
Idx);
526 for (
auto &AI :
FS->allocs())
527 for (
auto &MIB : AI.MIBs)
528 for (
auto Idx : MIB.StackIdIndices)
529 RecordStackIdReference(
Idx);
534 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
539 template<
typename Functor>
540 void forEachSummary(Functor Callback) {
541 if (ModuleToSummariesForIndex) {
542 for (
auto &M : *ModuleToSummariesForIndex)
543 for (
auto &Summary :
M.second) {
544 Callback(Summary,
false);
548 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
549 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
552 for (
auto &Summaries : Index)
553 for (
auto &Summary : Summaries.second.SummaryList)
554 Callback({Summaries.first,
Summary.get()},
false);
562 template <
typename Functor>
void forEachModule(Functor Callback) {
563 if (ModuleToSummariesForIndex) {
564 for (
const auto &M : *ModuleToSummariesForIndex) {
565 const auto &MPI =
Index.modulePaths().find(
M.first);
566 if (MPI ==
Index.modulePaths().end()) {
570 assert(ModuleToSummariesForIndex->size() == 1);
580 std::vector<StringRef> ModulePaths;
581 for (
auto &[ModPath,
_] :
Index.modulePaths())
582 ModulePaths.push_back(ModPath);
583 llvm::sort(ModulePaths.begin(), ModulePaths.end());
584 for (
auto &ModPath : ModulePaths)
585 Callback(*
Index.modulePaths().find(ModPath));
593 void writeModStrings();
594 void writeCombinedGlobalValueSummary();
597 auto VMI = GUIDToValueIdMap.find(ValGUID);
598 if (VMI == GUIDToValueIdMap.end())
603 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
637 case Instruction::Add:
639 case Instruction::Sub:
641 case Instruction::Mul:
644 case Instruction::FDiv:
647 case Instruction::FRem:
717 case Attribute::Alignment:
719 case Attribute::AllocAlign:
721 case Attribute::AllocSize:
723 case Attribute::AlwaysInline:
725 case Attribute::Builtin:
727 case Attribute::ByVal:
729 case Attribute::Convergent:
731 case Attribute::InAlloca:
733 case Attribute::Cold:
735 case Attribute::DisableSanitizerInstrumentation:
737 case Attribute::FnRetThunkExtern:
741 case Attribute::ElementType:
743 case Attribute::HybridPatchable:
745 case Attribute::InlineHint:
747 case Attribute::InReg:
749 case Attribute::JumpTable:
751 case Attribute::MinSize:
753 case Attribute::AllocatedPointer:
755 case Attribute::AllocKind:
757 case Attribute::Memory:
759 case Attribute::NoFPClass:
761 case Attribute::Naked:
763 case Attribute::Nest:
765 case Attribute::NoAlias:
767 case Attribute::NoBuiltin:
769 case Attribute::NoCallback:
771 case Attribute::NoDivergenceSource:
773 case Attribute::NoDuplicate:
775 case Attribute::NoFree:
777 case Attribute::NoImplicitFloat:
779 case Attribute::NoInline:
781 case Attribute::NoRecurse:
783 case Attribute::NoMerge:
785 case Attribute::NonLazyBind:
787 case Attribute::NonNull:
789 case Attribute::Dereferenceable:
791 case Attribute::DereferenceableOrNull:
793 case Attribute::NoRedZone:
795 case Attribute::NoReturn:
797 case Attribute::NoSync:
799 case Attribute::NoCfCheck:
801 case Attribute::NoProfile:
803 case Attribute::SkipProfile:
805 case Attribute::NoUnwind:
807 case Attribute::NoSanitizeBounds:
809 case Attribute::NoSanitizeCoverage:
811 case Attribute::NullPointerIsValid:
813 case Attribute::OptimizeForDebugging:
815 case Attribute::OptForFuzzing:
817 case Attribute::OptimizeForSize:
819 case Attribute::OptimizeNone:
821 case Attribute::ReadNone:
823 case Attribute::ReadOnly:
825 case Attribute::Returned:
827 case Attribute::ReturnsTwice:
829 case Attribute::SExt:
831 case Attribute::Speculatable:
833 case Attribute::StackAlignment:
835 case Attribute::StackProtect:
837 case Attribute::StackProtectReq:
839 case Attribute::StackProtectStrong:
841 case Attribute::SafeStack:
843 case Attribute::ShadowCallStack:
845 case Attribute::StrictFP:
847 case Attribute::StructRet:
849 case Attribute::SanitizeAddress:
851 case Attribute::SanitizeHWAddress:
853 case Attribute::SanitizeThread:
855 case Attribute::SanitizeType:
857 case Attribute::SanitizeMemory:
859 case Attribute::SanitizeNumericalStability:
861 case Attribute::SanitizeRealtime:
863 case Attribute::SanitizeRealtimeBlocking:
865 case Attribute::SpeculativeLoadHardening:
867 case Attribute::SwiftError:
869 case Attribute::SwiftSelf:
871 case Attribute::SwiftAsync:
873 case Attribute::UWTable:
875 case Attribute::VScaleRange:
877 case Attribute::WillReturn:
879 case Attribute::WriteOnly:
881 case Attribute::ZExt:
883 case Attribute::ImmArg:
885 case Attribute::SanitizeMemTag:
887 case Attribute::Preallocated:
889 case Attribute::NoUndef:
891 case Attribute::ByRef:
893 case Attribute::MustProgress:
895 case Attribute::PresplitCoroutine:
897 case Attribute::Writable:
899 case Attribute::CoroDestroyOnlyWhenComplete:
901 case Attribute::CoroElideSafe:
903 case Attribute::DeadOnUnwind:
905 case Attribute::Range:
907 case Attribute::Initializes:
909 case Attribute::NoExt:
911 case Attribute::Captures:
937 unsigned NumWords =
A.getActiveWords();
938 const uint64_t *RawData =
A.getRawData();
939 for (
unsigned i = 0; i < NumWords; i++)
959void ModuleBitcodeWriter::writeAttributeGroupTable() {
960 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
962 if (AttrGrps.empty())
return;
968 unsigned AttrListIndex = Pair.first;
971 Record.push_back(AttrListIndex);
974 if (Attr.isEnumAttribute()) {
977 }
else if (Attr.isIntAttribute()) {
980 Record.push_back(Attr.getValueAsInt());
981 }
else if (Attr.isStringAttribute()) {
992 }
else if (Attr.isTypeAttribute()) {
993 Type *Ty = Attr.getValueAsType();
994 Record.push_back(Ty ? 6 : 5);
998 }
else if (Attr.isConstantRangeAttribute()) {
1004 assert(Attr.isConstantRangeListAttribute());
1010 for (
auto &CR : Val)
1022void ModuleBitcodeWriter::writeAttributeTable() {
1024 if (
Attrs.empty())
return;
1030 for (
unsigned i :
AL.indexes()) {
1044void ModuleBitcodeWriter::writeTypeTable() {
1053 auto Abbv = std::make_shared<BitCodeAbbrev>();
1056 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1059 Abbv = std::make_shared<BitCodeAbbrev>();
1064 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1067 Abbv = std::make_shared<BitCodeAbbrev>();
1072 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1075 Abbv = std::make_shared<BitCodeAbbrev>();
1079 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1082 Abbv = std::make_shared<BitCodeAbbrev>();
1087 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1090 Abbv = std::make_shared<BitCodeAbbrev>();
1094 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1102 for (
Type *
T : TypeList) {
1103 int AbbrevToUse = 0;
1106 switch (
T->getTypeID()) {
1133 AbbrevToUse = OpaquePtrAbbrev;
1142 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1144 AbbrevToUse = FunctionAbbrev;
1152 for (
Type *ET :
ST->elements())
1155 if (
ST->isLiteral()) {
1157 AbbrevToUse = StructAnonAbbrev;
1159 if (
ST->isOpaque()) {
1163 AbbrevToUse = StructNamedAbbrev;
1167 if (!
ST->getName().empty())
1177 TypeVals.
push_back(AT->getNumElements());
1179 AbbrevToUse = ArrayAbbrev;
1188 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1190 if (isa<ScalableVectorType>(VT))
1200 for (
Type *InnerTy :
TET->type_params())
1202 for (
unsigned IntParam :
TET->int_params())
1211 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1252 RawFlags |= Flags.ReadNone;
1253 RawFlags |= (Flags.ReadOnly << 1);
1254 RawFlags |= (Flags.NoRecurse << 2);
1255 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1256 RawFlags |= (Flags.NoInline << 4);
1257 RawFlags |= (Flags.AlwaysInline << 5);
1258 RawFlags |= (Flags.NoUnwind << 6);
1259 RawFlags |= (Flags.MayThrow << 7);
1260 RawFlags |= (Flags.HasUnknownCall << 8);
1261 RawFlags |= (Flags.MustBeUnreachable << 9);
1268 bool ImportAsDecl =
false) {
1271 RawFlags |= Flags.NotEligibleToImport;
1272 RawFlags |= (Flags.Live << 1);
1273 RawFlags |= (Flags.DSOLocal << 2);
1274 RawFlags |= (Flags.CanAutoHide << 3);
1279 RawFlags = (RawFlags << 4) | Flags.Linkage;
1281 RawFlags |= (Flags.Visibility << 8);
1283 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1284 RawFlags |= (ImportType << 10);
1290 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1291 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1333 case GlobalVariable::NotThreadLocal:
return 0;
1334 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1335 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1336 case GlobalVariable::InitialExecTLSModel:
return 3;
1337 case GlobalVariable::LocalExecTLSModel:
return 4;
1343 switch (
C.getSelectionKind()) {
1360 case GlobalValue::UnnamedAddr::None:
return 0;
1361 case GlobalValue::UnnamedAddr::Local:
return 2;
1362 case GlobalValue::UnnamedAddr::Global:
return 1;
1367size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1370 return StrtabBuilder.
add(Str);
1373void ModuleBitcodeWriter::writeComdats() {
1388void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1393 auto Abbv = std::make_shared<BitCodeAbbrev>();
1399 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1415 bool isChar6 =
true;
1416 for (
char C : Str) {
1419 if ((
unsigned char)
C & 128)
1429 "Sanitizer Metadata is too large for naive serialization.");
1432 return Meta.NoAddress | (
Meta.NoHWAddress << 1) |
1433 (
Meta.Memtag << 2) | (
Meta.IsDynInit << 3);
1439void ModuleBitcodeWriter::writeModuleInfo() {
1441 if (!
M.getTargetTriple().empty())
1444 const std::string &
DL =
M.getDataLayoutStr();
1447 if (!
M.getModuleInlineAsm().empty())
1453 std::map<std::string, unsigned> SectionMap;
1454 std::map<std::string, unsigned> GCMap;
1456 unsigned MaxGlobalType = 0;
1457 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1459 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1462 UpdateMaxAlignment(GV.getAlign());
1463 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1464 if (GV.hasSection()) {
1466 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1470 Entry = SectionMap.size();
1475 UpdateMaxAlignment(
F.getAlign());
1476 if (
F.hasSection()) {
1478 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1482 Entry = SectionMap.size();
1487 unsigned &
Entry = GCMap[
F.getGC()];
1491 Entry = GCMap.size();
1497 unsigned SimpleGVarAbbrev = 0;
1498 if (!
M.global_empty()) {
1500 auto Abbv = std::make_shared<BitCodeAbbrev>();
1514 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1518 if (SectionMap.empty())
1524 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1538 auto Abbv = std::make_shared<BitCodeAbbrev>();
1541 Abbv->Add(AbbrevOpToUse);
1542 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1544 for (
const auto P :
M.getSourceFileName())
1554 unsigned AbbrevToUse = 0;
1560 Vals.
push_back(addToStrtab(GV.getName()));
1563 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1567 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1568 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1570 if (GV.isThreadLocal() ||
1572 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1573 GV.isExternallyInitialized() ||
1575 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1576 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1580 Vals.
push_back(GV.isExternallyInitialized());
1588 Vals.
push_back(addToStrtab(GV.getPartition()));
1589 Vals.
push_back(GV.getPartition().size());
1592 GV.getSanitizerMetadata())
1596 AbbrevToUse = SimpleGVarAbbrev;
1616 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1617 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1629 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1633 Vals.
push_back(addToStrtab(
F.getPartition()));
1636 unsigned AbbrevToUse = 0;
1649 Vals.
push_back(
A.getType()->getAddressSpace());
1657 Vals.
push_back(addToStrtab(
A.getPartition()));
1660 unsigned AbbrevToUse = 0;
1672 Vals.
push_back(
I.getType()->getAddressSpace());
1677 Vals.
push_back(addToStrtab(
I.getPartition()));
1683 writeValueSymbolTableForwardDecl();
1689 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1690 if (OBO->hasNoSignedWrap())
1692 if (OBO->hasNoUnsignedWrap())
1694 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1697 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1698 if (PDI->isDisjoint())
1700 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1701 if (FPMO->hasAllowReassoc())
1703 if (FPMO->hasNoNaNs())
1705 if (FPMO->hasNoInfs())
1707 if (FPMO->hasNoSignedZeros())
1709 if (FPMO->hasAllowReciprocal())
1711 if (FPMO->hasAllowContract())
1713 if (FPMO->hasApproxFunc())
1715 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1716 if (NNI->hasNonNeg())
1718 }
else if (
const auto *TI = dyn_cast<TruncInst>(V)) {
1719 if (TI->hasNoSignedWrap())
1721 if (TI->hasNoUnsignedWrap())
1723 }
else if (
const auto *
GEP = dyn_cast<GEPOperator>(V)) {
1724 if (
GEP->isInBounds())
1726 if (
GEP->hasNoUnsignedSignedWrap())
1728 if (
GEP->hasNoUnsignedWrap())
1730 }
else if (
const auto *ICmp = dyn_cast<ICmpInst>(V)) {
1731 if (ICmp->hasSameSign())
1738void ModuleBitcodeWriter::writeValueAsMetadata(
1748void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1753 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1754 "Unexpected function-local metadata");
1763unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1766 auto Abbv = std::make_shared<BitCodeAbbrev>();
1777void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1781 Abbrev = createDILocationAbbrev();
1783 Record.push_back(
N->isDistinct());
1784 Record.push_back(
N->getLine());
1785 Record.push_back(
N->getColumn());
1788 Record.push_back(
N->isImplicitCode());
1794unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1797 auto Abbv = std::make_shared<BitCodeAbbrev>();
1808void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1812 Abbrev = createGenericDINodeAbbrev();
1814 Record.push_back(
N->isDistinct());
1815 Record.push_back(
N->getTag());
1818 for (
auto &
I :
N->operands())
1825void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1839void ModuleBitcodeWriter::writeDIGenericSubrange(
1852void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1856 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1857 Record.push_back(
N->getValue().getBitWidth());
1865void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1868 Record.push_back(
N->isDistinct());
1869 Record.push_back(
N->getTag());
1871 Record.push_back(
N->getSizeInBits());
1872 Record.push_back(
N->getAlignInBits());
1873 Record.push_back(
N->getEncoding());
1874 Record.push_back(
N->getFlags());
1875 Record.push_back(
N->getNumExtraInhabitants());
1881void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1884 Record.push_back(
N->isDistinct());
1885 Record.push_back(
N->getTag());
1890 Record.push_back(
N->getSizeInBits());
1891 Record.push_back(
N->getAlignInBits());
1892 Record.push_back(
N->getEncoding());
1898void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1901 Record.push_back(
N->isDistinct());
1902 Record.push_back(
N->getTag());
1905 Record.push_back(
N->getLine());
1908 Record.push_back(
N->getSizeInBits());
1909 Record.push_back(
N->getAlignInBits());
1910 Record.push_back(
N->getOffsetInBits());
1911 Record.push_back(
N->getFlags());
1916 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1917 Record.push_back(*DWARFAddressSpace + 1);
1923 if (
auto PtrAuthData =
N->getPtrAuthData())
1924 Record.push_back(PtrAuthData->RawData);
1932void ModuleBitcodeWriter::writeDICompositeType(
1935 const unsigned IsNotUsedInOldTypeRef = 0x2;
1936 Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1937 Record.push_back(
N->getTag());
1940 Record.push_back(
N->getLine());
1943 Record.push_back(
N->getSizeInBits());
1944 Record.push_back(
N->getAlignInBits());
1945 Record.push_back(
N->getOffsetInBits());
1946 Record.push_back(
N->getFlags());
1948 Record.push_back(
N->getRuntimeLang());
1958 Record.push_back(
N->getNumExtraInhabitants());
1965void ModuleBitcodeWriter::writeDISubroutineType(
1968 const unsigned HasNoOldTypeRefs = 0x2;
1969 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1970 Record.push_back(
N->getFlags());
1978void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
1981 Record.push_back(
N->isDistinct());
1984 if (
N->getRawChecksum()) {
1985 Record.push_back(
N->getRawChecksum()->Kind);
1993 auto Source =
N->getRawSource();
2001void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
2004 assert(
N->isDistinct() &&
"Expected distinct compile units");
2006 Record.push_back(
N->getSourceLanguage());
2009 Record.push_back(
N->isOptimized());
2011 Record.push_back(
N->getRuntimeVersion());
2013 Record.push_back(
N->getEmissionKind());
2019 Record.push_back(
N->getDWOId());
2021 Record.push_back(
N->getSplitDebugInlining());
2022 Record.push_back(
N->getDebugInfoForProfiling());
2023 Record.push_back((
unsigned)
N->getNameTableKind());
2024 Record.push_back(
N->getRangesBaseAddress());
2032void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2035 const uint64_t HasUnitFlag = 1 << 1;
2036 const uint64_t HasSPFlagsFlag = 1 << 2;
2037 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2042 Record.push_back(
N->getLine());
2044 Record.push_back(
N->getScopeLine());
2046 Record.push_back(
N->getSPFlags());
2047 Record.push_back(
N->getVirtualIndex());
2048 Record.push_back(
N->getFlags());
2053 Record.push_back(
N->getThisAdjustment());
2065 Record.push_back(
N->isDistinct());
2068 Record.push_back(
N->getLine());
2069 Record.push_back(
N->getColumn());
2075void ModuleBitcodeWriter::writeDILexicalBlockFile(
2078 Record.push_back(
N->isDistinct());
2081 Record.push_back(
N->getDiscriminator());
2087void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2090 Record.push_back(
N->isDistinct());
2095 Record.push_back(
N->getLineNo());
2101void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2104 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2112void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2115 Record.push_back(
N->isDistinct());
2116 Record.push_back(
N->getMacinfoType());
2117 Record.push_back(
N->getLine());
2125void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2128 Record.push_back(
N->isDistinct());
2129 Record.push_back(
N->getMacinfoType());
2130 Record.push_back(
N->getLine());
2138void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2140 Record.reserve(
N->getArgs().size());
2148void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2151 Record.push_back(
N->isDistinct());
2152 for (
auto &
I :
N->operands())
2154 Record.push_back(
N->getLineNo());
2155 Record.push_back(
N->getIsDecl());
2161void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2165 Record.push_back(
N->isDistinct());
2170void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2173 Record.push_back(
N->isDistinct());
2176 Record.push_back(
N->isDefault());
2182void ModuleBitcodeWriter::writeDITemplateValueParameter(
2185 Record.push_back(
N->isDistinct());
2186 Record.push_back(
N->getTag());
2189 Record.push_back(
N->isDefault());
2196void ModuleBitcodeWriter::writeDIGlobalVariable(
2205 Record.push_back(
N->getLine());
2207 Record.push_back(
N->isLocalToUnit());
2208 Record.push_back(
N->isDefinition());
2211 Record.push_back(
N->getAlignInBits());
2218void ModuleBitcodeWriter::writeDILocalVariable(
2234 const uint64_t HasAlignmentFlag = 1 << 1;
2239 Record.push_back(
N->getLine());
2241 Record.push_back(
N->getArg());
2242 Record.push_back(
N->getFlags());
2243 Record.push_back(
N->getAlignInBits());
2250void ModuleBitcodeWriter::writeDILabel(
2257 Record.push_back(
N->getLine());
2263void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2266 Record.reserve(
N->getElements().size() + 1);
2269 Record.append(
N->elements_begin(),
N->elements_end());
2275void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2278 Record.push_back(
N->isDistinct());
2289 Record.push_back(
N->isDistinct());
2292 Record.push_back(
N->getLine());
2295 Record.push_back(
N->getAttributes());
2302void ModuleBitcodeWriter::writeDIImportedEntity(
2305 Record.push_back(
N->isDistinct());
2306 Record.push_back(
N->getTag());
2309 Record.push_back(
N->getLine());
2318unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2319 auto Abbv = std::make_shared<BitCodeAbbrev>();
2326void ModuleBitcodeWriter::writeNamedMetadata(
2328 if (
M.named_metadata_empty())
2331 unsigned Abbrev = createNamedMetadataAbbrev();
2335 Record.append(Str.bytes_begin(), Str.bytes_end());
2340 for (
const MDNode *
N : NMD.operands())
2347unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2348 auto Abbv = std::make_shared<BitCodeAbbrev>();
2360void ModuleBitcodeWriter::writeMetadataStrings(
2362 if (Strings.empty())
2367 Record.push_back(Strings.size());
2374 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2383 Blob.
append(cast<MDString>(MD)->getString());
2392#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2393#include "llvm/IR/Metadata.def"
2397void ModuleBitcodeWriter::writeMetadataRecords(
2399 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2404#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2405#include "llvm/IR/Metadata.def"
2410 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2411 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2413 switch (
N->getMetadataID()) {
2416#define HANDLE_MDNODE_LEAF(CLASS) \
2417 case Metadata::CLASS##Kind: \
2419 write##CLASS(cast<CLASS>(N), Record, \
2420 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2422 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2424#include "llvm/IR/Metadata.def"
2427 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2431 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2435void ModuleBitcodeWriter::writeModuleMetadata() {
2436 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2444 std::vector<unsigned> MDAbbrevs;
2447 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2448 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2449 createGenericDINodeAbbrev();
2451 auto Abbv = std::make_shared<BitCodeAbbrev>();
2455 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2457 Abbv = std::make_shared<BitCodeAbbrev>();
2461 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2483 std::vector<uint64_t> IndexPos;
2498 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2499 for (
auto &Elt : IndexPos) {
2500 auto EltDelta = Elt - PreviousValue;
2501 PreviousValue = Elt;
2510 writeNamedMetadata(
Record);
2512 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2515 pushGlobalMetadataAttachment(
Record, GO);
2519 if (
F.isDeclaration() &&
F.hasMetadata())
2520 AddDeclAttachedMetadata(
F);
2524 if (GV.hasMetadata())
2525 AddDeclAttachedMetadata(GV);
2530void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2541void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2546 for (
const auto &
I : MDs) {
2552void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2557 if (
F.hasMetadata()) {
2558 pushGlobalMetadataAttachment(
Record,
F);
2569 I.getAllMetadataOtherThanDebugLoc(MDs);
2572 if (MDs.
empty())
continue;
2576 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2577 Record.push_back(MDs[i].first);
2587void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2593 M.getMDKindNames(Names);
2595 if (Names.
empty())
return;
2599 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2600 Record.push_back(MDKindID);
2611void ModuleBitcodeWriter::writeOperandBundleTags() {
2619 M.getOperandBundleTags(Tags);
2628 for (
auto Tag : Tags) {
2638void ModuleBitcodeWriter::writeSyncScopeNames() {
2640 M.getContext().getSyncScopeNames(SSNs);
2647 for (
auto SSN : SSNs) {
2648 Record.append(SSN.begin(), SSN.end());
2656void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2658 if (FirstVal == LastVal)
return;
2662 unsigned AggregateAbbrev = 0;
2663 unsigned String8Abbrev = 0;
2664 unsigned CString7Abbrev = 0;
2665 unsigned CString6Abbrev = 0;
2669 auto Abbv = std::make_shared<BitCodeAbbrev>();
2673 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2676 Abbv = std::make_shared<BitCodeAbbrev>();
2680 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2682 Abbv = std::make_shared<BitCodeAbbrev>();
2686 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2688 Abbv = std::make_shared<BitCodeAbbrev>();
2692 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2698 Type *LastTy =
nullptr;
2699 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2700 const Value *
V = Vals[i].first;
2702 if (
V->getType() != LastTy) {
2703 LastTy =
V->getType();
2706 CONSTANTS_SETTYPE_ABBREV);
2710 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2713 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2714 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2717 const std::string &AsmStr =
IA->getAsmString();
2718 Record.push_back(AsmStr.size());
2719 Record.append(AsmStr.begin(), AsmStr.end());
2722 const std::string &ConstraintStr =
IA->getConstraintString();
2723 Record.push_back(ConstraintStr.size());
2724 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2730 unsigned Code = -1U;
2731 unsigned AbbrevToUse = 0;
2732 if (
C->isNullValue()) {
2734 }
else if (isa<PoisonValue>(
C)) {
2736 }
else if (isa<UndefValue>(
C)) {
2739 if (
IV->getBitWidth() <= 64) {
2743 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2748 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2753 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2757 APInt api = CFP->getValueAPF().bitcastToAPInt();
2759 Record.push_back((p[1] << 48) | (p[0] >> 16));
2760 Record.push_back(p[0] & 0xffffLL);
2762 APInt api = CFP->getValueAPF().bitcastToAPInt();
2767 assert(0 &&
"Unknown FP type!");
2769 }
else if (isa<ConstantDataSequential>(
C) &&
2770 cast<ConstantDataSequential>(
C)->isString()) {
2773 unsigned NumElts = Str->getNumElements();
2775 if (Str->isCString()) {
2780 AbbrevToUse = String8Abbrev;
2784 for (
unsigned i = 0; i != NumElts; ++i) {
2785 unsigned char V = Str->getElementAsInteger(i);
2787 isCStr7 &= (
V & 128) == 0;
2793 AbbrevToUse = CString6Abbrev;
2795 AbbrevToUse = CString7Abbrev;
2797 dyn_cast<ConstantDataSequential>(
C)) {
2799 Type *EltTy = CDS->getElementType();
2800 if (isa<IntegerType>(EltTy)) {
2801 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2802 Record.push_back(CDS->getElementAsInteger(i));
2804 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2806 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2808 }
else if (isa<ConstantAggregate>(
C)) {
2810 for (
const Value *
Op :
C->operands())
2812 AbbrevToUse = AggregateAbbrev;
2813 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2814 switch (
CE->getOpcode()) {
2821 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2823 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2833 case Instruction::FNeg: {
2834 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2843 case Instruction::GetElementPtr: {
2845 const auto *GO = cast<GEPOperator>(
C);
2848 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2852 for (
const Value *
Op :
CE->operands()) {
2858 case Instruction::ExtractElement:
2865 case Instruction::InsertElement:
2872 case Instruction::ShuffleVector:
2877 if (
C->getType() ==
C->getOperand(0)->getType()) {
2888 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2893 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2897 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
2901 }
else if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C)) {
2920void ModuleBitcodeWriter::writeModuleConstants() {
2925 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2926 if (!isa<GlobalValue>(Vals[i].first)) {
2927 writeConstants(i, Vals.size(),
true);
2941bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2946 if (
ValID >= InstID) {
2953bool ModuleBitcodeWriter::pushValueOrMetadata(
const Value *V,
unsigned InstID,
2955 bool IsMetadata =
V->getType()->isMetadataTy();
2958 Metadata *MD = cast<MetadataAsValue>(V)->getMetadata();
2963 return pushValueAndType(V, InstID, Vals);
2966void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
2973 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2975 for (
auto &Input : Bundle.Inputs)
2976 pushValueOrMetadata(Input, InstID,
Record);
2985void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2991void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2994 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2999void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
3003 unsigned AbbrevToUse = 0;
3005 switch (
I.getOpcode()) {
3009 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3010 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
3015 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
3016 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
3020 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
3022 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3023 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
3024 pushValue(
I.getOperand(1), InstID, Vals);
3028 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
3029 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
3034 case Instruction::FNeg: {
3036 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3037 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
3041 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3042 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3047 case Instruction::GetElementPtr: {
3049 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3050 auto &GEPInst = cast<GetElementPtrInst>(
I);
3053 for (
const Value *
Op :
I.operands())
3054 pushValueAndType(
Op, InstID, Vals);
3057 case Instruction::ExtractValue: {
3059 pushValueAndType(
I.getOperand(0), InstID, Vals);
3064 case Instruction::InsertValue: {
3066 pushValueAndType(
I.getOperand(0), InstID, Vals);
3067 pushValueAndType(
I.getOperand(1), InstID, Vals);
3072 case Instruction::Select: {
3074 pushValueAndType(
I.getOperand(1), InstID, Vals);
3075 pushValue(
I.getOperand(2), InstID, Vals);
3076 pushValueAndType(
I.getOperand(0), InstID, Vals);
3082 case Instruction::ExtractElement:
3084 pushValueAndType(
I.getOperand(0), InstID, Vals);
3085 pushValueAndType(
I.getOperand(1), InstID, Vals);
3087 case Instruction::InsertElement:
3089 pushValueAndType(
I.getOperand(0), InstID, Vals);
3090 pushValue(
I.getOperand(1), InstID, Vals);
3091 pushValueAndType(
I.getOperand(2), InstID, Vals);
3093 case Instruction::ShuffleVector:
3095 pushValueAndType(
I.getOperand(0), InstID, Vals);
3096 pushValue(
I.getOperand(1), InstID, Vals);
3097 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3100 case Instruction::ICmp:
3101 case Instruction::FCmp: {
3104 pushValueAndType(
I.getOperand(0), InstID, Vals);
3105 pushValue(
I.getOperand(1), InstID, Vals);
3113 case Instruction::Ret:
3116 unsigned NumOperands =
I.getNumOperands();
3117 if (NumOperands == 0)
3118 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3119 else if (NumOperands == 1) {
3120 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3121 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3123 for (
const Value *
Op :
I.operands())
3124 pushValueAndType(
Op, InstID, Vals);
3128 case Instruction::Br:
3133 if (
II.isConditional()) {
3135 pushValue(
II.getCondition(), InstID, Vals);
3139 case Instruction::Switch:
3144 pushValue(
SI.getCondition(), InstID, Vals);
3146 for (
auto Case :
SI.cases()) {
3152 case Instruction::IndirectBr:
3156 pushValue(
I.getOperand(0), InstID, Vals);
3161 case Instruction::Invoke: {
3166 if (
II->hasOperandBundles())
3167 writeOperandBundles(*
II, InstID);
3176 pushValueAndType(Callee, InstID, Vals);
3179 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3180 pushValue(
I.getOperand(i), InstID, Vals);
3183 if (FTy->isVarArg()) {
3184 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3185 pushValueAndType(
I.getOperand(i), InstID, Vals);
3189 case Instruction::Resume:
3191 pushValueAndType(
I.getOperand(0), InstID, Vals);
3193 case Instruction::CleanupRet: {
3195 const auto &CRI = cast<CleanupReturnInst>(
I);
3196 pushValue(CRI.getCleanupPad(), InstID, Vals);
3197 if (CRI.hasUnwindDest())
3201 case Instruction::CatchRet: {
3203 const auto &CRI = cast<CatchReturnInst>(
I);
3204 pushValue(CRI.getCatchPad(), InstID, Vals);
3208 case Instruction::CleanupPad:
3209 case Instruction::CatchPad: {
3210 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3213 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3215 unsigned NumArgOperands = FuncletPad.arg_size();
3217 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3218 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3221 case Instruction::CatchSwitch: {
3223 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3225 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3227 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3229 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3232 if (CatchSwitch.hasUnwindDest())
3236 case Instruction::CallBr: {
3242 writeOperandBundles(*CBI, InstID);
3257 pushValueAndType(Callee, InstID, Vals);
3260 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3261 pushValue(
I.getOperand(i), InstID, Vals);
3264 if (FTy->isVarArg()) {
3265 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3266 pushValueAndType(
I.getOperand(i), InstID, Vals);
3270 case Instruction::Unreachable:
3272 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3275 case Instruction::PHI: {
3276 const PHINode &PN = cast<PHINode>(
I);
3293 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3298 case Instruction::LandingPad: {
3309 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3314 case Instruction::Alloca: {
3322 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3323 Bitfield::set<APV::AlignLower>(
3324 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3325 Bitfield::set<APV::AlignUpper>(
Record,
3326 EncodedAlign >> APV::AlignLower::Bits);
3328 Bitfield::set<APV::ExplicitType>(
Record,
true);
3333 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3338 case Instruction::Load:
3339 if (cast<LoadInst>(
I).isAtomic()) {
3341 pushValueAndType(
I.getOperand(0), InstID, Vals);
3344 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3345 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3349 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3350 if (cast<LoadInst>(
I).isAtomic()) {
3352 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3355 case Instruction::Store:
3356 if (cast<StoreInst>(
I).isAtomic())
3360 pushValueAndType(
I.getOperand(1), InstID, Vals);
3361 pushValueAndType(
I.getOperand(0), InstID, Vals);
3363 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3364 if (cast<StoreInst>(
I).isAtomic()) {
3367 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3370 case Instruction::AtomicCmpXchg:
3372 pushValueAndType(
I.getOperand(0), InstID, Vals);
3373 pushValueAndType(
I.getOperand(1), InstID, Vals);
3374 pushValue(
I.getOperand(2), InstID, Vals);
3375 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3379 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3382 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3385 case Instruction::AtomicRMW:
3387 pushValueAndType(
I.getOperand(0), InstID, Vals);
3388 pushValueAndType(
I.getOperand(1), InstID, Vals);
3391 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3394 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3397 case Instruction::Fence:
3400 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3402 case Instruction::Call: {
3407 writeOperandBundles(CI, InstID);
3427 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3429 if (FTy->getParamType(i)->isLabelTy())
3436 if (FTy->isVarArg()) {
3437 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3442 case Instruction::VAArg:
3445 pushValue(
I.getOperand(0), InstID, Vals);
3448 case Instruction::Freeze:
3450 pushValueAndType(
I.getOperand(0), InstID, Vals);
3460void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3466 VSTOffset -= bitcodeStartBit();
3467 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3471 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3475 auto Abbv = std::make_shared<BitCodeAbbrev>();
3479 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3484 if (
F.isDeclaration())
3491 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3492 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3496 Record[1] = BitcodeIndex / 32 + 1;
3505void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3520 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3526 if (isa<BasicBlock>(
Name.getValue())) {
3529 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3533 AbbrevToUse = VST_ENTRY_6_ABBREV;
3535 AbbrevToUse = VST_ENTRY_7_ABBREV;
3538 for (
const auto P :
Name.getKey())
3542 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3549void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3550 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3552 if (isa<BasicBlock>(Order.V))
3562void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3564 "Expected to be preserving use-list order");
3566 auto hasMore = [&]() {
3582void ModuleBitcodeWriter::writeFunction(
3601 unsigned CstStart, CstEnd;
3603 writeConstants(CstStart, CstEnd,
false);
3606 writeFunctionMetadata(
F);
3609 unsigned InstID = CstEnd;
3611 bool NeedsMetadataAttachment =
F.hasMetadata();
3619 writeInstruction(
I, InstID, Vals);
3621 if (!
I.getType()->isVoidTy())
3625 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3652 auto PushValueOrMetadata = [&Vals, InstID,
3655 "RawLocation unexpectedly null in DbgVariableRecord");
3661 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3675 for (
DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3701 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3723 while (!Worklist.empty()) {
3724 Value *
V = Worklist.pop_back_val();
3725 for (
User *U :
V->users()) {
3726 if (
auto *
I = dyn_cast<Instruction>(U)) {
3730 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3731 Visited.insert(U).second)
3732 Worklist.push_back(U);
3738 if (!BlockAddressUsers.
empty()) {
3747 if (
auto *Symtab =
F.getValueSymbolTable())
3748 writeFunctionLevelValueSymbolTable(*Symtab);
3750 if (NeedsMetadataAttachment)
3751 writeFunctionMetadataAttachment(
F);
3753 writeUseListBlock(&
F);
3759void ModuleBitcodeWriter::writeBlockInfo() {
3766 auto Abbv = std::make_shared<BitCodeAbbrev>();
3777 auto Abbv = std::make_shared<BitCodeAbbrev>();
3787 auto Abbv = std::make_shared<BitCodeAbbrev>();
3797 auto Abbv = std::make_shared<BitCodeAbbrev>();
3803 VST_BBENTRY_6_ABBREV)
3808 auto Abbv = std::make_shared<BitCodeAbbrev>();
3813 CONSTANTS_SETTYPE_ABBREV)
3818 auto Abbv = std::make_shared<BitCodeAbbrev>();
3822 CONSTANTS_INTEGER_ABBREV)
3827 auto Abbv = std::make_shared<BitCodeAbbrev>();
3835 CONSTANTS_CE_CAST_Abbrev)
3839 auto Abbv = std::make_shared<BitCodeAbbrev>();
3842 CONSTANTS_NULL_Abbrev)
3849 auto Abbv = std::make_shared<BitCodeAbbrev>();
3857 FUNCTION_INST_LOAD_ABBREV)
3861 auto Abbv = std::make_shared<BitCodeAbbrev>();
3866 FUNCTION_INST_UNOP_ABBREV)
3870 auto Abbv = std::make_shared<BitCodeAbbrev>();
3876 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3880 auto Abbv = std::make_shared<BitCodeAbbrev>();
3886 FUNCTION_INST_BINOP_ABBREV)
3890 auto Abbv = std::make_shared<BitCodeAbbrev>();
3897 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3901 auto Abbv = std::make_shared<BitCodeAbbrev>();
3908 FUNCTION_INST_CAST_ABBREV)
3912 auto Abbv = std::make_shared<BitCodeAbbrev>();
3920 FUNCTION_INST_CAST_FLAGS_ABBREV)
3925 auto Abbv = std::make_shared<BitCodeAbbrev>();
3928 FUNCTION_INST_RET_VOID_ABBREV)
3932 auto Abbv = std::make_shared<BitCodeAbbrev>();
3936 FUNCTION_INST_RET_VAL_ABBREV)
3940 auto Abbv = std::make_shared<BitCodeAbbrev>();
3943 FUNCTION_INST_UNREACHABLE_ABBREV)
3947 auto Abbv = std::make_shared<BitCodeAbbrev>();
3955 FUNCTION_INST_GEP_ABBREV)
3959 auto Abbv = std::make_shared<BitCodeAbbrev>();
3966 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3974void IndexBitcodeWriter::writeModStrings() {
3980 auto Abbv = std::make_shared<BitCodeAbbrev>();
3985 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3988 Abbv = std::make_shared<BitCodeAbbrev>();
3993 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3996 Abbv = std::make_shared<BitCodeAbbrev>();
4001 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
4004 Abbv = std::make_shared<BitCodeAbbrev>();
4011 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
4016 const auto &Hash = MPSE.
getValue();
4018 unsigned AbbrevToUse = Abbrev8Bit;
4020 AbbrevToUse = Abbrev6Bit;
4022 AbbrevToUse = Abbrev7Bit;
4024 auto ModuleId = ModuleIdMap.
size();
4025 ModuleIdMap[
Key] = ModuleId;
4034 Vals.
assign(Hash.begin(), Hash.end());
4046template <
typename Fn>
4050 if (!FS->type_tests().empty())
4055 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4060 for (
auto &VF : VFs) {
4061 Record.push_back(VF.GUID);
4062 Record.push_back(VF.Offset);
4068 FS->type_test_assume_vcalls());
4070 FS->type_checked_load_vcalls());
4072 auto WriteConstVCallVec = [&](
uint64_t Ty,
4074 for (
auto &VC : VCs) {
4076 Record.push_back(VC.VFunc.GUID);
4077 Record.push_back(VC.VFunc.Offset);
4084 FS->type_test_assume_const_vcalls());
4086 FS->type_checked_load_const_vcalls());
4096 if (!FS->paramAccesses().empty()) {
4098 for (
auto &Arg : FS->paramAccesses()) {
4099 size_t UndoSize =
Record.size();
4100 Record.push_back(Arg.ParamNo);
4101 WriteRange(Arg.Use);
4102 Record.push_back(Arg.Calls.size());
4103 for (
auto &Call : Arg.Calls) {
4104 Record.push_back(Call.ParamNo);
4105 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4112 Record.push_back(*ValueID);
4113 WriteRange(Call.Offsets);
4124 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4125 if (!FS->type_tests().empty())
4126 for (
auto &TT : FS->type_tests())
4127 ReferencedTypeIds.insert(TT);
4129 auto GetReferencedTypesFromVFuncIdVec =
4131 for (
auto &VF : VFs)
4132 ReferencedTypeIds.insert(VF.GUID);
4135 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4136 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4138 auto GetReferencedTypesFromConstVCallVec =
4140 for (
auto &VC : VCs)
4141 ReferencedTypeIds.insert(VC.VFunc.GUID);
4144 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4145 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4181 NameVals.
push_back(Summary.TTRes.TheKind);
4182 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4183 NameVals.
push_back(Summary.TTRes.AlignLog2);
4184 NameVals.
push_back(Summary.TTRes.SizeM1);
4185 NameVals.
push_back(Summary.TTRes.BitMask);
4186 NameVals.
push_back(Summary.TTRes.InlineBits);
4188 for (
auto &W : Summary.WPDRes)
4200 for (
auto &
P : Summary) {
4216 static_assert(std::is_same_v<LinearFrameId, unsigned>);
4217 for (
auto &AI : FS->allocs()) {
4218 for (
auto &MIB : AI.MIBs) {
4220 StackIdIndices.
reserve(MIB.StackIdIndices.size());
4221 for (
auto Id : MIB.StackIdIndices)
4222 StackIdIndices.
push_back(GetStackIndex(Id));
4224 CallStacks.insert({CallStacks.size(), StackIdIndices});
4237 assert(!CallStacks.empty());
4243 Builder.
build(std::move(CallStacks),
nullptr,
4252 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
bool PerModule,
4253 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4254 std::function<
unsigned(
unsigned)> GetStackIndex,
4255 bool WriteContextSizeInfoIndex,
4260 for (
auto &CI : FS->callsites()) {
4264 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4265 Record.push_back(GetValueID(CI.Callee));
4267 Record.push_back(CI.StackIdIndices.size());
4268 Record.push_back(CI.Clones.size());
4270 for (
auto Id : CI.StackIdIndices)
4271 Record.push_back(GetStackIndex(Id));
4273 for (
auto V : CI.Clones)
4281 for (
auto &AI : FS->allocs()) {
4285 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4286 Record.push_back(AI.MIBs.size());
4288 Record.push_back(AI.Versions.size());
4289 for (
auto &MIB : AI.MIBs) {
4292 assert(CallStackCount <= CallStackPos.
size());
4293 Record.push_back(CallStackPos[CallStackCount++]);
4296 for (
auto V : AI.Versions)
4299 assert(AI.ContextSizeInfos.empty() ||
4300 AI.ContextSizeInfos.size() == AI.MIBs.size());
4302 if (WriteContextSizeInfoIndex && !AI.ContextSizeInfos.empty()) {
4310 ContextIds.
reserve(AI.ContextSizeInfos.size() * 2);
4311 for (
auto &Infos : AI.ContextSizeInfos) {
4312 Record.push_back(Infos.size());
4313 for (
auto [FullStackId, TotalSize] : Infos) {
4320 Record.push_back(TotalSize);
4335void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4337 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4338 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4339 unsigned AllocAbbrev,
unsigned ContextIdAbbvId,
const Function &
F,
4347 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4352 Stream, FS, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
4354 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4355 [&](
unsigned I) {
return I; },
4356 true, CallStackPos, CallStackCount);
4358 auto SpecialRefCnts =
FS->specialRefCounts();
4363 NameVals.
push_back(SpecialRefCnts.first);
4364 NameVals.
push_back(SpecialRefCnts.second);
4366 for (
auto &RI :
FS->refs())
4369 const bool UseRelBFRecord =
4372 for (
auto &ECI :
FS->calls()) {
4373 NameVals.
push_back(getValueId(ECI.first));
4381 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4392void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4394 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4395 auto VI =
Index->getValueInfo(
V.getGUID());
4396 if (!VI ||
VI.getSummaryList().empty()) {
4402 auto *
Summary =
VI.getSummaryList()[0].get();
4408 auto VTableFuncs =
VS->vTableFuncs();
4409 if (!VTableFuncs.empty())
4412 unsigned SizeBeforeRefs = NameVals.
size();
4413 for (
auto &RI :
VS->refs())
4419 if (VTableFuncs.empty())
4424 for (
auto &
P : VTableFuncs) {
4430 FSModVTableRefsAbbrev);
4437void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4440 bool IsThinLTO =
true;
4442 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4443 IsThinLTO = MD->getZExtValue();
4455 if (
Index->enableSplitLTOUnit())
4457 if (
Index->hasUnifiedLTO())
4467 auto Abbv = std::make_shared<BitCodeAbbrev>();
4473 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4475 for (
const auto &GVI : valueIds()) {
4478 static_cast<uint32_t>(GVI.first >> 32),
4483 if (!
Index->stackIds().empty()) {
4484 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4491 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4494 for (
auto Id :
Index->stackIds()) {
4502 auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>();
4508 unsigned ContextIdAbbvId = Stream.
EmitAbbrev(std::move(ContextIdAbbv));
4511 Abbv = std::make_shared<BitCodeAbbrev>();
4523 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4526 Abbv = std::make_shared<BitCodeAbbrev>();
4538 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4541 Abbv = std::make_shared<BitCodeAbbrev>();
4547 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4550 Abbv = std::make_shared<BitCodeAbbrev>();
4558 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4561 Abbv = std::make_shared<BitCodeAbbrev>();
4566 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4569 Abbv = std::make_shared<BitCodeAbbrev>();
4576 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4578 Abbv = std::make_shared<BitCodeAbbrev>();
4584 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4586 Abbv = std::make_shared<BitCodeAbbrev>();
4593 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4595 Abbv = std::make_shared<BitCodeAbbrev>();
4600 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4615 if (!VI ||
VI.getSummaryList().empty()) {
4621 auto *
Summary =
VI.getSummaryList()[0].get();
4624 FS, [](
unsigned I) {
return I; }, CallStacks);
4629 if (!CallStacks.
empty()) {
4647 if (!VI ||
VI.getSummaryList().empty()) {
4653 auto *
Summary =
VI.getSummaryList()[0].get();
4654 writePerModuleFunctionSummaryRecord(
4655 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4656 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev, ContextIdAbbvId,
F,
4657 CallStackPos, CallStackCount);
4663 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4664 FSModVTableRefsAbbrev);
4667 auto *Aliasee =
A.getAliaseeObject();
4670 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4683 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4687 TypeIdCompatibleVtableAbbrev);
4691 if (
Index->getBlockCount())
4699void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4708 auto Abbv = std::make_shared<BitCodeAbbrev>();
4714 unsigned ValueGuidAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4716 for (
const auto &GVI : valueIds()) {
4719 static_cast<uint32_t>(GVI.first >> 32),
4726 if (!StackIds.empty()) {
4727 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4734 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4736 Vals.
reserve(StackIds.size() * 2);
4737 for (
auto Id : StackIds) {
4745 Abbv = std::make_shared<BitCodeAbbrev>();
4759 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4762 Abbv = std::make_shared<BitCodeAbbrev>();
4769 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4772 Abbv = std::make_shared<BitCodeAbbrev>();
4778 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4780 Abbv = std::make_shared<BitCodeAbbrev>();
4788 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4790 Abbv = std::make_shared<BitCodeAbbrev>();
4799 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4801 Abbv = std::make_shared<BitCodeAbbrev>();
4806 unsigned RadixAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4809 if (DecSummaries ==
nullptr)
4811 return DecSummaries->count(GVS);
4825 std::set<GlobalValue::GUID> ReferencedTypeIds;
4839 NameVals.
push_back(S.getOriginalName());
4850 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4858 auto *
FS = dyn_cast<FunctionSummary>(S);
4869 return StackIdIndicesToIndex[
I];
4876 if (!CallStacks.
empty()) {
4885 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4888 DefOrUseGUIDs.
insert(
I.first);
4890 DefOrUseGUIDs.
insert(
VI.getGUID());
4892 auto ValueId = getValueId(
I.first);
4894 SummaryToValueIdMap[S] = *ValueId;
4902 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4909 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4912 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4916 for (
auto &RI :
VS->refs()) {
4917 auto RefValueId = getValueId(RI.getGUID());
4927 MaybeEmitOriginalName(*S);
4931 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
4933 return std::nullopt;
4934 return getValueId(
VI.getGUID());
4937 auto *
FS = cast<FunctionSummary>(S);
4942 Stream, FS, CallsiteAbbrev, AllocAbbrev, 0,
4946 std::optional<unsigned> ValueID = GetValueId(VI);
4961 return StackIdIndicesToIndex[
I];
4963 false, CallStackPos, CallStackCount);
4967 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4980 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4981 for (
auto &RI :
FS->refs()) {
4982 auto RefValueId = getValueId(RI.getGUID());
4986 if (RI.isReadOnly())
4988 else if (RI.isWriteOnly())
4992 NameVals[6] = Count;
4993 NameVals[7] = RORefCnt;
4994 NameVals[8] = WORefCnt;
4996 for (
auto &EI :
FS->calls()) {
4999 std::optional<unsigned> CallValueId = GetValueId(EI.first);
5008 FSCallsProfileAbbrev);
5010 MaybeEmitOriginalName(*S);
5013 for (
auto *AS : Aliases) {
5014 auto AliasValueId = SummaryToValueIdMap[AS];
5021 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
5028 MaybeEmitOriginalName(*AS);
5030 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
5034 if (!
Index.cfiFunctionDefs().empty()) {
5035 for (
auto &S :
Index.cfiFunctionDefs()) {
5042 if (!NameVals.
empty()) {
5048 if (!
Index.cfiFunctionDecls().empty()) {
5049 for (
auto &S :
Index.cfiFunctionDecls()) {
5056 if (!NameVals.
empty()) {
5064 for (
auto &
T : ReferencedTypeIds) {
5065 auto TidIter =
Index.typeIds().equal_range(
T);
5066 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter)) {
5074 if (
Index.getBlockCount())
5087 auto Abbv = std::make_shared<BitCodeAbbrev>();
5091 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5093 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
5096 Abbv = std::make_shared<BitCodeAbbrev>();
5099 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5105void ModuleBitcodeWriter::writeModuleHash(
StringRef View) {
5112 std::array<uint8_t, 20> Hash = Hasher.result();
5113 for (
int Pos = 0; Pos < 20; Pos += 4) {
5126void ModuleBitcodeWriter::write() {
5134 writeModuleVersion();
5143 writeAttributeGroupTable();
5146 writeAttributeTable();
5155 writeModuleConstants();
5158 writeModuleMetadataKinds();
5161 writeModuleMetadata();
5165 writeUseListBlock(
nullptr);
5167 writeOperandBundleTags();
5168 writeSyncScopeNames();
5173 if (!
F.isDeclaration())
5174 writeFunction(
F, FunctionToBitcodeIndex);
5179 writePerModuleGlobalValueSummary();
5181 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
5209 unsigned CPUType = ~0U;
5216 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
5217 DARWIN_CPU_TYPE_X86 = 7,
5218 DARWIN_CPU_TYPE_ARM = 12,
5219 DARWIN_CPU_TYPE_POWERPC = 18
5224 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
5226 CPUType = DARWIN_CPU_TYPE_X86;
5228 CPUType = DARWIN_CPU_TYPE_POWERPC;
5230 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
5232 CPUType = DARWIN_CPU_TYPE_ARM;
5236 "Expected header size to be reserved");
5241 unsigned Position = 0;
5249 while (Buffer.
size() & 15)
5256 Stream.
Emit((
unsigned)
'B', 8);
5257 Stream.
Emit((
unsigned)
'C', 8);
5258 Stream.
Emit(0x0, 4);
5259 Stream.
Emit(0xC, 4);
5260 Stream.
Emit(0xE, 4);
5261 Stream.
Emit(0xD, 4);
5279 auto Abbv = std::make_shared<BitCodeAbbrev>();
5282 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5290 assert(!WroteStrtab && !WroteSymtab);
5296 if (M->getModuleInlineAsm().empty())
5300 const Triple TT(M->getTargetTriple());
5302 if (!
T || !
T->hasMCAsmParser())
5324 std::vector<char> Strtab;
5326 Strtab.resize(StrtabBuilder.
getSize());
5330 {Strtab.data(), Strtab.size()});
5341 bool ShouldPreserveUseListOrder,
5350 assert(M.isMaterialized());
5351 Mods.push_back(
const_cast<Module *
>(&M));
5353 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5354 ShouldPreserveUseListOrder, Index,
5355 GenerateHash, ModHash);
5356 ModuleWriter.write();
5363 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5364 ModuleToSummariesForIndex);
5365 IndexWriter.write();
5370 bool ShouldPreserveUseListOrder,
5374 Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
5376 Writer.writeSymtab();
5377 Writer.writeStrtab();
5379 Triple TT(M.getTargetTriple());
5380 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5398void IndexBitcodeWriter::write() {
5401 writeModuleVersion();
5407 writeCombinedGlobalValueSummary();
5424 Writer.
writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5433class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5443 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5445 ModHash(&ModHash) {}
5450 void writeSimplifiedModuleInfo();
5460void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5472 auto Abbv = std::make_shared<BitCodeAbbrev>();
5475 Abbv->Add(AbbrevOpToUse);
5476 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5478 for (
const auto P :
M.getSourceFileName())
5542void ThinLinkBitcodeWriter::write() {
5545 writeModuleVersion();
5547 writeSimplifiedModuleInfo();
5549 writePerModuleGlobalValueSummary();
5566 assert(M.isMaterialized());
5567 Mods.push_back(
const_cast<Module *
>(&M));
5569 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
5571 ThinLinkWriter.write();
5592 switch (
T.getObjectFormat()) {
5594 return "__LLVM,__bitcode";
5619 switch (
T.getObjectFormat()) {
5621 return "__LLVM,__cmdline";
5647 const std::vector<uint8_t> &CmdArgs) {
5652 Type *UsedElementType = Used ? Used->getValueType()->getArrayElementType()
5654 for (
auto *GV : UsedGlobals) {
5655 if (GV->getName() !=
"llvm.embedded.module" &&
5656 GV->getName() !=
"llvm.cmdline")
5661 Used->eraseFromParent();
5666 Triple T(M.getTargetTriple());
5695 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5696 assert(Old->hasZeroLiveUses() &&
5697 "llvm.embedded.module can only be used once in llvm.compiler.used");
5699 Old->eraseFromParent();
5701 GV->
setName(
"llvm.embedded.module");
5719 assert(Old->hasZeroLiveUses() &&
5720 "llvm.cmdline can only be used once in llvm.compiler.used");
5722 Old->eraseFromParent();
5728 if (UsedArray.
empty())
5736 NewUsed->setSection(
"llvm.metadata");
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void 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 void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, unsigned ContextIdAbbvId, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex, bool WriteContextSizeInfoIndex, DenseMap< CallStackId, LinearCallStackId > &CallStackPos, CallStackId &CallStackCount)
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static void collectMemProfCallStacks(FunctionSummary *FS, std::function< LinearFrameId(unsigned)> GetStackIndex, MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &CallStacks)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static DenseMap< CallStackId, LinearCallStackId > writeMemoryProfileRadixTree(MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &&CallStacks, BitstreamWriter &Stream, unsigned RadixAbbrev)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
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 void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, StringRef Id, const TypeIdSummary &Summary)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
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 getNumWords() const
Get the number of words.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ 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 writeIndex(const ModuleSummaryIndex *Index, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
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.
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
bool isMustTailCall() const
@ 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.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
This class represents an Operation in the Expression.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
bool isDbgDeclare() const
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Generic tagged DWARF-like metadata node.
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
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Tracking metadata reference owned by Metadata.
This class implements a map that also provides access to all stored values in a deterministic order.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A class that wrap the SHA1 algorithm.
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
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_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
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.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
void build(llvm::MapVector< CallStackId, llvm::SmallVector< FrameIdTy > > &&MemProfCallStackData, const llvm::DenseMap< FrameIdTy, LinearFrameId > *MemProfFrameIndexes, llvm::DenseMap< FrameIdTy, FrameStat > &FrameHistogram)
ArrayRef< LinearFrameId > getRadixArray() const
llvm::DenseMap< CallStackId, LinearCallStackId > takeCallStackPos()
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_GLOBAL_VAR_EXPR
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
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.
template llvm::DenseMap< LinearFrameId, FrameStat > computeFrameHistogram< LinearFrameId >(llvm::MapVector< CallStackId, llvm::SmallVector< LinearFrameId > > &MemProfCallStackData)
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 tuples (A, B,...
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
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.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
DWARFExpression::Operation Op
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void consumeError(Error Err)
Consume a Error without doing anything.
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