Add a profile summary class specific to instrumentation profiles.

Modify ProfileSummary class to make it not instrumented profile specific.
Add a new InstrumentedProfileSummary class that inherits from ProfileSummary.

Differential Revision: http://reviews.llvm.org/D17310

llvm-svn: 261119
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 7968cf1..9c17d4e 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -589,15 +589,15 @@
     for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
       Dst[I] = endian::byte_swap<uint64_t, little>(Src[I]);
 
-    // initialize ProfileSummary using the SummaryData from disk.
-    this->Summary = llvm::make_unique<ProfileSummary>(*(SummaryData.get()));
+    // initialize InstrProfSummary using the SummaryData from disk.
+    this->Summary = llvm::make_unique<InstrProfSummary>(*(SummaryData.get()));
     return Cur + SummarySize;
   } else {
     // For older version of profile data, we need to compute on the fly:
     using namespace IndexedInstrProf;
     std::vector<uint32_t> Cutoffs(&SummaryCutoffs[0],
                                   &SummaryCutoffs[NumSummaryCutoffs]);
-    this->Summary = llvm::make_unique<ProfileSummary>(Cutoffs);
+    this->Summary = llvm::make_unique<InstrProfSummary>(Cutoffs);
     this->Summary->computeDetailedSummary();
     return Cur;
   }
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 3e32571..19a16b8 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -84,7 +84,7 @@
   typedef uint64_t offset_type;
 
   support::endianness ValueProfDataEndianness;
-  ProfileSummary *TheProfileSummary;
+  InstrProfSummary *TheProfileSummary;
 
   InstrProfRecordWriterTrait() : ValueProfDataEndianness(support::little) {}
   static hash_value_type ComputeHash(key_type_ref K) {
@@ -197,7 +197,7 @@
 }
 
 static void setSummary(IndexedInstrProf::Summary *TheSummary,
-                       ProfileSummary &PS) {
+                       InstrProfSummary &PS) {
   using namespace IndexedInstrProf;
   std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
   TheSummary->NumSummaryFields = Summary::NumKinds;
@@ -219,7 +219,7 @@
   using namespace IndexedInstrProf;
   std::vector<uint32_t> Cutoffs(&SummaryCutoffs[0],
                                 &SummaryCutoffs[NumSummaryCutoffs]);
-  ProfileSummary PS(Cutoffs);
+  InstrProfSummary PS(Cutoffs);
   InfoObj->TheProfileSummary = &PS;
 
   // Populate the hash table generator.
diff --git a/llvm/lib/ProfileData/ProfileSummary.cpp b/llvm/lib/ProfileData/ProfileSummary.cpp
index a16094b..716c39e 100644
--- a/llvm/lib/ProfileData/ProfileSummary.cpp
+++ b/llvm/lib/ProfileData/ProfileSummary.cpp
@@ -16,17 +16,14 @@
 
 using namespace llvm;
 
-void ProfileSummary::addRecord(const InstrProfRecord &R) {
-  NumFunctions++;
-  if (R.Counts[0] > MaxFunctionCount)
-    MaxFunctionCount = R.Counts[0];
-
-  for (size_t I = 0, E = R.Counts.size(); I < E; ++I)
-    addCount(R.Counts[I], (I == 0));
+void InstrProfSummary::addRecord(const InstrProfRecord &R) {
+  addEntryCount(R.Counts[0]);
+  for (size_t I = 1, E = R.Counts.size(); I < E; ++I)
+    addInternalCount(R.Counts[I]);
 }
 
 // The argument to this method is a vector of cutoff percentages and the return
-// value is a vector of (Cutoff, MinBlockCount, NumBlocks) triplets.
+// value is a vector of (Cutoff, MinCount, NumCounts) triplets.
 void ProfileSummary::computeDetailedSummary() {
   if (DetailedSummaryCutoffs.empty())
     return;
@@ -34,7 +31,7 @@
   auto End = CountFrequencies.end();
   std::sort(DetailedSummaryCutoffs.begin(), DetailedSummaryCutoffs.end());
 
-  uint32_t BlocksSeen = 0;
+  uint32_t CountsSeen = 0;
   uint64_t CurrSum = 0, Count = 0;
 
   for (uint32_t Cutoff : DetailedSummaryCutoffs) {
@@ -50,26 +47,40 @@
       Count = Iter->first;
       uint32_t Freq = Iter->second;
       CurrSum += (Count * Freq);
-      BlocksSeen += Freq;
+      CountsSeen += Freq;
       Iter++;
     }
     assert(CurrSum >= DesiredCount);
-    ProfileSummaryEntry PSE = {Cutoff, Count, BlocksSeen};
+    ProfileSummaryEntry PSE = {Cutoff, Count, CountsSeen};
     DetailedSummary.push_back(PSE);
   }
 }
 
-ProfileSummary::ProfileSummary(const IndexedInstrProf::Summary &S)
-    : TotalCount(S.get(IndexedInstrProf::Summary::TotalBlockCount)),
-      MaxBlockCount(S.get(IndexedInstrProf::Summary::MaxBlockCount)),
-      MaxInternalBlockCount(
-          S.get(IndexedInstrProf::Summary::MaxInternalBlockCount)),
+InstrProfSummary::InstrProfSummary(const IndexedInstrProf::Summary &S)
+    : ProfileSummary(), MaxInternalBlockCount(S.get(
+                            IndexedInstrProf::Summary::MaxInternalBlockCount)),
       MaxFunctionCount(S.get(IndexedInstrProf::Summary::MaxFunctionCount)),
-      NumBlocks(S.get(IndexedInstrProf::Summary::TotalNumBlocks)),
       NumFunctions(S.get(IndexedInstrProf::Summary::TotalNumFunctions)) {
+
+  TotalCount = S.get(IndexedInstrProf::Summary::TotalBlockCount);
+  MaxCount = S.get(IndexedInstrProf::Summary::MaxBlockCount);
+  NumCounts = S.get(IndexedInstrProf::Summary::TotalNumBlocks);
+
   for (unsigned I = 0; I < S.NumCutoffEntries; I++) {
     const IndexedInstrProf::Summary::Entry &Ent = S.getEntry(I);
     DetailedSummary.emplace_back((uint32_t)Ent.Cutoff, Ent.MinBlockCount,
                                  Ent.NumBlocks);
   }
 }
+void InstrProfSummary::addEntryCount(uint64_t Count) {
+  addCount(Count);
+  NumFunctions++;
+  if (Count > MaxFunctionCount)
+    MaxFunctionCount = Count;
+}
+
+void InstrProfSummary::addInternalCount(uint64_t Count) {
+  addCount(Count);
+  if (Count > MaxInternalBlockCount)
+    MaxInternalBlockCount = Count;
+}