[llvm] [NFC][PGO] Factor downscaling of branch weights out of `Instrumentation` into `ProfileData` (PR #153735)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 21:18:32 PDT 2025


================
@@ -144,6 +144,33 @@ LLVM_ABI bool extractProfTotalWeight(const Instruction &I,
 LLVM_ABI void setBranchWeights(Instruction &I, ArrayRef<uint32_t> Weights,
                                bool IsExpected);
 
+/// downscale the given weights preserving the ratio. If the maximum value is
+/// not already known and not provided via \param KnownMaxCount , it will be
+/// obtained from \param Weights.
+LLVM_ABI SmallVector<uint32_t>
+downscaleWeights(ArrayRef<uint64_t> Weights,
+                 std::optional<uint64_t> KnownMaxCount = std::nullopt);
+
+/// Calculate what to divide by to scale counts.
+///
+/// Given the maximum count, calculate a divisor that will scale all the
+/// weights to strictly less than std::numeric_limits<uint32_t>::max().
+LLVM_ABI inline uint64_t calculateCountScale(uint64_t MaxCount) {
----------------
mingmingl-llvm wrote:

What's the motivation to annotate `LLVM_ABI` for the helper functions here? 

https://github.com/llvm/llvm-project/pull/153735


More information about the llvm-commits mailing list