31#include "llvm/Config/llvm-config.h"
88 cl::desc(
"Number of metadatas above which we emit an index "
89 "to enable lazy-loading"));
92 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
96 cl::desc(
"Write relative block frequency to function summary "));
114 VST_BBENTRY_6_ABBREV,
118 CONSTANTS_INTEGER_ABBREV,
119 CONSTANTS_CE_CAST_Abbrev,
120 CONSTANTS_NULL_Abbrev,
124 FUNCTION_INST_UNOP_ABBREV,
125 FUNCTION_INST_UNOP_FLAGS_ABBREV,
126 FUNCTION_INST_BINOP_ABBREV,
127 FUNCTION_INST_BINOP_FLAGS_ABBREV,
128 FUNCTION_INST_CAST_ABBREV,
129 FUNCTION_INST_CAST_FLAGS_ABBREV,
130 FUNCTION_INST_RET_VOID_ABBREV,
131 FUNCTION_INST_RET_VAL_ABBREV,
132 FUNCTION_INST_UNREACHABLE_ABBREV,
133 FUNCTION_INST_GEP_ABBREV,
134 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
139class BitcodeWriterBase {
150 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
153 void writeModuleVersion();
156void BitcodeWriterBase::writeModuleVersion() {
163class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
177 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
180 unsigned GlobalValueId;
191 bool ShouldPreserveUseListOrder,
193 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
203 for (
const auto &GUIDSummaryLists : *
Index)
205 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
206 if (
auto FS = dyn_cast<FunctionSummary>(
Summary.get())) {
211 for (
auto &CallEdge :
FS->calls())
212 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
213 assignValueId(CallEdge.first.getGUID());
219 for (
auto &RefEdge :
FS->refs())
220 if (!RefEdge.haveGVs() || !RefEdge.getValue())
221 assignValueId(RefEdge.getGUID());
226 void writePerModuleGlobalValueSummary();
229 void writePerModuleFunctionSummaryRecord(
231 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
232 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
const Function &
F);
235 unsigned FSModRefsAbbrev,
236 unsigned FSModVTableRefsAbbrev);
239 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
243 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
246 assert(VMI != GUIDToValueIdMap.end() &&
247 "GUID does not have assigned value Id");
253 if (!
VI.haveGVs() || !
VI.getValue())
254 return getValueId(
VI.getGUID());
258 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
262class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
286 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
287 ShouldPreserveUseListOrder,
Index),
288 Buffer(Buffer), GenerateHash(GenerateHash), ModHash(ModHash),
289 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
295 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
299 void writeAttributeGroupTable();
300 void writeAttributeTable();
301 void writeTypeTable();
303 void writeValueSymbolTableForwardDecl();
304 void writeModuleInfo();
309 unsigned createDILocationAbbrev();
312 unsigned createGenericDINodeAbbrev();
380 unsigned createNamedMetadataAbbrev();
382 unsigned createMetadataStringsAbbrev();
387 std::vector<unsigned> *MDAbbrevs =
nullptr,
388 std::vector<uint64_t> *IndexPos =
nullptr);
389 void writeModuleMetadata();
390 void writeFunctionMetadata(
const Function &
F);
391 void writeFunctionMetadataAttachment(
const Function &
F);
394 void writeModuleMetadataKinds();
395 void writeOperandBundleTags();
396 void writeSyncScopeNames();
397 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
398 void writeModuleConstants();
399 bool pushValueAndType(
const Value *V,
unsigned InstID,
401 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
402 void pushValue(
const Value *V,
unsigned InstID,
404 void pushValueSigned(
const Value *V,
unsigned InstID,
406 void writeInstruction(
const Instruction &
I,
unsigned InstID,
409 void writeGlobalValueSymbolTable(
412 void writeUseListBlock(
const Function *
F);
416 void writeBlockInfo();
417 void writeModuleHash(
size_t BlockStartPos);
423 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
427class IndexBitcodeWriter :
public BitcodeWriterBase {
433 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
437 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
442 std::vector<unsigned> StackIdIndices;
445 unsigned GlobalValueId = 0;
457 const std::map<std::string, GVSummaryMapTy>
458 *ModuleToSummariesForIndex =
nullptr)
459 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
460 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
465 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
466 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
469 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
475 for (
auto &CI :
FS->callsites()) {
486 if (CI.StackIdIndices.empty()) {
487 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
490 for (
auto Idx : CI.StackIdIndices)
491 StackIdIndices.push_back(
Idx);
493 for (
auto &AI :
FS->allocs())
494 for (
auto &MIB : AI.MIBs)
495 for (
auto Idx : MIB.StackIdIndices)
496 StackIdIndices.push_back(
Idx);
499 StackIdIndices.erase(
500 std::unique(StackIdIndices.begin(), StackIdIndices.end()),
501 StackIdIndices.end());
505 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
510 template<
typename Functor>
511 void forEachSummary(Functor Callback) {
512 if (ModuleToSummariesForIndex) {
513 for (
auto &M : *ModuleToSummariesForIndex)
514 for (
auto &Summary :
M.second) {
515 Callback(Summary,
false);
519 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
520 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
523 for (
auto &Summaries :
Index)
524 for (
auto &Summary : Summaries.second.SummaryList)
525 Callback({Summaries.first,
Summary.get()},
false);
533 template <
typename Functor>
void forEachModule(Functor Callback) {
534 if (ModuleToSummariesForIndex) {
535 for (
const auto &M : *ModuleToSummariesForIndex) {
536 const auto &MPI =
Index.modulePaths().find(
M.first);
537 if (MPI ==
Index.modulePaths().end()) {
541 assert(ModuleToSummariesForIndex->size() == 1);
551 std::vector<StringRef> ModulePaths;
552 for (
auto &[ModPath,
_] :
Index.modulePaths())
553 ModulePaths.push_back(ModPath);
554 llvm::sort(ModulePaths.begin(), ModulePaths.end());
555 for (
auto &ModPath : ModulePaths)
556 Callback(*
Index.modulePaths().find(ModPath));
564 void writeModStrings();
565 void writeCombinedGlobalValueSummary();
568 auto VMI = GUIDToValueIdMap.find(ValGUID);
569 if (VMI == GUIDToValueIdMap.end())
574 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
608 case Instruction::Add:
610 case Instruction::Sub:
612 case Instruction::Mul:
615 case Instruction::FDiv:
618 case Instruction::FRem:
684 case Attribute::Alignment:
686 case Attribute::AllocAlign:
688 case Attribute::AllocSize:
690 case Attribute::AlwaysInline:
692 case Attribute::Builtin:
694 case Attribute::ByVal:
696 case Attribute::Convergent:
698 case Attribute::InAlloca:
700 case Attribute::Cold:
702 case Attribute::DisableSanitizerInstrumentation:
704 case Attribute::FnRetThunkExtern:
708 case Attribute::ElementType:
710 case Attribute::InlineHint:
712 case Attribute::InReg:
714 case Attribute::JumpTable:
716 case Attribute::MinSize:
718 case Attribute::AllocatedPointer:
720 case Attribute::AllocKind:
722 case Attribute::Memory:
724 case Attribute::NoFPClass:
726 case Attribute::Naked:
728 case Attribute::Nest:
730 case Attribute::NoAlias:
732 case Attribute::NoBuiltin:
734 case Attribute::NoCallback:
736 case Attribute::NoCapture:
738 case Attribute::NoDuplicate:
740 case Attribute::NoFree:
742 case Attribute::NoImplicitFloat:
744 case Attribute::NoInline:
746 case Attribute::NoRecurse:
748 case Attribute::NoMerge:
750 case Attribute::NonLazyBind:
752 case Attribute::NonNull:
754 case Attribute::Dereferenceable:
756 case Attribute::DereferenceableOrNull:
758 case Attribute::NoRedZone:
760 case Attribute::NoReturn:
762 case Attribute::NoSync:
764 case Attribute::NoCfCheck:
766 case Attribute::NoProfile:
768 case Attribute::SkipProfile:
770 case Attribute::NoUnwind:
772 case Attribute::NoSanitizeBounds:
774 case Attribute::NoSanitizeCoverage:
776 case Attribute::NullPointerIsValid:
778 case Attribute::OptimizeForDebugging:
780 case Attribute::OptForFuzzing:
782 case Attribute::OptimizeForSize:
784 case Attribute::OptimizeNone:
786 case Attribute::ReadNone:
788 case Attribute::ReadOnly:
790 case Attribute::Returned:
792 case Attribute::ReturnsTwice:
794 case Attribute::SExt:
796 case Attribute::Speculatable:
798 case Attribute::StackAlignment:
800 case Attribute::StackProtect:
802 case Attribute::StackProtectReq:
804 case Attribute::StackProtectStrong:
806 case Attribute::SafeStack:
808 case Attribute::ShadowCallStack:
810 case Attribute::StrictFP:
812 case Attribute::StructRet:
814 case Attribute::SanitizeAddress:
816 case Attribute::SanitizeHWAddress:
818 case Attribute::SanitizeThread:
820 case Attribute::SanitizeMemory:
822 case Attribute::SpeculativeLoadHardening:
824 case Attribute::SwiftError:
826 case Attribute::SwiftSelf:
828 case Attribute::SwiftAsync:
830 case Attribute::UWTable:
832 case Attribute::VScaleRange:
834 case Attribute::WillReturn:
836 case Attribute::WriteOnly:
838 case Attribute::ZExt:
840 case Attribute::ImmArg:
842 case Attribute::SanitizeMemTag:
844 case Attribute::Preallocated:
846 case Attribute::NoUndef:
848 case Attribute::ByRef:
850 case Attribute::MustProgress:
852 case Attribute::PresplitCoroutine:
854 case Attribute::Writable:
856 case Attribute::CoroDestroyOnlyWhenComplete:
858 case Attribute::DeadOnUnwind:
860 case Attribute::Range:
886 unsigned NumWords =
A.getActiveWords();
887 const uint64_t *RawData =
A.getRawData();
888 for (
unsigned i = 0; i < NumWords; i++)
907void ModuleBitcodeWriter::writeAttributeGroupTable() {
908 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
910 if (AttrGrps.empty())
return;
916 unsigned AttrListIndex = Pair.first;
919 Record.push_back(AttrListIndex);
922 if (Attr.isEnumAttribute()) {
925 }
else if (Attr.isIntAttribute()) {
928 Record.push_back(Attr.getValueAsInt());
929 }
else if (Attr.isStringAttribute()) {
940 }
else if (Attr.isTypeAttribute()) {
941 Type *Ty = Attr.getValueAsType();
942 Record.push_back(Ty ? 6 : 5);
947 assert(Attr.isConstantRangeAttribute());
961void ModuleBitcodeWriter::writeAttributeTable() {
963 if (
Attrs.empty())
return;
969 for (
unsigned i :
AL.indexes()) {
983void ModuleBitcodeWriter::writeTypeTable() {
992 auto Abbv = std::make_shared<BitCodeAbbrev>();
995 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
998 Abbv = std::make_shared<BitCodeAbbrev>();
1003 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1006 Abbv = std::make_shared<BitCodeAbbrev>();
1011 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1014 Abbv = std::make_shared<BitCodeAbbrev>();
1018 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1021 Abbv = std::make_shared<BitCodeAbbrev>();
1026 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1029 Abbv = std::make_shared<BitCodeAbbrev>();
1033 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1041 for (
Type *
T : TypeList) {
1042 int AbbrevToUse = 0;
1045 switch (
T->getTypeID()) {
1071 AbbrevToUse = OpaquePtrAbbrev;
1080 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1082 AbbrevToUse = FunctionAbbrev;
1090 for (
Type *ET :
ST->elements())
1093 if (
ST->isLiteral()) {
1095 AbbrevToUse = StructAnonAbbrev;
1097 if (
ST->isOpaque()) {
1101 AbbrevToUse = StructNamedAbbrev;
1105 if (!
ST->getName().empty())
1115 TypeVals.
push_back(AT->getNumElements());
1117 AbbrevToUse = ArrayAbbrev;
1126 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1128 if (isa<ScalableVectorType>(VT))
1138 for (
Type *InnerTy :
TET->type_params())
1140 for (
unsigned IntParam :
TET->int_params())
1149 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1190 RawFlags |= Flags.ReadNone;
1191 RawFlags |= (Flags.ReadOnly << 1);
1192 RawFlags |= (Flags.NoRecurse << 2);
1193 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1194 RawFlags |= (Flags.NoInline << 4);
1195 RawFlags |= (Flags.AlwaysInline << 5);
1196 RawFlags |= (Flags.NoUnwind << 6);
1197 RawFlags |= (Flags.MayThrow << 7);
1198 RawFlags |= (Flags.HasUnknownCall << 8);
1199 RawFlags |= (Flags.MustBeUnreachable << 9);
1208 RawFlags |= Flags.NotEligibleToImport;
1209 RawFlags |= (Flags.Live << 1);
1210 RawFlags |= (Flags.DSOLocal << 2);
1211 RawFlags |= (Flags.CanAutoHide << 3);
1216 RawFlags = (RawFlags << 4) | Flags.Linkage;
1218 RawFlags |= (Flags.Visibility << 8);
1220 RawFlags |= (Flags.ImportType << 10);
1226 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1227 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1269 case GlobalVariable::NotThreadLocal:
return 0;
1270 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1271 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1272 case GlobalVariable::InitialExecTLSModel:
return 3;
1273 case GlobalVariable::LocalExecTLSModel:
return 4;
1279 switch (
C.getSelectionKind()) {
1296 case GlobalValue::UnnamedAddr::None:
return 0;
1297 case GlobalValue::UnnamedAddr::Local:
return 2;
1298 case GlobalValue::UnnamedAddr::Global:
return 1;
1303size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1306 return StrtabBuilder.
add(Str);
1309void ModuleBitcodeWriter::writeComdats() {
1324void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1329 auto Abbv = std::make_shared<BitCodeAbbrev>();
1335 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1351 bool isChar6 =
true;
1352 for (
char C : Str) {
1355 if ((
unsigned char)
C & 128)
1365 "Sanitizer Metadata is too large for naive serialization.");
1368 return Meta.NoAddress | (Meta.NoHWAddress << 1) |
1369 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1375void ModuleBitcodeWriter::writeModuleInfo() {
1377 if (!
M.getTargetTriple().empty())
1380 const std::string &
DL =
M.getDataLayoutStr();
1383 if (!
M.getModuleInlineAsm().empty())
1389 std::map<std::string, unsigned> SectionMap;
1390 std::map<std::string, unsigned> GCMap;
1392 unsigned MaxGlobalType = 0;
1393 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1395 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1398 UpdateMaxAlignment(GV.getAlign());
1399 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1400 if (GV.hasSection()) {
1402 unsigned &Entry = SectionMap[std::string(GV.getSection())];
1406 Entry = SectionMap.size();
1411 UpdateMaxAlignment(
F.getAlign());
1412 if (
F.hasSection()) {
1414 unsigned &Entry = SectionMap[std::string(
F.getSection())];
1418 Entry = SectionMap.size();
1423 unsigned &Entry = GCMap[
F.getGC()];
1427 Entry = GCMap.size();
1433 unsigned SimpleGVarAbbrev = 0;
1434 if (!
M.global_empty()) {
1436 auto Abbv = std::make_shared<BitCodeAbbrev>();
1450 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1454 if (SectionMap.empty())
1460 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1474 auto Abbv = std::make_shared<BitCodeAbbrev>();
1477 Abbv->Add(AbbrevOpToUse);
1478 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1480 for (
const auto P :
M.getSourceFileName())
1490 unsigned AbbrevToUse = 0;
1496 Vals.
push_back(addToStrtab(GV.getName()));
1499 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1503 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1504 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1506 if (GV.isThreadLocal() ||
1508 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1509 GV.isExternallyInitialized() ||
1511 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1512 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1516 Vals.
push_back(GV.isExternallyInitialized());
1524 Vals.
push_back(addToStrtab(GV.getPartition()));
1525 Vals.
push_back(GV.getPartition().size());
1528 GV.getSanitizerMetadata())
1532 AbbrevToUse = SimpleGVarAbbrev;
1552 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1553 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1565 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1569 Vals.
push_back(addToStrtab(
F.getPartition()));
1572 unsigned AbbrevToUse = 0;
1585 Vals.
push_back(
A.getType()->getAddressSpace());
1593 Vals.
push_back(addToStrtab(
A.getPartition()));
1596 unsigned AbbrevToUse = 0;
1608 Vals.
push_back(
I.getType()->getAddressSpace());
1613 Vals.
push_back(addToStrtab(
I.getPartition()));
1619 writeValueSymbolTableForwardDecl();
1625 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1626 if (OBO->hasNoSignedWrap())
1628 if (OBO->hasNoUnsignedWrap())
1630 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1633 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1634 if (PDI->isDisjoint())
1636 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1637 if (FPMO->hasAllowReassoc())
1639 if (FPMO->hasNoNaNs())
1641 if (FPMO->hasNoInfs())
1643 if (FPMO->hasNoSignedZeros())
1645 if (FPMO->hasAllowReciprocal())
1647 if (FPMO->hasAllowContract())
1649 if (FPMO->hasApproxFunc())
1651 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1652 if (NNI->hasNonNeg())
1654 }
else if (
const auto *TI = dyn_cast<TruncInst>(V)) {
1655 if (TI->hasNoSignedWrap())
1657 if (TI->hasNoUnsignedWrap())
1664void ModuleBitcodeWriter::writeValueAsMetadata(
1674void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1679 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1680 "Unexpected function-local metadata");
1689unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1692 auto Abbv = std::make_shared<BitCodeAbbrev>();
1703void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1707 Abbrev = createDILocationAbbrev();
1709 Record.push_back(
N->isDistinct());
1710 Record.push_back(
N->getLine());
1711 Record.push_back(
N->getColumn());
1714 Record.push_back(
N->isImplicitCode());
1720unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1723 auto Abbv = std::make_shared<BitCodeAbbrev>();
1734void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1738 Abbrev = createGenericDINodeAbbrev();
1740 Record.push_back(
N->isDistinct());
1741 Record.push_back(
N->getTag());
1744 for (
auto &
I :
N->operands())
1751void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1765void ModuleBitcodeWriter::writeDIGenericSubrange(
1778void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1782 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1783 Record.push_back(
N->getValue().getBitWidth());
1791void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1794 Record.push_back(
N->isDistinct());
1795 Record.push_back(
N->getTag());
1797 Record.push_back(
N->getSizeInBits());
1798 Record.push_back(
N->getAlignInBits());
1799 Record.push_back(
N->getEncoding());
1800 Record.push_back(
N->getFlags());
1806void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1809 Record.push_back(
N->isDistinct());
1810 Record.push_back(
N->getTag());
1815 Record.push_back(
N->getSizeInBits());
1816 Record.push_back(
N->getAlignInBits());
1817 Record.push_back(
N->getEncoding());
1823void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1826 Record.push_back(
N->isDistinct());
1827 Record.push_back(
N->getTag());
1830 Record.push_back(
N->getLine());
1833 Record.push_back(
N->getSizeInBits());
1834 Record.push_back(
N->getAlignInBits());
1835 Record.push_back(
N->getOffsetInBits());
1836 Record.push_back(
N->getFlags());
1841 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1842 Record.push_back(*DWARFAddressSpace + 1);
1848 if (
auto PtrAuthData =
N->getPtrAuthData())
1849 Record.push_back(PtrAuthData->RawData);
1857void ModuleBitcodeWriter::writeDICompositeType(
1860 const unsigned IsNotUsedInOldTypeRef = 0x2;
1861 Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1862 Record.push_back(
N->getTag());
1865 Record.push_back(
N->getLine());
1868 Record.push_back(
N->getSizeInBits());
1869 Record.push_back(
N->getAlignInBits());
1870 Record.push_back(
N->getOffsetInBits());
1871 Record.push_back(
N->getFlags());
1873 Record.push_back(
N->getRuntimeLang());
1888void ModuleBitcodeWriter::writeDISubroutineType(
1891 const unsigned HasNoOldTypeRefs = 0x2;
1892 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1893 Record.push_back(
N->getFlags());
1901void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
1904 Record.push_back(
N->isDistinct());
1907 if (
N->getRawChecksum()) {
1908 Record.push_back(
N->getRawChecksum()->Kind);
1916 auto Source =
N->getRawSource();
1924void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
1927 assert(
N->isDistinct() &&
"Expected distinct compile units");
1929 Record.push_back(
N->getSourceLanguage());
1932 Record.push_back(
N->isOptimized());
1934 Record.push_back(
N->getRuntimeVersion());
1936 Record.push_back(
N->getEmissionKind());
1942 Record.push_back(
N->getDWOId());
1944 Record.push_back(
N->getSplitDebugInlining());
1945 Record.push_back(
N->getDebugInfoForProfiling());
1946 Record.push_back((
unsigned)
N->getNameTableKind());
1947 Record.push_back(
N->getRangesBaseAddress());
1955void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
1958 const uint64_t HasUnitFlag = 1 << 1;
1959 const uint64_t HasSPFlagsFlag = 1 << 2;
1960 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
1965 Record.push_back(
N->getLine());
1967 Record.push_back(
N->getScopeLine());
1969 Record.push_back(
N->getSPFlags());
1970 Record.push_back(
N->getVirtualIndex());
1971 Record.push_back(
N->getFlags());
1976 Record.push_back(
N->getThisAdjustment());
1988 Record.push_back(
N->isDistinct());
1991 Record.push_back(
N->getLine());
1992 Record.push_back(
N->getColumn());
1998void ModuleBitcodeWriter::writeDILexicalBlockFile(
2001 Record.push_back(
N->isDistinct());
2004 Record.push_back(
N->getDiscriminator());
2010void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2013 Record.push_back(
N->isDistinct());
2018 Record.push_back(
N->getLineNo());
2024void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2027 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2035void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2038 Record.push_back(
N->isDistinct());
2039 Record.push_back(
N->getMacinfoType());
2040 Record.push_back(
N->getLine());
2048void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2051 Record.push_back(
N->isDistinct());
2052 Record.push_back(
N->getMacinfoType());
2053 Record.push_back(
N->getLine());
2061void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2063 Record.reserve(
N->getArgs().size());
2071void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2074 Record.push_back(
N->isDistinct());
2075 for (
auto &
I :
N->operands())
2077 Record.push_back(
N->getLineNo());
2078 Record.push_back(
N->getIsDecl());
2084void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2088 Record.push_back(
N->isDistinct());
2093void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2096 Record.push_back(
N->isDistinct());
2099 Record.push_back(
N->isDefault());
2105void ModuleBitcodeWriter::writeDITemplateValueParameter(
2108 Record.push_back(
N->isDistinct());
2109 Record.push_back(
N->getTag());
2112 Record.push_back(
N->isDefault());
2119void ModuleBitcodeWriter::writeDIGlobalVariable(
2128 Record.push_back(
N->getLine());
2130 Record.push_back(
N->isLocalToUnit());
2131 Record.push_back(
N->isDefinition());
2134 Record.push_back(
N->getAlignInBits());
2141void ModuleBitcodeWriter::writeDILocalVariable(
2157 const uint64_t HasAlignmentFlag = 1 << 1;
2162 Record.push_back(
N->getLine());
2164 Record.push_back(
N->getArg());
2165 Record.push_back(
N->getFlags());
2166 Record.push_back(
N->getAlignInBits());
2173void ModuleBitcodeWriter::writeDILabel(
2180 Record.push_back(
N->getLine());
2186void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2189 Record.reserve(
N->getElements().size() + 1);
2192 Record.append(
N->elements_begin(),
N->elements_end());
2198void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2201 Record.push_back(
N->isDistinct());
2212 Record.push_back(
N->isDistinct());
2215 Record.push_back(
N->getLine());
2218 Record.push_back(
N->getAttributes());
2225void ModuleBitcodeWriter::writeDIImportedEntity(
2228 Record.push_back(
N->isDistinct());
2229 Record.push_back(
N->getTag());
2232 Record.push_back(
N->getLine());
2241unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2242 auto Abbv = std::make_shared<BitCodeAbbrev>();
2249void ModuleBitcodeWriter::writeNamedMetadata(
2251 if (
M.named_metadata_empty())
2254 unsigned Abbrev = createNamedMetadataAbbrev();
2258 Record.append(Str.bytes_begin(), Str.bytes_end());
2263 for (
const MDNode *
N : NMD.operands())
2270unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2271 auto Abbv = std::make_shared<BitCodeAbbrev>();
2283void ModuleBitcodeWriter::writeMetadataStrings(
2285 if (Strings.empty())
2290 Record.push_back(Strings.size());
2297 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2306 Blob.
append(cast<MDString>(MD)->getString());
2315#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2316#include "llvm/IR/Metadata.def"
2320void ModuleBitcodeWriter::writeMetadataRecords(
2322 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2327#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2328#include "llvm/IR/Metadata.def"
2333 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2334 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2336 switch (
N->getMetadataID()) {
2339#define HANDLE_MDNODE_LEAF(CLASS) \
2340 case Metadata::CLASS##Kind: \
2342 write##CLASS(cast<CLASS>(N), Record, \
2343 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2345 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2347#include "llvm/IR/Metadata.def"
2350 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2354 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2358void ModuleBitcodeWriter::writeModuleMetadata() {
2359 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2367 std::vector<unsigned> MDAbbrevs;
2370 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2371 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2372 createGenericDINodeAbbrev();
2374 auto Abbv = std::make_shared<BitCodeAbbrev>();
2378 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2380 Abbv = std::make_shared<BitCodeAbbrev>();
2384 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2406 std::vector<uint64_t> IndexPos;
2421 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2422 for (
auto &Elt : IndexPos) {
2423 auto EltDelta = Elt - PreviousValue;
2424 PreviousValue = Elt;
2433 writeNamedMetadata(
Record);
2435 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2438 pushGlobalMetadataAttachment(
Record, GO);
2442 if (
F.isDeclaration() &&
F.hasMetadata())
2443 AddDeclAttachedMetadata(
F);
2447 if (GV.hasMetadata())
2448 AddDeclAttachedMetadata(GV);
2453void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2464void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2469 for (
const auto &
I : MDs) {
2475void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2480 if (
F.hasMetadata()) {
2481 pushGlobalMetadataAttachment(
Record,
F);
2492 I.getAllMetadataOtherThanDebugLoc(MDs);
2495 if (MDs.
empty())
continue;
2499 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2500 Record.push_back(MDs[i].first);
2510void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2516 M.getMDKindNames(Names);
2518 if (Names.
empty())
return;
2522 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2523 Record.push_back(MDKindID);
2534void ModuleBitcodeWriter::writeOperandBundleTags() {
2542 M.getOperandBundleTags(Tags);
2551 for (
auto Tag : Tags) {
2561void ModuleBitcodeWriter::writeSyncScopeNames() {
2563 M.getContext().getSyncScopeNames(SSNs);
2570 for (
auto SSN : SSNs) {
2571 Record.append(SSN.begin(), SSN.end());
2579void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2581 if (FirstVal == LastVal)
return;
2585 unsigned AggregateAbbrev = 0;
2586 unsigned String8Abbrev = 0;
2587 unsigned CString7Abbrev = 0;
2588 unsigned CString6Abbrev = 0;
2592 auto Abbv = std::make_shared<BitCodeAbbrev>();
2596 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2599 Abbv = std::make_shared<BitCodeAbbrev>();
2603 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2605 Abbv = std::make_shared<BitCodeAbbrev>();
2609 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2611 Abbv = std::make_shared<BitCodeAbbrev>();
2615 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2621 Type *LastTy =
nullptr;
2622 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2623 const Value *
V = Vals[i].first;
2625 if (
V->getType() != LastTy) {
2626 LastTy =
V->getType();
2629 CONSTANTS_SETTYPE_ABBREV);
2633 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2636 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2637 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2640 const std::string &AsmStr =
IA->getAsmString();
2641 Record.push_back(AsmStr.size());
2642 Record.append(AsmStr.begin(), AsmStr.end());
2645 const std::string &ConstraintStr =
IA->getConstraintString();
2646 Record.push_back(ConstraintStr.size());
2647 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2653 unsigned Code = -1U;
2654 unsigned AbbrevToUse = 0;
2655 if (
C->isNullValue()) {
2657 }
else if (isa<PoisonValue>(
C)) {
2659 }
else if (isa<UndefValue>(
C)) {
2662 if (
IV->getBitWidth() <= 64) {
2666 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2671 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2676 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2680 APInt api = CFP->getValueAPF().bitcastToAPInt();
2682 Record.push_back((p[1] << 48) | (p[0] >> 16));
2683 Record.push_back(p[0] & 0xffffLL);
2685 APInt api = CFP->getValueAPF().bitcastToAPInt();
2690 assert(0 &&
"Unknown FP type!");
2692 }
else if (isa<ConstantDataSequential>(
C) &&
2693 cast<ConstantDataSequential>(
C)->isString()) {
2696 unsigned NumElts = Str->getNumElements();
2698 if (Str->isCString()) {
2703 AbbrevToUse = String8Abbrev;
2707 for (
unsigned i = 0; i != NumElts; ++i) {
2708 unsigned char V = Str->getElementAsInteger(i);
2710 isCStr7 &= (
V & 128) == 0;
2716 AbbrevToUse = CString6Abbrev;
2718 AbbrevToUse = CString7Abbrev;
2720 dyn_cast<ConstantDataSequential>(
C)) {
2722 Type *EltTy = CDS->getElementType();
2723 if (isa<IntegerType>(EltTy)) {
2724 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2725 Record.push_back(CDS->getElementAsInteger(i));
2727 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2729 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2731 }
else if (isa<ConstantAggregate>(
C)) {
2733 for (
const Value *
Op :
C->operands())
2735 AbbrevToUse = AggregateAbbrev;
2736 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2737 switch (
CE->getOpcode()) {
2744 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2746 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2756 case Instruction::FNeg: {
2757 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2766 case Instruction::GetElementPtr: {
2768 const auto *GO = cast<GEPOperator>(
C);
2770 if (std::optional<ConstantRange> Range = GO->getInRange()) {
2772 Record.push_back(GO->isInBounds());
2774 }
else if (GO->isInBounds())
2776 for (
unsigned i = 0, e =
CE->getNumOperands(); i != e; ++i) {
2782 case Instruction::ExtractElement:
2789 case Instruction::InsertElement:
2796 case Instruction::ShuffleVector:
2801 if (
C->getType() ==
C->getOperand(0)->getType()) {
2811 case Instruction::ICmp:
2812 case Instruction::FCmp:
2817 Record.push_back(
CE->getPredicate());
2820 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2825 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2829 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
2846void ModuleBitcodeWriter::writeModuleConstants() {
2851 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2852 if (!isa<GlobalValue>(Vals[i].first)) {
2853 writeConstants(i, Vals.size(),
true);
2867bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2872 if (
ValID >= InstID) {
2879void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
2886 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2888 for (
auto &Input : Bundle.Inputs)
2889 pushValueAndType(Input, InstID,
Record);
2898void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2904void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2907 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2912void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2916 unsigned AbbrevToUse = 0;
2918 switch (
I.getOpcode()) {
2922 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2923 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2928 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
2929 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
2933 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
2935 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2936 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2937 pushValue(
I.getOperand(1), InstID, Vals);
2941 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2942 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2947 case Instruction::FNeg: {
2949 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2950 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2954 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
2955 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
2960 case Instruction::GetElementPtr: {
2962 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2963 auto &GEPInst = cast<GetElementPtrInst>(
I);
2966 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i)
2967 pushValueAndType(
I.getOperand(i), InstID, Vals);
2970 case Instruction::ExtractValue: {
2972 pushValueAndType(
I.getOperand(0), InstID, Vals);
2977 case Instruction::InsertValue: {
2979 pushValueAndType(
I.getOperand(0), InstID, Vals);
2980 pushValueAndType(
I.getOperand(1), InstID, Vals);
2985 case Instruction::Select: {
2987 pushValueAndType(
I.getOperand(1), InstID, Vals);
2988 pushValue(
I.getOperand(2), InstID, Vals);
2989 pushValueAndType(
I.getOperand(0), InstID, Vals);
2995 case Instruction::ExtractElement:
2997 pushValueAndType(
I.getOperand(0), InstID, Vals);
2998 pushValueAndType(
I.getOperand(1), InstID, Vals);
3000 case Instruction::InsertElement:
3002 pushValueAndType(
I.getOperand(0), InstID, Vals);
3003 pushValue(
I.getOperand(1), InstID, Vals);
3004 pushValueAndType(
I.getOperand(2), InstID, Vals);
3006 case Instruction::ShuffleVector:
3008 pushValueAndType(
I.getOperand(0), InstID, Vals);
3009 pushValue(
I.getOperand(1), InstID, Vals);
3010 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3013 case Instruction::ICmp:
3014 case Instruction::FCmp: {
3017 pushValueAndType(
I.getOperand(0), InstID, Vals);
3018 pushValue(
I.getOperand(1), InstID, Vals);
3026 case Instruction::Ret:
3029 unsigned NumOperands =
I.getNumOperands();
3030 if (NumOperands == 0)
3031 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3032 else if (NumOperands == 1) {
3033 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3034 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3036 for (
unsigned i = 0, e = NumOperands; i !=
e; ++i)
3037 pushValueAndType(
I.getOperand(i), InstID, Vals);
3041 case Instruction::Br:
3052 case Instruction::Switch:
3057 pushValue(
SI.getCondition(), InstID, Vals);
3059 for (
auto Case :
SI.cases()) {
3065 case Instruction::IndirectBr:
3069 pushValue(
I.getOperand(0), InstID, Vals);
3070 for (
unsigned i = 1, e =
I.getNumOperands(); i != e; ++i)
3074 case Instruction::Invoke: {
3080 writeOperandBundles(*II, InstID);
3089 pushValueAndType(Callee, InstID, Vals);
3092 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3093 pushValue(
I.getOperand(i), InstID, Vals);
3096 if (FTy->isVarArg()) {
3097 for (
unsigned i = FTy->getNumParams(), e = II->
arg_size(); i != e; ++i)
3098 pushValueAndType(
I.getOperand(i), InstID, Vals);
3102 case Instruction::Resume:
3104 pushValueAndType(
I.getOperand(0), InstID, Vals);
3106 case Instruction::CleanupRet: {
3108 const auto &CRI = cast<CleanupReturnInst>(
I);
3109 pushValue(CRI.getCleanupPad(), InstID, Vals);
3110 if (CRI.hasUnwindDest())
3114 case Instruction::CatchRet: {
3116 const auto &CRI = cast<CatchReturnInst>(
I);
3117 pushValue(CRI.getCatchPad(), InstID, Vals);
3121 case Instruction::CleanupPad:
3122 case Instruction::CatchPad: {
3123 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3126 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3128 unsigned NumArgOperands = FuncletPad.arg_size();
3130 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3131 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3134 case Instruction::CatchSwitch: {
3136 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3138 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3140 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3142 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3145 if (CatchSwitch.hasUnwindDest())
3149 case Instruction::CallBr: {
3155 writeOperandBundles(*CBI, InstID);
3170 pushValueAndType(Callee, InstID, Vals);
3173 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3174 pushValue(
I.getOperand(i), InstID, Vals);
3177 if (FTy->isVarArg()) {
3178 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3179 pushValueAndType(
I.getOperand(i), InstID, Vals);
3183 case Instruction::Unreachable:
3185 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3188 case Instruction::PHI: {
3189 const PHINode &PN = cast<PHINode>(
I);
3206 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3211 case Instruction::LandingPad: {
3222 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3227 case Instruction::Alloca: {
3235 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3236 Bitfield::set<APV::AlignLower>(
3237 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3238 Bitfield::set<APV::AlignUpper>(
Record,
3239 EncodedAlign >> APV::AlignLower::Bits);
3241 Bitfield::set<APV::ExplicitType>(
Record,
true);
3246 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3251 case Instruction::Load:
3252 if (cast<LoadInst>(
I).isAtomic()) {
3254 pushValueAndType(
I.getOperand(0), InstID, Vals);
3257 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3258 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3262 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3263 if (cast<LoadInst>(
I).isAtomic()) {
3265 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3268 case Instruction::Store:
3269 if (cast<StoreInst>(
I).isAtomic())
3273 pushValueAndType(
I.getOperand(1), InstID, Vals);
3274 pushValueAndType(
I.getOperand(0), InstID, Vals);
3276 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3277 if (cast<StoreInst>(
I).isAtomic()) {
3280 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3283 case Instruction::AtomicCmpXchg:
3285 pushValueAndType(
I.getOperand(0), InstID, Vals);
3286 pushValueAndType(
I.getOperand(1), InstID, Vals);
3287 pushValue(
I.getOperand(2), InstID, Vals);
3288 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3292 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3295 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3298 case Instruction::AtomicRMW:
3300 pushValueAndType(
I.getOperand(0), InstID, Vals);
3301 pushValueAndType(
I.getOperand(1), InstID, Vals);
3304 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3307 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3310 case Instruction::Fence:
3313 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3315 case Instruction::Call: {
3320 writeOperandBundles(CI, InstID);
3340 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3342 if (FTy->getParamType(i)->isLabelTy())
3349 if (FTy->isVarArg()) {
3350 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3355 case Instruction::VAArg:
3358 pushValue(
I.getOperand(0), InstID, Vals);
3361 case Instruction::Freeze:
3363 pushValueAndType(
I.getOperand(0), InstID, Vals);
3373void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3379 VSTOffset -= bitcodeStartBit();
3380 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3384 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3388 auto Abbv = std::make_shared<BitCodeAbbrev>();
3392 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3397 if (
F.isDeclaration())
3404 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3405 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3409 Record[1] = BitcodeIndex / 32 + 1;
3418void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3433 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3439 if (isa<BasicBlock>(
Name.getValue())) {
3442 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3446 AbbrevToUse = VST_ENTRY_6_ABBREV;
3448 AbbrevToUse = VST_ENTRY_7_ABBREV;
3451 for (
const auto P :
Name.getKey())
3455 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3462void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3463 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3465 if (isa<BasicBlock>(Order.V))
3475void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3477 "Expected to be preserving use-list order");
3479 auto hasMore = [&]() {
3495void ModuleBitcodeWriter::writeFunction(
3514 unsigned CstStart, CstEnd;
3516 writeConstants(CstStart, CstEnd,
false);
3519 writeFunctionMetadata(
F);
3522 unsigned InstID = CstEnd;
3524 bool NeedsMetadataAttachment =
F.hasMetadata();
3532 writeInstruction(
I, InstID, Vals);
3534 if (!
I.getType()->isVoidTy())
3538 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3565 auto PushValueOrMetadata = [&Vals, InstID,
3568 "RawLocation unexpectedly null in DbgVariableRecord");
3574 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3588 for (
DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3614 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3636 while (!Worklist.empty()) {
3637 Value *
V = Worklist.pop_back_val();
3638 for (
User *U :
V->users()) {
3639 if (
auto *
I = dyn_cast<Instruction>(U)) {
3643 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3644 Visited.insert(U).second)
3645 Worklist.push_back(U);
3651 if (!BlockAddressUsers.
empty()) {
3660 if (
auto *Symtab =
F.getValueSymbolTable())
3661 writeFunctionLevelValueSymbolTable(*Symtab);
3663 if (NeedsMetadataAttachment)
3664 writeFunctionMetadataAttachment(
F);
3666 writeUseListBlock(&
F);
3672void ModuleBitcodeWriter::writeBlockInfo() {
3679 auto Abbv = std::make_shared<BitCodeAbbrev>();
3690 auto Abbv = std::make_shared<BitCodeAbbrev>();
3700 auto Abbv = std::make_shared<BitCodeAbbrev>();
3710 auto Abbv = std::make_shared<BitCodeAbbrev>();
3716 VST_BBENTRY_6_ABBREV)
3721 auto Abbv = std::make_shared<BitCodeAbbrev>();
3726 CONSTANTS_SETTYPE_ABBREV)
3731 auto Abbv = std::make_shared<BitCodeAbbrev>();
3735 CONSTANTS_INTEGER_ABBREV)
3740 auto Abbv = std::make_shared<BitCodeAbbrev>();
3748 CONSTANTS_CE_CAST_Abbrev)
3752 auto Abbv = std::make_shared<BitCodeAbbrev>();
3755 CONSTANTS_NULL_Abbrev)
3762 auto Abbv = std::make_shared<BitCodeAbbrev>();
3770 FUNCTION_INST_LOAD_ABBREV)
3774 auto Abbv = std::make_shared<BitCodeAbbrev>();
3779 FUNCTION_INST_UNOP_ABBREV)
3783 auto Abbv = std::make_shared<BitCodeAbbrev>();
3789 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3793 auto Abbv = std::make_shared<BitCodeAbbrev>();
3799 FUNCTION_INST_BINOP_ABBREV)
3803 auto Abbv = std::make_shared<BitCodeAbbrev>();
3810 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3814 auto Abbv = std::make_shared<BitCodeAbbrev>();
3821 FUNCTION_INST_CAST_ABBREV)
3825 auto Abbv = std::make_shared<BitCodeAbbrev>();
3833 FUNCTION_INST_CAST_FLAGS_ABBREV)
3838 auto Abbv = std::make_shared<BitCodeAbbrev>();
3841 FUNCTION_INST_RET_VOID_ABBREV)
3845 auto Abbv = std::make_shared<BitCodeAbbrev>();
3849 FUNCTION_INST_RET_VAL_ABBREV)
3853 auto Abbv = std::make_shared<BitCodeAbbrev>();
3856 FUNCTION_INST_UNREACHABLE_ABBREV)
3860 auto Abbv = std::make_shared<BitCodeAbbrev>();
3868 FUNCTION_INST_GEP_ABBREV)
3872 auto Abbv = std::make_shared<BitCodeAbbrev>();
3879 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3887void IndexBitcodeWriter::writeModStrings() {
3893 auto Abbv = std::make_shared<BitCodeAbbrev>();
3898 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3901 Abbv = std::make_shared<BitCodeAbbrev>();
3906 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3909 Abbv = std::make_shared<BitCodeAbbrev>();
3914 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3917 Abbv = std::make_shared<BitCodeAbbrev>();
3924 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3929 const auto &Hash = MPSE.
getValue();
3931 unsigned AbbrevToUse = Abbrev8Bit;
3933 AbbrevToUse = Abbrev6Bit;
3935 AbbrevToUse = Abbrev7Bit;
3937 auto ModuleId = ModuleIdMap.
size();
3938 ModuleIdMap[
Key] = ModuleId;
3947 Vals.
assign(Hash.begin(), Hash.end());
3959template <
typename Fn>
3963 if (!FS->type_tests().empty())
3968 auto WriteVFuncIdVec = [&](
uint64_t Ty,
3973 for (
auto &VF : VFs) {
3974 Record.push_back(VF.GUID);
3975 Record.push_back(VF.Offset);
3981 FS->type_test_assume_vcalls());
3983 FS->type_checked_load_vcalls());
3985 auto WriteConstVCallVec = [&](
uint64_t Ty,
3987 for (
auto &VC : VCs) {
3989 Record.push_back(VC.VFunc.GUID);
3990 Record.push_back(VC.VFunc.Offset);
3997 FS->type_test_assume_const_vcalls());
3999 FS->type_checked_load_const_vcalls());
4003 assert(Range.getLower().getNumWords() == 1);
4004 assert(Range.getUpper().getNumWords() == 1);
4009 if (!FS->paramAccesses().empty()) {
4011 for (
auto &Arg : FS->paramAccesses()) {
4012 size_t UndoSize =
Record.size();
4013 Record.push_back(Arg.ParamNo);
4014 WriteRange(Arg.Use);
4015 Record.push_back(Arg.Calls.size());
4016 for (
auto &Call : Arg.Calls) {
4017 Record.push_back(Call.ParamNo);
4018 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4025 Record.push_back(*ValueID);
4026 WriteRange(Call.Offsets);
4037 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4038 if (!FS->type_tests().empty())
4039 for (
auto &TT : FS->type_tests())
4040 ReferencedTypeIds.insert(TT);
4042 auto GetReferencedTypesFromVFuncIdVec =
4044 for (
auto &VF : VFs)
4045 ReferencedTypeIds.insert(VF.GUID);
4048 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4049 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4051 auto GetReferencedTypesFromConstVCallVec =
4053 for (
auto &VC : VCs)
4054 ReferencedTypeIds.insert(VC.VFunc.GUID);
4057 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4058 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4089 const std::string &Id,
4094 NameVals.
push_back(Summary.TTRes.TheKind);
4095 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4096 NameVals.
push_back(Summary.TTRes.AlignLog2);
4097 NameVals.
push_back(Summary.TTRes.SizeM1);
4098 NameVals.
push_back(Summary.TTRes.BitMask);
4099 NameVals.
push_back(Summary.TTRes.InlineBits);
4101 for (
auto &W : Summary.WPDRes)
4113 for (
auto &
P : Summary) {
4121 unsigned AllocAbbrev,
bool PerModule,
4122 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4123 std::function<
unsigned(
unsigned)> GetStackIndex) {
4126 for (
auto &CI : FS->callsites()) {
4130 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4131 Record.push_back(GetValueID(CI.Callee));
4133 Record.push_back(CI.StackIdIndices.size());
4134 Record.push_back(CI.Clones.size());
4136 for (
auto Id : CI.StackIdIndices)
4137 Record.push_back(GetStackIndex(Id));
4139 for (
auto V : CI.Clones)
4147 for (
auto &AI : FS->allocs()) {
4151 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4153 Record.push_back(AI.MIBs.size());
4154 Record.push_back(AI.Versions.size());
4156 for (
auto &MIB : AI.MIBs) {
4157 Record.push_back((uint8_t)MIB.AllocType);
4158 Record.push_back(MIB.StackIdIndices.size());
4159 for (
auto Id : MIB.StackIdIndices)
4160 Record.push_back(GetStackIndex(Id));
4163 for (
auto V : AI.Versions)
4173void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4175 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4176 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4177 unsigned AllocAbbrev,
const Function &
F) {
4183 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4188 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4190 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4191 [&](
unsigned I) {
return I; });
4193 auto SpecialRefCnts =
FS->specialRefCounts();
4198 NameVals.
push_back(SpecialRefCnts.first);
4199 NameVals.
push_back(SpecialRefCnts.second);
4201 for (
auto &RI :
FS->refs())
4204 const bool UseRelBFRecord =
4207 for (
auto &ECI :
FS->calls()) {
4208 NameVals.
push_back(getValueId(ECI.first));
4216 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4227void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4229 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4230 auto VI =
Index->getValueInfo(
V.getGUID());
4231 if (!VI ||
VI.getSummaryList().empty()) {
4237 auto *
Summary =
VI.getSummaryList()[0].get();
4243 auto VTableFuncs =
VS->vTableFuncs();
4244 if (!VTableFuncs.empty())
4247 unsigned SizeBeforeRefs = NameVals.
size();
4248 for (
auto &RI :
VS->refs())
4254 if (VTableFuncs.empty())
4259 for (
auto &
P : VTableFuncs) {
4265 FSModVTableRefsAbbrev);
4272void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4275 bool IsThinLTO =
true;
4277 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4278 IsThinLTO = MD->getZExtValue();
4290 if (
Index->enableSplitLTOUnit())
4292 if (
Index->hasUnifiedLTO())
4302 for (
const auto &GVI : valueIds()) {
4307 if (!
Index->stackIds().empty()) {
4308 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4313 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4318 auto Abbv = std::make_shared<BitCodeAbbrev>();
4330 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4333 Abbv = std::make_shared<BitCodeAbbrev>();
4345 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4348 Abbv = std::make_shared<BitCodeAbbrev>();
4354 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4357 Abbv = std::make_shared<BitCodeAbbrev>();
4365 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4368 Abbv = std::make_shared<BitCodeAbbrev>();
4373 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4376 Abbv = std::make_shared<BitCodeAbbrev>();
4383 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4385 Abbv = std::make_shared<BitCodeAbbrev>();
4391 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4393 Abbv = std::make_shared<BitCodeAbbrev>();
4398 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4410 if (!VI ||
VI.getSummaryList().empty()) {
4416 auto *
Summary =
VI.getSummaryList()[0].get();
4417 writePerModuleFunctionSummaryRecord(
4418 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4419 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev,
F);
4425 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4426 FSModVTableRefsAbbrev);
4429 auto *Aliasee =
A.getAliaseeObject();
4432 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4445 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4449 TypeIdCompatibleVtableAbbrev);
4453 if (
Index->getBlockCount())
4461void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4470 for (
const auto &GVI : valueIds()) {
4475 if (!StackIdIndices.empty()) {
4476 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4481 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4484 std::vector<uint64_t> StackIds;
4485 for (
auto &
I : StackIdIndices)
4486 StackIds.push_back(
Index.getStackIdAtIndex(
I));
4491 auto Abbv = std::make_shared<BitCodeAbbrev>();
4505 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4508 Abbv = std::make_shared<BitCodeAbbrev>();
4515 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4518 Abbv = std::make_shared<BitCodeAbbrev>();
4524 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4526 Abbv = std::make_shared<BitCodeAbbrev>();
4534 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4536 Abbv = std::make_shared<BitCodeAbbrev>();
4544 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4557 std::set<GlobalValue::GUID> ReferencedTypeIds;
4571 NameVals.
push_back(S.getOriginalName());
4576 std::set<GlobalValue::GUID> DefOrUseGUIDs;
4577 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4580 DefOrUseGUIDs.insert(
I.first);
4582 DefOrUseGUIDs.insert(
VI.getGUID());
4584 auto ValueId = getValueId(
I.first);
4586 SummaryToValueIdMap[S] = *ValueId;
4594 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4601 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4604 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4607 for (
auto &RI :
VS->refs()) {
4608 auto RefValueId = getValueId(RI.getGUID());
4618 MaybeEmitOriginalName(*S);
4622 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
4624 return std::nullopt;
4625 return getValueId(
VI.getGUID());
4628 auto *
FS = cast<FunctionSummary>(S);
4633 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4636 std::optional<unsigned> ValueID = GetValueId(VI);
4650 return std::distance(StackIdIndices.begin(),
Lower);
4655 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4666 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4667 for (
auto &RI :
FS->refs()) {
4668 auto RefValueId = getValueId(RI.getGUID());
4672 if (RI.isReadOnly())
4674 else if (RI.isWriteOnly())
4678 NameVals[6] = Count;
4679 NameVals[7] = RORefCnt;
4680 NameVals[8] = WORefCnt;
4682 for (
auto &EI :
FS->calls()) {
4685 std::optional<unsigned> CallValueId = GetValueId(EI.first);
4694 FSCallsProfileAbbrev);
4696 MaybeEmitOriginalName(*S);
4699 for (
auto *AS : Aliases) {
4700 auto AliasValueId = SummaryToValueIdMap[AS];
4706 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
4713 MaybeEmitOriginalName(*AS);
4715 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
4719 if (!
Index.cfiFunctionDefs().empty()) {
4720 for (
auto &S :
Index.cfiFunctionDefs()) {
4721 if (DefOrUseGUIDs.count(
4727 if (!NameVals.
empty()) {
4733 if (!
Index.cfiFunctionDecls().empty()) {
4734 for (
auto &S :
Index.cfiFunctionDecls()) {
4735 if (DefOrUseGUIDs.count(
4741 if (!NameVals.
empty()) {
4749 for (
auto &
T : ReferencedTypeIds) {
4750 auto TidIter =
Index.typeIds().equal_range(
T);
4751 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4759 if (
Index.getBlockCount())
4772 auto Abbv = std::make_shared<BitCodeAbbrev>();
4776 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4778 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4781 Abbv = std::make_shared<BitCodeAbbrev>();
4784 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4790void ModuleBitcodeWriter::writeModuleHash(
size_t BlockStartPos) {
4796 Buffer.size() - BlockStartPos));
4797 std::array<uint8_t, 20> Hash = Hasher.result();
4798 for (
int Pos = 0; Pos < 20; Pos += 4) {
4811void ModuleBitcodeWriter::write() {
4815 size_t BlockStartPos = Buffer.size();
4817 writeModuleVersion();
4826 writeAttributeGroupTable();
4829 writeAttributeTable();
4838 writeModuleConstants();
4841 writeModuleMetadataKinds();
4844 writeModuleMetadata();
4848 writeUseListBlock(
nullptr);
4850 writeOperandBundleTags();
4851 writeSyncScopeNames();
4856 if (!
F.isDeclaration())
4857 writeFunction(
F, FunctionToBitcodeIndex);
4862 writePerModuleGlobalValueSummary();
4864 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4866 writeModuleHash(BlockStartPos);
4892 unsigned CPUType = ~0U;
4899 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4900 DARWIN_CPU_TYPE_X86 = 7,
4901 DARWIN_CPU_TYPE_ARM = 12,
4902 DARWIN_CPU_TYPE_POWERPC = 18
4907 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4909 CPUType = DARWIN_CPU_TYPE_X86;
4911 CPUType = DARWIN_CPU_TYPE_POWERPC;
4913 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4915 CPUType = DARWIN_CPU_TYPE_ARM;
4919 "Expected header size to be reserved");
4924 unsigned Position = 0;
4932 while (Buffer.
size() & 15)
4939 Stream.
Emit((
unsigned)
'B', 8);
4940 Stream.
Emit((
unsigned)
'C', 8);
4941 Stream.
Emit(0x0, 4);
4942 Stream.
Emit(0xC, 4);
4943 Stream.
Emit(0xE, 4);
4944 Stream.
Emit(0xD, 4);
4957 auto Abbv = std::make_shared<BitCodeAbbrev>();
4960 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
4968 assert(!WroteStrtab && !WroteSymtab);
4974 if (M->getModuleInlineAsm().empty())
4978 const Triple TT(M->getTargetTriple());
4980 if (!
T || !
T->hasMCAsmParser())
5002 std::vector<char> Strtab;
5004 Strtab.resize(StrtabBuilder.
getSize());
5005 StrtabBuilder.
write((uint8_t *)Strtab.data());
5008 {Strtab.data(), Strtab.size()});
5019 bool ShouldPreserveUseListOrder,
5028 assert(M.isMaterialized());
5029 Mods.push_back(
const_cast<Module *
>(&M));
5031 ModuleBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream,
5032 ShouldPreserveUseListOrder,
Index,
5033 GenerateHash, ModHash);
5034 ModuleWriter.write();
5039 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5040 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *
Index,
5041 ModuleToSummariesForIndex);
5042 IndexWriter.write();
5047 bool ShouldPreserveUseListOrder,
5055 Triple TT(M.getTargetTriple());
5056 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
5059 BitcodeWriter Writer(Buffer, dyn_cast<raw_fd_stream>(&Out));
5065 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
5069 if (!Buffer.
empty())
5073void IndexBitcodeWriter::write() {
5076 writeModuleVersion();
5082 writeCombinedGlobalValueSummary();
5093 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5107class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5117 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5119 ModHash(&ModHash) {}
5124 void writeSimplifiedModuleInfo();
5134void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5146 auto Abbv = std::make_shared<BitCodeAbbrev>();
5149 Abbv->Add(AbbrevOpToUse);
5150 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5152 for (
const auto P :
M.getSourceFileName())
5216void ThinLinkBitcodeWriter::write() {
5219 writeModuleVersion();
5221 writeSimplifiedModuleInfo();
5223 writePerModuleGlobalValueSummary();
5240 assert(M.isMaterialized());
5241 Mods.push_back(
const_cast<Module *
>(&M));
5243 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream,
Index,
5245 ThinLinkWriter.write();
5266 switch (
T.getObjectFormat()) {
5268 return "__LLVM,__bitcode";
5291 switch (
T.getObjectFormat()) {
5293 return "__LLVM,__cmdline";
5317 const std::vector<uint8_t> &CmdArgs) {
5323 for (
auto *GV : UsedGlobals) {
5324 if (GV->getName() !=
"llvm.embedded.module" &&
5325 GV->getName() !=
"llvm.cmdline")
5330 Used->eraseFromParent();
5335 Triple T(M.getTargetTriple());
5364 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5365 assert(Old->hasZeroLiveUses() &&
5366 "llvm.embedded.module can only be used once in llvm.compiler.used");
5368 Old->eraseFromParent();
5370 GV->
setName(
"llvm.embedded.module");
5388 assert(Old->hasZeroLiveUses() &&
5389 "llvm.cmdline can only be used once in llvm.compiler.used");
5391 Old->eraseFromParent();
5397 if (UsedArray.
empty())
5405 NewUsed->setSection(
"llvm.metadata");
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
llvm::cl::opt< bool > UseNewDbgInfoFormat
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR)
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex)
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdSummary &Summary)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Min
*p = old <signed v ? old : v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
BitcodeWriter(SmallVectorImpl< char > &Buffer, raw_fd_stream *FS=nullptr)
Create a BitcodeWriter that writes to Buffer.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
void writeIndex(const ModuleSummaryIndex *Index, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex)
void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
bool isConditional() const
BasicBlock * getSuccessor(unsigned i) const
Value * getCondition() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the parameter attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
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.
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Generic tagged DWARF-like metadata node.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
Global variable summary information to aid decisions and implementation of importing.
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
BasicBlock * getUnwindDest() const
BasicBlock * getNormalDest() const
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Tracking metadata reference owned by Metadata.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A class that wrap the SHA1 algorithm.
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
uint64_t computeBitsRequiredForTypeIndicies() const
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
void takeName(Value *V)
Transfer the name from V to this value.
A raw_ostream of a file for reading/writing/seeking.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_GLOBAL_VAR_EXPR
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_CE_INBOUNDS_GEP
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ FIRST_APPLICATION_ABBREV
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
NodeAddr< CodeNode * > Code
void write32le(void *P, uint32_t V)
uint32_t read32be(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
AtomicOrdering
Atomic ordering for LLVM's memory model.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
DWARFExpression::Operation Op
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void consumeError(Error Err)
Consume a Error without doing anything.
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Structure to hold a use-list order.
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName