diff options
author | Easwaran Raman <eraman@google.com> | 2016-04-15 21:39:58 +0000 |
---|---|---|
committer | Easwaran Raman <eraman@google.com> | 2016-04-15 21:39:58 +0000 |
commit | f53baca686583eedf2c76bfbe3cbf88e1428fe26 (patch) | |
tree | a0df56353026c1fef7374206da006a1858f7f4cd /llvm/lib | |
parent | a283ddc5159ab3e2bb1cc1deea641b958de82075 (diff) | |
download | bcm5719-llvm-f53baca686583eedf2c76bfbe3cbf88e1428fe26.tar.gz bcm5719-llvm-f53baca686583eedf2c76bfbe3cbf88e1428fe26.zip |
Replace the use of MaxFunctionCount module flag
Adds an interface to get ProfileSummary for a module and makes InlineCost use ProfileSummary to get max function count.
Differential Revision: http://reviews.llvm.org/D18622
llvm-svn: 266477
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/ProfileData/ProfileSummary.cpp | 44 |
2 files changed, 48 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index aa46b68d8c3..bf93677302a 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -30,6 +30,7 @@ #include "llvm/IR/InstVisitor.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Operator.h" +#include "llvm/ProfileData/ProfileCommon.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -626,10 +627,11 @@ void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) { // a well-tuned heuristic based on *callsite* hotness and not callee hotness. uint64_t FunctionCount = 0, MaxFunctionCount = 0; bool HasPGOCounts = false; - if (Callee.getEntryCount() && Callee.getParent()->getMaximumFunctionCount()) { + ProfileSummary *PS = ProfileSummary::getProfileSummary(Callee.getParent()); + if (Callee.getEntryCount() && PS) { HasPGOCounts = true; FunctionCount = Callee.getEntryCount().getValue(); - MaxFunctionCount = Callee.getParent()->getMaximumFunctionCount().getValue(); + MaxFunctionCount = PS->getMaxFunctionCount(); } // Listen to the inlinehint attribute or profile based hotness information diff --git a/llvm/lib/ProfileData/ProfileSummary.cpp b/llvm/lib/ProfileData/ProfileSummary.cpp index 33c1479e19c..50aa95829b4 100644 --- a/llvm/lib/ProfileData/ProfileSummary.cpp +++ b/llvm/lib/ProfileData/ProfileSummary.cpp @@ -15,6 +15,7 @@ #include "llvm/IR/Constants.h" #include "llvm/IR/Function.h" #include "llvm/IR/Metadata.h" +#include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/ProfileData/InstrProf.h" #include "llvm/ProfileData/ProfileCommon.h" @@ -32,6 +33,10 @@ const std::vector<uint32_t> ProfileSummary::DefaultCutoffs( 900000, 950000, 990000, 999000, 999900, 999990, 999999}); const char *ProfileSummary::KindStr[2] = {"InstrProf", "SampleProfile"}; +ManagedStatic<std::pair<Module *, std::unique_ptr<ProfileSummary>>> + ProfileSummary::CachedSummary; +ManagedStatic<sys::SmartMutex<true>> ProfileSummary::CacheMutex; + void InstrProfSummary::addRecord(const InstrProfRecord &R) { addEntryCount(R.Counts[0]); for (size_t I = 1, E = R.Counts.size(); I < E; ++I) @@ -82,6 +87,39 @@ void ProfileSummary::computeDetailedSummary() { } } +bool ProfileSummary::operator==(ProfileSummary &Other) { + if (getKind() != Other.getKind()) + return false; + if (TotalCount != Other.TotalCount) + return false; + if (MaxCount != Other.MaxCount) + return false; + if (MaxFunctionCount != Other.MaxFunctionCount) + return false; + if (NumFunctions != Other.NumFunctions) + return false; + if (NumCounts != Other.NumCounts) + return false; + std::vector<ProfileSummaryEntry> DS1 = getDetailedSummary(); + std::vector<ProfileSummaryEntry> DS2 = Other.getDetailedSummary(); + auto CompareSummaryEntry = [](ProfileSummaryEntry &E1, + ProfileSummaryEntry &E2) { + return E1.Cutoff == E2.Cutoff && E1.MinCount == E2.MinCount && + E1.NumCounts == E2.NumCounts; + }; + if (!std::equal(DS1.begin(), DS1.end(), DS2.begin(), CompareSummaryEntry)) + return false; + return true; +} + +bool InstrProfSummary::operator==(ProfileSummary &Other) { + InstrProfSummary *OtherIPS = dyn_cast<InstrProfSummary>(&Other); + if (!OtherIPS) + return false; + return MaxInternalBlockCount == OtherIPS->MaxInternalBlockCount && + ProfileSummary::operator==(Other); +} + // Returns true if the function is a hot function. bool ProfileSummary::isFunctionHot(const Function *F) { // FIXME: update when summary data is stored in module's metadata. @@ -362,3 +400,9 @@ ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) { else return nullptr; } + +ProfileSummary *ProfileSummary::computeProfileSummary(Module *M) { + if (Metadata *MD = M->getProfileSummary()) + return getFromMD(MD); + return nullptr; +} |