summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMichael Kruse <llvm@meinersbur.de>2015-08-10 13:21:59 +0000
committerMichael Kruse <llvm@meinersbur.de>2015-08-10 13:21:59 +0000
commit20dcc9f7f113058f28ec1b15c60c71b1e10abe1a (patch)
tree83ed5cedd92b757f9c1e0605c46044be28218654 /llvm/lib
parent046dde40c53cd4558870e9bd3f96d8b6d70853df (diff)
downloadbcm5719-llvm-20dcc9f7f113058f28ec1b15c60c71b1e10abe1a.tar.gz
bcm5719-llvm-20dcc9f7f113058f28ec1b15c60c71b1e10abe1a.zip
[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 llvm-svn: 244444
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/RegionInfo.cpp9
-rw-r--r--llvm/lib/Analysis/RegionPrinter.cpp41
2 files changed, 50 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/RegionInfo.cpp b/llvm/lib/Analysis/RegionInfo.cpp
index 8cd85348fdc..f59d2673032 100644
--- a/llvm/lib/Analysis/RegionInfo.cpp
+++ b/llvm/lib/Analysis/RegionInfo.cpp
@@ -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, DominatorTree *DT_,
calculate(F);
}
+#ifndef NDEBUG
+void RegionInfo::view() { viewRegion(this); }
+
+void RegionInfo::viewOnly() { viewRegionOnly(this); }
+#endif
+
//===----------------------------------------------------------------------===//
// RegionInfoPass implementation
//
diff --git a/llvm/lib/Analysis/RegionPrinter.cpp b/llvm/lib/Analysis/RegionPrinter.cpp
index f41725244a5..acb218d5fea 100644
--- a/llvm/lib/Analysis/RegionPrinter.cpp
+++ b/llvm/lib/Analysis/RegionPrinter.cpp
@@ -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::createRegionOnlyViewerPass() {
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
OpenPOWER on IntegriCloud