[llvm] r282630 - Refactor the ProfileSummaryInfo to use doInitialization and doFinalization to handle Module update.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 14:00:59 PDT 2016
Author: dehao
Date: Wed Sep 28 16:00:58 2016
New Revision: 282630
URL: http://llvm.org/viewvc/llvm-project?rev=282630&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/trunk/lib/Transforms/IPO/Inliner.cpp
Modified: llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h?rev=282630&r1=282629&r2=282630&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h Wed Sep 28 16:00:58 2016
@@ -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();
}
Modified: llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp?rev=282630&r1=282629&r2=282630&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp Wed Sep 28 16:00:58 2016
@@ -228,7 +228,7 @@ ModuleSummaryIndexWrapperPass::ModuleSum
}
bool ModuleSummaryIndexWrapperPass::runOnModule(Module &M) {
- auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(M);
+ auto &PSI = *getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
Index = buildModuleSummaryIndex(
M,
[this](const Function &F) {
Modified: llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp?rev=282630&r1=282629&r2=282630&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp Wed Sep 28 16:00:58 2016
@@ -57,7 +57,7 @@ static uint64_t getMinCountForPercentile
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::computeThreshol
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(uin
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::ProfileSu
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
Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=282630&r1=282629&r2=282630&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Wed Sep 28 16:00:58 2016
@@ -378,7 +378,7 @@ ProcessThinLTOModule(Module &TheModule,
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);
}
Modified: llvm/trunk/lib/Transforms/IPO/Inliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Inliner.cpp?rev=282630&r1=282629&r2=282630&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Inliner.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Inliner.cpp Wed Sep 28 16:00:58 2016
@@ -634,7 +634,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallG
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
More information about the llvm-commits
mailing list