Andrew Trick | f289df2 | 2011-06-11 01:05:22 +0000 | [diff] [blame] | 1 | //===-------------- lib/Support/BranchProbability.cpp -----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements Branch Probability class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Support/BranchProbability.h" |
| 15 | #include "llvm/Support/Debug.h" |
| 16 | #include "llvm/Support/raw_ostream.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | BranchProbability::BranchProbability(uint32_t n, uint32_t d) { |
| 21 | assert(d > 0 && "Denomiator cannot be 0!"); |
| 22 | assert(n <= d && "Probability cannot be bigger than 1!"); |
| 23 | N = n; |
| 24 | D = d; |
| 25 | } |
| 26 | |
| 27 | raw_ostream &BranchProbability::print(raw_ostream &OS) const { |
| 28 | OS << N << " / " << D << " = " << ((double)N / D); |
| 29 | return OS; |
| 30 | } |
| 31 | |
| 32 | void BranchProbability::dump() const { |
| 33 | print(dbgs()); |
| 34 | dbgs() << "\n"; |
| 35 | } |
| 36 | |
| 37 | namespace llvm { |
| 38 | |
| 39 | raw_ostream &operator<<(raw_ostream &OS, const BranchProbability &Prob) { |
| 40 | Prob.print(OS); |
| 41 | return OS; |
| 42 | } |
| 43 | |
| 44 | } |