================ @@ -1027,6 +1027,20 @@ class FunctionSamples { return VirtualCallsiteTypeCounts[mapIRLocToProfileLoc(Loc)]; } + /// At location \p Loc, add a type sample for the given \p Type with + /// \p Count. This function uses saturating arithmetic to clamp the result to + /// maximum uint64_t (the counter type) and returns counter_overflow to caller + /// if the actual result is larger than maximum uint64_t. + sampleprof_error addTypeSamplesAt(const LineLocation &Loc, FunctionId Type, + uint64_t Count) { + auto &TypeCounts = getTypeSamplesAt(Loc); + bool Overflowed = false; + TypeCounts[Type] = SaturatingMultiplyAdd(Count, /* Weight= */ (uint64_t)1, ---------------- snehasish wrote:
I don't think we should insert into the map if it overflowed. Can you check the overflow first and then insert? https://github.com/llvm/llvm-project/pull/148013 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits