summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEaswaran Raman <eraman@google.com>2016-05-19 21:07:12 +0000
committerEaswaran Raman <eraman@google.com>2016-05-19 21:07:12 +0000
commit17e7f1191fc1e09714079ee52cc3ffb32f5736b5 (patch)
treefc5ef2c6b8a9554d8855a5bd915fcc59bc05c1d5 /include
parent4f4b87e93849eddd82a11c0d41c760aa6a5e8c31 (diff)
Move ProfileSummary to IR.
This splits ProfileSummary into two classes: a ProfileSummary class that has methods to convert from/to metadata and a ProfileSummaryBuilder class that computes the profiles summary which is in ProfileData. Differential Revision: http://reviews.llvm.org/D20314 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270136 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/IR/ProfileSummary.h129
-rw-r--r--include/llvm/ProfileData/ProfileCommon.h123
2 files changed, 148 insertions, 104 deletions
diff --git a/include/llvm/IR/ProfileSummary.h b/include/llvm/IR/ProfileSummary.h
new file mode 100644
index 00000000000..5da87f3b5fe
--- /dev/null
+++ b/include/llvm/IR/ProfileSummary.h
@@ -0,0 +1,129 @@
+//===-- ProfileSummary.h - Profile summary data structure. ------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the profile summary data structure.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_PROFILE_SUMMARY_H
+#define LLVM_SUPPORT_PROFILE_SUMMARY_H
+
+#include <cstdint>
+#include <vector>
+
+#include "llvm/Support/Casting.h"
+
+namespace llvm {
+
+class LLVMContext;
+class Metadata;
+class MDTuple;
+class MDNode;
+
+// The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
+// The semantics of counts depend on the type of profile. For instrumentation
+// profile, counts are block counts and for sample profile, counts are
+// per-line samples. Given a target counts percentile, we compute the minimum
+// number of counts needed to reach this target and the minimum among these
+// counts.
+struct ProfileSummaryEntry {
+ uint32_t Cutoff; ///< The required percentile of counts.
+ uint64_t MinCount; ///< The minimum count for this percentile.
+ uint64_t NumCounts; ///< Number of counts >= the minimum count.
+ ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
+ uint64_t TheNumCounts)
+ : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
+};
+
+typedef std::vector<ProfileSummaryEntry> SummaryEntryVector;
+
+class ProfileSummary {
+public:
+ enum Kind { PSK_Instr, PSK_Sample };
+
+private:
+ const Kind PSK;
+ static const char *KindStr[2];
+
+protected:
+ SummaryEntryVector DetailedSummary;
+ uint64_t TotalCount, MaxCount, MaxFunctionCount;
+ uint32_t NumCounts, NumFunctions;
+ ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
+ uint64_t TotalCount, uint64_t MaxCount,
+ uint64_t MaxFunctionCount, uint32_t NumCounts,
+ uint32_t NumFunctions)
+ : PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount),
+ MaxCount(MaxCount), MaxFunctionCount(MaxFunctionCount),
+ NumCounts(NumCounts), NumFunctions(NumFunctions) {}
+ ~ProfileSummary() = default;
+ /// \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; }
+ const char *getKindStr() const { return KindStr[PSK]; }
+ /// \brief Return summary information as metadata.
+ Metadata *getMD(LLVMContext &Context);
+ /// \brief Construct profile summary from metdata.
+ static ProfileSummary *getFromMD(Metadata *MD);
+ SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
+ uint32_t getNumFunctions() { return NumFunctions; }
+ uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
+};
+
+class InstrProfSummary final : public ProfileSummary {
+ uint64_t MaxInternalBlockCount;
+
+protected:
+ std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) override;
+
+public:
+ InstrProfSummary(uint64_t TotalCount, uint64_t MaxBlockCount,
+ uint64_t MaxInternalBlockCount, uint64_t MaxFunctionCount,
+ uint32_t NumBlocks, uint32_t NumFunctions,
+ SummaryEntryVector Summary)
+ : ProfileSummary(PSK_Instr, Summary, TotalCount, MaxBlockCount,
+ MaxFunctionCount, NumBlocks, NumFunctions),
+ MaxInternalBlockCount(MaxInternalBlockCount) {}
+ static bool classof(const ProfileSummary *PS) {
+ return PS->getKind() == PSK_Instr;
+ }
+ uint32_t getNumBlocks() { return NumCounts; }
+ uint64_t getTotalCount() { return TotalCount; }
+ uint64_t getMaxBlockCount() { return MaxCount; }
+ uint64_t getMaxInternalBlockCount() { return MaxInternalBlockCount; }
+};
+
+class SampleProfileSummary final : public ProfileSummary {
+protected:
+ std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) override;
+
+public:
+ uint32_t getNumLinesWithSamples() { return NumCounts; }
+ uint64_t getTotalSamples() { return TotalCount; }
+ uint64_t getMaxSamplesPerLine() { return MaxCount; }
+ SampleProfileSummary(uint64_t TotalSamples, uint64_t MaxSamplesPerLine,
+ uint64_t MaxFunctionCount, int32_t NumLinesWithSamples,
+ uint32_t NumFunctions,
+ SummaryEntryVector DetailedSummary)
+ : ProfileSummary(PSK_Sample, DetailedSummary, TotalSamples,
+ MaxSamplesPerLine, MaxFunctionCount, NumLinesWithSamples,
+ NumFunctions) {}
+ static bool classof(const ProfileSummary *PS) {
+ return PS->getKind() == PSK_Sample;
+ }
+};
+
+} // end namespace llvm
+#endif
diff --git a/include/llvm/ProfileData/ProfileCommon.h b/include/llvm/ProfileData/ProfileCommon.h
index 2702d6fc6ae..79eee91c3d7 100644
--- a/include/llvm/ProfileData/ProfileCommon.h
+++ b/include/llvm/ProfileData/ProfileCommon.h
@@ -20,7 +20,7 @@
#include <map>
#include <vector>
-#include "llvm/Support/Casting.h"
+#include "llvm/IR/ProfileSummary.h"
#include "llvm/Support/Error.h"
namespace llvm {
@@ -40,134 +40,54 @@ class MDNode;
inline const char *getHotSectionPrefix() { return ".hot"; }
inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }
-// The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
-// The semantics of counts depend on the type of profile. For instrumentation
-// profile, counts are block counts and for sample profile, counts are
-// per-line samples. Given a target counts percentile, we compute the minimum
-// number of counts needed to reach this target and the minimum among these
-// counts.
-struct ProfileSummaryEntry {
- uint32_t Cutoff; ///< The required percentile of counts.
- uint64_t MinCount; ///< The minimum count for this percentile.
- uint64_t NumCounts; ///< Number of counts >= the minimum count.
- ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
- uint64_t TheNumCounts)
- : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
-};
-
-typedef std::vector<ProfileSummaryEntry> SummaryEntryVector;
-
-class ProfileSummary {
-public:
- enum Kind { PSK_Instr, PSK_Sample };
+class ProfileSummaryBuilder {
private:
- const Kind PSK;
- static const char *KindStr[2];
// We keep track of the number of times a count (block count or samples)
// 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;
+ std::vector<uint32_t> DetailedSummaryCutoffs;
+
protected:
SummaryEntryVector DetailedSummary;
- std::vector<uint32_t> DetailedSummaryCutoffs;
- uint64_t TotalCount, MaxCount, MaxFunctionCount;
- uint32_t NumCounts, NumFunctions;
- ProfileSummary(Kind K, std::vector<uint32_t> Cutoffs)
- : PSK(K), DetailedSummaryCutoffs(Cutoffs), TotalCount(0), MaxCount(0),
+ ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
+ : DetailedSummaryCutoffs(Cutoffs), TotalCount(0), MaxCount(0),
MaxFunctionCount(0), NumCounts(0), NumFunctions(0) {}
- ProfileSummary(Kind K)
- : PSK(K), TotalCount(0), MaxCount(0), MaxFunctionCount(0), NumCounts(0),
- NumFunctions(0) {}
- ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
- uint64_t TotalCount, uint64_t MaxCount,
- uint64_t MaxFunctionCount, uint32_t NumCounts,
- uint32_t NumFunctions)
- : 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);
+ ~ProfileSummaryBuilder() = default;
+ void computeDetailedSummary();
+ uint64_t TotalCount, MaxCount, MaxFunctionCount;
+ uint32_t NumCounts, NumFunctions;
public:
- static const int Scale = 1000000;
- Kind getKind() const { return PSK; }
- const char *getKindStr() const { return KindStr[PSK]; }
- // \brief Returns true if F is a hot function.
- static bool isFunctionHot(const Function *F);
- // \brief Returns true if F is unlikley executed.
- static bool isFunctionUnlikely(const Function *F);
- inline SummaryEntryVector &getDetailedSummary();
- void computeDetailedSummary();
/// \brief A vector of useful cutoff values for detailed summary.
static const std::vector<uint32_t> DefaultCutoffs;
- /// \brief Return summary information as metadata.
- Metadata *getMD(LLVMContext &Context);
- /// \brief Construct profile summary from metdata.
- static ProfileSummary *getFromMD(Metadata *MD);
- uint32_t getNumFunctions() { return NumFunctions; }
- uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
};
-class InstrProfSummary final : public ProfileSummary {
+class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {
uint64_t MaxInternalBlockCount;
inline void addEntryCount(uint64_t Count);
inline void addInternalCount(uint64_t Count);
-protected:
- std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) override;
-
public:
- InstrProfSummary(std::vector<uint32_t> Cutoffs)
- : ProfileSummary(PSK_Instr, Cutoffs), MaxInternalBlockCount(0) {}
- InstrProfSummary(const IndexedInstrProf::Summary &S);
- InstrProfSummary(uint64_t TotalCount, uint64_t MaxBlockCount,
- uint64_t MaxInternalBlockCount, uint64_t MaxFunctionCount,
- uint32_t NumBlocks, uint32_t NumFunctions,
- SummaryEntryVector Summary)
- : ProfileSummary(PSK_Instr, Summary, TotalCount, MaxBlockCount,
- MaxFunctionCount, NumBlocks, NumFunctions),
- MaxInternalBlockCount(MaxInternalBlockCount) {}
- static bool classof(const ProfileSummary *PS) {
- return PS->getKind() == PSK_Instr;
- }
+ InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
+ : ProfileSummaryBuilder(Cutoffs), MaxInternalBlockCount(0) {}
void addRecord(const InstrProfRecord &);
- uint32_t getNumBlocks() { return NumCounts; }
- uint64_t getTotalCount() { return TotalCount; }
- uint64_t getMaxBlockCount() { return MaxCount; }
- uint64_t getMaxInternalBlockCount() { return MaxInternalBlockCount; }
+ InstrProfSummary *getSummary();
};
-class SampleProfileSummary final : public ProfileSummary {
-protected:
- std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) override;
+class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
public:
- uint32_t getNumLinesWithSamples() { return NumCounts; }
- uint64_t getTotalSamples() { return TotalCount; }
- uint64_t getMaxSamplesPerLine() { return MaxCount; }
void addRecord(const sampleprof::FunctionSamples &FS);
- SampleProfileSummary(std::vector<uint32_t> Cutoffs)
- : ProfileSummary(PSK_Sample, Cutoffs) {}
- SampleProfileSummary(uint64_t TotalSamples, uint64_t MaxSamplesPerLine,
- uint64_t MaxFunctionCount, int32_t NumLinesWithSamples,
- uint32_t NumFunctions,
- SummaryEntryVector DetailedSummary)
- : ProfileSummary(PSK_Sample, DetailedSummary, TotalSamples,
- MaxSamplesPerLine, MaxFunctionCount, NumLinesWithSamples,
- NumFunctions) {}
- static bool classof(const ProfileSummary *PS) {
- return PS->getKind() == PSK_Sample;
- }
+ SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
+ : ProfileSummaryBuilder(Cutoffs) {}
+ SampleProfileSummary *getSummary();
};
// This is called when a count is seen in the profile.
-void ProfileSummary::addCount(uint64_t Count) {
+void ProfileSummaryBuilder::addCount(uint64_t Count) {
TotalCount += Count;
if (Count > MaxCount)
MaxCount = Count;
@@ -175,11 +95,6 @@ void ProfileSummary::addCount(uint64_t Count) {
CountFrequencies[Count]++;
}
-SummaryEntryVector &ProfileSummary::getDetailedSummary() {
- if (!DetailedSummaryCutoffs.empty() && DetailedSummary.empty())
- computeDetailedSummary();
- return DetailedSummary;
-}
} // end namespace llvm
#endif