llvm.org GIT mirror llvm / 6b23651
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244442 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Kruse 4 years ago
1 changed file(s) with 66 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
5454 }
5555 };
5656
57 template<>
58 struct DOTGraphTraits : public DOTGraphTraits {
57 template <>
58 struct DOTGraphTraits : public DOTGraphTraits {
5959
6060 DOTGraphTraits (bool isSimple = false)
6161 : DOTGraphTraits(isSimple) {}
6262
63 static std::string getGraphName(RegionInfoPass *DT) {
64 return "Region Graph";
65 }
66
67 std::string getNodeLabel(RegionNode *Node, RegionInfoPass *G) {
68 RegionInfo &RI = G->getRegionInfo();
69 return DOTGraphTraits::getNodeLabel(Node,
70 reinterpret_cast(RI.getTopLevelRegion()));
63 static std::string getGraphName(const RegionInfo *) { return "Region Graph"; }
64
65 std::string getNodeLabel(RegionNode *Node, RegionInfo *G) {
66 return DOTGraphTraits::getNodeLabel(
67 Node, reinterpret_cast(G->getTopLevelRegion()));
7168 }
7269
7370 std::string getEdgeAttributes(RegionNode *srcNode,
74 GraphTraits::ChildIteratorType CI, RegionInfoPass *G) {
75 RegionInfo &RI = G->getRegionInfo();
71 GraphTraits::ChildIteratorType CI,
72 RegionInfo *G) {
7673 RegionNode *destNode = *CI;
7774
7875 if (srcNode->isSubRegion() || destNode->isSubRegion())
8279 BasicBlock *srcBB = srcNode->getNodeAs();
8380 BasicBlock *destBB = destNode->getNodeAs();
8481
85 Region *R = RI.getRegionFor(destBB);
82 Region *R = G->getRegionFor(destBB);
8683
8784 while (R && R->getParent())
8885 if (R->getParent()->getEntry() == destBB)
9087 else
9188 break;
9289
93 if (R->getEntry() == destBB && R->contains(srcBB))
90 if (R && R->getEntry() == destBB && R->contains(srcBB))
9491 return "constraint=false";
9592
9693 return "";
9895
9996 // Print the cluster of the subregions. This groups the single basic blocks
10097 // and adds a different background color for each group.
101 static void printRegionCluster(const Region &R,
102 GraphWriter*> &GW,
98 static void printRegionCluster(const Region &R, GraphWriter*> &GW,
10399 unsigned depth = 0) {
104100 raw_ostream &O = GW.getOStream();
105101 O.indent(2 * depth) << "subgraph cluster_" << static_cast(&R)
131127 O.indent(2 * depth) << "}\n";
132128 }
133129
134 static void addCustomGraphFeatures(const RegionInfoPass* RIP,
135 GraphWriter &GW) {
136 const RegionInfo &RI = RIP->getRegionInfo();
130 static void addCustomGraphFeatures(const RegionInfo *G,
131 GraphWriter &GW) {
137132 raw_ostream &O = GW.getOStream();
138133 O << "\tcolorscheme = \"paired12\"\n";
139 printRegionCluster(*RI.getTopLevelRegion(), GW, 4);
134 printRegionCluster(*G->getTopLevelRegion(), GW, 4);
140135 }
141136 };
142137 } //end namespace llvm
143138
144139 namespace {
145140
141 struct RegionInfoPassGraphTraits {
142 static RegionInfo *getGraph(RegionInfoPass *RIP) {
143 return &RIP->getRegionInfo();
144 }
145 };
146
147 struct RegionPrinter
148 : public DOTGraphTraitsPrinter
149 RegionInfoPassGraphTraits> {
150 static char ID;
151 RegionPrinter()
152 : DOTGraphTraitsPrinter
153 RegionInfoPassGraphTraits>("reg", ID) {
154 initializeRegionPrinterPass(*PassRegistry::getPassRegistry());
155 }
156 };
157 char RegionPrinter::ID = 0;
158
159 struct RegionOnlyPrinter
160 : public DOTGraphTraitsPrinter
161 RegionInfoPassGraphTraits> {
162 static char ID;
163 RegionOnlyPrinter()
164 : DOTGraphTraitsPrinter
165 RegionInfoPassGraphTraits>("reg", ID) {
166 initializeRegionOnlyPrinterPass(*PassRegistry::getPassRegistry());
167 }
168 };
169 char RegionOnlyPrinter::ID = 0;
170
146171 struct RegionViewer
147 : public DOTGraphTraitsViewer {
148 static char ID;
149 RegionViewer() : DOTGraphTraitsViewer("reg", ID){
172 : public DOTGraphTraitsViewer
173 RegionInfoPassGraphTraits> {
174 static char ID;
175 RegionViewer()
176 : DOTGraphTraitsViewer
177 RegionInfoPassGraphTraits>("reg", ID) {
150178 initializeRegionViewerPass(*PassRegistry::getPassRegistry());
151179 }
152180 };
153181 char RegionViewer::ID = 0;
154182
155183 struct RegionOnlyViewer
156 : public DOTGraphTraitsViewer {
157 static char ID;
158 RegionOnlyViewer() : DOTGraphTraitsViewer("regonly", ID) {
184 : public DOTGraphTraitsViewer
185 RegionInfoPassGraphTraits> {
186 static char ID;
187 RegionOnlyViewer()
188 : DOTGraphTraitsViewer
189 RegionInfoPassGraphTraits>("regonly", ID) {
159190 initializeRegionOnlyViewerPass(*PassRegistry::getPassRegistry());
160191 }
161192 };
162193 char RegionOnlyViewer::ID = 0;
163194
164 struct RegionPrinter
165 : public DOTGraphTraitsPrinter {
166 static char ID;
167 RegionPrinter() :
168 DOTGraphTraitsPrinter("reg", ID) {
169 initializeRegionPrinterPass(*PassRegistry::getPassRegistry());
170 }
171 };
172 char RegionPrinter::ID = 0;
173195 } //end anonymous namespace
174196
175197 INITIALIZE_PASS(RegionPrinter, "dot-regions",
176198 "Print regions of function to 'dot' file", true, true)
199
200 INITIALIZE_PASS(
201 RegionOnlyPrinter, "dot-regions-only",
202 "Print regions of function to 'dot' file (with no function bodies)", true,
203 true)
177204
178205 INITIALIZE_PASS(RegionViewer, "view-regions", "View regions of function",
179206 true, true)
182209 "View regions of function (with no function bodies)",
183210 true, true)
184211
185 namespace {
186
187 struct RegionOnlyPrinter
188 : public DOTGraphTraitsPrinter {
189 static char ID;
190 RegionOnlyPrinter() :
191 DOTGraphTraitsPrinter("reg", ID) {
192 initializeRegionOnlyPrinterPass(*PassRegistry::getPassRegistry());
193 }
194 };
195
212 FunctionPass *llvm::createRegionPrinterPass() { return new RegionPrinter(); }
213
214 FunctionPass *llvm::createRegionOnlyPrinterPass() {
215 return new RegionOnlyPrinter();
196216 }
197
198 char RegionOnlyPrinter::ID = 0;
199 INITIALIZE_PASS(RegionOnlyPrinter, "dot-regions-only",
200 "Print regions of function to 'dot' file "
201 "(with no function bodies)",
202 true, true)
203217
204218 FunctionPass* llvm::createRegionViewerPass() {
205219 return new RegionViewer();
209223 return new RegionOnlyViewer();
210224 }
211225
212 FunctionPass* llvm::createRegionPrinterPass() {
213 return new RegionPrinter();
214 }
215
216 FunctionPass* llvm::createRegionOnlyPrinterPass() {
217 return new RegionOnlyPrinter();
218 }
219