Skip to content

Commit d3443c7

Browse files
undo length record and check
1 parent 0fb3e6a commit d3443c7

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

llvm/lib/ProfileData/IndexedMemProfData.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,8 @@ static Error writeMemProfRadixTreeBased(
228228
OS.write(0ULL); // Reserve space for the memprof call stack payload offset.
229229
OS.write(0ULL); // Reserve space for the memprof record payload offset.
230230
OS.write(0ULL); // Reserve space for the memprof record table offset.
231-
if (Version >= memprof::Version4) {
231+
if (Version >= memprof::Version4)
232232
OS.write(0ULL); // Reserve space for the data access profile offset.
233-
OS.write(0ULL); // Reserve space for the size of data access profiles.
234-
}
235233

236234
auto Schema = memprof::getHotColdSchema();
237235
if (MemProfFullSchema)
@@ -259,14 +257,12 @@ static Error writeMemProfRadixTreeBased(
259257
OS, MemProfData.Records, &Schema, Version, &MemProfCallStackIndexes);
260258

261259
uint64_t DataAccessProfOffset = 0;
262-
uint64_t DataAccessProfLength = 0;
263260
if (DataAccessProfileData.has_value()) {
264261
assert(Version >= memprof::Version4 &&
265262
"Data access profiles are added starting from v4");
266263
DataAccessProfOffset = OS.tell();
267264
if (Error E = (*DataAccessProfileData).get().serialize(OS))
268265
return E;
269-
DataAccessProfLength = OS.tell() - DataAccessProfOffset;
270266
}
271267

272268
// Verify that the computation for the number of elements in the call stack
@@ -275,15 +271,14 @@ static Error writeMemProfRadixTreeBased(
275271
NumElements * sizeof(memprof::LinearFrameId) ==
276272
RecordPayloadOffset);
277273

278-
SmallVector<uint64_t, 8> Header = {
274+
SmallVector<uint64_t, 4> Header = {
279275
CallStackPayloadOffset,
280276
RecordPayloadOffset,
281277
RecordTableOffset,
282278
};
283-
if (Version >= memprof::Version4) {
279+
if (Version >= memprof::Version4)
284280
Header.push_back(DataAccessProfOffset);
285-
Header.push_back(DataAccessProfLength);
286-
}
281+
287282
OS.patch({{HeaderUpdatePos, Header}});
288283

289284
return Error::success();
@@ -400,13 +395,9 @@ Error IndexedMemProfReader::deserializeRadixTreeBased(
400395
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
401396

402397
uint64_t DataAccessProfOffset = 0;
403-
uint64_t DataAccessProfLength = 0;
404-
if (Version == memprof::Version4) {
398+
if (Version == memprof::Version4)
405399
DataAccessProfOffset =
406400
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
407-
DataAccessProfLength =
408-
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
409-
}
410401

411402
// Read the schema.
412403
auto SchemaOr = memprof::readMemProfSchema(Ptr);
@@ -429,7 +420,9 @@ Error IndexedMemProfReader::deserializeRadixTreeBased(
429420
/*Payload=*/Start + RecordPayloadOffset,
430421
/*Base=*/Start, memprof::RecordLookupTrait(Version, Schema)));
431422

432-
if (DataAccessProfLength > 0) {
423+
assert((!DataAccessProfOffset || DataAccessProfOffset > RecordTableOffset) &&
424+
"Data access profile is either empty or after the record table");
425+
if (DataAccessProfOffset > RecordTableOffset) {
433426
DataAccessProfileData =
434427
std::make_unique<data_access_prof::DataAccessProfData>();
435428
const unsigned char *DAPPtr = Start + DataAccessProfOffset;

llvm/test/tools/llvm-profdata/memprof-yaml.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
; RUN: llvm-profdata show --memory %t/memprof-out.indexed > %t/memprof-out.yaml
88
; RUN: diff -b %t/memprof-in.yaml %t/memprof-out.yaml
99

10-
; memprof-in-no-dap has empty data access profiles.
10+
; memprof-in-no-dap.yaml has empty data access profiles.
1111
; RUN: llvm-profdata merge --memprof-version=4 %t/memprof-in-no-dap.yaml -o %t/memprof-out.indexed
1212
; RUN: llvm-profdata show --memory %t/memprof-out.indexed > %t/memprof-out-no-dap.yaml
1313
; RUN: diff -b %t/memprof-in-no-dap.yaml %t/memprof-out-no-dap.yaml

0 commit comments

Comments
 (0)