Skip to content

Commit d38d6ca

Browse files
committed
[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
1 parent 9b4faa1 commit d38d6ca

File tree

17 files changed

+15
-386
lines changed

17 files changed

+15
-386
lines changed

llvm/include/llvm/ProfileData/SampleProf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace sampleprof {
9090
enum SampleProfileFormat {
9191
SPF_None = 0,
9292
SPF_Text = 0x1,
93-
SPF_Compact_Binary = 0x2,
93+
SPF_Compact_Binary = 0x2, // Deprecated
9494
SPF_GCC = 0x3,
9595
SPF_Ext_Binary = 0x4,
9696
SPF_Binary = 0xff

llvm/include/llvm/ProfileData/SampleProfReader.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -811,41 +811,6 @@ class SampleProfileReaderExtBinary : public SampleProfileReaderExtBinaryBase {
811811
static bool hasFormat(const MemoryBuffer &Buffer);
812812
};
813813

814-
class SampleProfileReaderCompactBinary : public SampleProfileReaderBinary {
815-
private:
816-
/// Function name table.
817-
std::vector<std::string> NameTable;
818-
/// The table mapping from function name to the offset of its FunctionSample
819-
/// towards file start.
820-
DenseMap<StringRef, uint64_t> FuncOffsetTable;
821-
/// The set containing the functions to use when compiling a module.
822-
DenseSet<StringRef> FuncsToUse;
823-
std::error_code verifySPMagic(uint64_t Magic) override;
824-
std::error_code readNameTable() override;
825-
/// Read a string indirectly via the name table.
826-
ErrorOr<StringRef> readStringFromTable() override;
827-
std::error_code readHeader() override;
828-
std::error_code readFuncOffsetTable();
829-
830-
public:
831-
SampleProfileReaderCompactBinary(std::unique_ptr<MemoryBuffer> B,
832-
LLVMContext &C)
833-
: SampleProfileReaderBinary(std::move(B), C, SPF_Compact_Binary) {}
834-
835-
/// \brief Return true if \p Buffer is in the format supported by this class.
836-
static bool hasFormat(const MemoryBuffer &Buffer);
837-
838-
/// Read samples only for functions to use.
839-
std::error_code readImpl() override;
840-
841-
/// Collect functions with definitions in Module M. Return true if
842-
/// the reader has been given a module.
843-
bool collectFuncsFromModule() override;
844-
845-
/// Return whether names in the profile are all MD5 numbers.
846-
bool useMD5() override { return true; }
847-
};
848-
849814
using InlineCallStack = SmallVector<FunctionSamples *, 10>;
850815

851816
// Supported histogram types in GCC. Currently, we only need support for

llvm/include/llvm/ProfileData/SampleProfWriter.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -414,55 +414,6 @@ class SampleProfileWriterExtBinary : public SampleProfileWriterExtBinaryBase {
414414
}
415415
};
416416

417-
// CompactBinary is a compact format of binary profile which both reduces
418-
// the profile size and the load time needed when compiling. It has two
419-
// major difference with Binary format.
420-
// 1. It represents all the strings in name table using md5 hash.
421-
// 2. It saves a function offset table which maps function name index to
422-
// the offset of its function profile to the start of the binary profile,
423-
// so by using the function offset table, for those function profiles which
424-
// will not be needed when compiling a module, the profile reader does't
425-
// have to read them and it saves compile time if the profile size is huge.
426-
// The layout of the compact format is shown as follows:
427-
//
428-
// Part1: Profile header, the same as binary format, containing magic
429-
// number, version, summary, name table...
430-
// Part2: Function Offset Table Offset, which saves the position of
431-
// Part4.
432-
// Part3: Function profile collection
433-
// function1 profile start
434-
// ....
435-
// function2 profile start
436-
// ....
437-
// function3 profile start
438-
// ....
439-
// ......
440-
// Part4: Function Offset Table
441-
// function1 name index --> function1 profile start
442-
// function2 name index --> function2 profile start
443-
// function3 name index --> function3 profile start
444-
//
445-
// We need Part2 because profile reader can use it to find out and read
446-
// function offset table without reading Part3 first.
447-
class SampleProfileWriterCompactBinary : public SampleProfileWriterBinary {
448-
using SampleProfileWriterBinary::SampleProfileWriterBinary;
449-
450-
public:
451-
std::error_code writeSample(const FunctionSamples &S) override;
452-
std::error_code write(const SampleProfileMap &ProfileMap) override;
453-
454-
protected:
455-
/// The table mapping from function name to the offset of its FunctionSample
456-
/// towards profile start.
457-
MapVector<StringRef, uint64_t> FuncOffsetTable;
458-
/// The offset of the slot to be filled with the offset of FuncOffsetTable
459-
/// towards profile start.
460-
uint64_t TableOffset;
461-
std::error_code writeNameTable() override;
462-
std::error_code writeHeader(const SampleProfileMap &ProfileMap) override;
463-
std::error_code writeFuncOffsetTable();
464-
};
465-
466417
} // end namespace sampleprof
467418
} // end namespace llvm
468419

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 2 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using namespace sampleprof;
5151
#define DEBUG_TYPE "samplepgo-reader"
5252

5353
// This internal option specifies if the profile uses FS discriminators.
54-
// It only applies to text, binary and compact binary format profiles.
54+
// It only applies to text, and binary format profiles.
5555
// For ext-binary format profiles, the flag is set in the summary.
5656
static cl::opt<bool> ProfileIsFSDisciminator(
5757
"profile-isfs", cl::Hidden, cl::init(false),
@@ -568,14 +568,6 @@ ErrorOr<StringRef> SampleProfileReaderExtBinaryBase::readStringFromTable() {
568568
return SR;
569569
}
570570

571-
ErrorOr<StringRef> SampleProfileReaderCompactBinary::readStringFromTable() {
572-
auto Idx = readStringIndex(NameTable);
573-
if (std::error_code EC = Idx.getError())
574-
return EC;
575-
576-
return StringRef(NameTable[*Idx]);
577-
}
578-
579571
std::error_code
580572
SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
581573
auto NumSamples = readNumber<uint64_t>();
@@ -1012,40 +1004,6 @@ std::error_code SampleProfileReaderExtBinaryBase::readImpl() {
10121004
return sampleprof_error::success;
10131005
}
10141006

1015-
std::error_code SampleProfileReaderCompactBinary::readImpl() {
1016-
// Collect functions used by current module if the Reader has been
1017-
// given a module.
1018-
bool LoadFuncsToBeUsed = collectFuncsFromModule();
1019-
ProfileIsFS = ProfileIsFSDisciminator;
1020-
FunctionSamples::ProfileIsFS = ProfileIsFS;
1021-
std::vector<uint64_t> OffsetsToUse;
1022-
if (!LoadFuncsToBeUsed) {
1023-
// load all the function profiles.
1024-
for (auto FuncEntry : FuncOffsetTable) {
1025-
OffsetsToUse.push_back(FuncEntry.second);
1026-
}
1027-
} else {
1028-
// load function profiles on demand.
1029-
for (auto Name : FuncsToUse) {
1030-
auto GUID = std::to_string(MD5Hash(Name));
1031-
auto iter = FuncOffsetTable.find(StringRef(GUID));
1032-
if (iter == FuncOffsetTable.end())
1033-
continue;
1034-
OffsetsToUse.push_back(iter->second);
1035-
}
1036-
}
1037-
1038-
for (auto Offset : OffsetsToUse) {
1039-
const uint8_t *SavedData = Data;
1040-
if (std::error_code EC = readFuncProfile(
1041-
reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
1042-
Offset))
1043-
return EC;
1044-
Data = SavedData;
1045-
}
1046-
return sampleprof_error::success;
1047-
}
1048-
10491007
std::error_code SampleProfileReaderRawBinary::verifySPMagic(uint64_t Magic) {
10501008
if (Magic == SPMagic())
10511009
return sampleprof_error::success;
@@ -1058,13 +1016,6 @@ std::error_code SampleProfileReaderExtBinary::verifySPMagic(uint64_t Magic) {
10581016
return sampleprof_error::bad_magic;
10591017
}
10601018

1061-
std::error_code
1062-
SampleProfileReaderCompactBinary::verifySPMagic(uint64_t Magic) {
1063-
if (Magic == SPMagic(SPF_Compact_Binary))
1064-
return sampleprof_error::success;
1065-
return sampleprof_error::bad_magic;
1066-
}
1067-
10681019
std::error_code SampleProfileReaderBinary::readNameTable() {
10691020
auto Size = readNumber<size_t>();
10701021
if (std::error_code EC = Size.getError())
@@ -1234,20 +1185,6 @@ SampleProfileReaderExtBinaryBase::readFuncMetadata(bool ProfileHasAttribute) {
12341185
return sampleprof_error::success;
12351186
}
12361187

1237-
std::error_code SampleProfileReaderCompactBinary::readNameTable() {
1238-
auto Size = readNumber<uint64_t>();
1239-
if (std::error_code EC = Size.getError())
1240-
return EC;
1241-
NameTable.reserve(*Size);
1242-
for (uint64_t I = 0; I < *Size; ++I) {
1243-
auto FID = readNumber<uint64_t>();
1244-
if (std::error_code EC = FID.getError())
1245-
return EC;
1246-
NameTable.push_back(std::to_string(*FID));
1247-
}
1248-
return sampleprof_error::success;
1249-
}
1250-
12511188
std::error_code
12521189
SampleProfileReaderExtBinaryBase::readSecHdrTableEntry(uint64_t Idx) {
12531190
SecHdrTableEntry Entry;
@@ -1427,54 +1364,6 @@ std::error_code SampleProfileReaderBinary::readHeader() {
14271364
return sampleprof_error::success;
14281365
}
14291366

1430-
std::error_code SampleProfileReaderCompactBinary::readHeader() {
1431-
SampleProfileReaderBinary::readHeader();
1432-
if (std::error_code EC = readFuncOffsetTable())
1433-
return EC;
1434-
return sampleprof_error::success;
1435-
}
1436-
1437-
std::error_code SampleProfileReaderCompactBinary::readFuncOffsetTable() {
1438-
auto TableOffset = readUnencodedNumber<uint64_t>();
1439-
if (std::error_code EC = TableOffset.getError())
1440-
return EC;
1441-
1442-
const uint8_t *SavedData = Data;
1443-
const uint8_t *TableStart =
1444-
reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
1445-
*TableOffset;
1446-
Data = TableStart;
1447-
1448-
auto Size = readNumber<uint64_t>();
1449-
if (std::error_code EC = Size.getError())
1450-
return EC;
1451-
1452-
FuncOffsetTable.reserve(*Size);
1453-
for (uint64_t I = 0; I < *Size; ++I) {
1454-
auto FName(readStringFromTable());
1455-
if (std::error_code EC = FName.getError())
1456-
return EC;
1457-
1458-
auto Offset = readNumber<uint64_t>();
1459-
if (std::error_code EC = Offset.getError())
1460-
return EC;
1461-
1462-
FuncOffsetTable[*FName] = *Offset;
1463-
}
1464-
End = TableStart;
1465-
Data = SavedData;
1466-
return sampleprof_error::success;
1467-
}
1468-
1469-
bool SampleProfileReaderCompactBinary::collectFuncsFromModule() {
1470-
if (!M)
1471-
return false;
1472-
FuncsToUse.clear();
1473-
for (auto &F : *M)
1474-
FuncsToUse.insert(FunctionSamples::getCanonicalFnName(F));
1475-
return true;
1476-
}
1477-
14781367
std::error_code SampleProfileReaderBinary::readSummaryEntry(
14791368
std::vector<ProfileSummaryEntry> &Entries) {
14801369
auto Cutoff = readNumber<uint64_t>();
@@ -1545,13 +1434,6 @@ bool SampleProfileReaderExtBinary::hasFormat(const MemoryBuffer &Buffer) {
15451434
return Magic == SPMagic(SPF_Ext_Binary);
15461435
}
15471436

1548-
bool SampleProfileReaderCompactBinary::hasFormat(const MemoryBuffer &Buffer) {
1549-
const uint8_t *Data =
1550-
reinterpret_cast<const uint8_t *>(Buffer.getBufferStart());
1551-
uint64_t Magic = decodeULEB128(Data);
1552-
return Magic == SPMagic(SPF_Compact_Binary);
1553-
}
1554-
15551437
std::error_code SampleProfileReaderGCC::skipNextWord() {
15561438
uint32_t dummy;
15571439
if (!GcovBuffer.readInt(dummy))
@@ -1803,7 +1685,7 @@ void SampleProfileReaderItaniumRemapper::applyRemapping(LLVMContext &Ctx) {
18031685
Ctx.diagnose(DiagnosticInfoSampleProfile(
18041686
Reader.getBuffer()->getBufferIdentifier(),
18051687
"Profile data remapping cannot be applied to profile data "
1806-
"in compact format (original mangled names are not available).",
1688+
"using MD5 names (original mangled names are not available).",
18071689
DS_Warning));
18081690
return;
18091691
}
@@ -1934,8 +1816,6 @@ SampleProfileReader::create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
19341816
Reader.reset(new SampleProfileReaderRawBinary(std::move(B), C));
19351817
else if (SampleProfileReaderExtBinary::hasFormat(*B))
19361818
Reader.reset(new SampleProfileReaderExtBinary(std::move(B), C));
1937-
else if (SampleProfileReaderCompactBinary::hasFormat(*B))
1938-
Reader.reset(new SampleProfileReaderCompactBinary(std::move(B), C));
19391819
else if (SampleProfileReaderGCC::hasFormat(*B))
19401820
Reader.reset(new SampleProfileReaderGCC(std::move(B), C));
19411821
else if (SampleProfileReaderText::hasFormat(*B))

0 commit comments

Comments
 (0)