[llvm] r282616 - Fix the bug when -compile-twice is specified, the PSI will be invalidated.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 11:41:15 PDT 2016
Author: dehao
Date: Wed Sep 28 13:41:14 2016
New Revision: 282616
URL: http://llvm.org/viewvc/llvm-project?rev=282616&view=rev
Log:
Fix the bug when -compile-twice is specified, the PSI will be invalidated.
Summary:
When using llc with -compile-twice, module is generated twice, but getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI will still get the old PSI with the original (invalidated) Module. This patch checks if the module has changed when calling getPSI, if yes, update the module and invalidate the Summary.
The bug does not show up in the current llc because PSI is not used in CodeGen yet. But with https://reviews.llvm.org/D24989, the bug will be exposed by test/CodeGen/PowerPC/pr26378.ll
Reviewers: eraman, davidxl
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D24993
Modified:
llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h?rev=282616&r1=282615&r2=282616&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h Wed Sep 28 13:41:14 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,6 +59,8 @@ 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.
Modified: llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp?rev=282616&r1=282615&r2=282616&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp Wed Sep 28 13:41:14 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,6 +113,13 @@ 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();
@@ -127,7 +134,9 @@ bool ProfileSummaryInfo::isColdCount(uin
ProfileSummaryInfo *ProfileSummaryInfoWrapperPass::getPSI(Module &M) {
if (!PSI)
- PSI.reset(new ProfileSummaryInfo(M));
+ PSI.reset(new ProfileSummaryInfo(&M));
+ else
+ PSI->resetModule(&M);
return PSI.get();
}
@@ -142,7 +151,7 @@ ProfileSummaryInfoWrapperPass::ProfileSu
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
More information about the llvm-commits
mailing list