Index: include/llvm/Analysis/ProfileSummaryInfo.h =================================================================== --- include/llvm/Analysis/ProfileSummaryInfo.h +++ include/llvm/Analysis/ProfileSummaryInfo.h @@ -40,7 +40,7 @@ // units. This would require making this depend on BFI. class ProfileSummaryInfo { private: - Module &M; + Module *M; std::unique_ptr Summary; void computeSummary(); void computeThresholds(); @@ -48,7 +48,7 @@ Optional HotCountThreshold, ColdCountThreshold; public: - ProfileSummaryInfo(Module &M) : M(M) {} + ProfileSummaryInfo(Module *M) : M(M) {} ProfileSummaryInfo(ProfileSummaryInfo &&Arg) : M(Arg.M), Summary(std::move(Arg.Summary)) {} /// \brief Returns true if \p F is a hot function. @@ -59,6 +59,8 @@ bool isHotCount(uint64_t C); /// \brief Returns true if count \p C is considered cold. bool isColdCount(uint64_t C); + /// \brief Checks if \p newM is up-to-date, if not, invalidate Summary. + void resetModule(Module *NewM); }; /// An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo. Index: lib/Analysis/ProfileSummaryInfo.cpp =================================================================== --- lib/Analysis/ProfileSummaryInfo.cpp +++ lib/Analysis/ProfileSummaryInfo.cpp @@ -57,7 +57,7 @@ void ProfileSummaryInfo::computeSummary() { if (Summary) return; - auto *SummaryMD = M.getProfileSummary(); + auto *SummaryMD = M->getProfileSummary(); if (!SummaryMD) return; Summary.reset(ProfileSummary::getFromMD(SummaryMD)); @@ -113,6 +113,13 @@ getMinCountForPercentile(DetailedSummary, ProfileSummaryCutoffCold); } +void ProfileSummaryInfo::resetModule(Module *newM) { + if (newM == M) + return; + M = newM; + Summary.reset(nullptr); +} + bool ProfileSummaryInfo::isHotCount(uint64_t C) { if (!HotCountThreshold) computeThresholds(); @@ -127,7 +134,9 @@ ProfileSummaryInfo *ProfileSummaryInfoWrapperPass::getPSI(Module &M) { if (!PSI) - PSI.reset(new ProfileSummaryInfo(M)); + PSI.reset(new ProfileSummaryInfo(&M)); + else + PSI->resetM(&M); return PSI.get(); } @@ -142,7 +151,7 @@ char ProfileSummaryAnalysis::PassID; ProfileSummaryInfo ProfileSummaryAnalysis::run(Module &M, ModuleAnalysisManager &) { - return ProfileSummaryInfo(M); + return ProfileSummaryInfo(&M); } // FIXME: This only tests isHotFunction and isColdFunction and not the