Initial implementation of 'fence' instruction, the new C++0x-style replacement for...
[oota-llvm.git] / include / llvm / Support / BlockFrequency.h
1 //===-------- BlockFrequency.h - Block Frequency Wrapper --------*- 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 Block Frequency class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
15 #define LLVM_SUPPORT_BLOCKFREQUENCY_H
16
17 namespace llvm {
18
19 class raw_ostream;
20 class BranchProbability;
21
22 // This class represents Block Frequency as a 64-bit value.
23 class BlockFrequency {
24
25   uint64_t Frequency;
26
27   static void mult96bit(uint64_t freq, uint32_t N, uint64_t W[2]);
28   static uint64_t div96bit(uint64_t W[2], uint32_t D);
29
30 public:
31   BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
32
33   uint64_t getFrequency() const { return Frequency; }
34
35   BlockFrequency &operator*=(const BranchProbability &Prob);
36   const BlockFrequency operator*(const BranchProbability &Prob) const;
37
38   BlockFrequency &operator+=(const BlockFrequency &Freq);
39   const BlockFrequency operator+(const BlockFrequency &Freq) const;
40
41   bool operator<(const BlockFrequency &RHS) const {
42     return Frequency < RHS.Frequency;
43   }
44
45   bool operator<=(const BlockFrequency &RHS) const {
46     return Frequency <= RHS.Frequency;
47   }
48
49   bool operator>(const BlockFrequency &RHS) const {
50     return Frequency > RHS.Frequency;
51   }
52
53   bool operator>=(const BlockFrequency &RHS) const {
54     return Frequency >= RHS.Frequency;
55   }
56
57   void print(raw_ostream &OS) const;
58 };
59
60 raw_ostream &operator<<(raw_ostream &OS, const BlockFrequency &Freq);
61
62 }
63
64 #endif