31#include "llvm/Config/llvm-config.h"
89 cl::desc(
"Number of metadatas above which we emit an index "
90 "to enable lazy-loading"));
93 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
97 cl::desc(
"Write relative block frequency to function summary "));
115 VST_BBENTRY_6_ABBREV,
119 CONSTANTS_INTEGER_ABBREV,
120 CONSTANTS_CE_CAST_Abbrev,
121 CONSTANTS_NULL_Abbrev,
125 FUNCTION_INST_UNOP_ABBREV,
126 FUNCTION_INST_UNOP_FLAGS_ABBREV,
127 FUNCTION_INST_BINOP_ABBREV,
128 FUNCTION_INST_BINOP_FLAGS_ABBREV,
129 FUNCTION_INST_CAST_ABBREV,
130 FUNCTION_INST_CAST_FLAGS_ABBREV,
131 FUNCTION_INST_RET_VOID_ABBREV,
132 FUNCTION_INST_RET_VAL_ABBREV,
133 FUNCTION_INST_UNREACHABLE_ABBREV,
134 FUNCTION_INST_GEP_ABBREV,
135 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
140class BitcodeWriterBase {
151 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
154 void writeModuleVersion();
157void BitcodeWriterBase::writeModuleVersion() {
164class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
178 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
181 unsigned GlobalValueId;
192 bool ShouldPreserveUseListOrder,
194 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
204 for (
const auto &GUIDSummaryLists : *
Index)
206 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
207 if (
auto FS = dyn_cast<FunctionSummary>(
Summary.get())) {
212 for (
auto &CallEdge :
FS->calls())
213 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
214 assignValueId(CallEdge.first.getGUID());
220 for (
auto &RefEdge :
FS->refs())
221 if (!RefEdge.haveGVs() || !RefEdge.getValue())
222 assignValueId(RefEdge.getGUID());
227 void writePerModuleGlobalValueSummary();
230 void writePerModuleFunctionSummaryRecord(
232 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
233 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
const Function &
F);
236 unsigned FSModRefsAbbrev,
237 unsigned FSModVTableRefsAbbrev);
240 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
244 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
247 assert(VMI != GUIDToValueIdMap.end() &&
248 "GUID does not have assigned value Id");
254 if (!
VI.haveGVs() || !
VI.getValue())
255 return getValueId(
VI.getGUID());
259 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
263class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
283 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
284 ShouldPreserveUseListOrder,
Index),
285 GenerateHash(GenerateHash), ModHash(ModHash),
286 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
292 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
296 void writeAttributeGroupTable();
297 void writeAttributeTable();
298 void writeTypeTable();
300 void writeValueSymbolTableForwardDecl();
301 void writeModuleInfo();
306 unsigned createDILocationAbbrev();
309 unsigned createGenericDINodeAbbrev();
377 unsigned createNamedMetadataAbbrev();
379 unsigned createMetadataStringsAbbrev();
384 std::vector<unsigned> *MDAbbrevs =
nullptr,
385 std::vector<uint64_t> *IndexPos =
nullptr);
386 void writeModuleMetadata();
387 void writeFunctionMetadata(
const Function &
F);
388 void writeFunctionMetadataAttachment(
const Function &
F);
391 void writeModuleMetadataKinds();
392 void writeOperandBundleTags();
393 void writeSyncScopeNames();
394 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
395 void writeModuleConstants();
396 bool pushValueAndType(
const Value *V,
unsigned InstID,
398 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
399 void pushValue(
const Value *V,
unsigned InstID,
401 void pushValueSigned(
const Value *V,
unsigned InstID,
403 void writeInstruction(
const Instruction &
I,
unsigned InstID,
406 void writeGlobalValueSymbolTable(
409 void writeUseListBlock(
const Function *
F);
413 void writeBlockInfo();
420 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
424class IndexBitcodeWriter :
public BitcodeWriterBase {
435 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
439 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
443 std::vector<uint64_t> StackIds;
451 unsigned GlobalValueId = 0;
467 const std::map<std::string, GVSummaryMapTy>
468 *ModuleToSummariesForIndex =
nullptr)
469 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
470 DecSummaries(DecSummaries),
471 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
475 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
480 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
482 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
489 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
490 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
493 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
499 for (
auto &CI :
FS->callsites()) {
510 if (CI.StackIdIndices.empty()) {
511 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
514 for (
auto Idx : CI.StackIdIndices)
515 RecordStackIdReference(
Idx);
517 for (
auto &AI :
FS->allocs())
518 for (
auto &MIB : AI.MIBs)
519 for (
auto Idx : MIB.StackIdIndices)
520 RecordStackIdReference(
Idx);
525 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
530 template<
typename Functor>
531 void forEachSummary(Functor Callback) {
532 if (ModuleToSummariesForIndex) {
533 for (
auto &M : *ModuleToSummariesForIndex)
534 for (
auto &Summary :
M.second) {
535 Callback(Summary,
false);
539 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
540 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
543 for (
auto &Summaries :
Index)
544 for (
auto &Summary : Summaries.second.SummaryList)
545 Callback({Summaries.first,
Summary.get()},
false);
553 template <
typename Functor>
void forEachModule(Functor Callback) {
554 if (ModuleToSummariesForIndex) {
555 for (
const auto &M : *ModuleToSummariesForIndex) {
556 const auto &MPI =
Index.modulePaths().find(
M.first);
557 if (MPI ==
Index.modulePaths().end()) {
561 assert(ModuleToSummariesForIndex->size() == 1);
571 std::vector<StringRef> ModulePaths;
572 for (
auto &[ModPath,
_] :
Index.modulePaths())
573 ModulePaths.push_back(ModPath);
574 llvm::sort(ModulePaths.begin(), ModulePaths.end());
575 for (
auto &ModPath : ModulePaths)
576 Callback(*
Index.modulePaths().find(ModPath));
584 void writeModStrings();
585 void writeCombinedGlobalValueSummary();
588 auto VMI = GUIDToValueIdMap.find(ValGUID);
589 if (VMI == GUIDToValueIdMap.end())
594 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
628 case Instruction::Add:
630 case Instruction::Sub:
632 case Instruction::Mul:
635 case Instruction::FDiv:
638 case Instruction::FRem:
704 case Attribute::Alignment:
706 case Attribute::AllocAlign:
708 case Attribute::AllocSize:
710 case Attribute::AlwaysInline:
712 case Attribute::Builtin:
714 case Attribute::ByVal:
716 case Attribute::Convergent:
718 case Attribute::InAlloca:
720 case Attribute::Cold:
722 case Attribute::DisableSanitizerInstrumentation:
724 case Attribute::FnRetThunkExtern:
728 case Attribute::ElementType:
730 case Attribute::HybridPatchable:
732 case Attribute::InlineHint:
734 case Attribute::InReg:
736 case Attribute::JumpTable:
738 case Attribute::MinSize:
740 case Attribute::AllocatedPointer:
742 case Attribute::AllocKind:
744 case Attribute::Memory:
746 case Attribute::NoFPClass:
748 case Attribute::Naked:
750 case Attribute::Nest:
752 case Attribute::NoAlias:
754 case Attribute::NoBuiltin:
756 case Attribute::NoCallback:
758 case Attribute::NoCapture:
760 case Attribute::NoDuplicate:
762 case Attribute::NoFree:
764 case Attribute::NoImplicitFloat:
766 case Attribute::NoInline:
768 case Attribute::NoRecurse:
770 case Attribute::NoMerge:
772 case Attribute::NonLazyBind:
774 case Attribute::NonNull:
776 case Attribute::Dereferenceable:
778 case Attribute::DereferenceableOrNull:
780 case Attribute::NoRedZone:
782 case Attribute::NoReturn:
784 case Attribute::NoSync:
786 case Attribute::NoCfCheck:
788 case Attribute::NoProfile:
790 case Attribute::SkipProfile:
792 case Attribute::NoUnwind:
794 case Attribute::NoSanitizeBounds:
796 case Attribute::NoSanitizeCoverage:
798 case Attribute::NullPointerIsValid:
800 case Attribute::OptimizeForDebugging:
802 case Attribute::OptForFuzzing:
804 case Attribute::OptimizeForSize:
806 case Attribute::OptimizeNone:
808 case Attribute::ReadNone:
810 case Attribute::ReadOnly:
812 case Attribute::Returned:
814 case Attribute::ReturnsTwice:
816 case Attribute::SExt:
818 case Attribute::Speculatable:
820 case Attribute::StackAlignment:
822 case Attribute::StackProtect:
824 case Attribute::StackProtectReq:
826 case Attribute::StackProtectStrong:
828 case Attribute::SafeStack:
830 case Attribute::ShadowCallStack:
832 case Attribute::StrictFP:
834 case Attribute::StructRet:
836 case Attribute::SanitizeAddress:
838 case Attribute::SanitizeHWAddress:
840 case Attribute::SanitizeThread:
842 case Attribute::SanitizeMemory:
844 case Attribute::SanitizeNumericalStability:
846 case Attribute::SpeculativeLoadHardening:
848 case Attribute::SwiftError:
850 case Attribute::SwiftSelf:
852 case Attribute::SwiftAsync:
854 case Attribute::UWTable:
856 case Attribute::VScaleRange:
858 case Attribute::WillReturn:
860 case Attribute::WriteOnly:
862 case Attribute::ZExt:
864 case Attribute::ImmArg:
866 case Attribute::SanitizeMemTag:
868 case Attribute::Preallocated:
870 case Attribute::NoUndef:
872 case Attribute::ByRef:
874 case Attribute::MustProgress:
876 case Attribute::PresplitCoroutine:
878 case Attribute::Writable:
880 case Attribute::CoroDestroyOnlyWhenComplete:
882 case Attribute::DeadOnUnwind:
884 case Attribute::Range:
886 case Attribute::Initializes:
912 unsigned NumWords =
A.getActiveWords();
913 const uint64_t *RawData =
A.getRawData();
914 for (
unsigned i = 0; i < NumWords; i++)
934void ModuleBitcodeWriter::writeAttributeGroupTable() {
935 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
937 if (AttrGrps.empty())
return;
943 unsigned AttrListIndex = Pair.first;
946 Record.push_back(AttrListIndex);
949 if (Attr.isEnumAttribute()) {
952 }
else if (Attr.isIntAttribute()) {
955 Record.push_back(Attr.getValueAsInt());
956 }
else if (Attr.isStringAttribute()) {
967 }
else if (Attr.isTypeAttribute()) {
968 Type *Ty = Attr.getValueAsType();
969 Record.push_back(Ty ? 6 : 5);
973 }
else if (Attr.isConstantRangeAttribute()) {
979 assert(Attr.isConstantRangeListAttribute());
997void ModuleBitcodeWriter::writeAttributeTable() {
999 if (
Attrs.empty())
return;
1005 for (
unsigned i :
AL.indexes()) {
1019void ModuleBitcodeWriter::writeTypeTable() {
1028 auto Abbv = std::make_shared<BitCodeAbbrev>();
1031 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1034 Abbv = std::make_shared<BitCodeAbbrev>();
1039 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1042 Abbv = std::make_shared<BitCodeAbbrev>();
1047 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1050 Abbv = std::make_shared<BitCodeAbbrev>();
1054 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1057 Abbv = std::make_shared<BitCodeAbbrev>();
1062 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1065 Abbv = std::make_shared<BitCodeAbbrev>();
1069 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1077 for (
Type *
T : TypeList) {
1078 int AbbrevToUse = 0;
1081 switch (
T->getTypeID()) {
1107 AbbrevToUse = OpaquePtrAbbrev;
1116 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1118 AbbrevToUse = FunctionAbbrev;
1126 for (
Type *ET :
ST->elements())
1129 if (
ST->isLiteral()) {
1131 AbbrevToUse = StructAnonAbbrev;
1133 if (
ST->isOpaque()) {
1137 AbbrevToUse = StructNamedAbbrev;
1141 if (!
ST->getName().empty())
1151 TypeVals.
push_back(AT->getNumElements());
1153 AbbrevToUse = ArrayAbbrev;
1162 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1164 if (isa<ScalableVectorType>(VT))
1174 for (
Type *InnerTy :
TET->type_params())
1176 for (
unsigned IntParam :
TET->int_params())
1185 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1226 RawFlags |= Flags.ReadNone;
1227 RawFlags |= (Flags.ReadOnly << 1);
1228 RawFlags |= (Flags.NoRecurse << 2);
1229 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1230 RawFlags |= (Flags.NoInline << 4);
1231 RawFlags |= (Flags.AlwaysInline << 5);
1232 RawFlags |= (Flags.NoUnwind << 6);
1233 RawFlags |= (Flags.MayThrow << 7);
1234 RawFlags |= (Flags.HasUnknownCall << 8);
1235 RawFlags |= (Flags.MustBeUnreachable << 9);
1242 bool ImportAsDecl =
false) {
1245 RawFlags |= Flags.NotEligibleToImport;
1246 RawFlags |= (Flags.Live << 1);
1247 RawFlags |= (Flags.DSOLocal << 2);
1248 RawFlags |= (Flags.CanAutoHide << 3);
1253 RawFlags = (RawFlags << 4) | Flags.Linkage;
1255 RawFlags |= (Flags.Visibility << 8);
1257 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1258 RawFlags |= (ImportType << 10);
1264 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1265 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1307 case GlobalVariable::NotThreadLocal:
return 0;
1308 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1309 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1310 case GlobalVariable::InitialExecTLSModel:
return 3;
1311 case GlobalVariable::LocalExecTLSModel:
return 4;
1317 switch (
C.getSelectionKind()) {
1334 case GlobalValue::UnnamedAddr::None:
return 0;
1335 case GlobalValue::UnnamedAddr::Local:
return 2;
1336 case GlobalValue::UnnamedAddr::Global:
return 1;
1341size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1344 return StrtabBuilder.
add(Str);
1347void ModuleBitcodeWriter::writeComdats() {
1362void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1367 auto Abbv = std::make_shared<BitCodeAbbrev>();
1373 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1389 bool isChar6 =
true;
1390 for (
char C : Str) {
1393 if ((
unsigned char)
C & 128)
1403 "Sanitizer Metadata is too large for naive serialization.");
1406 return Meta.NoAddress | (Meta.NoHWAddress << 1) |
1407 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1413void ModuleBitcodeWriter::writeModuleInfo() {
1415 if (!
M.getTargetTriple().empty())
1418 const std::string &
DL =
M.getDataLayoutStr();
1421 if (!
M.getModuleInlineAsm().empty())
1427 std::map<std::string, unsigned> SectionMap;
1428 std::map<std::string, unsigned> GCMap;
1430 unsigned MaxGlobalType = 0;
1431 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1433 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1436 UpdateMaxAlignment(GV.getAlign());
1437 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1438 if (GV.hasSection()) {
1440 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1444 Entry = SectionMap.size();
1449 UpdateMaxAlignment(
F.getAlign());
1450 if (
F.hasSection()) {
1452 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1456 Entry = SectionMap.size();
1461 unsigned &
Entry = GCMap[
F.getGC()];
1465 Entry = GCMap.size();
1471 unsigned SimpleGVarAbbrev = 0;
1472 if (!
M.global_empty()) {
1474 auto Abbv = std::make_shared<BitCodeAbbrev>();
1488 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1492 if (SectionMap.empty())
1498 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1512 auto Abbv = std::make_shared<BitCodeAbbrev>();
1515 Abbv->Add(AbbrevOpToUse);
1516 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1518 for (
const auto P :
M.getSourceFileName())
1528 unsigned AbbrevToUse = 0;
1534 Vals.
push_back(addToStrtab(GV.getName()));
1537 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1541 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1542 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1544 if (GV.isThreadLocal() ||
1546 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1547 GV.isExternallyInitialized() ||
1549 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1550 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1554 Vals.
push_back(GV.isExternallyInitialized());
1562 Vals.
push_back(addToStrtab(GV.getPartition()));
1563 Vals.
push_back(GV.getPartition().size());
1566 GV.getSanitizerMetadata())
1570 AbbrevToUse = SimpleGVarAbbrev;
1590 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1591 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1603 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1607 Vals.
push_back(addToStrtab(
F.getPartition()));
1610 unsigned AbbrevToUse = 0;
1623 Vals.
push_back(
A.getType()->getAddressSpace());
1631 Vals.
push_back(addToStrtab(
A.getPartition()));
1634 unsigned AbbrevToUse = 0;
1646 Vals.
push_back(
I.getType()->getAddressSpace());
1651 Vals.
push_back(addToStrtab(
I.getPartition()));
1657 writeValueSymbolTableForwardDecl();
1663 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1664 if (OBO->hasNoSignedWrap())
1666 if (OBO->hasNoUnsignedWrap())
1668 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1671 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1672 if (PDI->isDisjoint())
1674 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1675 if (FPMO->hasAllowReassoc())
1677 if (FPMO->hasNoNaNs())
1679 if (FPMO->hasNoInfs())
1681 if (FPMO->hasNoSignedZeros())
1683 if (FPMO->hasAllowReciprocal())
1685 if (FPMO->hasAllowContract())
1687 if (FPMO->hasApproxFunc())
1689 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1690 if (NNI->hasNonNeg())
1692 }
else if (
const auto *TI = dyn_cast<TruncInst>(V)) {
1693 if (TI->hasNoSignedWrap())
1695 if (TI->hasNoUnsignedWrap())
1697 }
else if (
const auto *
GEP = dyn_cast<GEPOperator>(V)) {
1698 if (
GEP->isInBounds())
1700 if (
GEP->hasNoUnsignedSignedWrap())
1702 if (
GEP->hasNoUnsignedWrap())
1709void ModuleBitcodeWriter::writeValueAsMetadata(
1719void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1724 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1725 "Unexpected function-local metadata");
1734unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1737 auto Abbv = std::make_shared<BitCodeAbbrev>();
1748void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1752 Abbrev = createDILocationAbbrev();
1754 Record.push_back(
N->isDistinct());
1755 Record.push_back(
N->getLine());
1756 Record.push_back(
N->getColumn());
1759 Record.push_back(
N->isImplicitCode());
1765unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1768 auto Abbv = std::make_shared<BitCodeAbbrev>();
1779void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1783 Abbrev = createGenericDINodeAbbrev();
1785 Record.push_back(
N->isDistinct());
1786 Record.push_back(
N->getTag());
1789 for (
auto &
I :
N->operands())
1796void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1810void ModuleBitcodeWriter::writeDIGenericSubrange(
1823void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1827 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1828 Record.push_back(
N->getValue().getBitWidth());
1836void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1839 Record.push_back(
N->isDistinct());
1840 Record.push_back(
N->getTag());
1842 Record.push_back(
N->getSizeInBits());
1843 Record.push_back(
N->getAlignInBits());
1844 Record.push_back(
N->getEncoding());
1845 Record.push_back(
N->getFlags());
1851void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1854 Record.push_back(
N->isDistinct());
1855 Record.push_back(
N->getTag());
1860 Record.push_back(
N->getSizeInBits());
1861 Record.push_back(
N->getAlignInBits());
1862 Record.push_back(
N->getEncoding());
1868void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1871 Record.push_back(
N->isDistinct());
1872 Record.push_back(
N->getTag());
1875 Record.push_back(
N->getLine());
1878 Record.push_back(
N->getSizeInBits());
1879 Record.push_back(
N->getAlignInBits());
1880 Record.push_back(
N->getOffsetInBits());
1881 Record.push_back(
N->getFlags());
1886 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1887 Record.push_back(*DWARFAddressSpace + 1);
1893 if (
auto PtrAuthData =
N->getPtrAuthData())
1894 Record.push_back(PtrAuthData->RawData);
1902void ModuleBitcodeWriter::writeDICompositeType(
1905 const unsigned IsNotUsedInOldTypeRef = 0x2;
1906 Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1907 Record.push_back(
N->getTag());
1910 Record.push_back(
N->getLine());
1913 Record.push_back(
N->getSizeInBits());
1914 Record.push_back(
N->getAlignInBits());
1915 Record.push_back(
N->getOffsetInBits());
1916 Record.push_back(
N->getFlags());
1918 Record.push_back(
N->getRuntimeLang());
1933void ModuleBitcodeWriter::writeDISubroutineType(
1936 const unsigned HasNoOldTypeRefs = 0x2;
1937 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1938 Record.push_back(
N->getFlags());
1946void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
1949 Record.push_back(
N->isDistinct());
1952 if (
N->getRawChecksum()) {
1953 Record.push_back(
N->getRawChecksum()->Kind);
1961 auto Source =
N->getRawSource();
1969void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
1972 assert(
N->isDistinct() &&
"Expected distinct compile units");
1974 Record.push_back(
N->getSourceLanguage());
1977 Record.push_back(
N->isOptimized());
1979 Record.push_back(
N->getRuntimeVersion());
1981 Record.push_back(
N->getEmissionKind());
1987 Record.push_back(
N->getDWOId());
1989 Record.push_back(
N->getSplitDebugInlining());
1990 Record.push_back(
N->getDebugInfoForProfiling());
1991 Record.push_back((
unsigned)
N->getNameTableKind());
1992 Record.push_back(
N->getRangesBaseAddress());
2000void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2003 const uint64_t HasUnitFlag = 1 << 1;
2004 const uint64_t HasSPFlagsFlag = 1 << 2;
2005 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2010 Record.push_back(
N->getLine());
2012 Record.push_back(
N->getScopeLine());
2014 Record.push_back(
N->getSPFlags());
2015 Record.push_back(
N->getVirtualIndex());
2016 Record.push_back(
N->getFlags());
2021 Record.push_back(
N->getThisAdjustment());
2033 Record.push_back(
N->isDistinct());
2036 Record.push_back(
N->getLine());
2037 Record.push_back(
N->getColumn());
2043void ModuleBitcodeWriter::writeDILexicalBlockFile(
2046 Record.push_back(
N->isDistinct());
2049 Record.push_back(
N->getDiscriminator());
2055void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2058 Record.push_back(
N->isDistinct());
2063 Record.push_back(
N->getLineNo());
2069void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2072 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2080void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2083 Record.push_back(
N->isDistinct());
2084 Record.push_back(
N->getMacinfoType());
2085 Record.push_back(
N->getLine());
2093void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2096 Record.push_back(
N->isDistinct());
2097 Record.push_back(
N->getMacinfoType());
2098 Record.push_back(
N->getLine());
2106void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2108 Record.reserve(
N->getArgs().size());
2116void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2119 Record.push_back(
N->isDistinct());
2120 for (
auto &
I :
N->operands())
2122 Record.push_back(
N->getLineNo());
2123 Record.push_back(
N->getIsDecl());
2129void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2133 Record.push_back(
N->isDistinct());
2138void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2141 Record.push_back(
N->isDistinct());
2144 Record.push_back(
N->isDefault());
2150void ModuleBitcodeWriter::writeDITemplateValueParameter(
2153 Record.push_back(
N->isDistinct());
2154 Record.push_back(
N->getTag());
2157 Record.push_back(
N->isDefault());
2164void ModuleBitcodeWriter::writeDIGlobalVariable(
2173 Record.push_back(
N->getLine());
2175 Record.push_back(
N->isLocalToUnit());
2176 Record.push_back(
N->isDefinition());
2179 Record.push_back(
N->getAlignInBits());
2186void ModuleBitcodeWriter::writeDILocalVariable(
2202 const uint64_t HasAlignmentFlag = 1 << 1;
2207 Record.push_back(
N->getLine());
2209 Record.push_back(
N->getArg());
2210 Record.push_back(
N->getFlags());
2211 Record.push_back(
N->getAlignInBits());
2218void ModuleBitcodeWriter::writeDILabel(
2225 Record.push_back(
N->getLine());
2231void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2234 Record.reserve(
N->getElements().size() + 1);
2237 Record.append(
N->elements_begin(),
N->elements_end());
2243void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2246 Record.push_back(
N->isDistinct());
2257 Record.push_back(
N->isDistinct());
2260 Record.push_back(
N->getLine());
2263 Record.push_back(
N->getAttributes());
2270void ModuleBitcodeWriter::writeDIImportedEntity(
2273 Record.push_back(
N->isDistinct());
2274 Record.push_back(
N->getTag());
2277 Record.push_back(
N->getLine());
2286unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2287 auto Abbv = std::make_shared<BitCodeAbbrev>();
2294void ModuleBitcodeWriter::writeNamedMetadata(
2296 if (
M.named_metadata_empty())
2299 unsigned Abbrev = createNamedMetadataAbbrev();
2303 Record.append(Str.bytes_begin(), Str.bytes_end());
2308 for (
const MDNode *
N : NMD.operands())
2315unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2316 auto Abbv = std::make_shared<BitCodeAbbrev>();
2328void ModuleBitcodeWriter::writeMetadataStrings(
2330 if (Strings.empty())
2335 Record.push_back(Strings.size());
2342 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2351 Blob.
append(cast<MDString>(MD)->getString());
2360#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2361#include "llvm/IR/Metadata.def"
2365void ModuleBitcodeWriter::writeMetadataRecords(
2367 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2372#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2373#include "llvm/IR/Metadata.def"
2378 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2379 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2381 switch (
N->getMetadataID()) {
2384#define HANDLE_MDNODE_LEAF(CLASS) \
2385 case Metadata::CLASS##Kind: \
2387 write##CLASS(cast<CLASS>(N), Record, \
2388 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2390 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2392#include "llvm/IR/Metadata.def"
2395 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2399 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2403void ModuleBitcodeWriter::writeModuleMetadata() {
2404 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2412 std::vector<unsigned> MDAbbrevs;
2415 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2416 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2417 createGenericDINodeAbbrev();
2419 auto Abbv = std::make_shared<BitCodeAbbrev>();
2423 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2425 Abbv = std::make_shared<BitCodeAbbrev>();
2429 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2451 std::vector<uint64_t> IndexPos;
2466 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2467 for (
auto &Elt : IndexPos) {
2468 auto EltDelta = Elt - PreviousValue;
2469 PreviousValue = Elt;
2478 writeNamedMetadata(
Record);
2480 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2483 pushGlobalMetadataAttachment(
Record, GO);
2487 if (
F.isDeclaration() &&
F.hasMetadata())
2488 AddDeclAttachedMetadata(
F);
2492 if (GV.hasMetadata())
2493 AddDeclAttachedMetadata(GV);
2498void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2509void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2514 for (
const auto &
I : MDs) {
2520void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2525 if (
F.hasMetadata()) {
2526 pushGlobalMetadataAttachment(
Record,
F);
2537 I.getAllMetadataOtherThanDebugLoc(MDs);
2540 if (MDs.
empty())
continue;
2544 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2545 Record.push_back(MDs[i].first);
2555void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2561 M.getMDKindNames(Names);
2563 if (Names.
empty())
return;
2567 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2568 Record.push_back(MDKindID);
2579void ModuleBitcodeWriter::writeOperandBundleTags() {
2587 M.getOperandBundleTags(Tags);
2596 for (
auto Tag : Tags) {
2606void ModuleBitcodeWriter::writeSyncScopeNames() {
2608 M.getContext().getSyncScopeNames(SSNs);
2615 for (
auto SSN : SSNs) {
2616 Record.append(SSN.begin(), SSN.end());
2624void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2626 if (FirstVal == LastVal)
return;
2630 unsigned AggregateAbbrev = 0;
2631 unsigned String8Abbrev = 0;
2632 unsigned CString7Abbrev = 0;
2633 unsigned CString6Abbrev = 0;
2637 auto Abbv = std::make_shared<BitCodeAbbrev>();
2641 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2644 Abbv = std::make_shared<BitCodeAbbrev>();
2648 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2650 Abbv = std::make_shared<BitCodeAbbrev>();
2654 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2656 Abbv = std::make_shared<BitCodeAbbrev>();
2660 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2666 Type *LastTy =
nullptr;
2667 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2668 const Value *
V = Vals[i].first;
2670 if (
V->getType() != LastTy) {
2671 LastTy =
V->getType();
2674 CONSTANTS_SETTYPE_ABBREV);
2678 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2681 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2682 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2685 const std::string &AsmStr =
IA->getAsmString();
2686 Record.push_back(AsmStr.size());
2687 Record.append(AsmStr.begin(), AsmStr.end());
2690 const std::string &ConstraintStr =
IA->getConstraintString();
2691 Record.push_back(ConstraintStr.size());
2692 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2698 unsigned Code = -1U;
2699 unsigned AbbrevToUse = 0;
2700 if (
C->isNullValue()) {
2702 }
else if (isa<PoisonValue>(
C)) {
2704 }
else if (isa<UndefValue>(
C)) {
2707 if (
IV->getBitWidth() <= 64) {
2711 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2716 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2721 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2725 APInt api = CFP->getValueAPF().bitcastToAPInt();
2727 Record.push_back((p[1] << 48) | (p[0] >> 16));
2728 Record.push_back(p[0] & 0xffffLL);
2730 APInt api = CFP->getValueAPF().bitcastToAPInt();
2735 assert(0 &&
"Unknown FP type!");
2737 }
else if (isa<ConstantDataSequential>(
C) &&
2738 cast<ConstantDataSequential>(
C)->isString()) {
2741 unsigned NumElts = Str->getNumElements();
2743 if (Str->isCString()) {
2748 AbbrevToUse = String8Abbrev;
2752 for (
unsigned i = 0; i != NumElts; ++i) {
2753 unsigned char V = Str->getElementAsInteger(i);
2755 isCStr7 &= (
V & 128) == 0;
2761 AbbrevToUse = CString6Abbrev;
2763 AbbrevToUse = CString7Abbrev;
2765 dyn_cast<ConstantDataSequential>(
C)) {
2767 Type *EltTy = CDS->getElementType();
2768 if (isa<IntegerType>(EltTy)) {
2769 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2770 Record.push_back(CDS->getElementAsInteger(i));
2772 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2774 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2776 }
else if (isa<ConstantAggregate>(
C)) {
2778 for (
const Value *
Op :
C->operands())
2780 AbbrevToUse = AggregateAbbrev;
2781 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2782 switch (
CE->getOpcode()) {
2789 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2791 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2801 case Instruction::FNeg: {
2802 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2811 case Instruction::GetElementPtr: {
2813 const auto *GO = cast<GEPOperator>(
C);
2816 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2820 for (
unsigned i = 0, e =
CE->getNumOperands(); i != e; ++i) {
2826 case Instruction::ExtractElement:
2833 case Instruction::InsertElement:
2840 case Instruction::ShuffleVector:
2845 if (
C->getType() ==
C->getOperand(0)->getType()) {
2856 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2861 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2865 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
2869 }
else if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C)) {
2888void ModuleBitcodeWriter::writeModuleConstants() {
2893 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2894 if (!isa<GlobalValue>(Vals[i].first)) {
2895 writeConstants(i, Vals.size(),
true);
2909bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2914 if (
ValID >= InstID) {
2921void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
2928 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2930 for (
auto &Input : Bundle.Inputs)
2931 pushValueAndType(Input, InstID,
Record);
2940void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2946void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2949 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2954void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2958 unsigned AbbrevToUse = 0;
2960 switch (
I.getOpcode()) {
2964 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2965 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2970 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
2971 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
2975 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
2977 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2978 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2979 pushValue(
I.getOperand(1), InstID, Vals);
2983 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2984 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2989 case Instruction::FNeg: {
2991 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2992 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2996 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
2997 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3002 case Instruction::GetElementPtr: {
3004 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3005 auto &GEPInst = cast<GetElementPtrInst>(
I);
3008 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
3009 pushValueAndType(
I.getOperand(i), InstID, Vals);
3012 case Instruction::ExtractValue: {
3014 pushValueAndType(
I.getOperand(0), InstID, Vals);
3019 case Instruction::InsertValue: {
3021 pushValueAndType(
I.getOperand(0), InstID, Vals);
3022 pushValueAndType(
I.getOperand(1), InstID, Vals);
3027 case Instruction::Select: {
3029 pushValueAndType(
I.getOperand(1), InstID, Vals);
3030 pushValue(
I.getOperand(2), InstID, Vals);
3031 pushValueAndType(
I.getOperand(0), InstID, Vals);
3037 case Instruction::ExtractElement:
3039 pushValueAndType(
I.getOperand(0), InstID, Vals);
3040 pushValueAndType(
I.getOperand(1), InstID, Vals);
3042 case Instruction::InsertElement:
3044 pushValueAndType(
I.getOperand(0), InstID, Vals);
3045 pushValue(
I.getOperand(1), InstID, Vals);
3046 pushValueAndType(
I.getOperand(2), InstID, Vals);
3048 case Instruction::ShuffleVector:
3050 pushValueAndType(
I.getOperand(0), InstID, Vals);
3051 pushValue(
I.getOperand(1), InstID, Vals);
3052 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3055 case Instruction::ICmp:
3056 case Instruction::FCmp: {
3059 pushValueAndType(
I.getOperand(0), InstID, Vals);
3060 pushValue(
I.getOperand(1), InstID, Vals);
3068 case Instruction::Ret:
3071 unsigned NumOperands =
I.getNumOperands();
3072 if (NumOperands == 0)
3073 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3074 else if (NumOperands == 1) {
3075 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3076 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3078 for (
unsigned i = 0, e = NumOperands; i !=
e; ++i)
3079 pushValueAndType(
I.getOperand(i), InstID, Vals);
3083 case Instruction::Br:
3088 if (
II.isConditional()) {
3090 pushValue(
II.getCondition(), InstID, Vals);
3094 case Instruction::Switch:
3099 pushValue(
SI.getCondition(), InstID, Vals);
3101 for (
auto Case :
SI.cases()) {
3107 case Instruction::IndirectBr:
3111 pushValue(
I.getOperand(0), InstID, Vals);
3112 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i)
3116 case Instruction::Invoke: {
3121 if (
II->hasOperandBundles())
3122 writeOperandBundles(*
II, InstID);
3131 pushValueAndType(Callee, InstID, Vals);
3134 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3135 pushValue(
I.getOperand(i), InstID, Vals);
3138 if (FTy->isVarArg()) {
3139 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3140 pushValueAndType(
I.getOperand(i), InstID, Vals);
3144 case Instruction::Resume:
3146 pushValueAndType(
I.getOperand(0), InstID, Vals);
3148 case Instruction::CleanupRet: {
3150 const auto &CRI = cast<CleanupReturnInst>(
I);
3151 pushValue(CRI.getCleanupPad(), InstID, Vals);
3152 if (CRI.hasUnwindDest())
3156 case Instruction::CatchRet: {
3158 const auto &CRI = cast<CatchReturnInst>(
I);
3159 pushValue(CRI.getCatchPad(), InstID, Vals);
3163 case Instruction::CleanupPad:
3164 case Instruction::CatchPad: {
3165 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3168 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3170 unsigned NumArgOperands = FuncletPad.arg_size();
3172 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3173 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3176 case Instruction::CatchSwitch: {
3178 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3180 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3182 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3184 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3187 if (CatchSwitch.hasUnwindDest())
3191 case Instruction::CallBr: {
3197 writeOperandBundles(*CBI, InstID);
3212 pushValueAndType(Callee, InstID, Vals);
3215 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3216 pushValue(
I.getOperand(i), InstID, Vals);
3219 if (FTy->isVarArg()) {
3220 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3221 pushValueAndType(
I.getOperand(i), InstID, Vals);
3225 case Instruction::Unreachable:
3227 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3230 case Instruction::PHI: {
3231 const PHINode &PN = cast<PHINode>(
I);
3248 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3253 case Instruction::LandingPad: {
3264 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3269 case Instruction::Alloca: {
3277 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3278 Bitfield::set<APV::AlignLower>(
3279 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3280 Bitfield::set<APV::AlignUpper>(
Record,
3281 EncodedAlign >> APV::AlignLower::Bits);
3283 Bitfield::set<APV::ExplicitType>(
Record,
true);
3288 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3293 case Instruction::Load:
3294 if (cast<LoadInst>(
I).isAtomic()) {
3296 pushValueAndType(
I.getOperand(0), InstID, Vals);
3299 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3300 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3304 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3305 if (cast<LoadInst>(
I).isAtomic()) {
3307 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3310 case Instruction::Store:
3311 if (cast<StoreInst>(
I).isAtomic())
3315 pushValueAndType(
I.getOperand(1), InstID, Vals);
3316 pushValueAndType(
I.getOperand(0), InstID, Vals);
3318 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3319 if (cast<StoreInst>(
I).isAtomic()) {
3322 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3325 case Instruction::AtomicCmpXchg:
3327 pushValueAndType(
I.getOperand(0), InstID, Vals);
3328 pushValueAndType(
I.getOperand(1), InstID, Vals);
3329 pushValue(
I.getOperand(2), InstID, Vals);
3330 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3334 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3337 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3340 case Instruction::AtomicRMW:
3342 pushValueAndType(
I.getOperand(0), InstID, Vals);
3343 pushValueAndType(
I.getOperand(1), InstID, Vals);
3346 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3349 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3352 case Instruction::Fence:
3355 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3357 case Instruction::Call: {
3362 writeOperandBundles(CI, InstID);
3382 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3384 if (FTy->getParamType(i)->isLabelTy())
3391 if (FTy->isVarArg()) {
3392 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3397 case Instruction::VAArg:
3400 pushValue(
I.getOperand(0), InstID, Vals);
3403 case Instruction::Freeze:
3405 pushValueAndType(
I.getOperand(0), InstID, Vals);
3415void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3421 VSTOffset -= bitcodeStartBit();
3422 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3426 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3430 auto Abbv = std::make_shared<BitCodeAbbrev>();
3434 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3439 if (
F.isDeclaration())
3446 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3447 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3451 Record[1] = BitcodeIndex / 32 + 1;
3460void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3475 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3481 if (isa<BasicBlock>(
Name.getValue())) {
3484 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3488 AbbrevToUse = VST_ENTRY_6_ABBREV;
3490 AbbrevToUse = VST_ENTRY_7_ABBREV;
3493 for (
const auto P :
Name.getKey())
3497 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3504void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3505 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3507 if (isa<BasicBlock>(Order.V))
3517void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3519 "Expected to be preserving use-list order");
3521 auto hasMore = [&]() {
3537void ModuleBitcodeWriter::writeFunction(
3556 unsigned CstStart, CstEnd;
3558 writeConstants(CstStart, CstEnd,
false);
3561 writeFunctionMetadata(
F);
3564 unsigned InstID = CstEnd;
3566 bool NeedsMetadataAttachment =
F.hasMetadata();
3574 writeInstruction(
I, InstID, Vals);
3576 if (!
I.getType()->isVoidTy())
3580 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3607 auto PushValueOrMetadata = [&Vals, InstID,
3610 "RawLocation unexpectedly null in DbgVariableRecord");
3616 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3630 for (
DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3656 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3678 while (!Worklist.empty()) {
3679 Value *
V = Worklist.pop_back_val();
3680 for (
User *U :
V->users()) {
3681 if (
auto *
I = dyn_cast<Instruction>(U)) {
3685 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3686 Visited.insert(U).second)
3687 Worklist.push_back(U);
3693 if (!BlockAddressUsers.
empty()) {
3702 if (
auto *Symtab =
F.getValueSymbolTable())
3703 writeFunctionLevelValueSymbolTable(*Symtab);
3705 if (NeedsMetadataAttachment)
3706 writeFunctionMetadataAttachment(
F);
3708 writeUseListBlock(&
F);
3714void ModuleBitcodeWriter::writeBlockInfo() {
3721 auto Abbv = std::make_shared<BitCodeAbbrev>();
3732 auto Abbv = std::make_shared<BitCodeAbbrev>();
3742 auto Abbv = std::make_shared<BitCodeAbbrev>();
3752 auto Abbv = std::make_shared<BitCodeAbbrev>();
3758 VST_BBENTRY_6_ABBREV)
3763 auto Abbv = std::make_shared<BitCodeAbbrev>();
3768 CONSTANTS_SETTYPE_ABBREV)
3773 auto Abbv = std::make_shared<BitCodeAbbrev>();
3777 CONSTANTS_INTEGER_ABBREV)
3782 auto Abbv = std::make_shared<BitCodeAbbrev>();
3790 CONSTANTS_CE_CAST_Abbrev)
3794 auto Abbv = std::make_shared<BitCodeAbbrev>();
3797 CONSTANTS_NULL_Abbrev)
3804 auto Abbv = std::make_shared<BitCodeAbbrev>();
3812 FUNCTION_INST_LOAD_ABBREV)
3816 auto Abbv = std::make_shared<BitCodeAbbrev>();
3821 FUNCTION_INST_UNOP_ABBREV)
3825 auto Abbv = std::make_shared<BitCodeAbbrev>();
3831 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3835 auto Abbv = std::make_shared<BitCodeAbbrev>();
3841 FUNCTION_INST_BINOP_ABBREV)
3845 auto Abbv = std::make_shared<BitCodeAbbrev>();
3852 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3856 auto Abbv = std::make_shared<BitCodeAbbrev>();
3863 FUNCTION_INST_CAST_ABBREV)
3867 auto Abbv = std::make_shared<BitCodeAbbrev>();
3875 FUNCTION_INST_CAST_FLAGS_ABBREV)
3880 auto Abbv = std::make_shared<BitCodeAbbrev>();
3883 FUNCTION_INST_RET_VOID_ABBREV)
3887 auto Abbv = std::make_shared<BitCodeAbbrev>();
3891 FUNCTION_INST_RET_VAL_ABBREV)
3895 auto Abbv = std::make_shared<BitCodeAbbrev>();
3898 FUNCTION_INST_UNREACHABLE_ABBREV)
3902 auto Abbv = std::make_shared<BitCodeAbbrev>();
3910 FUNCTION_INST_GEP_ABBREV)
3914 auto Abbv = std::make_shared<BitCodeAbbrev>();
3921 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3929void IndexBitcodeWriter::writeModStrings() {
3935 auto Abbv = std::make_shared<BitCodeAbbrev>();
3940 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3943 Abbv = std::make_shared<BitCodeAbbrev>();
3948 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3951 Abbv = std::make_shared<BitCodeAbbrev>();
3956 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3959 Abbv = std::make_shared<BitCodeAbbrev>();
3966 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3971 const auto &Hash = MPSE.
getValue();
3973 unsigned AbbrevToUse = Abbrev8Bit;
3975 AbbrevToUse = Abbrev6Bit;
3977 AbbrevToUse = Abbrev7Bit;
3979 auto ModuleId = ModuleIdMap.
size();
3980 ModuleIdMap[
Key] = ModuleId;
3989 Vals.
assign(Hash.begin(), Hash.end());
4001template <
typename Fn>
4005 if (!FS->type_tests().empty())
4010 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4015 for (
auto &VF : VFs) {
4016 Record.push_back(VF.GUID);
4017 Record.push_back(VF.Offset);
4023 FS->type_test_assume_vcalls());
4025 FS->type_checked_load_vcalls());
4027 auto WriteConstVCallVec = [&](
uint64_t Ty,
4029 for (
auto &VC : VCs) {
4031 Record.push_back(VC.VFunc.GUID);
4032 Record.push_back(VC.VFunc.Offset);
4039 FS->type_test_assume_const_vcalls());
4041 FS->type_checked_load_const_vcalls());
4051 if (!FS->paramAccesses().empty()) {
4053 for (
auto &Arg : FS->paramAccesses()) {
4054 size_t UndoSize =
Record.size();
4055 Record.push_back(Arg.ParamNo);
4056 WriteRange(Arg.Use);
4057 Record.push_back(Arg.Calls.size());
4058 for (
auto &Call : Arg.Calls) {
4059 Record.push_back(Call.ParamNo);
4060 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4067 Record.push_back(*ValueID);
4068 WriteRange(Call.Offsets);
4079 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4080 if (!FS->type_tests().empty())
4081 for (
auto &TT : FS->type_tests())
4082 ReferencedTypeIds.insert(TT);
4084 auto GetReferencedTypesFromVFuncIdVec =
4086 for (
auto &VF : VFs)
4087 ReferencedTypeIds.insert(VF.GUID);
4090 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4091 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4093 auto GetReferencedTypesFromConstVCallVec =
4095 for (
auto &VC : VCs)
4096 ReferencedTypeIds.insert(VC.VFunc.GUID);
4099 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4100 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4131 const std::string &Id,
4136 NameVals.
push_back(Summary.TTRes.TheKind);
4137 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4138 NameVals.
push_back(Summary.TTRes.AlignLog2);
4139 NameVals.
push_back(Summary.TTRes.SizeM1);
4140 NameVals.
push_back(Summary.TTRes.BitMask);
4141 NameVals.
push_back(Summary.TTRes.InlineBits);
4143 for (
auto &W : Summary.WPDRes)
4155 for (
auto &
P : Summary) {
4163 unsigned AllocAbbrev,
bool PerModule,
4164 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4165 std::function<
unsigned(
unsigned)> GetStackIndex) {
4168 for (
auto &CI : FS->callsites()) {
4172 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4173 Record.push_back(GetValueID(CI.Callee));
4175 Record.push_back(CI.StackIdIndices.size());
4176 Record.push_back(CI.Clones.size());
4178 for (
auto Id : CI.StackIdIndices)
4179 Record.push_back(GetStackIndex(Id));
4181 for (
auto V : CI.Clones)
4189 for (
auto &AI : FS->allocs()) {
4193 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4194 Record.push_back(AI.MIBs.size());
4196 Record.push_back(AI.Versions.size());
4197 for (
auto &MIB : AI.MIBs) {
4198 Record.push_back((uint8_t)MIB.AllocType);
4199 Record.push_back(MIB.StackIdIndices.size());
4200 for (
auto Id : MIB.StackIdIndices)
4201 Record.push_back(GetStackIndex(Id));
4204 for (
auto V : AI.Versions)
4207 assert(AI.TotalSizes.empty() || AI.TotalSizes.size() == AI.MIBs.size());
4208 if (!AI.TotalSizes.empty()) {
4209 for (
auto Size : AI.TotalSizes)
4219void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4221 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4222 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4223 unsigned AllocAbbrev,
const Function &
F) {
4229 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4234 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4236 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4237 [&](
unsigned I) {
return I; });
4239 auto SpecialRefCnts =
FS->specialRefCounts();
4244 NameVals.
push_back(SpecialRefCnts.first);
4245 NameVals.
push_back(SpecialRefCnts.second);
4247 for (
auto &RI :
FS->refs())
4250 const bool UseRelBFRecord =
4253 for (
auto &ECI :
FS->calls()) {
4254 NameVals.
push_back(getValueId(ECI.first));
4262 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4273void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4275 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4276 auto VI =
Index->getValueInfo(
V.getGUID());
4277 if (!VI ||
VI.getSummaryList().empty()) {
4283 auto *
Summary =
VI.getSummaryList()[0].get();
4289 auto VTableFuncs =
VS->vTableFuncs();
4290 if (!VTableFuncs.empty())
4293 unsigned SizeBeforeRefs = NameVals.
size();
4294 for (
auto &RI :
VS->refs())
4300 if (VTableFuncs.empty())
4305 for (
auto &
P : VTableFuncs) {
4311 FSModVTableRefsAbbrev);
4318void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4321 bool IsThinLTO =
true;
4323 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4324 IsThinLTO = MD->getZExtValue();
4336 if (
Index->enableSplitLTOUnit())
4338 if (
Index->hasUnifiedLTO())
4348 for (
const auto &GVI : valueIds()) {
4353 if (!
Index->stackIds().empty()) {
4354 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4359 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4364 auto Abbv = std::make_shared<BitCodeAbbrev>();
4376 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4379 Abbv = std::make_shared<BitCodeAbbrev>();
4391 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4394 Abbv = std::make_shared<BitCodeAbbrev>();
4400 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4403 Abbv = std::make_shared<BitCodeAbbrev>();
4411 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4414 Abbv = std::make_shared<BitCodeAbbrev>();
4419 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4422 Abbv = std::make_shared<BitCodeAbbrev>();
4429 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4431 Abbv = std::make_shared<BitCodeAbbrev>();
4437 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4439 Abbv = std::make_shared<BitCodeAbbrev>();
4446 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4458 if (!VI ||
VI.getSummaryList().empty()) {
4464 auto *
Summary =
VI.getSummaryList()[0].get();
4465 writePerModuleFunctionSummaryRecord(
4466 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4467 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev,
F);
4473 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4474 FSModVTableRefsAbbrev);
4477 auto *Aliasee =
A.getAliaseeObject();
4480 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4493 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4497 TypeIdCompatibleVtableAbbrev);
4501 if (
Index->getBlockCount())
4509void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4518 for (
const auto &GVI : valueIds()) {
4525 if (!StackIds.empty()) {
4526 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4531 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4536 auto Abbv = std::make_shared<BitCodeAbbrev>();
4550 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4553 Abbv = std::make_shared<BitCodeAbbrev>();
4560 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4563 Abbv = std::make_shared<BitCodeAbbrev>();
4569 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4571 Abbv = std::make_shared<BitCodeAbbrev>();
4579 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4581 Abbv = std::make_shared<BitCodeAbbrev>();
4590 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4593 if (DecSummaries ==
nullptr)
4595 return DecSummaries->count(GVS);
4609 std::set<GlobalValue::GUID> ReferencedTypeIds;
4623 NameVals.
push_back(S.getOriginalName());
4628 std::set<GlobalValue::GUID> DefOrUseGUIDs;
4629 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4632 DefOrUseGUIDs.insert(
I.first);
4634 DefOrUseGUIDs.insert(
VI.getGUID());
4636 auto ValueId = getValueId(
I.first);
4638 SummaryToValueIdMap[S] = *ValueId;
4646 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4653 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4656 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4659 for (
auto &RI :
VS->refs()) {
4660 auto RefValueId = getValueId(RI.getGUID());
4670 MaybeEmitOriginalName(*S);
4674 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
4676 return std::nullopt;
4677 return getValueId(
VI.getGUID());
4680 auto *
FS = cast<FunctionSummary>(S);
4685 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4689 std::optional<unsigned> ValueID = GetValueId(VI);
4704 return StackIdIndicesToIndex[
I];
4709 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4721 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4722 for (
auto &RI :
FS->refs()) {
4723 auto RefValueId = getValueId(RI.getGUID());
4727 if (RI.isReadOnly())
4729 else if (RI.isWriteOnly())
4733 NameVals[6] = Count;
4734 NameVals[7] = RORefCnt;
4735 NameVals[8] = WORefCnt;
4737 for (
auto &EI :
FS->calls()) {
4740 std::optional<unsigned> CallValueId = GetValueId(EI.first);
4749 FSCallsProfileAbbrev);
4751 MaybeEmitOriginalName(*S);
4754 for (
auto *AS : Aliases) {
4755 auto AliasValueId = SummaryToValueIdMap[AS];
4762 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
4769 MaybeEmitOriginalName(*AS);
4771 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
4775 if (!
Index.cfiFunctionDefs().empty()) {
4776 for (
auto &S :
Index.cfiFunctionDefs()) {
4777 if (DefOrUseGUIDs.count(
4783 if (!NameVals.
empty()) {
4789 if (!
Index.cfiFunctionDecls().empty()) {
4790 for (
auto &S :
Index.cfiFunctionDecls()) {
4791 if (DefOrUseGUIDs.count(
4797 if (!NameVals.
empty()) {
4805 for (
auto &
T : ReferencedTypeIds) {
4806 auto TidIter =
Index.typeIds().equal_range(
T);
4807 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4815 if (
Index.getBlockCount())
4828 auto Abbv = std::make_shared<BitCodeAbbrev>();
4832 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4834 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4837 Abbv = std::make_shared<BitCodeAbbrev>();
4840 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4846void ModuleBitcodeWriter::writeModuleHash(
StringRef View) {
4852 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
4853 std::array<uint8_t, 20> Hash = Hasher.result();
4854 for (
int Pos = 0; Pos < 20; Pos += 4) {
4867void ModuleBitcodeWriter::write() {
4875 writeModuleVersion();
4884 writeAttributeGroupTable();
4887 writeAttributeTable();
4896 writeModuleConstants();
4899 writeModuleMetadataKinds();
4902 writeModuleMetadata();
4906 writeUseListBlock(
nullptr);
4908 writeOperandBundleTags();
4909 writeSyncScopeNames();
4914 if (!
F.isDeclaration())
4915 writeFunction(
F, FunctionToBitcodeIndex);
4920 writePerModuleGlobalValueSummary();
4922 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4950 unsigned CPUType = ~0U;
4957 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4958 DARWIN_CPU_TYPE_X86 = 7,
4959 DARWIN_CPU_TYPE_ARM = 12,
4960 DARWIN_CPU_TYPE_POWERPC = 18
4965 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4967 CPUType = DARWIN_CPU_TYPE_X86;
4969 CPUType = DARWIN_CPU_TYPE_POWERPC;
4971 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4973 CPUType = DARWIN_CPU_TYPE_ARM;
4977 "Expected header size to be reserved");
4982 unsigned Position = 0;
4990 while (Buffer.
size() & 15)
4997 Stream.
Emit((
unsigned)
'B', 8);
4998 Stream.
Emit((
unsigned)
'C', 8);
4999 Stream.
Emit(0x0, 4);
5000 Stream.
Emit(0xC, 4);
5001 Stream.
Emit(0xE, 4);
5002 Stream.
Emit(0xD, 4);
5020 auto Abbv = std::make_shared<BitCodeAbbrev>();
5023 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5031 assert(!WroteStrtab && !WroteSymtab);
5037 if (M->getModuleInlineAsm().empty())
5041 const Triple TT(M->getTargetTriple());
5043 if (!
T || !
T->hasMCAsmParser())
5065 std::vector<char> Strtab;
5067 Strtab.resize(StrtabBuilder.
getSize());
5068 StrtabBuilder.
write((uint8_t *)Strtab.data());
5071 {Strtab.data(), Strtab.size()});
5082 bool ShouldPreserveUseListOrder,
5091 assert(M.isMaterialized());
5092 Mods.push_back(
const_cast<Module *
>(&M));
5094 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5095 ShouldPreserveUseListOrder,
Index,
5096 GenerateHash, ModHash);
5097 ModuleWriter.write();
5102 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5104 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *
Index, DecSummaries,
5105 ModuleToSummariesForIndex);
5106 IndexWriter.write();
5111 bool ShouldPreserveUseListOrder,
5115 Writer.writeModule(M, ShouldPreserveUseListOrder,
Index, GenerateHash,
5117 Writer.writeSymtab();
5118 Writer.writeStrtab();
5120 Triple TT(M.getTargetTriple());
5121 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5139void IndexBitcodeWriter::write() {
5142 writeModuleVersion();
5148 writeCombinedGlobalValueSummary();
5159 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5174class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5184 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5186 ModHash(&ModHash) {}
5191 void writeSimplifiedModuleInfo();
5201void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5213 auto Abbv = std::make_shared<BitCodeAbbrev>();
5216 Abbv->Add(AbbrevOpToUse);
5217 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5219 for (
const auto P :
M.getSourceFileName())
5283void ThinLinkBitcodeWriter::write() {
5286 writeModuleVersion();
5288 writeSimplifiedModuleInfo();
5290 writePerModuleGlobalValueSummary();
5307 assert(M.isMaterialized());
5308 Mods.push_back(
const_cast<Module *
>(&M));
5310 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream,
Index,
5312 ThinLinkWriter.write();
5333 switch (
T.getObjectFormat()) {
5335 return "__LLVM,__bitcode";
5360 switch (
T.getObjectFormat()) {
5362 return "__LLVM,__cmdline";
5388 const std::vector<uint8_t> &CmdArgs) {
5394 for (
auto *GV : UsedGlobals) {
5395 if (GV->getName() !=
"llvm.embedded.module" &&
5396 GV->getName() !=
"llvm.cmdline")
5401 Used->eraseFromParent();
5406 Triple T(M.getTargetTriple());
5435 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5436 assert(Old->hasZeroLiveUses() &&
5437 "llvm.embedded.module can only be used once in llvm.compiler.used");
5439 Old->eraseFromParent();
5441 GV->
setName(
"llvm.embedded.module");
5459 assert(Old->hasZeroLiveUses() &&
5460 "llvm.cmdline can only be used once in llvm.compiler.used");
5462 Old->eraseFromParent();
5468 if (UsedArray.
empty())
5476 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 unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static 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 writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex)
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdSummary &Summary)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Module.h This file contains the declarations for the Module class.
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.
@ Min
*p = old <signed v ? old : v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
void writeIndex(const ModuleSummaryIndex *Index, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
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 parameter attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
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.
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
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.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A class that wrap the SHA1 algorithm.
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_GLOBAL_VAR_EXPR
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_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_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_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *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 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
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