Skip to content

Commit 0fb3e6a

Browse files
record data access profile payload length
1 parent c5d8fcf commit 0fb3e6a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

llvm/lib/ProfileData/IndexedMemProfData.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ 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+
}
233235

234236
auto Schema = memprof::getHotColdSchema();
235237
if (MemProfFullSchema)
@@ -257,12 +259,14 @@ static Error writeMemProfRadixTreeBased(
257259
OS, MemProfData.Records, &Schema, Version, &MemProfCallStackIndexes);
258260

259261
uint64_t DataAccessProfOffset = 0;
262+
uint64_t DataAccessProfLength = 0;
260263
if (DataAccessProfileData.has_value()) {
261264
assert(Version >= memprof::Version4 &&
262265
"Data access profiles are added starting from v4");
263266
DataAccessProfOffset = OS.tell();
264267
if (Error E = (*DataAccessProfileData).get().serialize(OS))
265268
return E;
269+
DataAccessProfLength = OS.tell() - DataAccessProfOffset;
266270
}
267271

268272
// Verify that the computation for the number of elements in the call stack
@@ -271,13 +275,15 @@ static Error writeMemProfRadixTreeBased(
271275
NumElements * sizeof(memprof::LinearFrameId) ==
272276
RecordPayloadOffset);
273277

274-
SmallVector<uint64_t, 4> Header = {
278+
SmallVector<uint64_t, 8> Header = {
275279
CallStackPayloadOffset,
276280
RecordPayloadOffset,
277281
RecordTableOffset,
278282
};
279-
if (Version >= memprof::Version4)
283+
if (Version >= memprof::Version4) {
280284
Header.push_back(DataAccessProfOffset);
285+
Header.push_back(DataAccessProfLength);
286+
}
281287
OS.patch({{HeaderUpdatePos, Header}});
282288

283289
return Error::success();
@@ -394,9 +400,13 @@ Error IndexedMemProfReader::deserializeRadixTreeBased(
394400
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
395401

396402
uint64_t DataAccessProfOffset = 0;
397-
if (Version == memprof::Version4)
403+
uint64_t DataAccessProfLength = 0;
404+
if (Version == memprof::Version4) {
398405
DataAccessProfOffset =
399406
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
407+
DataAccessProfLength =
408+
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
409+
}
400410

401411
// Read the schema.
402412
auto SchemaOr = memprof::readMemProfSchema(Ptr);
@@ -419,7 +429,7 @@ Error IndexedMemProfReader::deserializeRadixTreeBased(
419429
/*Payload=*/Start + RecordPayloadOffset,
420430
/*Base=*/Start, memprof::RecordLookupTrait(Version, Schema)));
421431

422-
if (DataAccessProfOffset > RecordTableOffset) {
432+
if (DataAccessProfLength > 0) {
423433
DataAccessProfileData =
424434
std::make_unique<data_access_prof::DataAccessProfData>();
425435
const unsigned char *DAPPtr = Start + DataAccessProfOffset;

0 commit comments

Comments
 (0)