Mercurial > hg > CbC > CbC_llvm
comparison include/llvm/Support/BranchProbability.h @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- BranchProbability.h - Branch Probability Wrapper ---------*- C++ -*-===// | 1 //===- BranchProbability.h - Branch Probability Wrapper ---------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 // | 8 // |
10 // Definition of BranchProbability shared by IR and Machine Instructions. | 9 // Definition of BranchProbability shared by IR and Machine Instructions. |
11 // | 10 // |
71 | 70 |
72 raw_ostream &print(raw_ostream &OS) const; | 71 raw_ostream &print(raw_ostream &OS) const; |
73 | 72 |
74 void dump() const; | 73 void dump() const; |
75 | 74 |
76 /// \brief Scale a large integer. | 75 /// Scale a large integer. |
77 /// | 76 /// |
78 /// Scales \c Num. Guarantees full precision. Returns the floor of the | 77 /// Scales \c Num. Guarantees full precision. Returns the floor of the |
79 /// result. | 78 /// result. |
80 /// | 79 /// |
81 /// \return \c Num times \c this. | 80 /// \return \c Num times \c this. |
82 uint64_t scale(uint64_t Num) const; | 81 uint64_t scale(uint64_t Num) const; |
83 | 82 |
84 /// \brief Scale a large integer by the inverse. | 83 /// Scale a large integer by the inverse. |
85 /// | 84 /// |
86 /// Scales \c Num by the inverse of \c this. Guarantees full precision. | 85 /// Scales \c Num by the inverse of \c this. Guarantees full precision. |
87 /// Returns the floor of the result. | 86 /// Returns the floor of the result. |
88 /// | 87 /// |
89 /// \return \c Num divided by \c this. | 88 /// \return \c Num divided by \c this. |
117 "Unknown probability cannot participate in arithmetics."); | 116 "Unknown probability cannot participate in arithmetics."); |
118 N = (uint64_t(N) * RHS > D) ? D : N * RHS; | 117 N = (uint64_t(N) * RHS > D) ? D : N * RHS; |
119 return *this; | 118 return *this; |
120 } | 119 } |
121 | 120 |
121 BranchProbability &operator/=(BranchProbability RHS) { | |
122 assert(N != UnknownN && RHS.N != UnknownN && | |
123 "Unknown probability cannot participate in arithmetics."); | |
124 N = (static_cast<uint64_t>(N) * D + RHS.N / 2) / RHS.N; | |
125 return *this; | |
126 } | |
127 | |
122 BranchProbability &operator/=(uint32_t RHS) { | 128 BranchProbability &operator/=(uint32_t RHS) { |
123 assert(N != UnknownN && | 129 assert(N != UnknownN && |
124 "Unknown probability cannot participate in arithmetics."); | 130 "Unknown probability cannot participate in arithmetics."); |
125 assert(RHS > 0 && "The divider cannot be zero."); | 131 assert(RHS > 0 && "The divider cannot be zero."); |
126 N /= RHS; | 132 N /= RHS; |
127 return *this; | 133 return *this; |
128 } | 134 } |
129 | 135 |
130 BranchProbability operator+(BranchProbability RHS) const { | 136 BranchProbability operator+(BranchProbability RHS) const { |
131 BranchProbability Prob(*this); | 137 BranchProbability Prob(*this); |
132 return Prob += RHS; | 138 Prob += RHS; |
139 return Prob; | |
133 } | 140 } |
134 | 141 |
135 BranchProbability operator-(BranchProbability RHS) const { | 142 BranchProbability operator-(BranchProbability RHS) const { |
136 BranchProbability Prob(*this); | 143 BranchProbability Prob(*this); |
137 return Prob -= RHS; | 144 Prob -= RHS; |
145 return Prob; | |
138 } | 146 } |
139 | 147 |
140 BranchProbability operator*(BranchProbability RHS) const { | 148 BranchProbability operator*(BranchProbability RHS) const { |
141 BranchProbability Prob(*this); | 149 BranchProbability Prob(*this); |
142 return Prob *= RHS; | 150 Prob *= RHS; |
151 return Prob; | |
143 } | 152 } |
144 | 153 |
145 BranchProbability operator*(uint32_t RHS) const { | 154 BranchProbability operator*(uint32_t RHS) const { |
146 BranchProbability Prob(*this); | 155 BranchProbability Prob(*this); |
147 return Prob *= RHS; | 156 Prob *= RHS; |
157 return Prob; | |
158 } | |
159 | |
160 BranchProbability operator/(BranchProbability RHS) const { | |
161 BranchProbability Prob(*this); | |
162 Prob /= RHS; | |
163 return Prob; | |
148 } | 164 } |
149 | 165 |
150 BranchProbability operator/(uint32_t RHS) const { | 166 BranchProbability operator/(uint32_t RHS) const { |
151 BranchProbability Prob(*this); | 167 BranchProbability Prob(*this); |
152 return Prob /= RHS; | 168 Prob /= RHS; |
169 return Prob; | |
153 } | 170 } |
154 | 171 |
155 bool operator==(BranchProbability RHS) const { return N == RHS.N; } | 172 bool operator==(BranchProbability RHS) const { return N == RHS.N; } |
156 bool operator!=(BranchProbability RHS) const { return !(*this == RHS); } | 173 bool operator!=(BranchProbability RHS) const { return !(*this == RHS); } |
157 | 174 |