Skip to content

Commit f1fbb47

Browse files
[memprof] Remove MemProf format Version 1
This patch removes MemProf format Version 1 now that Version 2 and 3 are working well.
1 parent a5f501e commit f1fbb47

File tree

9 files changed

+7
-285
lines changed

9 files changed

+7
-285
lines changed

llvm/include/llvm/ProfileData/InstrProfReader.h

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

689-
Error deserializeV12(const unsigned char *Start, const unsigned char *Ptr);
689+
Error deserializeV2(const unsigned char *Start, const unsigned char *Ptr);
690690
Error deserializeV3(const unsigned char *Start, const unsigned char *Ptr);
691691

692692
public:

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ struct MemProfRecord;
2525

2626
// The versions of the indexed MemProf format
2727
enum IndexedVersion : uint64_t {
28-
// Version 1: Added a version field to the header.
29-
Version1 = 1,
3028
// Version 2: Added a call stack table.
3129
Version2 = 2,
3230
// Version 3: Added a radix tree for call stacks. Switched to linear IDs for
3331
// frames and call stacks.
3432
Version3 = 3,
3533
};
3634

37-
constexpr uint64_t MinimumSupportedVersion = Version1;
35+
constexpr uint64_t MinimumSupportedVersion = Version2;
3836
constexpr uint64_t MaximumSupportedVersion = Version3;
3937

4038
// Verify that the minimum and maximum satisfy the obvious constraint.
@@ -486,20 +484,6 @@ struct MemProfRecord {
486484
llvm::SmallVector<std::vector<Frame>> CallSites;
487485

488486
MemProfRecord() = default;
489-
MemProfRecord(
490-
const IndexedMemProfRecord &Record,
491-
llvm::function_ref<const Frame(const FrameId Id)> IdToFrameCallback) {
492-
for (const IndexedAllocationInfo &IndexedAI : Record.AllocSites) {
493-
AllocSites.emplace_back(IndexedAI, IdToFrameCallback);
494-
}
495-
for (const ArrayRef<FrameId> Site : Record.CallSites) {
496-
std::vector<Frame> Frames;
497-
for (const FrameId Id : Site) {
498-
Frames.push_back(IdToFrameCallback(Id));
499-
}
500-
CallSites.push_back(Frames);
501-
}
502-
}
503487

504488
// Prints out the contents of the memprof record in YAML.
505489
void print(llvm::raw_ostream &OS) const {

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,8 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
12251225
}
12261226
}
12271227

1228-
Error IndexedMemProfReader::deserializeV12(const unsigned char *Start,
1229-
const unsigned char *Ptr) {
1228+
Error IndexedMemProfReader::deserializeV2(const unsigned char *Start,
1229+
const unsigned char *Ptr) {
12301230
// The value returned from RecordTableGenerator.Emit.
12311231
const uint64_t RecordTableOffset =
12321232
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
@@ -1322,8 +1322,7 @@ Error IndexedMemProfReader::deserialize(const unsigned char *Start,
13221322
const uint64_t FirstWord =
13231323
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
13241324

1325-
if (FirstWord == memprof::Version1 || FirstWord == memprof::Version2 ||
1326-
FirstWord == memprof::Version3) {
1325+
if (FirstWord == memprof::Version2 || FirstWord == memprof::Version3) {
13271326
// Everything is good. We can proceed to deserialize the rest.
13281327
Version = static_cast<memprof::IndexedVersion>(FirstWord);
13291328
} else {
@@ -1336,9 +1335,8 @@ Error IndexedMemProfReader::deserialize(const unsigned char *Start,
13361335
}
13371336

13381337
switch (Version) {
1339-
case memprof::Version1:
13401338
case memprof::Version2:
1341-
if (Error E = deserializeV12(Start, Ptr))
1339+
if (Error E = deserializeV2(Start, Ptr))
13421340
return E;
13431341
break;
13441342
case memprof::Version3:
@@ -1558,25 +1556,6 @@ Expected<InstrProfRecord> IndexedInstrProfReader::getInstrProfRecord(
15581556
return error(instrprof_error::unknown_function);
15591557
}
15601558

1561-
static Expected<memprof::MemProfRecord>
1562-
getMemProfRecordV0(const memprof::IndexedMemProfRecord &IndexedRecord,
1563-
MemProfFrameHashTable &MemProfFrameTable) {
1564-
memprof::FrameIdConverter<MemProfFrameHashTable> FrameIdConv(
1565-
MemProfFrameTable);
1566-
1567-
memprof::MemProfRecord Record =
1568-
memprof::MemProfRecord(IndexedRecord, FrameIdConv);
1569-
1570-
// Check that all frame ids were successfully converted to frames.
1571-
if (FrameIdConv.LastUnmappedId) {
1572-
return make_error<InstrProfError>(instrprof_error::hash_mismatch,
1573-
"memprof frame not found for frame id " +
1574-
Twine(*FrameIdConv.LastUnmappedId));
1575-
}
1576-
1577-
return Record;
1578-
}
1579-
15801559
static Expected<memprof::MemProfRecord>
15811560
getMemProfRecordV2(const memprof::IndexedMemProfRecord &IndexedRecord,
15821561
MemProfFrameHashTable &MemProfFrameTable,
@@ -1631,11 +1610,6 @@ IndexedMemProfReader::getMemProfRecord(const uint64_t FuncNameHash) const {
16311610

16321611
const memprof::IndexedMemProfRecord &IndexedRecord = *Iter;
16331612
switch (Version) {
1634-
case memprof::Version1:
1635-
assert(MemProfFrameTable && "MemProfFrameTable must be available");
1636-
assert(!MemProfCallStackTable &&
1637-
"MemProfCallStackTable must not be available");
1638-
return getMemProfRecordV0(IndexedRecord, *MemProfFrameTable);
16391613
case memprof::Version2:
16401614
assert(MemProfFrameTable && "MemProfFrameTable must be available");
16411615
assert(MemProfCallStackTable && "MemProfCallStackTable must be available");

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -649,41 +649,6 @@ writeMemProfCallStackArray(
649649
return MemProfCallStackIndexes;
650650
}
651651

652-
// Write out MemProf Version1 as follows:
653-
// uint64_t Version (NEW in V1)
654-
// uint64_t RecordTableOffset = RecordTableGenerator.Emit
655-
// uint64_t FramePayloadOffset = Offset for the frame payload
656-
// uint64_t FrameTableOffset = FrameTableGenerator.Emit
657-
// uint64_t Num schema entries
658-
// uint64_t Schema entry 0
659-
// uint64_t Schema entry 1
660-
// ....
661-
// uint64_t Schema entry N - 1
662-
// OnDiskChainedHashTable MemProfRecordData
663-
// OnDiskChainedHashTable MemProfFrameData
664-
static Error writeMemProfV1(ProfOStream &OS,
665-
memprof::IndexedMemProfData &MemProfData) {
666-
OS.write(memprof::Version1);
667-
uint64_t HeaderUpdatePos = OS.tell();
668-
OS.write(0ULL); // Reserve space for the memprof record table offset.
669-
OS.write(0ULL); // Reserve space for the memprof frame payload offset.
670-
OS.write(0ULL); // Reserve space for the memprof frame table offset.
671-
672-
auto Schema = memprof::getFullSchema();
673-
writeMemProfSchema(OS, Schema);
674-
675-
uint64_t RecordTableOffset =
676-
writeMemProfRecords(OS, MemProfData.Records, &Schema, memprof::Version1);
677-
678-
uint64_t FramePayloadOffset = OS.tell();
679-
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
680-
681-
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
682-
OS.patch({{HeaderUpdatePos, Header}});
683-
684-
return Error::success();
685-
}
686-
687652
// Write out MemProf Version2 as follows:
688653
// uint64_t Version
689654
// uint64_t RecordTableOffset = RecordTableGenerator.Emit
@@ -805,8 +770,6 @@ static Error writeMemProf(ProfOStream &OS,
805770
memprof::IndexedVersion MemProfVersionRequested,
806771
bool MemProfFullSchema) {
807772
switch (MemProfVersionRequested) {
808-
case memprof::Version1:
809-
return writeMemProfV1(OS, MemProfData);
810773
case memprof::Version2:
811774
return writeMemProfV2(OS, MemProfData, MemProfFullSchema);
812775
case memprof::Version3:

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ MemProfSchema getHotColdSchema() {
2323
Meta::TotalLifetimeAccessDensity};
2424
}
2525

26-
static size_t serializedSizeV0(const IndexedAllocationInfo &IAI,
27-
const MemProfSchema &Schema) {
28-
size_t Size = 0;
29-
// The number of frames to serialize.
30-
Size += sizeof(uint64_t);
31-
// The callstack frame ids.
32-
Size += sizeof(FrameId) * IAI.CallStack.size();
33-
// The size of the payload.
34-
Size += PortableMemInfoBlock::serializedSize(Schema);
35-
return Size;
36-
}
37-
3826
static size_t serializedSizeV2(const IndexedAllocationInfo &IAI,
3927
const MemProfSchema &Schema) {
4028
size_t Size = 0;
@@ -58,8 +46,6 @@ static size_t serializedSizeV3(const IndexedAllocationInfo &IAI,
5846
size_t IndexedAllocationInfo::serializedSize(const MemProfSchema &Schema,
5947
IndexedVersion Version) const {
6048
switch (Version) {
61-
case Version1:
62-
return serializedSizeV0(*this, Schema);
6349
case Version2:
6450
return serializedSizeV2(*this, Schema);
6551
case Version3:
@@ -68,23 +54,6 @@ size_t IndexedAllocationInfo::serializedSize(const MemProfSchema &Schema,
6854
llvm_unreachable("unsupported MemProf version");
6955
}
7056

71-
static size_t serializedSizeV1(const IndexedMemProfRecord &Record,
72-
const MemProfSchema &Schema) {
73-
// The number of alloc sites to serialize.
74-
size_t Result = sizeof(uint64_t);
75-
for (const IndexedAllocationInfo &N : Record.AllocSites)
76-
Result += N.serializedSize(Schema, Version1);
77-
78-
// The number of callsites we have information for.
79-
Result += sizeof(uint64_t);
80-
for (const auto &Frames : Record.CallSites) {
81-
// The number of frame ids to serialize.
82-
Result += sizeof(uint64_t);
83-
Result += Frames.size() * sizeof(FrameId);
84-
}
85-
return Result;
86-
}
87-
8857
static size_t serializedSizeV2(const IndexedMemProfRecord &Record,
8958
const MemProfSchema &Schema) {
9059
// The number of alloc sites to serialize.
@@ -116,8 +85,6 @@ static size_t serializedSizeV3(const IndexedMemProfRecord &Record,
11685
size_t IndexedMemProfRecord::serializedSize(const MemProfSchema &Schema,
11786
IndexedVersion Version) const {
11887
switch (Version) {
119-
case Version1:
120-
return serializedSizeV1(*this, Schema);
12188
case Version2:
12289
return serializedSizeV2(*this, Schema);
12390
case Version3:
@@ -126,29 +93,6 @@ size_t IndexedMemProfRecord::serializedSize(const MemProfSchema &Schema,
12693
llvm_unreachable("unsupported MemProf version");
12794
}
12895

129-
static void serializeV1(const IndexedMemProfRecord &Record,
130-
const MemProfSchema &Schema, raw_ostream &OS) {
131-
using namespace support;
132-
133-
endian::Writer LE(OS, llvm::endianness::little);
134-
135-
LE.write<uint64_t>(Record.AllocSites.size());
136-
for (const IndexedAllocationInfo &N : Record.AllocSites) {
137-
LE.write<uint64_t>(N.CallStack.size());
138-
for (const FrameId &Id : N.CallStack)
139-
LE.write<FrameId>(Id);
140-
N.Info.serialize(Schema, OS);
141-
}
142-
143-
// Related contexts.
144-
LE.write<uint64_t>(Record.CallSites.size());
145-
for (const auto &Frames : Record.CallSites) {
146-
LE.write<uint64_t>(Frames.size());
147-
for (const FrameId &Id : Frames)
148-
LE.write<FrameId>(Id);
149-
}
150-
}
151-
15296
static void serializeV2(const IndexedMemProfRecord &Record,
15397
const MemProfSchema &Schema, raw_ostream &OS) {
15498
using namespace support;
@@ -195,9 +139,6 @@ void IndexedMemProfRecord::serialize(
195139
llvm::DenseMap<CallStackId, LinearCallStackId> *MemProfCallStackIndexes)
196140
const {
197141
switch (Version) {
198-
case Version1:
199-
serializeV1(*this, Schema, OS);
200-
return;
201142
case Version2:
202143
serializeV2(*this, Schema, OS);
203144
return;
@@ -208,50 +149,6 @@ void IndexedMemProfRecord::serialize(
208149
llvm_unreachable("unsupported MemProf version");
209150
}
210151

211-
static IndexedMemProfRecord deserializeV1(const MemProfSchema &Schema,
212-
const unsigned char *Ptr) {
213-
using namespace support;
214-
215-
IndexedMemProfRecord Record;
216-
217-
// Read the meminfo nodes.
218-
const uint64_t NumNodes =
219-
endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
220-
for (uint64_t I = 0; I < NumNodes; I++) {
221-
IndexedAllocationInfo Node;
222-
const uint64_t NumFrames =
223-
endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
224-
for (uint64_t J = 0; J < NumFrames; J++) {
225-
const FrameId Id =
226-
endian::readNext<FrameId, llvm::endianness::little>(Ptr);
227-
Node.CallStack.push_back(Id);
228-
}
229-
Node.CSId = hashCallStack(Node.CallStack);
230-
Node.Info.deserialize(Schema, Ptr);
231-
Ptr += PortableMemInfoBlock::serializedSize(Schema);
232-
Record.AllocSites.push_back(Node);
233-
}
234-
235-
// Read the callsite information.
236-
const uint64_t NumCtxs =
237-
endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
238-
for (uint64_t J = 0; J < NumCtxs; J++) {
239-
const uint64_t NumFrames =
240-
endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
241-
llvm::SmallVector<FrameId> Frames;
242-
Frames.reserve(NumFrames);
243-
for (uint64_t K = 0; K < NumFrames; K++) {
244-
const FrameId Id =
245-
endian::readNext<FrameId, llvm::endianness::little>(Ptr);
246-
Frames.push_back(Id);
247-
}
248-
Record.CallSites.push_back(Frames);
249-
Record.CallSiteIds.push_back(hashCallStack(Frames));
250-
}
251-
252-
return Record;
253-
}
254-
255152
static IndexedMemProfRecord deserializeV2(const MemProfSchema &Schema,
256153
const unsigned char *Ptr) {
257154
using namespace support;
@@ -324,8 +221,6 @@ IndexedMemProfRecord::deserialize(const MemProfSchema &Schema,
324221
const unsigned char *Ptr,
325222
IndexedVersion Version) {
326223
switch (Version) {
327-
case Version1:
328-
return deserializeV1(Schema, Ptr);
329224
case Version2:
330225
return deserializeV2(Schema, Ptr);
331226
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=1 --profiled-binary %p/Inputs/basic.memprofexe -o %t.prof.v1
11-
RUN: llvm-profdata show %t.prof.v1 | FileCheck %s
12-
1310
RUN: llvm-profdata merge %t.proftext %p/Inputs/basic.memprofraw --memprof-version=2 --profiled-binary %p/Inputs/basic.memprofexe -o %t.prof.v2
1411
RUN: llvm-profdata show %t.prof.v2 | 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::Version1, "1", "version 1"),
337-
clEnumValN(memprof::Version2, "2", "version 2"),
336+
cl::values(clEnumValN(memprof::Version2, "2", "version 2"),
338337
clEnumValN(memprof::Version3, "3", "version 3")));
339338

340339
cl::opt<bool> MemProfFullSchema(

0 commit comments

Comments
 (0)