[llvm] [SampleFDO][TypeProf]Support vtable type profiling for ext-binary and text format (PR #148002)
Shafik Yaghmour via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 24 18:22:48 PDT 2025
================
@@ -1000,6 +1028,46 @@ class FunctionSamples {
return CallsiteSamples;
}
+ /// Returns vtable access samples for the C++ types collected in this
+ /// function.
+ const CallsiteTypeMap &getCallsiteTypeCounts() const {
+ return VirtualCallsiteTypeCounts;
+ }
+
+ /// Returns the vtable access samples for the C++ types for \p Loc.
+ /// Under the hood, the caller-specified \p Loc will be un-drifted before the
+ /// type sample lookup if possible.
+ TypeCountMap &getTypeSamplesAt(const LineLocation &Loc) {
+ return VirtualCallsiteTypeCounts[mapIRLocToProfileLoc(Loc)];
+ }
+
+ /// Scale \p Other sample counts by \p Weight and add the scaled result to the
+ /// type samples for \p Loc. Under the hoold, the caller-provided \p Loc will
+ /// be un-drifted before the type sample lookup if possible.
+ /// typename T is either a std::map or a DenseMap.
+ template <typename T>
+ sampleprof_error addCallsiteVTableTypeProfAt(const LineLocation &Loc,
+ const T &Other,
+ uint64_t Weight = 1) {
+ static_assert((std::is_same_v<typename T::key_type, StringRef> ||
+ std::is_same_v<typename T::key_type, FunctionId>) &&
+ std::is_same_v<typename T::mapped_type, uint64_t>,
+ "T must be a map with StringRef or FunctionId as key and "
+ "uint64_t as value");
+ TypeCountMap &TypeCounts = getTypeSamplesAt(Loc);
+ bool Overflowed = false;
+
+ for (const auto [Type, Count] : Other) {
----------------
shafik wrote:
Did you mean this to be copies here?
https://github.com/llvm/llvm-project/pull/148002
More information about the llvm-commits
mailing list