diff options
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 9072be68372..be75df0820d 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3353,10 +3353,14 @@ void IndexBitcodeWriter::writeModStrings() { /// Write the function type metadata related records that need to appear before /// a function summary entry (whether per-module or combined). -static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, - FunctionSummary *FS) { - if (!FS->type_tests().empty()) +static void writeFunctionTypeMetadataRecords( + BitstreamWriter &Stream, FunctionSummary *FS, + std::set<GlobalValue::GUID> &ReferencedTypeIds) { + if (!FS->type_tests().empty()) { Stream.EmitRecord(bitc::FS_TYPE_TESTS, FS->type_tests()); + for (auto &TT : FS->type_tests()) + ReferencedTypeIds.insert(TT); + } SmallVector<uint64_t, 64> Record; @@ -3368,6 +3372,7 @@ static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, for (auto &VF : VFs) { Record.push_back(VF.GUID); Record.push_back(VF.Offset); + ReferencedTypeIds.insert(VF.GUID); } Stream.EmitRecord(Ty, Record); }; @@ -3382,6 +3387,7 @@ static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, for (auto &VC : VCs) { Record.clear(); Record.push_back(VC.VFunc.GUID); + ReferencedTypeIds.insert(VC.VFunc.GUID); Record.push_back(VC.VFunc.Offset); Record.insert(Record.end(), VC.Args.begin(), VC.Args.end()); Stream.EmitRecord(Ty, Record); @@ -3447,7 +3453,8 @@ void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord( NameVals.push_back(ValueID); FunctionSummary *FS = cast<FunctionSummary>(Summary); - writeFunctionTypeMetadataRecords(Stream, FS); + std::set<GlobalValue::GUID> ReferencedTypeIds; + writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds); NameVals.push_back(getEncodedGVSummaryFlags(FS->flags())); NameVals.push_back(FS->instCount()); @@ -3702,6 +3709,10 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { SmallVector<uint64_t, 64> NameVals; + // Set that will be populated during call to writeFunctionTypeMetadataRecords + // with the type ids referenced by this index file. + std::set<GlobalValue::GUID> ReferencedTypeIds; + // For local linkage, we also emit the original name separately // immediately after the record. auto MaybeEmitOriginalName = [&](GlobalValueSummary &S) { @@ -3753,7 +3764,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { } auto *FS = cast<FunctionSummary>(S); - writeFunctionTypeMetadataRecords(Stream, FS); + writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds); NameVals.push_back(*ValueId); NameVals.push_back(Index.getModuleId(FS->modulePath())); @@ -3862,6 +3873,9 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { if (!Index.typeIds().empty()) { for (auto &S : Index.typeIds()) { + // Skip if not referenced in any GV summary within this index file. + if (!ReferencedTypeIds.count(GlobalValue::getGUID(S.first))) + continue; writeTypeIdSummaryRecord(NameVals, StrtabBuilder, S.first, S.second); Stream.EmitRecord(bitc::FS_TYPE_ID, NameVals); NameVals.clear(); |