Skip to content

Commit 0d38f64

Browse files
[memprof] Remove MemProf format Version 0 (llvm#116442)
This patch removes MemProf format Version 0 now that version 2 and 3 seem to be working well. I'm not touching version 1 for now because some tests still rely on version 1. Note that Version 0 is identical to Version 1 except that the MemProf section of the indexed format has a MemProf version field.
1 parent 57ed628 commit 0d38f64

File tree

8 files changed

+18
-79
lines changed

8 files changed

+18
-79
lines changed

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,7 @@ class IndexedMemProfReader {
686686
// The number of elements in the radix tree array.
687687
unsigned RadixTreeSize = 0;
688688

689-
Error deserializeV012(const unsigned char *Start, const unsigned char *Ptr,
690-
uint64_t FirstWord);
689+
Error deserializeV12(const unsigned char *Start, const unsigned char *Ptr);
691690
Error deserializeV3(const unsigned char *Start, const unsigned char *Ptr);
692691

693692
public:

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ struct MemProfRecord;
2525

2626
// The versions of the indexed MemProf format
2727
enum IndexedVersion : uint64_t {
28-
// Version 0: This version didn't have a version field.
29-
Version0 = 0,
3028
// Version 1: Added a version field to the header.
3129
Version1 = 1,
3230
// Version 2: Added a call stack table.
@@ -36,7 +34,7 @@ enum IndexedVersion : uint64_t {
3634
Version3 = 3,
3735
};
3836

39-
constexpr uint64_t MinimumSupportedVersion = Version0;
37+
constexpr uint64_t MinimumSupportedVersion = Version1;
4038
constexpr uint64_t MaximumSupportedVersion = Version3;
4139

4240
// Verify that the minimum and maximum satisfy the obvious constraint.

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,14 +1226,11 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
12261226
}
12271227
}
12281228

1229-
Error IndexedMemProfReader::deserializeV012(const unsigned char *Start,
1230-
const unsigned char *Ptr,
1231-
uint64_t FirstWord) {
1229+
Error IndexedMemProfReader::deserializeV12(const unsigned char *Start,
1230+
const unsigned char *Ptr) {
12321231
// The value returned from RecordTableGenerator.Emit.
12331232
const uint64_t RecordTableOffset =
1234-
Version == memprof::Version0
1235-
? FirstWord
1236-
: support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
1233+
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
12371234
// The offset in the stream right before invoking
12381235
// FrameTableGenerator.Emit.
12391236
const uint64_t FramePayloadOffset =
@@ -1322,22 +1319,14 @@ Error IndexedMemProfReader::deserialize(const unsigned char *Start,
13221319
uint64_t MemProfOffset) {
13231320
const unsigned char *Ptr = Start + MemProfOffset;
13241321

1325-
// Read the first 64-bit word, which may be RecordTableOffset in
1326-
// memprof::MemProfVersion0 or the MemProf version number in
1327-
// memprof::MemProfVersion1 and above.
1322+
// Read the MemProf version number.
13281323
const uint64_t FirstWord =
13291324
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
13301325

13311326
if (FirstWord == memprof::Version1 || FirstWord == memprof::Version2 ||
13321327
FirstWord == memprof::Version3) {
13331328
// Everything is good. We can proceed to deserialize the rest.
13341329
Version = static_cast<memprof::IndexedVersion>(FirstWord);
1335-
} else if (FirstWord >= 24) {
1336-
// This is a heuristic/hack to detect memprof::MemProfVersion0,
1337-
// which does not have a version field in the header.
1338-
// In memprof::MemProfVersion0, FirstWord will be RecordTableOffset,
1339-
// which should be at least 24 because of the MemProf header size.
1340-
Version = memprof::Version0;
13411330
} else {
13421331
return make_error<InstrProfError>(
13431332
instrprof_error::unsupported_version,
@@ -1348,10 +1337,9 @@ Error IndexedMemProfReader::deserialize(const unsigned char *Start,
13481337
}
13491338

13501339
switch (Version) {
1351-
case memprof::Version0:
13521340
case memprof::Version1:
13531341
case memprof::Version2:
1354-
if (Error E = deserializeV012(Start, Ptr, FirstWord))
1342+
if (Error E = deserializeV12(Start, Ptr))
13551343
return E;
13561344
break;
13571345
case memprof::Version3:
@@ -1644,7 +1632,6 @@ IndexedMemProfReader::getMemProfRecord(const uint64_t FuncNameHash) const {
16441632

16451633
const memprof::IndexedMemProfRecord &IndexedRecord = *Iter;
16461634
switch (Version) {
1647-
case memprof::Version0:
16481635
case memprof::Version1:
16491636
assert(MemProfFrameTable && "MemProfFrameTable must be available");
16501637
assert(!MemProfCallStackTable &&

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -620,39 +620,6 @@ writeMemProfCallStackArray(
620620
return MemProfCallStackIndexes;
621621
}
622622

623-
// Write out MemProf Version0 as follows:
624-
// uint64_t RecordTableOffset = RecordTableGenerator.Emit
625-
// uint64_t FramePayloadOffset = Offset for the frame payload
626-
// uint64_t FrameTableOffset = FrameTableGenerator.Emit
627-
// uint64_t Num schema entries
628-
// uint64_t Schema entry 0
629-
// uint64_t Schema entry 1
630-
// ....
631-
// uint64_t Schema entry N - 1
632-
// OnDiskChainedHashTable MemProfRecordData
633-
// OnDiskChainedHashTable MemProfFrameData
634-
static Error writeMemProfV0(ProfOStream &OS,
635-
memprof::IndexedMemProfData &MemProfData) {
636-
uint64_t HeaderUpdatePos = OS.tell();
637-
OS.write(0ULL); // Reserve space for the memprof record table offset.
638-
OS.write(0ULL); // Reserve space for the memprof frame payload offset.
639-
OS.write(0ULL); // Reserve space for the memprof frame table offset.
640-
641-
auto Schema = memprof::getFullSchema();
642-
writeMemProfSchema(OS, Schema);
643-
644-
uint64_t RecordTableOffset =
645-
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version0);
646-
647-
uint64_t FramePayloadOffset = OS.tell();
648-
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
649-
650-
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
651-
OS.patch({{HeaderUpdatePos, Header}});
652-
653-
return Error::success();
654-
}
655-
656623
// Write out MemProf Version1 as follows:
657624
// uint64_t Version (NEW in V1)
658625
// uint64_t RecordTableOffset = RecordTableGenerator.Emit
@@ -809,8 +776,6 @@ static Error writeMemProf(ProfOStream &OS,
809776
memprof::IndexedVersion MemProfVersionRequested,
810777
bool MemProfFullSchema) {
811778
switch (MemProfVersionRequested) {
812-
case memprof::Version0:
813-
return writeMemProfV0(OS, MemProfData);
814779
case memprof::Version1:
815780
return writeMemProfV1(OS, MemProfData);
816781
case memprof::Version2:

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static size_t serializedSizeV3(const IndexedAllocationInfo &IAI,
5858
size_t IndexedAllocationInfo::serializedSize(const MemProfSchema &Schema,
5959
IndexedVersion Version) const {
6060
switch (Version) {
61-
case Version0:
6261
case Version1:
6362
return serializedSizeV0(*this, Schema);
6463
case Version2:
@@ -69,12 +68,12 @@ size_t IndexedAllocationInfo::serializedSize(const MemProfSchema &Schema,
6968
llvm_unreachable("unsupported MemProf version");
7069
}
7170

72-
static size_t serializedSizeV0(const IndexedMemProfRecord &Record,
71+
static size_t serializedSizeV1(const IndexedMemProfRecord &Record,
7372
const MemProfSchema &Schema) {
7473
// The number of alloc sites to serialize.
7574
size_t Result = sizeof(uint64_t);
7675
for (const IndexedAllocationInfo &N : Record.AllocSites)
77-
Result += N.serializedSize(Schema, Version0);
76+
Result += N.serializedSize(Schema, Version1);
7877

7978
// The number of callsites we have information for.
8079
Result += sizeof(uint64_t);
@@ -117,9 +116,8 @@ static size_t serializedSizeV3(const IndexedMemProfRecord &Record,
117116
size_t IndexedMemProfRecord::serializedSize(const MemProfSchema &Schema,
118117
IndexedVersion Version) const {
119118
switch (Version) {
120-
case Version0:
121119
case Version1:
122-
return serializedSizeV0(*this, Schema);
120+
return serializedSizeV1(*this, Schema);
123121
case Version2:
124122
return serializedSizeV2(*this, Schema);
125123
case Version3:
@@ -128,7 +126,7 @@ size_t IndexedMemProfRecord::serializedSize(const MemProfSchema &Schema,
128126
llvm_unreachable("unsupported MemProf version");
129127
}
130128

131-
static void serializeV0(const IndexedMemProfRecord &Record,
129+
static void serializeV1(const IndexedMemProfRecord &Record,
132130
const MemProfSchema &Schema, raw_ostream &OS) {
133131
using namespace support;
134132

@@ -197,9 +195,8 @@ void IndexedMemProfRecord::serialize(
197195
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes)
198196
const {
199197
switch (Version) {
200-
case Version0:
201198
case Version1:
202-
serializeV0(*this, Schema, OS);
199+
serializeV1(*this, Schema, OS);
203200
return;
204201
case Version2:
205202
serializeV2(*this, Schema, OS);
@@ -211,7 +208,7 @@ void IndexedMemProfRecord::serialize(
211208
llvm_unreachable("unsupported MemProf version");
212209
}
213210

214-
static IndexedMemProfRecord deserializeV0(const MemProfSchema &Schema,
211+
static IndexedMemProfRecord deserializeV1(const MemProfSchema &Schema,
215212
const unsigned char *Ptr) {
216213
using namespace support;
217214

@@ -327,9 +324,8 @@ IndexedMemProfRecord::deserialize(const MemProfSchema &Schema,
327324
const unsigned char *Ptr,
328325
IndexedVersion Version) {
329326
switch (Version) {
330-
case Version0:
331327
case Version1:
332-
return deserializeV0(Schema, Ptr);
328+
return deserializeV1(Schema, Ptr);
333329
case Version2:
334330
return deserializeV2(Schema, Ptr);
335331
case Version3:

llvm/test/tools/llvm-profdata/memprof-merge-versions.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ RUN: echo "1" >> %t.proftext
77
RUN: echo "1" >> %t.proftext
88

99
To update the inputs used below run Inputs/update_memprof_inputs.sh /path/to/updated/clang
10-
RUN: llvm-profdata merge %t.proftext %p/Inputs/basic.memprofraw --memprof-version=0 --profiled-binary %p/Inputs/basic.memprofexe -o %t.prof.v0
11-
RUN: llvm-profdata show %t.prof.v0 | FileCheck %s
12-
1310
RUN: llvm-profdata merge %t.proftext %p/Inputs/basic.memprofraw --memprof-version=1 --profiled-binary %p/Inputs/basic.memprofexe -o %t.prof.v1
1411
RUN: llvm-profdata show %t.prof.v1 | FileCheck %s
1512

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ cl::opt<memprof::IndexedVersion> MemProfVersionRequested(
333333
"memprof-version", cl::Hidden, cl::sub(MergeSubcommand),
334334
cl::desc("Specify the version of the memprof format to use"),
335335
cl::init(memprof::Version3),
336-
cl::values(clEnumValN(memprof::Version0, "0", "version 0"),
337-
clEnumValN(memprof::Version1, "1", "version 1"),
336+
cl::values(clEnumValN(memprof::Version1, "1", "version 1"),
338337
clEnumValN(memprof::Version2, "2", "version 2"),
339338
clEnumValN(memprof::Version3, "3", "version 3")));
340339

llvm/unittests/ProfileData/MemProfTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ TEST(MemProf, PortableWrapper) {
268268
EXPECT_EQ(3UL, ReadBlock.getAllocCpuId());
269269
}
270270

271-
// Version0 and Version1 serialize IndexedMemProfRecord in the same format, so
272-
// we share one test.
273-
TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
271+
TEST(MemProf, RecordSerializationRoundTripVersion1) {
274272
const auto Schema = llvm::memprof::getFullSchema();
275273

276274
MemInfoBlock Info(/*size=*/16, /*access_count=*/7, /*alloc_timestamp=*/1000,
@@ -294,11 +292,11 @@ TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
294292

295293
std::string Buffer;
296294
llvm::raw_string_ostream OS(Buffer);
297-
Record.serialize(Schema, OS, llvm::memprof::Version0);
295+
Record.serialize(Schema, OS, llvm::memprof::Version1);
298296

299297
const IndexedMemProfRecord GotRecord = IndexedMemProfRecord::deserialize(
300298
Schema, reinterpret_cast<const unsigned char *>(Buffer.data()),
301-
llvm::memprof::Version0);
299+
llvm::memprof::Version1);
302300

303301
EXPECT_EQ(Record, GotRecord);
304302
}

0 commit comments

Comments
 (0)