[llvm] r292815 - [PGO] add debug option to view annotated cfg after prof use annotation

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 10:58:24 PST 2017


Author: davidxl
Date: Mon Jan 23 12:58:24 2017
New Revision: 292815

URL: http://llvm.org/viewvc/llvm-project?rev=292815&view=rev
Log:
[PGO] add debug option to view annotated cfg after prof use annotation

Differential Revision: http://reviews.llvm.org/D28967 

Modified:
    llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
    llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=292815&r1=292814&r2=292815&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Mon Jan 23 12:58:24 2017
@@ -55,8 +55,18 @@ cl::opt<unsigned>
                                 "is no less than the max frequency of the "
                                 "function multiplied by this percent."));
 
+// Command line option to turn on CFG dot dump after profile annotation.
+cl::opt<bool> PGOViewCounts("pgo-view-counts", cl::init(false), cl::Hidden);
+
 namespace llvm {
 
+static GVDAGType getGVDT() {
+
+  if (PGOViewCounts)
+    return GVDT_Count;
+  return ViewBlockFreqPropagationDAG;
+}
+
 template <>
 struct GraphTraits<BlockFrequencyInfo *> {
   typedef const BasicBlock *NodeRef;
@@ -89,8 +99,7 @@ struct DOTGraphTraits<BlockFrequencyInfo
   std::string getNodeLabel(const BasicBlock *Node,
                            const BlockFrequencyInfo *Graph) {
 
-    return BFIDOTGTraitsBase::getNodeLabel(Node, Graph,
-                                           ViewBlockFreqPropagationDAG);
+    return BFIDOTGTraitsBase::getNodeLabel(Node, Graph, getGVDT());
   }
 
   std::string getNodeAttributes(const BasicBlock *Node,

Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=292815&r1=292814&r2=292815&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Mon Jan 23 12:58:24 2017
@@ -58,7 +58,9 @@
 #include "llvm/Analysis/BranchProbabilityInfo.h"
 #include "llvm/Analysis/CFG.h"
 #include "llvm/Analysis/IndirectCallSiteVisitor.h"
+#include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/CallSite.h"
+#include "llvm/IR/Dominators.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/IRBuilder.h"
@@ -143,6 +145,17 @@ static cl::opt<bool> NoPGOWarnMismatchCo
 // Command line option to enable/disable select instruction instrumentation.
 static cl::opt<bool> PGOInstrSelect("pgo-instr-select", cl::init(true),
                                     cl::Hidden);
+
+// Command line option to specify the name of the function for CFG dump
+static cl::opt<std::string>
+    PGOViewFunction("pgo-view-function", cl::Hidden,
+                    cl::desc("The option to specify "
+                             "the name of the function "
+                             "whose CFG will be displayed."));
+
+// Command line option to turn on CFG dot dump after profile annotation.
+extern cl::opt<bool> PGOViewCounts;
+
 namespace {
 
 /// The select instruction visitor plays three roles specified
@@ -1202,6 +1215,18 @@ static bool annotateAllFunctions(
       ColdFunctions.push_back(&F);
     else if (FreqAttr == PGOUseFunc::FFA_Hot)
       HotFunctions.push_back(&F);
+#ifndef NDEBUG
+    if (PGOViewCounts &&
+        (PGOViewFunction.empty() || F.getName().equals(PGOViewFunction))) {
+      LoopInfo LI{DominatorTree(F)};
+      std::unique_ptr<BranchProbabilityInfo> NewBPI =
+          llvm::make_unique<BranchProbabilityInfo>(F, LI);
+      std::unique_ptr<BlockFrequencyInfo> NewBFI =
+          llvm::make_unique<BlockFrequencyInfo>(F, *NewBPI, LI);
+
+      NewBFI->view();
+    }
+#endif
   }
   M.setProfileSummary(PGOReader->getSummary().getMD(M.getContext()));
   // Set function hotness attribute from the profile.




More information about the llvm-commits mailing list