-static std::error_code combineInstrProfRecords(InstrProfRecord &Dest,
- InstrProfRecord &Source,
- uint64_t &MaxFunctionCount) {
- // If the number of counters doesn't match we either have bad data
- // or a hash collision.
- if (Dest.Counts.size() != Source.Counts.size())
- return instrprof_error::count_mismatch;
-
- for (size_t I = 0, E = Source.Counts.size(); I < E; ++I) {
- if (Dest.Counts[I] + Source.Counts[I] < Dest.Counts[I])
- return instrprof_error::counter_overflow;
- Dest.Counts[I] += Source.Counts[I];
- }
-
- for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind) {
- if (std::error_code EC = Dest.mergeValueProfData(Kind, Source))
- return EC;
- }
-
- // We keep track of the max function count as we go for simplicity.
- if (Dest.Counts[0] > MaxFunctionCount)
- MaxFunctionCount = Dest.Counts[0];
-
- return instrprof_error::success;
-}
-