31 #include "llvm/Config/llvm-config.h" 87 cl::desc(
"Number of metadatas above which we emit an index " 88 "to enable lazy-loading"));
92 cl::desc(
"Write relative block frequency to function summary "));
105 VST_BBENTRY_6_ABBREV,
109 CONSTANTS_INTEGER_ABBREV,
110 CONSTANTS_CE_CAST_Abbrev,
111 CONSTANTS_NULL_Abbrev,
115 FUNCTION_INST_UNOP_ABBREV,
116 FUNCTION_INST_UNOP_FLAGS_ABBREV,
117 FUNCTION_INST_BINOP_ABBREV,
118 FUNCTION_INST_BINOP_FLAGS_ABBREV,
119 FUNCTION_INST_CAST_ABBREV,
120 FUNCTION_INST_RET_VOID_ABBREV,
121 FUNCTION_INST_RET_VAL_ABBREV,
122 FUNCTION_INST_UNREACHABLE_ABBREV,
123 FUNCTION_INST_GEP_ABBREV,
128 class BitcodeWriterBase {
139 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
143 void writeModuleVersion();
146 void BitcodeWriterBase::writeModuleVersion() {
153 class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
167 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
170 unsigned GlobalValueId;
174 uint64_t VSTOffsetPlaceholder = 0;
181 bool ShouldPreserveUseListOrder,
183 : BitcodeWriterBase(Stream, StrtabBuilder), M(M),
184 VE(M, ShouldPreserveUseListOrder), Index(Index) {
193 for (
const auto &GUIDSummaryLists : *Index)
195 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
196 if (
auto FS = dyn_cast<FunctionSummary>(Summary.get()))
201 for (
auto &CallEdge :
FS->calls())
202 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
203 assignValueId(CallEdge.first.getGUID());
207 void writePerModuleGlobalValueSummary();
213 unsigned FSCallsAbbrev,
214 unsigned FSCallsProfileAbbrev,
218 unsigned FSModRefsAbbrev,
219 unsigned FSModVTableRefsAbbrev);
222 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
226 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
229 assert(VMI != GUIDToValueIdMap.end() &&
230 "GUID does not have assigned value Id");
237 return getValueId(VI.
getGUID());
241 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
245 class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
259 uint64_t BitcodeStartBit;
269 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
270 ShouldPreserveUseListOrder, Index),
271 Buffer(Buffer), GenerateHash(GenerateHash), ModHash(ModHash),
272 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
278 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
282 void writeAttributeGroupTable();
283 void writeAttributeTable();
284 void writeTypeTable();
286 void writeValueSymbolTableForwardDecl();
287 void writeModuleInfo();
292 unsigned createDILocationAbbrev();
295 unsigned createGenericDINodeAbbrev();
355 unsigned createNamedMetadataAbbrev();
357 unsigned createMetadataStringsAbbrev();
362 std::vector<unsigned> *MDAbbrevs =
nullptr,
363 std::vector<uint64_t> *IndexPos =
nullptr);
364 void writeModuleMetadata();
365 void writeFunctionMetadata(
const Function &
F);
366 void writeFunctionMetadataAttachment(
const Function &
F);
367 void writeGlobalVariableMetadataAttachment(
const GlobalVariable &GV);
370 void writeModuleMetadataKinds();
371 void writeOperandBundleTags();
372 void writeSyncScopeNames();
373 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
374 void writeModuleConstants();
375 bool pushValueAndType(
const Value *V,
unsigned InstID,
378 void pushValue(
const Value *V,
unsigned InstID,
380 void pushValueSigned(
const Value *V,
unsigned InstID,
382 void writeInstruction(
const Instruction &
I,
unsigned InstID,
385 void writeGlobalValueSymbolTable(
388 void writeUseListBlock(
const Function *
F);
392 void writeBlockInfo();
393 void writeModuleHash(
size_t BlockStartPos);
401 class IndexBitcodeWriter :
public BitcodeWriterBase {
407 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
411 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
414 unsigned GlobalValueId = 0;
422 const std::map<std::string, GVSummaryMapTy>
423 *ModuleToSummariesForIndex =
nullptr)
424 : BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
425 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
430 forEachSummary([&](GVInfo
I,
bool) {
431 GUIDToValueIdMap[I.first] = ++GlobalValueId;
436 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
441 template<
typename Functor>
442 void forEachSummary(Functor Callback) {
443 if (ModuleToSummariesForIndex) {
444 for (
auto &M : *ModuleToSummariesForIndex)
445 for (
auto &Summary : M.second) {
446 Callback(Summary,
false);
450 if (
auto *AS = dyn_cast<AliasSummary>(Summary.getSecond()))
451 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
454 for (
auto &Summaries : Index)
455 for (
auto &Summary : Summaries.second.SummaryList)
456 Callback({Summaries.first, Summary.get()},
false);
464 template <
typename Functor>
void forEachModule(Functor Callback) {
465 if (ModuleToSummariesForIndex) {
466 for (
const auto &M : *ModuleToSummariesForIndex) {
467 const auto &MPI = Index.modulePaths().find(M.first);
468 if (MPI == Index.modulePaths().end()) {
472 assert(ModuleToSummariesForIndex->size() == 1);
478 for (
const auto &MPSE : Index.modulePaths())
487 void writeModStrings();
488 void writeCombinedGlobalValueSummary();
491 auto VMI = GUIDToValueIdMap.find(ValGUID);
492 if (VMI == GUIDToValueIdMap.end())
497 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
533 case Instruction::Sub:
535 case Instruction::Mul:
538 case Instruction::FDiv:
541 case Instruction::FRem:
589 for (
unsigned i = 0,
e = Str.
size(); i !=
e; ++i) {
601 case Attribute::Alignment:
603 case Attribute::AllocSize:
605 case Attribute::AlwaysInline:
607 case Attribute::ArgMemOnly:
609 case Attribute::Builtin:
611 case Attribute::ByVal:
615 case Attribute::InAlloca:
619 case Attribute::InaccessibleMemOnly:
621 case Attribute::InaccessibleMemOrArgMemOnly:
623 case Attribute::InlineHint:
625 case Attribute::InReg:
629 case Attribute::MinSize:
631 case Attribute::Naked:
633 case Attribute::Nest:
637 case Attribute::NoBuiltin:
639 case Attribute::NoCapture:
641 case Attribute::NoDuplicate:
643 case Attribute::NoFree:
645 case Attribute::NoImplicitFloat:
647 case Attribute::NoInline:
649 case Attribute::NoRecurse:
651 case Attribute::NonLazyBind:
653 case Attribute::NonNull:
655 case Attribute::Dereferenceable:
657 case Attribute::DereferenceableOrNull:
659 case Attribute::NoRedZone:
661 case Attribute::NoReturn:
663 case Attribute::NoSync:
665 case Attribute::NoCfCheck:
667 case Attribute::NoUnwind:
669 case Attribute::OptForFuzzing:
671 case Attribute::OptimizeForSize:
673 case Attribute::OptimizeNone:
675 case Attribute::ReadNone:
677 case Attribute::ReadOnly:
679 case Attribute::Returned:
681 case Attribute::ReturnsTwice:
683 case Attribute::SExt:
685 case Attribute::Speculatable:
687 case Attribute::StackAlignment:
689 case Attribute::StackProtect:
691 case Attribute::StackProtectReq:
693 case Attribute::StackProtectStrong:
695 case Attribute::SafeStack:
697 case Attribute::ShadowCallStack:
699 case Attribute::StrictFP:
701 case Attribute::StructRet:
703 case Attribute::SanitizeAddress:
705 case Attribute::SanitizeHWAddress:
707 case Attribute::SanitizeThread:
709 case Attribute::SanitizeMemory:
711 case Attribute::SpeculativeLoadHardening:
713 case Attribute::SwiftError:
715 case Attribute::SwiftSelf:
717 case Attribute::UWTable:
719 case Attribute::WillReturn:
721 case Attribute::WriteOnly:
723 case Attribute::ZExt:
725 case Attribute::ImmArg:
727 case Attribute::SanitizeMemTag:
738 void ModuleBitcodeWriter::writeAttributeGroupTable() {
739 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
741 if (AttrGrps.empty())
return;
747 unsigned AttrListIndex = Pair.first;
753 if (Attr.isEnumAttribute()) {
756 }
else if (Attr.isIntAttribute()) {
760 }
else if (Attr.isStringAttribute()) {
772 assert(Attr.isTypeAttribute());
773 Type *Ty = Attr.getValueAsType();
788 void ModuleBitcodeWriter::writeAttributeTable() {
790 if (Attrs.empty())
return;
795 for (
unsigned i = 0,
e = Attrs.size(); i !=
e; ++i) {
811 void ModuleBitcodeWriter::writeTypeTable() {
820 auto Abbv = std::make_shared<BitCodeAbbrev>();
824 unsigned PtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
827 Abbv = std::make_shared<BitCodeAbbrev>();
832 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
835 Abbv = std::make_shared<BitCodeAbbrev>();
840 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
843 Abbv = std::make_shared<BitCodeAbbrev>();
847 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
850 Abbv = std::make_shared<BitCodeAbbrev>();
855 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
858 Abbv = std::make_shared<BitCodeAbbrev>();
862 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
870 for (
unsigned i = 0,
e = TypeList.size(); i !=
e; ++i) {
871 Type *
T = TypeList[i];
899 if (AddressSpace == 0) AbbrevToUse = PtrAbbrev;
910 AbbrevToUse = FunctionAbbrev;
924 AbbrevToUse = StructAnonAbbrev;
930 AbbrevToUse = StructNamedAbbrev;
946 AbbrevToUse = ArrayAbbrev;
963 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
1003 uint64_t RawFlags = 0;
1015 uint64_t RawFlags = 0;
1018 RawFlags |= (Flags.
Live << 1);
1025 RawFlags = (RawFlags << 4) | Flags.
Linkage;
1089 size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1092 return StrtabBuilder.
add(Str);
1095 void ModuleBitcodeWriter::writeComdats() {
1110 void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1115 auto Abbv = std::make_shared<BitCodeAbbrev>();
1121 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1137 bool isChar6 =
true;
1138 for (
char C : Str) {
1141 if ((
unsigned char)
C & 128)
1153 void ModuleBitcodeWriter::writeModuleInfo() {
1167 std::map<std::string, unsigned> SectionMap;
1168 std::map<std::string, unsigned> GCMap;
1169 unsigned MaxAlignment = 0;
1170 unsigned MaxGlobalType = 0;
1172 MaxAlignment =
std::max(MaxAlignment, GV.getAlignment());
1174 if (GV.hasSection()) {
1176 unsigned &
Entry = SectionMap[GV.getSection()];
1180 Entry = SectionMap.size();
1185 MaxAlignment =
std::max(MaxAlignment,
F.getAlignment());
1186 if (
F.hasSection()) {
1188 unsigned &
Entry = SectionMap[
F.getSection()];
1192 Entry = SectionMap.size();
1197 unsigned &
Entry = GCMap[
F.getGC()];
1201 Entry = GCMap.size();
1207 unsigned SimpleGVarAbbrev = 0;
1208 if (!M.global_empty()) {
1210 auto Abbv = std::make_shared<BitCodeAbbrev>();
1221 if (MaxAlignment == 0)
1224 unsigned MaxEncAlignment =
Log2_32(MaxAlignment)+1;
1228 if (SectionMap.empty())
1234 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1248 auto Abbv = std::make_shared<BitCodeAbbrev>();
1251 Abbv->Add(AbbrevOpToUse);
1252 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1254 for (
const auto P : M.getSourceFileName())
1264 unsigned AbbrevToUse = 0;
1270 Vals.
push_back(addToStrtab(GV.getName()));
1273 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1278 Vals.
push_back(GV.hasSection() ? SectionMap[GV.getSection()] : 0);
1279 if (GV.isThreadLocal() ||
1282 GV.isExternallyInitialized() ||
1285 GV.hasAttributes() ||
1287 GV.hasPartition()) {
1291 Vals.
push_back(GV.isExternallyInitialized());
1299 Vals.
push_back(addToStrtab(GV.getPartition()));
1300 Vals.
push_back(GV.getPartition().size());
1302 AbbrevToUse = SimpleGVarAbbrev;
1323 Vals.
push_back(
F.hasSection() ? SectionMap[
F.getSection()] : 0);
1334 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1338 Vals.
push_back(addToStrtab(
F.getPartition()));
1341 unsigned AbbrevToUse = 0;
1351 Vals.
push_back(addToStrtab(A.getName()));
1354 Vals.
push_back(A.getType()->getAddressSpace());
1362 Vals.
push_back(addToStrtab(A.getPartition()));
1363 Vals.
push_back(A.getPartition().size());
1365 unsigned AbbrevToUse = 0;
1377 Vals.
push_back(
I.getType()->getAddressSpace());
1382 Vals.
push_back(addToStrtab(
I.getPartition()));
1388 writeValueSymbolTableForwardDecl();
1394 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1395 if (OBO->hasNoSignedWrap())
1397 if (OBO->hasNoUnsignedWrap())
1399 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1402 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1403 if (FPMO->hasAllowReassoc())
1405 if (FPMO->hasNoNaNs())
1407 if (FPMO->hasNoInfs())
1409 if (FPMO->hasNoSignedZeros())
1411 if (FPMO->hasAllowReciprocal())
1413 if (FPMO->hasAllowContract())
1415 if (FPMO->hasApproxFunc())
1422 void ModuleBitcodeWriter::writeValueAsMetadata(
1437 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1438 "Unexpected function-local metadata");
1447 unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1450 auto Abbv = std::make_shared<BitCodeAbbrev>();
1465 Abbrev = createDILocationAbbrev();
1478 unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1481 auto Abbv = std::make_shared<BitCodeAbbrev>();
1496 Abbrev = createGenericDINodeAbbrev();
1511 return I < 0 ? ~(U << 1) : U << 1;
1517 const uint64_t
Version = 1 << 1;
1570 if (
const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
1571 Record.
push_back(*DWARFAddressSpace + 1);
1582 const unsigned IsNotUsedInOldTypeRef = 0x2;
1608 const unsigned HasNoOldTypeRefs = 0x2;
1624 if (N->getRawChecksum()) {
1625 Record.
push_back(N->getRawChecksum()->Kind);
1633 auto Source = N->getRawSource();
1672 const uint64_t HasUnitFlag = 1 << 1;
1673 const uint64_t HasSPFlagsFlag = 1 << 2;
1690 Record.
push_back(N->getThisAdjustment());
1811 const uint64_t
Version = 2 << 1;
1845 const uint64_t HasAlignmentFlag = 1 << 1;
1877 const uint64_t
Version = 3 << 1;
1927 unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
1928 auto Abbv = std::make_shared<BitCodeAbbrev>();
1935 void ModuleBitcodeWriter::writeNamedMetadata(
1940 unsigned Abbrev = createNamedMetadataAbbrev();
1956 unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
1957 auto Abbv = std::make_shared<BitCodeAbbrev>();
1969 void ModuleBitcodeWriter::writeMetadataStrings(
1971 if (Strings.
empty())
1983 W.
EmitVBR(cast<MDString>(MD)->getLength(), 6);
1992 Blob.
append(cast<MDString>(MD)->getString());
2001 #define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID, 2002 #include "llvm/IR/Metadata.def" 2006 void ModuleBitcodeWriter::writeMetadataRecords(
2008 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
2013 #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0; 2014 #include "llvm/IR/Metadata.def" 2019 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
2025 #define HANDLE_MDNODE_LEAF(CLASS) \ 2026 case Metadata::CLASS##Kind: \ 2028 write##CLASS(cast<CLASS>(N), Record, \ 2029 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \ 2031 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \ 2033 #include "llvm/IR/Metadata.def" 2036 writeValueAsMetadata(cast<ValueAsMetadata>(MD), Record);
2040 void ModuleBitcodeWriter::writeModuleMetadata() {
2049 std::vector<unsigned> MDAbbrevs;
2052 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2053 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2054 createGenericDINodeAbbrev();
2056 auto Abbv = std::make_shared<BitCodeAbbrev>();
2060 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2062 Abbv = std::make_shared<BitCodeAbbrev>();
2066 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2078 uint64_t Vals[] = {0, 0};
2088 std::vector<uint64_t> IndexPos;
2092 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2103 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2104 for (
auto &Elt : IndexPos) {
2105 auto EltDelta = Elt - PreviousValue;
2106 PreviousValue = Elt;
2115 writeNamedMetadata(Record);
2117 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2120 pushGlobalMetadataAttachment(Record, GO);
2124 if (
F.isDeclaration() &&
F.hasMetadata())
2125 AddDeclAttachedMetadata(
F);
2129 if (GV.hasMetadata())
2130 AddDeclAttachedMetadata(GV);
2135 void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2146 void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2151 for (
const auto &
I : MDs) {
2157 void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &F) {
2163 pushGlobalMetadataAttachment(Record, F);
2174 I.getAllMetadataOtherThanDebugLoc(MDs);
2177 if (MDs.
empty())
continue;
2181 for (
unsigned i = 0,
e = MDs.
size(); i !=
e; ++i) {
2192 void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2200 if (Names.
empty())
return;
2204 for (
unsigned MDKindID = 0,
e = Names.
size(); MDKindID !=
e; ++MDKindID) {
2216 void ModuleBitcodeWriter::writeOperandBundleTags() {
2233 for (
auto Tag : Tags) {
2243 void ModuleBitcodeWriter::writeSyncScopeNames() {
2252 for (
auto SSN : SSNs) {
2253 Record.
append(SSN.begin(), SSN.end());
2262 if ((int64_t)V >= 0)
2268 void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2270 if (FirstVal == LastVal)
return;
2274 unsigned AggregateAbbrev = 0;
2275 unsigned String8Abbrev = 0;
2276 unsigned CString7Abbrev = 0;
2277 unsigned CString6Abbrev = 0;
2281 auto Abbv = std::make_shared<BitCodeAbbrev>();
2285 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2288 Abbv = std::make_shared<BitCodeAbbrev>();
2292 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2294 Abbv = std::make_shared<BitCodeAbbrev>();
2298 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2300 Abbv = std::make_shared<BitCodeAbbrev>();
2304 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2310 Type *LastTy =
nullptr;
2311 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2312 const Value *V = Vals[i].first;
2318 CONSTANTS_SETTYPE_ABBREV);
2322 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2323 Record.
push_back(
unsigned(IA->hasSideEffects()) |
2324 unsigned(IA->isAlignStack()) << 1 |
2325 unsigned(IA->getDialect()&1) << 2);
2328 const std::string &AsmStr = IA->getAsmString();
2330 Record.
append(AsmStr.begin(), AsmStr.end());
2333 const std::string &ConstraintStr = IA->getConstraintString();
2335 Record.
append(ConstraintStr.begin(), ConstraintStr.end());
2341 unsigned Code = -1U;
2342 unsigned AbbrevToUse = 0;
2345 }
else if (isa<UndefValue>(C)) {
2347 }
else if (
const ConstantInt *IV = dyn_cast<ConstantInt>(C)) {
2348 if (IV->getBitWidth() <= 64) {
2349 uint64_t V = IV->getSExtValue();
2352 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2358 unsigned NWords = IV->getValue().getActiveWords();
2359 const uint64_t *RawWords = IV->getValue().getRawData();
2360 for (
unsigned i = 0; i != NWords; ++i) {
2365 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2367 Type *Ty = CFP->getType();
2369 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2373 APInt api = CFP->getValueAPF().bitcastToAPInt();
2375 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2378 APInt api = CFP->getValueAPF().bitcastToAPInt();
2383 assert(0 &&
"Unknown FP type!");
2385 }
else if (isa<ConstantDataSequential>(C) &&
2386 cast<ConstantDataSequential>(C)->isString()) {
2396 AbbrevToUse = String8Abbrev;
2400 for (
unsigned i = 0; i != NumElts; ++i) {
2403 isCStr7 &= (V & 128) == 0;
2409 AbbrevToUse = CString6Abbrev;
2411 AbbrevToUse = CString7Abbrev;
2413 dyn_cast<ConstantDataSequential>(C)) {
2415 Type *EltTy = CDS->getType()->getElementType();
2416 if (isa<IntegerType>(EltTy)) {
2417 for (
unsigned i = 0,
e = CDS->getNumElements(); i !=
e; ++i)
2418 Record.
push_back(CDS->getElementAsInteger(i));
2420 for (
unsigned i = 0,
e = CDS->getNumElements(); i !=
e; ++i)
2422 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2424 }
else if (isa<ConstantAggregate>(C)) {
2428 AbbrevToUse = AggregateAbbrev;
2429 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2430 switch (CE->getOpcode()) {
2437 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2439 assert(CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2449 case Instruction::FNeg: {
2450 assert(CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2459 case Instruction::GetElementPtr: {
2461 const auto *GO = cast<GEPOperator>(
C);
2465 Record.
push_back((*Idx << 1) | GO->isInBounds());
2466 }
else if (GO->isInBounds())
2468 for (
unsigned i = 0,
e = CE->getNumOperands(); i !=
e; ++i) {
2480 case Instruction::ExtractElement:
2487 case Instruction::InsertElement:
2494 case Instruction::ShuffleVector:
2509 case Instruction::ICmp:
2510 case Instruction::FCmp:
2518 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
2529 Stream.
EmitRecord(Code, Record, AbbrevToUse);
2536 void ModuleBitcodeWriter::writeModuleConstants() {
2541 for (
unsigned i = 0,
e = Vals.size(); i !=
e; ++i) {
2542 if (!isa<GlobalValue>(Vals[i].
first)) {
2543 writeConstants(i, Vals.size(),
true);
2557 bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2562 if (ValID >= InstID) {
2578 for (
auto &Input : Bundle.Inputs)
2579 pushValueAndType(Input, InstID, Record);
2588 void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2594 void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2597 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2602 void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2606 unsigned AbbrevToUse = 0;
2612 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2613 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2617 assert(isa<BinaryOperator>(I) &&
"Unknown instruction!");
2619 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2620 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2625 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2626 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2631 case Instruction::FNeg: {
2633 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2634 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2638 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
2639 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
2644 case Instruction::GetElementPtr: {
2646 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2647 auto &GEPInst = cast<GetElementPtrInst>(
I);
2651 pushValueAndType(I.
getOperand(i), InstID, Vals);
2654 case Instruction::ExtractValue: {
2656 pushValueAndType(I.
getOperand(0), InstID, Vals);
2658 Vals.
append(EVI->idx_begin(), EVI->idx_end());
2661 case Instruction::InsertValue: {
2663 pushValueAndType(I.
getOperand(0), InstID, Vals);
2664 pushValueAndType(I.
getOperand(1), InstID, Vals);
2666 Vals.
append(IVI->idx_begin(), IVI->idx_end());
2671 pushValueAndType(I.
getOperand(1), InstID, Vals);
2673 pushValueAndType(I.
getOperand(0), InstID, Vals);
2679 case Instruction::ExtractElement:
2681 pushValueAndType(I.
getOperand(0), InstID, Vals);
2682 pushValueAndType(I.
getOperand(1), InstID, Vals);
2684 case Instruction::InsertElement:
2686 pushValueAndType(I.
getOperand(0), InstID, Vals);
2688 pushValueAndType(I.
getOperand(2), InstID, Vals);
2690 case Instruction::ShuffleVector:
2692 pushValueAndType(I.
getOperand(0), InstID, Vals);
2696 case Instruction::ICmp:
2697 case Instruction::FCmp: {
2700 pushValueAndType(I.
getOperand(0), InstID, Vals);
2713 if (NumOperands == 0)
2714 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
2715 else if (NumOperands == 1) {
2716 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2717 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
2719 for (
unsigned i = 0,
e = NumOperands; i !=
e; ++i)
2720 pushValueAndType(I.
getOperand(i), InstID, Vals);
2724 case Instruction::Br:
2735 case Instruction::Switch:
2742 for (
auto Case : SI.
cases()) {
2748 case Instruction::IndirectBr:
2757 case Instruction::Invoke: {
2763 writeOperandBundles(II, InstID);
2772 pushValueAndType(Callee, InstID, Vals);
2782 pushValueAndType(I.
getOperand(i), InstID, Vals);
2786 case Instruction::Resume:
2788 pushValueAndType(I.
getOperand(0), InstID, Vals);
2790 case Instruction::CleanupRet: {
2792 const auto &CRI = cast<CleanupReturnInst>(
I);
2793 pushValue(CRI.getCleanupPad(), InstID, Vals);
2794 if (CRI.hasUnwindDest())
2798 case Instruction::CatchRet: {
2800 const auto &CRI = cast<CatchReturnInst>(
I);
2801 pushValue(CRI.getCatchPad(), InstID, Vals);
2805 case Instruction::CleanupPad:
2806 case Instruction::CatchPad: {
2807 const auto &FuncletPad = cast<FuncletPadInst>(
I);
2810 pushValue(FuncletPad.getParentPad(), InstID, Vals);
2812 unsigned NumArgOperands = FuncletPad.getNumArgOperands();
2814 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
2815 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
2818 case Instruction::CatchSwitch: {
2820 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
2822 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
2824 unsigned NumHandlers = CatchSwitch.getNumHandlers();
2826 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
2829 if (CatchSwitch.hasUnwindDest())
2833 case Instruction::CallBr: {
2839 writeOperandBundles(CBI, InstID);
2854 pushValueAndType(Callee, InstID, Vals);
2864 pushValueAndType(I.
getOperand(i), InstID, Vals);
2868 case Instruction::Unreachable:
2870 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
2873 case Instruction::PHI: {
2874 const PHINode &PN = cast<PHINode>(
I);
2891 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
2896 case Instruction::LandingPad: {
2907 pushValueAndType(LP.
getClause(I), InstID, Vals);
2912 case Instruction::Alloca: {
2920 "not enough bits for maximum alignment");
2921 assert(AlignRecord < 1 << 5 &&
"alignment greater than 1 << 64");
2923 AlignRecord |= 1 << 6;
2930 if (cast<LoadInst>(I).
isAtomic()) {
2932 pushValueAndType(I.
getOperand(0), InstID, Vals);
2935 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2936 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
2941 if (cast<LoadInst>(I).
isAtomic()) {
2943 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
2951 pushValueAndType(I.
getOperand(1), InstID, Vals);
2952 pushValueAndType(I.
getOperand(0), InstID, Vals);
2955 if (cast<StoreInst>(I).
isAtomic()) {
2958 getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
2961 case Instruction::AtomicCmpXchg:
2963 pushValueAndType(I.
getOperand(0), InstID, Vals);
2964 pushValueAndType(I.
getOperand(1), InstID, Vals);
2970 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
2973 Vals.
push_back(cast<AtomicCmpXchgInst>(I).isWeak());
2975 case Instruction::AtomicRMW:
2977 pushValueAndType(I.
getOperand(0), InstID, Vals);
2984 getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
2986 case Instruction::Fence:
2989 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
2996 writeOperandBundles(&CI, InstID);
3016 for (
unsigned i = 0,
e = FTy->getNumParams(); i !=
e; ++i) {
3018 if (FTy->getParamType(i)->isLabelTy())
3025 if (FTy->isVarArg()) {
3032 case Instruction::VAArg:
3038 case Instruction::Freeze:
3040 pushValueAndType(I.
getOperand(0), InstID, Vals);
3050 void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
3056 VSTOffset -= bitcodeStartBit();
3057 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
3061 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
3065 auto Abbv = std::make_shared<BitCodeAbbrev>();
3069 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3081 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
3082 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
3086 Record[1] = BitcodeIndex / 32 + 1;
3095 void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3110 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3116 if (isa<BasicBlock>(
Name.getValue())) {
3119 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3123 AbbrevToUse = VST_ENTRY_6_ABBREV;
3125 AbbrevToUse = VST_ENTRY_7_ABBREV;
3128 for (
const auto P :
Name.getKey())
3132 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3139 void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3140 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3142 if (isa<BasicBlock>(Order.V))
3152 void ModuleBitcodeWriter::writeUseListBlock(
const Function *F) {
3154 "Expected to be preserving use-list order");
3156 auto hasMore = [&]() {
3172 void ModuleBitcodeWriter::writeFunction(
3191 unsigned CstStart, CstEnd;
3193 writeConstants(CstStart, CstEnd,
false);
3196 writeFunctionMetadata(F);
3199 unsigned InstID = CstEnd;
3208 writeInstruction(*I, InstID, Vals);
3240 writeFunctionLevelValueSymbolTable(*Symtab);
3242 if (NeedsMetadataAttachment)
3243 writeFunctionMetadataAttachment(F);
3245 writeUseListBlock(&F);
3251 void ModuleBitcodeWriter::writeBlockInfo() {
3258 auto Abbv = std::make_shared<BitCodeAbbrev>();
3269 auto Abbv = std::make_shared<BitCodeAbbrev>();
3279 auto Abbv = std::make_shared<BitCodeAbbrev>();
3289 auto Abbv = std::make_shared<BitCodeAbbrev>();
3295 VST_BBENTRY_6_ABBREV)
3300 auto Abbv = std::make_shared<BitCodeAbbrev>();
3305 CONSTANTS_SETTYPE_ABBREV)
3310 auto Abbv = std::make_shared<BitCodeAbbrev>();
3314 CONSTANTS_INTEGER_ABBREV)
3319 auto Abbv = std::make_shared<BitCodeAbbrev>();
3327 CONSTANTS_CE_CAST_Abbrev)
3331 auto Abbv = std::make_shared<BitCodeAbbrev>();
3334 CONSTANTS_NULL_Abbrev)
3341 auto Abbv = std::make_shared<BitCodeAbbrev>();
3349 FUNCTION_INST_LOAD_ABBREV)
3353 auto Abbv = std::make_shared<BitCodeAbbrev>();
3358 FUNCTION_INST_UNOP_ABBREV)
3362 auto Abbv = std::make_shared<BitCodeAbbrev>();
3368 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3372 auto Abbv = std::make_shared<BitCodeAbbrev>();
3378 FUNCTION_INST_BINOP_ABBREV)
3382 auto Abbv = std::make_shared<BitCodeAbbrev>();
3389 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3393 auto Abbv = std::make_shared<BitCodeAbbrev>();
3400 FUNCTION_INST_CAST_ABBREV)
3405 auto Abbv = std::make_shared<BitCodeAbbrev>();
3408 FUNCTION_INST_RET_VOID_ABBREV)
3412 auto Abbv = std::make_shared<BitCodeAbbrev>();
3416 FUNCTION_INST_RET_VAL_ABBREV)
3420 auto Abbv = std::make_shared<BitCodeAbbrev>();
3423 FUNCTION_INST_UNREACHABLE_ABBREV)
3427 auto Abbv = std::make_shared<BitCodeAbbrev>();
3435 FUNCTION_INST_GEP_ABBREV)
3444 void IndexBitcodeWriter::writeModStrings() {
3450 auto Abbv = std::make_shared<BitCodeAbbrev>();
3455 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3458 Abbv = std::make_shared<BitCodeAbbrev>();
3463 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3466 Abbv = std::make_shared<BitCodeAbbrev>();
3471 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3474 Abbv = std::make_shared<BitCodeAbbrev>();
3481 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3485 [&](
const StringMapEntry<std::pair<uint64_t, ModuleHash>> &MPSE) {
3487 const auto &
Value = MPSE.getValue();
3489 unsigned AbbrevToUse = Abbrev8Bit;
3491 AbbrevToUse = Abbrev6Bit;
3493 AbbrevToUse = Abbrev7Bit;
3502 const auto &Hash =
Value.second;
3504 Vals.
assign(Hash.begin(), Hash.end());
3523 auto WriteVFuncIdVec = [&](uint64_t Ty,
3528 for (
auto &VF : VFs) {
3540 auto WriteConstVCallVec = [&](uint64_t Ty,
3542 for (
auto &
VC : VCs) {
3546 Record.
insert(Record.
end(),
VC.Args.begin(),
VC.Args.end());
3560 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
3563 ReferencedTypeIds.insert(
TT);
3565 auto GetReferencedTypesFromVFuncIdVec =
3567 for (
auto &VF : VFs)
3568 ReferencedTypeIds.insert(VF.GUID);
3574 auto GetReferencedTypesFromConstVCallVec =
3576 for (
auto &
VC : VCs)
3577 ReferencedTypeIds.insert(
VC.VFunc.GUID);
3588 NameVals.
insert(NameVals.
end(), args.begin(), args.end());
3612 const std::string &
Id,
3624 for (
auto &
W : Summary.
WPDRes)
3636 for (
auto &
P : Summary) {
3643 void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
3645 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
3657 NameVals.
push_back(SpecialRefCnts.first);
3658 NameVals.
push_back(SpecialRefCnts.second);
3660 for (
auto &RI : FS->
refs())
3663 bool HasProfileData =
3665 for (
auto &ECI : FS->
calls()) {
3666 NameVals.
push_back(getValueId(ECI.first));
3668 NameVals.
push_back(static_cast<uint8_t>(ECI.second.Hotness));
3670 NameVals.
push_back(ECI.second.RelBlockFreq);
3673 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3686 void ModuleBitcodeWriterBase::writeModuleLevelReferences(
3688 unsigned FSModRefsAbbrev,
unsigned FSModVTableRefsAbbrev) {
3689 auto VI = Index->getValueInfo(V.
getGUID());
3703 if (!VTableFuncs.empty())
3706 unsigned SizeBeforeRefs = NameVals.
size();
3707 for (
auto &RI : VS->
refs())
3713 if (VTableFuncs.empty())
3718 for (
auto &
P : VTableFuncs) {
3724 FSModVTableRefsAbbrev);
3731 void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
3734 bool IsThinLTO =
true;
3736 mdconst::extract_or_null<ConstantInt>(M.
getModuleFlag(
"ThinLTO")))
3737 IsThinLTO = MD->getZExtValue();
3749 if (Index->enableSplitLTOUnit())
3753 if (Index->begin() == Index->end()) {
3758 for (
const auto &GVI : valueIds()) {
3764 auto Abbv = std::make_shared<BitCodeAbbrev>();
3776 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3779 Abbv = std::make_shared<BitCodeAbbrev>();
3794 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3797 Abbv = std::make_shared<BitCodeAbbrev>();
3803 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3806 Abbv = std::make_shared<BitCodeAbbrev>();
3814 unsigned FSModVTableRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3817 Abbv = std::make_shared<BitCodeAbbrev>();
3822 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3825 Abbv = std::make_shared<BitCodeAbbrev>();
3832 unsigned TypeIdCompatibleVtableAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3851 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&F),
3852 FSCallsAbbrev, FSCallsProfileAbbrev,
F);
3858 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev,
3859 FSModVTableRefsAbbrev);
3862 auto *Aliasee = A.getBaseObject();
3863 if (!Aliasee->hasName())
3869 auto *Summary = Index->getGlobalValueSummary(A);
3877 for (
auto &S : Index->typeIdCompatibleVtableMap()) {
3881 TypeIdCompatibleVtableAbbrev);
3889 void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
3897 if (Index.withGlobalValueDeadStripping())
3899 if (Index.skipModuleByDistributedBackend())
3901 if (Index.hasSyntheticEntryCounts())
3903 if (Index.enableSplitLTOUnit())
3905 if (Index.partiallySplitLTOUnits())
3907 if (Index.withAttributePropagation())
3911 for (
const auto &GVI : valueIds()) {
3917 auto Abbv = std::make_shared<BitCodeAbbrev>();
3931 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3934 Abbv = std::make_shared<BitCodeAbbrev>();
3948 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3951 Abbv = std::make_shared<BitCodeAbbrev>();
3958 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3961 Abbv = std::make_shared<BitCodeAbbrev>();
3967 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3980 std::set<GlobalValue::GUID> ReferencedTypeIds;
3987 NameVals.
push_back(S.getOriginalName());
3992 std::set<GlobalValue::GUID> DefOrUseGUIDs;
3993 forEachSummary([&](GVInfo I,
bool IsAliasee) {
3996 DefOrUseGUIDs.insert(I.first);
3998 DefOrUseGUIDs.insert(VI.
getGUID());
4000 auto ValueId = getValueId(I.first);
4002 SummaryToValueIdMap[S] = *ValueId;
4010 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
4017 if (
auto *
VS = dyn_cast<GlobalVarSummary>(S)) {
4019 NameVals.
push_back(Index.getModuleId(
VS->modulePath()));
4022 for (
auto &RI :
VS->refs()) {
4023 auto RefValueId = getValueId(RI.getGUID());
4033 MaybeEmitOriginalName(*S);
4037 auto *
FS = cast<FunctionSummary>(S);
4042 NameVals.
push_back(Index.getModuleId(
FS->modulePath()));
4053 unsigned Count = 0, RORefCnt = 0, WORefCnt = 0;
4054 for (
auto &RI :
FS->refs()) {
4055 auto RefValueId = getValueId(RI.getGUID());
4059 if (RI.isReadOnly())
4061 else if (RI.isWriteOnly())
4065 NameVals[6] = Count;
4066 NameVals[7] = RORefCnt;
4067 NameVals[8] = WORefCnt;
4069 bool HasProfileData =
false;
4070 for (
auto &EI :
FS->calls()) {
4077 for (
auto &EI :
FS->calls()) {
4081 auto CallValueId = getValueId(GUID);
4086 GUID = Index.getGUIDFromOriginalID(GUID);
4089 CallValueId = getValueId(GUID);
4102 auto *GVSum = Index.getGlobalValueSummary(GUID,
false);
4109 NameVals.
push_back(static_cast<uint8_t>(EI.second.Hotness));
4112 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
4119 MaybeEmitOriginalName(*S);
4122 for (
auto *AS : Aliases) {
4123 auto AliasValueId = SummaryToValueIdMap[AS];
4126 NameVals.
push_back(Index.getModuleId(AS->modulePath()));
4128 auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
4135 MaybeEmitOriginalName(*AS);
4137 if (
auto *
FS = dyn_cast<FunctionSummary>(&AS->getAliasee()))
4141 if (!Index.cfiFunctionDefs().empty()) {
4142 for (
auto &S : Index.cfiFunctionDefs()) {
4143 if (DefOrUseGUIDs.count(
4149 if (!NameVals.
empty()) {
4155 if (!Index.cfiFunctionDecls().empty()) {
4156 for (
auto &S : Index.cfiFunctionDecls()) {
4157 if (DefOrUseGUIDs.count(
4163 if (!NameVals.
empty()) {
4171 for (
auto &
T : ReferencedTypeIds) {
4172 auto TidIter = Index.typeIds().equal_range(
T);
4173 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4190 auto Abbv = std::make_shared<BitCodeAbbrev>();
4194 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4196 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4199 Abbv = std::make_shared<BitCodeAbbrev>();
4202 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4208 void ModuleBitcodeWriter::writeModuleHash(
size_t BlockStartPos) {
4214 Buffer.size() - BlockStartPos));
4216 for (
int Pos = 0; Pos < 20; Pos += 4) {
4233 size_t BlockStartPos = Buffer.size();
4235 writeModuleVersion();
4244 writeAttributeGroupTable();
4247 writeAttributeTable();
4256 writeModuleConstants();
4259 writeModuleMetadataKinds();
4262 writeModuleMetadata();
4266 writeUseListBlock(
nullptr);
4268 writeOperandBundleTags();
4269 writeSyncScopeNames();
4275 writeFunction(*F, FunctionToBitcodeIndex);
4280 writePerModuleGlobalValueSummary();
4282 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4284 writeModuleHash(BlockStartPos);
4317 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4318 DARWIN_CPU_TYPE_X86 = 7,
4319 DARWIN_CPU_TYPE_ARM = 12,
4320 DARWIN_CPU_TYPE_POWERPC = 18
4325 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4327 CPUType = DARWIN_CPU_TYPE_X86;
4329 CPUType = DARWIN_CPU_TYPE_POWERPC;
4331 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4333 CPUType = DARWIN_CPU_TYPE_ARM;
4337 "Expected header size to be reserved");
4350 while (Buffer.
size() & 15)
4357 Stream.
Emit((
unsigned)
'B', 8);
4358 Stream.
Emit((
unsigned)
'C', 8);
4359 Stream.
Emit(0x0, 4);
4360 Stream.
Emit(0xC, 4);
4361 Stream.
Emit(0xE, 4);
4362 Stream.
Emit(0xD, 4);
4372 void BitcodeWriter::writeBlob(
unsigned Block,
unsigned Record,
StringRef Blob) {
4375 auto Abbv = std::make_shared<BitCodeAbbrev>();
4378 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
4386 assert(!WroteStrtab && !WroteSymtab);
4398 if (!T || !T->hasMCAsmParser())
4420 std::vector<char> Strtab;
4422 Strtab.resize(StrtabBuilder.
getSize());
4423 StrtabBuilder.
write((uint8_t *)Strtab.data());
4426 {Strtab.data(), Strtab.size()});
4437 bool ShouldPreserveUseListOrder,
4447 Mods.push_back(const_cast<Module *>(&M));
4449 ModuleBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream,
4450 ShouldPreserveUseListOrder, Index,
4451 GenerateHash, ModHash);
4452 ModuleWriter.write();
4457 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
4458 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index,
4459 ModuleToSummariesForIndex);
4460 IndexWriter.write();
4465 bool ShouldPreserveUseListOrder,
4474 if (
TT.isOSDarwin() ||
TT.isOSBinFormatMachO())
4478 Writer.
writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
4483 if (
TT.isOSDarwin() ||
TT.isOSBinFormatMachO())
4493 writeModuleVersion();
4499 writeCombinedGlobalValueSummary();
4510 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
4515 Writer.
writeIndex(&Index, ModuleToSummariesForIndex);
4524 class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
4534 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
4536 ModHash(&ModHash) {}
4541 void writeSimplifiedModuleInfo();
4551 void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
4563 auto Abbv = std::make_shared<BitCodeAbbrev>();
4566 Abbv->Add(AbbrevOpToUse);
4567 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4636 writeModuleVersion();
4638 writeSimplifiedModuleInfo();
4640 writePerModuleGlobalValueSummary();
4658 Mods.push_back(const_cast<Module *>(&M));
4660 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
4662 ThinLinkWriter.write();
4685 return "__LLVM,__bitcode";
4701 return "__LLVM,__cmdline";
4715 bool EmbedBitcode,
bool EmbedMarker,
4716 const std::vector<uint8_t> *CmdArgs) {
4722 for (
auto *GV : UsedGlobals) {
4723 if (GV->getName() !=
"llvm.embedded.module" &&
4724 GV->getName() !=
"llvm.cmdline")
4762 assert(Old->hasOneUse() &&
4763 "llvm.embedded.module can only be used once in llvm.compiler.used");
4765 Old->eraseFromParent();
4767 GV->setName(
"llvm.embedded.module");
4784 assert(Old->hasOneUse() &&
4785 "llvm.cmdline can only be used once in llvm.compiler.used");
4787 Old->eraseFromParent();
4789 GV->setName(
"llvm.cmdline");
4793 if (UsedArray.
empty())
4801 NewUsed->setSection(
"llvm.metadata");
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
MDString * getRawName() const
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
void writeIndex(const ModuleSummaryIndex *Index, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
ThreadLocalMode getThreadLocalMode() const
ArrayRef< uint64_t > getElements() const
This class provides a symbol table of name/value pairs.
uint64_t getOffsetInBits() const
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
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"))
Special purpose, only applies to global arrays.
*p = old <signed v ? old : v
iterator_range< CaseIt > cases()
Iteration adapter for range-for loops.
bool isDefinition() const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static void writeDIBasicType(raw_ostream &Out, const DIBasicType *N, TypePrinting *, SlotTracker *, const Module *)
static uint64_t getOptimizationFlags(const Value *V)
unsigned getMetadataOrNullID(const Metadata *MD) const
Atomic ordering constants.
unsigned getValueID(const Value *V) const
const ValueList & getValues() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags)
Type * getParamType(unsigned i) const
Parameter type accessors.
const unsigned char * bytes_end() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
unsigned getRuntimeVersion() const
unsigned Linkage
The linkage type of the associated global value.
const char * getBufferEnd() const
bool hasMetadataOtherThanDebugLoc() const
Return true if this instruction has metadata attached to it other than a debug location.
MDString * getRawName() const
A Module instance is used to store all the information related to an LLVM module. ...
static void getReferencedTypeIds(FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Collect type IDs from type tests used by function.
2: 32-bit floating point type
MDString * getRawName() const
Same, but only replaced by something equivalent.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
const GlobalValue * getValue() const
ArrayRef< VFuncId > type_test_assume_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics that do not have all constant integer arguments.
Metadata * getRawFile() const
Global variable summary information to aid decisions and implementation of importing.
static unsigned getEncodedThreadLocalMode(const GlobalValue &GV)
std::pair< unsigned, AttributeSet > IndexAndAttrSet
Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...
Available for inspection, not emission.
void push_back(const T &Elt)
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
unsigned getDiscriminator() const
bool isFP128Ty() const
Return true if this is 'fp128'.
MDString * getRawValue() const
This class represents a function call, abstracting a target machine's calling convention.
void setInstructionID(const Instruction *I)
Value * getCondition() const
The two locations do not alias at all.
bool shouldPreserveUseListOrder() const
*p = old <unsigned v ? old : v
void writeSymtab()
Attempt to write a symbol table to the bitcode file.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
uint64_t Info
Additional information for the resolution:
Like Internal, but omit from symbol table.
*p = old >unsigned v ? old : v
Externally visible function.
LLVMContext & getContext() const
All values hold a context through their type.
The data referenced by the COMDAT must be the same size.
DICompositeTypeArray getEnumTypes() const
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
static void writeDIMacroFile(raw_ostream &Out, const DIMacroFile *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
uint64_t getDWOId() const
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
BasicBlock * getSuccessor(unsigned i) const
void write32le(void *P, uint32_t V)
uint64_t GetCurrentBitNo() const
Retrieve the current position in the stream, in bits.
4: 80-bit floating point type (X87)
const MDOperand & getOperand(unsigned I) const
A class that wrap the SHA1 algorithm.
1: 16-bit floating point type
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
Value * getCondition() const
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
unsigned index_end() const
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
static void writeDILocation(raw_ostream &Out, const DILocation *DL, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static void writeDITemplateTypeParameter(raw_ostream &Out, const DITemplateTypeParameter *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
Appends all attachments for the global to MDs, sorting by attachment ID.
void reserve(size_type N)
bool hasMDs() const
Check whether the current block has any metadata to emit.
bool isMustTailCall() const
bool getDebugInfoForProfiling() const
static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
unsigned getAttributeGroupID(IndexAndAttrSet Group) const
*p = old >signed v ? old : v
static unsigned getEncodedRMWOperation(AtomicRMWInst::BinOp Op)
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
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...
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
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 bool isLocalLinkage(LinkageTypes Linkage)
DINodeArray getElements() const
MDString * getRawName() const
unsigned getMetadataID(const Metadata *MD) const
void incorporateFunction(const Function &F)
incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...
Value * getArgOperand(unsigned i) const
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.
void dump() const
Support for debugging, callable in GDB: V->dump()
static const char * getSectionNameForBitcode(const Triple &T)
The address of a basic block.
static void writeWholeProgramDevirtResolutionByArg(SmallVector< uint64_t, 64 > &NameVals, const std::vector< uint64_t > &args, const WholeProgramDevirtResolution::ByArg &ByArg)
DIScope * getScope() const
static uint32_t getAlignment(const MCSectionCOFF &Sec)
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
GlobalValue::GUID getGUID() const
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version...
static void writeTypeIdCompatibleVtableSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdCompatibleVtableInfo &Summary, ValueEnumerator &VE)
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
uint32_t read32be(const void *P)
TypeID getTypeID() const
Return the type id for the type.
bool isResolved() const
Check if node is fully resolved.
DIGlobalVariable * getVariable() const
Class to represent struct types.
void BackpatchWord(uint64_t BitNo, unsigned NewWord)
Backpatch a 32-bit word in the output at the given bit offset with the specified value.
LLVMContext & getContext() const
Get the global data context.
MDString * getRawSetterName() const
const TypeList & getTypes() const
UnnamedAddr getUnnamedAddr() const
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
static unsigned getEncodedBinaryOpcode(unsigned Opcode)
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
void Emit(uint32_t Val, unsigned NumBits)
void EnterBlockInfoBlock()
EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
The linker may choose any COMDAT.
uint64_t computeBitsRequiredForTypeIndicies() const
uint64_t getSizeInBits() const
static void writeGenericDINode(raw_ostream &Out, const GenericDINode *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
static const unsigned MaximumAlignment
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Position
Position to insert a new instruction relative to an existing instruction.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
static uint64_t getEncodedGVarFlags(GlobalVarSummary::GVarFlags Flags)
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...
This file implements a class to represent arbitrary precision integral constant values and operations...
ArrayRef< GlobalValue::GUID > type_tests() const
Returns the list of type identifiers used by this function in llvm.type.test intrinsics other than by...
static void writeDIGlobalVariableExpression(raw_ostream &Out, const DIGlobalVariableExpression *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
AtomicOrdering
Atomic ordering for LLVM's memory model.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
static Optional< DebugNameTableKind > getNameTableKind(StringRef Str)
void assign(size_type NumElts, const T &Elt)
bool getExportSymbols() const
InstrTy * getInstruction() const
static void writeDIFile(raw_ostream &Out, const DIFile *N, TypePrinting *, SlotTracker *, const Module *)
ArrayRef< ConstVCall > type_checked_load_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics with ...
bool isLocalToUnit() const
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static const char * getSectionNameForCommandline(const Triple &T)
A constant value that is initialized with an expression using other constant values.
Class to represent function types.
void write(raw_ostream &OS) const
Utility for building string tables with deduplicated suffixes.
DIType * getBaseType() const
Type * getType() const
All values are typed, get the type of this value.
DIScope * getScope() const
static unsigned getEncodedUnaryOpcode(unsigned Opcode)
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
ArrayRef< VFuncId > type_checked_load_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics that ...
op_range operands() const
unsigned getRuntimeLang() const
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
BinOp
This enumeration lists the possible modifications atomicrmw can make.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
size_t add(CachedHashStringRef S)
Add a string to the builder.
MDString * getRawName() const
Class to represent array types.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
DIMacroNodeArray getElements() const
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS)
Write the function type metadata related records that need to appear before a function summary entry ...
LLVM_NODISCARD size_t size() const
size - Get the string size.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
uint32_t getAlignInBits() const
ArrayRef< const Metadata * > getMDStrings() const
Get the MDString metadata for this block.
LinkageTypes getLinkage() const
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 ...
static constexpr uint64_t BitcodeSummaryVersion
static void writeDINamespace(raw_ostream &Out, const DINamespace *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Structure to hold a use-list order.
Type::subtype_iterator element_iterator
Class to hold module path string table and global value map, and encapsulate methods for operating on...
DIScope * getScope() const
static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
Value * getOperand(unsigned i) const
Class to represent pointers.
const std::string & getSourceFileName() const
Get the module's original source file name.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
void append(in_iter S, in_iter E)
Append from an iterator pair.
11: Arbitrary bit width integers
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
DIScope * getScope() const
DIMacroNodeArray getMacros() const
bool isVoidTy() const
Return true if this is 'void'.
void BackpatchWord64(uint64_t BitNo, uint64_t Val)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
ExternalWeak linkage description.
Metadata * getValue() const
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.
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
DITemplateParameterArray getTemplateParams() const
Same, but only replaced by something equivalent.
initializer< Ty > init(const Ty &Val)
No other Module may specify this COMDAT.
std::vector< Type * > TypeList
unsigned getColumn() const
unsigned getNumIndirectDests() const
Return the number of callbr indirect dest labels.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
BitcodeWriter(SmallVectorImpl< char > &Buffer)
Create a BitcodeWriter that writes to Buffer.
DLLStorageClassTypes getDLLStorageClass() const
FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold
VisibilityTypes getVisibility() const
size_t getBufferSize() const
Value * getCalledValue() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
void finalizeInOrder()
Finalize the string table without reording it.
static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind)
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
unsigned getInstructionID(const Instruction *I) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
unsigned instCount() const
Get the instruction count recorded for this function.
void getSyncScopeNames(SmallVectorImpl< StringRef > &SSNs) const
getSyncScopeNames - Populates client supplied SmallVector with synchronization scope names registered...
FunctionType * getFunctionType() const
static unsigned getEncodedDLLStorageClass(const GlobalValue &GV)
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
ConstantFP - Floating Point Values [float, double].
unsigned getAttributes() const
static void writeDIModule(raw_ostream &Out, const DIModule *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
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.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
DIExpression * getExpression() const
BasicBlock * getDefaultDest() const
element_iterator element_end() const
iterator_range< named_metadata_iterator > named_metadata()
A pair of DIGlobalVariable and DIExpression.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
unsigned getGlobalBasicBlockID(const BasicBlock *BB) const
getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
DIImportedEntityArray getImportedEntities() const
MDTuple * getTemplateParams() const
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
DIDerivedType * getStaticDataMemberDeclaration() const
StringRef getName() const
Return the name for this struct type if it has an identity.
6: 128-bit floating point type (two 64-bits, PowerPC)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
const std::vector< AttributeList > & getAttributeLists() const
ArrayRef< const Metadata * > getNonMDStrings() const
Get the non-MDString metadata for this block.
void getFunctionConstantRange(unsigned &Start, unsigned &End) const
getFunctionConstantRange - Return the range of values that corresponds to function-local constants...
static void writeDICommonBlock(raw_ostream &Out, const DICommonBlock *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
The data referenced by the COMDAT must be the same.
static unsigned getEncodedCastOpcode(unsigned Opcode)
Sentinal value useful for loops.
static cl::opt< bool > WriteRelBFToSummary("write-relbf-to-summary", cl::Hidden, cl::init(false), cl::desc("Write relative block frequency to function summary "))
Function and variable summary information to aid decisions and implementation of importing.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
std::vector< std::pair< const Value *, unsigned > > ValueList
static unsigned getEncodedComdatSelectionKind(const Comdat &C)
void EmitVBR(uint32_t Val, unsigned NumBits)
static void writeDILexicalBlockFile(raw_ostream &Out, const DILexicalBlockFile *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
DIScope * getScope() const
static void write(bool isBE, void *P, T V)
void consumeError(Error Err)
Consume a Error without doing anything.
element_iterator elements_end() const
static bool isAtomic(Instruction *I)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static uint64_t rotateSign(int64_t I)
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
MDString * getRawName() const
MDString * getRawName() const
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static void writeDILabel(raw_ostream &Out, const DILabel *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static void writeDIMacro(raw_ostream &Out, const DIMacro *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags)
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
Triple - Helper class for working with autoconf configuration names.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
An imported module (C++ using directive or similar).
raw_ostream & write(unsigned char C)
void sort(IteratorTy Start, IteratorTy End)
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics with all constant integer arguments.
Struct that holds a reference to a particular GUID in a global value summary.
MDString * getRawName() const
const ComdatSetType & getComdats() const
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
BasicBlock * getNormalDest() const
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
static void emitSignedInt64(SmallVectorImpl< uint64_t > &Vals, uint64_t V)
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallPtrSetImpl< GlobalValue *> &Set, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
static void writeDIObjCProperty(raw_ostream &Out, const DIObjCProperty *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool isScalable() const
Returns whether or not this is a scalable vector (meaning the total element count is a multiple of th...
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
Align max(MaybeAlign Lhs, Align Rhs)
16: SIMD 'packed' format, or other vector type
static Optional< DebugEmissionKind > getEmissionKind(StringRef Str)
static void writeStringRecord(BitstreamWriter &Stream, unsigned Code, StringRef Str, unsigned AbbrevToUse)
static void writeDITemplateValueParameter(raw_ostream &Out, const DITemplateValueParameter *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
Keep one copy of function when linking (inline)
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
static void writeInt32ToBuffer(uint32_t Value, SmallVectorImpl< char > &Buffer, uint32_t &Position)
Module.h This file contains the declarations for the Module class.
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, either with or without a wrapper.
unsigned getNumOperandBundles() const
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
BasicBlock * getIndirectDest(unsigned i) const
static void writeMDTuple(raw_ostream &Out, const MDTuple *Node, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static void writeDIEnumerator(raw_ostream &Out, const DIEnumerator *N, TypePrinting *, SlotTracker *, const Module *)
DIScope * getScope() const
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
Type * getReturnType() const
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...
Alias summary information.
bool isConditional() const
The linker will choose the largest COMDAT.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
ArrayRef< VirtFuncOffset > vTableFuncs() const
AttributeList getAttributes() const
Return the parameter attributes for this call.
std::string SingleImplName
enum llvm::TypeTestResolution::Kind TheKind
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
unsigned getSourceLanguage() const
unsigned getTypeID(Type *T) const
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
Class to represent vector types.
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1', drop it.
DIType * getVTableHolder() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out, const std::map< std::string, GVSummaryMapTy > *ModuleToSummariesForIndex=nullptr)
Write the specified module summary index to the given raw output stream, where it will be written in ...
amdgpu Simplify well known AMD library false FunctionCallee Callee
A (clang) module that has been imported by the compile unit.
static void writeDISubrange(raw_ostream &Out, const DISubrange *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
static unsigned getEncodedOrdering(AtomicOrdering Ordering)
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
void EmbedBitcodeInModule(Module &M, MemoryBufferRef Buf, bool EmbedBitcode, bool EmbedMarker, const std::vector< uint8_t > *CmdArgs)
Save a copy of the llvm IR as data in the __LLVM,__bitcode section.
DIGlobalVariableExpressionArray getGlobalVariables() const
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
UseListOrderStack UseListOrders
static unsigned getEncodedUnnamedAddr(const GlobalValue &GV)
Generic tagged DWARF-like metadata node.
iterator insert(iterator I, T &&Elt)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
element_iterator element_begin() const
bool isX86_FP80Ty() const
Return true if this is x86 long double.
FFlags fflags() const
Get function summary flags.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
MDString * getRawName() const
Type array for a subprogram.
bool isMaterialized() const
const std::vector< IndexAndAttrSet > & getAttributeGroups() const
Function to be accessible from DLL.
BasicBlock * getDefaultDest() const
bool getSplitDebugInlining() const
MDString * getRawIdentifier() const
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
unsigned getNumArgOperands() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
ValID - Represents a reference of a definition of some sort with no type.
const unsigned char * bytes_begin() const
unsigned getEncoding() const
pointer data()
Return a pointer to the vector's buffer, even if empty().
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
Linkage
Describes symbol linkage.
LLVM_NODISCARD bool empty() const
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
MDString * getRawSplitDebugFilename() const
void copyStrtab(StringRef Strtab)
Copy the string table for another module into this bitcode file.
static void writeDIExpression(raw_ostream &Out, const DIExpression *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit...
CallingConv::ID getCallingConv() const
DIGlobalVariable * getDecl() const
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
const std::vector< const BasicBlock * > & getBasicBlocks() const
bool isCatch(unsigned Idx) const
Return 'true' if the clause and index Idx is a catch clause.
MDString * getRawProducer() const
MDString * getRawName() const
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
element_iterator elements_begin() const
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
unsigned getMacinfoType() const
Flags specific to function summaries.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
Function summary information to aid decisions and implementation of importing.
Function to be imported from DLL.
MDString * getRawLinkageName() const
static void writeTypeIdSummaryRecord(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, const std::string &Id, const TypeIdSummary &Summary)
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
DIScopeArray getRetainedTypes() const
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
3: 64-bit floating point type
DILocalScope * getScope() const
Get the local scope for this label.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint32_t getAlignInBits() const
const char * getBufferStart() const
bool hasAttributes() const
Return true if attributes exists in this set.
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
A raw_ostream that writes to an std::string.
DINode * getEntity() const
BasicBlock * getUnwindDest() const
LLVM Value Representation.
bool hasMetadata() const
Check if this has any metadata.
Lightweight error class with error context and mandatory checking.
GVarFlags varflags() const
bool named_metadata_empty() const
DITypeRefArray getTypeArray() const
DIDerivedType * getDiscriminator() const
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This class implements an extremely fast bulk output stream that can only output to a stream...
Type * getElementType() const
iterator_range< global_iterator > globals()
unsigned getLineNo() const
bool isNoTailCall() const
StringRef - Represent a constant reference to a string, i.e.
DILocalScope * getScope() const
OperandBundleUse getOperandBundleAt(unsigned Index) const
unsigned getNumElements() const
Return the number of elements in the array or vector.
static bool isVolatile(Instruction *Inst)
9: MMX vectors (64 bits, X86 specific)
unsigned getComdatID(const Comdat *C) const
unsigned getAttributeListID(AttributeList PAL) const
void writeStrtab()
Write the bitcode file's string table.
DILocalScope * getScope() const
Get the local scope for this variable.
unsigned getNumOperands() const
Return number of MDNode operands.
OutputIt copy(R &&Range, OutputIt Out)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
unsigned ReturnDoesNotAlias
std::pair< unsigned, unsigned > specialRefCounts() const
MDString * getRawGetterName() const
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
Change the section for this global.
Type * getElementType() const
static void writeDIImportedEntity(raw_ostream &Out, const DIImportedEntity *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
bool empty() const
empty - Check if the array is empty.
MDString * getRawFlags() const
unsigned index_begin() const
Use these to iterate over the valid attribute indices.
static void writeDILexicalBlock(raw_ostream &Out, const DILexicalBlock *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
uint32_t getOperandBundleTagID(StringRef Tag) const
getOperandBundleTagID - Maps a bundle tag to an integer ID.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr< BitCodeAbbrev > Abbv)
EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified BlockID.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
5: 128-bit floating point type (112-bit mantissa)
Basic type, like 'int' or 'float'.
static unsigned getEncodedVisibility(const GlobalValue &GV)
SelectionKind getSelectionKind() const