diff options
| author | Dehao Chen <dehao@google.com> | 2016-09-28 21:00:58 +0000 |
|---|---|---|
| committer | Dehao Chen <dehao@google.com> | 2016-09-28 21:00:58 +0000 |
| commit | 5461d8bdb5acdc92e1f4c18c380a637d8d2be82e (patch) | |
| tree | dff83a3a7e01a90fbf4fbe0c8ddae57812d1aa67 /llvm | |
| parent | 6e4bedc0d7865d9afa36f31a12496a66238e8358 (diff) | |
| download | bcm5719-llvm-5461d8bdb5acdc92e1f4c18c380a637d8d2be82e.tar.gz bcm5719-llvm-5461d8bdb5acdc92e1f4c18c380a637d8d2be82e.zip | |
Refactor the ProfileSummaryInfo to use doInitialization and doFinalization to handle Module update.
Summary: This refactors the change in r282616
Reviewers: davidxl, eraman, mehdi_amini
Subscribers: mehdi_amini, davide, llvm-commits
Differential Revision: https://reviews.llvm.org/D25041
llvm-svn: 282630
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/Analysis/ProfileSummaryInfo.h | 13 | ||||
| -rw-r--r-- | llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Analysis/ProfileSummaryInfo.cpp | 29 | ||||
| -rw-r--r-- | llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/Inliner.cpp | 2 |
5 files changed, 23 insertions, 25 deletions
diff --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h index decb0ad86bd..6d4f5829685 100644 --- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h +++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h @@ -40,7 +40,7 @@ class ProfileSummary; // units. This would require making this depend on BFI. class ProfileSummaryInfo { private: - Module *M; + Module &M; std::unique_ptr<ProfileSummary> Summary; void computeSummary(); void computeThresholds(); @@ -48,7 +48,7 @@ private: Optional<uint64_t> 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 @@ public: 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 @@ public: 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(); } diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index c736c6aa169..5a9d9a6604f 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -228,7 +228,7 @@ ModuleSummaryIndexWrapperPass::ModuleSummaryIndexWrapperPass() } bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) { - auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(M); + auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(); Index = buildModuleSummaryIndex( M, [this](const Function &F) { diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp index ecfa5c2a3fc..df1414d6811 100644 --- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp +++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp @@ -57,7 +57,7 @@ static uint64_t getMinCountForPercentile(SummaryEntryVector &DS, 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 @@ void ProfileSummaryInfo::computeThresholds() { 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 @@ bool ProfileSummaryInfo::isColdCount(uint64_t C) { 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 @@ ProfileSummaryInfoWrapperPass::ProfileSummaryInfoWrapperPass() 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 diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 49b73e117d9..f4232dc2f89 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -378,7 +378,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index, SmallVector<char, 128> OutputBuffer; { raw_svector_ostream OS(OutputBuffer); - ProfileSummaryInfo PSI(&TheModule); + ProfileSummaryInfo PSI(TheModule); auto Index = buildModuleSummaryIndex(TheModule, nullptr, nullptr); WriteBitcodeToFile(&TheModule, OS, true, &Index); } diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp index 7aa1e187d31..ceaa214201f 100644 --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -634,7 +634,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG, bool Inliner::inlineCalls(CallGraphSCC &SCC) { CallGraph &CG = getAnalysis<CallGraphWrapperPass>().getCallGraph(); ACT = &getAnalysis<AssumptionCacheTracker>(); - PSI = getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(CG.getModule()); + PSI = getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(); auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().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 |

