@@ -494,28 +494,28 @@ struct CallSiteInfo {
494494 // / Whether all call sites represented by this CallSiteInfo, including those
495495 // / in summaries, have been devirtualized. This starts off as true because a
496496 // / default constructed CallSiteInfo represents no call sites.
497+ // /
498+ // / If at the end of the pass there are still undevirtualized calls, we will
499+ // / need to add a use of llvm.type.test to each of the function summaries in
500+ // / the vector.
497501 bool AllCallSitesDevirted = true ;
498502
499503 // These fields are used during the export phase of ThinLTO and reflect
500504 // information collected from function summaries.
501505
502- // / Whether any function summary contains an llvm.assume(llvm.type.test) for
503- // / this slot.
504- bool SummaryHasTypeTestAssumeUsers = false ;
505-
506506 // / CFI-specific: a vector containing the list of function summaries that use
507507 // / the llvm.type.checked.load intrinsic and therefore will require
508508 // / resolutions for llvm.type.test in order to implement CFI checks if
509- // / devirtualization was unsuccessful. If devirtualization was successful, the
510- // / pass will clear this vector by calling markDevirt(). If at the end of the
511- // / pass the vector is non-empty, we will need to add a use of llvm.type.test
512- // / to each of the function summaries in the vector.
509+ // / devirtualization was unsuccessful.
513510 std::vector<FunctionSummary *> SummaryTypeCheckedLoadUsers;
511+
512+ // / A vector containing the list of function summaries that use
513+ // / assume(llvm.type.test).
514514 std::vector<FunctionSummary *> SummaryTypeTestAssumeUsers;
515515
516516 bool isExported () const {
517- return SummaryHasTypeTestAssumeUsers ||
518- !SummaryTypeCheckedLoadUsers .empty ();
517+ return !SummaryTypeCheckedLoadUsers. empty () ||
518+ !SummaryTypeTestAssumeUsers .empty ();
519519 }
520520
521521 void addSummaryTypeCheckedLoadUser (FunctionSummary *FS) {
@@ -525,16 +525,10 @@ struct CallSiteInfo {
525525
526526 void addSummaryTypeTestAssumeUser (FunctionSummary *FS) {
527527 SummaryTypeTestAssumeUsers.push_back (FS);
528- SummaryHasTypeTestAssumeUsers = true ;
529528 AllCallSitesDevirted = false ;
530529 }
531530
532- void markDevirt () {
533- AllCallSitesDevirted = true ;
534-
535- // As explained in the comment for SummaryTypeCheckedLoadUsers.
536- SummaryTypeCheckedLoadUsers.clear ();
537- }
531+ void markDevirt () { AllCallSitesDevirted = true ; }
538532};
539533
540534// Call site information collected for a specific VTableSlot.
@@ -2465,11 +2459,14 @@ bool DevirtModule::run() {
24652459 if (ExportSummary && isa<MDString>(S.first .TypeID )) {
24662460 auto GUID = GlobalValue::getGUIDAssumingExternalLinkage (
24672461 cast<MDString>(S.first .TypeID )->getString ());
2468- for (auto *FS : S.second .CSInfo .SummaryTypeCheckedLoadUsers )
2469- FS->addTypeTest (GUID);
2462+ auto AddTypeTestsForTypeCheckedLoads = [&](CallSiteInfo &CSI) {
2463+ if (!CSI.AllCallSitesDevirted )
2464+ for (auto *FS : CSI.SummaryTypeCheckedLoadUsers )
2465+ FS->addTypeTest (GUID);
2466+ };
2467+ AddTypeTestsForTypeCheckedLoads (S.second .CSInfo );
24702468 for (auto &CCS : S.second .ConstCSInfo )
2471- for (auto *FS : CCS.second .SummaryTypeCheckedLoadUsers )
2472- FS->addTypeTest (GUID);
2469+ AddTypeTestsForTypeCheckedLoads (CCS.second );
24732470 }
24742471 }
24752472
0 commit comments