31#include "llvm/Config/llvm-config.h"
89 cl::desc(
"Number of metadatas above which we emit an index "
90 "to enable lazy-loading"));
93 cl::desc(
"The threshold (unit M) for flushing LLVM bitcode."));
97 cl::desc(
"Write relative block frequency to function summary "));
115 VST_BBENTRY_6_ABBREV,
119 CONSTANTS_INTEGER_ABBREV,
120 CONSTANTS_CE_CAST_Abbrev,
121 CONSTANTS_NULL_Abbrev,
125 FUNCTION_INST_UNOP_ABBREV,
126 FUNCTION_INST_UNOP_FLAGS_ABBREV,
127 FUNCTION_INST_BINOP_ABBREV,
128 FUNCTION_INST_BINOP_FLAGS_ABBREV,
129 FUNCTION_INST_CAST_ABBREV,
130 FUNCTION_INST_CAST_FLAGS_ABBREV,
131 FUNCTION_INST_RET_VOID_ABBREV,
132 FUNCTION_INST_RET_VAL_ABBREV,
133 FUNCTION_INST_UNREACHABLE_ABBREV,
134 FUNCTION_INST_GEP_ABBREV,
135 FUNCTION_DEBUG_RECORD_VALUE_ABBREV,
140class BitcodeWriterBase {
151 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
154 void writeModuleVersion();
157void BitcodeWriterBase::writeModuleVersion() {
164class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
178 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
181 unsigned GlobalValueId;
192 bool ShouldPreserveUseListOrder,
194 : BitcodeWriterBase(Stream, StrtabBuilder),
M(
M),
204 for (
const auto &GUIDSummaryLists : *
Index)
206 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
207 if (
auto FS = dyn_cast<FunctionSummary>(
Summary.get())) {
212 for (
auto &CallEdge :
FS->calls())
213 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
214 assignValueId(CallEdge.first.getGUID());
220 for (
auto &RefEdge :
FS->refs())
221 if (!RefEdge.haveGVs() || !RefEdge.getValue())
222 assignValueId(RefEdge.getGUID());
227 void writePerModuleGlobalValueSummary();
230 void writePerModuleFunctionSummaryRecord(
232 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
233 unsigned CallsiteAbbrev,
unsigned AllocAbbrev,
const Function &
F);
236 unsigned FSModRefsAbbrev,
237 unsigned FSModVTableRefsAbbrev);
240 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
244 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
247 assert(VMI != GUIDToValueIdMap.end() &&
248 "GUID does not have assigned value Id");
254 if (!
VI.haveGVs() || !
VI.getValue())
255 return getValueId(
VI.getGUID());
259 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
263class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
283 : ModuleBitcodeWriterBase(
M, StrtabBuilder, Stream,
284 ShouldPreserveUseListOrder,
Index),
285 GenerateHash(GenerateHash), ModHash(ModHash),
286 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
292 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
296 void writeAttributeGroupTable();
297 void writeAttributeTable();
298 void writeTypeTable();
300 void writeValueSymbolTableForwardDecl();
301 void writeModuleInfo();
306 unsigned createDILocationAbbrev();
309 unsigned createGenericDINodeAbbrev();
377 unsigned createNamedMetadataAbbrev();
379 unsigned createMetadataStringsAbbrev();
384 std::vector<unsigned> *MDAbbrevs =
nullptr,
385 std::vector<uint64_t> *IndexPos =
nullptr);
386 void writeModuleMetadata();
387 void writeFunctionMetadata(
const Function &
F);
388 void writeFunctionMetadataAttachment(
const Function &
F);
391 void writeModuleMetadataKinds();
392 void writeOperandBundleTags();
393 void writeSyncScopeNames();
394 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
395 void writeModuleConstants();
396 bool pushValueAndType(
const Value *V,
unsigned InstID,
398 void writeOperandBundles(
const CallBase &CB,
unsigned InstID);
399 void pushValue(
const Value *V,
unsigned InstID,
401 void pushValueSigned(
const Value *V,
unsigned InstID,
403 void writeInstruction(
const Instruction &
I,
unsigned InstID,
406 void writeGlobalValueSymbolTable(
409 void writeUseListBlock(
const Function *
F);
413 void writeBlockInfo();
420 unsigned getEncodedAlign(
MaybeAlign Alignment) {
return encode(Alignment); }
424class IndexBitcodeWriter :
public BitcodeWriterBase {
435 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
439 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
443 std::vector<uint64_t> StackIds;
451 unsigned GlobalValueId = 0;
467 const std::map<std::string, GVSummaryMapTy>
468 *ModuleToSummariesForIndex =
nullptr)
469 : BitcodeWriterBase(Stream, StrtabBuilder),
Index(
Index),
470 DecSummaries(DecSummaries),
471 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
475 auto RecordStackIdReference = [&](
unsigned StackIdIndex) {
480 StackIdIndicesToIndex.
insert({StackIdIndex, StackIds.size()});
482 StackIds.push_back(
Index.getStackIdAtIndex(StackIdIndex));
489 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
490 GUIDToValueIdMap[
I.first] = ++GlobalValueId;
493 auto *
FS = dyn_cast<FunctionSummary>(
I.second);
499 for (
auto &CI :
FS->callsites()) {
510 if (CI.StackIdIndices.empty()) {
511 GUIDToValueIdMap[CI.Callee.getGUID()] = ++GlobalValueId;
514 for (
auto Idx : CI.StackIdIndices)
515 RecordStackIdReference(
Idx);
517 for (
auto &AI :
FS->allocs())
518 for (
auto &MIB : AI.MIBs)
519 for (
auto Idx : MIB.StackIdIndices)
520 RecordStackIdReference(
Idx);
525 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
530 template<
typename Functor>
531 void forEachSummary(Functor Callback) {
532 if (ModuleToSummariesForIndex) {
533 for (
auto &M : *ModuleToSummariesForIndex)
534 for (
auto &Summary :
M.second) {
535 Callback(Summary,
false);
539 if (
auto *AS = dyn_cast<AliasSummary>(
Summary.getSecond()))
540 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
543 for (
auto &Summaries :
Index)
544 for (
auto &Summary : Summaries.second.SummaryList)
545 Callback({Summaries.first,
Summary.get()},
false);
553 template <
typename Functor>
void forEachModule(Functor Callback) {
554 if (ModuleToSummariesForIndex) {
555 for (
const auto &M : *ModuleToSummariesForIndex) {
556 const auto &MPI =
Index.modulePaths().find(
M.first);
557 if (MPI ==
Index.modulePaths().end()) {
561 assert(ModuleToSummariesForIndex->size() == 1);
571 std::vector<StringRef> ModulePaths;
572 for (
auto &[ModPath,
_] :
Index.modulePaths())
573 ModulePaths.push_back(ModPath);
574 llvm::sort(ModulePaths.begin(), ModulePaths.end());
575 for (
auto &ModPath : ModulePaths)
576 Callback(*
Index.modulePaths().find(ModPath));
584 void writeModStrings();
585 void writeCombinedGlobalValueSummary();
588 auto VMI = GUIDToValueIdMap.find(ValGUID);
589 if (VMI == GUIDToValueIdMap.end())
594 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
628 case Instruction::Add:
630 case Instruction::Sub:
632 case Instruction::Mul:
635 case Instruction::FDiv:
638 case Instruction::FRem:
704 case Attribute::Alignment:
706 case Attribute::AllocAlign:
708 case Attribute::AllocSize:
710 case Attribute::AlwaysInline:
712 case Attribute::Builtin:
714 case Attribute::ByVal:
716 case Attribute::Convergent:
718 case Attribute::InAlloca:
720 case Attribute::Cold:
722 case Attribute::DisableSanitizerInstrumentation:
724 case Attribute::FnRetThunkExtern:
728 case Attribute::ElementType:
730 case Attribute::HybridPatchable:
732 case Attribute::InlineHint:
734 case Attribute::InReg:
736 case Attribute::JumpTable:
738 case Attribute::MinSize:
740 case Attribute::AllocatedPointer:
742 case Attribute::AllocKind:
744 case Attribute::Memory:
746 case Attribute::NoFPClass:
748 case Attribute::Naked:
750 case Attribute::Nest:
752 case Attribute::NoAlias:
754 case Attribute::NoBuiltin:
756 case Attribute::NoCallback:
758 case Attribute::NoCapture:
760 case Attribute::NoDuplicate:
762 case Attribute::NoFree:
764 case Attribute::NoImplicitFloat:
766 case Attribute::NoInline:
768 case Attribute::NoRecurse:
770 case Attribute::NoMerge:
772 case Attribute::NonLazyBind:
774 case Attribute::NonNull:
776 case Attribute::Dereferenceable:
778 case Attribute::DereferenceableOrNull:
780 case Attribute::NoRedZone:
782 case Attribute::NoReturn:
784 case Attribute::NoSync:
786 case Attribute::NoCfCheck:
788 case Attribute::NoProfile:
790 case Attribute::SkipProfile:
792 case Attribute::NoUnwind:
794 case Attribute::NoSanitizeBounds:
796 case Attribute::NoSanitizeCoverage:
798 case Attribute::NullPointerIsValid:
800 case Attribute::OptimizeForDebugging:
802 case Attribute::OptForFuzzing:
804 case Attribute::OptimizeForSize:
806 case Attribute::OptimizeNone:
808 case Attribute::ReadNone:
810 case Attribute::ReadOnly:
812 case Attribute::Returned:
814 case Attribute::ReturnsTwice:
816 case Attribute::SExt:
818 case Attribute::Speculatable:
820 case Attribute::StackAlignment:
822 case Attribute::StackProtect:
824 case Attribute::StackProtectReq:
826 case Attribute::StackProtectStrong:
828 case Attribute::SafeStack:
830 case Attribute::ShadowCallStack:
832 case Attribute::StrictFP:
834 case Attribute::StructRet:
836 case Attribute::SanitizeAddress:
838 case Attribute::SanitizeHWAddress:
840 case Attribute::SanitizeThread:
842 case Attribute::SanitizeMemory:
844 case Attribute::SanitizeNumericalStability:
846 case Attribute::SanitizeRealtime:
848 case Attribute::SpeculativeLoadHardening:
850 case Attribute::SwiftError:
852 case Attribute::SwiftSelf:
854 case Attribute::SwiftAsync:
856 case Attribute::UWTable:
858 case Attribute::VScaleRange:
860 case Attribute::WillReturn:
862 case Attribute::WriteOnly:
864 case Attribute::ZExt:
866 case Attribute::ImmArg:
868 case Attribute::SanitizeMemTag:
870 case Attribute::Preallocated:
872 case Attribute::NoUndef:
874 case Attribute::ByRef:
876 case Attribute::MustProgress:
878 case Attribute::PresplitCoroutine:
880 case Attribute::Writable:
882 case Attribute::CoroDestroyOnlyWhenComplete:
884 case Attribute::DeadOnUnwind:
886 case Attribute::Range:
888 case Attribute::Initializes:
914 unsigned NumWords =
A.getActiveWords();
915 const uint64_t *RawData =
A.getRawData();
916 for (
unsigned i = 0; i < NumWords; i++)
936void ModuleBitcodeWriter::writeAttributeGroupTable() {
937 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
939 if (AttrGrps.empty())
return;
945 unsigned AttrListIndex = Pair.first;
948 Record.push_back(AttrListIndex);
951 if (Attr.isEnumAttribute()) {
954 }
else if (Attr.isIntAttribute()) {
957 Record.push_back(Attr.getValueAsInt());
958 }
else if (Attr.isStringAttribute()) {
969 }
else if (Attr.isTypeAttribute()) {
970 Type *Ty = Attr.getValueAsType();
971 Record.push_back(Ty ? 6 : 5);
975 }
else if (Attr.isConstantRangeAttribute()) {
981 assert(Attr.isConstantRangeListAttribute());
999void ModuleBitcodeWriter::writeAttributeTable() {
1001 if (
Attrs.empty())
return;
1007 for (
unsigned i :
AL.indexes()) {
1021void ModuleBitcodeWriter::writeTypeTable() {
1030 auto Abbv = std::make_shared<BitCodeAbbrev>();
1033 unsigned OpaquePtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1036 Abbv = std::make_shared<BitCodeAbbrev>();
1041 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1044 Abbv = std::make_shared<BitCodeAbbrev>();
1049 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1052 Abbv = std::make_shared<BitCodeAbbrev>();
1056 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1059 Abbv = std::make_shared<BitCodeAbbrev>();
1064 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1067 Abbv = std::make_shared<BitCodeAbbrev>();
1071 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1079 for (
Type *
T : TypeList) {
1080 int AbbrevToUse = 0;
1083 switch (
T->getTypeID()) {
1110 AbbrevToUse = OpaquePtrAbbrev;
1119 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
1121 AbbrevToUse = FunctionAbbrev;
1129 for (
Type *ET :
ST->elements())
1132 if (
ST->isLiteral()) {
1134 AbbrevToUse = StructAnonAbbrev;
1136 if (
ST->isOpaque()) {
1140 AbbrevToUse = StructNamedAbbrev;
1144 if (!
ST->getName().empty())
1154 TypeVals.
push_back(AT->getNumElements());
1156 AbbrevToUse = ArrayAbbrev;
1165 TypeVals.
push_back(VT->getElementCount().getKnownMinValue());
1167 if (isa<ScalableVectorType>(VT))
1177 for (
Type *InnerTy :
TET->type_params())
1179 for (
unsigned IntParam :
TET->int_params())
1188 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1229 RawFlags |= Flags.ReadNone;
1230 RawFlags |= (Flags.ReadOnly << 1);
1231 RawFlags |= (Flags.NoRecurse << 2);
1232 RawFlags |= (Flags.ReturnDoesNotAlias << 3);
1233 RawFlags |= (Flags.NoInline << 4);
1234 RawFlags |= (Flags.AlwaysInline << 5);
1235 RawFlags |= (Flags.NoUnwind << 6);
1236 RawFlags |= (Flags.MayThrow << 7);
1237 RawFlags |= (Flags.HasUnknownCall << 8);
1238 RawFlags |= (Flags.MustBeUnreachable << 9);
1245 bool ImportAsDecl =
false) {
1248 RawFlags |= Flags.NotEligibleToImport;
1249 RawFlags |= (Flags.Live << 1);
1250 RawFlags |= (Flags.DSOLocal << 2);
1251 RawFlags |= (Flags.CanAutoHide << 3);
1256 RawFlags = (RawFlags << 4) | Flags.Linkage;
1258 RawFlags |= (Flags.Visibility << 8);
1260 unsigned ImportType = Flags.ImportType | ImportAsDecl;
1261 RawFlags |= (ImportType << 10);
1267 uint64_t RawFlags = Flags.MaybeReadOnly | (Flags.MaybeWriteOnly << 1) |
1268 (Flags.Constant << 2) | Flags.VCallVisibility << 3;
1310 case GlobalVariable::NotThreadLocal:
return 0;
1311 case GlobalVariable::GeneralDynamicTLSModel:
return 1;
1312 case GlobalVariable::LocalDynamicTLSModel:
return 2;
1313 case GlobalVariable::InitialExecTLSModel:
return 3;
1314 case GlobalVariable::LocalExecTLSModel:
return 4;
1320 switch (
C.getSelectionKind()) {
1337 case GlobalValue::UnnamedAddr::None:
return 0;
1338 case GlobalValue::UnnamedAddr::Local:
return 2;
1339 case GlobalValue::UnnamedAddr::Global:
return 1;
1344size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1347 return StrtabBuilder.
add(Str);
1350void ModuleBitcodeWriter::writeComdats() {
1365void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1370 auto Abbv = std::make_shared<BitCodeAbbrev>();
1376 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1392 bool isChar6 =
true;
1393 for (
char C : Str) {
1396 if ((
unsigned char)
C & 128)
1406 "Sanitizer Metadata is too large for naive serialization.");
1409 return Meta.NoAddress | (Meta.NoHWAddress << 1) |
1410 (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
1416void ModuleBitcodeWriter::writeModuleInfo() {
1418 if (!
M.getTargetTriple().empty())
1421 const std::string &
DL =
M.getDataLayoutStr();
1424 if (!
M.getModuleInlineAsm().empty())
1430 std::map<std::string, unsigned> SectionMap;
1431 std::map<std::string, unsigned> GCMap;
1433 unsigned MaxGlobalType = 0;
1434 const auto UpdateMaxAlignment = [&MaxAlignment](
const MaybeAlign A) {
1436 MaxAlignment = !MaxAlignment ? *
A : std::max(*MaxAlignment, *
A);
1439 UpdateMaxAlignment(GV.getAlign());
1440 MaxGlobalType = std::max(MaxGlobalType, VE.
getTypeID(GV.getValueType()));
1441 if (GV.hasSection()) {
1443 unsigned &
Entry = SectionMap[std::string(GV.getSection())];
1447 Entry = SectionMap.size();
1452 UpdateMaxAlignment(
F.getAlign());
1453 if (
F.hasSection()) {
1455 unsigned &
Entry = SectionMap[std::string(
F.getSection())];
1459 Entry = SectionMap.size();
1464 unsigned &
Entry = GCMap[
F.getGC()];
1468 Entry = GCMap.size();
1474 unsigned SimpleGVarAbbrev = 0;
1475 if (!
M.global_empty()) {
1477 auto Abbv = std::make_shared<BitCodeAbbrev>();
1491 unsigned MaxEncAlignment = getEncodedAlign(MaxAlignment);
1495 if (SectionMap.empty())
1501 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1515 auto Abbv = std::make_shared<BitCodeAbbrev>();
1518 Abbv->Add(AbbrevOpToUse);
1519 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1521 for (
const auto P :
M.getSourceFileName())
1531 unsigned AbbrevToUse = 0;
1537 Vals.
push_back(addToStrtab(GV.getName()));
1540 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1544 Vals.
push_back(getEncodedAlign(GV.getAlign()));
1545 Vals.
push_back(GV.hasSection() ? SectionMap[std::string(GV.getSection())]
1547 if (GV.isThreadLocal() ||
1549 GV.getUnnamedAddr() != GlobalValue::UnnamedAddr::None ||
1550 GV.isExternallyInitialized() ||
1552 GV.hasComdat() || GV.hasAttributes() || GV.isDSOLocal() ||
1553 GV.hasPartition() || GV.hasSanitizerMetadata() || GV.getCodeModel()) {
1557 Vals.
push_back(GV.isExternallyInitialized());
1565 Vals.
push_back(addToStrtab(GV.getPartition()));
1566 Vals.
push_back(GV.getPartition().size());
1569 GV.getSanitizerMetadata())
1573 AbbrevToUse = SimpleGVarAbbrev;
1593 Vals.
push_back(getEncodedAlign(
F.getAlign()));
1594 Vals.
push_back(
F.hasSection() ? SectionMap[std::string(
F.getSection())]
1606 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1610 Vals.
push_back(addToStrtab(
F.getPartition()));
1613 unsigned AbbrevToUse = 0;
1626 Vals.
push_back(
A.getType()->getAddressSpace());
1634 Vals.
push_back(addToStrtab(
A.getPartition()));
1637 unsigned AbbrevToUse = 0;
1649 Vals.
push_back(
I.getType()->getAddressSpace());
1654 Vals.
push_back(addToStrtab(
I.getPartition()));
1660 writeValueSymbolTableForwardDecl();
1666 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1667 if (OBO->hasNoSignedWrap())
1669 if (OBO->hasNoUnsignedWrap())
1671 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1674 }
else if (
const auto *PDI = dyn_cast<PossiblyDisjointInst>(V)) {
1675 if (PDI->isDisjoint())
1677 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1678 if (FPMO->hasAllowReassoc())
1680 if (FPMO->hasNoNaNs())
1682 if (FPMO->hasNoInfs())
1684 if (FPMO->hasNoSignedZeros())
1686 if (FPMO->hasAllowReciprocal())
1688 if (FPMO->hasAllowContract())
1690 if (FPMO->hasApproxFunc())
1692 }
else if (
const auto *NNI = dyn_cast<PossiblyNonNegInst>(V)) {
1693 if (NNI->hasNonNeg())
1695 }
else if (
const auto *TI = dyn_cast<TruncInst>(V)) {
1696 if (TI->hasNoSignedWrap())
1698 if (TI->hasNoUnsignedWrap())
1700 }
else if (
const auto *
GEP = dyn_cast<GEPOperator>(V)) {
1701 if (
GEP->isInBounds())
1703 if (
GEP->hasNoUnsignedSignedWrap())
1705 if (
GEP->hasNoUnsignedWrap())
1712void ModuleBitcodeWriter::writeValueAsMetadata(
1722void ModuleBitcodeWriter::writeMDTuple(
const MDTuple *
N,
1727 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1728 "Unexpected function-local metadata");
1737unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1740 auto Abbv = std::make_shared<BitCodeAbbrev>();
1751void ModuleBitcodeWriter::writeDILocation(
const DILocation *
N,
1755 Abbrev = createDILocationAbbrev();
1757 Record.push_back(
N->isDistinct());
1758 Record.push_back(
N->getLine());
1759 Record.push_back(
N->getColumn());
1762 Record.push_back(
N->isImplicitCode());
1768unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1771 auto Abbv = std::make_shared<BitCodeAbbrev>();
1782void ModuleBitcodeWriter::writeGenericDINode(
const GenericDINode *
N,
1786 Abbrev = createGenericDINodeAbbrev();
1788 Record.push_back(
N->isDistinct());
1789 Record.push_back(
N->getTag());
1792 for (
auto &
I :
N->operands())
1799void ModuleBitcodeWriter::writeDISubrange(
const DISubrange *
N,
1813void ModuleBitcodeWriter::writeDIGenericSubrange(
1826void ModuleBitcodeWriter::writeDIEnumerator(
const DIEnumerator *
N,
1830 Record.push_back(IsBigInt | (
N->isUnsigned() << 1) |
N->isDistinct());
1831 Record.push_back(
N->getValue().getBitWidth());
1839void ModuleBitcodeWriter::writeDIBasicType(
const DIBasicType *
N,
1842 Record.push_back(
N->isDistinct());
1843 Record.push_back(
N->getTag());
1845 Record.push_back(
N->getSizeInBits());
1846 Record.push_back(
N->getAlignInBits());
1847 Record.push_back(
N->getEncoding());
1848 Record.push_back(
N->getFlags());
1854void ModuleBitcodeWriter::writeDIStringType(
const DIStringType *
N,
1857 Record.push_back(
N->isDistinct());
1858 Record.push_back(
N->getTag());
1863 Record.push_back(
N->getSizeInBits());
1864 Record.push_back(
N->getAlignInBits());
1865 Record.push_back(
N->getEncoding());
1871void ModuleBitcodeWriter::writeDIDerivedType(
const DIDerivedType *
N,
1874 Record.push_back(
N->isDistinct());
1875 Record.push_back(
N->getTag());
1878 Record.push_back(
N->getLine());
1881 Record.push_back(
N->getSizeInBits());
1882 Record.push_back(
N->getAlignInBits());
1883 Record.push_back(
N->getOffsetInBits());
1884 Record.push_back(
N->getFlags());
1889 if (
const auto &DWARFAddressSpace =
N->getDWARFAddressSpace())
1890 Record.push_back(*DWARFAddressSpace + 1);
1896 if (
auto PtrAuthData =
N->getPtrAuthData())
1897 Record.push_back(PtrAuthData->RawData);
1905void ModuleBitcodeWriter::writeDICompositeType(
1908 const unsigned IsNotUsedInOldTypeRef = 0x2;
1909 Record.push_back(IsNotUsedInOldTypeRef | (
unsigned)
N->isDistinct());
1910 Record.push_back(
N->getTag());
1913 Record.push_back(
N->getLine());
1916 Record.push_back(
N->getSizeInBits());
1917 Record.push_back(
N->getAlignInBits());
1918 Record.push_back(
N->getOffsetInBits());
1919 Record.push_back(
N->getFlags());
1921 Record.push_back(
N->getRuntimeLang());
1936void ModuleBitcodeWriter::writeDISubroutineType(
1939 const unsigned HasNoOldTypeRefs = 0x2;
1940 Record.push_back(HasNoOldTypeRefs | (
unsigned)
N->isDistinct());
1941 Record.push_back(
N->getFlags());
1949void ModuleBitcodeWriter::writeDIFile(
const DIFile *
N,
1952 Record.push_back(
N->isDistinct());
1955 if (
N->getRawChecksum()) {
1956 Record.push_back(
N->getRawChecksum()->Kind);
1964 auto Source =
N->getRawSource();
1972void ModuleBitcodeWriter::writeDICompileUnit(
const DICompileUnit *
N,
1975 assert(
N->isDistinct() &&
"Expected distinct compile units");
1977 Record.push_back(
N->getSourceLanguage());
1980 Record.push_back(
N->isOptimized());
1982 Record.push_back(
N->getRuntimeVersion());
1984 Record.push_back(
N->getEmissionKind());
1990 Record.push_back(
N->getDWOId());
1992 Record.push_back(
N->getSplitDebugInlining());
1993 Record.push_back(
N->getDebugInfoForProfiling());
1994 Record.push_back((
unsigned)
N->getNameTableKind());
1995 Record.push_back(
N->getRangesBaseAddress());
2003void ModuleBitcodeWriter::writeDISubprogram(
const DISubprogram *
N,
2006 const uint64_t HasUnitFlag = 1 << 1;
2007 const uint64_t HasSPFlagsFlag = 1 << 2;
2008 Record.push_back(
uint64_t(
N->isDistinct()) | HasUnitFlag | HasSPFlagsFlag);
2013 Record.push_back(
N->getLine());
2015 Record.push_back(
N->getScopeLine());
2017 Record.push_back(
N->getSPFlags());
2018 Record.push_back(
N->getVirtualIndex());
2019 Record.push_back(
N->getFlags());
2024 Record.push_back(
N->getThisAdjustment());
2036 Record.push_back(
N->isDistinct());
2039 Record.push_back(
N->getLine());
2040 Record.push_back(
N->getColumn());
2046void ModuleBitcodeWriter::writeDILexicalBlockFile(
2049 Record.push_back(
N->isDistinct());
2052 Record.push_back(
N->getDiscriminator());
2058void ModuleBitcodeWriter::writeDICommonBlock(
const DICommonBlock *
N,
2061 Record.push_back(
N->isDistinct());
2066 Record.push_back(
N->getLineNo());
2072void ModuleBitcodeWriter::writeDINamespace(
const DINamespace *
N,
2075 Record.push_back(
N->isDistinct() |
N->getExportSymbols() << 1);
2083void ModuleBitcodeWriter::writeDIMacro(
const DIMacro *
N,
2086 Record.push_back(
N->isDistinct());
2087 Record.push_back(
N->getMacinfoType());
2088 Record.push_back(
N->getLine());
2096void ModuleBitcodeWriter::writeDIMacroFile(
const DIMacroFile *
N,
2099 Record.push_back(
N->isDistinct());
2100 Record.push_back(
N->getMacinfoType());
2101 Record.push_back(
N->getLine());
2109void ModuleBitcodeWriter::writeDIArgList(
const DIArgList *
N,
2111 Record.reserve(
N->getArgs().size());
2119void ModuleBitcodeWriter::writeDIModule(
const DIModule *
N,
2122 Record.push_back(
N->isDistinct());
2123 for (
auto &
I :
N->operands())
2125 Record.push_back(
N->getLineNo());
2126 Record.push_back(
N->getIsDecl());
2132void ModuleBitcodeWriter::writeDIAssignID(
const DIAssignID *
N,
2136 Record.push_back(
N->isDistinct());
2141void ModuleBitcodeWriter::writeDITemplateTypeParameter(
2144 Record.push_back(
N->isDistinct());
2147 Record.push_back(
N->isDefault());
2153void ModuleBitcodeWriter::writeDITemplateValueParameter(
2156 Record.push_back(
N->isDistinct());
2157 Record.push_back(
N->getTag());
2160 Record.push_back(
N->isDefault());
2167void ModuleBitcodeWriter::writeDIGlobalVariable(
2176 Record.push_back(
N->getLine());
2178 Record.push_back(
N->isLocalToUnit());
2179 Record.push_back(
N->isDefinition());
2182 Record.push_back(
N->getAlignInBits());
2189void ModuleBitcodeWriter::writeDILocalVariable(
2205 const uint64_t HasAlignmentFlag = 1 << 1;
2210 Record.push_back(
N->getLine());
2212 Record.push_back(
N->getArg());
2213 Record.push_back(
N->getFlags());
2214 Record.push_back(
N->getAlignInBits());
2221void ModuleBitcodeWriter::writeDILabel(
2228 Record.push_back(
N->getLine());
2234void ModuleBitcodeWriter::writeDIExpression(
const DIExpression *
N,
2237 Record.reserve(
N->getElements().size() + 1);
2240 Record.append(
N->elements_begin(),
N->elements_end());
2246void ModuleBitcodeWriter::writeDIGlobalVariableExpression(
2249 Record.push_back(
N->isDistinct());
2260 Record.push_back(
N->isDistinct());
2263 Record.push_back(
N->getLine());
2266 Record.push_back(
N->getAttributes());
2273void ModuleBitcodeWriter::writeDIImportedEntity(
2276 Record.push_back(
N->isDistinct());
2277 Record.push_back(
N->getTag());
2280 Record.push_back(
N->getLine());
2289unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
2290 auto Abbv = std::make_shared<BitCodeAbbrev>();
2297void ModuleBitcodeWriter::writeNamedMetadata(
2299 if (
M.named_metadata_empty())
2302 unsigned Abbrev = createNamedMetadataAbbrev();
2306 Record.append(Str.bytes_begin(), Str.bytes_end());
2311 for (
const MDNode *
N : NMD.operands())
2318unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
2319 auto Abbv = std::make_shared<BitCodeAbbrev>();
2331void ModuleBitcodeWriter::writeMetadataStrings(
2333 if (Strings.empty())
2338 Record.push_back(Strings.size());
2345 W.EmitVBR(cast<MDString>(MD)->getLength(), 6);
2354 Blob.
append(cast<MDString>(MD)->getString());
2363#define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID,
2364#include "llvm/IR/Metadata.def"
2368void ModuleBitcodeWriter::writeMetadataRecords(
2370 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2375#define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0;
2376#include "llvm/IR/Metadata.def"
2381 if (
const MDNode *
N = dyn_cast<MDNode>(MD)) {
2382 assert(
N->isResolved() &&
"Expected forward references to be resolved");
2384 switch (
N->getMetadataID()) {
2387#define HANDLE_MDNODE_LEAF(CLASS) \
2388 case Metadata::CLASS##Kind: \
2390 write##CLASS(cast<CLASS>(N), Record, \
2391 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \
2393 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \
2395#include "llvm/IR/Metadata.def"
2398 if (
auto *
AL = dyn_cast<DIArgList>(MD)) {
2402 writeValueAsMetadata(cast<ValueAsMetadata>(MD),
Record);
2406void ModuleBitcodeWriter::writeModuleMetadata() {
2407 if (!VE.
hasMDs() &&
M.named_metadata_empty())
2415 std::vector<unsigned> MDAbbrevs;
2418 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2419 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2420 createGenericDINodeAbbrev();
2422 auto Abbv = std::make_shared<BitCodeAbbrev>();
2426 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2428 Abbv = std::make_shared<BitCodeAbbrev>();
2432 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2454 std::vector<uint64_t> IndexPos;
2469 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2470 for (
auto &Elt : IndexPos) {
2471 auto EltDelta = Elt - PreviousValue;
2472 PreviousValue = Elt;
2481 writeNamedMetadata(
Record);
2483 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2486 pushGlobalMetadataAttachment(
Record, GO);
2490 if (
F.isDeclaration() &&
F.hasMetadata())
2491 AddDeclAttachedMetadata(
F);
2495 if (GV.hasMetadata())
2496 AddDeclAttachedMetadata(GV);
2501void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2512void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2517 for (
const auto &
I : MDs) {
2523void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &
F) {
2528 if (
F.hasMetadata()) {
2529 pushGlobalMetadataAttachment(
Record,
F);
2540 I.getAllMetadataOtherThanDebugLoc(MDs);
2543 if (MDs.
empty())
continue;
2547 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2548 Record.push_back(MDs[i].first);
2558void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2564 M.getMDKindNames(Names);
2566 if (Names.
empty())
return;
2570 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2571 Record.push_back(MDKindID);
2582void ModuleBitcodeWriter::writeOperandBundleTags() {
2590 M.getOperandBundleTags(Tags);
2599 for (
auto Tag : Tags) {
2609void ModuleBitcodeWriter::writeSyncScopeNames() {
2611 M.getContext().getSyncScopeNames(SSNs);
2618 for (
auto SSN : SSNs) {
2619 Record.append(SSN.begin(), SSN.end());
2627void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2629 if (FirstVal == LastVal)
return;
2633 unsigned AggregateAbbrev = 0;
2634 unsigned String8Abbrev = 0;
2635 unsigned CString7Abbrev = 0;
2636 unsigned CString6Abbrev = 0;
2640 auto Abbv = std::make_shared<BitCodeAbbrev>();
2644 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2647 Abbv = std::make_shared<BitCodeAbbrev>();
2651 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2653 Abbv = std::make_shared<BitCodeAbbrev>();
2657 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2659 Abbv = std::make_shared<BitCodeAbbrev>();
2663 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2669 Type *LastTy =
nullptr;
2670 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2671 const Value *
V = Vals[i].first;
2673 if (
V->getType() != LastTy) {
2674 LastTy =
V->getType();
2677 CONSTANTS_SETTYPE_ABBREV);
2681 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2684 unsigned(
IA->hasSideEffects()) |
unsigned(
IA->isAlignStack()) << 1 |
2685 unsigned(
IA->getDialect() & 1) << 2 |
unsigned(
IA->canThrow()) << 3);
2688 const std::string &AsmStr =
IA->getAsmString();
2689 Record.push_back(AsmStr.size());
2690 Record.append(AsmStr.begin(), AsmStr.end());
2693 const std::string &ConstraintStr =
IA->getConstraintString();
2694 Record.push_back(ConstraintStr.size());
2695 Record.append(ConstraintStr.begin(), ConstraintStr.end());
2701 unsigned Code = -1U;
2702 unsigned AbbrevToUse = 0;
2703 if (
C->isNullValue()) {
2705 }
else if (isa<PoisonValue>(
C)) {
2707 }
else if (isa<UndefValue>(
C)) {
2710 if (
IV->getBitWidth() <= 64) {
2714 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2719 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
2724 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2728 APInt api = CFP->getValueAPF().bitcastToAPInt();
2730 Record.push_back((p[1] << 48) | (p[0] >> 16));
2731 Record.push_back(p[0] & 0xffffLL);
2733 APInt api = CFP->getValueAPF().bitcastToAPInt();
2738 assert(0 &&
"Unknown FP type!");
2740 }
else if (isa<ConstantDataSequential>(
C) &&
2741 cast<ConstantDataSequential>(
C)->isString()) {
2744 unsigned NumElts = Str->getNumElements();
2746 if (Str->isCString()) {
2751 AbbrevToUse = String8Abbrev;
2755 for (
unsigned i = 0; i != NumElts; ++i) {
2756 unsigned char V = Str->getElementAsInteger(i);
2758 isCStr7 &= (
V & 128) == 0;
2764 AbbrevToUse = CString6Abbrev;
2766 AbbrevToUse = CString7Abbrev;
2768 dyn_cast<ConstantDataSequential>(
C)) {
2770 Type *EltTy = CDS->getElementType();
2771 if (isa<IntegerType>(EltTy)) {
2772 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2773 Record.push_back(CDS->getElementAsInteger(i));
2775 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2777 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2779 }
else if (isa<ConstantAggregate>(
C)) {
2781 for (
const Value *
Op :
C->operands())
2783 AbbrevToUse = AggregateAbbrev;
2784 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
C)) {
2785 switch (
CE->getOpcode()) {
2792 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2794 assert(
CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2804 case Instruction::FNeg: {
2805 assert(
CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2814 case Instruction::GetElementPtr: {
2816 const auto *GO = cast<GEPOperator>(
C);
2819 if (std::optional<ConstantRange>
Range = GO->getInRange()) {
2823 for (
const Value *
Op :
CE->operands()) {
2829 case Instruction::ExtractElement:
2836 case Instruction::InsertElement:
2843 case Instruction::ShuffleVector:
2848 if (
C->getType() ==
C->getOperand(0)->getType()) {
2859 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
C)) {
2864 }
else if (
const auto *Equiv = dyn_cast<DSOLocalEquivalent>(
C)) {
2868 }
else if (
const auto *
NC = dyn_cast<NoCFIValue>(
C)) {
2872 }
else if (
const auto *CPA = dyn_cast<ConstantPtrAuth>(
C)) {
2891void ModuleBitcodeWriter::writeModuleConstants() {
2896 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2897 if (!isa<GlobalValue>(Vals[i].first)) {
2898 writeConstants(i, Vals.size(),
true);
2912bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2917 if (
ValID >= InstID) {
2924void ModuleBitcodeWriter::writeOperandBundles(
const CallBase &CS,
2931 Record.push_back(
C.getOperandBundleTagID(Bundle.getTagName()));
2933 for (
auto &Input : Bundle.Inputs)
2934 pushValueAndType(Input, InstID,
Record);
2943void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2949void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2952 int64_t diff = ((int32_t)InstID - (int32_t)
ValID);
2957void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2961 unsigned AbbrevToUse = 0;
2963 switch (
I.getOpcode()) {
2967 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2968 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2973 if (AbbrevToUse == FUNCTION_INST_CAST_ABBREV)
2974 AbbrevToUse = FUNCTION_INST_CAST_FLAGS_ABBREV;
2978 assert(isa<BinaryOperator>(
I) &&
"Unknown instruction!");
2980 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2981 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2982 pushValue(
I.getOperand(1), InstID, Vals);
2986 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2987 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2992 case Instruction::FNeg: {
2994 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
2995 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2999 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
3000 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
3005 case Instruction::GetElementPtr: {
3007 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
3008 auto &GEPInst = cast<GetElementPtrInst>(
I);
3011 for (
const Value *
Op :
I.operands())
3012 pushValueAndType(
Op, InstID, Vals);
3015 case Instruction::ExtractValue: {
3017 pushValueAndType(
I.getOperand(0), InstID, Vals);
3022 case Instruction::InsertValue: {
3024 pushValueAndType(
I.getOperand(0), InstID, Vals);
3025 pushValueAndType(
I.getOperand(1), InstID, Vals);
3030 case Instruction::Select: {
3032 pushValueAndType(
I.getOperand(1), InstID, Vals);
3033 pushValue(
I.getOperand(2), InstID, Vals);
3034 pushValueAndType(
I.getOperand(0), InstID, Vals);
3040 case Instruction::ExtractElement:
3042 pushValueAndType(
I.getOperand(0), InstID, Vals);
3043 pushValueAndType(
I.getOperand(1), InstID, Vals);
3045 case Instruction::InsertElement:
3047 pushValueAndType(
I.getOperand(0), InstID, Vals);
3048 pushValue(
I.getOperand(1), InstID, Vals);
3049 pushValueAndType(
I.getOperand(2), InstID, Vals);
3051 case Instruction::ShuffleVector:
3053 pushValueAndType(
I.getOperand(0), InstID, Vals);
3054 pushValue(
I.getOperand(1), InstID, Vals);
3055 pushValue(cast<ShuffleVectorInst>(
I).getShuffleMaskForBitcode(), InstID,
3058 case Instruction::ICmp:
3059 case Instruction::FCmp: {
3062 pushValueAndType(
I.getOperand(0), InstID, Vals);
3063 pushValue(
I.getOperand(1), InstID, Vals);
3071 case Instruction::Ret:
3074 unsigned NumOperands =
I.getNumOperands();
3075 if (NumOperands == 0)
3076 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
3077 else if (NumOperands == 1) {
3078 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3079 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
3081 for (
const Value *
Op :
I.operands())
3082 pushValueAndType(
Op, InstID, Vals);
3086 case Instruction::Br:
3091 if (
II.isConditional()) {
3093 pushValue(
II.getCondition(), InstID, Vals);
3097 case Instruction::Switch:
3102 pushValue(
SI.getCondition(), InstID, Vals);
3104 for (
auto Case :
SI.cases()) {
3110 case Instruction::IndirectBr:
3114 pushValue(
I.getOperand(0), InstID, Vals);
3119 case Instruction::Invoke: {
3124 if (
II->hasOperandBundles())
3125 writeOperandBundles(*
II, InstID);
3134 pushValueAndType(Callee, InstID, Vals);
3137 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3138 pushValue(
I.getOperand(i), InstID, Vals);
3141 if (FTy->isVarArg()) {
3142 for (
unsigned i = FTy->getNumParams(), e =
II->arg_size(); i != e; ++i)
3143 pushValueAndType(
I.getOperand(i), InstID, Vals);
3147 case Instruction::Resume:
3149 pushValueAndType(
I.getOperand(0), InstID, Vals);
3151 case Instruction::CleanupRet: {
3153 const auto &CRI = cast<CleanupReturnInst>(
I);
3154 pushValue(CRI.getCleanupPad(), InstID, Vals);
3155 if (CRI.hasUnwindDest())
3159 case Instruction::CatchRet: {
3161 const auto &CRI = cast<CatchReturnInst>(
I);
3162 pushValue(CRI.getCatchPad(), InstID, Vals);
3166 case Instruction::CleanupPad:
3167 case Instruction::CatchPad: {
3168 const auto &FuncletPad = cast<FuncletPadInst>(
I);
3171 pushValue(FuncletPad.getParentPad(), InstID, Vals);
3173 unsigned NumArgOperands = FuncletPad.arg_size();
3175 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
3176 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
3179 case Instruction::CatchSwitch: {
3181 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
3183 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
3185 unsigned NumHandlers = CatchSwitch.getNumHandlers();
3187 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
3190 if (CatchSwitch.hasUnwindDest())
3194 case Instruction::CallBr: {
3200 writeOperandBundles(*CBI, InstID);
3215 pushValueAndType(Callee, InstID, Vals);
3218 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
3219 pushValue(
I.getOperand(i), InstID, Vals);
3222 if (FTy->isVarArg()) {
3223 for (
unsigned i = FTy->getNumParams(), e = CBI->
arg_size(); i != e; ++i)
3224 pushValueAndType(
I.getOperand(i), InstID, Vals);
3228 case Instruction::Unreachable:
3230 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
3233 case Instruction::PHI: {
3234 const PHINode &PN = cast<PHINode>(
I);
3251 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
3256 case Instruction::LandingPad: {
3267 pushValueAndType(LP.
getClause(
I), InstID, Vals);
3272 case Instruction::Alloca: {
3280 unsigned EncodedAlign = getEncodedAlign(AI.
getAlign());
3281 Bitfield::set<APV::AlignLower>(
3282 Record, EncodedAlign & ((1 << APV::AlignLower::Bits) - 1));
3283 Bitfield::set<APV::AlignUpper>(
Record,
3284 EncodedAlign >> APV::AlignLower::Bits);
3286 Bitfield::set<APV::ExplicitType>(
Record,
true);
3291 if (AS !=
M.getDataLayout().getAllocaAddrSpace())
3296 case Instruction::Load:
3297 if (cast<LoadInst>(
I).isAtomic()) {
3299 pushValueAndType(
I.getOperand(0), InstID, Vals);
3302 if (!pushValueAndType(
I.getOperand(0), InstID, Vals))
3303 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
3307 Vals.
push_back(cast<LoadInst>(
I).isVolatile());
3308 if (cast<LoadInst>(
I).isAtomic()) {
3310 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(
I).getSyncScopeID()));
3313 case Instruction::Store:
3314 if (cast<StoreInst>(
I).isAtomic())
3318 pushValueAndType(
I.getOperand(1), InstID, Vals);
3319 pushValueAndType(
I.getOperand(0), InstID, Vals);
3321 Vals.
push_back(cast<StoreInst>(
I).isVolatile());
3322 if (cast<StoreInst>(
I).isAtomic()) {
3325 getEncodedSyncScopeID(cast<StoreInst>(
I).getSyncScopeID()));
3328 case Instruction::AtomicCmpXchg:
3330 pushValueAndType(
I.getOperand(0), InstID, Vals);
3331 pushValueAndType(
I.getOperand(1), InstID, Vals);
3332 pushValue(
I.getOperand(2), InstID, Vals);
3333 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isVolatile());
3337 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(
I).getSyncScopeID()));
3340 Vals.
push_back(cast<AtomicCmpXchgInst>(
I).isWeak());
3343 case Instruction::AtomicRMW:
3345 pushValueAndType(
I.getOperand(0), InstID, Vals);
3346 pushValueAndType(
I.getOperand(1), InstID, Vals);
3349 Vals.
push_back(cast<AtomicRMWInst>(
I).isVolatile());
3352 getEncodedSyncScopeID(cast<AtomicRMWInst>(
I).getSyncScopeID()));
3355 case Instruction::Fence:
3358 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(
I).getSyncScopeID()));
3360 case Instruction::Call: {
3365 writeOperandBundles(CI, InstID);
3385 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
3387 if (FTy->getParamType(i)->isLabelTy())
3394 if (FTy->isVarArg()) {
3395 for (
unsigned i = FTy->getNumParams(), e = CI.
arg_size(); i != e; ++i)
3400 case Instruction::VAArg:
3403 pushValue(
I.getOperand(0), InstID, Vals);
3406 case Instruction::Freeze:
3408 pushValueAndType(
I.getOperand(0), InstID, Vals);
3418void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3424 VSTOffset -= bitcodeStartBit();
3425 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3429 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3433 auto Abbv = std::make_shared<BitCodeAbbrev>();
3437 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3442 if (
F.isDeclaration())
3449 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3450 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3454 Record[1] = BitcodeIndex / 32 + 1;
3463void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3478 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3484 if (isa<BasicBlock>(
Name.getValue())) {
3487 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3491 AbbrevToUse = VST_ENTRY_6_ABBREV;
3493 AbbrevToUse = VST_ENTRY_7_ABBREV;
3496 for (
const auto P :
Name.getKey())
3500 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3507void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3508 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3510 if (isa<BasicBlock>(Order.V))
3520void ModuleBitcodeWriter::writeUseListBlock(
const Function *
F) {
3522 "Expected to be preserving use-list order");
3524 auto hasMore = [&]() {
3540void ModuleBitcodeWriter::writeFunction(
3559 unsigned CstStart, CstEnd;
3561 writeConstants(CstStart, CstEnd,
false);
3564 writeFunctionMetadata(
F);
3567 unsigned InstID = CstEnd;
3569 bool NeedsMetadataAttachment =
F.hasMetadata();
3577 writeInstruction(
I, InstID, Vals);
3579 if (!
I.getType()->isVoidTy())
3583 NeedsMetadataAttachment |=
I.hasMetadataOtherThanDebugLoc();
3610 auto PushValueOrMetadata = [&Vals, InstID,
3613 "RawLocation unexpectedly null in DbgVariableRecord");
3619 if (!pushValueAndType(VAM->getValue(), InstID, ValAndType)) {
3633 for (
DbgRecord &DR :
I.DebugMarker->getDbgRecordRange()) {
3659 FUNCTION_DEBUG_RECORD_VALUE_ABBREV);
3681 while (!Worklist.empty()) {
3682 Value *
V = Worklist.pop_back_val();
3683 for (
User *U :
V->users()) {
3684 if (
auto *
I = dyn_cast<Instruction>(U)) {
3688 }
else if (isa<Constant>(U) && !isa<GlobalValue>(U) &&
3689 Visited.insert(U).second)
3690 Worklist.push_back(U);
3696 if (!BlockAddressUsers.
empty()) {
3705 if (
auto *Symtab =
F.getValueSymbolTable())
3706 writeFunctionLevelValueSymbolTable(*Symtab);
3708 if (NeedsMetadataAttachment)
3709 writeFunctionMetadataAttachment(
F);
3711 writeUseListBlock(&
F);
3717void ModuleBitcodeWriter::writeBlockInfo() {
3724 auto Abbv = std::make_shared<BitCodeAbbrev>();
3735 auto Abbv = std::make_shared<BitCodeAbbrev>();
3745 auto Abbv = std::make_shared<BitCodeAbbrev>();
3755 auto Abbv = std::make_shared<BitCodeAbbrev>();
3761 VST_BBENTRY_6_ABBREV)
3766 auto Abbv = std::make_shared<BitCodeAbbrev>();
3771 CONSTANTS_SETTYPE_ABBREV)
3776 auto Abbv = std::make_shared<BitCodeAbbrev>();
3780 CONSTANTS_INTEGER_ABBREV)
3785 auto Abbv = std::make_shared<BitCodeAbbrev>();
3793 CONSTANTS_CE_CAST_Abbrev)
3797 auto Abbv = std::make_shared<BitCodeAbbrev>();
3800 CONSTANTS_NULL_Abbrev)
3807 auto Abbv = std::make_shared<BitCodeAbbrev>();
3815 FUNCTION_INST_LOAD_ABBREV)
3819 auto Abbv = std::make_shared<BitCodeAbbrev>();
3824 FUNCTION_INST_UNOP_ABBREV)
3828 auto Abbv = std::make_shared<BitCodeAbbrev>();
3834 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3838 auto Abbv = std::make_shared<BitCodeAbbrev>();
3844 FUNCTION_INST_BINOP_ABBREV)
3848 auto Abbv = std::make_shared<BitCodeAbbrev>();
3855 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3859 auto Abbv = std::make_shared<BitCodeAbbrev>();
3866 FUNCTION_INST_CAST_ABBREV)
3870 auto Abbv = std::make_shared<BitCodeAbbrev>();
3878 FUNCTION_INST_CAST_FLAGS_ABBREV)
3883 auto Abbv = std::make_shared<BitCodeAbbrev>();
3886 FUNCTION_INST_RET_VOID_ABBREV)
3890 auto Abbv = std::make_shared<BitCodeAbbrev>();
3894 FUNCTION_INST_RET_VAL_ABBREV)
3898 auto Abbv = std::make_shared<BitCodeAbbrev>();
3901 FUNCTION_INST_UNREACHABLE_ABBREV)
3905 auto Abbv = std::make_shared<BitCodeAbbrev>();
3913 FUNCTION_INST_GEP_ABBREV)
3917 auto Abbv = std::make_shared<BitCodeAbbrev>();
3924 FUNCTION_DEBUG_RECORD_VALUE_ABBREV)
3932void IndexBitcodeWriter::writeModStrings() {
3938 auto Abbv = std::make_shared<BitCodeAbbrev>();
3943 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3946 Abbv = std::make_shared<BitCodeAbbrev>();
3951 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3954 Abbv = std::make_shared<BitCodeAbbrev>();
3959 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3962 Abbv = std::make_shared<BitCodeAbbrev>();
3969 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3974 const auto &Hash = MPSE.
getValue();
3976 unsigned AbbrevToUse = Abbrev8Bit;
3978 AbbrevToUse = Abbrev6Bit;
3980 AbbrevToUse = Abbrev7Bit;
3982 auto ModuleId = ModuleIdMap.
size();
3983 ModuleIdMap[
Key] = ModuleId;
3992 Vals.
assign(Hash.begin(), Hash.end());
4004template <
typename Fn>
4008 if (!FS->type_tests().empty())
4013 auto WriteVFuncIdVec = [&](
uint64_t Ty,
4018 for (
auto &VF : VFs) {
4019 Record.push_back(VF.GUID);
4020 Record.push_back(VF.Offset);
4026 FS->type_test_assume_vcalls());
4028 FS->type_checked_load_vcalls());
4030 auto WriteConstVCallVec = [&](
uint64_t Ty,
4032 for (
auto &VC : VCs) {
4034 Record.push_back(VC.VFunc.GUID);
4035 Record.push_back(VC.VFunc.Offset);
4042 FS->type_test_assume_const_vcalls());
4044 FS->type_checked_load_const_vcalls());
4054 if (!FS->paramAccesses().empty()) {
4056 for (
auto &Arg : FS->paramAccesses()) {
4057 size_t UndoSize =
Record.size();
4058 Record.push_back(Arg.ParamNo);
4059 WriteRange(Arg.Use);
4060 Record.push_back(Arg.Calls.size());
4061 for (
auto &Call : Arg.Calls) {
4062 Record.push_back(Call.ParamNo);
4063 std::optional<unsigned> ValueID = GetValueID(Call.Callee);
4070 Record.push_back(*ValueID);
4071 WriteRange(Call.Offsets);
4082 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
4083 if (!FS->type_tests().empty())
4084 for (
auto &TT : FS->type_tests())
4085 ReferencedTypeIds.insert(TT);
4087 auto GetReferencedTypesFromVFuncIdVec =
4089 for (
auto &VF : VFs)
4090 ReferencedTypeIds.insert(VF.GUID);
4093 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
4094 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
4096 auto GetReferencedTypesFromConstVCallVec =
4098 for (
auto &VC : VCs)
4099 ReferencedTypeIds.insert(VC.VFunc.GUID);
4102 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
4103 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
4134 const std::string &Id,
4139 NameVals.
push_back(Summary.TTRes.TheKind);
4140 NameVals.
push_back(Summary.TTRes.SizeM1BitWidth);
4141 NameVals.
push_back(Summary.TTRes.AlignLog2);
4142 NameVals.
push_back(Summary.TTRes.SizeM1);
4143 NameVals.
push_back(Summary.TTRes.BitMask);
4144 NameVals.
push_back(Summary.TTRes.InlineBits);
4146 for (
auto &W : Summary.WPDRes)
4158 for (
auto &
P : Summary) {
4166 unsigned AllocAbbrev,
bool PerModule,
4167 std::function<
unsigned(
const ValueInfo &VI)> GetValueID,
4168 std::function<
unsigned(
unsigned)> GetStackIndex) {
4171 for (
auto &CI : FS->callsites()) {
4175 assert(!PerModule || (CI.Clones.size() == 1 && CI.Clones[0] == 0));
4176 Record.push_back(GetValueID(CI.Callee));
4178 Record.push_back(CI.StackIdIndices.size());
4179 Record.push_back(CI.Clones.size());
4181 for (
auto Id : CI.StackIdIndices)
4182 Record.push_back(GetStackIndex(Id));
4184 for (
auto V : CI.Clones)
4192 for (
auto &AI : FS->allocs()) {
4196 assert(!PerModule || (AI.Versions.size() == 1 && AI.Versions[0] == 0));
4197 Record.push_back(AI.MIBs.size());
4199 Record.push_back(AI.Versions.size());
4200 for (
auto &MIB : AI.MIBs) {
4201 Record.push_back((uint8_t)MIB.AllocType);
4202 Record.push_back(MIB.StackIdIndices.size());
4203 for (
auto Id : MIB.StackIdIndices)
4204 Record.push_back(GetStackIndex(Id));
4207 for (
auto V : AI.Versions)
4210 assert(AI.TotalSizes.empty() || AI.TotalSizes.size() == AI.MIBs.size());
4211 if (!AI.TotalSizes.empty()) {
4212 for (
auto Size : AI.TotalSizes)
4222void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
4224 unsigned ValueID,
unsigned FSCallsRelBFAbbrev,
4225 unsigned FSCallsProfileAbbrev,
unsigned CallsiteAbbrev,
4226 unsigned AllocAbbrev,
const Function &
F) {
4232 Stream, FS, [&](
const ValueInfo &VI) -> std::optional<unsigned> {
4237 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4239 [&](
const ValueInfo &VI) {
return getValueId(VI); },
4240 [&](
unsigned I) {
return I; });
4242 auto SpecialRefCnts =
FS->specialRefCounts();
4247 NameVals.
push_back(SpecialRefCnts.first);
4248 NameVals.
push_back(SpecialRefCnts.second);
4250 for (
auto &RI :
FS->refs())
4253 const bool UseRelBFRecord =
4256 for (
auto &ECI :
FS->calls()) {
4257 NameVals.
push_back(getValueId(ECI.first));
4265 (UseRelBFRecord ? FSCallsRelBFAbbrev : FSCallsProfileAbbrev);
4276void ModuleBitcodeWriterBase::writeModuleLevelReferences(
4278 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
4279 auto VI =
Index->getValueInfo(
V.getGUID());
4280 if (!VI ||
VI.getSummaryList().empty()) {
4286 auto *
Summary =
VI.getSummaryList()[0].get();
4292 auto VTableFuncs =
VS->vTableFuncs();
4293 if (!VTableFuncs.empty())
4296 unsigned SizeBeforeRefs = NameVals.
size();
4297 for (
auto &RI :
VS->refs())
4303 if (VTableFuncs.empty())
4308 for (
auto &
P : VTableFuncs) {
4314 FSModVTableRefsAbbrev);
4321void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
4324 bool IsThinLTO =
true;
4326 mdconst::extract_or_null<ConstantInt>(
M.getModuleFlag(
"ThinLTO")))
4327 IsThinLTO = MD->getZExtValue();
4339 if (
Index->enableSplitLTOUnit())
4341 if (
Index->hasUnifiedLTO())
4351 for (
const auto &GVI : valueIds()) {
4356 if (!
Index->stackIds().empty()) {
4357 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4362 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4367 auto Abbv = std::make_shared<BitCodeAbbrev>();
4379 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4382 Abbv = std::make_shared<BitCodeAbbrev>();
4394 unsigned FSCallsRelBFAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4397 Abbv = std::make_shared<BitCodeAbbrev>();
4403 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4406 Abbv = std::make_shared<BitCodeAbbrev>();
4414 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4417 Abbv = std::make_shared<BitCodeAbbrev>();
4422 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4425 Abbv = std::make_shared<BitCodeAbbrev>();
4432 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4434 Abbv = std::make_shared<BitCodeAbbrev>();
4440 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4442 Abbv = std::make_shared<BitCodeAbbrev>();
4449 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4461 if (!VI ||
VI.getSummaryList().empty()) {
4467 auto *
Summary =
VI.getSummaryList()[0].get();
4468 writePerModuleFunctionSummaryRecord(
4469 NameVals, Summary, VE.
getValueID(&
F), FSCallsRelBFAbbrev,
4470 FSCallsProfileAbbrev, CallsiteAbbrev, AllocAbbrev,
F);
4476 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
4477 FSModVTableRefsAbbrev);
4480 auto *Aliasee =
A.getAliaseeObject();
4483 if (!Aliasee->hasName() || isa<GlobalIFunc>(Aliasee))
4496 for (
auto &S :
Index->typeIdCompatibleVtableMap()) {
4500 TypeIdCompatibleVtableAbbrev);
4504 if (
Index->getBlockCount())
4512void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
4521 for (
const auto &GVI : valueIds()) {
4528 if (!StackIds.empty()) {
4529 auto StackIdAbbv = std::make_shared<BitCodeAbbrev>();
4534 unsigned StackIdAbbvId = Stream.
EmitAbbrev(std::move(StackIdAbbv));
4539 auto Abbv = std::make_shared<BitCodeAbbrev>();
4553 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4556 Abbv = std::make_shared<BitCodeAbbrev>();
4563 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4566 Abbv = std::make_shared<BitCodeAbbrev>();
4572 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4574 Abbv = std::make_shared<BitCodeAbbrev>();
4582 unsigned CallsiteAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4584 Abbv = std::make_shared<BitCodeAbbrev>();
4593 unsigned AllocAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4596 if (DecSummaries ==
nullptr)
4598 return DecSummaries->count(GVS);
4612 std::set<GlobalValue::GUID> ReferencedTypeIds;
4626 NameVals.
push_back(S.getOriginalName());
4631 std::set<GlobalValue::GUID> DefOrUseGUIDs;
4632 forEachSummary([&](GVInfo
I,
bool IsAliasee) {
4635 DefOrUseGUIDs.insert(
I.first);
4637 DefOrUseGUIDs.insert(
VI.getGUID());
4639 auto ValueId = getValueId(
I.first);
4641 SummaryToValueIdMap[S] = *ValueId;
4649 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4656 if (
auto *VS = dyn_cast<GlobalVarSummary>(S)) {
4659 NameVals.
push_back(ModuleIdMap[
VS->modulePath()]);
4662 for (
auto &RI :
VS->refs()) {
4663 auto RefValueId = getValueId(RI.getGUID());
4673 MaybeEmitOriginalName(*S);
4677 auto GetValueId = [&](
const ValueInfo &
VI) -> std::optional<unsigned> {
4679 return std::nullopt;
4680 return getValueId(
VI.getGUID());
4683 auto *
FS = cast<FunctionSummary>(S);
4688 Stream, FS, CallsiteAbbrev, AllocAbbrev,
4692 std::optional<unsigned> ValueID = GetValueId(VI);
4707 return StackIdIndicesToIndex[
I];
4712 NameVals.
push_back(ModuleIdMap[
FS->modulePath()]);
4724 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4725 for (
auto &RI :
FS->refs()) {
4726 auto RefValueId = getValueId(RI.getGUID());
4730 if (RI.isReadOnly())
4732 else if (RI.isWriteOnly())
4736 NameVals[6] = Count;
4737 NameVals[7] = RORefCnt;
4738 NameVals[8] = WORefCnt;
4740 for (
auto &EI :
FS->calls()) {
4743 std::optional<unsigned> CallValueId = GetValueId(EI.first);
4752 FSCallsProfileAbbrev);
4754 MaybeEmitOriginalName(*S);
4757 for (
auto *AS : Aliases) {
4758 auto AliasValueId = SummaryToValueIdMap[AS];
4765 auto AliaseeValueId = SummaryToValueIdMap[&AS->
getAliasee()];
4772 MaybeEmitOriginalName(*AS);
4774 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->
getAliasee()))
4778 if (!
Index.cfiFunctionDefs().empty()) {
4779 for (
auto &S :
Index.cfiFunctionDefs()) {
4780 if (DefOrUseGUIDs.count(
4786 if (!NameVals.
empty()) {
4792 if (!
Index.cfiFunctionDecls().empty()) {
4793 for (
auto &S :
Index.cfiFunctionDecls()) {
4794 if (DefOrUseGUIDs.count(
4800 if (!NameVals.
empty()) {
4808 for (
auto &
T : ReferencedTypeIds) {
4809 auto TidIter =
Index.typeIds().equal_range(
T);
4810 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4818 if (
Index.getBlockCount())
4831 auto Abbv = std::make_shared<BitCodeAbbrev>();
4835 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4837 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4840 Abbv = std::make_shared<BitCodeAbbrev>();
4843 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4849void ModuleBitcodeWriter::writeModuleHash(
StringRef View) {
4855 reinterpret_cast<const uint8_t *
>(
View.data()),
View.size()));
4856 std::array<uint8_t, 20> Hash = Hasher.result();
4857 for (
int Pos = 0; Pos < 20; Pos += 4) {
4870void ModuleBitcodeWriter::write() {
4878 writeModuleVersion();
4887 writeAttributeGroupTable();
4890 writeAttributeTable();
4899 writeModuleConstants();
4902 writeModuleMetadataKinds();
4905 writeModuleMetadata();
4909 writeUseListBlock(
nullptr);
4911 writeOperandBundleTags();
4912 writeSyncScopeNames();
4917 if (!
F.isDeclaration())
4918 writeFunction(
F, FunctionToBitcodeIndex);
4923 writePerModuleGlobalValueSummary();
4925 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4953 unsigned CPUType = ~0U;
4960 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4961 DARWIN_CPU_TYPE_X86 = 7,
4962 DARWIN_CPU_TYPE_ARM = 12,
4963 DARWIN_CPU_TYPE_POWERPC = 18
4968 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4970 CPUType = DARWIN_CPU_TYPE_X86;
4972 CPUType = DARWIN_CPU_TYPE_POWERPC;
4974 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4976 CPUType = DARWIN_CPU_TYPE_ARM;
4980 "Expected header size to be reserved");
4985 unsigned Position = 0;
4993 while (Buffer.
size() & 15)
5000 Stream.
Emit((
unsigned)
'B', 8);
5001 Stream.
Emit((
unsigned)
'C', 8);
5002 Stream.
Emit(0x0, 4);
5003 Stream.
Emit(0xC, 4);
5004 Stream.
Emit(0xE, 4);
5005 Stream.
Emit(0xD, 4);
5023 auto Abbv = std::make_shared<BitCodeAbbrev>();
5026 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
5034 assert(!WroteStrtab && !WroteSymtab);
5040 if (M->getModuleInlineAsm().empty())
5044 const Triple TT(M->getTargetTriple());
5046 if (!
T || !
T->hasMCAsmParser())
5068 std::vector<char> Strtab;
5070 Strtab.resize(StrtabBuilder.
getSize());
5071 StrtabBuilder.
write((uint8_t *)Strtab.data());
5074 {Strtab.data(), Strtab.size()});
5085 bool ShouldPreserveUseListOrder,
5094 assert(M.isMaterialized());
5095 Mods.push_back(
const_cast<Module *
>(&M));
5097 ModuleBitcodeWriter ModuleWriter(M, StrtabBuilder, *Stream,
5098 ShouldPreserveUseListOrder,
Index,
5099 GenerateHash, ModHash);
5100 ModuleWriter.write();
5105 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5107 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *
Index, DecSummaries,
5108 ModuleToSummariesForIndex);
5109 IndexWriter.write();
5114 bool ShouldPreserveUseListOrder,
5118 Writer.writeModule(M, ShouldPreserveUseListOrder,
Index, GenerateHash,
5120 Writer.writeSymtab();
5121 Writer.writeStrtab();
5123 Triple TT(M.getTargetTriple());
5124 if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) {
5142void IndexBitcodeWriter::write() {
5145 writeModuleVersion();
5151 writeCombinedGlobalValueSummary();
5162 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5177class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
5187 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
5189 ModHash(&ModHash) {}
5194 void writeSimplifiedModuleInfo();
5204void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
5216 auto Abbv = std::make_shared<BitCodeAbbrev>();
5219 Abbv->Add(AbbrevOpToUse);
5220 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
5222 for (
const auto P :
M.getSourceFileName())
5286void ThinLinkBitcodeWriter::write() {
5289 writeModuleVersion();
5291 writeSimplifiedModuleInfo();
5293 writePerModuleGlobalValueSummary();
5310 assert(M.isMaterialized());
5311 Mods.push_back(
const_cast<Module *
>(&M));
5313 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream,
Index,
5315 ThinLinkWriter.write();
5336 switch (
T.getObjectFormat()) {
5338 return "__LLVM,__bitcode";
5363 switch (
T.getObjectFormat()) {
5365 return "__LLVM,__cmdline";
5391 const std::vector<uint8_t> &CmdArgs) {
5397 for (
auto *GV : UsedGlobals) {
5398 if (GV->getName() !=
"llvm.embedded.module" &&
5399 GV->getName() !=
"llvm.cmdline")
5404 Used->eraseFromParent();
5409 Triple T(M.getTargetTriple());
5438 M.getGlobalVariable(
"llvm.embedded.module",
true)) {
5439 assert(Old->hasZeroLiveUses() &&
5440 "llvm.embedded.module can only be used once in llvm.compiler.used");
5442 Old->eraseFromParent();
5444 GV->
setName(
"llvm.embedded.module");
5462 assert(Old->hasZeroLiveUses() &&
5463 "llvm.cmdline can only be used once in llvm.compiler.used");
5465 Old->eraseFromParent();
5471 if (UsedArray.
empty())
5479 NewUsed->setSection(
"llvm.metadata");
This file defines the StringMap class.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, AsmWriterContext &WriterCtx)
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, AsmWriterContext &WriterCtx)
static void writeDIStringType(raw_ostream &Out, const DIStringType *N, AsmWriterContext &WriterCtx)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, AsmWriterContext &WriterCtx)
static void writeDIModule(raw_ostream &Out, const DIModule *N, AsmWriterContext &WriterCtx)
static void writeDIFile(raw_ostream &Out, const DIFile *N, AsmWriterContext &)
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, AsmWriterContext &WriterCtx)
static void writeDILabel(raw_ostream &Out, const DILabel *N, AsmWriterContext &WriterCtx)
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, AsmWriterContext &WriterCtx)
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, AsmWriterContext &WriterCtx)
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, AsmWriterContext &WriterCtx)
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, AsmWriterContext &WriterCtx)
static void writeDILocation(raw_ostream &Out, const DILocation *DL, AsmWriterContext &WriterCtx)
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, AsmWriterContext &WriterCtx)
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, AsmWriterContext &WriterCtx)
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, AsmWriterContext &)
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, AsmWriterContext &WriterCtx)
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, AsmWriterContext &WriterCtx)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, AsmWriterContext &WriterCtx)
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, AsmWriterContext &WriterCtx)
static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N, AsmWriterContext &WriterCtx)
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, AsmWriterContext &WriterCtx)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, AsmWriterContext &WriterCtx)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, AsmWriterContext &)
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, AsmWriterContext &WriterCtx)
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, AsmWriterContext &WriterCtx)
static void writeDIAssignID(raw_ostream &Out, const DIAssignID *DL, AsmWriterContext &WriterCtx)
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, AsmWriterContext &WriterCtx)
static void writeDIArgList(raw_ostream &Out, const DIArgList *N, AsmWriterContext &WriterCtx, bool FromValue=false)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, AsmWriterContext &WriterCtx)
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, AsmWriterContext &WriterCtx)
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static unsigned serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata &Meta)
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
static unsigned getEncodedVisibility(const GlobalValue &GV)
static uint64_t getOptimizationFlags(const Value *V)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version,...
static unsigned getEncodedCastOpcode(unsigned Opcode)
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
static cl::opt< uint32_t > FlushThreshold("bitcode-flush-threshold", cl::Hidden, cl::init(512), cl::desc("The threshold (unit M) for flushing LLVM bitcode."))
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
bool WriteNewDbgInfoFormatToBitcode
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, bool ImportAsDecl=false)
static void emitDarwinBCHeaderAndTrailer(SmallVectorImpl< char > &Buffer, const Triple &TT)
If generating a bc file on darwin, we have to emit a header and trailer to make it compatible with th...
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
llvm::cl::opt< bool > UseNewDbgInfoFormat
static uint64_t getEncodedRelBFCallEdgeInfo(const CalleeInfo &CI)
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
static void emitConstantRange(SmallVectorImpl< uint64_t > &Record, const ConstantRange &CR, bool EmitBitWidth)
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
static const char * getSectionNameForCommandline(const Triple &T)
static cl::opt< unsigned > IndexThreshold("bitcode-mdindex-threshold", cl::Hidden, cl::init(25), cl::desc("Number of metadatas above which we emit an index " "to enable lazy-loading"))
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, Fn GetValueID)
Write the function type metadata related records that need to appear before a function summary entry ...
static uint64_t getEncodedHotnessCallEdgeInfo(const CalleeInfo &CI)
static void emitWideAPInt(SmallVectorImpl< uint64_t > &Vals, const APInt &A)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
static const char * getSectionNameForBitcode(const Triple &T)
static void writeFunctionHeapProfileRecords(BitstreamWriter &Stream, FunctionSummary *FS, unsigned CallsiteAbbrev, unsigned AllocAbbrev, bool PerModule, std::function< unsigned(const ValueInfo &VI)> GetValueID, std::function< unsigned(unsigned)> GetStackIndex)
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdSummary &Summary)
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static MaybeAlign getAlign(Value *Ptr)
static cl::opt< LTOBitcodeEmbedding > EmbedBitcode("lto-embed-bitcode", cl::init(LTOBitcodeEmbedding::DoNotEmbed), cl::values(clEnumValN(LTOBitcodeEmbedding::DoNotEmbed, "none", "Do not embed"), clEnumValN(LTOBitcodeEmbedding::EmbedOptimized, "optimized", "Embed after all optimization passes"), clEnumValN(LTOBitcodeEmbedding::EmbedPostMergePreOptimized, "post-merge-pre-opt", "Embed post merge, but before optimizations")), cl::desc("Embed LLVM bitcode in object files produced by LTO"))
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const uint32_t IV[8]
Class for arbitrary precision integers.
unsigned getNumWords() const
Get the number of words.
unsigned getActiveWords() const
Compute the number of active words in the value of this APInt.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
int64_t getSExtValue() const
Get sign extended value.
Alias summary information.
const GlobalValueSummary & getAliasee() const
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
Align getAlign() const
Return the alignment of the memory that is being allocated by the instruction.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
unsigned getAddressSpace() const
Return the address space for the allocation.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Min
*p = old <signed v ? old : v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool hasAttributes() const
Return true if attributes exists in this set.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the buffer specified...
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
void writeStrtab()
Write the bitcode file's string table.
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
void writeIndex(const ModuleSummaryIndex *Index, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex, const GVSummaryPtrSet *DecSummaries)
void writeModule(const Module &M, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the buffer specified at construction time.
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void markAndBlockFlushing()
For scenarios where the user wants to access a section of the stream to (for example) compute some ch...
StringRef getMarkedBufferAndResumeFlushing()
resumes flushing, but does not flush, and returns the section in the internal buffer starting from th...
void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev=0)
EmitRecord - Emit the specified record to the stream, using an abbrev if we have one to compress the ...
void Emit(uint32_t Val, unsigned NumBits)
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
void BackpatchWord(uint64_t BitNo, unsigned Val)
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
AttributeList getAttributes() const
Return the parameter attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
BasicBlock * getIndirectDest(unsigned i) const
BasicBlock * getDefaultDest() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
bool isMustTailCall() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
A constant value that is initialized with an expression using other constant values.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
ConstantFP - Floating Point Values [float, double].
This is the shared class of boolean and integer constants.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
This is an important base class in LLVM.
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
Basic type, like 'int' or 'float'.
A pair of DIGlobalVariable and DIExpression.
An imported module (C++ using directive or similar).
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
String type, Fortran CHARACTER(n)
Type array for a subprogram.
This class represents an Operation in the Expression.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
DIAssignID * getAssignID() const
DIExpression * getExpression() const
DILocalVariable * getVariable() const
Metadata * getRawLocation() const
Returns the metadata operand for the first location description.
Metadata * getRawAddress() const
DIExpression * getAddressExpression() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
Function summary information to aid decisions and implementation of importing.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
Generic tagged DWARF-like metadata node.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
ThreadLocalMode getThreadLocalMode() const
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
UnnamedAddr getUnnamedAddr() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
DLLStorageClassTypes getDLLStorageClass() const
Global variable summary information to aid decisions and implementation of importing.
This instruction inserts a struct field of array element value into an aggregate value.
idx_iterator idx_end() const
idx_iterator idx_begin() const
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
Tracking metadata reference owned by Metadata.
size_t getBufferSize() const
const char * getBufferStart() const
const char * getBufferEnd() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static constexpr uint64_t BitcodeSummaryVersion
A Module instance is used to store all the information related to an LLVM module.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A class that wrap the SHA1 algorithm.
size_type size() const
Determine the number of elements in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getTypeID(Type *T) const
unsigned getMetadataID(const Metadata *MD) const
UseListOrderStack UseListOrders
std::vector< std::pair< const Value *, unsigned > > ValueList
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
unsigned getInstructionID(const Instruction *I) const
unsigned getAttributeListID(AttributeList PAL) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
bool hasMDs() const
Check whether the current block has any metadata to emit.
unsigned getComdatID(const Comdat *C) const
uint64_t computeBitsRequiredForTypeIndices() const
unsigned getValueID(const Value *V) const
unsigned getMetadataOrNullID(const Metadata *MD) const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
const ValueList & getValues() const
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.
void setInstructionID(const Instruction *I)
const std::vector< const BasicBlock * > & getBasicBlocks() const
const std::vector< AttributeList > & getAttributeLists() const
bool shouldPreserveUseListOrder() const
const ComdatSetType & getComdats() const
std::vector< Type * > TypeList
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
const TypeList & getTypes() const
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
LLVMContext & getContext() const
All values hold a context through their type.
void takeName(Value *V)
Transfer the name from V to this value.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an std::string.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
@ C
The default llvm calling convention, compatible with C.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
@ CE
Windows NT (Windows on ARM)
@ TYPE_CODE_OPAQUE_POINTER
@ METADATA_TEMPLATE_VALUE
@ METADATA_LEXICAL_BLOCK_FILE
@ METADATA_SUBROUTINE_TYPE
@ METADATA_GLOBAL_DECL_ATTACHMENT
@ METADATA_IMPORTED_ENTITY
@ METADATA_GENERIC_SUBRANGE
@ METADATA_COMPOSITE_TYPE
@ METADATA_GLOBAL_VAR_EXPR
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_CE_GEP_WITH_INRANGE
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_HYBRID_PATCHABLE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ 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 tuples (A, B,...
void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void embedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedCmdline, const std::vector< uint8_t > &CmdArgs)
If EmbedBitcode is set, save a copy of the llvm IR as data in the __LLVM,__bitcode section (....
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr, const GVSummaryPtrSet *DecSummaries=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
AtomicOrdering
Atomic ordering for LLVM's memory model.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
DWARFExpression::Operation Op
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode,...
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void consumeError(Error Err)
Consume a Error without doing anything.
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
Structure to hold a use-list order.
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName