diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h index ef96b74c9d400..883e24d718615 100644 --- a/llvm/include/llvm/ProfileData/MemProf.h +++ b/llvm/include/llvm/ProfileData/MemProf.h @@ -323,21 +323,6 @@ struct Frame { << " Column: " << Column << "\n" << " Inline: " << IsInlineFrame << "\n"; } - - // Return a hash value based on the contents of the frame. Here we use a - // cryptographic hash function to minimize the chance of hash collisions. We - // do persist FrameIds as part of memprof formats up to Version 2, inclusive. - // However, the deserializer never calls this function; it uses FrameIds - // merely as keys to look up Frames proper. - inline FrameId hash() const { - llvm::HashBuilder, llvm::endianness::little> - HashBuilder; - HashBuilder.add(Function, LineOffset, Column, IsInlineFrame); - llvm::BLAKE3Result<8> Hash = HashBuilder.final(); - FrameId Id; - std::memcpy(&Id, Hash.data(), sizeof(Hash)); - return Id; - } }; // A type representing the index into the table of call stacks. @@ -775,9 +760,6 @@ class CallStackLookupTrait { } }; -// Compute a CallStackId for a given call stack. -CallStackId hashCallStack(ArrayRef CS); - namespace detail { // "Dereference" the iterator from DenseMap or OnDiskChainedHashTable. We have // to do so in one of two different ways depending on the type of the hash @@ -1011,7 +993,7 @@ struct IndexedMemProfData { llvm::MapVector> CallStacks; FrameId addFrame(const Frame &F) { - const FrameId Id = F.hash(); + const FrameId Id = hashFrame(F); Frames.try_emplace(Id, F); return Id; } @@ -1027,6 +1009,25 @@ struct IndexedMemProfData { CallStacks.try_emplace(CSId, std::move(CS)); return CSId; } + +private: + // Return a hash value based on the contents of the frame. Here we use a + // cryptographic hash function to minimize the chance of hash collisions. We + // do persist FrameIds as part of memprof formats up to Version 2, inclusive. + // However, the deserializer never calls this function; it uses FrameIds + // merely as keys to look up Frames proper. + FrameId hashFrame(const Frame &F) const { + llvm::HashBuilder, llvm::endianness::little> + HashBuilder; + HashBuilder.add(F.Function, F.LineOffset, F.Column, F.IsInlineFrame); + llvm::BLAKE3Result<8> Hash = HashBuilder.final(); + FrameId Id; + std::memcpy(&Id, Hash.data(), sizeof(Hash)); + return Id; + } + + // Compute a CallStackId for a given call stack. + CallStackId hashCallStack(ArrayRef CS) const; }; struct FrameStat { diff --git a/llvm/lib/ProfileData/MemProf.cpp b/llvm/lib/ProfileData/MemProf.cpp index 1c240c3858cc7..15ab44934bbf0 100644 --- a/llvm/lib/ProfileData/MemProf.cpp +++ b/llvm/lib/ProfileData/MemProf.cpp @@ -290,7 +290,7 @@ Expected readMemProfSchema(const unsigned char *&Buffer) { return Result; } -CallStackId hashCallStack(ArrayRef CS) { +CallStackId IndexedMemProfData::hashCallStack(ArrayRef CS) const { llvm::HashBuilder, llvm::endianness::little> HashBuilder; for (FrameId F : CS)