diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-10-23 11:19:14 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-10-23 11:19:14 +0000 |
commit | 341473c86d19cad5f3be432533ecdb42d9e07044 (patch) | |
tree | 776128d2718fe2b92d1a6e4ee1a8ca7ef10be089 /include | |
parent | 3071363bcdfd75e81326b4033970d8bee5b1b376 (diff) | |
download | llvm-341473c86d19cad5f3be432533ecdb42d9e07044.tar.gz llvm-341473c86d19cad5f3be432533ecdb42d9e07044.tar.bz2 llvm-341473c86d19cad5f3be432533ecdb42d9e07044.tar.xz |
Add compare operators to BranchProbability and use it to determine if an edge is hot.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142751 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Support/BranchProbability.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/include/llvm/Support/BranchProbability.h b/include/llvm/Support/BranchProbability.h index 05c24d4fcf..a1e5ceb625 100644 --- a/include/llvm/Support/BranchProbability.h +++ b/include/llvm/Support/BranchProbability.h @@ -15,6 +15,7 @@ #define LLVM_SUPPORT_BRANCHPROBABILITY_H #include "llvm/Support/DataTypes.h" +#include <cassert> namespace llvm { @@ -22,15 +23,21 @@ class raw_ostream; // This class represents Branch Probability as a non-negative fraction. class BranchProbability { - // Numerator uint32_t N; // Denominator uint32_t D; + int64_t compare(BranchProbability RHS) const { + return (uint64_t)N * RHS.D - (uint64_t)D * RHS.N; + } + public: - BranchProbability(uint32_t n, uint32_t d); + BranchProbability(uint32_t n, uint32_t d) : N(n), D(d) { + assert(d > 0 && "Denomiator cannot be 0!"); + assert(n <= d && "Probability cannot be bigger than 1!"); + } uint32_t getNumerator() const { return N; } uint32_t getDenominator() const { return D; } @@ -43,6 +50,13 @@ public: void print(raw_ostream &OS) const; void dump() const; + + bool operator==(BranchProbability RHS) const { return compare(RHS) == 0; } + bool operator!=(BranchProbability RHS) const { return compare(RHS) != 0; } + bool operator< (BranchProbability RHS) const { return compare(RHS) < 0; } + bool operator> (BranchProbability RHS) const { return compare(RHS) > 0; } + bool operator<=(BranchProbability RHS) const { return compare(RHS) <= 0; } + bool operator>=(BranchProbability RHS) const { return compare(RHS) >= 0; } }; raw_ostream &operator<<(raw_ostream &OS, const BranchProbability &Prob); |