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,8 +59,6 @@ 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. @@ -71,7 +69,12 @@ static char ID; ProfileSummaryInfoWrapperPass(); - ProfileSummaryInfo *getPSI(Module &M); + ProfileSummaryInfo *getPSI() { + return &*PSI; + } + + bool doInitialization(Module &M) override; + bool doFinalization(Module &M) override; void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesAll(); } Index: lib/Analysis/ModuleSummaryAnalysis.cpp =================================================================== --- lib/Analysis/ModuleSummaryAnalysis.cpp +++ lib/Analysis/ModuleSummaryAnalysis.cpp @@ -228,7 +228,7 @@ } bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) { - auto &PSI = *getAnalysis().getPSI(M); + auto &PSI = *getAnalysis().getPSI(); Index = buildModuleSummaryIndex( M, [this](const Function &F) { 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,13 +113,6 @@ 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(); @@ -132,14 +125,6 @@ return ColdCountThreshold && C <= ColdCountThreshold.getValue(); } -ProfileSummaryInfo *ProfileSummaryInfoWrapperPass::getPSI(Module &M) { - if (!PSI) - PSI.reset(new ProfileSummaryInfo(&M)); - else - PSI->resetModule(&M); - return PSI.get(); -} - INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info", "Profile summary info", false, true) @@ -148,10 +133,20 @@ initializeProfileSummaryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); } +bool ProfileSummaryInfoWrapperPass::doInitialization(Module &M) { + PSI.reset(new ProfileSummaryInfo(M)); + return false; +} + +bool ProfileSummaryInfoWrapperPass::doFinalization(Module &M) { + PSI.reset(); + return false; +} + 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 Index: lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- lib/LTO/ThinLTOCodeGenerator.cpp +++ lib/LTO/ThinLTOCodeGenerator.cpp @@ -378,7 +378,7 @@ SmallVector OutputBuffer; { raw_svector_ostream OS(OutputBuffer); - ProfileSummaryInfo PSI(&TheModule); + ProfileSummaryInfo PSI(TheModule); auto Index = buildModuleSummaryIndex(TheModule, nullptr, nullptr); WriteBitcodeToFile(&TheModule, OS, true, &Index); } Index: lib/Transforms/IPO/Inliner.cpp =================================================================== --- lib/Transforms/IPO/Inliner.cpp +++ lib/Transforms/IPO/Inliner.cpp @@ -634,7 +634,7 @@ bool Inliner::inlineCalls(CallGraphSCC &SCC) { CallGraph &CG = getAnalysis().getCallGraph(); ACT = &getAnalysis(); - PSI = getAnalysis().getPSI(CG.getModule()); + PSI = getAnalysis().getPSI(); auto &TLI = getAnalysis().getTLI(); // We compute dedicated AA results for each function in the SCC as needed. We // use a lambda referencing external objects so that they live long enough to