LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 DomViewer
85  : public DOTGraphTraitsViewer<DominatorTree, false> {
86  static char ID;
87  DomViewer() : DOTGraphTraitsViewer<DominatorTree, false>("dom", ID){
89  }
90 };
91 
92 struct DomOnlyViewer
93  : public DOTGraphTraitsViewer<DominatorTree, true> {
94  static char ID;
95  DomOnlyViewer() : DOTGraphTraitsViewer<DominatorTree, true>("domonly", ID){
97  }
98 };
99 
100 struct PostDomViewer
101  : public DOTGraphTraitsViewer<PostDominatorTree, false> {
102  static char ID;
103  PostDomViewer() :
106  }
107 };
108 
109 struct PostDomOnlyViewer
110  : public DOTGraphTraitsViewer<PostDominatorTree, true> {
111  static char ID;
112  PostDomOnlyViewer() :
113  DOTGraphTraitsViewer<PostDominatorTree, true>("postdomonly", ID){
115  }
116 };
117 } // end anonymous namespace
118 
119 char DomViewer::ID = 0;
120 INITIALIZE_PASS(DomViewer, "view-dom",
121  "View dominance tree of function", false, false)
122 
123 char DomOnlyViewer::ID = 0;
124 INITIALIZE_PASS(DomOnlyViewer, "view-dom-only",
125  "View dominance tree of function (with no function bodies)",
126  false, false)
127 
128 char PostDomViewer::ID = 0;
129 INITIALIZE_PASS(PostDomViewer, "view-postdom",
130  "View postdominance tree of function", false, false)
131 
132 char PostDomOnlyViewer::ID = 0;
133 INITIALIZE_PASS(PostDomOnlyViewer, "view-postdom-only",
134  "View postdominance tree of function "
135  "(with no function bodies)",
136  false, false)
137 
138 namespace {
139 struct DomPrinter
140  : public DOTGraphTraitsPrinter<DominatorTree, false> {
141  static char ID;
142  DomPrinter() : DOTGraphTraitsPrinter<DominatorTree, false>("dom", ID) {
144  }
145 };
146 
147 struct DomOnlyPrinter
148  : public DOTGraphTraitsPrinter<DominatorTree, true> {
149  static char ID;
150  DomOnlyPrinter() : DOTGraphTraitsPrinter<DominatorTree, true>("domonly", ID) {
152  }
153 };
154 
155 struct PostDomPrinter
156  : public DOTGraphTraitsPrinter<PostDominatorTree, false> {
157  static char ID;
158  PostDomPrinter() :
161  }
162 };
163 
164 struct PostDomOnlyPrinter
165  : public DOTGraphTraitsPrinter<PostDominatorTree, true> {
166  static char ID;
167  PostDomOnlyPrinter() :
170  }
171 };
172 } // end anonymous namespace
173 
174 
175 
176 char DomPrinter::ID = 0;
177 INITIALIZE_PASS(DomPrinter, "dot-dom",
178  "Print dominance tree of function to 'dot' file",
179  false, false)
180 
181 char DomOnlyPrinter::ID = 0;
182 INITIALIZE_PASS(DomOnlyPrinter, "dot-dom-only",
183  "Print dominance tree of function to 'dot' file "
184  "(with no function bodies)",
185  false, false)
186 
187 char PostDomPrinter::ID = 0;
188 INITIALIZE_PASS(PostDomPrinter, "dot-postdom",
189  "Print postdominance tree of function to 'dot' file",
190  false, false)
191 
192 char PostDomOnlyPrinter::ID = 0;
193 INITIALIZE_PASS(PostDomOnlyPrinter, "dot-postdom-only",
194  "Print postdominance tree of function to 'dot' file "
195  "(with no function bodies)",
196  false, false)
197 
198 // Create methods available outside of this file, to use them
199 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
200 // the link time optimization.
201 
203  return new DomPrinter();
204 }
205 
207  return new DomOnlyPrinter();
208 }
209 
211  return new DomViewer();
212 }
213 
215  return new DomOnlyViewer();
216 }
217 
219  return new PostDomPrinter();
220 }
221 
223  return new PostDomOnlyPrinter();
224 }
225 
227  return new PostDomViewer();
228 }
229 
231  return new PostDomOnlyViewer();
232 }
FunctionPass * createDomOnlyViewerPass()
Definition: DomPrinter.cpp:214
void initializeDomViewerPass(PassRegistry &)
static PassRegistry * getPassRegistry()
FunctionPass * createPostDomPrinterPass()
Definition: DomPrinter.cpp:218
void initializePostDomViewerPass(PassRegistry &)
void initializePostDomOnlyViewerPass(PassRegistry &)
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:116
void initializeDomOnlyPrinterPass(PassRegistry &)
FunctionPass * createDomViewerPass()
Definition: DomPrinter.cpp:210
void initializePostDomPrinterPass(PassRegistry &)
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
#define false
Definition: ConvertUTF.c:64
#define G(x, y, z)
Definition: MD5.cpp:52
std::string getNodeLabel(const void *, const GraphType &)
NodeT * getBlock() const
Definition: Dominators.h:82
#define true
Definition: ConvertUTF.c:65
FunctionPass * createDomPrinterPass()
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
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:133
std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G)
Definition: DomPrinter.cpp:61
static std::string getGraphName(PostDominatorTree *DT)
Definition: DomPrinter.cpp:73
std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph)
Definition: DomPrinter.cpp:34
void initializePostDomOnlyPrinterPass(PassRegistry &)
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:31
FunctionPass * createDomOnlyPrinterPass()
Definition: DomPrinter.cpp:206
std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G)
Definition: DomPrinter.cpp:77
DomTreeNode * getRootNode() const
Definition: Dominators.h:768
FunctionPass * createPostDomViewerPass()
Definition: DomPrinter.cpp:226
void initializeDomPrinterPass(PassRegistry &)
DomTreeNode * getRootNode() const
FunctionPass * createPostDomOnlyViewerPass()
Definition: DomPrinter.cpp:230
FunctionPass * createPostDomOnlyPrinterPass()
Definition: DomPrinter.cpp:222
static std::string getGraphName(DominatorTree *DT)
Definition: DomPrinter.cpp:57
print Print MemDeps of function