[llvm] r244442 - [RegionInfo] Use RegionInfo* instead of RegionInfoPass* as graph type
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 05:57:23 PDT 2015
Author: meinersbur
Date: Mon Aug 10 07:57:23 2015
New Revision: 244442
URL: http://llvm.org/viewvc/llvm-project?rev=244442&view=rev
Log:
[RegionInfo] Use RegionInfo* instead of RegionInfoPass* as graph type
This allows printing region graphs when only the RegionInfo (e.g. Region::getRegionInfo()), but no RegionInfoPass object is available.
Specifically, we will use this to print RegionInfo graphs in the debugger.
Differential version: http://reviews.llvm.org/D11874
Reviewed-by: grosser
Modified:
llvm/trunk/lib/Analysis/RegionPrinter.cpp
Modified: llvm/trunk/lib/Analysis/RegionPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionPrinter.cpp?rev=244442&r1=244441&r2=244442&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionPrinter.cpp Mon Aug 10 07:57:23 2015
@@ -55,25 +55,22 @@ struct DOTGraphTraits<RegionNode*> : pub
}
};
-template<>
-struct DOTGraphTraits<RegionInfoPass*> : public DOTGraphTraits<RegionNode*> {
+template <>
+struct DOTGraphTraits<RegionInfo *> : public DOTGraphTraits<RegionNode *> {
DOTGraphTraits (bool isSimple = false)
: DOTGraphTraits<RegionNode*>(isSimple) {}
- static std::string getGraphName(RegionInfoPass *DT) {
- return "Region Graph";
- }
+ static std::string getGraphName(const RegionInfo *) { return "Region Graph"; }
- std::string getNodeLabel(RegionNode *Node, RegionInfoPass *G) {
- RegionInfo &RI = G->getRegionInfo();
- return DOTGraphTraits<RegionNode*>::getNodeLabel(Node,
- reinterpret_cast<RegionNode*>(RI.getTopLevelRegion()));
+ std::string getNodeLabel(RegionNode *Node, RegionInfo *G) {
+ return DOTGraphTraits<RegionNode *>::getNodeLabel(
+ Node, reinterpret_cast<RegionNode *>(G->getTopLevelRegion()));
}
std::string getEdgeAttributes(RegionNode *srcNode,
- GraphTraits<RegionInfo*>::ChildIteratorType CI, RegionInfoPass *G) {
- RegionInfo &RI = G->getRegionInfo();
+ GraphTraits<RegionInfo *>::ChildIteratorType CI,
+ RegionInfo *G) {
RegionNode *destNode = *CI;
if (srcNode->isSubRegion() || destNode->isSubRegion())
@@ -83,7 +80,7 @@ struct DOTGraphTraits<RegionInfoPass*> :
BasicBlock *srcBB = srcNode->getNodeAs<BasicBlock>();
BasicBlock *destBB = destNode->getNodeAs<BasicBlock>();
- Region *R = RI.getRegionFor(destBB);
+ Region *R = G->getRegionFor(destBB);
while (R && R->getParent())
if (R->getParent()->getEntry() == destBB)
@@ -91,7 +88,7 @@ struct DOTGraphTraits<RegionInfoPass*> :
else
break;
- if (R->getEntry() == destBB && R->contains(srcBB))
+ if (R && R->getEntry() == destBB && R->contains(srcBB))
return "constraint=false";
return "";
@@ -99,8 +96,7 @@ struct DOTGraphTraits<RegionInfoPass*> :
// Print the cluster of the subregions. This groups the single basic blocks
// and adds a different background color for each group.
- static void printRegionCluster(const Region &R,
- GraphWriter<RegionInfoPass*> &GW,
+ static void printRegionCluster(const Region &R, GraphWriter<RegionInfo *> &GW,
unsigned depth = 0) {
raw_ostream &O = GW.getOStream();
O.indent(2 * depth) << "subgraph cluster_" << static_cast<const void*>(&R)
@@ -132,50 +128,81 @@ struct DOTGraphTraits<RegionInfoPass*> :
O.indent(2 * depth) << "}\n";
}
- static void addCustomGraphFeatures(const RegionInfoPass* RIP,
- GraphWriter<RegionInfoPass*> &GW) {
- const RegionInfo &RI = RIP->getRegionInfo();
+ static void addCustomGraphFeatures(const RegionInfo *G,
+ GraphWriter<RegionInfo *> &GW) {
raw_ostream &O = GW.getOStream();
O << "\tcolorscheme = \"paired12\"\n";
- printRegionCluster(*RI.getTopLevelRegion(), GW, 4);
+ printRegionCluster(*G->getTopLevelRegion(), GW, 4);
}
};
} //end namespace llvm
namespace {
+struct RegionInfoPassGraphTraits {
+ static RegionInfo *getGraph(RegionInfoPass *RIP) {
+ return &RIP->getRegionInfo();
+ }
+};
+
+struct RegionPrinter
+ : public DOTGraphTraitsPrinter<RegionInfoPass, false, RegionInfo *,
+ RegionInfoPassGraphTraits> {
+ static char ID;
+ RegionPrinter()
+ : DOTGraphTraitsPrinter<RegionInfoPass, false, RegionInfo *,
+ RegionInfoPassGraphTraits>("reg", ID) {
+ initializeRegionPrinterPass(*PassRegistry::getPassRegistry());
+ }
+};
+char RegionPrinter::ID = 0;
+
+struct RegionOnlyPrinter
+ : public DOTGraphTraitsPrinter<RegionInfoPass, true, RegionInfo *,
+ RegionInfoPassGraphTraits> {
+ static char ID;
+ RegionOnlyPrinter()
+ : DOTGraphTraitsPrinter<RegionInfoPass, true, RegionInfo *,
+ RegionInfoPassGraphTraits>("reg", ID) {
+ initializeRegionOnlyPrinterPass(*PassRegistry::getPassRegistry());
+ }
+};
+char RegionOnlyPrinter::ID = 0;
+
struct RegionViewer
- : public DOTGraphTraitsViewer<RegionInfoPass, false> {
+ : public DOTGraphTraitsViewer<RegionInfoPass, false, RegionInfo *,
+ RegionInfoPassGraphTraits> {
static char ID;
- RegionViewer() : DOTGraphTraitsViewer<RegionInfoPass, false>("reg", ID){
+ RegionViewer()
+ : DOTGraphTraitsViewer<RegionInfoPass, false, RegionInfo *,
+ RegionInfoPassGraphTraits>("reg", ID) {
initializeRegionViewerPass(*PassRegistry::getPassRegistry());
}
};
char RegionViewer::ID = 0;
struct RegionOnlyViewer
- : public DOTGraphTraitsViewer<RegionInfoPass, true> {
+ : public DOTGraphTraitsViewer<RegionInfoPass, true, RegionInfo *,
+ RegionInfoPassGraphTraits> {
static char ID;
- RegionOnlyViewer() : DOTGraphTraitsViewer<RegionInfoPass, true>("regonly", ID) {
+ RegionOnlyViewer()
+ : DOTGraphTraitsViewer<RegionInfoPass, true, RegionInfo *,
+ RegionInfoPassGraphTraits>("regonly", ID) {
initializeRegionOnlyViewerPass(*PassRegistry::getPassRegistry());
}
};
char RegionOnlyViewer::ID = 0;
-struct RegionPrinter
- : public DOTGraphTraitsPrinter<RegionInfoPass, false> {
- static char ID;
- RegionPrinter() :
- DOTGraphTraitsPrinter<RegionInfoPass, false>("reg", ID) {
- initializeRegionPrinterPass(*PassRegistry::getPassRegistry());
- }
-};
-char RegionPrinter::ID = 0;
} //end anonymous namespace
INITIALIZE_PASS(RegionPrinter, "dot-regions",
"Print regions of function to 'dot' file", true, true)
+INITIALIZE_PASS(
+ RegionOnlyPrinter, "dot-regions-only",
+ "Print regions of function to 'dot' file (with no function bodies)", true,
+ true)
+
INITIALIZE_PASS(RegionViewer, "view-regions", "View regions of function",
true, true)
@@ -183,25 +210,12 @@ INITIALIZE_PASS(RegionOnlyViewer, "view-
"View regions of function (with no function bodies)",
true, true)
-namespace {
-
-struct RegionOnlyPrinter
- : public DOTGraphTraitsPrinter<RegionInfoPass, true> {
- static char ID;
- RegionOnlyPrinter() :
- DOTGraphTraitsPrinter<RegionInfoPass, true>("reg", ID) {
- initializeRegionOnlyPrinterPass(*PassRegistry::getPassRegistry());
- }
-};
+FunctionPass *llvm::createRegionPrinterPass() { return new RegionPrinter(); }
+FunctionPass *llvm::createRegionOnlyPrinterPass() {
+ return new RegionOnlyPrinter();
}
-char RegionOnlyPrinter::ID = 0;
-INITIALIZE_PASS(RegionOnlyPrinter, "dot-regions-only",
- "Print regions of function to 'dot' file "
- "(with no function bodies)",
- true, true)
-
FunctionPass* llvm::createRegionViewerPass() {
return new RegionViewer();
}
@@ -210,11 +224,3 @@ FunctionPass* llvm::createRegionOnlyView
return new RegionOnlyViewer();
}
-FunctionPass* llvm::createRegionPrinterPass() {
- return new RegionPrinter();
-}
-
-FunctionPass* llvm::createRegionOnlyPrinterPass() {
- return new RegionOnlyPrinter();
-}
-
More information about the llvm-commits
mailing list