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/include | |
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/include')
-rw-r--r-- | llvm/include/llvm/ProfileData/ProfileCommon.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/llvm/include/llvm/ProfileData/ProfileCommon.h b/llvm/include/llvm/ProfileData/ProfileCommon.h index c9cc756b0c6..0da6565c6f1 100644 --- a/llvm/include/llvm/ProfileData/ProfileCommon.h +++ b/llvm/include/llvm/ProfileData/ProfileCommon.h @@ -22,6 +22,8 @@ #include <vector> #include "llvm/Support/Casting.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Mutex.h" namespace llvm { class Function; @@ -36,6 +38,7 @@ class LLVMContext; class Metadata; class MDTuple; class MDNode; +class Module; inline const char *getHotSectionPrefix() { return ".hot"; } inline const char *getUnlikelySectionPrefix() { return ".unlikely"; } @@ -68,6 +71,14 @@ private: // appears in the profile. The map is kept sorted in the descending order of // counts. std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies; + // Compute profile summary for a module. + static ProfileSummary *computeProfileSummary(Module *M); + // Cache of last seen module and its profile summary. + static ManagedStatic<std::pair<Module *, std::unique_ptr<ProfileSummary>>> + CachedSummary; + // Mutex to access summary cache + static ManagedStatic<sys::SmartMutex<true>> CacheMutex; + protected: SummaryEntryVector DetailedSummary; std::vector<uint32_t> DetailedSummaryCutoffs; @@ -86,14 +97,12 @@ protected: : PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount), MaxCount(MaxCount), MaxFunctionCount(MaxFunctionCount), NumCounts(NumCounts), NumFunctions(NumFunctions) {} - ~ProfileSummary() = default; inline void addCount(uint64_t Count); /// \brief Return metadata specific to the profile format. /// Derived classes implement this method to return a vector of Metadata. virtual std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) = 0; /// \brief Return detailed summary as metadata. Metadata *getDetailedSummaryMD(LLVMContext &Context); - public: static const int Scale = 1000000; Kind getKind() const { return PSK; } @@ -112,6 +121,10 @@ public: static ProfileSummary *getFromMD(Metadata *MD); uint32_t getNumFunctions() { return NumFunctions; } uint64_t getMaxFunctionCount() { return MaxFunctionCount; } + /// \brief Get profile summary associated with module \p M + static inline ProfileSummary *getProfileSummary(Module *M); + virtual ~ProfileSummary() = default; + virtual bool operator==(ProfileSummary &Other); }; class InstrProfSummary final : public ProfileSummary { @@ -141,6 +154,7 @@ public: uint64_t getTotalCount() { return TotalCount; } uint64_t getMaxBlockCount() { return MaxCount; } uint64_t getMaxInternalBlockCount() { return MaxInternalBlockCount; } + bool operator==(ProfileSummary &Other) override; }; class SampleProfileSummary final : public ProfileSummary { @@ -181,5 +195,24 @@ SummaryEntryVector &ProfileSummary::getDetailedSummary() { return DetailedSummary; } +ProfileSummary *ProfileSummary::getProfileSummary(Module *M) { + if (!M) + return nullptr; + sys::SmartScopedLock<true> Lock(*CacheMutex); + // Computing profile summary for a module involves parsing a fairly large + // metadata and could be expensive. We use a simple cache of the last seen + // module and its profile summary. + if (CachedSummary->first != M) { + auto *Summary = computeProfileSummary(M); + // Do not cache if the summary is empty. This is because a later pass + // (sample profile loader, for example) could attach the summary metadata on + // the module. + if (!Summary) + return nullptr; + CachedSummary->first = M; + CachedSummary->second.reset(Summary); + } + return CachedSummary->second.get(); +} } // end namespace llvm #endif |