[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
Mingming Liu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 30 14:54:01 PDT 2025
================
@@ -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
More information about the llvm-branch-commits
mailing list