summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNathan Slingerland <slingn@gmail.com>2015-12-02 18:19:24 +0000
committerNathan Slingerland <slingn@gmail.com>2015-12-02 18:19:24 +0000
commit1c2b998913d05c83a781da1a15738ac4c9379f6f (patch)
tree094a24ef57567744d8eb499a24f8aa7d13044ba3 /include
parent57b1a9599b8b3a3c571103ed481932c2768d8da9 (diff)
[llvm-profdata] Change instr prof counter overflow to saturate rather than discard
Summary: This changes overflow handling during instrumentation profile merge. Rathar than throwing away records that would result in counter overflow, merged counts are instead clamped to the maximum representable value. A warning about counter overflow is still surfaced to the user as before. Reviewers: dnovillo, davidxl, silvas Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14893 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254525 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ProfileData/InstrProf.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h
index 13f6c70b3e8..95648511910 100644
--- a/include/llvm/ProfileData/InstrProf.h
+++ b/include/llvm/ProfileData/InstrProf.h
@@ -428,19 +428,22 @@ instrprof_error InstrProfRecord::merge(InstrProfRecord &Other) {
if (Counts.size() != Other.Counts.size())
return instrprof_error::count_mismatch;
+ instrprof_error Result = instrprof_error::success;
+
for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
- if (Counts[I] + Other.Counts[I] < Counts[I])
- return instrprof_error::counter_overflow;
- Counts[I] += Other.Counts[I];
+ bool ResultOverflowed;
+ Counts[I] = SaturatingAdd(Counts[I], Other.Counts[I], ResultOverflowed);
+ if (ResultOverflowed)
+ Result = instrprof_error::counter_overflow;
}
for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
- instrprof_error result = mergeValueProfData(Kind, Other);
- if (result != instrprof_error::success)
- return result;
+ instrprof_error MergeValueResult = mergeValueProfData(Kind, Other);
+ if (MergeValueResult != instrprof_error::success)
+ Result = MergeValueResult;
}
- return instrprof_error::success;
+ return Result;
}
inline support::endianness getHostEndianness() {