[llvm] r257737 - [PGO] clean up and documentation

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 13 18:47:01 PST 2016


Author: davidxl
Date: Wed Jan 13 20:47:01 2016
New Revision: 257737

URL: http://llvm.org/viewvc/llvm-project?rev=257737&view=rev
Log:
[PGO] clean up and documentation

Introduce enum for indexed format versions and 
document indexed format change history.

Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProf.h
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp
    llvm/trunk/lib/ProfileData/InstrProfWriter.cpp

Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=257737&r1=257736&r2=257737&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Wed Jan 13 20:47:01 2016
@@ -581,7 +581,26 @@ inline uint64_t ComputeHash(HashT Type,
 }
 
 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
-const uint64_t Version = INSTR_PROF_INDEX_VERSION;
+
+enum ProfVersion {
+  // Version 1 is the first version. In this version, the value of
+  // a key/value pair can only include profile data of a single function.
+  // Due to this restriction, the number of block counters for a given
+  // function is not recorded by derived from the length of the value.
+  Version1 = 1,
+  // In version 2, the format supports recording profile data of multiple
+  // functions which share the same key in one value field. To suppor this,
+  // the number block counters is recorded as an uint64_t right after the
+  // function structural hash.
+  Version2 = 2,
+  // Version 3 supports value profile data. Value profile data is expected
+  // to follow the block counter profile data.
+  Version3 = 3,
+  // The current version is 3.
+  CurrentVersion = INSTR_PROF_INDEX_VERSION
+};
+const uint64_t Version = ProfVersion::CurrentVersion;
+
 const HashT HashType = HashT::MD5;
 
 inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=257737&r1=257736&r2=257737&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Wed Jan 13 20:47:01 2016
@@ -478,7 +478,7 @@ data_type InstrProfLookupTrait::ReadData
     // Initialize number of counters for FormatVersion == 1.
     uint64_t CountsSize = N / sizeof(uint64_t) - 1;
     // If format version is different then read the number of counters.
-    if (FormatVersion != 1) {
+    if (FormatVersion != IndexedInstrProf::ProfVersion::Version1) {
       if (D + sizeof(uint64_t) > End)
         return data_type();
       CountsSize = endian::readNext<uint64_t, little, unaligned>(D);
@@ -495,7 +495,8 @@ data_type InstrProfLookupTrait::ReadData
     DataBuffer.emplace_back(K, Hash, std::move(CounterBuffer));
 
     // Read value profiling data.
-    if (FormatVersion > 2 && !readValueProfilingData(D, End)) {
+    if (FormatVersion > IndexedInstrProf::ProfVersion::Version2 &&
+        !readValueProfilingData(D, End)) {
       DataBuffer.clear();
       return data_type();
     }
@@ -572,7 +573,7 @@ std::error_code IndexedInstrProfReader::
 
   // Read the version.
   uint64_t FormatVersion = endian::byte_swap<uint64_t, little>(Header->Version);
-  if (FormatVersion > IndexedInstrProf::Version)
+  if (FormatVersion > IndexedInstrProf::ProfVersion::CurrentVersion)
     return error(instrprof_error::unsupported_version);
 
   // Read the maximal function count.

Modified: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=257737&r1=257736&r2=257737&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp Wed Jan 13 20:47:01 2016
@@ -140,7 +140,7 @@ std::pair<uint64_t, uint64_t> InstrProfW
   // Write the header.
   IndexedInstrProf::Header Header;
   Header.Magic = IndexedInstrProf::Magic;
-  Header.Version = IndexedInstrProf::Version;
+  Header.Version = IndexedInstrProf::ProfVersion::CurrentVersion;
   Header.MaxFunctionCount = MaxFunctionCount;
   Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
   Header.HashOffset = 0;




More information about the llvm-commits mailing list