================
@@ -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,
----------------
mingmingl-llvm wrote:

As clarified offline, the `SaturatingMultiplyAdd` will clamp the result if 
overflow happens, and we insert the return value of `SaturatingMultiplyAdd`. 
From this perspective, counter_overflow is more of informative warning as 
opposed to a real error that wraps around a large unsigned integer into another 
value. 

I updated the comment to make this more explicit, and will probably prepare a 
separate change around the warning handling (in SampleProf or InstrProf).

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

Reply via email to