Support: Add BranchProbability::scale() and ::scaleByInverse()

Add API to `BranchProbability` for scaling big integers.  Next job is to
rip the logic out of `BlockMass` and `BlockFrequency`.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207544 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2014-04-29 16:15:35 +00:00
parent f90262a09d
commit 048f520b91
3 changed files with 139 additions and 0 deletions

View File

@ -50,6 +50,30 @@ public:
void dump() const;
/// \brief Scale a large integer.
///
/// Scales \c Num. Guarantees full precision. Returns the floor of the
/// result.
///
/// \return \c Num times \c this.
///
/// \note This code should be shared with (or replaced by) the implementation
/// of \a BlockFrequency::scale(), which seems to be calculating something
/// similar.
uint64_t scale(uint64_t Num) const;
/// \brief Scale a large integer by the inverse.
///
/// Scales \c Num by the inverse of \c this. Guarantees full precision.
/// Returns the floor of the result.
///
/// \return \c Num divided by \c this.
///
/// \note This code should be shared with (or replaced by) the implementation
/// of \a BlockFrequency::scale(), which seems to be calculating something
/// similar.
uint64_t scaleByInverse(uint64_t Num) const;
bool operator==(BranchProbability RHS) const {
return (uint64_t)N * RHS.D == (uint64_t)D * RHS.N;
}