[llvm] d38d6ca - [llvm-profdata] Deprecate Compact Binary Sample Profile Format

William Huang via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 10:10:18 PDT 2023


Author: William Huang
Date: 2023-05-01T17:10:08Z
New Revision: d38d6ca1798b339a8d292e91f8e0708c334769ff

URL: https://github.com/llvm/llvm-project/commit/d38d6ca1798b339a8d292e91f8e0708c334769ff
DIFF: https://github.com/llvm/llvm-project/commit/d38d6ca1798b339a8d292e91f8e0708c334769ff.diff

LOG: [llvm-profdata] Deprecate Compact Binary Sample Profile Format

Remove support for compact binary sample profile format

Reviewed By: davidxl, wenlei

Differential Revision: https://reviews.llvm.org/D149400

Added: 
    llvm/test/Transforms/SampleProfile/Inputs/indirect-call.extbinary.afdo

Modified: 
    llvm/include/llvm/ProfileData/SampleProf.h
    llvm/include/llvm/ProfileData/SampleProfReader.h
    llvm/include/llvm/ProfileData/SampleProfWriter.h
    llvm/lib/ProfileData/SampleProfReader.cpp
    llvm/lib/ProfileData/SampleProfWriter.cpp
    llvm/test/Transforms/SampleProfile/indirect-call.ll
    llvm/test/Transforms/SampleProfile/profile-format.ll
    llvm/test/tools/llvm-profdata/roundtrip.test
    llvm/tools/llvm-profdata/llvm-profdata.cpp
    llvm/tools/llvm-profgen/ProfileGenerator.cpp
    llvm/unittests/ProfileData/SampleProfTest.cpp
    llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp

Removed: 
    llvm/test/Transforms/SampleProfile/Inputs/indirect-call.compact.afdo
    llvm/test/Transforms/SampleProfile/Inputs/inline.compactbinary.afdo
    llvm/test/tools/llvm-profdata/Inputs/compat-sample.profdata
    llvm/test/tools/llvm-profdata/compact-sample.proftext


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 69003d32699b5..b8456eec1e9fd 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -90,7 +90,7 @@ namespace sampleprof {
 enum SampleProfileFormat {
   SPF_None = 0,
   SPF_Text = 0x1,
-  SPF_Compact_Binary = 0x2,
+  SPF_Compact_Binary = 0x2, // Deprecated
   SPF_GCC = 0x3,
   SPF_Ext_Binary = 0x4,
   SPF_Binary = 0xff

diff  --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index d6f8c27fbe6b9..3b657b3ab4621 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -811,41 +811,6 @@ class SampleProfileReaderExtBinary : public SampleProfileReaderExtBinaryBase {
   static bool hasFormat(const MemoryBuffer &Buffer);
 };
 
-class SampleProfileReaderCompactBinary : public SampleProfileReaderBinary {
-private:
-  /// Function name table.
-  std::vector<std::string> NameTable;
-  /// The table mapping from function name to the offset of its FunctionSample
-  /// towards file start.
-  DenseMap<StringRef, uint64_t> FuncOffsetTable;
-  /// The set containing the functions to use when compiling a module.
-  DenseSet<StringRef> FuncsToUse;
-  std::error_code verifySPMagic(uint64_t Magic) override;
-  std::error_code readNameTable() override;
-  /// Read a string indirectly via the name table.
-  ErrorOr<StringRef> readStringFromTable() override;
-  std::error_code readHeader() override;
-  std::error_code readFuncOffsetTable();
-
-public:
-  SampleProfileReaderCompactBinary(std::unique_ptr<MemoryBuffer> B,
-                                   LLVMContext &C)
-      : SampleProfileReaderBinary(std::move(B), C, SPF_Compact_Binary) {}
-
-  /// \brief Return true if \p Buffer is in the format supported by this class.
-  static bool hasFormat(const MemoryBuffer &Buffer);
-
-  /// Read samples only for functions to use.
-  std::error_code readImpl() override;
-
-  /// Collect functions with definitions in Module M. Return true if
-  /// the reader has been given a module.
-  bool collectFuncsFromModule() override;
-
-  /// Return whether names in the profile are all MD5 numbers.
-  bool useMD5() override { return true; }
-};
-
 using InlineCallStack = SmallVector<FunctionSamples *, 10>;
 
 // Supported histogram types in GCC.  Currently, we only need support for

diff  --git a/llvm/include/llvm/ProfileData/SampleProfWriter.h b/llvm/include/llvm/ProfileData/SampleProfWriter.h
index 4edb3b049e704..1f19283ea1dd0 100644
--- a/llvm/include/llvm/ProfileData/SampleProfWriter.h
+++ b/llvm/include/llvm/ProfileData/SampleProfWriter.h
@@ -414,55 +414,6 @@ class SampleProfileWriterExtBinary : public SampleProfileWriterExtBinaryBase {
   }
 };
 
-// CompactBinary is a compact format of binary profile which both reduces
-// the profile size and the load time needed when compiling. It has two
-// major 
diff erence with Binary format.
-// 1. It represents all the strings in name table using md5 hash.
-// 2. It saves a function offset table which maps function name index to
-// the offset of its function profile to the start of the binary profile,
-// so by using the function offset table, for those function profiles which
-// will not be needed when compiling a module, the profile reader does't
-// have to read them and it saves compile time if the profile size is huge.
-// The layout of the compact format is shown as follows:
-//
-//    Part1: Profile header, the same as binary format, containing magic
-//           number, version, summary, name table...
-//    Part2: Function Offset Table Offset, which saves the position of
-//           Part4.
-//    Part3: Function profile collection
-//             function1 profile start
-//                 ....
-//             function2 profile start
-//                 ....
-//             function3 profile start
-//                 ....
-//                ......
-//    Part4: Function Offset Table
-//             function1 name index --> function1 profile start
-//             function2 name index --> function2 profile start
-//             function3 name index --> function3 profile start
-//
-// We need Part2 because profile reader can use it to find out and read
-// function offset table without reading Part3 first.
-class SampleProfileWriterCompactBinary : public SampleProfileWriterBinary {
-  using SampleProfileWriterBinary::SampleProfileWriterBinary;
-
-public:
-  std::error_code writeSample(const FunctionSamples &S) override;
-  std::error_code write(const SampleProfileMap &ProfileMap) override;
-
-protected:
-  /// The table mapping from function name to the offset of its FunctionSample
-  /// towards profile start.
-  MapVector<StringRef, uint64_t> FuncOffsetTable;
-  /// The offset of the slot to be filled with the offset of FuncOffsetTable
-  /// towards profile start.
-  uint64_t TableOffset;
-  std::error_code writeNameTable() override;
-  std::error_code writeHeader(const SampleProfileMap &ProfileMap) override;
-  std::error_code writeFuncOffsetTable();
-};
-
 } // end namespace sampleprof
 } // end namespace llvm
 

diff  --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index dd23a4029ba9e..6f5dedb26b1aa 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -51,7 +51,7 @@ using namespace sampleprof;
 #define DEBUG_TYPE "samplepgo-reader"
 
 // This internal option specifies if the profile uses FS discriminators.
-// It only applies to text, binary and compact binary format profiles.
+// It only applies to text, and binary format profiles.
 // For ext-binary format profiles, the flag is set in the summary.
 static cl::opt<bool> ProfileIsFSDisciminator(
     "profile-isfs", cl::Hidden, cl::init(false),
@@ -568,14 +568,6 @@ ErrorOr<StringRef> SampleProfileReaderExtBinaryBase::readStringFromTable() {
   return SR;
 }
 
-ErrorOr<StringRef> SampleProfileReaderCompactBinary::readStringFromTable() {
-  auto Idx = readStringIndex(NameTable);
-  if (std::error_code EC = Idx.getError())
-    return EC;
-
-  return StringRef(NameTable[*Idx]);
-}
-
 std::error_code
 SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
   auto NumSamples = readNumber<uint64_t>();
@@ -1012,40 +1004,6 @@ std::error_code SampleProfileReaderExtBinaryBase::readImpl() {
   return sampleprof_error::success;
 }
 
-std::error_code SampleProfileReaderCompactBinary::readImpl() {
-  // Collect functions used by current module if the Reader has been
-  // given a module.
-  bool LoadFuncsToBeUsed = collectFuncsFromModule();
-  ProfileIsFS = ProfileIsFSDisciminator;
-  FunctionSamples::ProfileIsFS = ProfileIsFS;
-  std::vector<uint64_t> OffsetsToUse;
-  if (!LoadFuncsToBeUsed) {
-    // load all the function profiles.
-    for (auto FuncEntry : FuncOffsetTable) {
-      OffsetsToUse.push_back(FuncEntry.second);
-    }
-  } else {
-    // load function profiles on demand.
-    for (auto Name : FuncsToUse) {
-      auto GUID = std::to_string(MD5Hash(Name));
-      auto iter = FuncOffsetTable.find(StringRef(GUID));
-      if (iter == FuncOffsetTable.end())
-        continue;
-      OffsetsToUse.push_back(iter->second);
-    }
-  }
-
-  for (auto Offset : OffsetsToUse) {
-    const uint8_t *SavedData = Data;
-    if (std::error_code EC = readFuncProfile(
-            reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
-            Offset))
-      return EC;
-    Data = SavedData;
-  }
-  return sampleprof_error::success;
-}
-
 std::error_code SampleProfileReaderRawBinary::verifySPMagic(uint64_t Magic) {
   if (Magic == SPMagic())
     return sampleprof_error::success;
@@ -1058,13 +1016,6 @@ std::error_code SampleProfileReaderExtBinary::verifySPMagic(uint64_t Magic) {
   return sampleprof_error::bad_magic;
 }
 
-std::error_code
-SampleProfileReaderCompactBinary::verifySPMagic(uint64_t Magic) {
-  if (Magic == SPMagic(SPF_Compact_Binary))
-    return sampleprof_error::success;
-  return sampleprof_error::bad_magic;
-}
-
 std::error_code SampleProfileReaderBinary::readNameTable() {
   auto Size = readNumber<size_t>();
   if (std::error_code EC = Size.getError())
@@ -1234,20 +1185,6 @@ SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute) {
   return sampleprof_error::success;
 }
 
-std::error_code SampleProfileReaderCompactBinary::readNameTable() {
-  auto Size = readNumber<uint64_t>();
-  if (std::error_code EC = Size.getError())
-    return EC;
-  NameTable.reserve(*Size);
-  for (uint64_t I = 0; I < *Size; ++I) {
-    auto FID = readNumber<uint64_t>();
-    if (std::error_code EC = FID.getError())
-      return EC;
-    NameTable.push_back(std::to_string(*FID));
-  }
-  return sampleprof_error::success;
-}
-
 std::error_code
 SampleProfileReaderExtBinaryBase::readSecHdrTableEntry(uint64_t Idx) {
   SecHdrTableEntry Entry;
@@ -1427,54 +1364,6 @@ std::error_code SampleProfileReaderBinary::readHeader() {
   return sampleprof_error::success;
 }
 
-std::error_code SampleProfileReaderCompactBinary::readHeader() {
-  SampleProfileReaderBinary::readHeader();
-  if (std::error_code EC = readFuncOffsetTable())
-    return EC;
-  return sampleprof_error::success;
-}
-
-std::error_code SampleProfileReaderCompactBinary::readFuncOffsetTable() {
-  auto TableOffset = readUnencodedNumber<uint64_t>();
-  if (std::error_code EC = TableOffset.getError())
-    return EC;
-
-  const uint8_t *SavedData = Data;
-  const uint8_t *TableStart =
-      reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
-      *TableOffset;
-  Data = TableStart;
-
-  auto Size = readNumber<uint64_t>();
-  if (std::error_code EC = Size.getError())
-    return EC;
-
-  FuncOffsetTable.reserve(*Size);
-  for (uint64_t I = 0; I < *Size; ++I) {
-    auto FName(readStringFromTable());
-    if (std::error_code EC = FName.getError())
-      return EC;
-
-    auto Offset = readNumber<uint64_t>();
-    if (std::error_code EC = Offset.getError())
-      return EC;
-
-    FuncOffsetTable[*FName] = *Offset;
-  }
-  End = TableStart;
-  Data = SavedData;
-  return sampleprof_error::success;
-}
-
-bool SampleProfileReaderCompactBinary::collectFuncsFromModule() {
-  if (!M)
-    return false;
-  FuncsToUse.clear();
-  for (auto &F : *M)
-    FuncsToUse.insert(FunctionSamples::getCanonicalFnName(F));
-  return true;
-}
-
 std::error_code SampleProfileReaderBinary::readSummaryEntry(
     std::vector<ProfileSummaryEntry> &Entries) {
   auto Cutoff = readNumber<uint64_t>();
@@ -1545,13 +1434,6 @@ bool SampleProfileReaderExtBinary::hasFormat(const MemoryBuffer &Buffer) {
   return Magic == SPMagic(SPF_Ext_Binary);
 }
 
-bool SampleProfileReaderCompactBinary::hasFormat(const MemoryBuffer &Buffer) {
-  const uint8_t *Data =
-      reinterpret_cast<const uint8_t *>(Buffer.getBufferStart());
-  uint64_t Magic = decodeULEB128(Data);
-  return Magic == SPMagic(SPF_Compact_Binary);
-}
-
 std::error_code SampleProfileReaderGCC::skipNextWord() {
   uint32_t dummy;
   if (!GcovBuffer.readInt(dummy))
@@ -1803,7 +1685,7 @@ void SampleProfileReaderItaniumRemapper::applyRemapping(LLVMContext &Ctx) {
     Ctx.diagnose(DiagnosticInfoSampleProfile(
         Reader.getBuffer()->getBufferIdentifier(),
         "Profile data remapping cannot be applied to profile data "
-        "in compact format (original mangled names are not available).",
+        "using MD5 names (original mangled names are not available).",
         DS_Warning));
     return;
   }
@@ -1934,8 +1816,6 @@ SampleProfileReader::create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
     Reader.reset(new SampleProfileReaderRawBinary(std::move(B), C));
   else if (SampleProfileReaderExtBinary::hasFormat(*B))
     Reader.reset(new SampleProfileReaderExtBinary(std::move(B), C));
-  else if (SampleProfileReaderCompactBinary::hasFormat(*B))
-    Reader.reset(new SampleProfileReaderCompactBinary(std::move(B), C));
   else if (SampleProfileReaderGCC::hasFormat(*B))
     Reader.reset(new SampleProfileReaderGCC(std::move(B), C));
   else if (SampleProfileReaderText::hasFormat(*B))

diff  --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp
index bce858a99a819..0873093ad426c 100644
--- a/llvm/lib/ProfileData/SampleProfWriter.cpp
+++ b/llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -557,15 +557,6 @@ std::error_code SampleProfileWriterExtBinary::writeSections(
   return EC;
 }
 
-std::error_code
-SampleProfileWriterCompactBinary::write(const SampleProfileMap &ProfileMap) {
-  if (std::error_code EC = SampleProfileWriter::write(ProfileMap))
-    return EC;
-  if (std::error_code EC = writeFuncOffsetTable())
-    return EC;
-  return sampleprof_error::success;
-}
-
 /// Write samples to a text file.
 ///
 /// Note: it may be tempting to implement this in terms of
@@ -712,41 +703,6 @@ std::error_code SampleProfileWriterBinary::writeNameTable() {
   return sampleprof_error::success;
 }
 
-std::error_code SampleProfileWriterCompactBinary::writeFuncOffsetTable() {
-  auto &OS = *OutputStream;
-
-  // Fill the slot remembered by TableOffset with the offset of FuncOffsetTable.
-  uint64_t FuncOffsetTableStart = OS.tell();
-  support::endian::SeekableWriter Writer(static_cast<raw_pwrite_stream &>(OS),
-                                         support::little);
-  Writer.pwrite(FuncOffsetTableStart, TableOffset);
-
-  // Write out the table size.
-  encodeULEB128(FuncOffsetTable.size(), OS);
-
-  // Write out FuncOffsetTable.
-  for (auto Entry : FuncOffsetTable) {
-    if (std::error_code EC = writeNameIdx(Entry.first))
-      return EC;
-    encodeULEB128(Entry.second, OS);
-  }
-  FuncOffsetTable.clear();
-  return sampleprof_error::success;
-}
-
-std::error_code SampleProfileWriterCompactBinary::writeNameTable() {
-  auto &OS = *OutputStream;
-  std::set<StringRef> V;
-  stablizeNameTable(NameTable, V);
-
-  // Write out the name table.
-  encodeULEB128(NameTable.size(), OS);
-  for (auto N : V) {
-    encodeULEB128(MD5Hash(N), OS);
-  }
-  return sampleprof_error::success;
-}
-
 std::error_code
 SampleProfileWriterBinary::writeMagicIdent(SampleProfileFormat Format) {
   auto &OS = *OutputStream;
@@ -848,19 +804,6 @@ std::error_code SampleProfileWriterExtBinaryBase::writeHeader(
   return sampleprof_error::success;
 }
 
-std::error_code SampleProfileWriterCompactBinary::writeHeader(
-    const SampleProfileMap &ProfileMap) {
-  support::endian::Writer Writer(*OutputStream, support::little);
-  if (auto EC = SampleProfileWriterBinary::writeHeader(ProfileMap))
-    return EC;
-
-  // Reserve a slot for the offset of function offset table. The slot will
-  // be populated with the offset of FuncOffsetTable later.
-  TableOffset = OutputStream->tell();
-  Writer.write(static_cast<uint64_t>(-2));
-  return sampleprof_error::success;
-}
-
 std::error_code SampleProfileWriterBinary::writeSummary() {
   auto &OS = *OutputStream;
   encodeULEB128(Summary->getTotalCount(), OS);
@@ -930,15 +873,6 @@ SampleProfileWriterBinary::writeSample(const FunctionSamples &S) {
   return writeBody(S);
 }
 
-std::error_code
-SampleProfileWriterCompactBinary::writeSample(const FunctionSamples &S) {
-  uint64_t Offset = OutputStream->tell();
-  StringRef Name = S.getName();
-  FuncOffsetTable[Name] = Offset;
-  encodeULEB128(S.getHeadSamples(), *OutputStream);
-  return writeBody(S);
-}
-
 /// Create a sample profile file writer based on the specified format.
 ///
 /// \param Filename The file to create.
@@ -950,8 +884,7 @@ ErrorOr<std::unique_ptr<SampleProfileWriter>>
 SampleProfileWriter::create(StringRef Filename, SampleProfileFormat Format) {
   std::error_code EC;
   std::unique_ptr<raw_ostream> OS;
-  if (Format == SPF_Binary || Format == SPF_Ext_Binary ||
-      Format == SPF_Compact_Binary)
+  if (Format == SPF_Binary || Format == SPF_Ext_Binary)
     OS.reset(new raw_fd_ostream(Filename, EC, sys::fs::OF_None));
   else
     OS.reset(new raw_fd_ostream(Filename, EC, sys::fs::OF_TextWithCRLF));
@@ -976,15 +909,13 @@ SampleProfileWriter::create(std::unique_ptr<raw_ostream> &OS,
 
   // Currently only Text and Extended Binary format are supported for CSSPGO.
   if ((FunctionSamples::ProfileIsCS || FunctionSamples::ProfileIsProbeBased) &&
-      (Format == SPF_Binary || Format == SPF_Compact_Binary))
+      Format == SPF_Binary)
     return sampleprof_error::unsupported_writing_format;
 
   if (Format == SPF_Binary)
     Writer.reset(new SampleProfileWriterRawBinary(OS));
   else if (Format == SPF_Ext_Binary)
     Writer.reset(new SampleProfileWriterExtBinary(OS));
-  else if (Format == SPF_Compact_Binary)
-    Writer.reset(new SampleProfileWriterCompactBinary(OS));
   else if (Format == SPF_Text)
     Writer.reset(new SampleProfileWriterText(OS));
   else if (Format == SPF_GCC)

diff  --git a/llvm/test/Transforms/SampleProfile/Inputs/indirect-call.compact.afdo b/llvm/test/Transforms/SampleProfile/Inputs/indirect-call.compact.afdo
deleted file mode 100644
index b08efbecf55fe..0000000000000
Binary files a/llvm/test/Transforms/SampleProfile/Inputs/indirect-call.compact.afdo and /dev/null 
diff er

diff  --git a/llvm/test/Transforms/SampleProfile/Inputs/indirect-call.extbinary.afdo b/llvm/test/Transforms/SampleProfile/Inputs/indirect-call.extbinary.afdo
new file mode 100644
index 0000000000000..51cac9231fcf6
Binary files /dev/null and b/llvm/test/Transforms/SampleProfile/Inputs/indirect-call.extbinary.afdo 
diff er

diff  --git a/llvm/test/Transforms/SampleProfile/Inputs/inline.compactbinary.afdo b/llvm/test/Transforms/SampleProfile/Inputs/inline.compactbinary.afdo
deleted file mode 100644
index c9fde76998281..0000000000000
Binary files a/llvm/test/Transforms/SampleProfile/Inputs/inline.compactbinary.afdo and /dev/null 
diff er

diff  --git a/llvm/test/Transforms/SampleProfile/indirect-call.ll b/llvm/test/Transforms/SampleProfile/indirect-call.ll
index 53aaa977c1807..089474c7c149a 100644
--- a/llvm/test/Transforms/SampleProfile/indirect-call.ll
+++ b/llvm/test/Transforms/SampleProfile/indirect-call.ll
@@ -1,5 +1,5 @@
 ; RUN: opt -S %s -passes=sample-profile -sample-profile-file=%S/Inputs/indirect-call.prof | FileCheck %s
-; RUN: opt -S %s -passes=sample-profile -sample-profile-file=%S/Inputs/indirect-call.compact.afdo | FileCheck %s
+; RUN: opt -S %s -passes=sample-profile -sample-profile-file=%S/Inputs/indirect-call.extbinary.afdo | FileCheck %s
 
 ; CHECK-LABEL: @test
 define void @test(ptr) #0 !dbg !3 {

diff  --git a/llvm/test/Transforms/SampleProfile/profile-format.ll b/llvm/test/Transforms/SampleProfile/profile-format.ll
index be36267d8e3c9..d9e26404b7ae0 100644
--- a/llvm/test/Transforms/SampleProfile/profile-format.ll
+++ b/llvm/test/Transforms/SampleProfile/profile-format.ll
@@ -1,5 +1,4 @@
 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.prof -S | FileCheck %s
-; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.compactbinary.afdo -S | FileCheck %s
 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.extbinary.afdo -S | FileCheck %s
 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.md5extbinary.afdo -S | FileCheck %s
 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.fixlenmd5.extbinary.afdo -S | FileCheck %s

diff  --git a/llvm/test/tools/llvm-profdata/Inputs/compat-sample.profdata b/llvm/test/tools/llvm-profdata/Inputs/compat-sample.profdata
deleted file mode 100644
index 9c954d4feaf38..0000000000000
Binary files a/llvm/test/tools/llvm-profdata/Inputs/compat-sample.profdata and /dev/null 
diff er

diff  --git a/llvm/test/tools/llvm-profdata/compact-sample.proftext b/llvm/test/tools/llvm-profdata/compact-sample.proftext
deleted file mode 100644
index 6ebb83949481f..0000000000000
--- a/llvm/test/tools/llvm-profdata/compact-sample.proftext
+++ /dev/null
@@ -1,20 +0,0 @@
-# Make sure "llvm-profdata show" works for sample profile in binary compact format
-
-# RUN: llvm-profdata show -sample %S/Inputs/compat-sample.profdata | FileCheck %s
-
-# CHECK: Function: 15822663052811949562: 17, 0, 6 sampled lines
-# CHECK-NEXT: Samples collected in the function's body {
-# CHECK: Samples collected in inlined callsites {
-# CHECK-NEXT: 1: inlined callee: 6309742469962978389: 17, 0, 1
-
-# RUN: llvm-profdata show -hot-func-list -sample %S/Inputs/compat-sample.profdata | FileCheck %s --check-prefix=HOTFUNC
-# HOTFUNC:      24753993 out of 24754010 profile counts (100.00%) are from hot functions.
-# HOTFUNC:       Total sample (%)       Max sample        Entry sample    Function name
-# HOTFUNC-NEXT:  24753993 (100.00%)     1284671           1284671         16429767378996342100
-
-# Make sure "llvm-profdata overlap" works for sample profile in binary compact format
-# RUN: llvm-profdata overlap -sample %S/Inputs/compat-sample.profdata %S/Inputs/compat-sample.profdata | FileCheck %s --check-prefix=OVERLAP
-
-# OVERLAP:      Program level:
-# OVERLAP-NEXT:   Whole program profile similarity: 100.000%
-# OVERLAP-NEXT:   Whole program sample overlap: 100.000%

diff  --git a/llvm/test/tools/llvm-profdata/roundtrip.test b/llvm/test/tools/llvm-profdata/roundtrip.test
index a458b21ac0839..7af76e0a58224 100644
--- a/llvm/test/tools/llvm-profdata/roundtrip.test
+++ b/llvm/test/tools/llvm-profdata/roundtrip.test
@@ -16,11 +16,3 @@ RUN: llvm-profdata merge --sample --binary -output=%t.4.profdata %S/Inputs/sampl
 RUN: llvm-profdata merge --sample --extbinary -output=%t.5.profdata %t.4.profdata
 RUN: llvm-profdata merge --sample --text -output=%t.4.proftext %t.5.profdata
 RUN: 
diff  -b %t.4.proftext %S/Inputs/sample-profile.proftext
-# Trip from text --> extbinary --> md5text
-# Trip from text --> compbinary --> md5text
-# Compare the two md5 texts
-RUN: llvm-profdata merge --sample --compbinary -output=%t.6.profdata %S/Inputs/sample-profile.proftext
-RUN: llvm-profdata merge --sample --text -output=%t.6.proftext %t.6.profdata
-RUN: llvm-profdata merge --sample --extbinary -use-md5 -output=%t.7.profdata %S/Inputs/sample-profile.proftext
-RUN: llvm-profdata merge --sample --text -output=%t.7.proftext %t.7.profdata
-RUN: 
diff  -b %t.6.proftext %t.7.proftext

diff  --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index e14bfd826cfd7..d3dc26aa28855 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -53,7 +53,7 @@ const std::string DuplicateNameStr = "----";
 enum ProfileFormat {
   PF_None = 0,
   PF_Text,
-  PF_Compact_Binary,
+  PF_Compact_Binary, // Deprecated
   PF_Ext_Binary,
   PF_GCC,
   PF_Binary
@@ -409,8 +409,10 @@ mergeInstrProfile(const WeightedFileVector &Inputs, StringRef DebugInfoFilename,
                   uint64_t MaxTraceLength, bool OutputSparse,
                   unsigned NumThreads, FailureMode FailMode,
                   const StringRef ProfiledBinary) {
-  if (OutputFormat != PF_Binary && OutputFormat != PF_Compact_Binary &&
-      OutputFormat != PF_Ext_Binary && OutputFormat != PF_Text)
+  if (OutputFormat == PF_Compact_Binary)
+    exitWithError("Compact Binary is deprecated");
+  if (OutputFormat != PF_Binary && OutputFormat != PF_Ext_Binary &&
+      OutputFormat != PF_Text)
     exitWithError("unknown format is specified");
 
   std::unique_ptr<InstrProfCorrelator> Correlator;
@@ -912,7 +914,7 @@ remapSamples(const sampleprof::FunctionSamples &Samples,
 static sampleprof::SampleProfileFormat FormatMap[] = {
     sampleprof::SPF_None,
     sampleprof::SPF_Text,
-    sampleprof::SPF_Compact_Binary,
+    sampleprof::SPF_None,
     sampleprof::SPF_Ext_Binary,
     sampleprof::SPF_GCC,
     sampleprof::SPF_Binary};
@@ -1183,8 +1185,6 @@ static int merge_main(int argc, const char *argv[]) {
       cl::desc("Format of output profile"), cl::init(PF_Binary),
       cl::values(
           clEnumValN(PF_Binary, "binary", "Binary encoding (default)"),
-          clEnumValN(PF_Compact_Binary, "compbinary",
-                     "Compact binary encoding"),
           clEnumValN(PF_Ext_Binary, "extbinary", "Extensible binary encoding"),
           clEnumValN(PF_Text, "text", "Text encoding"),
           clEnumValN(PF_GCC, "gcc",

diff  --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 2728f80da64bc..8e4b912e1b8b1 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -27,7 +27,6 @@ static cl::opt<SampleProfileFormat> OutputFormat(
     "format", cl::desc("Format of output profile"), cl::init(SPF_Ext_Binary),
     cl::values(
         clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
-        clEnumValN(SPF_Compact_Binary, "compbinary", "Compact binary encoding"),
         clEnumValN(SPF_Ext_Binary, "extbinary", "Extensible binary encoding"),
         clEnumValN(SPF_Text, "text", "Text encoding"),
         clEnumValN(SPF_GCC, "gcc",

diff  --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp
index bd34b05336e19..e01025440e4a5 100644
--- a/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -289,11 +289,10 @@ struct SampleProfTest : ::testing::Test {
     ASSERT_FALSE(CTMap.getError());
 
     // Because _Z3bazi is not defined in module M, expect _Z3bazi's profile
-    // is not loaded when the profile is ExtBinary or Compact format because
-    // these formats support loading function profiles on demand.
+    // is not loaded when the profile is ExtBinary format because this format
+    // supports loading function profiles on demand.
     FunctionSamples *ReadBazSamples = Reader->getSamplesFor(BazName);
-    if (Format == SampleProfileFormat::SPF_Ext_Binary ||
-        Format == SampleProfileFormat::SPF_Compact_Binary) {
+    if (Format == SampleProfileFormat::SPF_Ext_Binary) {
       ASSERT_TRUE(ReadBazSamples == nullptr);
       ASSERT_EQ(3u, Reader->getProfiles().size());
     } else {
@@ -408,10 +407,6 @@ TEST_F(SampleProfTest, roundtrip_raw_binary_profile) {
   testRoundTrip(SampleProfileFormat::SPF_Binary, false, false);
 }
 
-TEST_F(SampleProfTest, roundtrip_compact_binary_profile) {
-  testRoundTrip(SampleProfileFormat::SPF_Compact_Binary, false, true);
-}
-
 TEST_F(SampleProfTest, roundtrip_ext_binary_profile) {
   testRoundTrip(SampleProfileFormat::SPF_Ext_Binary, false, false);
 }
@@ -473,19 +468,6 @@ TEST_F(SampleProfTest, default_suffix_elision_text) {
   testSuffixElisionPolicy(SampleProfileFormat::SPF_Text, "", Expected);
 }
 
-TEST_F(SampleProfTest, default_suffix_elision_compact_binary) {
-  // Default suffix elision policy: strip everything after first dot.
-  // This implies that all suffix variants will map to "foo", so
-  // we don't expect to see any entries for them in the sample
-  // profile.
-  StringMap<uint64_t> Expected;
-  Expected["foo"] = uint64_t(20301);
-  Expected["foo.bar"] = uint64_t(-1);
-  Expected["foo.llvm.2465"] = uint64_t(-1);
-  testSuffixElisionPolicy(SampleProfileFormat::SPF_Compact_Binary, "",
-                          Expected);
-}
-
 TEST_F(SampleProfTest, selected_suffix_elision_text) {
   // Profile is created and searched using the "selected"
   // suffix elision policy: we only strip a .XXX suffix if
@@ -498,19 +480,6 @@ TEST_F(SampleProfTest, selected_suffix_elision_text) {
   testSuffixElisionPolicy(SampleProfileFormat::SPF_Text, "selected", Expected);
 }
 
-TEST_F(SampleProfTest, selected_suffix_elision_compact_binary) {
-  // Profile is created and searched using the "selected"
-  // suffix elision policy: we only strip a .XXX suffix if
-  // it matches a pattern known to be generated by the compiler
-  // (e.g. ".llvm.<digits>").
-  StringMap<uint64_t> Expected;
-  Expected["foo"] = uint64_t(20301);
-  Expected["foo.bar"] = uint64_t(20303);
-  Expected["foo.llvm.2465"] = uint64_t(-1);
-  testSuffixElisionPolicy(SampleProfileFormat::SPF_Compact_Binary, "selected",
-                          Expected);
-}
-
 TEST_F(SampleProfTest, none_suffix_elision_text) {
   // Profile is created and searched using the "none"
   // suffix elision policy: no stripping of suffixes at all.
@@ -522,16 +491,4 @@ TEST_F(SampleProfTest, none_suffix_elision_text) {
   testSuffixElisionPolicy(SampleProfileFormat::SPF_Text, "none", Expected);
 }
 
-TEST_F(SampleProfTest, none_suffix_elision_compact_binary) {
-  // Profile is created and searched using the "none"
-  // suffix elision policy: no stripping of suffixes at all.
-  // Here we expect to see all variants in the profile.
-  StringMap<uint64_t> Expected;
-  Expected["foo"] = uint64_t(20301);
-  Expected["foo.bar"] = uint64_t(20303);
-  Expected["foo.llvm.2465"] = uint64_t(20305);
-  testSuffixElisionPolicy(SampleProfileFormat::SPF_Compact_Binary, "none",
-                          Expected);
-}
-
 } // end anonymous namespace

diff  --git a/llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp b/llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
index 25da748865ec7..522a2c2dd3367 100644
--- a/llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
+++ b/llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp
@@ -123,24 +123,6 @@ static ExpectedErrorOr<void *> RunTest(StringRef Input, size_t SizeLimit,
   RETURN_IF_ERROR(sys::fs::file_size(Temp.path(), FileSize));
   EXPECT_LE(FileSize, SizeLimit);
 
-  // For compact binary format, function names are stored as MD5, so we cannot
-  // directly match the samples of the new profile with the old profile. A
-  // simple way is to convert the old profile to compact binary format and read
-  // it back
-  if (Format == llvm::sampleprof::SPF_Compact_Binary) {
-    TempFile CompBinary("compbinary", "afdo", "", true);
-    {
-      DEF_VAR_RETURN_IF_ERROR(
-          Writer, SampleProfileWriter::create(
-                      CompBinary.path(), llvm::sampleprof::SPF_Compact_Binary));
-      RETURN_IF_ERROR(Writer->write(OldProfiles));
-    }
-    VAR_RETURN_IF_ERROR(Reader, SampleProfileReader::create(
-                                    CompBinary.path().str(), Context, *FS));
-    RETURN_IF_ERROR(Reader->read());
-    OldProfiles = Reader->getProfiles();
-  }
-
   // For every sample in the new profile, confirm it is in the old profile and
   // unchanged.
   for (auto Sample : NewProfiles) {
@@ -169,13 +151,6 @@ TEST(TestOutputSizeLimit, TestOutputSizeLimitBinary) {
         Succeeded());
 }
 
-TEST(TestOutputSizeLimit, TestOutputSizeLimitCompBinary) {
-  for (size_t OutputSizeLimit : {277, 276, 275, 264, 263, 250, 200})
-    ASSERT_THAT_EXPECTED(
-        RunTest(Input1, OutputSizeLimit, llvm::sampleprof::SPF_Compact_Binary),
-        Succeeded());
-}
-
 TEST(TestOutputSizeLimit, TestOutputSizeLimitText) {
   for (size_t OutputSizeLimit :
        {229, 228, 227, 213, 212, 211, 189, 188, 187, 186, 150})


        


More information about the llvm-commits mailing list