From 0c432b1a70d29e60c3428198dd6dba9ebcc91851 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 19 Jul 2018 22:25:56 +0000 Subject: [ThinLTO] Only emit referenced type id records in index files Summary: Currently all type ids are emitted into the index file when it is written. For distributed ThinLTO, that meant that all type ids were being duplicated into every single distributed index file, regardless of whether they were referenced, leading to huge amounts of unnecessary duplication and size bloat. Keep track of the type id GUIDs actually referenced by the GV summary records being emitted, and only emit those type IDs. Add a new test, and fix test/Assembler/thinlto-summary.ll so that all type ids are referenced to prevent deletion in that test. Reviewers: pcc Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, vitalybuka, llvm-commits Differential Revision: https://reviews.llvm.org/D49565 llvm-svn: 337503 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') 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 &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 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(Summary); - writeFunctionTypeMetadataRecords(Stream, FS); + std::set ReferencedTypeIds; + writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds); NameVals.push_back(getEncodedGVSummaryFlags(FS->flags())); NameVals.push_back(FS->instCount()); @@ -3702,6 +3709,10 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { SmallVector NameVals; + // Set that will be populated during call to writeFunctionTypeMetadataRecords + // with the type ids referenced by this index file. + std::set 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(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(); -- cgit v1.2.3