[llvm] r207009 - ProfileData: Avoid unnecessary copies of CounterData

Justin Bogner mail at justinbogner.com
Wed Apr 23 11:50:16 PDT 2014


Author: bogner
Date: Wed Apr 23 13:50:16 2014
New Revision: 207009

URL: http://llvm.org/viewvc/llvm-project?rev=207009&view=rev
Log:
ProfileData: Avoid unnecessary copies of CounterData

We're currently copying CounterData from InstrProfWriter into the
OnDiskHashTable, even though we don't need to, and then carelessly
leaking those copies. A const pointer is much better here.

Modified:
    llvm/trunk/lib/ProfileData/InstrProfWriter.cpp

Modified: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=207009&r1=207008&r2=207009&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp Wed Apr 23 13:50:16 2014
@@ -27,8 +27,8 @@ public:
   typedef StringRef key_type;
   typedef StringRef key_type_ref;
 
-  typedef InstrProfWriter::CounterData data_type;
-  typedef const InstrProfWriter::CounterData &data_type_ref;
+  typedef const InstrProfWriter::CounterData *const data_type;
+  typedef const InstrProfWriter::CounterData *const data_type_ref;
 
   typedef uint64_t hash_value_type;
   typedef uint64_t offset_type;
@@ -45,7 +45,7 @@ public:
     offset_type N = K.size();
     LE.write<offset_type>(N);
 
-    offset_type M = (1 + V.Counts.size()) * sizeof(uint64_t);
+    offset_type M = (1 + V->Counts.size()) * sizeof(uint64_t);
     LE.write<offset_type>(M);
 
     return std::make_pair(N, M);
@@ -59,8 +59,8 @@ public:
                        offset_type) {
     using namespace llvm::support;
     endian::Writer<little> LE(Out);
-    LE.write<uint64_t>(V.Hash);
-    for (uint64_t I : V.Counts)
+    LE.write<uint64_t>(V->Hash);
+    for (uint64_t I : V->Counts)
       LE.write<uint64_t>(I);
   }
 };
@@ -100,7 +100,7 @@ void InstrProfWriter::write(raw_fd_ostre
 
   // Populate the hash table generator.
   for (const auto &I : FunctionData) {
-    Generator.insert(I.getKey(), I.getValue());
+    Generator.insert(I.getKey(), &I.getValue());
     if (I.getValue().Counts[0] > MaxFunctionCount)
       MaxFunctionCount = I.getValue().Counts[0];
   }





More information about the llvm-commits mailing list