summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2011-06-11 01:05:22 +0000
committerAndrew Trick <atrick@apple.com>2011-06-11 01:05:22 +0000
commit3d4e64b082717170ef918cb88b337087fb461b35 (patch)
tree6a57d0daadb6031af45cc0c8d4844e2266e52799 /llvm/lib/Support
parentc3bcde088f39a470116c51da271c301d5114933a (diff)
downloadbcm5719-llvm-3d4e64b082717170ef918cb88b337087fb461b35.tar.gz
bcm5719-llvm-3d4e64b082717170ef918cb88b337087fb461b35.zip
Branch profiling: floating-point avoidance.
Patch by: Jakub Staszak! Introduces BranchProbability. Changes unsigned to uint32_t all over and uint64_t only when overflow is expected. llvm-svn: 132867
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/BranchProbability.cpp44
-rw-r--r--llvm/lib/Support/CMakeLists.txt1
2 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/Support/BranchProbability.cpp b/llvm/lib/Support/BranchProbability.cpp
new file mode 100644
index 00000000000..97342da3f07
--- /dev/null
+++ b/llvm/lib/Support/BranchProbability.cpp
@@ -0,0 +1,44 @@
+//===-------------- lib/Support/BranchProbability.cpp -----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements Branch Probability class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/BranchProbability.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+BranchProbability::BranchProbability(uint32_t n, uint32_t d) {
+ assert(d > 0 && "Denomiator cannot be 0!");
+ assert(n <= d && "Probability cannot be bigger than 1!");
+ N = n;
+ D = d;
+}
+
+raw_ostream &BranchProbability::print(raw_ostream &OS) const {
+ OS << N << " / " << D << " = " << ((double)N / D);
+ return OS;
+}
+
+void BranchProbability::dump() const {
+ print(dbgs());
+ dbgs() << "\n";
+}
+
+namespace llvm {
+
+raw_ostream &operator<<(raw_ostream &OS, const BranchProbability &Prob) {
+ Prob.print(OS);
+ return OS;
+}
+
+}
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index a0e997d349f..867d930a0f9 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -9,6 +9,7 @@ add_llvm_library(LLVMSupport
APInt.cpp
APSInt.cpp
Allocator.cpp
+ BranchProbability.cpp
circular_raw_ostream.cpp
CommandLine.cpp
ConstantRange.cpp
OpenPOWER on IntegriCloud