[llvm] r297500 - Refactor the PSI to extract getCallSiteCount and remove checks for profile type.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 10 11:45:17 PST 2017
Author: dehao
Date: Fri Mar 10 13:45:16 2017
New Revision: 297500
URL: http://llvm.org/viewvc/llvm-project?rev=297500&view=rev
Log:
Refactor the PSI to extract getCallSiteCount and remove checks for profile type.
Summary: There is no need to check profile count as only CallInst will have metadata attached.
Reviewers: eraman
Reviewed By: eraman
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D30799
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=297500&r1=297499&r2=297500&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h Fri Mar 10 13:45:16 2017
@@ -49,12 +49,14 @@ private:
void computeThresholds();
// Count thresholds to answer isHotCount and isColdCount queries.
Optional<uint64_t> HotCountThreshold, ColdCountThreshold;
- bool extractProfTotalWeight(const Instruction *TI, uint64_t &TotalCount);
public:
ProfileSummaryInfo(Module &M) : M(M) {}
ProfileSummaryInfo(ProfileSummaryInfo &&Arg)
: M(Arg.M), Summary(std::move(Arg.Summary)) {}
+ /// Returns the profile count for \p CallInst.
+ static Optional<uint64_t> getProfileCount(const Instruction *CallInst,
+ BlockFrequencyInfo *BFI);
/// \brief Returns true if \p F has hot function entry.
bool isFunctionEntryHot(const Function *F);
/// \brief Returns true if \p F has cold function entry.
Modified: llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp?rev=297500&r1=297499&r2=297500&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp Fri Mar 10 13:45:16 2017
@@ -68,6 +68,23 @@ bool ProfileSummaryInfo::computeSummary(
return true;
}
+Optional<uint64_t>
+ProfileSummaryInfo::getProfileCount(const Instruction *Inst,
+ BlockFrequencyInfo *BFI) {
+ if (!Inst)
+ return None;
+ assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) &&
+ "We can only get profile count for call/invoke instruction.");
+ // Check if there is a profile metadata on the instruction. If it is present,
+ // determine hotness solely based on that.
+ uint64_t TotalCount;
+ if (Inst->extractProfTotalWeight(TotalCount))
+ return TotalCount;
+ if (BFI)
+ return BFI->getBlockProfileCount(Inst->getParent());
+ return None;
+}
+
/// Returns true if the function's entry is hot. If it returns false, it
/// either means it is not hot or it is unknown whether it is hot or not (for
/// example, no profile data is available).
@@ -133,44 +150,16 @@ bool ProfileSummaryInfo::isColdBB(const
return Count && isColdCount(*Count);
}
-bool ProfileSummaryInfo::extractProfTotalWeight(const Instruction *I,
- uint64_t &TotalCount) {
- if (!computeSummary())
- return false;
- // Use profile weight on metadata only for sample profiling where block counts
- // could differ from the count of an instruction within the block.
- if (Summary.get()->getKind() != ProfileSummary::PSK_Sample)
- return false;
-
- return (isa<CallInst>(I) ||
- (isa<TerminatorInst>(I) && !isa<ReturnInst>(I))) &&
- I->extractProfTotalWeight(TotalCount);
-}
-
bool ProfileSummaryInfo::isHotCallSite(const CallSite &CS,
BlockFrequencyInfo *BFI) {
- auto *CallInst = CS.getInstruction();
- if (!CS)
- return false;
- // Check if there is a profile metadata on the instruction. If it is present,
- // determine hotness solely based on that.
- uint64_t TotalCount;
- if (extractProfTotalWeight(CallInst, TotalCount))
- return isHotCount(TotalCount);
- return BFI && isHotBB(CallInst->getParent(), BFI);
+ auto C = getProfileCount(CS.getInstruction(), BFI);
+ return C && isHotCount(*C);
}
bool ProfileSummaryInfo::isColdCallSite(const CallSite &CS,
BlockFrequencyInfo *BFI) {
- auto *CallInst = CS.getInstruction();
- if (!CS)
- return false;
- // Check if there is a profile metadata on the instruction. If it is present,
- // and tells that the callsite is not cold, then return false;
- uint64_t TotalCount;
- if (extractProfTotalWeight(CallInst, TotalCount) && !isColdCount(TotalCount))
- return false;
- return BFI && isColdBB(CallInst->getParent(), BFI);
+ auto C = getProfileCount(CS.getInstruction(), BFI);
+ return C && isColdCount(*C);
}
INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info",
Modified: llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp?rev=297500&r1=297499&r2=297500&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/ProfileSummaryInfoTest.cpp Fri Mar 10 13:45:16 2017
@@ -162,12 +162,6 @@ TEST_F(ProfileSummaryInfoTest, InstrProf
EXPECT_TRUE(PSI.isHotCallSite(CS1, &BFI));
EXPECT_FALSE(PSI.isHotCallSite(CS2, &BFI));
-
- // Test that adding an MD_prof metadata with a hot count on CS2 does not
- // change itas hotness as it has no effect in instrumented profiling.
- MDBuilder MDB(M->getContext());
- CI2->setMetadata(llvm::LLVMContext::MD_prof, MDB.createBranchWeights({400}));
- EXPECT_FALSE(PSI.isHotCallSite(CS2, &BFI));
}
TEST_F(ProfileSummaryInfoTest, SampleProf) {
More information about the llvm-commits
mailing list