[PGO] Move value profile data definitions out of IndexedInstrProf
authorXinliang David Li <davidxl@google.com>
Tue, 17 Nov 2015 23:00:40 +0000 (23:00 +0000)
committerXinliang David Li <davidxl@google.com>
Tue, 17 Nov 2015 23:00:40 +0000 (23:00 +0000)
Move the data structure defintions out of the namespace. The defs will
be shared by raw format. [NFC]

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253394 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2339a46f9c5540c55b3cd3a788e07aadf0b34add..aa100a796f2d60e23b59b51e6215a54229f124f9 100644 (file)
@@ -401,46 +401,6 @@ void InstrProfRecord::updateStrings(InstrProfStringTable *StrTab) {
       VData.Value = (uint64_t)StrTab->insertString((const char *)VData.Value);
 }
 
-namespace IndexedInstrProf {
-enum class HashT : uint32_t {
-  MD5,
-
-  Last = MD5
-};
-
-static inline uint64_t MD5Hash(StringRef Str) {
-  MD5 Hash;
-  Hash.update(Str);
-  llvm::MD5::MD5Result Result;
-  Hash.final(Result);
-  // Return the least significant 8 bytes. Our MD5 implementation returns the
-  // result in little endian, so we may need to swap bytes.
-  using namespace llvm::support;
-  return endian::read<uint64_t, little, unaligned>(Result);
-}
-
-static inline uint64_t ComputeHash(HashT Type, StringRef K) {
-  switch (Type) {
-    case HashT::MD5:
-      return IndexedInstrProf::MD5Hash(K);
-  }
-  llvm_unreachable("Unhandled hash type");
-}
-
-const uint64_t Magic = 0x8169666f72706cff;  // "\xfflprofi\x81"
-const uint64_t Version = 3;
-const HashT HashType = HashT::MD5;
-
-// This structure defines the file header of the LLVM profile
-// data file in indexed-format.
-struct Header {
-  uint64_t Magic;
-  uint64_t Version;
-  uint64_t MaxFunctionCount;
-  uint64_t HashType;
-  uint64_t HashOffset;
-};
-
 inline support::endianness getHostEndianness() {
   return sys::IsLittleEndianHost ? support::little : support::big;
 }
@@ -540,7 +500,48 @@ struct ValueProfData {
   ValueProfRecord *getFirstValueProfRecord();
 };
 
-}  // end namespace IndexedInstrProf
+namespace IndexedInstrProf {
+
+enum class HashT : uint32_t {
+  MD5,
+
+  Last = MD5
+};
+
+static inline uint64_t MD5Hash(StringRef Str) {
+  MD5 Hash;
+  Hash.update(Str);
+  llvm::MD5::MD5Result Result;
+  Hash.final(Result);
+  // Return the least significant 8 bytes. Our MD5 implementation returns the
+  // result in little endian, so we may need to swap bytes.
+  using namespace llvm::support;
+  return endian::read<uint64_t, little, unaligned>(Result);
+}
+
+static inline uint64_t ComputeHash(HashT Type, StringRef K) {
+  switch (Type) {
+  case HashT::MD5:
+    return IndexedInstrProf::MD5Hash(K);
+  }
+  llvm_unreachable("Unhandled hash type");
+}
+
+const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
+const uint64_t Version = 3;
+const HashT HashType = HashT::MD5;
+
+// This structure defines the file header of the LLVM profile
+// data file in indexed-format.
+struct Header {
+  uint64_t Magic;
+  uint64_t Version;
+  uint64_t MaxFunctionCount;
+  uint64_t HashType;
+  uint64_t HashOffset;
+};
+
+} // end namespace IndexedInstrProf
 
 namespace RawInstrProf {
 
index 2dd0f916c6d25955071b6d341932f9cc452607fb..fc7fc8aa1e25dd4e621048d183c9a97daa324c93 100644 (file)
@@ -131,8 +131,6 @@ GlobalVariable *createPGOFuncNameVar(Function &F, StringRef FuncName) {
   return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), FuncName);
 }
 
-namespace IndexedInstrProf {
-
 uint32_t ValueProfRecord::getHeaderSize(uint32_t NumValueSites) {
   uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
                   sizeof(uint8_t) * NumValueSites;
@@ -174,7 +172,8 @@ void ValueProfRecord::serializeFrom(const InstrProfRecord &Record,
       DstVD[I] = SrcVD[I];
       switch (ValueKind) {
       case IPVK_IndirectCallTarget:
-        DstVD[I].Value = ComputeHash(HashType, (const char *)DstVD[I].Value);
+        DstVD[I].Value = IndexedInstrProf::ComputeHash(
+            IndexedInstrProf::HashType, (const char *)DstVD[I].Value);
         break;
       default:
         llvm_unreachable("value kind not handled !");
@@ -361,6 +360,4 @@ InstrProfValueData *ValueProfRecord::getValueData() {
   return reinterpret_cast<InstrProfValueData *>((char *)this +
                                                 getHeaderSize(NumValueSites));
 }
-
-} // End of IndexedInstrProf namespace.
 }
index 6f201243736d09baecce19d27c1fa7478a70add8..479b6bc61d95e706b1489b16bec22d829eab6a3f 100644 (file)
@@ -313,9 +313,8 @@ typedef InstrProfLookupTrait::offset_type offset_type;
 
 bool InstrProfLookupTrait::ReadValueProfilingData(
     const unsigned char *&D, const unsigned char *const End) {
-  ErrorOr<std::unique_ptr<IndexedInstrProf::ValueProfData>> VDataPtrOrErr =
-      IndexedInstrProf::ValueProfData::getValueProfData(
-          D, End, ValueProfDataEndianness);
+  ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
+      ValueProfData::getValueProfData(D, End, ValueProfDataEndianness);
 
   if (VDataPtrOrErr.getError())
     return false;
index b6725df52780250393570ea42a744386f3fef45b..cb123e29982fd56737a36d16041c60efd80e6688 100644 (file)
@@ -53,7 +53,7 @@ public:
       M += ProfRecord.Counts.size() * sizeof(uint64_t);
 
       // Value data
-      M += IndexedInstrProf::ValueProfData::getSize(ProfileData.second);
+      M += ValueProfData::getSize(ProfileData.second);
     }
     LE.write<offset_type>(M);
 
@@ -77,8 +77,8 @@ public:
         LE.write<uint64_t>(I);
 
       // Write value data
-      std::unique_ptr<IndexedInstrProf::ValueProfData> VDataPtr =
-          IndexedInstrProf::ValueProfData::serializeFrom(ProfileData.second);
+      std::unique_ptr<ValueProfData> VDataPtr =
+          ValueProfData::serializeFrom(ProfileData.second);
       uint32_t S = VDataPtr->getSize();
       VDataPtr->swapBytesFromHost(ValueProfDataEndianness);
       Out.write((const char *)VDataPtr.get(), S);