[llvm] c5e4e8f - [memprof] Add IndexedMemProfData::addCallStack (#118920)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 6 12:10:15 PST 2024
Author: Kazu Hirata
Date: 2024-12-06T12:10:11-08:00
New Revision: c5e4e8f87da8156108716b0e24e9ef40682562e8
URL: https://github.com/llvm/llvm-project/commit/c5e4e8f87da8156108716b0e24e9ef40682562e8
DIFF: https://github.com/llvm/llvm-project/commit/c5e4e8f87da8156108716b0e24e9ef40682562e8.diff
LOG: [memprof] Add IndexedMemProfData::addCallStack (#118920)
This patch adds a helper function to replace an idiom like:
CallStackId CSId = hashCallStack(CallStack)
MemProfData.CallStacks.try_emplace(CSId, CallStack);
// Do something with CSId.
Added:
Modified:
llvm/include/llvm/ProfileData/MemProf.h
llvm/lib/ProfileData/MemProfReader.cpp
llvm/unittests/ProfileData/MemProfTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index 51f012cdaed3ac..8a85196e57044d 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -1029,6 +1029,18 @@ struct IndexedMemProfData {
Frames.try_emplace(Id, F);
return Id;
}
+
+ CallStackId addCallStack(ArrayRef<FrameId> CS) {
+ CallStackId CSId = hashCallStack(CS);
+ CallStacks.try_emplace(CSId, CS);
+ return CSId;
+ }
+
+ CallStackId addCallStack(SmallVector<FrameId> &&CS) {
+ CallStackId CSId = hashCallStack(CS);
+ CallStacks.try_emplace(CSId, std::move(CS));
+ return CSId;
+ }
};
struct FrameStat {
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index 9dacf298985937..2cf0e9c74c0d23 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -500,8 +500,7 @@ Error RawMemProfReader::mapRawProfileToRecords() {
Callstack.append(Frames.begin(), Frames.end());
}
- CallStackId CSId = hashCallStack(Callstack);
- MemProfData.CallStacks.insert({CSId, Callstack});
+ CallStackId CSId = MemProfData.addCallStack(Callstack);
// We attach the memprof record to each function bottom-up including the
// first non-inline frame.
@@ -520,11 +519,8 @@ Error RawMemProfReader::mapRawProfileToRecords() {
// Some functions may have only callsite data and no allocation data. Here
// we insert a new entry for callsite data if we need to.
IndexedMemProfRecord &Record = MemProfData.Records[Id];
- for (LocationPtr Loc : Locs) {
- CallStackId CSId = hashCallStack(*Loc);
- MemProfData.CallStacks.insert({CSId, *Loc});
- Record.CallSiteIds.push_back(CSId);
- }
+ for (LocationPtr Loc : Locs)
+ Record.CallSiteIds.push_back(MemProfData.addCallStack(*Loc));
}
return Error::success();
@@ -769,9 +765,7 @@ void YAMLMemProfReader::parse(StringRef YAMLData) {
IndexedCallStack.reserve(CallStack.size());
for (const Frame &F : CallStack)
IndexedCallStack.push_back(MemProfData.addFrame(F));
- CallStackId CSId = hashCallStack(IndexedCallStack);
- MemProfData.CallStacks.try_emplace(CSId, std::move(IndexedCallStack));
- return CSId;
+ return MemProfData.addCallStack(std::move(IndexedCallStack));
};
for (const auto &[GUID, Record] : Doc.HeapProfileRecords) {
diff --git a/llvm/unittests/ProfileData/MemProfTest.cpp b/llvm/unittests/ProfileData/MemProfTest.cpp
index f0567d0707fef0..74a6acf9e9a82f 100644
--- a/llvm/unittests/ProfileData/MemProfTest.cpp
+++ b/llvm/unittests/ProfileData/MemProfTest.cpp
@@ -434,8 +434,7 @@ TEST(MemProf, BaseMemProfReader) {
MemProfData.addFrame(F2);
llvm::SmallVector<FrameId> CallStack{F1.hash(), F2.hash()};
- CallStackId CSId = hashCallStack(CallStack);
- MemProfData.CallStacks.try_emplace(CSId, CallStack);
+ CallStackId CSId = MemProfData.addCallStack(std::move(CallStack));
IndexedMemProfRecord FakeRecord;
MemInfoBlock Block;
@@ -470,8 +469,7 @@ TEST(MemProf, BaseMemProfReaderWithCSIdMap) {
MemProfData.addFrame(F2);
llvm::SmallVector<FrameId> CallStack = {F1.hash(), F2.hash()};
- CallStackId CSId = hashCallStack(CallStack);
- MemProfData.CallStacks.insert({CSId, CallStack});
+ MemProfData.addCallStack(CallStack);
IndexedMemProfRecord FakeRecord;
MemInfoBlock Block;
More information about the llvm-commits
mailing list