[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)

Snehasish Kumar via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jul 30 10:10: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,
----------------
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


More information about the llvm-branch-commits mailing list