Skip to content

Commit 6fb967e

Browse files
[memprof] Move Frame::hash and hashCallStack to IndexedMemProfData (NFC) (#120365)
Now that IndexedMemProfData::{addFrame,addCallStack} are the only callers of Frame::hash and hashCallStack, respectively, this patch moves those functions into IndexedMemProfData and makes them private. With this patch, we can obtain FrameId and CallStackId only through addFrame and addCallStack, respectively.
1 parent 6e41483 commit 6fb967e

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

llvm/include/llvm/ProfileData/MemProf.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,6 @@ struct Frame {
323323
<< " Column: " << Column << "\n"
324324
<< " Inline: " << IsInlineFrame << "\n";
325325
}
326-
327-
// Return a hash value based on the contents of the frame. Here we use a
328-
// cryptographic hash function to minimize the chance of hash collisions. We
329-
// do persist FrameIds as part of memprof formats up to Version 2, inclusive.
330-
// However, the deserializer never calls this function; it uses FrameIds
331-
// merely as keys to look up Frames proper.
332-
inline FrameId hash() const {
333-
llvm::HashBuilder<llvm::TruncatedBLAKE3<8>, llvm::endianness::little>
334-
HashBuilder;
335-
HashBuilder.add(Function, LineOffset, Column, IsInlineFrame);
336-
llvm::BLAKE3Result<8> Hash = HashBuilder.final();
337-
FrameId Id;
338-
std::memcpy(&Id, Hash.data(), sizeof(Hash));
339-
return Id;
340-
}
341326
};
342327

343328
// A type representing the index into the table of call stacks.
@@ -775,9 +760,6 @@ class CallStackLookupTrait {
775760
}
776761
};
777762

778-
// Compute a CallStackId for a given call stack.
779-
CallStackId hashCallStack(ArrayRef<FrameId> CS);
780-
781763
namespace detail {
782764
// "Dereference" the iterator from DenseMap or OnDiskChainedHashTable. We have
783765
// to do so in one of two different ways depending on the type of the hash
@@ -1011,7 +993,7 @@ struct IndexedMemProfData {
1011993
llvm::MapVector<CallStackId, llvm::SmallVector<FrameId>> CallStacks;
1012994

1013995
FrameId addFrame(const Frame &F) {
1014-
const FrameId Id = F.hash();
996+
const FrameId Id = hashFrame(F);
1015997
Frames.try_emplace(Id, F);
1016998
return Id;
1017999
}
@@ -1027,6 +1009,25 @@ struct IndexedMemProfData {
10271009
CallStacks.try_emplace(CSId, std::move(CS));
10281010
return CSId;
10291011
}
1012+
1013+
private:
1014+
// Return a hash value based on the contents of the frame. Here we use a
1015+
// cryptographic hash function to minimize the chance of hash collisions. We
1016+
// do persist FrameIds as part of memprof formats up to Version 2, inclusive.
1017+
// However, the deserializer never calls this function; it uses FrameIds
1018+
// merely as keys to look up Frames proper.
1019+
FrameId hashFrame(const Frame &F) const {
1020+
llvm::HashBuilder<llvm::TruncatedBLAKE3<8>, llvm::endianness::little>
1021+
HashBuilder;
1022+
HashBuilder.add(F.Function, F.LineOffset, F.Column, F.IsInlineFrame);
1023+
llvm::BLAKE3Result<8> Hash = HashBuilder.final();
1024+
FrameId Id;
1025+
std::memcpy(&Id, Hash.data(), sizeof(Hash));
1026+
return Id;
1027+
}
1028+
1029+
// Compute a CallStackId for a given call stack.
1030+
CallStackId hashCallStack(ArrayRef<FrameId> CS) const;
10301031
};
10311032

10321033
struct FrameStat {

llvm/lib/ProfileData/MemProf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Expected<MemProfSchema> readMemProfSchema(const unsigned char *&Buffer) {
290290
return Result;
291291
}
292292

293-
CallStackId hashCallStack(ArrayRef<FrameId> CS) {
293+
CallStackId IndexedMemProfData::hashCallStack(ArrayRef<FrameId> CS) const {
294294
llvm::HashBuilder<llvm::TruncatedBLAKE3<8>, llvm::endianness::little>
295295
HashBuilder;
296296
for (FrameId F : CS)

0 commit comments

Comments
 (0)