From 8f17dccdcb1dbfceaaf5b14ee1186c76b0584a35 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Sat, 14 Dec 2013 02:24:22 +0000 Subject: [block-freq] Add a right shift to BlockFrequency that saturates at 1. llvm-svn: 197302 --- llvm/lib/Support/BlockFrequency.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/Support') diff --git a/llvm/lib/Support/BlockFrequency.cpp b/llvm/lib/Support/BlockFrequency.cpp index d1f8408dfcb..00cf75bd5cf 100644 --- a/llvm/lib/Support/BlockFrequency.cpp +++ b/llvm/lib/Support/BlockFrequency.cpp @@ -145,6 +145,18 @@ BlockFrequency::operator+(const BlockFrequency &Prob) const { return Freq; } +BlockFrequency &BlockFrequency::operator>>=(const unsigned count) { + // Frequency can never be 0 by design. + assert(Frequency != 0); + + // Shift right by count. + Frequency >>= count; + + // Saturate to 1 if we are 0. + Frequency |= Frequency == 0; + return *this; +} + uint32_t BlockFrequency::scale(const BranchProbability &Prob) { return scale(Prob.getNumerator(), Prob.getDenominator()); } -- cgit v1.2.3