[PATCH] D21596: [MBFI] add edge label with branch probability info

David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 09:11:55 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL273430: [MBFI]: show branch probability in DOT graph (authored by davidxl).

Changed prior to commit:
  http://reviews.llvm.org/D21596?vs=61501&id=61561#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21596

Files:
  llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp

Index: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -20,7 +20,9 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Format.h"
 #include "llvm/Support/GraphWriter.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
@@ -80,6 +82,7 @@
   explicit DOTGraphTraits(bool isSimple = false)
       : DefaultDOTGraphTraits(isSimple) {}
 
+  typedef MachineBasicBlock::const_succ_iterator EdgeIter;
   static std::string getGraphName(const MachineBlockFrequencyInfo *G) {
     return G->getFunction()->getName();
   }
@@ -104,6 +107,21 @@
 
     return Result;
   }
+  static std::string getEdgeAttributes(const MachineBasicBlock *Node,
+                                       EdgeIter EI,
+                                       const MachineBlockFrequencyInfo *MBFI) {
+    MachineBranchProbabilityInfo &MBPI =
+        MBFI->getAnalysis<MachineBranchProbabilityInfo>();
+    BranchProbability BP = MBPI.getEdgeProbability(Node, EI);
+    uint32_t N = BP.getNumerator();
+    uint32_t D = BP.getDenominator();
+    double Percent = 100.0 * N / D;
+    std::string Str;
+    raw_string_ostream OS(Str);
+    OS << format("label=\"%.1f%%\"", Percent);
+    OS.flush();
+    return Str;
+  }
 };
 
 } // end namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21596.61561.patch
Type: text/x-patch
Size: 1504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160622/d2a7d4a5/attachment.bin>


More information about the llvm-commits mailing list