[llvm] r303204 - Add hasProfileSummary and has{Sample|Instrumentation}Profile methods
Easwaran Raman via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 13:14:40 PDT 2017
Author: eraman
Date: Tue May 16 15:14:39 2017
New Revision: 303204
URL: http://llvm.org/viewvc/llvm-project?rev=303204&view=rev
Log:
Add hasProfileSummary and has{Sample|Instrumentation}Profile methods
ProfileSummaryInfo already checks whether the module has sample profile
in determining profile counts. This will also be useful in inliner to
clean up threshold updates.
Modified:
llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp
Modified: llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h?rev=303204&r1=303203&r2=303204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h Tue May 16 15:14:39 2017
@@ -55,6 +55,21 @@ public:
ProfileSummaryInfo(ProfileSummaryInfo &&Arg)
: M(Arg.M), Summary(std::move(Arg.Summary)) {}
+ /// \brief Returns true if profile summary is available.
+ bool hasProfileSummary() { return computeSummary(); }
+
+ /// \brief Returns true if module \c M has sample profile.
+ bool hasSampleProfile() {
+ return hasProfileSummary() &&
+ Summary->getKind() == ProfileSummary::PSK_Sample;
+ }
+
+ /// \brief Returns true if module \c M has instrumentation profile.
+ bool hasInstrumentationProfile() {
+ return hasProfileSummary() &&
+ Summary->getKind() == ProfileSummary::PSK_Instr;
+ }
+
/// Handle the invalidation of this information.
///
/// When used as a result of \c ProfileSummaryAnalysis this method will be
Modified: llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp?rev=303204&r1=303203&r2=303204&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp Tue May 16 15:14:39 2017
@@ -75,7 +75,7 @@ ProfileSummaryInfo::getProfileCount(cons
return None;
assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
"We can only get profile count for call/invoke instruction.");
- if (computeSummary() && Summary->getKind() == ProfileSummary::PSK_Sample) {
+ if (hasSampleProfile()) {
// In sample PGO mode, check if there is a profile metadata on the
// instruction. If it is present, determine hotness solely based on that,
// since the sampled entry count may not be accurate.
Modified: llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp?rev=303204&r1=303203&r2=303204&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp Tue May 16 15:14:39 2017
@@ -102,6 +102,9 @@ TEST_F(ProfileSummaryInfoTest, TestNoPro
Function *F = M->getFunction("f");
ProfileSummaryInfo PSI = buildPSI(M.get());
+ EXPECT_FALSE(PSI.hasProfileSummary());
+ EXPECT_FALSE(PSI.hasSampleProfile());
+ EXPECT_FALSE(PSI.hasInstrumentationProfile());
// In the absence of profiles, is{Hot|Cold}X methods should always return
// false.
EXPECT_FALSE(PSI.isHotCount(1000));
@@ -130,6 +133,7 @@ TEST_F(ProfileSummaryInfoTest, TestCommo
Function *H = M->getFunction("h");
ProfileSummaryInfo PSI = buildPSI(M.get());
+ EXPECT_TRUE(PSI.hasProfileSummary());
EXPECT_TRUE(PSI.isHotCount(400));
EXPECT_TRUE(PSI.isColdCount(2));
EXPECT_FALSE(PSI.isColdCount(100));
@@ -144,6 +148,8 @@ TEST_F(ProfileSummaryInfoTest, InstrProf
auto M = makeLLVMModule("InstrProf");
Function *F = M->getFunction("f");
ProfileSummaryInfo PSI = buildPSI(M.get());
+ EXPECT_TRUE(PSI.hasProfileSummary());
+ EXPECT_TRUE(PSI.hasInstrumentationProfile());
BasicBlock &BB0 = F->getEntryBlock();
BasicBlock *BB1 = BB0.getTerminator()->getSuccessor(0);
@@ -174,6 +180,8 @@ TEST_F(ProfileSummaryInfoTest, SamplePro
auto M = makeLLVMModule("SampleProfile");
Function *F = M->getFunction("f");
ProfileSummaryInfo PSI = buildPSI(M.get());
+ EXPECT_TRUE(PSI.hasProfileSummary());
+ EXPECT_TRUE(PSI.hasSampleProfile());
BasicBlock &BB0 = F->getEntryBlock();
BasicBlock *BB1 = BB0.getTerminator()->getSuccessor(0);
More information about the llvm-commits
mailing list