aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorEllis Hoag <ellis.sparky.hoag@gmail.com>2024-05-15 18:41:25 -0500
committerGitHub <noreply@github.com>2024-05-15 18:41:25 -0500
commitc87b1ca4edefe3c267a20f28eaf79f6b83d36c66 (patch)
treee8cbc6ff021c31c84a900bc44885254f472d3293 /llvm/lib/ProfileData/InstrProfWriter.cpp
parent3ddfb6807e905868a3a9df71fa5ea87309181270 (diff)
downloadllvm-c87b1ca4edefe3c267a20f28eaf79f6b83d36c66.zip
llvm-c87b1ca4edefe3c267a20f28eaf79f6b83d36c66.tar.gz
llvm-c87b1ca4edefe3c267a20f28eaf79f6b83d36c66.tar.bz2
[InstrProf] Fix bug when clearing traces with samples (#92310)
The `--temporal-profile-max-trace-length=0` flag in the `llvm-profdata merge` command is used to remove traces from a profile. There was a bug where traces would not be cleared if the profile was already sampled. This patch fixes that.
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index b61c59a..c941b9d 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -320,11 +320,8 @@ void InstrProfWriter::addBinaryIds(ArrayRef<llvm::object::BuildID> BIs) {
}
void InstrProfWriter::addTemporalProfileTrace(TemporalProfTraceTy Trace) {
- if (Trace.FunctionNameRefs.size() > MaxTemporalProfTraceLength)
- Trace.FunctionNameRefs.resize(MaxTemporalProfTraceLength);
- if (Trace.FunctionNameRefs.empty())
- return;
-
+ assert(Trace.FunctionNameRefs.size() <= MaxTemporalProfTraceLength);
+ assert(!Trace.FunctionNameRefs.empty());
if (TemporalProfTraceStreamSize < TemporalProfTraceReservoirSize) {
// Simply append the trace if we have not yet hit our reservoir size limit.
TemporalProfTraces.push_back(std::move(Trace));
@@ -341,6 +338,10 @@ void InstrProfWriter::addTemporalProfileTrace(TemporalProfTraceTy Trace) {
void InstrProfWriter::addTemporalProfileTraces(
SmallVectorImpl<TemporalProfTraceTy> &SrcTraces, uint64_t SrcStreamSize) {
+ for (auto &Trace : SrcTraces)
+ if (Trace.FunctionNameRefs.size() > MaxTemporalProfTraceLength)
+ Trace.FunctionNameRefs.resize(MaxTemporalProfTraceLength);
+ llvm::erase_if(SrcTraces, [](auto &T) { return T.FunctionNameRefs.empty(); });
// Assume that the source has the same reservoir size as the destination to
// avoid needing to record it in the indexed profile format.
bool IsDestSampled =