blob: e8b83e59802d167ef45f0d80d612786803e7c1fe [file] [log] [blame]
Andrew Trickf289df22011-06-11 01:05:22 +00001//===-------------- 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"
Benjamin Kramer7102b612011-10-23 11:32:54 +000016#include "llvm/Support/Format.h"
Andrew Trickf289df22011-06-11 01:05:22 +000017#include "llvm/Support/raw_ostream.h"
18
19using namespace llvm;
20
Jakub Staszak15b35672011-07-25 22:27:42 +000021void BranchProbability::print(raw_ostream &OS) const {
Benjamin Kramer7102b612011-10-23 11:32:54 +000022 OS << N << " / " << D << " = " << format("%g%%", ((double)N / D) * 100.0);
Andrew Trickf289df22011-06-11 01:05:22 +000023}
24
25void BranchProbability::dump() const {
Benjamin Kramer7102b612011-10-23 11:32:54 +000026 dbgs() << *this << '\n';
Andrew Trickf289df22011-06-11 01:05:22 +000027}
28
29namespace llvm {
30
31raw_ostream &operator<<(raw_ostream &OS, const BranchProbability &Prob) {
32 Prob.print(OS);
33 return OS;
34}
35
36}