[CodeGen] Don't compute BranchProbability for MBB::print
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>
Fri, 9 Feb 2018 00:40:57 +0000 (00:40 +0000)
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>
Fri, 9 Feb 2018 00:40:57 +0000 (00:40 +0000)
Avoid re-computing BP only to print successor probabilities in -debug
printing.

llvm-svn: 324690

llvm/lib/CodeGen/MachineBasicBlock.cpp

index 8f4d9b7..76ed383 100644 (file)
@@ -341,23 +341,27 @@ void MachineBasicBlock::print(raw_ostream &OS, ModuleSlotTracker &MST,
       if (I != succ_begin())
         OS << ", ";
       OS << printMBBReference(**I);
-      OS << '(' << format("0x%08" PRIx32, getSuccProbability(I).getNumerator())
-         << ')';
+      if (!Probs.empty())
+        OS << '('
+           << format("0x%08" PRIx32, getSuccProbability(I).getNumerator())
+           << ')';
     }
-    // Print human readable probabilities as comments.
-    OS << "; ";
-    for (auto I = succ_begin(), E = succ_end(); I != E; ++I) {
-      const BranchProbability &BP = *getProbabilityIterator(I);
-      if (I != succ_begin())
-        OS << ", ";
-      OS << printMBBReference(**I) << '('
-         << format("%.2f%%",
-                   rint(((double)BP.getNumerator() / BP.getDenominator()) *
-                        100.0 * 100.0) /
-                       100.0)
-         << ')';
+    if (!Probs.empty()) {
+      // Print human readable probabilities as comments.
+      OS << "; ";
+      for (auto I = succ_begin(), E = succ_end(); I != E; ++I) {
+        const BranchProbability &BP = *getProbabilityIterator(I);
+        if (I != succ_begin())
+          OS << ", ";
+        OS << printMBBReference(**I) << '('
+           << format("%.2f%%",
+                     rint(((double)BP.getNumerator() / BP.getDenominator()) *
+                          100.0 * 100.0) /
+                         100.0)
+           << ')';
+      }
+      OS << '\n';
     }
-    OS << '\n';
   }
 
   // Print the preds of this block according to the CFG.