[llvm] r273460 - [MBFI]: Add a new suboption for graph viewer

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 12:26:44 PDT 2016


Author: davidxl
Date: Wed Jun 22 14:26:44 2016
New Revision: 273460

URL: http://llvm.org/viewvc/llvm-project?rev=273460&view=rev
Log:
[MBFI]: Add a new suboption for graph viewer

 -view-machine-block-freq-propagation-dags currently
support integer and fraction as the suboptions. This
patch adds the 'count' suboption to display actual
profile count if available.


Modified:
    llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
    llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h?rev=273460&r1=273459&r2=273460&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBlockFrequencyInfo.h Wed Jun 22 14:26:44 2016
@@ -14,6 +14,7 @@
 #ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Support/BlockFrequency.h"
 #include <climits>
@@ -50,6 +51,8 @@ public:
   ///
   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
 
+  Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
+
   const MachineFunction *getFunction() const;
   void view() const;
 

Modified: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp?rev=273460&r1=273459&r2=273460&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp Wed Jun 22 14:26:44 2016
@@ -29,7 +29,7 @@ using namespace llvm;
 #define DEBUG_TYPE "block-freq"
 
 #ifndef NDEBUG
-enum GVDAGType { GVDT_None, GVDT_Fraction, GVDT_Integer };
+enum GVDAGType { GVDT_None, GVDT_Fraction, GVDT_Integer, GVDT_Count };
 
 static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG(
     "view-machine-block-freq-propagation-dags", cl::Hidden,
@@ -42,6 +42,9 @@ static cl::opt<GVDAGType> ViewMachineBlo
                clEnumValN(GVDT_Integer, "integer",
                           "display a graph using the raw "
                           "integer fractional block frequency representation."),
+               clEnumValN(GVDT_Count, "count", "display a graph using the real "
+                                               "profile count if available."),
+
                clEnumValEnd));
 
 static cl::opt<std::string> ViewMachineBlockFreqFuncName("view-mbfi-func-name",
@@ -92,7 +95,7 @@ struct DOTGraphTraits<MachineBlockFreque
     std::string Result;
     raw_string_ostream OS(Result);
 
-    OS << Node->getName().str() << ":";
+    OS << Node->getName().str() << " : ";
     switch (ViewMachineBlockFreqPropagationDAG) {
     case GVDT_Fraction:
       Graph->printBlockFreq(OS, Node);
@@ -100,11 +103,18 @@ struct DOTGraphTraits<MachineBlockFreque
     case GVDT_Integer:
       OS << Graph->getBlockFreq(Node).getFrequency();
       break;
+    case GVDT_Count: {
+      auto Count = Graph->getBlockProfileCount(Node);
+      if (Count)
+        OS << Count.getValue();
+      else
+        OS << "Unknown";
+      break;
+    }
     case GVDT_None:
       llvm_unreachable("If we are not supposed to render a graph we should "
                        "never reach this point.");
     }
-
     return Result;
   }
   static std::string getEdgeAttributes(const MachineBasicBlock *Node,
@@ -187,6 +197,12 @@ MachineBlockFrequencyInfo::getBlockFreq(
   return MBFI ? MBFI->getBlockFreq(MBB) : 0;
 }
 
+Optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
+    const MachineBasicBlock *MBB) const {
+  const Function *F = MBFI->getFunction()->getFunction();
+  return MBFI ? MBFI->getBlockProfileCount(*F, MBB) : None;
+}
+
 const MachineFunction *MachineBlockFrequencyInfo::getFunction() const {
   return MBFI ? MBFI->getFunction() : nullptr;
 }




More information about the llvm-commits mailing list