From 7e880a4f6de50b3f72156cb72c0749862b2d9ceb Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 19 Sep 2018 18:51:25 +0000 Subject: [PATCH] [ThinLTO] Extract getReferencedTypeIds from [NFC] Summary: Refactoring before D52201 Reviewers: eugenis, tejohnson Subscribers: pcc, inglorion, hiraditya, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D52203 llvm-svn: 342573 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 45 ++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 1262401..576db06 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3358,14 +3358,10 @@ 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, - std::set &ReferencedTypeIds) { - if (!FS->type_tests().empty()) { +static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream, + FunctionSummary *FS) { + 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; @@ -3377,7 +3373,6 @@ static void writeFunctionTypeMetadataRecords( for (auto &VF : VFs) { Record.push_back(VF.GUID); Record.push_back(VF.Offset); - ReferencedTypeIds.insert(VF.GUID); } Stream.EmitRecord(Ty, Record); }; @@ -3392,7 +3387,6 @@ static void writeFunctionTypeMetadataRecords( 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); @@ -3405,6 +3399,33 @@ static void writeFunctionTypeMetadataRecords( FS->type_checked_load_const_vcalls()); } +/// Collect type IDs from type tests used by function. +static void +getReferencedTypeIds(FunctionSummary *FS, + std::set &ReferencedTypeIds) { + if (!FS->type_tests().empty()) + for (auto &TT : FS->type_tests()) + ReferencedTypeIds.insert(TT); + + auto GetReferencedTypesFromVFuncIdVec = + [&](ArrayRef VFs) { + for (auto &VF : VFs) + ReferencedTypeIds.insert(VF.GUID); + }; + + GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls()); + GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls()); + + auto GetReferencedTypesFromConstVCallVec = + [&](ArrayRef VCs) { + for (auto &VC : VCs) + ReferencedTypeIds.insert(VC.VFunc.GUID); + }; + + GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls()); + GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls()); +} + static void writeWholeProgramDevirtResolutionByArg( SmallVector &NameVals, const std::vector &args, const WholeProgramDevirtResolution::ByArg &ByArg) { @@ -3458,8 +3479,7 @@ void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord( NameVals.push_back(ValueID); FunctionSummary *FS = cast(Summary); - std::set ReferencedTypeIds; - writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds); + writeFunctionTypeMetadataRecords(Stream, FS); NameVals.push_back(getEncodedGVSummaryFlags(FS->flags())); NameVals.push_back(FS->instCount()); @@ -3769,7 +3789,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { } auto *FS = cast(S); - writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds); + writeFunctionTypeMetadataRecords(Stream, FS); + getReferencedTypeIds(FS, ReferencedTypeIds); NameVals.push_back(*ValueId); NameVals.push_back(Index.getModuleId(FS->modulePath())); -- 2.7.4