mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:50:30 +00:00
[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 llvm-svn: 244442
This commit is contained in:
parent
f4a0009c80
commit
3373ce735a
@ -55,25 +55,22 @@ struct DOTGraphTraits<RegionNode*> : public DefaultDOTGraphTraits {
|
||||
}
|
||||
};
|
||||
|
||||
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*> : public DOTGraphTraits<RegionNode*> {
|
||||
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*> : public DOTGraphTraits<RegionNode*> {
|
||||
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*> : public DOTGraphTraits<RegionNode*> {
|
||||
|
||||
// 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*> : public DOTGraphTraits<RegionNode*> {
|
||||
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 RegionViewer
|
||||
: public DOTGraphTraitsViewer<RegionInfoPass, false> {
|
||||
struct RegionInfoPassGraphTraits {
|
||||
static RegionInfo *getGraph(RegionInfoPass *RIP) {
|
||||
return &RIP->getRegionInfo();
|
||||
}
|
||||
};
|
||||
|
||||
struct RegionPrinter
|
||||
: public DOTGraphTraitsPrinter<RegionInfoPass, false, RegionInfo *,
|
||||
RegionInfoPassGraphTraits> {
|
||||
static char ID;
|
||||
RegionViewer() : DOTGraphTraitsViewer<RegionInfoPass, false>("reg", 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, RegionInfo *,
|
||||
RegionInfoPassGraphTraits> {
|
||||
static char 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-regions-only",
|
||||
"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::createRegionOnlyViewerPass() {
|
||||
return new RegionOnlyViewer();
|
||||
}
|
||||
|
||||
FunctionPass* llvm::createRegionPrinterPass() {
|
||||
return new RegionPrinter();
|
||||
}
|
||||
|
||||
FunctionPass* llvm::createRegionOnlyPrinterPass() {
|
||||
return new RegionOnlyPrinter();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user