Minor refactor to make VP writing more efficient
authorXinliang David Li <davidxl@google.com>
Tue, 24 Nov 2015 17:03:24 +0000 (17:03 +0000)
committerXinliang David Li <davidxl@google.com>
Tue, 24 Nov 2015 17:03:24 +0000 (17:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253994 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProf.h
lib/ProfileData/InstrProf.cpp

index b28689bfce1d5898c5df65655bcb7e01a8468c54..872cc764bc0e9451d1c935ac26a9037a8c111bd8 100644 (file)
@@ -259,8 +259,11 @@ struct InstrProfRecord {
   /// site: Site.
   inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
                                          uint32_t Site) const;
+  /// Return the array of profiled values at \p Site.
   inline std::unique_ptr<InstrProfValueData[]>
   getValueForSite(uint32_t ValueKind, uint32_t Site) const;
+  inline void getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind,
+                              uint32_t Site) const;
   /// Reserve space for NumValueSites sites.
   inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
   /// Add ValueData for ValueKind at value Site.
@@ -369,14 +372,17 @@ InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {
     return std::unique_ptr<InstrProfValueData[]>(nullptr);
 
   auto VD = llvm::make_unique<InstrProfValueData[]>(N);
+  getValueForSite(VD.get(), ValueKind, Site);
+
+  return VD;
+}
+void InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
+                                      uint32_t ValueKind, uint32_t Site) const {
   uint32_t I = 0;
   for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
-    VD[I] = V;
+    Dest[I] = V;
     I++;
   }
-  assert(I == N);
-
-  return VD;
 }
 
 void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
index fc7fc8aa1e25dd4e621048d183c9a97daa324c93..b670902f3f9f5ca824c413af3abab09a629fbed8 100644 (file)
@@ -166,10 +166,8 @@ void ValueProfRecord::serializeFrom(const InstrProfRecord &Record,
   for (uint32_t S = 0; S < NumValueSites; S++) {
     uint32_t ND = Record.getNumValueDataForSite(ValueKind, S);
     SiteCountArray[S] = ND;
-    std::unique_ptr<InstrProfValueData[]> SrcVD =
-        Record.getValueForSite(ValueKind, S);
+    Record.getValueForSite(DstVD, ValueKind, S);
     for (uint32_t I = 0; I < ND; I++) {
-      DstVD[I] = SrcVD[I];
       switch (ValueKind) {
       case IPVK_IndirectCallTarget:
         DstVD[I].Value = IndexedInstrProf::ComputeHash(