llvm.org GIT mirror llvm / 3c27669
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342573 91177308-0d34-0410-b5e6-96231b3b80d8 Vitaly Buka 1 year, 9 months ago
1 changed file(s) with 33 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
33573357
33583358 /// Write the function type metadata related records that need to appear before
33593359 /// a function summary entry (whether per-module or combined).
3360 static void writeFunctionTypeMetadataRecords(
3361 BitstreamWriter &Stream, FunctionSummary *FS,
3362 std::set &ReferencedTypeIds) {
3363 if (!FS->type_tests().empty()) {
3360 static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream,
3361 FunctionSummary *FS) {
3362 if (!FS->type_tests().empty())
33643363 Stream.EmitRecord(bitc::FS_TYPE_TESTS, FS->type_tests());
3365 for (auto &TT : FS->type_tests())
3366 ReferencedTypeIds.insert(TT);
3367 }
33683364
33693365 SmallVector Record;
33703366
33763372 for (auto &VF : VFs) {
33773373 Record.push_back(VF.GUID);
33783374 Record.push_back(VF.Offset);
3379 ReferencedTypeIds.insert(VF.GUID);
33803375 }
33813376 Stream.EmitRecord(Ty, Record);
33823377 };
33913386 for (auto &VC : VCs) {
33923387 Record.clear();
33933388 Record.push_back(VC.VFunc.GUID);
3394 ReferencedTypeIds.insert(VC.VFunc.GUID);
33953389 Record.push_back(VC.VFunc.Offset);
33963390 Record.insert(Record.end(), VC.Args.begin(), VC.Args.end());
33973391 Stream.EmitRecord(Ty, Record);
34023396 FS->type_test_assume_const_vcalls());
34033397 WriteConstVCallVec(bitc::FS_TYPE_CHECKED_LOAD_CONST_VCALL,
34043398 FS->type_checked_load_const_vcalls());
3399 }
3400
3401 /// Collect type IDs from type tests used by function.
3402 static void
3403 getReferencedTypeIds(FunctionSummary *FS,
3404 std::set &ReferencedTypeIds) {
3405 if (!FS->type_tests().empty())
3406 for (auto &TT : FS->type_tests())
3407 ReferencedTypeIds.insert(TT);
3408
3409 auto GetReferencedTypesFromVFuncIdVec =
3410 [&](ArrayRef VFs) {
3411 for (auto &VF : VFs)
3412 ReferencedTypeIds.insert(VF.GUID);
3413 };
3414
3415 GetReferencedTypesFromVFuncIdVec(FS->type_test_assume_vcalls());
3416 GetReferencedTypesFromVFuncIdVec(FS->type_checked_load_vcalls());
3417
3418 auto GetReferencedTypesFromConstVCallVec =
3419 [&](ArrayRef VCs) {
3420 for (auto &VC : VCs)
3421 ReferencedTypeIds.insert(VC.VFunc.GUID);
3422 };
3423
3424 GetReferencedTypesFromConstVCallVec(FS->type_test_assume_const_vcalls());
3425 GetReferencedTypesFromConstVCallVec(FS->type_checked_load_const_vcalls());
34053426 }
34063427
34073428 static void writeWholeProgramDevirtResolutionByArg(
34573478 NameVals.push_back(ValueID);
34583479
34593480 FunctionSummary *FS = cast(Summary);
3460 std::set ReferencedTypeIds;
3461 writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds);
3481 writeFunctionTypeMetadataRecords(Stream, FS);
34623482
34633483 NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
34643484 NameVals.push_back(FS->instCount());
37683788 }
37693789
37703790 auto *FS = cast(S);
3771 writeFunctionTypeMetadataRecords(Stream, FS, ReferencedTypeIds);
3791 writeFunctionTypeMetadataRecords(Stream, FS);
3792 getReferencedTypeIds(FS, ReferencedTypeIds);
37723793
37733794 NameVals.push_back(*ValueId);
37743795 NameVals.push_back(Index.getModuleId(FS->modulePath()));