[llvm] r244444 - [RegionInfo] Add debug-time region viewer functions

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 06:21:59 PDT 2015


Author: meinersbur
Date: Mon Aug 10 08:21:59 2015
New Revision: 244444

URL: http://llvm.org/viewvc/llvm-project?rev=244444&view=rev
Log:
[RegionInfo] Add debug-time region viewer functions

Summary:
Analogously to Function::viewCFG(), RegionInfo::view() and RegionInfo::viewOnly() are meant to be called in debugging sessions. They open a viewer to show how RegionInfo currently understands the region hierarchy.

The functions viewRegion(Function*) and viewRegionOnly(Function*) invoke a fresh region analysis of the function in contrast to viewRegion(RegionInfo*) and viewRegionOnly(RegionInfo*) which show the current analysis result.

Reviewers: grosser

Subscribers: llvm-commits

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

Modified:
    llvm/trunk/include/llvm/Analysis/RegionInfo.h
    llvm/trunk/include/llvm/Analysis/RegionPrinter.h
    llvm/trunk/lib/Analysis/RegionInfo.cpp
    llvm/trunk/lib/Analysis/RegionPrinter.cpp

Modified: llvm/trunk/include/llvm/Analysis/RegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/RegionInfo.h?rev=244444&r1=244443&r2=244444&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/RegionInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/RegionInfo.h Mon Aug 10 08:21:59 2015
@@ -846,6 +846,19 @@ public:
 
   void recalculate(Function &F, DominatorTree *DT, PostDominatorTree *PDT,
                    DominanceFrontier *DF);
+
+#ifndef NDEBUG
+  /// @brief Opens a viewer to show the GraphViz visualization of the regions.
+  ///
+  /// Useful during debugging as an alternative to dump().
+  void view();
+
+  /// @brief Opens a viewer to show the GraphViz visalization of this region
+  /// without instructions in the BasicBlocks.
+  ///
+  /// Useful during debugging as an alternative to dump().
+  void viewOnly();
+#endif
 };
 
 class RegionInfoPass : public FunctionPass {

Modified: llvm/trunk/include/llvm/Analysis/RegionPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/RegionPrinter.h?rev=244444&r1=244443&r2=244444&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/RegionPrinter.h (original)
+++ llvm/trunk/include/llvm/Analysis/RegionPrinter.h Mon Aug 10 08:21:59 2015
@@ -17,10 +17,55 @@
 
 namespace llvm {
   class FunctionPass;
+  class Function;
+  class RegionInfo;
+
   FunctionPass *createRegionViewerPass();
   FunctionPass *createRegionOnlyViewerPass();
   FunctionPass *createRegionPrinterPass();
   FunctionPass *createRegionOnlyPrinterPass();
+
+#ifndef NDEBUG
+  /// @brief Open a viewer to display the GraphViz vizualization of the analysis
+  /// result.
+  ///
+  /// Practical to call in the debugger.
+  /// Includes the instructions in each BasicBlock.
+  ///
+  /// @param RI The analysis to display.
+  void viewRegion(llvm::RegionInfo *RI);
+
+  /// @brief Analyze the regions of a function and open its GraphViz
+  /// visualization in a viewer.
+  ///
+  /// Useful to call in the debugger.
+  /// Includes the instructions in each BasicBlock.
+  /// The result of a new analysis may differ from the RegionInfo the pass
+  /// manager currently holds.
+  ///
+  /// @param F Function to analyze.
+  void viewRegion(const llvm::Function *F);
+
+  /// @brief Open a viewer to display the GraphViz vizualization of the analysis
+  /// result.
+  ///
+  /// Useful to call in the debugger.
+  /// Shows only the BasicBlock names without their instructions.
+  ///
+  /// @param RI The analysis to display.
+  void viewRegionOnly(llvm::RegionInfo *RI);
+
+  /// @brief Analyze the regions of a function and open its GraphViz
+  /// visualization in a viewer.
+  ///
+  /// Useful to call in the debugger.
+  /// Shows only the BasicBlock names without their instructions.
+  /// The result of a new analysis may differ from the RegionInfo the pass
+  /// manager currently holds.
+  ///
+  /// @param F Function to analyze.
+  void viewRegionOnly(const llvm::Function *F);
+#endif
 } // End llvm namespace
 
 #endif

Modified: llvm/trunk/lib/Analysis/RegionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionInfo.cpp?rev=244444&r1=244443&r2=244444&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionInfo.cpp Mon Aug 10 08:21:59 2015
@@ -21,6 +21,9 @@
 #include <algorithm>
 #include <iterator>
 #include <set>
+#ifndef NDEBUG
+#include "llvm/Analysis/RegionPrinter.h"
+#endif
 
 using namespace llvm;
 
@@ -103,6 +106,12 @@ void RegionInfo::recalculate(Function &F
   calculate(F);
 }
 
+#ifndef NDEBUG
+void RegionInfo::view() { viewRegion(this); }
+
+void RegionInfo::viewOnly() { viewRegionOnly(this); }
+#endif
+
 //===----------------------------------------------------------------------===//
 // RegionInfoPass implementation
 //

Modified: llvm/trunk/lib/Analysis/RegionPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionPrinter.cpp?rev=244444&r1=244443&r2=244444&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionPrinter.cpp Mon Aug 10 08:21:59 2015
@@ -20,6 +20,9 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
+#ifndef NDEBUG
+#include "llvm/IR/LegacyPassManager.h"
+#endif
 
 using namespace llvm;
 
@@ -224,3 +227,41 @@ FunctionPass* llvm::createRegionOnlyView
   return new RegionOnlyViewer();
 }
 
+#ifndef NDEBUG
+static void viewRegionInfo(RegionInfo *RI, bool ShortNames) {
+  assert(RI && "Argument must be non-null");
+
+  llvm::Function *F = RI->getTopLevelRegion()->getEntry()->getParent();
+  std::string GraphName = DOTGraphTraits<RegionInfo *>::getGraphName(RI);
+
+  llvm::ViewGraph(RI, "reg", ShortNames,
+                  Twine(GraphName) + " for '" + F->getName() + "' function");
+}
+
+static void invokeFunctionPass(const Function *F, FunctionPass *ViewerPass) {
+  assert(F && "Argument must be non-null");
+  assert(!F->isDeclaration() && "Function must have an implementation");
+
+  // The viewer and analysis passes do not modify anything, so we can safely
+  // remove the const qualifier
+  auto NonConstF = const_cast<Function *>(F);
+
+  llvm::legacy::FunctionPassManager FPM(NonConstF->getParent());
+  FPM.add(ViewerPass);
+  FPM.doInitialization();
+  FPM.run(*NonConstF);
+  FPM.doFinalization();
+}
+
+void llvm::viewRegion(RegionInfo *RI) { viewRegionInfo(RI, false); }
+
+void llvm::viewRegion(const Function *F) {
+  invokeFunctionPass(F, createRegionViewerPass());
+}
+
+void llvm::viewRegionOnly(RegionInfo *RI) { viewRegionInfo(RI, true); }
+
+void llvm::viewRegionOnly(const Function *F) {
+  invokeFunctionPass(F, createRegionOnlyViewerPass());
+}
+#endif




More information about the llvm-commits mailing list