mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
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
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user