summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-12-14 02:24:22 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-12-14 02:24:22 +0000
commit1b98ef1c19082fb49bf6db7b008eec33361e1080 (patch)
tree2a14da4524f8fd0aa01a5405b03fe23a36dad9d5 /lib
parent7cc5f793bc858e4be4fbf532942d14013f123e55 (diff)
downloadllvm-1b98ef1c19082fb49bf6db7b008eec33361e1080.tar.gz
llvm-1b98ef1c19082fb49bf6db7b008eec33361e1080.tar.bz2
llvm-1b98ef1c19082fb49bf6db7b008eec33361e1080.tar.xz
[block-freq] Add a right shift to BlockFrequency that saturates at 1.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/BlockFrequency.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Support/BlockFrequency.cpp b/lib/Support/BlockFrequency.cpp
index d1f8408dfc..00cf75bd5c 100644
--- a/lib/Support/BlockFrequency.cpp
+++ b/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());
}