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);
221 GUIDToValueIdMap[ValGUID] = ++GlobalValueId;
225 const auto &VMI = GUIDToValueIdMap.find(ValGUID);
228 assert(VMI != GUIDToValueIdMap.end() &&
229 "GUID does not have assigned value Id");
236 return getValueId(VI.
getGUID());
240 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
244 class ModuleBitcodeWriter :
public ModuleBitcodeWriterBase {
258 uint64_t BitcodeStartBit;
268 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
269 ShouldPreserveUseListOrder, Index),
270 Buffer(Buffer), GenerateHash(GenerateHash), ModHash(ModHash),
271 BitcodeStartBit(Stream.GetCurrentBitNo()) {}
277 uint64_t bitcodeStartBit() {
return BitcodeStartBit; }
281 void writeAttributeGroupTable();
282 void writeAttributeTable();
283 void writeTypeTable();
285 void writeValueSymbolTableForwardDecl();
286 void writeModuleInfo();
291 unsigned createDILocationAbbrev();
294 unsigned createGenericDINodeAbbrev();
352 unsigned createNamedMetadataAbbrev();
354 unsigned createMetadataStringsAbbrev();
359 std::vector<unsigned> *MDAbbrevs =
nullptr,
360 std::vector<uint64_t> *IndexPos =
nullptr);
361 void writeModuleMetadata();
362 void writeFunctionMetadata(
const Function &
F);
363 void writeFunctionMetadataAttachment(
const Function &
F);
364 void writeGlobalVariableMetadataAttachment(
const GlobalVariable &GV);
367 void writeModuleMetadataKinds();
368 void writeOperandBundleTags();
369 void writeSyncScopeNames();
370 void writeConstants(
unsigned FirstVal,
unsigned LastVal,
bool isGlobal);
371 void writeModuleConstants();
372 bool pushValueAndType(
const Value *V,
unsigned InstID,
375 void pushValue(
const Value *V,
unsigned InstID,
377 void pushValueSigned(
const Value *V,
unsigned InstID,
379 void writeInstruction(
const Instruction &
I,
unsigned InstID,
382 void writeGlobalValueSymbolTable(
385 void writeUseListBlock(
const Function *
F);
389 void writeBlockInfo();
390 void writeModuleHash(
size_t BlockStartPos);
398 class IndexBitcodeWriter :
public BitcodeWriterBase {
404 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
408 std::map<GlobalValue::GUID, unsigned> GUIDToValueIdMap;
411 unsigned GlobalValueId = 0;
419 const std::map<std::string, GVSummaryMapTy>
420 *ModuleToSummariesForIndex =
nullptr)
421 : BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
422 ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
427 forEachSummary([&](GVInfo
I,
bool) {
428 GUIDToValueIdMap[I.first] = ++GlobalValueId;
433 using GVInfo = std::pair<GlobalValue::GUID, GlobalValueSummary *>;
438 template<
typename Functor>
439 void forEachSummary(Functor Callback) {
440 if (ModuleToSummariesForIndex) {
441 for (
auto &M : *ModuleToSummariesForIndex)
442 for (
auto &Summary : M.second) {
443 Callback(Summary,
false);
447 if (
auto *AS = dyn_cast<AliasSummary>(Summary.getSecond()))
448 Callback({AS->getAliaseeGUID(), &AS->getAliasee()},
true);
451 for (
auto &Summaries : Index)
452 for (
auto &Summary : Summaries.second.SummaryList)
453 Callback({Summaries.first, Summary.get()},
false);
461 template <
typename Functor>
void forEachModule(Functor Callback) {
462 if (ModuleToSummariesForIndex) {
463 for (
const auto &M : *ModuleToSummariesForIndex) {
464 const auto &MPI = Index.modulePaths().find(M.first);
465 if (MPI == Index.modulePaths().end()) {
469 assert(ModuleToSummariesForIndex->size() == 1);
475 for (
const auto &MPSE : Index.modulePaths())
484 void writeModStrings();
485 void writeCombinedGlobalValueSummary();
488 auto VMI = GUIDToValueIdMap.find(ValGUID);
489 if (VMI == GUIDToValueIdMap.end())
494 std::map<GlobalValue::GUID, unsigned> &valueIds() {
return GUIDToValueIdMap; }
530 case Instruction::Sub:
532 case Instruction::Mul:
535 case Instruction::FDiv:
538 case Instruction::FRem:
584 for (
unsigned i = 0, e = Str.
size(); i != e; ++i) {
723 void ModuleBitcodeWriter::writeAttributeGroupTable() {
724 const std::vector<ValueEnumerator::IndexAndAttrSet> &AttrGrps =
726 if (AttrGrps.empty())
return;
732 unsigned AttrListIndex = Pair.first;
738 if (Attr.isEnumAttribute()) {
741 }
else if (Attr.isIntAttribute()) {
766 void ModuleBitcodeWriter::writeAttributeTable() {
768 if (Attrs.empty())
return;
773 for (
unsigned i = 0, e = Attrs.size(); i != e; ++i) {
789 void ModuleBitcodeWriter::writeTypeTable() {
798 auto Abbv = std::make_shared<BitCodeAbbrev>();
802 unsigned PtrAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
805 Abbv = std::make_shared<BitCodeAbbrev>();
810 unsigned FunctionAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
813 Abbv = std::make_shared<BitCodeAbbrev>();
818 unsigned StructAnonAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
821 Abbv = std::make_shared<BitCodeAbbrev>();
825 unsigned StructNameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
828 Abbv = std::make_shared<BitCodeAbbrev>();
833 unsigned StructNamedAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
836 Abbv = std::make_shared<BitCodeAbbrev>();
840 unsigned ArrayAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
848 for (
unsigned i = 0, e = TypeList.size(); i != e; ++i) {
849 Type *
T = TypeList[i];
877 if (AddressSpace == 0) AbbrevToUse = PtrAbbrev;
886 for (
unsigned i = 0, e = FT->
getNumParams(); i != e; ++i)
888 AbbrevToUse = FunctionAbbrev;
902 AbbrevToUse = StructAnonAbbrev;
908 AbbrevToUse = StructNamedAbbrev;
924 AbbrevToUse = ArrayAbbrev;
938 Stream.
EmitRecord(Code, TypeVals, AbbrevToUse);
978 uint64_t RawFlags = 0;
989 uint64_t RawFlags = 0;
992 RawFlags |= (Flags.
Live << 1);
998 RawFlags = (RawFlags << 4) | Flags.
Linkage;
1004 uint64_t RawFlags = Flags.
ReadOnly;
1062 size_t ModuleBitcodeWriter::addToStrtab(
StringRef Str) {
1065 return StrtabBuilder.
add(Str);
1068 void ModuleBitcodeWriter::writeComdats() {
1083 void ModuleBitcodeWriter::writeValueSymbolTableForwardDecl() {
1088 auto Abbv = std::make_shared<BitCodeAbbrev>();
1094 unsigned VSTOffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1110 bool isChar6 =
true;
1111 for (
char C : Str) {
1114 if ((
unsigned char)
C & 128)
1126 void ModuleBitcodeWriter::writeModuleInfo() {
1140 std::map<std::string, unsigned> SectionMap;
1141 std::map<std::string, unsigned> GCMap;
1142 unsigned MaxAlignment = 0;
1143 unsigned MaxGlobalType = 0;
1145 MaxAlignment =
std::max(MaxAlignment, GV.getAlignment());
1147 if (GV.hasSection()) {
1149 unsigned &Entry = SectionMap[GV.getSection()];
1153 Entry = SectionMap.size();
1158 MaxAlignment =
std::max(MaxAlignment,
F.getAlignment());
1159 if (
F.hasSection()) {
1161 unsigned &Entry = SectionMap[
F.getSection()];
1165 Entry = SectionMap.size();
1170 unsigned &Entry = GCMap[
F.getGC()];
1174 Entry = GCMap.size();
1180 unsigned SimpleGVarAbbrev = 0;
1181 if (!M.global_empty()) {
1183 auto Abbv = std::make_shared<BitCodeAbbrev>();
1194 if (MaxAlignment == 0)
1197 unsigned MaxEncAlignment =
Log2_32(MaxAlignment)+1;
1201 if (SectionMap.empty())
1207 SimpleGVarAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1221 auto Abbv = std::make_shared<BitCodeAbbrev>();
1224 Abbv->Add(AbbrevOpToUse);
1225 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
1227 for (
const auto P : M.getSourceFileName())
1237 unsigned AbbrevToUse = 0;
1243 Vals.
push_back(addToStrtab(GV.getName()));
1246 Vals.
push_back(GV.getType()->getAddressSpace() << 2 | 2 | GV.isConstant());
1251 Vals.
push_back(GV.hasSection() ? SectionMap[GV.getSection()] : 0);
1252 if (GV.isThreadLocal() ||
1255 GV.isExternallyInitialized() ||
1258 GV.hasAttributes() ||
1263 Vals.
push_back(GV.isExternallyInitialized());
1272 AbbrevToUse = SimpleGVarAbbrev;
1293 Vals.
push_back(
F.hasSection() ? SectionMap[
F.getSection()] : 0);
1304 F.hasPersonalityFn() ? (VE.
getValueID(
F.getPersonalityFn()) + 1) : 0);
1309 unsigned AbbrevToUse = 0;
1319 Vals.
push_back(addToStrtab(A.getName()));
1322 Vals.
push_back(A.getType()->getAddressSpace());
1331 unsigned AbbrevToUse = 0;
1343 Vals.
push_back(
I.getType()->getAddressSpace());
1352 writeValueSymbolTableForwardDecl();
1358 if (
const auto *OBO = dyn_cast<OverflowingBinaryOperator>(V)) {
1359 if (OBO->hasNoSignedWrap())
1361 if (OBO->hasNoUnsignedWrap())
1363 }
else if (
const auto *PEO = dyn_cast<PossiblyExactOperator>(V)) {
1366 }
else if (
const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
1367 if (FPMO->hasAllowReassoc())
1369 if (FPMO->hasNoNaNs())
1371 if (FPMO->hasNoInfs())
1373 if (FPMO->hasNoSignedZeros())
1375 if (FPMO->hasAllowReciprocal())
1377 if (FPMO->hasAllowContract())
1379 if (FPMO->hasApproxFunc())
1386 void ModuleBitcodeWriter::writeValueAsMetadata(
1401 assert(!(MD && isa<LocalAsMetadata>(MD)) &&
1402 "Unexpected function-local metadata");
1411 unsigned ModuleBitcodeWriter::createDILocationAbbrev() {
1414 auto Abbv = std::make_shared<BitCodeAbbrev>();
1429 Abbrev = createDILocationAbbrev();
1442 unsigned ModuleBitcodeWriter::createGenericDINodeAbbrev() {
1445 auto Abbv = std::make_shared<BitCodeAbbrev>();
1460 Abbrev = createGenericDINodeAbbrev();
1475 return I < 0 ? ~(U << 1) : U << 1;
1481 const uint64_t
Version = 1 << 1;
1534 if (
const auto &DWARFAddressSpace = N->getDWARFAddressSpace())
1535 Record.
push_back(*DWARFAddressSpace + 1);
1546 const unsigned IsNotUsedInOldTypeRef = 0x2;
1572 const unsigned HasNoOldTypeRefs = 0x2;
1588 if (N->getRawChecksum()) {
1589 Record.
push_back(N->getRawChecksum()->Kind);
1597 auto Source = N->getRawSource();
1636 const uint64_t HasUnitFlag = 1 << 1;
1637 const uint64_t HasSPFlagsFlag = 1 << 2;
1654 Record.
push_back(N->getThisAdjustment());
1761 const uint64_t
Version = 2 << 1;
1795 const uint64_t HasAlignmentFlag = 1 << 1;
1827 const uint64_t
Version = 3 << 1;
1877 unsigned ModuleBitcodeWriter::createNamedMetadataAbbrev() {
1878 auto Abbv = std::make_shared<BitCodeAbbrev>();
1885 void ModuleBitcodeWriter::writeNamedMetadata(
1890 unsigned Abbrev = createNamedMetadataAbbrev();
1906 unsigned ModuleBitcodeWriter::createMetadataStringsAbbrev() {
1907 auto Abbv = std::make_shared<BitCodeAbbrev>();
1919 void ModuleBitcodeWriter::writeMetadataStrings(
1921 if (Strings.
empty())
1933 W.
EmitVBR(cast<MDString>(MD)->getLength(), 6);
1942 Blob.
append(cast<MDString>(MD)->getString());
1951 #define HANDLE_MDNODE_LEAF(CLASS) CLASS##AbbrevID, 1952 #include "llvm/IR/Metadata.def" 1956 void ModuleBitcodeWriter::writeMetadataRecords(
1958 std::vector<unsigned> *MDAbbrevs, std::vector<uint64_t> *IndexPos) {
1963 #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0; 1964 #include "llvm/IR/Metadata.def" 1969 if (
const MDNode *N = dyn_cast<MDNode>(MD)) {
1975 #define HANDLE_MDNODE_LEAF(CLASS) \ 1976 case Metadata::CLASS##Kind: \ 1978 write##CLASS(cast<CLASS>(N), Record, \ 1979 (*MDAbbrevs)[MetadataAbbrev::CLASS##AbbrevID]); \ 1981 write##CLASS(cast<CLASS>(N), Record, CLASS##Abbrev); \ 1983 #include "llvm/IR/Metadata.def" 1986 writeValueAsMetadata(cast<ValueAsMetadata>(MD), Record);
1990 void ModuleBitcodeWriter::writeModuleMetadata() {
1999 std::vector<unsigned> MDAbbrevs;
2002 MDAbbrevs[MetadataAbbrev::DILocationAbbrevID] = createDILocationAbbrev();
2003 MDAbbrevs[MetadataAbbrev::GenericDINodeAbbrevID] =
2004 createGenericDINodeAbbrev();
2006 auto Abbv = std::make_shared<BitCodeAbbrev>();
2010 unsigned OffsetAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2012 Abbv = std::make_shared<BitCodeAbbrev>();
2016 unsigned IndexAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2028 uint64_t Vals[] = {0, 0};
2038 std::vector<uint64_t> IndexPos;
2042 writeMetadataRecords(VE.
getNonMDStrings(), Record, &MDAbbrevs, &IndexPos);
2053 uint64_t PreviousValue = IndexOffsetRecordBitPos;
2054 for (
auto &Elt : IndexPos) {
2055 auto EltDelta = Elt - PreviousValue;
2056 PreviousValue = Elt;
2065 writeNamedMetadata(Record);
2067 auto AddDeclAttachedMetadata = [&](
const GlobalObject &GO) {
2070 pushGlobalMetadataAttachment(Record, GO);
2074 if (
F.isDeclaration() &&
F.hasMetadata())
2075 AddDeclAttachedMetadata(
F);
2079 if (GV.hasMetadata())
2080 AddDeclAttachedMetadata(GV);
2085 void ModuleBitcodeWriter::writeFunctionMetadata(
const Function &
F) {
2096 void ModuleBitcodeWriter::pushGlobalMetadataAttachment(
2101 for (
const auto &
I : MDs) {
2107 void ModuleBitcodeWriter::writeFunctionMetadataAttachment(
const Function &F) {
2113 pushGlobalMetadataAttachment(Record, F);
2124 I.getAllMetadataOtherThanDebugLoc(MDs);
2127 if (MDs.
empty())
continue;
2131 for (
unsigned i = 0, e = MDs.
size(); i != e; ++i) {
2142 void ModuleBitcodeWriter::writeModuleMetadataKinds() {
2150 if (Names.
empty())
return;
2154 for (
unsigned MDKindID = 0, e = Names.
size(); MDKindID != e; ++MDKindID) {
2166 void ModuleBitcodeWriter::writeOperandBundleTags() {
2183 for (
auto Tag : Tags) {
2193 void ModuleBitcodeWriter::writeSyncScopeNames() {
2202 for (
auto SSN : SSNs) {
2203 Record.
append(SSN.begin(), SSN.end());
2212 if ((int64_t)V >= 0)
2218 void ModuleBitcodeWriter::writeConstants(
unsigned FirstVal,
unsigned LastVal,
2220 if (FirstVal == LastVal)
return;
2224 unsigned AggregateAbbrev = 0;
2225 unsigned String8Abbrev = 0;
2226 unsigned CString7Abbrev = 0;
2227 unsigned CString6Abbrev = 0;
2231 auto Abbv = std::make_shared<BitCodeAbbrev>();
2235 AggregateAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2238 Abbv = std::make_shared<BitCodeAbbrev>();
2242 String8Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2244 Abbv = std::make_shared<BitCodeAbbrev>();
2248 CString7Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2250 Abbv = std::make_shared<BitCodeAbbrev>();
2254 CString6Abbrev = Stream.
EmitAbbrev(std::move(Abbv));
2260 Type *LastTy =
nullptr;
2261 for (
unsigned i = FirstVal; i != LastVal; ++i) {
2262 const Value *V = Vals[i].first;
2268 CONSTANTS_SETTYPE_ABBREV);
2272 if (
const InlineAsm *IA = dyn_cast<InlineAsm>(V)) {
2273 Record.
push_back(
unsigned(IA->hasSideEffects()) |
2274 unsigned(IA->isAlignStack()) << 1 |
2275 unsigned(IA->getDialect()&1) << 2);
2278 const std::string &AsmStr = IA->getAsmString();
2280 Record.
append(AsmStr.begin(), AsmStr.end());
2283 const std::string &ConstraintStr = IA->getConstraintString();
2285 Record.
append(ConstraintStr.begin(), ConstraintStr.end());
2291 unsigned Code = -1U;
2292 unsigned AbbrevToUse = 0;
2295 }
else if (isa<UndefValue>(C)) {
2297 }
else if (
const ConstantInt *IV = dyn_cast<ConstantInt>(C)) {
2298 if (IV->getBitWidth() <= 64) {
2299 uint64_t V = IV->getSExtValue();
2302 AbbrevToUse = CONSTANTS_INTEGER_ABBREV;
2308 unsigned NWords = IV->getValue().getActiveWords();
2309 const uint64_t *RawWords = IV->getValue().getRawData();
2310 for (
unsigned i = 0; i != NWords; ++i) {
2315 }
else if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
2317 Type *Ty = CFP->getType();
2319 Record.
push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
2323 APInt api = CFP->getValueAPF().bitcastToAPInt();
2325 Record.
push_back((p[1] << 48) | (p[0] >> 16));
2328 APInt api = CFP->getValueAPF().bitcastToAPInt();
2333 assert(0 &&
"Unknown FP type!");
2335 }
else if (isa<ConstantDataSequential>(C) &&
2336 cast<ConstantDataSequential>(C)->isString()) {
2346 AbbrevToUse = String8Abbrev;
2350 for (
unsigned i = 0; i != NumElts; ++i) {
2353 isCStr7 &= (V & 128) == 0;
2359 AbbrevToUse = CString6Abbrev;
2361 AbbrevToUse = CString7Abbrev;
2363 dyn_cast<ConstantDataSequential>(C)) {
2365 Type *EltTy = CDS->getType()->getElementType();
2366 if (isa<IntegerType>(EltTy)) {
2367 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2368 Record.
push_back(CDS->getElementAsInteger(i));
2370 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
2372 CDS->getElementAsAPFloat(i).bitcastToAPInt().getLimitedValue());
2374 }
else if (isa<ConstantAggregate>(C)) {
2378 AbbrevToUse = AggregateAbbrev;
2379 }
else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
2380 switch (CE->getOpcode()) {
2387 AbbrevToUse = CONSTANTS_CE_CAST_Abbrev;
2389 assert(CE->getNumOperands() == 2 &&
"Unknown constant expr!");
2399 case Instruction::FNeg: {
2400 assert(CE->getNumOperands() == 1 &&
"Unknown constant expr!");
2409 case Instruction::GetElementPtr: {
2411 const auto *GO = cast<GEPOperator>(
C);
2415 Record.
push_back((*Idx << 1) | GO->isInBounds());
2416 }
else if (GO->isInBounds())
2418 for (
unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
2430 case Instruction::ExtractElement:
2437 case Instruction::InsertElement:
2444 case Instruction::ShuffleVector:
2459 case Instruction::ICmp:
2460 case Instruction::FCmp:
2468 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
2479 Stream.
EmitRecord(Code, Record, AbbrevToUse);
2486 void ModuleBitcodeWriter::writeModuleConstants() {
2491 for (
unsigned i = 0, e = Vals.size(); i != e; ++i) {
2492 if (!isa<GlobalValue>(Vals[i].
first)) {
2493 writeConstants(i, Vals.size(),
true);
2507 bool ModuleBitcodeWriter::pushValueAndType(
const Value *V,
unsigned InstID,
2512 if (ValID >= InstID) {
2528 for (
auto &Input : Bundle.Inputs)
2529 pushValueAndType(Input, InstID, Record);
2538 void ModuleBitcodeWriter::pushValue(
const Value *V,
unsigned InstID,
2544 void ModuleBitcodeWriter::pushValueSigned(
const Value *V,
unsigned InstID,
2547 int64_t diff = ((int32_t)InstID - (int32_t)ValID);
2552 void ModuleBitcodeWriter::writeInstruction(
const Instruction &
I,
2556 unsigned AbbrevToUse = 0;
2562 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2563 AbbrevToUse = FUNCTION_INST_CAST_ABBREV;
2567 assert(isa<BinaryOperator>(I) &&
"Unknown instruction!");
2569 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2570 AbbrevToUse = FUNCTION_INST_BINOP_ABBREV;
2575 if (AbbrevToUse == FUNCTION_INST_BINOP_ABBREV)
2576 AbbrevToUse = FUNCTION_INST_BINOP_FLAGS_ABBREV;
2581 case Instruction::FNeg: {
2583 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2584 AbbrevToUse = FUNCTION_INST_UNOP_ABBREV;
2588 if (AbbrevToUse == FUNCTION_INST_UNOP_ABBREV)
2589 AbbrevToUse = FUNCTION_INST_UNOP_FLAGS_ABBREV;
2594 case Instruction::GetElementPtr: {
2596 AbbrevToUse = FUNCTION_INST_GEP_ABBREV;
2597 auto &GEPInst = cast<GetElementPtrInst>(
I);
2601 pushValueAndType(I.
getOperand(i), InstID, Vals);
2604 case Instruction::ExtractValue: {
2606 pushValueAndType(I.
getOperand(0), InstID, Vals);
2608 Vals.
append(EVI->idx_begin(), EVI->idx_end());
2611 case Instruction::InsertValue: {
2613 pushValueAndType(I.
getOperand(0), InstID, Vals);
2614 pushValueAndType(I.
getOperand(1), InstID, Vals);
2616 Vals.
append(IVI->idx_begin(), IVI->idx_end());
2621 pushValueAndType(I.
getOperand(1), InstID, Vals);
2623 pushValueAndType(I.
getOperand(0), InstID, Vals);
2625 case Instruction::ExtractElement:
2627 pushValueAndType(I.
getOperand(0), InstID, Vals);
2628 pushValueAndType(I.
getOperand(1), InstID, Vals);
2630 case Instruction::InsertElement:
2632 pushValueAndType(I.
getOperand(0), InstID, Vals);
2634 pushValueAndType(I.
getOperand(2), InstID, Vals);
2636 case Instruction::ShuffleVector:
2638 pushValueAndType(I.
getOperand(0), InstID, Vals);
2642 case Instruction::ICmp:
2643 case Instruction::FCmp: {
2646 pushValueAndType(I.
getOperand(0), InstID, Vals);
2659 if (NumOperands == 0)
2660 AbbrevToUse = FUNCTION_INST_RET_VOID_ABBREV;
2661 else if (NumOperands == 1) {
2662 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2663 AbbrevToUse = FUNCTION_INST_RET_VAL_ABBREV;
2665 for (
unsigned i = 0, e = NumOperands; i != e; ++i)
2666 pushValueAndType(I.
getOperand(i), InstID, Vals);
2670 case Instruction::Br:
2681 case Instruction::Switch:
2688 for (
auto Case : SI.
cases()) {
2694 case Instruction::IndirectBr:
2703 case Instruction::Invoke: {
2709 writeOperandBundles(II, InstID);
2718 pushValueAndType(Callee, InstID, Vals);
2721 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i)
2728 pushValueAndType(I.
getOperand(i), InstID, Vals);
2732 case Instruction::Resume:
2734 pushValueAndType(I.
getOperand(0), InstID, Vals);
2736 case Instruction::CleanupRet: {
2738 const auto &CRI = cast<CleanupReturnInst>(
I);
2739 pushValue(CRI.getCleanupPad(), InstID, Vals);
2740 if (CRI.hasUnwindDest())
2744 case Instruction::CatchRet: {
2746 const auto &CRI = cast<CatchReturnInst>(
I);
2747 pushValue(CRI.getCatchPad(), InstID, Vals);
2751 case Instruction::CleanupPad:
2752 case Instruction::CatchPad: {
2753 const auto &FuncletPad = cast<FuncletPadInst>(
I);
2756 pushValue(FuncletPad.getParentPad(), InstID, Vals);
2758 unsigned NumArgOperands = FuncletPad.getNumArgOperands();
2760 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op)
2761 pushValueAndType(FuncletPad.getArgOperand(
Op), InstID, Vals);
2764 case Instruction::CatchSwitch: {
2766 const auto &CatchSwitch = cast<CatchSwitchInst>(
I);
2768 pushValue(CatchSwitch.getParentPad(), InstID, Vals);
2770 unsigned NumHandlers = CatchSwitch.getNumHandlers();
2772 for (
const BasicBlock *CatchPadBB : CatchSwitch.handlers())
2775 if (CatchSwitch.hasUnwindDest())
2779 case Instruction::Unreachable:
2781 AbbrevToUse = FUNCTION_INST_UNREACHABLE_ABBREV;
2784 case Instruction::PHI: {
2785 const PHINode &PN = cast<PHINode>(
I);
2797 Stream.
EmitRecord(Code, Vals64, AbbrevToUse);
2802 case Instruction::LandingPad: {
2813 pushValueAndType(LP.
getClause(I), InstID, Vals);
2818 case Instruction::Alloca: {
2826 "not enough bits for maximum alignment");
2827 assert(AlignRecord < 1 << 5 &&
"alignment greater than 1 << 64");
2829 AlignRecord |= 1 << 6;
2836 if (cast<LoadInst>(I).
isAtomic()) {
2838 pushValueAndType(I.
getOperand(0), InstID, Vals);
2841 if (!pushValueAndType(I.
getOperand(0), InstID, Vals))
2842 AbbrevToUse = FUNCTION_INST_LOAD_ABBREV;
2847 if (cast<LoadInst>(I).
isAtomic()) {
2849 Vals.
push_back(getEncodedSyncScopeID(cast<LoadInst>(I).getSyncScopeID()));
2857 pushValueAndType(I.
getOperand(1), InstID, Vals);
2858 pushValueAndType(I.
getOperand(0), InstID, Vals);
2861 if (cast<StoreInst>(I).
isAtomic()) {
2864 getEncodedSyncScopeID(cast<StoreInst>(I).getSyncScopeID()));
2867 case Instruction::AtomicCmpXchg:
2869 pushValueAndType(I.
getOperand(0), InstID, Vals);
2870 pushValueAndType(I.
getOperand(1), InstID, Vals);
2876 getEncodedSyncScopeID(cast<AtomicCmpXchgInst>(I).getSyncScopeID()));
2881 case Instruction::AtomicRMW:
2883 pushValueAndType(I.
getOperand(0), InstID, Vals);
2890 getEncodedSyncScopeID(cast<AtomicRMWInst>(I).getSyncScopeID()));
2892 case Instruction::Fence:
2895 Vals.
push_back(getEncodedSyncScopeID(cast<FenceInst>(I).getSyncScopeID()));
2902 writeOperandBundles(&CI, InstID);
2922 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
2924 if (FTy->getParamType(i)->isLabelTy())
2931 if (FTy->isVarArg()) {
2938 case Instruction::VAArg:
2952 void ModuleBitcodeWriter::writeGlobalValueSymbolTable(
2958 VSTOffset -= bitcodeStartBit();
2959 assert((VSTOffset & 31) == 0 &&
"VST block not 32-bit aligned");
2963 Stream.
BackpatchWord(VSTOffsetPlaceholder, VSTOffset / 32 + 1);
2967 auto Abbv = std::make_shared<BitCodeAbbrev>();
2971 unsigned FnEntryAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
2983 uint64_t BitcodeIndex = FunctionToBitcodeIndex[&
F] - bitcodeStartBit();
2984 assert((BitcodeIndex & 31) == 0 &&
"function block not 32-bit aligned");
2988 Record[1] = BitcodeIndex / 32 + 1;
2997 void ModuleBitcodeWriter::writeFunctionLevelValueSymbolTable(
3012 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
3018 if (isa<BasicBlock>(
Name.getValue())) {
3021 AbbrevToUse = VST_BBENTRY_6_ABBREV;
3025 AbbrevToUse = VST_ENTRY_6_ABBREV;
3027 AbbrevToUse = VST_ENTRY_7_ABBREV;
3030 for (
const auto P :
Name.getKey())
3034 Stream.
EmitRecord(Code, NameVals, AbbrevToUse);
3041 void ModuleBitcodeWriter::writeUseList(
UseListOrder &&Order) {
3042 assert(Order.Shuffle.size() >= 2 &&
"Shuffle too small");
3044 if (isa<BasicBlock>(Order.V))
3054 void ModuleBitcodeWriter::writeUseListBlock(
const Function *F) {
3056 "Expected to be preserving use-list order");
3058 auto hasMore = [&]() {
3074 void ModuleBitcodeWriter::writeFunction(
3093 unsigned CstStart, CstEnd;
3095 writeConstants(CstStart, CstEnd,
false);
3098 writeFunctionMetadata(F);
3101 unsigned InstID = CstEnd;
3110 writeInstruction(*I, InstID, Vals);
3142 writeFunctionLevelValueSymbolTable(*Symtab);
3144 if (NeedsMetadataAttachment)
3145 writeFunctionMetadataAttachment(F);
3147 writeUseListBlock(&F);
3153 void ModuleBitcodeWriter::writeBlockInfo() {
3160 auto Abbv = std::make_shared<BitCodeAbbrev>();
3171 auto Abbv = std::make_shared<BitCodeAbbrev>();
3181 auto Abbv = std::make_shared<BitCodeAbbrev>();
3191 auto Abbv = std::make_shared<BitCodeAbbrev>();
3197 VST_BBENTRY_6_ABBREV)
3202 auto Abbv = std::make_shared<BitCodeAbbrev>();
3207 CONSTANTS_SETTYPE_ABBREV)
3212 auto Abbv = std::make_shared<BitCodeAbbrev>();
3216 CONSTANTS_INTEGER_ABBREV)
3221 auto Abbv = std::make_shared<BitCodeAbbrev>();
3229 CONSTANTS_CE_CAST_Abbrev)
3233 auto Abbv = std::make_shared<BitCodeAbbrev>();
3236 CONSTANTS_NULL_Abbrev)
3243 auto Abbv = std::make_shared<BitCodeAbbrev>();
3251 FUNCTION_INST_LOAD_ABBREV)
3255 auto Abbv = std::make_shared<BitCodeAbbrev>();
3260 FUNCTION_INST_UNOP_ABBREV)
3264 auto Abbv = std::make_shared<BitCodeAbbrev>();
3270 FUNCTION_INST_UNOP_FLAGS_ABBREV)
3274 auto Abbv = std::make_shared<BitCodeAbbrev>();
3280 FUNCTION_INST_BINOP_ABBREV)
3284 auto Abbv = std::make_shared<BitCodeAbbrev>();
3291 FUNCTION_INST_BINOP_FLAGS_ABBREV)
3295 auto Abbv = std::make_shared<BitCodeAbbrev>();
3302 FUNCTION_INST_CAST_ABBREV)
3307 auto Abbv = std::make_shared<BitCodeAbbrev>();
3310 FUNCTION_INST_RET_VOID_ABBREV)
3314 auto Abbv = std::make_shared<BitCodeAbbrev>();
3318 FUNCTION_INST_RET_VAL_ABBREV)
3322 auto Abbv = std::make_shared<BitCodeAbbrev>();
3325 FUNCTION_INST_UNREACHABLE_ABBREV)
3329 auto Abbv = std::make_shared<BitCodeAbbrev>();
3337 FUNCTION_INST_GEP_ABBREV)
3346 void IndexBitcodeWriter::writeModStrings() {
3352 auto Abbv = std::make_shared<BitCodeAbbrev>();
3357 unsigned Abbrev8Bit = Stream.
EmitAbbrev(std::move(Abbv));
3360 Abbv = std::make_shared<BitCodeAbbrev>();
3365 unsigned Abbrev7Bit = Stream.
EmitAbbrev(std::move(Abbv));
3368 Abbv = std::make_shared<BitCodeAbbrev>();
3373 unsigned Abbrev6Bit = Stream.
EmitAbbrev(std::move(Abbv));
3376 Abbv = std::make_shared<BitCodeAbbrev>();
3383 unsigned AbbrevHash = Stream.
EmitAbbrev(std::move(Abbv));
3387 [&](
const StringMapEntry<std::pair<uint64_t, ModuleHash>> &MPSE) {
3389 const auto &
Value = MPSE.getValue();
3391 unsigned AbbrevToUse = Abbrev8Bit;
3393 AbbrevToUse = Abbrev6Bit;
3395 AbbrevToUse = Abbrev7Bit;
3404 const auto &Hash =
Value.second;
3406 Vals.
assign(Hash.begin(), Hash.end());
3425 auto WriteVFuncIdVec = [&](uint64_t Ty,
3430 for (
auto &VF : VFs) {
3442 auto WriteConstVCallVec = [&](uint64_t Ty,
3444 for (
auto &
VC : VCs) {
3448 Record.
insert(Record.
end(),
VC.Args.begin(),
VC.Args.end());
3462 std::set<GlobalValue::GUID> &ReferencedTypeIds) {
3465 ReferencedTypeIds.insert(TT);
3467 auto GetReferencedTypesFromVFuncIdVec =
3469 for (
auto &VF : VFs)
3470 ReferencedTypeIds.insert(VF.GUID);
3476 auto GetReferencedTypesFromConstVCallVec =
3478 for (
auto &
VC : VCs)
3479 ReferencedTypeIds.insert(
VC.VFunc.GUID);
3490 NameVals.
insert(NameVals.
end(), args.begin(), args.end());
3514 const std::string &
Id,
3526 for (
auto &
W : Summary.
WPDRes)
3532 void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
3534 unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
3547 for (
auto &RI : FS->
refs())
3550 bool HasProfileData =
3552 for (
auto &ECI : FS->
calls()) {
3553 NameVals.
push_back(getValueId(ECI.first));
3555 NameVals.
push_back(static_cast<uint8_t>(ECI.second.Hotness));
3557 NameVals.
push_back(ECI.second.RelBlockFreq);
3560 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3573 void ModuleBitcodeWriterBase::writeModuleLevelReferences(
3575 unsigned FSModRefsAbbrev) {
3576 auto VI = Index->getValueInfo(V.
getGUID());
3589 unsigned SizeBeforeRefs = NameVals.
size();
3590 for (
auto &RI : VS->
refs())
3608 void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
3611 bool IsThinLTO =
true;
3613 mdconst::extract_or_null<ConstantInt>(M.
getModuleFlag(
"ThinLTO")))
3614 IsThinLTO = MD->getZExtValue();
3624 if (Index->enableSplitLTOUnit())
3628 if (Index->begin() == Index->end()) {
3633 for (
const auto &GVI : valueIds()) {
3639 auto Abbv = std::make_shared<BitCodeAbbrev>();
3650 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3653 Abbv = std::make_shared<BitCodeAbbrev>();
3667 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3670 Abbv = std::make_shared<BitCodeAbbrev>();
3676 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3679 Abbv = std::make_shared<BitCodeAbbrev>();
3684 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3703 writePerModuleFunctionSummaryRecord(NameVals, Summary, VE.
getValueID(&F),
3704 FSCallsAbbrev, FSCallsProfileAbbrev,
F);
3710 writeModuleLevelReferences(
G, NameVals, FSModRefsAbbrev);
3713 auto *Aliasee = A.getBaseObject();
3714 if (!Aliasee->hasName())
3720 auto *Summary = Index->getGlobalValueSummary(A);
3732 void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
3738 if (Index.withGlobalValueDeadStripping())
3740 if (Index.skipModuleByDistributedBackend())
3742 if (Index.hasSyntheticEntryCounts())
3744 if (Index.enableSplitLTOUnit())
3746 if (Index.partiallySplitLTOUnits())
3750 for (
const auto &GVI : valueIds()) {
3756 auto Abbv = std::make_shared<BitCodeAbbrev>();
3769 unsigned FSCallsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3772 Abbv = std::make_shared<BitCodeAbbrev>();
3784 unsigned FSCallsProfileAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3787 Abbv = std::make_shared<BitCodeAbbrev>();
3794 unsigned FSModRefsAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3797 Abbv = std::make_shared<BitCodeAbbrev>();
3803 unsigned FSAliasAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
3816 std::set<GlobalValue::GUID> ReferencedTypeIds;
3823 NameVals.
push_back(S.getOriginalName());
3828 forEachSummary([&](GVInfo I,
bool IsAliasee) {
3832 auto ValueId = getValueId(I.first);
3834 SummaryToValueIdMap[S] = *ValueId;
3842 if (
auto *AS = dyn_cast<AliasSummary>(S)) {
3849 if (
auto *
VS = dyn_cast<GlobalVarSummary>(S)) {
3851 NameVals.
push_back(Index.getModuleId(
VS->modulePath()));
3854 for (
auto &RI :
VS->refs()) {
3855 auto RefValueId = getValueId(RI.getGUID());
3865 MaybeEmitOriginalName(*S);
3869 auto *FS = cast<FunctionSummary>(S);
3874 NameVals.
push_back(Index.getModuleId(FS->modulePath()));
3884 unsigned Count = 0, ImmutableRefCnt = 0;
3885 for (
auto &RI : FS->refs()) {
3886 auto RefValueId = getValueId(RI.getGUID());
3890 if (RI.isReadOnly())
3894 NameVals[6] = Count;
3895 NameVals[7] = ImmutableRefCnt;
3897 bool HasProfileData =
false;
3898 for (
auto &EI : FS->calls()) {
3905 for (
auto &EI : FS->calls()) {
3909 auto CallValueId = getValueId(GUID);
3914 GUID = Index.getGUIDFromOriginalID(GUID);
3917 CallValueId = getValueId(GUID);
3930 auto *GVSum = Index.getGlobalValueSummary(GUID,
false);
3937 NameVals.
push_back(static_cast<uint8_t>(EI.second.Hotness));
3940 unsigned FSAbbrev = (HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
3947 MaybeEmitOriginalName(*S);
3950 for (
auto *AS : Aliases) {
3951 auto AliasValueId = SummaryToValueIdMap[AS];
3954 NameVals.
push_back(Index.getModuleId(AS->modulePath()));
3956 auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
3963 MaybeEmitOriginalName(*AS);
3965 if (
auto *FS = dyn_cast<FunctionSummary>(&AS->getAliasee()))
3969 if (!Index.cfiFunctionDefs().empty()) {
3970 for (
auto &S : Index.cfiFunctionDefs()) {
3978 if (!Index.cfiFunctionDecls().empty()) {
3979 for (
auto &S : Index.cfiFunctionDecls()) {
3989 for (
auto &
T : ReferencedTypeIds) {
3990 auto TidIter = Index.typeIds().equal_range(
T);
3991 for (
auto It = TidIter.first; It != TidIter.second; ++It) {
4008 auto Abbv = std::make_shared<BitCodeAbbrev>();
4012 auto StringAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4014 "LLVM" LLVM_VERSION_STRING, StringAbbrev);
4017 Abbv = std::make_shared<BitCodeAbbrev>();
4020 auto EpochAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4026 void ModuleBitcodeWriter::writeModuleHash(
size_t BlockStartPos) {
4032 Buffer.size() - BlockStartPos));
4034 for (
int Pos = 0; Pos < 20; Pos += 4) {
4051 size_t BlockStartPos = Buffer.size();
4053 writeModuleVersion();
4059 writeAttributeGroupTable();
4062 writeAttributeTable();
4074 writeModuleConstants();
4077 writeModuleMetadataKinds();
4080 writeModuleMetadata();
4084 writeUseListBlock(
nullptr);
4086 writeOperandBundleTags();
4087 writeSyncScopeNames();
4093 writeFunction(*F, FunctionToBitcodeIndex);
4098 writePerModuleGlobalValueSummary();
4100 writeGlobalValueSymbolTable(FunctionToBitcodeIndex);
4102 writeModuleHash(BlockStartPos);
4135 DARWIN_CPU_ARCH_ABI64 = 0x01000000,
4136 DARWIN_CPU_TYPE_X86 = 7,
4137 DARWIN_CPU_TYPE_ARM = 12,
4138 DARWIN_CPU_TYPE_POWERPC = 18
4143 CPUType = DARWIN_CPU_TYPE_X86 | DARWIN_CPU_ARCH_ABI64;
4145 CPUType = DARWIN_CPU_TYPE_X86;
4147 CPUType = DARWIN_CPU_TYPE_POWERPC;
4149 CPUType = DARWIN_CPU_TYPE_POWERPC | DARWIN_CPU_ARCH_ABI64;
4151 CPUType = DARWIN_CPU_TYPE_ARM;
4155 "Expected header size to be reserved");
4168 while (Buffer.
size() & 15)
4175 Stream.
Emit((
unsigned)
'B', 8);
4176 Stream.
Emit((
unsigned)
'C', 8);
4177 Stream.
Emit(0x0, 4);
4178 Stream.
Emit(0xC, 4);
4179 Stream.
Emit(0xE, 4);
4180 Stream.
Emit(0xD, 4);
4190 void BitcodeWriter::writeBlob(
unsigned Block,
unsigned Record,
StringRef Blob) {
4193 auto Abbv = std::make_shared<BitCodeAbbrev>();
4196 auto AbbrevNo = Stream->
EmitAbbrev(std::move(Abbv));
4204 assert(!WroteStrtab && !WroteSymtab);
4216 if (!T || !T->hasMCAsmParser())
4238 std::vector<char> Strtab;
4240 Strtab.resize(StrtabBuilder.
getSize());
4241 StrtabBuilder.
write((uint8_t *)Strtab.data());
4244 {Strtab.data(), Strtab.size()});
4255 bool ShouldPreserveUseListOrder,
4265 Mods.push_back(const_cast<Module *>(&M));
4267 ModuleBitcodeWriter ModuleWriter(M, Buffer, StrtabBuilder, *Stream,
4268 ShouldPreserveUseListOrder, Index,
4269 GenerateHash, ModHash);
4270 ModuleWriter.write();
4275 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
4276 IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index,
4277 ModuleToSummariesForIndex);
4278 IndexWriter.write();
4283 bool ShouldPreserveUseListOrder,
4292 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
4296 Writer.
writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
4301 if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
4311 writeModuleVersion();
4317 writeCombinedGlobalValueSummary();
4328 const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
4333 Writer.
writeIndex(&Index, ModuleToSummariesForIndex);
4342 class ThinLinkBitcodeWriter :
public ModuleBitcodeWriterBase {
4352 : ModuleBitcodeWriterBase(M, StrtabBuilder, Stream,
4354 ModHash(&ModHash) {}
4359 void writeSimplifiedModuleInfo();
4369 void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
4381 auto Abbv = std::make_shared<BitCodeAbbrev>();
4384 Abbv->Add(AbbrevOpToUse);
4385 unsigned FilenameAbbrev = Stream.
EmitAbbrev(std::move(Abbv));
4454 writeModuleVersion();
4456 writeSimplifiedModuleInfo();
4458 writePerModuleGlobalValueSummary();
4476 Mods.push_back(const_cast<Module *>(&M));
4478 ThinLinkBitcodeWriter ThinLinkWriter(M, StrtabBuilder, *Stream, Index,
4480 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
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.
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.
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.
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.
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.
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
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
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
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()
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static void writeIdentificationBlock(BitstreamWriter &Stream)
Create the "IDENTIFICATION_BLOCK_ID" containing a single string with the current llvm version...
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.
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
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.
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.
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
static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, FunctionSummary *FS)
Write the function type metadata related records that need to appear before a function summary entry ...
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
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
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.
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...
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.
DIExpression * getExpression() const
BasicBlock * getDefaultDest() const
element_iterator element_end() const
iterator_range< named_metadata_iterator > named_metadata()
unsigned immutableRefCount() const
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...
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
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.
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 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
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.
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)
unsigned getNumArgOperands() const
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)
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
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
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
DITypeRef getType() const
DILocalScope * getScope() const
Get the local scope for this label.
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.
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.
GVarFlags varflags() const
bool named_metadata_empty() const
DITypeRefArray getTypeArray() const
DIDerivedType * getDiscriminator() const
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