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_BINOP_ABBREV,
116 FUNCTION_INST_BINOP_FLAGS_ABBREV,
117 FUNCTION_INST_CAST_ABBREV,
118 FUNCTION_INST_RET_VOID_ABBREV,
119 FUNCTION_INST_RET_VAL_ABBREV,
120 FUNCTION_INST_UNREACHABLE_ABBREV,
121 FUNCTION_INST_GEP_ABBREV,
126 class BitcodeWriterBase {
137 : Stream(Stream), StrtabBuilder(StrtabBuilder) {}
141 void writeModuleVersion();
144 void BitcodeWriterBase::writeModuleVersion() {
151 class ModuleBitcodeWriterBase :
public BitcodeWriterBase {
165 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
168 unsigned GlobalValueId;
172 uint64_t VSTOffsetPlaceholder = 0;
179 bool ShouldPreserveUseListOrder,
181 : BitcodeWriterBase(Stream, StrtabBuilder), M(M),
182 VE(M, ShouldPreserveUseListOrder), Index(Index) {
191 for (
const auto &GUIDSummaryLists : *Index)
193 for (
auto &Summary : GUIDSummaryLists.second.SummaryList)
194 if (
auto FS = dyn_cast<FunctionSummary>(Summary.get()))
199 for (
auto &CallEdge : FS->calls())
200 if (!CallEdge.first.haveGVs() || !CallEdge.first.getValue())
201 assignValueId(CallEdge.first.getGUID());
205 void writePerModuleGlobalValueSummary();
211 unsigned FSCallsAbbrev,
212 unsigned FSCallsProfileAbbrev,
216 unsigned FSModRefsAbbrev);
219 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
223 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
226 assert(VMI != GUIDToValueIdMap.end() &&
227 "GUID does not have assigned value Id");
234 return getValueId(VI.
getGUID());
238 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
242 class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
256 uint64_t BitcodeStartBit;
266 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
267 ShouldPreserveUseListOrder, Index),
268 Buffer(Buffer), GenerateHash(GenerateHash), ModHash(ModHash),
269 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
275 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
279 void writeAttributeGroupTable();
280 void writeAttributeTable();
281 void writeTypeTable();
283 void writeValueSymbolTableForwardDecl();
284 void writeModuleInfo();
289 unsigned createDILocationAbbrev();
292 unsigned createGenericDINodeAbbrev();
350 unsigned createNamedMetadataAbbrev();
352 unsigned createMetadataStringsAbbrev();
357 std::vector<unsigned> *MDAbbrevs =
nullptr,
358 std::vector<uint64_t> *IndexPos =
nullptr);
359 void writeModuleMetadata();
360 void writeFunctionMetadata(
const Function &
F);
361 void writeFunctionMetadataAttachment(
const Function &
F);
362 void writeGlobalVariableMetadataAttachment(
const GlobalVariable &GV);
365 void writeModuleMetadataKinds();
366 void writeOperandBundleTags();
367 void writeSyncScopeNames();
368 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
369 void writeModuleConstants();
370 bool pushValueAndType(
const Value *V,
unsigned InstID,
373 void pushValue(
const Value *V,
unsigned InstID,
375 void pushValueSigned(
const Value *V,
unsigned InstID,
377 void writeInstruction(
const Instruction &
I,
unsigned InstID,
380 void writeGlobalValueSymbolTable(
383 void writeUseListBlock(
const Function *
F);
387 void writeBlockInfo();
388 void writeModuleHash(
size_t BlockStartPos);
396 class IndexBitcodeWriter :
public BitcodeWriterBase {
402 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
406 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
409 unsigned GlobalValueId = 0;
417 const std::map<std::string, GVSummaryMapTy>
418 *ModuleToSummariesForIndex =
nullptr)
419 : BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
420 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
425 forEachSummary([&](GVInfo
I,
bool) {
426 GUIDToValueIdMap[I.first] = ++GlobalValueId;
431 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
436 template<
typename Functor>
437 void forEachSummary(Functor Callback) {
438 if (ModuleToSummariesForIndex) {
439 for (
auto &M : *ModuleToSummariesForIndex)
440 for (
auto &Summary : M.second) {
441 Callback(Summary,
false);
445 if (
auto *
AS = dyn_cast<AliasSummary>(Summary.getSecond()))
446 Callback({
AS->getAliaseeGUID(), &
AS->getAliasee()},
true);
449 for (
auto &Summaries : Index)
450 for (
auto &Summary : Summaries.second.SummaryList)
451 Callback({Summaries.first, Summary.get()},
false);
459 template <
typename Functor>
void forEachModule(Functor Callback) {
460 if (ModuleToSummariesForIndex) {
461 for (
const auto &M : *ModuleToSummariesForIndex) {
462 const auto &MPI = Index.modulePaths().find(M.first);
463 if (MPI == Index.modulePaths().end()) {
467 assert(ModuleToSummariesForIndex->size() == 1);
473 for (
const auto &MPSE : Index.modulePaths())
482 void writeModStrings();
483 void writeCombinedGlobalValueSummary();
486 auto VMI = GUIDToValueIdMap.find(ValGUID);
487 if (VMI == GUIDToValueIdMap.end())
492 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
521 case Instruction::Sub:
523 case Instruction::Mul:
526 case Instruction::FDiv:
529 case Instruction::FRem:
575 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
587 case Attribute::Alignment:
589 case Attribute::AllocSize:
591 case Attribute::AlwaysInline:
593 case Attribute::ArgMemOnly:
595 case Attribute::Builtin:
597 case Attribute::ByVal:
601 case Attribute::InAlloca:
605 case Attribute::InaccessibleMemOnly:
607 case Attribute::InaccessibleMemOrArgMemOnly:
609 case Attribute::InlineHint:
611 case Attribute::InReg:
615 case Attribute::MinSize:
617 case Attribute::Naked:
619 case Attribute::Nest:
623 case Attribute::NoBuiltin:
625 case Attribute::NoCapture:
627 case Attribute::NoDuplicate:
629 case Attribute::NoImplicitFloat:
631 case Attribute::NoInline:
633 case Attribute::NoRecurse:
635 case Attribute::NonLazyBind:
637 case Attribute::NonNull:
639 case Attribute::Dereferenceable:
641 case Attribute::DereferenceableOrNull:
643 case Attribute::NoRedZone:
645 case Attribute::NoReturn:
647 case Attribute::NoCfCheck:
649 case Attribute::NoUnwind:
651 case Attribute::OptForFuzzing:
653 case Attribute::OptimizeForSize:
655 case Attribute::OptimizeNone:
657 case Attribute::ReadNone:
659 case Attribute::ReadOnly:
661 case Attribute::Returned:
663 case Attribute::ReturnsTwice:
665 case Attribute::SExt:
667 case Attribute::Speculatable:
669 case Attribute::StackAlignment:
671 case Attribute::StackProtect:
673 case Attribute::StackProtectReq:
675 case Attribute::StackProtectStrong:
677 case Attribute::SafeStack:
679 case Attribute::ShadowCallStack:
681 case Attribute::StrictFP:
683 case Attribute::StructRet:
685 case Attribute::SanitizeAddress:
687 case Attribute::SanitizeHWAddress:
689 case Attribute::SanitizeThread:
691 case Attribute::SanitizeMemory:
693 case Attribute::SwiftError:
695 case Attribute::SwiftSelf:
697 case Attribute::UWTable:
699 case Attribute::WriteOnly:
701 case Attribute::ZExt:
712 void ModuleBitcodeWriter::writeAttributeGroupTable() {
713 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
715 if (AttrGrps.empty())
return;
721 unsigned AttrListIndex = Pair.first;
727 if (Attr.isEnumAttribute()) {
730 }
else if (Attr.isIntAttribute()) {
755 void ModuleBitcodeWriter::writeAttributeTable() {
757 if (Attrs.empty())
return;
762 for (
unsigned i = 0, e = Attrs.size(); i != e; ++i) {
778 void ModuleBitcodeWriter::writeTypeTable() {
787 auto Abbv = std::make_shared<BitCodeAbbrev>();
791 unsigned PtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
794 Abbv = std::make_shared<BitCodeAbbrev>();
799 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
802 Abbv = std::make_shared<BitCodeAbbrev>();
807 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
810 Abbv = std::make_shared<BitCodeAbbrev>();
814 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
817 Abbv = std::make_shared<BitCodeAbbrev>();
822 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
825 Abbv = std::make_shared<BitCodeAbbrev>();
829 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
837 for (
unsigned i = 0, e = TypeList.size(); i != e; ++i) {
838 Type *
T = TypeList[i];
866 if (AddressSpace == 0) AbbrevToUse = PtrAbbrev;
875 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i)
877 AbbrevToUse = FunctionAbbrev;
891 AbbrevToUse = StructAnonAbbrev;
897 AbbrevToUse = StructNamedAbbrev;
913 AbbrevToUse = ArrayAbbrev;
927 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
967 uint64_t RawFlags = 0;
977 uint64_t RawFlags = 0;
980 RawFlags |= (Flags.
Live << 1);
986 RawFlags = (RawFlags << 4) | Flags.
Linkage;
1045 size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1048 return StrtabBuilder.
add(Str);
1051 void ModuleBitcodeWriter::writeComdats() {
1066 void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1071 auto Abbv = std::make_shared<BitCodeAbbrev>();
1077 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1093 bool isChar6 =
true;
1094 for (
char C : Str) {
1097 if ((
unsigned char)
C & 128)
1109 void ModuleBitcodeWriter::writeModuleInfo() {
1123 std::map<std::string, unsigned> SectionMap;
1124 std::map<std::string, unsigned> GCMap;
1125 unsigned MaxAlignment = 0;
1126 unsigned MaxGlobalType = 0;
1128 MaxAlignment =
std::max(MaxAlignment, GV.getAlignment());
1130 if (GV.hasSection()) {
1132 unsigned &Entry = SectionMap[GV.getSection()];
1136 Entry = SectionMap.size();
1141 MaxAlignment =
std::max(MaxAlignment,
F.getAlignment());
1142 if (
F.hasSection()) {
1144 unsigned &Entry = SectionMap[
F.getSection()];
1148 Entry = SectionMap.size();
1153 unsigned &Entry = GCMap[
F.getGC()];
1157 Entry = GCMap.size();
1163 unsigned SimpleGVarAbbrev = 0;
1164 if (!M.global_empty()) {
1166 auto Abbv = std::make_shared<BitCodeAbbrev>();
1177 if (MaxAlignment == 0)
1180 unsigned MaxEncAlignment =
Log2_32(MaxAlignment)+1;
1184 if (SectionMap.empty())
1190 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1204 auto Abbv = std::make_shared<BitCodeAbbrev>();
1207 Abbv->Add(AbbrevOpToUse);
1208 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1210 for (
const auto P : M.getSourceFileName())
1220 unsigned AbbrevToUse = 0;
1226 Vals.
push_back(addToStrtab(GV.getName()));
1229 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1234 Vals.
push_back(GV.hasSection() ? SectionMap[GV.getSection()] : 0);
1235 if (GV.isThreadLocal() ||
1238 GV.isExternallyInitialized() ||
1241 GV.hasAttributes() ||
1246 Vals.
push_back(GV.isExternallyInitialized());
1255 AbbrevToUse = SimpleGVarAbbrev;
1276 Vals.
push_back(
F.hasSection() ? SectionMap[
F.getSection()] : 0);
1287 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1290 unsigned AbbrevToUse = 0;
1300 Vals.
push_back(addToStrtab(A.getName()));
1303 Vals.
push_back(A.getType()->getAddressSpace());
1312 unsigned AbbrevToUse = 0;
1324 Vals.
push_back(
I.getType()->getAddressSpace());
1333 writeValueSymbolTableForwardDecl();
1339 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1340 if (OBO->hasNoSignedWrap())
1342 if (OBO->hasNoUnsignedWrap())
1344 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1347 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1348 if (FPMO->hasAllowReassoc())
1350 if (FPMO->hasNoNaNs())
1352 if (FPMO->hasNoInfs())
1354 if (FPMO->hasNoSignedZeros())
1356 if (FPMO->hasAllowReciprocal())
1358 if (FPMO->hasAllowContract())
1360 if (FPMO->hasApproxFunc())
1367 void ModuleBitcodeWriter::writeValueAsMetadata(
1382 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1383 "Unexpected function-local metadata");
1392 unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1395 auto Abbv = std::make_shared<BitCodeAbbrev>();
1409 Abbrev = createDILocationAbbrev();
1421 unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1424 auto Abbv = std::make_shared<BitCodeAbbrev>();
1439 Abbrev = createGenericDINodeAbbrev();
1454 return I < 0 ? ~(U << 1) : U << 1;
1460 const uint64_t
Version = 1 << 1;
1512 if (
const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
1513 Record.
push_back(*DWARFAddressSpace + 1);
1524 const unsigned IsNotUsedInOldTypeRef = 0x2;
1550 const unsigned HasNoOldTypeRefs = 0x2;
1566 if (N->getRawChecksum()) {
1567 Record.
push_back(N->getRawChecksum()->Kind);
1575 auto Source = N->getRawSource();
1614 uint64_t HasUnitFlag = 1 << 1;
1634 Record.
push_back(N->getThisAdjustment());
1741 const uint64_t
Version = 1 << 1;
1775 const uint64_t HasAlignmentFlag = 1 << 1;
1807 const uint64_t
Version = 3 << 1;
1857 unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
1858 auto Abbv = std::make_shared<BitCodeAbbrev>();
1865 void ModuleBitcodeWriter::writeNamedMetadata(
1870 unsigned Abbrev = createNamedMetadataAbbrev();
1886 unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
1887 auto Abbv = std::make_shared<BitCodeAbbrev>();
1899 void ModuleBitcodeWriter::writeMetadataStrings(
1901 if (Strings.
empty())
1913 W.
EmitVBR(cast<MDString>(MD)->getLength(), 6);
1922 Blob.
append(cast<MDString>(MD)->getString());
1931 #define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID, 1932 #include "llvm/IR/Metadata.def" 1936 void ModuleBitcodeWriter::writeMetadataRecords(
1938 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
1943 #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0; 1944 #include "llvm/IR/Metadata.def" 1949 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
1955 #define HANDLE_MDNODE_LEAF(CLASS) \ 1956 case Metadata::CLASS##Kind: \ 1958 write##CLASS(cast<CLASS>(N), Record, \ 1959 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \ 1961 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \ 1963 #include "llvm/IR/Metadata.def" 1966 writeValueAsMetadata(cast<ValueAsMetadata>(MD), Record);
1970 void ModuleBitcodeWriter::writeModuleMetadata() {
1979 std::vector<unsigned> MDAbbrevs;
1982 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
1983 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
1984 createGenericDINodeAbbrev();
1986 auto Abbv = std::make_shared<BitCodeAbbrev>();
1990 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1992 Abbv = std::make_shared<BitCodeAbbrev>();
1996 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2008 uint64_t Vals[] = {0, 0};
2018 std::vector<uint64_t> IndexPos;
2022 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2033 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2034 for (
auto &Elt : IndexPos) {
2035 auto EltDelta = Elt - PreviousValue;
2036 PreviousValue = Elt;
2045 writeNamedMetadata(Record);
2047 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2050 pushGlobalMetadataAttachment(Record, GO);
2054 if (
F.isDeclaration() &&
F.hasMetadata())
2055 AddDeclAttachedMetadata(
F);
2059 if (GV.hasMetadata())
2060 AddDeclAttachedMetadata(GV);
2065 void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2076 void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2081 for (
const auto &
I : MDs) {
2087 void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &F) {
2093 pushGlobalMetadataAttachment(Record, F);
2104 I.getAllMetadataOtherThanDebugLoc(MDs);
2107 if (MDs.
empty())
continue;
2111 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2122 void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2130 if (Names.
empty())
return;
2134 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2146 void ModuleBitcodeWriter::writeOperandBundleTags() {
2163 for (
auto Tag : Tags) {
2173 void ModuleBitcodeWriter::writeSyncScopeNames() {
2182 for (
auto SSN : SSNs) {
2183 Record.
append(SSN.begin(), SSN.end());
2192 if ((int64_t)V >= 0)
2198 void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2200 if (FirstVal == LastVal)
return;
2204 unsigned AggregateAbbrev = 0;
2205 unsigned String8Abbrev = 0;
2206 unsigned CString7Abbrev = 0;
2207 unsigned CString6Abbrev = 0;
2211 auto Abbv = std::make_shared<BitCodeAbbrev>();
2215 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2218 Abbv = std::make_shared<BitCodeAbbrev>();
2222 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2224 Abbv = std::make_shared<BitCodeAbbrev>();
2228 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2230 Abbv = std::make_shared<BitCodeAbbrev>();
2234 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2240 Type *LastTy =
nullptr;
2241 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2242 const Value *V = Vals[i].first;
2248 CONSTANTS_SETTYPE_ABBREV);
2252 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2253 Record.
push_back(
unsigned(IA->hasSideEffects()) |
2254 unsigned(IA->isAlignStack()) << 1 |
2255 unsigned(IA->getDialect()&1) << 2);
2258 const std::string &AsmStr = IA->getAsmString();
2260 Record.
append(AsmStr.begin(), AsmStr.end());
2263 const std::string &ConstraintStr = IA->getConstraintString();
2265 Record.
append(ConstraintStr.begin(), ConstraintStr.end());
2271 unsigned Code = -1U;
2272 unsigned AbbrevToUse = 0;
2275 }
else if (isa<UndefValue>(C)) {
2277 }
else if (
const ConstantInt *IV = dyn_cast<ConstantInt>(C)) {
2278 if (IV->getBitWidth() <= 64) {
2279 uint64_t V = IV->getSExtValue();
2282 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2288 unsigned NWords = IV->getValue().getActiveWords();
2289 const uint64_t *RawWords = IV->getValue().getRawData();
2290 for (
unsigned i = 0; i != NWords; ++i) {
2295 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2297 Type *Ty = CFP->getType();
2299 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2303 APInt api = CFP->getValueAPF().bitcastToAPInt();
2305 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2308 APInt api = CFP->getValueAPF().bitcastToAPInt();
2313 assert(0 &&
"Unknown FP type!");
2315 }
else if (isa<ConstantDataSequential>(C) &&
2316 cast<ConstantDataSequential>(C)->isString()) {
2326 AbbrevToUse = String8Abbrev;
2330 for (
unsigned i = 0; i != NumElts; ++i) {
2333 isCStr7 &= (V & 128) == 0;
2339 AbbrevToUse = CString6Abbrev;
2341 AbbrevToUse = CString7Abbrev;
2343 dyn_cast<ConstantDataSequential>(C)) {
2345 Type *EltTy = CDS->getType()->getElementType();
2346 if (isa<IntegerType>(EltTy)) {
2347 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2348 Record.
push_back(CDS->getElementAsInteger(i));
2350 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2352 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2354 }
else if (isa<ConstantAggregate>(C)) {
2358 AbbrevToUse = AggregateAbbrev;
2359 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2360 switch (CE->getOpcode()) {
2367 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2369 assert(CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2379 case Instruction::GetElementPtr: {
2381 const auto *GO = cast<GEPOperator>(
C);
2385 Record.
push_back((*Idx << 1) | GO->isInBounds());
2386 }
else if (GO->isInBounds())
2388 for (
unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
2400 case Instruction::ExtractElement:
2407 case Instruction::InsertElement:
2414 case Instruction::ShuffleVector:
2429 case Instruction::ICmp:
2430 case Instruction::FCmp:
2438 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
2449 Stream.
EmitRecord(Code, Record, AbbrevToUse);
2456 void ModuleBitcodeWriter::writeModuleConstants() {
2461 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2462 if (!isa<GlobalValue>(Vals[i].
first)) {
2463 writeConstants(i, Vals.size(),
true);
2477 bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2482 if (ValID >= InstID) {
2498 for (
auto &Input : Bundle.Inputs)
2499 pushValueAndType(Input, InstID, Record);
2508 void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2514 void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2517 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2522 void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2526 unsigned AbbrevToUse = 0;
2532 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2533 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2537 assert(isa<BinaryOperator>(I) &&
"Unknown instruction!");
2539 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2540 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2545 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2546 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2552 case Instruction::GetElementPtr: {
2554 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2555 auto &GEPInst = cast<GetElementPtrInst>(
I);
2559 pushValueAndType(I.
getOperand(i), InstID, Vals);
2562 case Instruction::ExtractValue: {
2564 pushValueAndType(I.
getOperand(0), InstID, Vals);
2566 Vals.
append(EVI->idx_begin(), EVI->idx_end());
2569 case Instruction::InsertValue: {
2571 pushValueAndType(I.
getOperand(0), InstID, Vals);
2572 pushValueAndType(I.
getOperand(1), InstID, Vals);
2574 Vals.
append(IVI->idx_begin(), IVI->idx_end());
2579 pushValueAndType(I.
getOperand(1), InstID, Vals);
2581 pushValueAndType(I.
getOperand(0), InstID, Vals);
2583 case Instruction::ExtractElement:
2585 pushValueAndType(I.
getOperand(0), InstID, Vals);
2586 pushValueAndType(I.
getOperand(1), InstID, Vals);
2588 case Instruction::InsertElement:
2590 pushValueAndType(I.
getOperand(0), InstID, Vals);
2592 pushValueAndType(I.
getOperand(2), InstID, Vals);
2594 case Instruction::ShuffleVector:
2596 pushValueAndType(I.
getOperand(0), InstID, Vals);
2600 case Instruction::ICmp:
2601 case Instruction::FCmp: {
2604 pushValueAndType(I.
getOperand(0), InstID, Vals);
2617 if (NumOperands == 0)
2618 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
2619 else if (NumOperands == 1) {
2620 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2621 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
2623 for (
unsigned i = 0, e = NumOperands; i != e; ++i)
2624 pushValueAndType(I.
getOperand(i), InstID, Vals);
2628 case Instruction::Br:
2639 case Instruction::Switch:
2646 for (
auto Case : SI.
cases()) {
2652 case Instruction::IndirectBr:
2661 case Instruction::Invoke: {
2667 writeOperandBundles(II, InstID);
2676 pushValueAndType(Callee, InstID, Vals);
2679 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i)
2686 pushValueAndType(I.
getOperand(i), InstID, Vals);
2690 case Instruction::Resume:
2692 pushValueAndType(I.
getOperand(0), InstID, Vals);
2694 case Instruction::CleanupRet: {
2696 const auto &CRI = cast<CleanupReturnInst>(
I);
2697 pushValue(CRI.getCleanupPad(), InstID, Vals);
2698 if (CRI.hasUnwindDest())
2702 case Instruction::CatchRet: {
2704 const auto &CRI = cast<CatchReturnInst>(
I);
2705 pushValue(CRI.getCatchPad(), InstID, Vals);
2709 case Instruction::CleanupPad:
2710 case Instruction::CatchPad: {
2711 const auto &FuncletPad = cast<FuncletPadInst>(
I);
2714 pushValue(FuncletPad.getParentPad(), InstID, Vals);
2716 unsigned NumArgOperands = FuncletPad.getNumArgOperands();
2718 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
2719 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
2722 case Instruction::CatchSwitch: {
2724 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
2726 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
2728 unsigned NumHandlers = CatchSwitch.getNumHandlers();
2730 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
2733 if (CatchSwitch.hasUnwindDest())
2737 case Instruction::Unreachable:
2739 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
2742 case Instruction::PHI: {
2743 const PHINode &PN = cast<PHINode>(
I);
2755 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
2760 case Instruction::LandingPad: {
2771 pushValueAndType(LP.
getClause(I), InstID, Vals);
2776 case Instruction::Alloca: {
2784 "not enough bits for maximum alignment");
2785 assert(AlignRecord < 1 << 5 &&
"alignment greater than 1 << 64");
2787 AlignRecord |= 1 << 6;
2794 if (cast<LoadInst>(I).
isAtomic()) {
2796 pushValueAndType(I.
getOperand(0), InstID, Vals);
2799 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2800 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
2805 if (cast<LoadInst>(I).
isAtomic()) {
2807 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
2815 pushValueAndType(I.
getOperand(1), InstID, Vals);
2816 pushValueAndType(I.
getOperand(0), InstID, Vals);
2819 if (cast<StoreInst>(I).
isAtomic()) {
2822 getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
2825 case Instruction::AtomicCmpXchg:
2827 pushValueAndType(I.
getOperand(0), InstID, Vals);
2828 pushValueAndType(I.
getOperand(1), InstID, Vals);
2834 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
2839 case Instruction::AtomicRMW:
2841 pushValueAndType(I.
getOperand(0), InstID, Vals);
2848 getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
2850 case Instruction::Fence:
2853 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
2860 writeOperandBundles(&CI, InstID);
2880 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2882 if (FTy->getParamType(i)->isLabelTy())
2889 if (FTy->isVarArg()) {
2896 case Instruction::VAArg:
2910 void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
2916 VSTOffset -= bitcodeStartBit();
2917 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
2921 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
2925 auto Abbv = std::make_shared<BitCodeAbbrev>();
2929 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2941 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
2942 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
2946 Record[1] = BitcodeIndex / 32 + 1;
2955 void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
2970 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
2976 if (isa<BasicBlock>(
Name.getValue())) {
2979 AbbrevToUse = VST_BBENTRY_6_ABBREV;
2983 AbbrevToUse = VST_ENTRY_6_ABBREV;
2985 AbbrevToUse = VST_ENTRY_7_ABBREV;
2988 for (
const auto P :
Name.getKey())
2992 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
2999 void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3000 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3002 if (isa<BasicBlock>(Order.V))
3012 void ModuleBitcodeWriter::writeUseListBlock(
const Function *F) {
3014 "Expected to be preserving use-list order");
3016 auto hasMore = [&]() {
3032 void ModuleBitcodeWriter::writeFunction(
3051 unsigned CstStart, CstEnd;
3053 writeConstants(CstStart, CstEnd,
false);
3056 writeFunctionMetadata(F);
3059 unsigned InstID = CstEnd;
3068 writeInstruction(*I, InstID, Vals);
3099 writeFunctionLevelValueSymbolTable(*Symtab);
3101 if (NeedsMetadataAttachment)
3102 writeFunctionMetadataAttachment(F);
3104 writeUseListBlock(&F);
3110 void ModuleBitcodeWriter::writeBlockInfo() {
3117 auto Abbv = std::make_shared<BitCodeAbbrev>();
3128 auto Abbv = std::make_shared<BitCodeAbbrev>();
3138 auto Abbv = std::make_shared<BitCodeAbbrev>();
3148 auto Abbv = std::make_shared<BitCodeAbbrev>();
3154 VST_BBENTRY_6_ABBREV)
3159 auto Abbv = std::make_shared<BitCodeAbbrev>();
3164 CONSTANTS_SETTYPE_ABBREV)
3169 auto Abbv = std::make_shared<BitCodeAbbrev>();
3173 CONSTANTS_INTEGER_ABBREV)
3178 auto Abbv = std::make_shared<BitCodeAbbrev>();
3186 CONSTANTS_CE_CAST_Abbrev)
3190 auto Abbv = std::make_shared<BitCodeAbbrev>();
3193 CONSTANTS_NULL_Abbrev)
3200 auto Abbv = std::make_shared<BitCodeAbbrev>();
3208 FUNCTION_INST_LOAD_ABBREV)
3212 auto Abbv = std::make_shared<BitCodeAbbrev>();
3218 FUNCTION_INST_BINOP_ABBREV)
3222 auto Abbv = std::make_shared<BitCodeAbbrev>();
3229 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3233 auto Abbv = std::make_shared<BitCodeAbbrev>();
3240 FUNCTION_INST_CAST_ABBREV)
3245 auto Abbv = std::make_shared<BitCodeAbbrev>();
3248 FUNCTION_INST_RET_VOID_ABBREV)
3252 auto Abbv = std::make_shared<BitCodeAbbrev>();
3256 FUNCTION_INST_RET_VAL_ABBREV)
3260 auto Abbv = std::make_shared<BitCodeAbbrev>();
3263 FUNCTION_INST_UNREACHABLE_ABBREV)
3267 auto Abbv = std::make_shared<BitCodeAbbrev>();
3275 FUNCTION_INST_GEP_ABBREV)
3284 void IndexBitcodeWriter::writeModStrings() {
3290 auto Abbv = std::make_shared<BitCodeAbbrev>();
3295 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3298 Abbv = std::make_shared<BitCodeAbbrev>();
3303 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3306 Abbv = std::make_shared<BitCodeAbbrev>();
3311 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3314 Abbv = std::make_shared<BitCodeAbbrev>();
3321 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3325 [&](
const StringMapEntry<std::pair<uint64_t, ModuleHash>> &MPSE) {
3327 const auto &
Value = MPSE.getValue();
3329 unsigned AbbrevToUse = Abbrev8Bit;
3331 AbbrevToUse = Abbrev6Bit;
3333 AbbrevToUse = Abbrev7Bit;
3342 const auto &Hash =
Value.second;
3344 Vals.
assign(Hash.begin(), Hash.end());
3358 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
3362 ReferencedTypeIds.insert(TT);
3367 auto WriteVFuncIdVec = [&](uint64_t Ty,
3372 for (
auto &VF : VFs) {
3375 ReferencedTypeIds.insert(VF.GUID);
3385 auto WriteConstVCallVec = [&](uint64_t Ty,
3387 for (
auto &
VC : VCs) {
3390 ReferencedTypeIds.insert(
VC.VFunc.GUID);
3392 Record.
insert(Record.
end(),
VC.Args.begin(),
VC.Args.end());
3407 NameVals.
insert(NameVals.
end(), args.begin(), args.end());
3431 const std::string &
Id,
3443 for (
auto &
W : Summary.
WPDRes)
3449 void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
3451 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
3456 std::set<GlobalValue::GUID> ReferencedTypeIds;
3464 for (
auto &RI : FS->
refs())
3467 bool HasProfileData =
3469 for (
auto &ECI : FS->
calls()) {
3470 NameVals.
push_back(getValueId(ECI.first));
3472 NameVals.
push_back(static_cast<uint8_t>(ECI.second.Hotness));
3474 NameVals.
push_back(ECI.second.RelBlockFreq);
3477 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3490 void ModuleBitcodeWriterBase::writeModuleLevelReferences(
3492 unsigned FSModRefsAbbrev) {
3493 auto VI = Index->getValueInfo(V.
getGUID());
3505 unsigned SizeBeforeRefs = NameVals.
size();
3506 for (
auto &RI : VS->
refs())
3524 void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
3527 bool IsThinLTO =
true;
3529 mdconst::extract_or_null<ConstantInt>(M.
getModuleFlag(
"ThinLTO")))
3530 IsThinLTO = MD->getZExtValue();
3537 if (Index->begin() == Index->end()) {
3542 for (
const auto &GVI : valueIds()) {
3548 auto Abbv = std::make_shared<BitCodeAbbrev>();
3558 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3561 Abbv = std::make_shared<BitCodeAbbrev>();
3574 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3577 Abbv = std::make_shared<BitCodeAbbrev>();
3583 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3586 Abbv = std::make_shared<BitCodeAbbrev>();
3591 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3610 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&F),
3611 FSCallsAbbrev, FSCallsProfileAbbrev,
F);
3617 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev);
3620 auto *Aliasee = A.getBaseObject();
3621 if (!Aliasee->hasName())
3627 auto *Summary = Index->getGlobalValueSummary(A);
3639 void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
3645 if (Index.withGlobalValueDeadStripping())
3647 if (Index.skipModuleByDistributedBackend())
3651 for (
const auto &GVI : valueIds()) {
3657 auto Abbv = std::make_shared<BitCodeAbbrev>();
3668 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3671 Abbv = std::make_shared<BitCodeAbbrev>();
3682 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3685 Abbv = std::make_shared<BitCodeAbbrev>();
3692 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3695 Abbv = std::make_shared<BitCodeAbbrev>();
3701 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3714 std::set<GlobalValue::GUID> ReferencedTypeIds;
3721 NameVals.
push_back(S.getOriginalName());
3726 forEachSummary([&](GVInfo I,
bool IsAliasee) {
3730 auto ValueId = getValueId(I.first);
3732 SummaryToValueIdMap[S] = *ValueId;
3740 if (
auto *
AS = dyn_cast<AliasSummary>(S)) {
3747 if (
auto *
VS = dyn_cast<GlobalVarSummary>(S)) {
3749 NameVals.
push_back(Index.getModuleId(
VS->modulePath()));
3751 for (
auto &RI :
VS->refs()) {
3752 auto RefValueId = getValueId(RI.getGUID());
3762 MaybeEmitOriginalName(*S);
3766 auto *FS = cast<FunctionSummary>(S);
3770 NameVals.
push_back(Index.getModuleId(FS->modulePath()));
3778 for (
auto &RI : FS->refs()) {
3779 auto RefValueId = getValueId(RI.getGUID());
3785 NameVals[5] = Count;
3787 bool HasProfileData =
false;
3788 for (
auto &EI : FS->calls()) {
3795 for (
auto &EI : FS->calls()) {
3799 auto CallValueId = getValueId(GUID);
3804 GUID = Index.getGUIDFromOriginalID(GUID);
3807 CallValueId = getValueId(GUID);
3820 auto *GVSum = Index.getGlobalValueSummary(GUID,
false);
3827 NameVals.
push_back(static_cast<uint8_t>(EI.second.Hotness));
3830 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3837 MaybeEmitOriginalName(*S);
3840 for (
auto *
AS : Aliases) {
3841 auto AliasValueId = SummaryToValueIdMap[
AS];
3844 NameVals.
push_back(Index.getModuleId(
AS->modulePath()));
3846 auto AliaseeValueId = SummaryToValueIdMap[&
AS->getAliasee()];
3853 MaybeEmitOriginalName(*
AS);
3856 if (!Index.cfiFunctionDefs().empty()) {
3857 for (
auto &S : Index.cfiFunctionDefs()) {
3865 if (!Index.cfiFunctionDecls().empty()) {
3866 for (
auto &S : Index.cfiFunctionDecls()) {
3874 if (!Index.typeIds().empty()) {
3875 for (
auto &S : Index.typeIds()) {
3894 auto Abbv = std::make_shared<BitCodeAbbrev>();
3898 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3900 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
3903 Abbv = std::make_shared<BitCodeAbbrev>();
3906 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3912 void ModuleBitcodeWriter::writeModuleHash(
size_t BlockStartPos) {
3918 Buffer.size() - BlockStartPos));
3920 for (
int Pos = 0; Pos < 20; Pos += 4) {
3937 size_t BlockStartPos = Buffer.size();
3939 writeModuleVersion();
3945 writeAttributeGroupTable();
3948 writeAttributeTable();
3960 writeModuleConstants();
3963 writeModuleMetadataKinds();
3966 writeModuleMetadata();
3970 writeUseListBlock(
nullptr);
3972 writeOperandBundleTags();
3973 writeSyncScopeNames();
3979 writeFunction(*F, FunctionToBitcodeIndex);
3984 writePerModuleGlobalValueSummary();
3986 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
3988 writeModuleHash(BlockStartPos);
4021 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4022 DARWIN_CPU_TYPE_X86 = 7,
4023 DARWIN_CPU_TYPE_ARM = 12,
4024 DARWIN_CPU_TYPE_POWERPC = 18
4029 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4031 CPUType = DARWIN_CPU_TYPE_X86;
4033 CPUType = DARWIN_CPU_TYPE_POWERPC;
4035 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4037 CPUType = DARWIN_CPU_TYPE_ARM;
4041 "Expected header size to be reserved");
4054 while (Buffer.
size() & 15)
4061 Stream.
Emit((
unsigned)
'B', 8);
4062 Stream.
Emit((
unsigned)
'C', 8);
4063 Stream.
Emit(0x0, 4);
4064 Stream.
Emit(0xC, 4);
4065 Stream.
Emit(0xE, 4);
4066 Stream.
Emit(0xD, 4);
4076 void BitcodeWriter::writeBlob(
unsigned Block,
unsigned Record,
StringRef Blob) {
4079 auto Abbv = std::make_shared<BitCodeAbbrev>();
4082 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
4090 assert(!WroteStrtab && !WroteSymtab);
4102 if (!T || !T->hasMCAsmParser())
4124 std::vector<char> Strtab;
4126 Strtab.resize(StrtabBuilder.
getSize());
4127 StrtabBuilder.
write((uint8_t *)Strtab.data());
4130 {Strtab.data(), Strtab.size()});
4141 bool ShouldPreserveUseListOrder,
4151 Mods.push_back(const_cast<Module *>(&M));
4153 ModuleBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream,
4154 ShouldPreserveUseListOrder, Index,
4155 GenerateHash, ModHash);
4156 ModuleWriter.write();
4161 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
4162 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index,
4163 ModuleToSummariesForIndex);
4164 IndexWriter.write();
4169 bool ShouldPreserveUseListOrder,
4178 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
4182 Writer.
writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
4187 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
4197 writeModuleVersion();
4203 writeCombinedGlobalValueSummary();
4214 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
4219 Writer.
writeIndex(&Index, ModuleToSummariesForIndex);
4228 class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
4238 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
4240 ModHash(&ModHash) {}
4245 void writeSimplifiedModuleInfo();
4255 void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
4267 auto Abbv = std::make_shared<BitCodeAbbrev>();
4270 Abbv->Add(AbbrevOpToUse);
4271 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4340 writeModuleVersion();
4342 writeSimplifiedModuleInfo();
4344 writePerModuleGlobalValueSummary();
4362 Mods.push_back(const_cast<Module *>(&M));
4364 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
4366 ThinLinkWriter.write();
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
void push_back(const T &Elt)
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
const_iterator end(StringRef path)
Get end iterator over path.
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.
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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isDefinition() const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
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. ...
2: 32-bit floating point type
MDString * getRawName() const
Same, but only replaced by something equivalent.
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.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
DITypeRef getBaseType() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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
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
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static StringEncoding getStringEncoding(StringRef Str)
Determine the encoding to use for the given string name and length.
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
static const uint64_t INDEX_VERSION
MDString * getRawName() const
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS, std::set< GlobalValue::GUID > &ReferencedTypeIds)
Write the function type metadata related records that need to appear before a function summary entry ...
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...
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()
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...
FunctionType * getFunctionType() const
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.
InstrTy * getInstruction() const
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
static const unsigned MaximumAlignment
DITypeRef getVTableHolder() const
Position
Position to insert a new instruction relative to an existing instruction.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
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
void assign(size_type NumElts, const T &Elt)
bool getExportSymbols() 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.
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.
Type * getType() const
All values are typed, get the type of this value.
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.
DITypeRef getType() const
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
DIMacroNodeArray getElements() const
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 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
AttributeList getAttributes() const
Return the parameter attributes for this call.
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)
amdgpu Simplify well known AMD library false Value * Callee
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
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
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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...
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.
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
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...
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.
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)
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
#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.
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.
const ComdatSetType & getComdats() const
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
EmitAbbrev - This emits an abbreviation 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)
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
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)
static void writeWholeProgramDevirtResolution(SmallVector< uint64_t, 64 > &NameVals, StringTableBuilder &StrtabBuilder, uint64_t Id, const WholeProgramDevirtResolution &Wpd)
OperandBundleUse getOperandBundleAt(unsigned Index) const
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)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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 isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
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 *)
static unsigned getEncodedLinkage(const GlobalValue::LinkageTypes Linkage)
Type * getReturnType() const
bool getGnuPubnames() 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.
static const unsigned BWH_HeaderSize
bool isConditional() const
The linker will choose the largest COMDAT.
DITypeRef getType() const
unsigned getNumIncomingValues() const
Return the number of incoming edges.
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 bool isWeak(const MCSymbolELF &Sym)
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 ...
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.
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 attribute 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.
bool getSplitDebugInlining() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
MDString * getRawIdentifier() const
static void writeDISubroutineType(raw_ostream &Out, const DISubroutineType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
unsigned getNumOperandBundles() const
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().
LLVM_NODISCARD bool empty() const
static void writeDIDerivedType(raw_ostream &Out, const DIDerivedType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
unsigned getNumArgOperands() const
Return the number of call arguments.
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...
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.
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
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
Function attribute flags.
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
DITypeRef getType() const
DILocalScope * getScope() const
Get the local scope for this label.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
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
bool hasAttributes() const
Return true if attributes exists in this set.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
static void writeDICompositeType(raw_ostream &Out, const DICompositeType *N, TypePrinting *TypePrinter, SlotTracker *Machine, const Module *Context)
BasicBlock * getUnwindDest() const
LLVM Value Representation.
DIScopeRef getScope() const
bool hasMetadata() const
Check if this has any metadata.
DINodeRef getEntity() const
Lightweight error class with error context and mandatory checking.
bool named_metadata_empty() const
DITypeRefArray getTypeArray() const
DIDerivedType * getDiscriminator() const
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
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()
bool isNoTailCall() const
StringRef - Represent a constant reference to a string, i.e.
DILocalScope * getScope() 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
MDString * getRawGetterName() const
static void writeBitcodeHeader(BitstreamWriter &Stream)
Helper to write the header common to all bitcode files.
bool hasProfileData() const
Return true if the function is annotated with profile data.
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
DIScopeRef getScope() const