Skip to content

Commit 6646fe8

Browse files
[memprof] Compute CallStackId when deserializing IndexedAllocationInfo (#86421)
There are two ways to create in-memory instances of IndexedAllocationInfo -- deserialization of the raw MemProf data and that of the indexed MemProf data. With: commit 74799f4 Author: Kazu Hirata <[email protected]> Date: Sat Mar 23 19:50:15 2024 -0700 we compute CallStackId for each call stack in IndexedAllocationInfo while deserializing the raw MemProf data. This patch does the same while deserilizing the indexed MemProf data. As with the patch above, this patch does not add any use of CallStackId yet.
1 parent a9d8bf4 commit 6646fe8

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ class FrameLookupTrait {
635635
// Compute a CallStackId for a given call stack.
636636
CallStackId hashCallStack(ArrayRef<FrameId> CS);
637637

638+
// Verify that each CallStackId is computed with hashCallStack. This function
639+
// is intended to help transition from CallStack to CSId in
640+
// IndexedAllocationInfo.
641+
void verifyIndexedMemProfRecord(const IndexedMemProfRecord &Record);
642+
638643
// Verify that each CallStackId is computed with hashCallStack. This function
639644
// is intended to help transition from CallStack to CSId in
640645
// IndexedAllocationInfo.

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,14 @@ Error IndexedInstrProfReader::readHeader() {
12611261
/*Buckets=*/Start + FrameTableOffset,
12621262
/*Payload=*/Start + FramePayloadOffset,
12631263
/*Base=*/Start, memprof::FrameLookupTrait()));
1264+
1265+
#if EXPENSIVE_CHECKS
1266+
// Go through all the records and verify that CSId has been correctly
1267+
// populated. Do this only under EXPENSIVE_CHECKS. Otherwise, we
1268+
// would defeat the purpose of OnDiskIterableChainedHashTable.
1269+
for (const auto &Record : MemProfRecordTable->data())
1270+
verifyIndexedMemProfRecord(Record);
1271+
#endif
12641272
}
12651273

12661274
// BinaryIdOffset field in the header is only valid when the format version

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ IndexedMemProfRecord::deserialize(const MemProfSchema &Schema,
5353
endian::readNext<FrameId, llvm::endianness::little, unaligned>(Ptr);
5454
Node.CallStack.push_back(Id);
5555
}
56+
Node.CSId = hashCallStack(Node.CallStack);
5657
Node.Info.deserialize(Schema, Ptr);
5758
Ptr += PortableMemInfoBlock::serializedSize();
5859
Record.AllocSites.push_back(Node);
@@ -130,15 +131,19 @@ CallStackId hashCallStack(ArrayRef<FrameId> CS) {
130131
return CSId;
131132
}
132133

134+
void verifyIndexedMemProfRecord(const IndexedMemProfRecord &Record) {
135+
for (const auto &AS : Record.AllocSites) {
136+
assert(AS.CSId == hashCallStack(AS.CallStack));
137+
(void)AS;
138+
}
139+
}
140+
133141
void verifyFunctionProfileData(
134142
const llvm::MapVector<GlobalValue::GUID, IndexedMemProfRecord>
135143
&FunctionProfileData) {
136144
for (const auto &[GUID, Record] : FunctionProfileData) {
137145
(void)GUID;
138-
for (const auto &AS : Record.AllocSites) {
139-
assert(AS.CSId == hashCallStack(AS.CallStack));
140-
(void)AS;
141-
}
146+
verifyIndexedMemProfRecord(Record);
142147
}
143148
}
144149

0 commit comments

Comments
 (0)