[block-freq] Add a print method on BlockFrequencyImpl for printing block frequencies...
[oota-llvm.git] / include / llvm / Analysis / BlockFrequencyImpl.h
index 8be75e604997a13a7cadfeb7ee6b881e7a77c5ad..95ce4aab8ec2cb7dca29eb1dcd0a7a0d5db5b9c5 100644 (file)
@@ -343,6 +343,30 @@ public:
   void dump() const {
     print(dbgs());
   }
+
+  // Utility method that looks up the block frequency associated with BB and
+  // prints it to OS.
+  raw_ostream &printBlockFreq(raw_ostream &OS,
+                              const BlockT *BB) {
+    return printBlockFreq(OS, getBlockFreq(BB));
+  }
+
+  raw_ostream &printBlockFreq(raw_ostream &OS,
+                              const BlockFrequency &Freq) const {
+    // Convert fixed-point number to decimal.
+    uint64_t Frequency = Freq.getFrequency();
+    OS << Frequency / EntryFreq << ".";
+    uint64_t Rem = Frequency % EntryFreq;
+    uint64_t Eps = 1;
+    do {
+      Rem *= 10;
+      Eps *= 10;
+      OS << Rem / EntryFreq;
+      Rem = Rem % EntryFreq;
+    } while (Rem >= Eps/2);
+    return OS;
+  }
+
 };
 
 }