LLVM  4.0.0
DomPrinter.cpp
Go to the documentation of this file.
1 //===- DomPrinter.cpp - DOT printer for the dominance trees ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines '-dot-dom' and '-dot-postdom' analysis passes, which emit
11 // a dom.<fnname>.dot or postdom.<fnname>.dot file for each function in the
12 // program, with a graph of the dominance/postdominance tree of that
13 // function.
14 //
15 // There are also passes available to directly call dotty ('-view-dom' or
16 // '-view-postdom'). By appending '-only' like '-dot-dom-only' only the
17 // names of the bbs are printed, but the content is hidden.
18 //
19 //===----------------------------------------------------------------------===//
20 
24 
25 using namespace llvm;
26 
27 namespace llvm {
28 template<>
30 
31  DOTGraphTraits (bool isSimple=false)
33 
34  std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) {
35 
36  BasicBlock *BB = Node->getBlock();
37 
38  if (!BB)
39  return "Post dominance root node";
40 
41 
42  if (isSimple())
45  else
48  }
49 };
50 
51 template<>
53 
54  DOTGraphTraits (bool isSimple=false)
56 
57  static std::string getGraphName(DominatorTree *DT) {
58  return "Dominator tree";
59  }
60 
61  std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) {
63  }
64 };
65 
66 template<>
69 
70  DOTGraphTraits (bool isSimple=false)
72 
73  static std::string getGraphName(PostDominatorTree *DT) {
74  return "Post dominator tree";
75  }
76 
77  std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G ) {
79  }
80 };
81 }
82 
83 namespace {
84 struct DominatorTreeWrapperPassAnalysisGraphTraits {
85  static DominatorTree *getGraph(DominatorTreeWrapperPass *DTWP) {
86  return &DTWP->getDomTree();
87  }
88 };
89 
90 struct DomViewer : public DOTGraphTraitsViewer<
91  DominatorTreeWrapperPass, false, DominatorTree *,
92  DominatorTreeWrapperPassAnalysisGraphTraits> {
93  static char ID;
94  DomViewer()
96  DominatorTreeWrapperPassAnalysisGraphTraits>(
97  "dom", ID) {
99  }
100 };
101 
102 struct DomOnlyViewer : public DOTGraphTraitsViewer<
103  DominatorTreeWrapperPass, true, DominatorTree *,
104  DominatorTreeWrapperPassAnalysisGraphTraits> {
105  static char ID;
106  DomOnlyViewer()
108  DominatorTreeWrapperPassAnalysisGraphTraits>(
109  "domonly", ID) {
111  }
112 };
113 
114 struct PostDominatorTreeWrapperPassAnalysisGraphTraits {
115  static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
116  return &PDTWP->getPostDomTree();
117  }
118 };
119 
120 struct PostDomViewer : public DOTGraphTraitsViewer<
121  PostDominatorTreeWrapperPass, false,
122  PostDominatorTree *,
123  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
124  static char ID;
125  PostDomViewer() :
128  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
129  "postdom", ID){
131  }
132 };
133 
134 struct PostDomOnlyViewer : public DOTGraphTraitsViewer<
135  PostDominatorTreeWrapperPass, true,
136  PostDominatorTree *,
137  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
138  static char ID;
139  PostDomOnlyViewer() :
142  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
143  "postdomonly", ID){
145  }
146 };
147 } // end anonymous namespace
148 
149 char DomViewer::ID = 0;
150 INITIALIZE_PASS(DomViewer, "view-dom",
151  "View dominance tree of function", false, false)
152 
153 char DomOnlyViewer::ID = 0;
154 INITIALIZE_PASS(DomOnlyViewer, "view-dom-only",
155  "View dominance tree of function (with no function bodies)",
156  false, false)
157 
158 char PostDomViewer::ID = 0;
159 INITIALIZE_PASS(PostDomViewer, "view-postdom",
160  "View postdominance tree of function", false, false)
161 
162 char PostDomOnlyViewer::ID = 0;
163 INITIALIZE_PASS(PostDomOnlyViewer, "view-postdom-only",
164  "View postdominance tree of function "
165  "(with no function bodies)",
166  false, false)
167 
168 namespace {
169 struct DomPrinter : public DOTGraphTraitsPrinter<
170  DominatorTreeWrapperPass, false, DominatorTree *,
171  DominatorTreeWrapperPassAnalysisGraphTraits> {
172  static char ID;
173  DomPrinter()
175  DominatorTreeWrapperPassAnalysisGraphTraits>(
176  "dom", ID) {
178  }
179 };
180 
181 struct DomOnlyPrinter : public DOTGraphTraitsPrinter<
182  DominatorTreeWrapperPass, true, DominatorTree *,
183  DominatorTreeWrapperPassAnalysisGraphTraits> {
184  static char ID;
185  DomOnlyPrinter()
187  DominatorTreeWrapperPassAnalysisGraphTraits>(
188  "domonly", ID) {
190  }
191 };
192 
193 struct PostDomPrinter
194  : public DOTGraphTraitsPrinter<
195  PostDominatorTreeWrapperPass, false,
196  PostDominatorTree *,
197  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
198  static char ID;
199  PostDomPrinter() :
202  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
203  "postdom", ID) {
205  }
206 };
207 
208 struct PostDomOnlyPrinter
209  : public DOTGraphTraitsPrinter<
210  PostDominatorTreeWrapperPass, true,
211  PostDominatorTree *,
212  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
213  static char ID;
214  PostDomOnlyPrinter() :
217  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
218  "postdomonly", ID) {
220  }
221 };
222 } // end anonymous namespace
223 
224 
225 
226 char DomPrinter::ID = 0;
227 INITIALIZE_PASS(DomPrinter, "dot-dom",
228  "Print dominance tree of function to 'dot' file",
229  false, false)
230 
231 char DomOnlyPrinter::ID = 0;
232 INITIALIZE_PASS(DomOnlyPrinter, "dot-dom-only",
233  "Print dominance tree of function to 'dot' file "
234  "(with no function bodies)",
235  false, false)
236 
237 char PostDomPrinter::ID = 0;
238 INITIALIZE_PASS(PostDomPrinter, "dot-postdom",
239  "Print postdominance tree of function to 'dot' file",
240  false, false)
241 
242 char PostDomOnlyPrinter::ID = 0;
243 INITIALIZE_PASS(PostDomOnlyPrinter, "dot-postdom-only",
244  "Print postdominance tree of function to 'dot' file "
245  "(with no function bodies)",
246  false, false)
247 
248 // Create methods available outside of this file, to use them
249 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
250 // the link time optimization.
251 
253  return new DomPrinter();
254 }
255 
257  return new DomOnlyPrinter();
258 }
259 
261  return new DomViewer();
262 }
263 
265  return new DomOnlyViewer();
266 }
267 
269  return new PostDomPrinter();
270 }
271 
273  return new PostDomOnlyPrinter();
274 }
275 
277  return new PostDomViewer();
278 }
279 
281  return new PostDomOnlyViewer();
282 }
FunctionPass * createDomOnlyViewerPass()
Definition: DomPrinter.cpp:264
void initializeDomViewerPass(PassRegistry &)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void Print(const Unit &v, const char *PrintAfter)
Definition: FuzzerUtil.cpp:34
FunctionPass * createPostDomPrinterPass()
Definition: DomPrinter.cpp:268
void initializePostDomViewerPass(PassRegistry &)
void initializePostDomOnlyViewerPass(PassRegistry &)
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:100
dot regions only
void initializeDomOnlyPrinterPass(PassRegistry &)
FunctionPass * createDomViewerPass()
Definition: DomPrinter.cpp:260
void initializePostDomPrinterPass(PassRegistry &)
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
DominatorTree & getDomTree()
Definition: Dominators.h:227
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)
Function Alias Analysis false
Base class for the actual dominator tree node.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
NodeT * getBlock() const
FunctionPass * createDomPrinterPass()
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
void initializeDomOnlyViewerPass(PassRegistry &)
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:163
std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G)
Definition: DomPrinter.cpp:61
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
static std::string getGraphName(PostDominatorTree *DT)
Definition: DomPrinter.cpp:73
dot regions Print regions of function to dot file(with no function bodies)"
std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph)
Definition: DomPrinter.cpp:34
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
void initializePostDomOnlyPrinterPass(PassRegistry &)
PostDominatorTree & getPostDomTree()
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:31
FunctionPass * createDomOnlyPrinterPass()
Definition: DomPrinter.cpp:256
std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G)
Definition: DomPrinter.cpp:77
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
FunctionPass * createPostDomViewerPass()
Definition: DomPrinter.cpp:276
void initializeDomPrinterPass(PassRegistry &)
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
Basic Alias true
FunctionPass * createPostDomOnlyViewerPass()
Definition: DomPrinter.cpp:280
FunctionPass * createPostDomOnlyPrinterPass()
Definition: DomPrinter.cpp:272
static std::string getGraphName(DominatorTree *DT)
Definition: DomPrinter.cpp:57
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
print Print MemDeps of function
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:217