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 {
430 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
434 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
438 std::vector<uint64_t> StackIds;
446 unsigned GlobalValueId = 0;
458 const std::map<std::string, GVSummaryMapTy>
459 *ModuleToSummariesForIndex =
nullptr)
460 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
461 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
465 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
470 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
472 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
479 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
480 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
483 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
489 for (
auto &CI :
FS->callsites()) {
500 if (CI.StackIdIndices.empty()) {
501 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
504 for (
auto Idx : CI.StackIdIndices)
505 RecordStackIdReference(
Idx);
507 for (
auto &AI :
FS->allocs())
508 for (
auto &MIB : AI.MIBs)
509 for (
auto Idx : MIB.StackIdIndices)
510 RecordStackIdReference(
Idx);
515 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
520 template<
typename Functor>
521 void forEachSummary(Functor Callback) {
522 if (ModuleToSummariesForIndex) {
523 for (
auto &M : *ModuleToSummariesForIndex)
524 for (
auto &Summary :
M.second) {
525 Callback(Summary,
false);
529 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
530 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
533 for (
auto &Summaries :
Index)
534 for (
auto &Summary : Summaries.second.SummaryList)
535 Callback({Summaries.first,
Summary.get()},
false);
543 template <
typename Functor>
void forEachModule(Functor Callback) {
544 if (ModuleToSummariesForIndex) {
545 for (
const auto &M : *ModuleToSummariesForIndex) {
546 const auto &MPI =
Index.modulePaths().find(
M.first);
547 if (MPI ==
Index.modulePaths().end()) {
551 assert(ModuleToSummariesForIndex->size() == 1);
561 std::vector<StringRef> ModulePaths;
562 for (
auto &[ModPath,
_] :
Index.modulePaths())
563 ModulePaths.push_back(ModPath);
564 llvm::sort(ModulePaths.begin(), ModulePaths.end());
565 for (
auto &ModPath : ModulePaths)
566 Callback(*
Index.modulePaths().find(ModPath));
574 void writeModStrings();
575 void writeCombinedGlobalValueSummary();
578 auto VMI = GUIDToValueIdMap.find(ValGUID);
579 if (VMI == GUIDToValueIdMap.end())
584 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
618 case Instruction::Add:
620 case Instruction::Sub:
622 case Instruction::Mul:
625 case Instruction::FDiv:
628 case Instruction::FRem:
694 case Attribute::Alignment:
696 case Attribute::AllocAlign:
698 case Attribute::AllocSize:
700 case Attribute::AlwaysInline:
702 case Attribute::Builtin:
704 case Attribute::ByVal:
706 case Attribute::Convergent:
708 case Attribute::InAlloca:
710 case Attribute::Cold:
712 case Attribute::DisableSanitizerInstrumentation:
714 case Attribute::FnRetThunkExtern:
718 case Attribute::ElementType:
720 case Attribute::InlineHint:
722 case Attribute::InReg:
724 case Attribute::JumpTable:
726 case Attribute::MinSize:
728 case Attribute::AllocatedPointer:
730 case Attribute::AllocKind:
732 case Attribute::Memory:
734 case Attribute::NoFPClass:
736 case Attribute::Naked:
738 case Attribute::Nest:
740 case Attribute::NoAlias:
742 case Attribute::NoBuiltin:
744 case Attribute::NoCallback:
746 case Attribute::NoCapture:
748 case Attribute::NoDuplicate:
750 case Attribute::NoFree:
752 case Attribute::NoImplicitFloat:
754 case Attribute::NoInline:
756 case Attribute::NoRecurse:
758 case Attribute::NoMerge:
760 case Attribute::NonLazyBind:
762 case Attribute::NonNull:
764 case Attribute::Dereferenceable:
766 case Attribute::DereferenceableOrNull:
768 case Attribute::NoRedZone:
770 case Attribute::NoReturn:
772 case Attribute::NoSync:
774 case Attribute::NoCfCheck:
776 case Attribute::NoProfile:
778 case Attribute::SkipProfile:
780 case Attribute::NoUnwind:
782 case Attribute::NoSanitizeBounds:
784 case Attribute::NoSanitizeCoverage:
786 case Attribute::NullPointerIsValid:
788 case Attribute::OptimizeForDebugging:
790 case Attribute::OptForFuzzing:
792 case Attribute::OptimizeForSize:
794 case Attribute::OptimizeNone:
796 case Attribute::ReadNone:
798 case Attribute::ReadOnly:
800 case Attribute::Returned:
802 case Attribute::ReturnsTwice:
804 case Attribute::SExt:
806 case Attribute::Speculatable:
808 case Attribute::StackAlignment:
810 case Attribute::StackProtect:
812 case Attribute::StackProtectReq:
814 case Attribute::StackProtectStrong:
816 case Attribute::SafeStack:
818 case Attribute::ShadowCallStack:
820 case Attribute::StrictFP:
822 case Attribute::StructRet:
824 case Attribute::SanitizeAddress:
826 case Attribute::SanitizeHWAddress:
828 case Attribute::SanitizeThread:
830 case Attribute::SanitizeMemory:
832 case Attribute::SanitizeNumericalStability:
834 case Attribute::SpeculativeLoadHardening:
836 case Attribute::SwiftError:
838 case Attribute::SwiftSelf:
840 case Attribute::SwiftAsync:
842 case Attribute::UWTable:
844 case Attribute::VScaleRange:
846 case Attribute::WillReturn:
848 case Attribute::WriteOnly:
850 case Attribute::ZExt:
852 case Attribute::ImmArg:
854 case Attribute::SanitizeMemTag:
856 case Attribute::Preallocated:
858 case Attribute::NoUndef:
860 case Attribute::ByRef:
862 case Attribute::MustProgress:
864 case Attribute::PresplitCoroutine:
866 case Attribute::Writable:
868 case Attribute::CoroDestroyOnlyWhenComplete:
870 case Attribute::DeadOnUnwind:
872 case Attribute::Range:
874 case Attribute::Initializes:
900 unsigned NumWords =
A.getActiveWords();
901 const uint64_t *RawData =
A.getRawData();
902 for (
unsigned i = 0; i < NumWords; i++)
922void ModuleBitcodeWriter::writeAttributeGroupTable() {
923 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
925 if (AttrGrps.empty())
return;
931 unsigned AttrListIndex = Pair.first;
934 Record.push_back(AttrListIndex);
937 if (Attr.isEnumAttribute()) {
940 }
else if (Attr.isIntAttribute()) {
943 Record.push_back(Attr.getValueAsInt());
944 }
else if (Attr.isStringAttribute()) {
955 }
else if (Attr.isTypeAttribute()) {
956 Type *Ty = Attr.getValueAsType();
957 Record.push_back(Ty ? 6 : 5);
961 }
else if (Attr.isConstantRangeAttribute()) {
967 assert(Attr.isConstantRangeListAttribute());
985void ModuleBitcodeWriter::writeAttributeTable() {
987 if (
Attrs.empty())
return;
993 for (
unsigned i :
AL.indexes()) {
1007void ModuleBitcodeWriter::writeTypeTable() {
1016 auto Abbv = std::make_shared<BitCodeAbbrev>();
1019 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1022 Abbv = std::make_shared<BitCodeAbbrev>();
1027 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1030 Abbv = std::make_shared<BitCodeAbbrev>();
1035 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1038 Abbv = std::make_shared<BitCodeAbbrev>();
1042 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1045 Abbv = std::make_shared<BitCodeAbbrev>();
1050 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1053 Abbv = std::make_shared<BitCodeAbbrev>();
1057 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1065 for (
Type *
T : TypeList) {
1066 int AbbrevToUse = 0;
1069 switch (
T->getTypeID()) {
1095 AbbrevToUse = OpaquePtrAbbrev;
1104 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1106 AbbrevToUse = FunctionAbbrev;
1114 for (
Type *ET :
ST->elements())
1117 if (
ST->isLiteral()) {
1119 AbbrevToUse = StructAnonAbbrev;
1121 if (
ST->isOpaque()) {
1125 AbbrevToUse = StructNamedAbbrev;
1129 if (!
ST->getName().empty())
1139 TypeVals.
push_back(AT->getNumElements());
1141 AbbrevToUse = ArrayAbbrev;
1150 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1152 if (isa<ScalableVectorType>(VT))
1162 for (
Type *InnerTy :
TET->type_params())
1164 for (
unsigned IntParam :
TET->int_params())
1173 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1214 RawFlags |= Flags.ReadNone;
1215 RawFlags |= (Flags.ReadOnly << 1);
1216 RawFlags |= (Flags.NoRecurse << 2);
1217 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1218 RawFlags |= (Flags.NoInline << 4);
1219 RawFlags |= (Flags.AlwaysInline << 5);
1220 RawFlags |= (Flags.NoUnwind << 6);
1221 RawFlags |= (Flags.MayThrow << 7);
1222 RawFlags |= (Flags.HasUnknownCall << 8);
1223 RawFlags |= (Flags.MustBeUnreachable << 9);
1232 RawFlags |= Flags.NotEligibleToImport;
1233 RawFlags |= (Flags.Live << 1);
1234 RawFlags |= (Flags.DSOLocal << 2);
1235 RawFlags |= (Flags.CanAutoHide << 3);
1240 RawFlags = (RawFlags << 4) | Flags.Linkage;
1242 RawFlags |= (Flags.Visibility << 8);
1244 RawFlags |= (Flags.ImportType << 10);
1250 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1251 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1293 case GlobalVariable::NotThreadLocal:
return 0;
1294 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1295 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1296 case GlobalVariable::InitialExecTLSModel:
return 3;
1297 case GlobalVariable::LocalExecTLSModel:
return 4;
1303 switch (
C.getSelectionKind()) {
1320 case GlobalValue::UnnamedAddr::None:
return 0;
1321 case GlobalValue::UnnamedAddr::Local:
return 2;
1322 case GlobalValue::UnnamedAddr::Global:
return 1;
1327size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1330 return StrtabBuilder.
add(Str);
1333void ModuleBitcodeWriter::writeComdats() {
1348void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1353 auto Abbv = std::make_shared<BitCodeAbbrev>();
1359 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1375 bool isChar6 =
true;
1376 for (
char C : Str) {
1379 if ((
unsigned char)
C & 128)
1389 "Sanitizer Metadata is too large for naive serialization.");
1392 return Meta.NoAddress | (Meta.NoHWAddress << 1) |
1393 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1399void ModuleBitcodeWriter::writeModuleInfo() {
1401 if (!
M.getTargetTriple().empty())
1404 const std::string &
DL =
M.getDataLayoutStr();
1407 if (!
M.getModuleInlineAsm().empty())
1413 std::map<std::string, unsigned> SectionMap;
1414 std::map<std::string, unsigned> GCMap;
1416 unsigned MaxGlobalType = 0;
1417 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1419 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1422 UpdateMaxAlignment(GV.getAlign());
1423 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1424 if (GV.hasSection()) {
1426 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1430 Entry = SectionMap.size();
1435 UpdateMaxAlignment(
F.getAlign());
1436 if (
F.hasSection()) {
1438 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1442 Entry = SectionMap.size();
1447 unsigned &
Entry = GCMap[
F.getGC()];
1451 Entry = GCMap.size();
1457 unsigned SimpleGVarAbbrev = 0;
1458 if (!
M.global_empty()) {
1460 auto Abbv = std::make_shared<BitCodeAbbrev>();
1474 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1478 if (SectionMap.empty())
1484 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1498 auto Abbv = std::make_shared<BitCodeAbbrev>();
1501 Abbv->Add(AbbrevOpToUse);
1502 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1504 for (
const auto P :
M.getSourceFileName())
1514 unsigned AbbrevToUse = 0;
1520 Vals.
push_back(addToStrtab(GV.getName()));
1523 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1527 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1528 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1530 if (GV.isThreadLocal() ||
1532 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1533 GV.isExternallyInitialized() ||
1535 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1536 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1540 Vals.
push_back(GV.isExternallyInitialized());
1548 Vals.
push_back(addToStrtab(GV.getPartition()));
1549 Vals.
push_back(GV.getPartition().size());
1552 GV.getSanitizerMetadata())
1556 AbbrevToUse = SimpleGVarAbbrev;
1576 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1577 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1589 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1593 Vals.
push_back(addToStrtab(
F.getPartition()));
1596 unsigned AbbrevToUse = 0;
1609 Vals.
push_back(
A.getType()->getAddressSpace());
1617 Vals.
push_back(addToStrtab(
A.getPartition()));
1620 unsigned AbbrevToUse = 0;
1632 Vals.
push_back(
I.getType()->getAddressSpace());
1637 Vals.
push_back(addToStrtab(
I.getPartition()));
1643 writeValueSymbolTableForwardDecl();
1649 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1650 if (OBO->hasNoSignedWrap())
1652 if (OBO->hasNoUnsignedWrap())
1654 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1657 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1658 if (PDI->isDisjoint())
1660 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1661 if (FPMO->hasAllowReassoc())
1663 if (FPMO->hasNoNaNs())
1665 if (FPMO->hasNoInfs())
1667 if (FPMO->hasNoSignedZeros())
1669 if (FPMO->hasAllowReciprocal())
1671 if (FPMO->hasAllowContract())
1673 if (FPMO->hasApproxFunc())
1675 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1676 if (NNI->hasNonNeg())
1678 }
else if (
const auto *TI = dyn_cast<TruncInst>(V)) {
1679 if (TI->hasNoSignedWrap())
1681 if (TI->hasNoUnsignedWrap())
1683 }
else if (
const auto *
GEP = dyn_cast<GEPOperator>(V)) {
1684 if (
GEP->isInBounds())
1686 if (
GEP->hasNoUnsignedSignedWrap())
1688 if (
GEP->hasNoUnsignedWrap())
1695void ModuleBitcodeWriter::writeValueAsMetadata(
1705void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1710 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1711 "Unexpected function-local metadata");
1720unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1723 auto Abbv = std::make_shared<BitCodeAbbrev>();
1734void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1738 Abbrev = createDILocationAbbrev();
1740 Record.push_back(
N->isDistinct());
1741 Record.push_back(
N->getLine());
1742 Record.push_back(
N->getColumn());
1745 Record.push_back(
N->isImplicitCode());
1751unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1754 auto Abbv = std::make_shared<BitCodeAbbrev>();
1765void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1769 Abbrev = createGenericDINodeAbbrev();
1771 Record.push_back(
N->isDistinct());
1772 Record.push_back(
N->getTag());
1775 for (
auto &
I :
N->operands())
1782void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1796void ModuleBitcodeWriter::writeDIGenericSubrange(
1809void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1813 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1814 Record.push_back(
N->getValue().getBitWidth());
1822void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1825 Record.push_back(
N->isDistinct());
1826 Record.push_back(
N->getTag());
1828 Record.push_back(
N->getSizeInBits());
1829 Record.push_back(
N->getAlignInBits());
1830 Record.push_back(
N->getEncoding());
1831 Record.push_back(
N->getFlags());
1837void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1840 Record.push_back(
N->isDistinct());
1841 Record.push_back(
N->getTag());
1846 Record.push_back(
N->getSizeInBits());
1847 Record.push_back(
N->getAlignInBits());
1848 Record.push_back(
N->getEncoding());
1854void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1857 Record.push_back(
N->isDistinct());
1858 Record.push_back(
N->getTag());
1861 Record.push_back(
N->getLine());
1864 Record.push_back(
N->getSizeInBits());
1865 Record.push_back(
N->getAlignInBits());
1866 Record.push_back(
N->getOffsetInBits());
1867 Record.push_back(
N->getFlags());
1872 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1873 Record.push_back(*DWARFAddressSpace + 1);
1879 if (
auto PtrAuthData =
N->getPtrAuthData())
1880 Record.push_back(PtrAuthData->RawData);
1888void ModuleBitcodeWriter::writeDICompositeType(
1891 const unsigned IsNotUsedInOldTypeRef = 0x2;
1892 Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1893 Record.push_back(
N->getTag());
1896 Record.push_back(
N->getLine());
1899 Record.push_back(
N->getSizeInBits());
1900 Record.push_back(
N->getAlignInBits());
1901 Record.push_back(
N->getOffsetInBits());
1902 Record.push_back(
N->getFlags());
1904 Record.push_back(
N->getRuntimeLang());
1919void ModuleBitcodeWriter::writeDISubroutineType(
1922 const unsigned HasNoOldTypeRefs = 0x2;
1923 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1924 Record.push_back(
N->getFlags());
1932void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
1935 Record.push_back(
N->isDistinct());
1938 if (
N->getRawChecksum()) {
1939 Record.push_back(
N->getRawChecksum()->Kind);
1947 auto Source =
N->getRawSource();
1955void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
1958 assert(
N->isDistinct() &&
"Expected distinct compile units");
1960 Record.push_back(
N->getSourceLanguage());
1963 Record.push_back(
N->isOptimized());
1965 Record.push_back(
N->getRuntimeVersion());
1967 Record.push_back(
N->getEmissionKind());
1973 Record.push_back(
N->getDWOId());
1975 Record.push_back(
N->getSplitDebugInlining());
1976 Record.push_back(
N->getDebugInfoForProfiling());
1977 Record.push_back((
unsigned)
N->getNameTableKind());
1978 Record.push_back(
N->getRangesBaseAddress());
1986void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
1989 const uint64_t HasUnitFlag = 1 << 1;
1990 const uint64_t HasSPFlagsFlag = 1 << 2;
1991 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
1996 Record.push_back(
N->getLine());
1998 Record.push_back(
N->getScopeLine());
2000 Record.push_back(
N->getSPFlags());
2001 Record.push_back(
N->getVirtualIndex());
2002 Record.push_back(
N->getFlags());
2007 Record.push_back(
N->getThisAdjustment());
2019 Record.push_back(
N->isDistinct());
2022 Record.push_back(
N->getLine());
2023 Record.push_back(
N->getColumn());
2029void ModuleBitcodeWriter::writeDILexicalBlockFile(
2032 Record.push_back(
N->isDistinct());
2035 Record.push_back(
N->getDiscriminator());
2041void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2044 Record.push_back(
N->isDistinct());
2049 Record.push_back(
N->getLineNo());
2055void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2058 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2066void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2069 Record.push_back(
N->isDistinct());
2070 Record.push_back(
N->getMacinfoType());
2071 Record.push_back(
N->getLine());
2079void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2082 Record.push_back(
N->isDistinct());
2083 Record.push_back(
N->getMacinfoType());
2084 Record.push_back(
N->getLine());
2092void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2094 Record.reserve(
N->getArgs().size());
2102void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2105 Record.push_back(
N->isDistinct());
2106 for (
auto &
I :
N->operands())
2108 Record.push_back(
N->getLineNo());
2109 Record.push_back(
N->getIsDecl());
2115void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2119 Record.push_back(
N->isDistinct());
2124void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2127 Record.push_back(
N->isDistinct());
2130 Record.push_back(
N->isDefault());
2136void ModuleBitcodeWriter::writeDITemplateValueParameter(
2139 Record.push_back(
N->isDistinct());
2140 Record.push_back(
N->getTag());
2143 Record.push_back(
N->isDefault());
2150void ModuleBitcodeWriter::writeDIGlobalVariable(
2159 Record.push_back(
N->getLine());
2161 Record.push_back(
N->isLocalToUnit());
2162 Record.push_back(
N->isDefinition());
2165 Record.push_back(
N->getAlignInBits());
2172void ModuleBitcodeWriter::writeDILocalVariable(
2188 const uint64_t HasAlignmentFlag = 1 << 1;
2193 Record.push_back(
N->getLine());
2195 Record.push_back(
N->getArg());
2196 Record.push_back(
N->getFlags());
2197 Record.push_back(
N->getAlignInBits());
2204void ModuleBitcodeWriter::writeDILabel(
2211 Record.push_back(
N->getLine());
2217void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2220 Record.reserve(
N->getElements().size() + 1);
2223 Record.append(
N->elements_begin(),
N->elements_end());
2229void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2232 Record.push_back(
N->isDistinct());
2243 Record.push_back(
N->isDistinct());
2246 Record.push_back(
N->getLine());
2249 Record.push_back(
N->getAttributes());
2256void ModuleBitcodeWriter::writeDIImportedEntity(
2259 Record.push_back(
N->isDistinct());
2260 Record.push_back(
N->getTag());
2263 Record.push_back(
N->getLine());
2272unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2273 auto Abbv = std::make_shared<BitCodeAbbrev>();
2280void ModuleBitcodeWriter::writeNamedMetadata(
2282 if (
M.named_metadata_empty())
2285 unsigned Abbrev = createNamedMetadataAbbrev();
2289 Record.append(Str.bytes_begin(), Str.bytes_end());
2294 for (
const MDNode *
N : NMD.operands())
2301unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2302 auto Abbv = std::make_shared<BitCodeAbbrev>();
2314void ModuleBitcodeWriter::writeMetadataStrings(
2316 if (Strings.empty())
2321 Record.push_back(Strings.size());
2328 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2337 Blob.
append(cast<MDString>(MD)->getString());
2346#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2347#include "llvm/IR/Metadata.def"
2351void ModuleBitcodeWriter::writeMetadataRecords(
2353 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2358#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2359#include "llvm/IR/Metadata.def"
2364 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2365 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2367 switch (
N->getMetadataID()) {
2370#define HANDLE_MDNODE_LEAF(CLASS) \
2371 case Metadata::CLASS##Kind: \
2373 write##CLASS(cast<CLASS>(N), Record, \
2374 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2376 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2378#include "llvm/IR/Metadata.def"
2381 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2385 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2389void ModuleBitcodeWriter::writeModuleMetadata() {
2390 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2398 std::vector<unsigned> MDAbbrevs;
2401 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2402 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2403 createGenericDINodeAbbrev();
2405 auto Abbv = std::make_shared<BitCodeAbbrev>();
2409 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2411 Abbv = std::make_shared<BitCodeAbbrev>();
2415 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2437 std::vector<uint64_t> IndexPos;
2452 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2453 for (
auto &Elt : IndexPos) {
2454 auto EltDelta = Elt - PreviousValue;
2455 PreviousValue = Elt;
2464 writeNamedMetadata(
Record);
2466 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2469 pushGlobalMetadataAttachment(
Record, GO);
2473 if (
F.isDeclaration() &&
F.hasMetadata())
2474 AddDeclAttachedMetadata(
F);
2478 if (GV.hasMetadata())
2479 AddDeclAttachedMetadata(GV);
2484void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2495void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2500 for (
const auto &
I : MDs) {
2506void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2511 if (
F.hasMetadata()) {
2512 pushGlobalMetadataAttachment(
Record,
F);
2523 I.getAllMetadataOtherThanDebugLoc(MDs);
2526 if (MDs.
empty())
continue;
2530 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2531 Record.push_back(MDs[i].first);
2541void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2547 M.getMDKindNames(Names);
2549 if (Names.
empty())
return;
2553 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2554 Record.push_back(MDKindID);
2565void ModuleBitcodeWriter::writeOperandBundleTags() {
2573 M.getOperandBundleTags(Tags);
2582 for (
auto Tag : Tags) {
2592void ModuleBitcodeWriter::writeSyncScopeNames() {
2594 M.getContext().getSyncScopeNames(SSNs);
2601 for (
auto SSN : SSNs) {
2602 Record.append(SSN.begin(), SSN.end());
2610void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2612 if (FirstVal == LastVal)
return;
2616 unsigned AggregateAbbrev = 0;
2617 unsigned String8Abbrev = 0;
2618 unsigned CString7Abbrev = 0;
2619 unsigned CString6Abbrev = 0;
2623 auto Abbv = std::make_shared<BitCodeAbbrev>();
2627 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2630 Abbv = std::make_shared<BitCodeAbbrev>();
2634 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2636 Abbv = std::make_shared<BitCodeAbbrev>();
2640 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2642 Abbv = std::make_shared<BitCodeAbbrev>();
2646 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2652 Type *LastTy =
nullptr;
2653 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2654 const Value *
V = Vals[i].first;
2656 if (
V->getType() != LastTy) {
2657 LastTy =
V->getType();
2660 CONSTANTS_SETTYPE_ABBREV);
2664 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2667 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2668 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2671 const std::string &AsmStr =
IA->getAsmString();
2672 Record.push_back(AsmStr.size());
2673 Record.append(AsmStr.begin(), AsmStr.end());
2676 const std::string &ConstraintStr =
IA->getConstraintString();
2677 Record.push_back(ConstraintStr.size());
2678 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2684 unsigned Code = -1U;
2685 unsigned AbbrevToUse = 0;
2686 if (
C->isNullValue()) {
2688 }
else if (isa<PoisonValue>(
C)) {
2690 }
else if (isa<UndefValue>(
C)) {
2693 if (
IV->getBitWidth() <= 64) {
2697 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2702 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2707 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2711 APInt api = CFP->getValueAPF().bitcastToAPInt();
2713 Record.push_back((p[1] << 48) | (p[0] >> 16));
2714 Record.push_back(p[0] & 0xffffLL);
2716 APInt api = CFP->getValueAPF().bitcastToAPInt();
2721 assert(0 &&
"Unknown FP type!");
2723 }
else if (isa<ConstantDataSequential>(
C) &&
2724 cast<ConstantDataSequential>(
C)->isString()) {
2727 unsigned NumElts = Str->getNumElements();
2729 if (Str->isCString()) {
2734 AbbrevToUse = String8Abbrev;
2738 for (
unsigned i = 0; i != NumElts; ++i) {
2739 unsigned char V = Str->getElementAsInteger(i);
2741 isCStr7 &= (
V & 128) == 0;
2747 AbbrevToUse = CString6Abbrev;
2749 AbbrevToUse = CString7Abbrev;
2751 dyn_cast<ConstantDataSequential>(
C)) {
2753 Type *EltTy = CDS->getElementType();
2754 if (isa<IntegerType>(EltTy)) {
2755 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2756 Record.push_back(CDS->getElementAsInteger(i));
2758 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2760 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2762 }
else if (isa<ConstantAggregate>(
C)) {
2764 for (
const Value *
Op :
C->operands())
2766 AbbrevToUse = AggregateAbbrev;
2767 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2768 switch (
CE->getOpcode()) {
2775 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2777 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2787 case Instruction::FNeg: {
2788 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2797 case Instruction::GetElementPtr: {
2799 const auto *GO = cast<GEPOperator>(
C);
2802 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2806 for (
unsigned i = 0, e =
CE->getNumOperands(); i != e; ++i) {
2812 case Instruction::ExtractElement:
2819 case Instruction::InsertElement:
2826 case Instruction::ShuffleVector:
2831 if (
C->getType() ==
C->getOperand(0)->getType()) {
2842 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2847 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2851 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
2855 }
else if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C)) {
2874void ModuleBitcodeWriter::writeModuleConstants() {
2879 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2880 if (!isa<GlobalValue>(Vals[i].first)) {
2881 writeConstants(i, Vals.size(),
true);
2895bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2900 if (
ValID >= InstID) {
2907void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
2914 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2916 for (
auto &Input : Bundle.Inputs)
2917 pushValueAndType(Input, InstID,
Record);
2926void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2932void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2935 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2940void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2944 unsigned AbbrevToUse = 0;
2946 switch (
I.getOpcode()) {
2950 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2951 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2956 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
2957 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
2961 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
2963 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2964 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2965 pushValue(
I.getOperand(1), InstID, Vals);
2969 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2970 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2975 case Instruction::FNeg: {
2977 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2978 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2982 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
2983 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
2988 case Instruction::GetElementPtr: {
2990 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2991 auto &GEPInst = cast<GetElementPtrInst>(
I);
2994 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
2995 pushValueAndType(
I.getOperand(i), InstID, Vals);
2998 case Instruction::ExtractValue: {
3000 pushValueAndType(
I.getOperand(0), InstID, Vals);
3005 case Instruction::InsertValue: {
3007 pushValueAndType(
I.getOperand(0), InstID, Vals);
3008 pushValueAndType(
I.getOperand(1), InstID, Vals);
3013 case Instruction::Select: {
3015 pushValueAndType(
I.getOperand(1), InstID, Vals);
3016 pushValue(
I.getOperand(2), InstID, Vals);
3017 pushValueAndType(
I.getOperand(0), InstID, Vals);
3023 case Instruction::ExtractElement:
3025 pushValueAndType(
I.getOperand(0), InstID, Vals);
3026 pushValueAndType(
I.getOperand(1), InstID, Vals);
3028 case Instruction::InsertElement:
3030 pushValueAndType(
I.getOperand(0), InstID, Vals);
3031 pushValue(
I.getOperand(1), InstID, Vals);
3032 pushValueAndType(
I.getOperand(2), InstID, Vals);
3034 case Instruction::ShuffleVector:
3036 pushValueAndType(
I.getOperand(0), InstID, Vals);
3037 pushValue(
I.getOperand(1), InstID, Vals);
3038 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3041 case Instruction::ICmp:
3042 case Instruction::FCmp: {
3045 pushValueAndType(
I.getOperand(0), InstID, Vals);
3046 pushValue(
I.getOperand(1), InstID, Vals);
3054 case Instruction::Ret:
3057 unsigned NumOperands =
I.getNumOperands();
3058 if (NumOperands == 0)
3059 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3060 else if (NumOperands == 1) {
3061 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3062 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3064 for (
unsigned i = 0, e = NumOperands; i !=
e; ++i)
3065 pushValueAndType(
I.getOperand(i), InstID, Vals);
3069 case Instruction::Br:
3074 if (
II.isConditional()) {
3076 pushValue(
II.getCondition(), InstID, Vals);
3080 case Instruction::Switch:
3085 pushValue(
SI.getCondition(), InstID, Vals);
3087 for (
auto Case :
SI.cases()) {
3093 case Instruction::IndirectBr:
3097 pushValue(
I.getOperand(0), InstID, Vals);
3098 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i)
3102 case Instruction::Invoke: {
3107 if (
II->hasOperandBundles())
3108 writeOperandBundles(*
II, InstID);
3117 pushValueAndType(Callee, InstID, Vals);
3120 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3121 pushValue(
I.getOperand(i), InstID, Vals);
3124 if (FTy->isVarArg()) {
3125 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3126 pushValueAndType(
I.getOperand(i), InstID, Vals);
3130 case Instruction::Resume:
3132 pushValueAndType(
I.getOperand(0), InstID, Vals);
3134 case Instruction::CleanupRet: {
3136 const auto &CRI = cast<CleanupReturnInst>(
I);
3137 pushValue(CRI.getCleanupPad(), InstID, Vals);
3138 if (CRI.hasUnwindDest())
3142 case Instruction::CatchRet: {
3144 const auto &CRI = cast<CatchReturnInst>(
I);
3145 pushValue(CRI.getCatchPad(), InstID, Vals);
3149 case Instruction::CleanupPad:
3150 case Instruction::CatchPad: {
3151 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3154 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3156 unsigned NumArgOperands = FuncletPad.arg_size();
3158 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3159 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3162 case Instruction::CatchSwitch: {
3164 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3166 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3168 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3170 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3173 if (CatchSwitch.hasUnwindDest())
3177 case Instruction::CallBr: {
3183 writeOperandBundles(*CBI, InstID);
3198 pushValueAndType(Callee, InstID, Vals);
3201 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3202 pushValue(
I.getOperand(i), InstID, Vals);
3205 if (FTy->isVarArg()) {
3206 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3207 pushValueAndType(
I.getOperand(i), InstID, Vals);
3211 case Instruction::Unreachable:
3213 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3216 case Instruction::PHI: {
3217 const PHINode &PN = cast<PHINode>(
I);
3234 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3239 case Instruction::LandingPad: {
3250 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3255 case Instruction::Alloca: {
3263 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3264 Bitfield::set<APV::AlignLower>(
3265 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3266 Bitfield::set<APV::AlignUpper>(
Record,
3267 EncodedAlign >> APV::AlignLower::Bits);
3269 Bitfield::set<APV::ExplicitType>(
Record,
true);
3274 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3279 case Instruction::Load:
3280 if (cast<LoadInst>(
I).isAtomic()) {
3282 pushValueAndType(
I.getOperand(0), InstID, Vals);
3285 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3286 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3290 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3291 if (cast<LoadInst>(
I).isAtomic()) {
3293 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3296 case Instruction::Store:
3297 if (cast<StoreInst>(
I).isAtomic())
3301 pushValueAndType(
I.getOperand(1), InstID, Vals);
3302 pushValueAndType(
I.getOperand(0), InstID, Vals);
3304 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3305 if (cast<StoreInst>(
I).isAtomic()) {
3308 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3311 case Instruction::AtomicCmpXchg:
3313 pushValueAndType(
I.getOperand(0), InstID, Vals);
3314 pushValueAndType(
I.getOperand(1), InstID, Vals);
3315 pushValue(
I.getOperand(2), InstID, Vals);
3316 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3320 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3323 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3326 case Instruction::AtomicRMW:
3328 pushValueAndType(
I.getOperand(0), InstID, Vals);
3329 pushValueAndType(
I.getOperand(1), InstID, Vals);
3332 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3335 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3338 case Instruction::Fence:
3341 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3343 case Instruction::Call: {
3348 writeOperandBundles(CI, InstID);
3368 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3370 if (FTy->getParamType(i)->isLabelTy())
3377 if (FTy->isVarArg()) {
3378 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3383 case Instruction::VAArg:
3386 pushValue(
I.getOperand(0), InstID, Vals);
3389 case Instruction::Freeze:
3391 pushValueAndType(
I.getOperand(0), InstID, Vals);
3401void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3407 VSTOffset -= bitcodeStartBit();
3408 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3412 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3416 auto Abbv = std::make_shared<BitCodeAbbrev>();
3420 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3425 if (
F.isDeclaration())
3432 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3433 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3437 Record[1] = BitcodeIndex / 32 + 1;
3446void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3461 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3467 if (isa<BasicBlock>(
Name.getValue())) {
3470 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3474 AbbrevToUse = VST_ENTRY_6_ABBREV;
3476 AbbrevToUse = VST_ENTRY_7_ABBREV;
3479 for (
const auto P :
Name.getKey())
3483 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3490void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3491 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3493 if (isa<BasicBlock>(Order.V))
3503void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3505 "Expected to be preserving use-list order");
3507 auto hasMore = [&]() {
3523void ModuleBitcodeWriter::writeFunction(
3542 unsigned CstStart, CstEnd;
3544 writeConstants(CstStart, CstEnd,
false);
3547 writeFunctionMetadata(
F);
3550 unsigned InstID = CstEnd;
3552 bool NeedsMetadataAttachment =
F.hasMetadata();
3560 writeInstruction(
I, InstID, Vals);
3562 if (!
I.getType()->isVoidTy())
3566 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3593 auto PushValueOrMetadata = [&Vals, InstID,
3596 "RawLocation unexpectedly null in DbgVariableRecord");
3602 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3616 for (
DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3642 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3664 while (!Worklist.empty()) {
3665 Value *
V = Worklist.pop_back_val();
3666 for (
User *U :
V->users()) {
3667 if (
auto *
I = dyn_cast<Instruction>(U)) {
3671 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3672 Visited.insert(U).second)
3673 Worklist.push_back(U);
3679 if (!BlockAddressUsers.
empty()) {
3688 if (
auto *Symtab =
F.getValueSymbolTable())
3689 writeFunctionLevelValueSymbolTable(*Symtab);
3691 if (NeedsMetadataAttachment)
3692 writeFunctionMetadataAttachment(
F);
3694 writeUseListBlock(&
F);
3700void ModuleBitcodeWriter::writeBlockInfo() {
3707 auto Abbv = std::make_shared<BitCodeAbbrev>();
3718 auto Abbv = std::make_shared<BitCodeAbbrev>();
3728 auto Abbv = std::make_shared<BitCodeAbbrev>();
3738 auto Abbv = std::make_shared<BitCodeAbbrev>();
3744 VST_BBENTRY_6_ABBREV)
3749 auto Abbv = std::make_shared<BitCodeAbbrev>();
3754 CONSTANTS_SETTYPE_ABBREV)
3759 auto Abbv = std::make_shared<BitCodeAbbrev>();
3763 CONSTANTS_INTEGER_ABBREV)
3768 auto Abbv = std::make_shared<BitCodeAbbrev>();
3776 CONSTANTS_CE_CAST_Abbrev)
3780 auto Abbv = std::make_shared<BitCodeAbbrev>();
3783 CONSTANTS_NULL_Abbrev)
3790 auto Abbv = std::make_shared<BitCodeAbbrev>();
3798 FUNCTION_INST_LOAD_ABBREV)
3802 auto Abbv = std::make_shared<BitCodeAbbrev>();
3807 FUNCTION_INST_UNOP_ABBREV)
3811 auto Abbv = std::make_shared<BitCodeAbbrev>();
3817 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3821 auto Abbv = std::make_shared<BitCodeAbbrev>();
3827 FUNCTION_INST_BINOP_ABBREV)
3831 auto Abbv = std::make_shared<BitCodeAbbrev>();
3838 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3842 auto Abbv = std::make_shared<BitCodeAbbrev>();
3849 FUNCTION_INST_CAST_ABBREV)
3853 auto Abbv = std::make_shared<BitCodeAbbrev>();
3861 FUNCTION_INST_CAST_FLAGS_ABBREV)
3866 auto Abbv = std::make_shared<BitCodeAbbrev>();
3869 FUNCTION_INST_RET_VOID_ABBREV)
3873 auto Abbv = std::make_shared<BitCodeAbbrev>();
3877 FUNCTION_INST_RET_VAL_ABBREV)
3881 auto Abbv = std::make_shared<BitCodeAbbrev>();
3884 FUNCTION_INST_UNREACHABLE_ABBREV)
3888 auto Abbv = std::make_shared<BitCodeAbbrev>();
3896 FUNCTION_INST_GEP_ABBREV)
3900 auto Abbv = std::make_shared<BitCodeAbbrev>();
3907 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3915void IndexBitcodeWriter::writeModStrings() {
3921 auto Abbv = std::make_shared<BitCodeAbbrev>();
3926 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3929 Abbv = std::make_shared<BitCodeAbbrev>();
3934 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3937 Abbv = std::make_shared<BitCodeAbbrev>();
3942 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3945 Abbv = std::make_shared<BitCodeAbbrev>();
3952 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3957 const auto &Hash = MPSE.
getValue();
3959 unsigned AbbrevToUse = Abbrev8Bit;
3961 AbbrevToUse = Abbrev6Bit;
3963 AbbrevToUse = Abbrev7Bit;
3965 auto ModuleId = ModuleIdMap.
size();
3966 ModuleIdMap[
Key] = ModuleId;
3975 Vals.
assign(Hash.begin(), Hash.end());
3987template <
typename Fn>
3991 if (!FS->type_tests().empty())
3996 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4001 for (
auto &VF : VFs) {
4002 Record.push_back(VF.GUID);
4003 Record.push_back(VF.Offset);
4009 FS->type_test_assume_vcalls());
4011 FS->type_checked_load_vcalls());
4013 auto WriteConstVCallVec = [&](
uint64_t Ty,
4015 for (
auto &VC : VCs) {
4017 Record.push_back(VC.VFunc.GUID);
4018 Record.push_back(VC.VFunc.Offset);
4025 FS->type_test_assume_const_vcalls());
4027 FS->type_checked_load_const_vcalls());
4037 if (!FS->paramAccesses().empty()) {
4039 for (
auto &Arg : FS->paramAccesses()) {
4040 size_t UndoSize =
Record.size();
4041 Record.push_back(Arg.ParamNo);
4042 WriteRange(Arg.Use);
4043 Record.push_back(Arg.Calls.size());
4044 for (
auto &Call : Arg.Calls) {
4045 Record.push_back(Call.ParamNo);
4046 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4053 Record.push_back(*ValueID);
4054 WriteRange(Call.Offsets);
4065 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4066 if (!FS->type_tests().empty())
4067 for (
auto &TT : FS->type_tests())
4068 ReferencedTypeIds.insert(TT);
4070 auto GetReferencedTypesFromVFuncIdVec =
4072 for (
auto &VF : VFs)
4073 ReferencedTypeIds.insert(VF.GUID);
4076 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4077 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4079 auto GetReferencedTypesFromConstVCallVec =
4081 for (
auto &VC : VCs)
4082 ReferencedTypeIds.insert(VC.VFunc.GUID);
4085 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4086 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4117 const std::string &Id,
4122 NameVals.
push_back(Summary.TTRes.TheKind);
4123 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4124 NameVals.
push_back(Summary.TTRes.AlignLog2);
4125 NameVals.
push_back(Summary.TTRes.SizeM1);
4126 NameVals.
push_back(Summary.TTRes.BitMask);
4127 NameVals.
push_back(Summary.TTRes.InlineBits);
4129 for (
auto &W : Summary.WPDRes)
4141 for (
auto &
P : Summary) {
4149 unsigned AllocAbbrev,
bool PerModule,
4150 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4151 std::function<
unsigned(
unsigned)> GetStackIndex) {
4154 for (
auto &CI : FS->callsites()) {
4158 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4159 Record.push_back(GetValueID(CI.Callee));
4161 Record.push_back(CI.StackIdIndices.size());
4162 Record.push_back(CI.Clones.size());
4164 for (
auto Id : CI.StackIdIndices)
4165 Record.push_back(GetStackIndex(Id));
4167 for (
auto V : CI.Clones)
4175 for (
auto &AI : FS->allocs()) {
4179 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4181 Record.push_back(AI.MIBs.size());
4182 Record.push_back(AI.Versions.size());
4184 for (
auto &MIB : AI.MIBs) {
4185 Record.push_back((uint8_t)MIB.AllocType);
4186 Record.push_back(MIB.StackIdIndices.size());
4187 for (
auto Id : MIB.StackIdIndices)
4188 Record.push_back(GetStackIndex(Id));
4191 for (
auto V : AI.Versions)
4201void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4203 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4204 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4205 unsigned AllocAbbrev,
const Function &
F) {
4211 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4216 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4218 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4219 [&](
unsigned I) {
return I; });
4221 auto SpecialRefCnts =
FS->specialRefCounts();
4226 NameVals.
push_back(SpecialRefCnts.first);
4227 NameVals.
push_back(SpecialRefCnts.second);
4229 for (
auto &RI :
FS->refs())
4232 const bool UseRelBFRecord =
4235 for (
auto &ECI :
FS->calls()) {
4236 NameVals.
push_back(getValueId(ECI.first));
4244 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4255void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4257 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4258 auto VI =
Index->getValueInfo(
V.getGUID());
4259 if (!VI ||
VI.getSummaryList().empty()) {
4265 auto *
Summary =
VI.getSummaryList()[0].get();
4271 auto VTableFuncs =
VS->vTableFuncs();
4272 if (!VTableFuncs.empty())
4275 unsigned SizeBeforeRefs = NameVals.
size();
4276 for (
auto &RI :
VS->refs())
4282 if (VTableFuncs.empty())
4287 for (
auto &
P : VTableFuncs) {
4293 FSModVTableRefsAbbrev);
4300void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4303 bool IsThinLTO =
true;
4305 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4306 IsThinLTO = MD->getZExtValue();
4318 if (
Index->enableSplitLTOUnit())
4320 if (
Index->hasUnifiedLTO())
4330 for (
const auto &GVI : valueIds()) {
4335 if (!
Index->stackIds().empty()) {
4336 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4341 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4346 auto Abbv = std::make_shared<BitCodeAbbrev>();
4358 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4361 Abbv = std::make_shared<BitCodeAbbrev>();
4373 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4376 Abbv = std::make_shared<BitCodeAbbrev>();
4382 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4385 Abbv = std::make_shared<BitCodeAbbrev>();
4393 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4396 Abbv = std::make_shared<BitCodeAbbrev>();
4401 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4404 Abbv = std::make_shared<BitCodeAbbrev>();
4411 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4413 Abbv = std::make_shared<BitCodeAbbrev>();
4419 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4421 Abbv = std::make_shared<BitCodeAbbrev>();
4426 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4438 if (!VI ||
VI.getSummaryList().empty()) {
4444 auto *
Summary =
VI.getSummaryList()[0].get();
4445 writePerModuleFunctionSummaryRecord(
4446 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4447 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev,
F);
4453 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4454 FSModVTableRefsAbbrev);
4457 auto *Aliasee =
A.getAliaseeObject();
4460 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4473 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4477 TypeIdCompatibleVtableAbbrev);
4481 if (
Index->getBlockCount())
4489void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4498 for (
const auto &GVI : valueIds()) {
4505 if (!StackIds.empty()) {
4506 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4511 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4516 auto Abbv = std::make_shared<BitCodeAbbrev>();
4530 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4533 Abbv = std::make_shared<BitCodeAbbrev>();
4540 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4543 Abbv = std::make_shared<BitCodeAbbrev>();
4549 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4551 Abbv = std::make_shared<BitCodeAbbrev>();
4559 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4561 Abbv = std::make_shared<BitCodeAbbrev>();
4569 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4582 std::set<GlobalValue::GUID> ReferencedTypeIds;
4596 NameVals.
push_back(S.getOriginalName());
4601 std::set<GlobalValue::GUID> DefOrUseGUIDs;
4602 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4605 DefOrUseGUIDs.insert(
I.first);
4607 DefOrUseGUIDs.insert(
VI.getGUID());
4609 auto ValueId = getValueId(
I.first);
4611 SummaryToValueIdMap[S] = *ValueId;
4619 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4626 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4629 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4632 for (
auto &RI :
VS->refs()) {
4633 auto RefValueId = getValueId(RI.getGUID());
4643 MaybeEmitOriginalName(*S);
4647 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
4649 return std::nullopt;
4650 return getValueId(
VI.getGUID());
4653 auto *
FS = cast<FunctionSummary>(S);
4658 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4661 std::optional<unsigned> ValueID = GetValueId(VI);
4675 return StackIdIndicesToIndex[
I];
4680 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4691 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4692 for (
auto &RI :
FS->refs()) {
4693 auto RefValueId = getValueId(RI.getGUID());
4697 if (RI.isReadOnly())
4699 else if (RI.isWriteOnly())
4703 NameVals[6] = Count;
4704 NameVals[7] = RORefCnt;
4705 NameVals[8] = WORefCnt;
4707 for (
auto &EI :
FS->calls()) {
4710 std::optional<unsigned> CallValueId = GetValueId(EI.first);
4719 FSCallsProfileAbbrev);
4721 MaybeEmitOriginalName(*S);
4724 for (
auto *AS : Aliases) {
4725 auto AliasValueId = SummaryToValueIdMap[AS];
4731 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
4738 MaybeEmitOriginalName(*AS);
4740 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
4744 if (!
Index.cfiFunctionDefs().empty()) {
4745 for (
auto &S :
Index.cfiFunctionDefs()) {
4746 if (DefOrUseGUIDs.count(
4752 if (!NameVals.
empty()) {
4758 if (!
Index.cfiFunctionDecls().empty()) {
4759 for (
auto &S :
Index.cfiFunctionDecls()) {
4760 if (DefOrUseGUIDs.count(
4766 if (!NameVals.
empty()) {
4774 for (
auto &
T : ReferencedTypeIds) {
4775 auto TidIter =
Index.typeIds().equal_range(
T);
4776 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4784 if (
Index.getBlockCount())
4797 auto Abbv = std::make_shared<BitCodeAbbrev>();
4801 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4803 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4806 Abbv = std::make_shared<BitCodeAbbrev>();
4809 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4815void ModuleBitcodeWriter::writeModuleHash(
StringRef View) {
4821 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
4822 std::array<uint8_t, 20> Hash = Hasher.result();
4823 for (
int Pos = 0; Pos < 20; Pos += 4) {
4836void ModuleBitcodeWriter::write() {
4844 writeModuleVersion();
4853 writeAttributeGroupTable();
4856 writeAttributeTable();
4865 writeModuleConstants();
4868 writeModuleMetadataKinds();
4871 writeModuleMetadata();
4875 writeUseListBlock(
nullptr);
4877 writeOperandBundleTags();
4878 writeSyncScopeNames();
4883 if (!
F.isDeclaration())
4884 writeFunction(
F, FunctionToBitcodeIndex);
4889 writePerModuleGlobalValueSummary();
4891 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4919 unsigned CPUType = ~0U;
4926 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4927 DARWIN_CPU_TYPE_X86 = 7,
4928 DARWIN_CPU_TYPE_ARM = 12,
4929 DARWIN_CPU_TYPE_POWERPC = 18
4934 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4936 CPUType = DARWIN_CPU_TYPE_X86;
4938 CPUType = DARWIN_CPU_TYPE_POWERPC;
4940 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4942 CPUType = DARWIN_CPU_TYPE_ARM;
4946 "Expected header size to be reserved");
4951 unsigned Position = 0;
4959 while (Buffer.
size() & 15)
4966 Stream.
Emit((
unsigned)
'B', 8);
4967 Stream.
Emit((
unsigned)
'C', 8);
4968 Stream.
Emit(0x0, 4);
4969 Stream.
Emit(0xC, 4);
4970 Stream.
Emit(0xE, 4);
4971 Stream.
Emit(0xD, 4);
4989 auto Abbv = std::make_shared<BitCodeAbbrev>();
4992 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5000 assert(!WroteStrtab && !WroteSymtab);
5006 if (M->getModuleInlineAsm().empty())
5010 const Triple TT(M->getTargetTriple());
5012 if (!
T || !
T->hasMCAsmParser())
5034 std::vector<char> Strtab;
5036 Strtab.resize(StrtabBuilder.
getSize());
5037 StrtabBuilder.
write((uint8_t *)Strtab.data());
5040 {Strtab.data(), Strtab.size()});
5051 bool ShouldPreserveUseListOrder,
5060 assert(M.isMaterialized());
5061 Mods.push_back(
const_cast<Module *
>(&M));
5063 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5064 ShouldPreserveUseListOrder,
Index,
5065 GenerateHash, ModHash);
5066 ModuleWriter.write();
5071 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5072 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *
Index,
5073 ModuleToSummariesForIndex);
5074 IndexWriter.write();
5079 bool ShouldPreserveUseListOrder,
5083 Writer.writeModule(M, ShouldPreserveUseListOrder,
Index, GenerateHash,
5085 Writer.writeSymtab();
5086 Writer.writeStrtab();
5088 Triple TT(M.getTargetTriple());
5089 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5107void IndexBitcodeWriter::write() {
5110 writeModuleVersion();
5116 writeCombinedGlobalValueSummary();
5127 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5141class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5151 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5153 ModHash(&ModHash) {}
5158 void writeSimplifiedModuleInfo();
5168void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5180 auto Abbv = std::make_shared<BitCodeAbbrev>();
5183 Abbv->Add(AbbrevOpToUse);
5184 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5186 for (
const auto P :
M.getSourceFileName())
5250void ThinLinkBitcodeWriter::write() {
5253 writeModuleVersion();
5255 writeSimplifiedModuleInfo();
5257 writePerModuleGlobalValueSummary();
5274 assert(M.isMaterialized());
5275 Mods.push_back(
const_cast<Module *
>(&M));
5277 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream,
Index,
5279 ThinLinkWriter.write();
5300 switch (
T.getObjectFormat()) {
5302 return "__LLVM,__bitcode";
5327 switch (
T.getObjectFormat()) {
5329 return "__LLVM,__cmdline";
5355 const std::vector<uint8_t> &CmdArgs) {
5361 for (
auto *GV : UsedGlobals) {
5362 if (GV->getName() !=
"llvm.embedded.module" &&
5363 GV->getName() !=
"llvm.cmdline")
5368 Used->eraseFromParent();
5373 Triple T(M.getTargetTriple());
5402 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5403 assert(Old->hasZeroLiveUses() &&
5404 "llvm.embedded.module can only be used once in llvm.compiler.used");
5406 Old->eraseFromParent();
5408 GV->
setName(
"llvm.embedded.module");
5426 assert(Old->hasZeroLiveUses() &&
5427 "llvm.cmdline can only be used once in llvm.compiler.used");
5429 Old->eraseFromParent();
5435 if (UsedArray.
empty())
5443 NewUsed->setSection(
"llvm.metadata");
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
llvm::cl::opt< bool > UseNewDbgInfoFormat
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static 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)
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_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
AtomicOrdering
Atomic ordering for LLVM's memory model.
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