Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3358,14 +3358,10 @@ /// 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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()));