aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-11-18 08:56:25 -0800
committerGitHub <noreply@github.com>2024-11-18 08:56:25 -0800
commit6bf8f08989420ccd10efed5fac88052ca16e1250 (patch)
tree291e25d131ec4600bf4caa9459b1a5db480e92b3 /llvm/lib/ProfileData/InstrProfWriter.cpp
parentb7d635ed30da49cc32b5b46d00e67ecc3ff9522f (diff)
downloadllvm-6bf8f08989420ccd10efed5fac88052ca16e1250.zip
llvm-6bf8f08989420ccd10efed5fac88052ca16e1250.tar.gz
llvm-6bf8f08989420ccd10efed5fac88052ca16e1250.tar.bz2
[memprof] Add InstrProfWriter::addMemProfData (#116528)
This patch adds InstrProfWriter::addMemProfData, which adds the complete MemProf profile (frames, call stacks, and records) to the writer context. Without this function, functions like loadInput in llvm-profdata.cpp and InstrProfWriter::mergeRecordsFromWriter must add one item (frame, call stack, or record) at a time. The new function std::moves the entire MemProf profile to the writer context if the destination is empty, which is the common use case. Otherwise, we fall back to adding one item at a time behind the scene. Here are a couple of reasons why we should add this function: - We've had a bug where we forgot to add one of the three data structures (frames, call stacks, and records) to the writer context, resulting in a nearly empty indexed profile. We should always package the three data structures together, especially on API boundaries. - We expose a little too much of the MemProf detail to InstrProfWriter. I'd like to gradually transform InstrProfReader/Writer to entities managing buffers (sequences of bytes), with actual serialization/deserialization left to external classes. We already do some of this in InstrProfReader, where InstrProfReader "contracts out" to IndexedMemProfReader to handle MemProf details. I am not changing loadInput or InstrProfWriter::mergeRecordsFromWriter for now because MemProfReader uses DenseMap for frames and call stacks, whereas MemProfData uses MapVector. I'll resolve these mismatches in subsequent patches.
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 47f4635..87a538f 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -350,6 +350,35 @@ bool InstrProfWriter::addMemProfCallStack(
return true;
}
+bool InstrProfWriter::addMemProfData(memprof::IndexedMemProfData Incoming,
+ function_ref<void(Error)> Warn) {
+ // TODO: Once we remove support for MemProf format Version V1, assert that
+ // the three components (frames, call stacks, and records) are either all
+ // empty or populated.
+
+ if (MemProfData.Frames.empty())
+ MemProfData.Frames = std::move(Incoming.Frames);
+ else
+ for (const auto &[Id, F] : Incoming.Frames)
+ if (addMemProfFrame(Id, F, Warn))
+ return false;
+
+ if (MemProfData.CallStacks.empty())
+ MemProfData.CallStacks = std::move(Incoming.CallStacks);
+ else
+ for (const auto &[CSId, CS] : Incoming.CallStacks)
+ if (addMemProfCallStack(CSId, CS, Warn))
+ return false;
+
+ if (MemProfData.Records.empty())
+ MemProfData.Records = std::move(Incoming.Records);
+ else
+ for (const auto &[GUID, Record] : Incoming.Records)
+ addMemProfRecord(GUID, Record);
+
+ return true;
+}
+
void InstrProfWriter::addBinaryIds(ArrayRef<llvm::object::BuildID> BIs) {
llvm::append_range(BinaryIds, BIs);
}