LLVM  3.7.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)
32  : DefaultDOTGraphTraits(isSimple) {}
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)
55  : DOTGraphTraits<DomTreeNode*>(isSimple) {}
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)
71  : DOTGraphTraits<DomTreeNode*>(isSimple) {}
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 PostDomViewer
115  : public DOTGraphTraitsViewer<PostDominatorTree, false> {
116  static char ID;
117  PostDomViewer() :
120  }
121 };
122 
123 struct PostDomOnlyViewer
124  : public DOTGraphTraitsViewer<PostDominatorTree, true> {
125  static char ID;
126  PostDomOnlyViewer() :
127  DOTGraphTraitsViewer<PostDominatorTree, true>("postdomonly", ID){
129  }
130 };
131 } // end anonymous namespace
132 
133 char DomViewer::ID = 0;
134 INITIALIZE_PASS(DomViewer, "view-dom",
135  "View dominance tree of function", false, false)
136 
137 char DomOnlyViewer::ID = 0;
138 INITIALIZE_PASS(DomOnlyViewer, "view-dom-only",
139  "View dominance tree of function (with no function bodies)",
140  false, false)
141 
142 char PostDomViewer::ID = 0;
143 INITIALIZE_PASS(PostDomViewer, "view-postdom",
144  "View postdominance tree of function", false, false)
145 
146 char PostDomOnlyViewer::ID = 0;
147 INITIALIZE_PASS(PostDomOnlyViewer, "view-postdom-only",
148  "View postdominance tree of function "
149  "(with no function bodies)",
150  false, false)
151 
152 namespace {
153 struct DomPrinter : public DOTGraphTraitsPrinter<
154  DominatorTreeWrapperPass, false, DominatorTree *,
155  DominatorTreeWrapperPassAnalysisGraphTraits> {
156  static char ID;
157  DomPrinter()
159  DominatorTreeWrapperPassAnalysisGraphTraits>(
160  "dom", ID) {
162  }
163 };
164 
165 struct DomOnlyPrinter : public DOTGraphTraitsPrinter<
166  DominatorTreeWrapperPass, true, DominatorTree *,
167  DominatorTreeWrapperPassAnalysisGraphTraits> {
168  static char ID;
169  DomOnlyPrinter()
171  DominatorTreeWrapperPassAnalysisGraphTraits>(
172  "domonly", ID) {
174  }
175 };
176 
177 struct PostDomPrinter
178  : public DOTGraphTraitsPrinter<PostDominatorTree, false> {
179  static char ID;
180  PostDomPrinter() :
183  }
184 };
185 
186 struct PostDomOnlyPrinter
187  : public DOTGraphTraitsPrinter<PostDominatorTree, true> {
188  static char ID;
189  PostDomOnlyPrinter() :
192  }
193 };
194 } // end anonymous namespace
195 
196 
197 
198 char DomPrinter::ID = 0;
199 INITIALIZE_PASS(DomPrinter, "dot-dom",
200  "Print dominance tree of function to 'dot' file",
201  false, false)
202 
203 char DomOnlyPrinter::ID = 0;
204 INITIALIZE_PASS(DomOnlyPrinter, "dot-dom-only",
205  "Print dominance tree of function to 'dot' file "
206  "(with no function bodies)",
207  false, false)
208 
209 char PostDomPrinter::ID = 0;
210 INITIALIZE_PASS(PostDomPrinter, "dot-postdom",
211  "Print postdominance tree of function to 'dot' file",
212  false, false)
213 
214 char PostDomOnlyPrinter::ID = 0;
215 INITIALIZE_PASS(PostDomOnlyPrinter, "dot-postdom-only",
216  "Print postdominance tree of function to 'dot' file "
217  "(with no function bodies)",
218  false, false)
219 
220 // Create methods available outside of this file, to use them
221 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
222 // the link time optimization.
223 
225  return new DomPrinter();
226 }
227 
229  return new DomOnlyPrinter();
230 }
231 
233  return new DomViewer();
234 }
235 
237  return new DomOnlyViewer();
238 }
239 
241  return new PostDomPrinter();
242 }
243 
245  return new PostDomOnlyPrinter();
246 }
247 
249  return new PostDomViewer();
250 }
251 
253  return new PostDomOnlyViewer();
254 }
FunctionPass * createDomOnlyViewerPass()
Definition: DomPrinter.cpp:236
void initializeDomViewerPass(PassRegistry &)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
FunctionPass * createPostDomPrinterPass()
Definition: DomPrinter.cpp:240
void Print(const Unit &U, const char *PrintAfter="")
Definition: FuzzerUtil.cpp:23
void initializePostDomViewerPass(PassRegistry &)
void initializePostDomOnlyViewerPass(PassRegistry &)
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:111
void initializeDomOnlyPrinterPass(PassRegistry &)
FunctionPass * createDomViewerPass()
Definition: DomPrinter.cpp:232
void initializePostDomPrinterPass(PassRegistry &)
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If Reload the main corpus periodically to get new units discovered by other processes Read the given input file
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
DominatorTree & getDomTree()
Definition: Dominators.h:213
#define false
Definition: ConvertUTF.c:65
#define G(x, y, z)
Definition: MD5.cpp:52
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...
Base class for the actual dominator tree node.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:67
#define true
Definition: ConvertUTF.c:66
FunctionPass * createDomPrinterPass()
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
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:147
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:294
static std::string getGraphName(PostDominatorTree *DT)
Definition: DomPrinter.cpp:73
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 &)
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:31
FunctionPass * createDomOnlyPrinterPass()
Definition: DomPrinter.cpp:228
std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G)
Definition: DomPrinter.cpp:77
FunctionPass * createPostDomViewerPass()
Definition: DomPrinter.cpp:248
void initializeDomPrinterPass(PassRegistry &)
NodeT * getBlock() const
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
DomTreeNode * getRootNode() const
FunctionPass * createPostDomOnlyViewerPass()
Definition: DomPrinter.cpp:252
FunctionPass * createPostDomOnlyPrinterPass()
Definition: DomPrinter.cpp:244
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:203