diff options
Diffstat (limited to 'llvm/include/llvm/ProfileData/ProfileCommon.h')
-rw-r--r-- | llvm/include/llvm/ProfileData/ProfileCommon.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/include/llvm/ProfileData/ProfileCommon.h b/llvm/include/llvm/ProfileData/ProfileCommon.h index 04f5cb27254..a7ac78d2523 100644 --- a/llvm/include/llvm/ProfileData/ProfileCommon.h +++ b/llvm/include/llvm/ProfileData/ProfileCommon.h @@ -15,6 +15,7 @@ #ifndef LLVM_PROFILEDATA_PROFILE_COMMON_H #define LLVM_PROFILEDATA_PROFILE_COMMON_H +#include "llvm/ADT/APInt.h" #include <cstdint> #include <functional> #include <map> @@ -184,5 +185,18 @@ SummaryEntryVector &ProfileSummary::getDetailedSummary() { return DetailedSummary; } +/// Helper to compute the profile count for a block, based on the +/// ratio of its frequency to the entry block frequency, multiplied +/// by the entry block count. +inline uint64_t getBlockProfileCount(uint64_t BlockFreq, uint64_t EntryFreq, + uint64_t EntryCount) { + APInt ScaledCount(128, EntryCount); + APInt BlockFreqAPInt(128, BlockFreq); + APInt EntryFreqAPInt(128, EntryFreq); + ScaledCount *= BlockFreqAPInt; + ScaledCount = ScaledCount.udiv(EntryFreqAPInt); + return ScaledCount.getLimitedValue(); +} + } // end namespace llvm #endif |