diff options
author | Teresa Johnson <tejohnson@google.com> | 2018-07-19 22:25:56 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2018-07-19 22:25:56 +0000 |
commit | 0c432b1a70d29e60c3428198dd6dba9ebcc91851 (patch) | |
tree | 1620c6ad5124747d0ca5c3308359cd0bed510b73 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | c12c5d421fc92a8f689ce0cabc4962f69774d1be (diff) | |
download | bcm5719-llvm-0c432b1a70d29e60c3428198dd6dba9ebcc91851.tar.gz bcm5719-llvm-0c432b1a70d29e60c3428198dd6dba9ebcc91851.zip |
[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
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-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(); |