LLVM  9.0.0svn
DomPrinter.cpp
Go to the documentation of this file.
1 //===- DomPrinter.cpp - DOT printer for the dominance trees ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines '-dot-dom' and '-dot-postdom' analysis passes, which emit
10 // a dom.<fnname>.dot or postdom.<fnname>.dot file for each function in the
11 // program, with a graph of the dominance/postdominance tree of that
12 // function.
13 //
14 // There are also passes available to directly call dotty ('-view-dom' or
15 // '-view-postdom'). By appending '-only' like '-dot-dom-only' only the
16 // names of the bbs are printed, but the content is hidden.
17 //
18 //===----------------------------------------------------------------------===//
19 
23 
24 using namespace llvm;
25 
26 namespace llvm {
27 template<>
29 
30  DOTGraphTraits (bool isSimple=false)
32 
33  std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) {
34 
35  BasicBlock *BB = Node->getBlock();
36 
37  if (!BB)
38  return "Post dominance root node";
39 
40 
41  if (isSimple())
44  else
47  }
48 };
49 
50 template<>
52 
53  DOTGraphTraits (bool isSimple=false)
55 
56  static std::string getGraphName(DominatorTree *DT) {
57  return "Dominator tree";
58  }
59 
60  std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) {
62  }
63 };
64 
65 template<>
68 
69  DOTGraphTraits (bool isSimple=false)
71 
72  static std::string getGraphName(PostDominatorTree *DT) {
73  return "Post dominator tree";
74  }
75 
76  std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G ) {
78  }
79 };
80 }
81 
82 void DominatorTree::viewGraph(const Twine &Name, const Twine &Title) {
83 #ifndef NDEBUG
84  ViewGraph(this, Name, false, Title);
85 #else
86  errs() << "DomTree dump not available, build with DEBUG\n";
87 #endif // NDEBUG
88 }
89 
91 #ifndef NDEBUG
92  this->viewGraph("domtree", "Dominator Tree for function");
93 #else
94  errs() << "DomTree dump not available, build with DEBUG\n";
95 #endif // NDEBUG
96 }
97 
98 namespace {
99 struct DominatorTreeWrapperPassAnalysisGraphTraits {
100  static DominatorTree *getGraph(DominatorTreeWrapperPass *DTWP) {
101  return &DTWP->getDomTree();
102  }
103 };
104 
105 struct DomViewer : public DOTGraphTraitsViewer<
106  DominatorTreeWrapperPass, false, DominatorTree *,
107  DominatorTreeWrapperPassAnalysisGraphTraits> {
108  static char ID;
109  DomViewer()
111  DominatorTreeWrapperPassAnalysisGraphTraits>(
112  "dom", ID) {
114  }
115 };
116 
117 struct DomOnlyViewer : public DOTGraphTraitsViewer<
118  DominatorTreeWrapperPass, true, DominatorTree *,
119  DominatorTreeWrapperPassAnalysisGraphTraits> {
120  static char ID;
121  DomOnlyViewer()
123  DominatorTreeWrapperPassAnalysisGraphTraits>(
124  "domonly", ID) {
126  }
127 };
128 
129 struct PostDominatorTreeWrapperPassAnalysisGraphTraits {
130  static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
131  return &PDTWP->getPostDomTree();
132  }
133 };
134 
135 struct PostDomViewer : public DOTGraphTraitsViewer<
136  PostDominatorTreeWrapperPass, false,
137  PostDominatorTree *,
138  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
139  static char ID;
140  PostDomViewer() :
143  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
144  "postdom", ID){
146  }
147 };
148 
149 struct PostDomOnlyViewer : public DOTGraphTraitsViewer<
150  PostDominatorTreeWrapperPass, true,
151  PostDominatorTree *,
152  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
153  static char ID;
154  PostDomOnlyViewer() :
157  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
158  "postdomonly", ID){
160  }
161 };
162 } // end anonymous namespace
163 
164 char DomViewer::ID = 0;
165 INITIALIZE_PASS(DomViewer, "view-dom",
166  "View dominance tree of function", false, false)
167 
168 char DomOnlyViewer::ID = 0;
169 INITIALIZE_PASS(DomOnlyViewer, "view-dom-only",
170  "View dominance tree of function (with no function bodies)",
171  false, false)
172 
173 char PostDomViewer::ID = 0;
174 INITIALIZE_PASS(PostDomViewer, "view-postdom",
175  "View postdominance tree of function", false, false)
176 
177 char PostDomOnlyViewer::ID = 0;
178 INITIALIZE_PASS(PostDomOnlyViewer, "view-postdom-only",
179  "View postdominance tree of function "
180  "(with no function bodies)",
181  false, false)
182 
183 namespace {
184 struct DomPrinter : public DOTGraphTraitsPrinter<
185  DominatorTreeWrapperPass, false, DominatorTree *,
186  DominatorTreeWrapperPassAnalysisGraphTraits> {
187  static char ID;
188  DomPrinter()
190  DominatorTreeWrapperPassAnalysisGraphTraits>(
191  "dom", ID) {
193  }
194 };
195 
196 struct DomOnlyPrinter : public DOTGraphTraitsPrinter<
197  DominatorTreeWrapperPass, true, DominatorTree *,
198  DominatorTreeWrapperPassAnalysisGraphTraits> {
199  static char ID;
200  DomOnlyPrinter()
202  DominatorTreeWrapperPassAnalysisGraphTraits>(
203  "domonly", ID) {
205  }
206 };
207 
208 struct PostDomPrinter
209  : public DOTGraphTraitsPrinter<
210  PostDominatorTreeWrapperPass, false,
211  PostDominatorTree *,
212  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
213  static char ID;
214  PostDomPrinter() :
217  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
218  "postdom", ID) {
220  }
221 };
222 
223 struct PostDomOnlyPrinter
224  : public DOTGraphTraitsPrinter<
225  PostDominatorTreeWrapperPass, true,
226  PostDominatorTree *,
227  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
228  static char ID;
229  PostDomOnlyPrinter() :
232  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
233  "postdomonly", ID) {
235  }
236 };
237 } // end anonymous namespace
238 
239 
240 
241 char DomPrinter::ID = 0;
242 INITIALIZE_PASS(DomPrinter, "dot-dom",
243  "Print dominance tree of function to 'dot' file",
244  false, false)
245 
246 char DomOnlyPrinter::ID = 0;
247 INITIALIZE_PASS(DomOnlyPrinter, "dot-dom-only",
248  "Print dominance tree of function to 'dot' file "
249  "(with no function bodies)",
250  false, false)
251 
252 char PostDomPrinter::ID = 0;
253 INITIALIZE_PASS(PostDomPrinter, "dot-postdom",
254  "Print postdominance tree of function to 'dot' file",
255  false, false)
256 
257 char PostDomOnlyPrinter::ID = 0;
258 INITIALIZE_PASS(PostDomOnlyPrinter, "dot-postdom-only",
259  "Print postdominance tree of function to 'dot' file "
260  "(with no function bodies)",
261  false, false)
262 
263 // Create methods available outside of this file, to use them
264 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
265 // the link time optimization.
266 
268  return new DomPrinter();
269 }
270 
272  return new DomOnlyPrinter();
273 }
274 
276  return new DomViewer();
277 }
278 
280  return new DomOnlyViewer();
281 }
282 
284  return new PostDomPrinter();
285 }
286 
288  return new PostDomOnlyPrinter();
289 }
290 
292  return new PostDomViewer();
293 }
294 
296  return new PostDomOnlyViewer();
297 }
FunctionPass * createDomOnlyViewerPass()
Definition: DomPrinter.cpp:279
void initializeDomViewerPass(PassRegistry &)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
FunctionPass * createPostDomPrinterPass()
Definition: DomPrinter.cpp:283
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void initializePostDomViewerPass(PassRegistry &)
void initializePostDomOnlyViewerPass(PassRegistry &)
*ViewGraph Emit a dot run run gv on the postscript *then cleanup For use from the debugger *void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
Definition: GraphWriter.h:366
void initializeDomOnlyPrinterPass(PassRegistry &)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
FunctionPass * createDomViewerPass()
Definition: DomPrinter.cpp:275
void initializePostDomPrinterPass(PassRegistry &)
DominatorTree & getDomTree()
Definition: Dominators.h:269
std::string getNodeLabel(const void *, const GraphType &)
getNodeLabel - Given a node and a pointer to the top level graph, return the label to print in the no...
static bool isSimple(Instruction *I)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
NodeT * getBlock() const
FunctionPass * createDomPrinterPass()
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
void initializeDomOnlyViewerPass(PassRegistry &)
std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G)
Definition: DomPrinter.cpp:60
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
static std::string getGraphName(PostDominatorTree *DT)
Definition: DomPrinter.cpp:72
std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph)
Definition: DomPrinter.cpp:33
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to &#39;dot...
void initializePostDomOnlyPrinterPass(PassRegistry &)
PostDominatorTree & getPostDomTree()
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:30
FunctionPass * createDomOnlyPrinterPass()
Definition: DomPrinter.cpp:271
std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G)
Definition: DomPrinter.cpp:76
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
FunctionPass * createPostDomViewerPass()
Definition: DomPrinter.cpp:291
void initializeDomPrinterPass(PassRegistry &)
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:106
FunctionPass * createPostDomOnlyViewerPass()
Definition: DomPrinter.cpp:295
FunctionPass * createPostDomOnlyPrinterPass()
Definition: DomPrinter.cpp:287
static std::string getGraphName(DominatorTree *DT)
Definition: DomPrinter.cpp:56
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:259
INITIALIZE_PASS(DomViewer, "view-dom", "View dominance tree of function", false, false) char DomOnlyViewer INITIALIZE_PASS(DomOnlyViewer, "view-dom-only", "View dominance tree of function (with no function bodies)", false, false) char PostDomViewer INITIALIZE_PASS(PostDomViewer, "view-postdom", "View postdominance tree of function", false, false) char PostDomOnlyViewer INITIALIZE_PASS(PostDomOnlyViewer, "view-postdom-only", "View postdominance tree of function " "(with no function bodies)", false, false) namespace
Definition: DomPrinter.cpp:178