LLVM  14.0.0git
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 #include "llvm/InitializePasses.h"
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())
44  ::getSimpleNodeLabel(BB, nullptr);
45  else
47  ::getCompleteNodeLabel(BB, nullptr);
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) {
62  return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode());
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 ) {
78  return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode());
79  }
80 };
81 }
82 
83 void DominatorTree::viewGraph(const Twine &Name, const Twine &Title) {
84 #ifndef NDEBUG
85  ViewGraph(this, Name, false, Title);
86 #else
87  errs() << "DomTree dump not available, build with DEBUG\n";
88 #endif // NDEBUG
89 }
90 
92 #ifndef NDEBUG
93  this->viewGraph("domtree", "Dominator Tree for function");
94 #else
95  errs() << "DomTree dump not available, build with DEBUG\n";
96 #endif // NDEBUG
97 }
98 
99 namespace {
100 struct DominatorTreeWrapperPassAnalysisGraphTraits {
101  static DominatorTree *getGraph(DominatorTreeWrapperPass *DTWP) {
102  return &DTWP->getDomTree();
103  }
104 };
105 
106 struct DomViewer : public DOTGraphTraitsViewer<
107  DominatorTreeWrapperPass, false, DominatorTree *,
108  DominatorTreeWrapperPassAnalysisGraphTraits> {
109  static char ID;
110  DomViewer()
112  DominatorTreeWrapperPassAnalysisGraphTraits>(
113  "dom", ID) {
115  }
116 };
117 
118 struct DomOnlyViewer : public DOTGraphTraitsViewer<
119  DominatorTreeWrapperPass, true, DominatorTree *,
120  DominatorTreeWrapperPassAnalysisGraphTraits> {
121  static char ID;
122  DomOnlyViewer()
124  DominatorTreeWrapperPassAnalysisGraphTraits>(
125  "domonly", ID) {
127  }
128 };
129 
130 struct PostDominatorTreeWrapperPassAnalysisGraphTraits {
131  static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
132  return &PDTWP->getPostDomTree();
133  }
134 };
135 
136 struct PostDomViewer : public DOTGraphTraitsViewer<
137  PostDominatorTreeWrapperPass, false,
138  PostDominatorTree *,
139  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
140  static char ID;
141  PostDomViewer() :
144  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
145  "postdom", ID){
147  }
148 };
149 
150 struct PostDomOnlyViewer : public DOTGraphTraitsViewer<
151  PostDominatorTreeWrapperPass, true,
152  PostDominatorTree *,
153  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
154  static char ID;
155  PostDomOnlyViewer() :
158  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
159  "postdomonly", ID){
161  }
162 };
163 } // end anonymous namespace
164 
165 char DomViewer::ID = 0;
166 INITIALIZE_PASS(DomViewer, "view-dom",
167  "View dominance tree of function", false, false)
168 
169 char DomOnlyViewer::ID = 0;
170 INITIALIZE_PASS(DomOnlyViewer, "view-dom-only",
171  "View dominance tree of function (with no function bodies)",
172  false, false)
173 
174 char PostDomViewer::ID = 0;
175 INITIALIZE_PASS(PostDomViewer, "view-postdom",
176  "View postdominance tree of function", false, false)
177 
178 char PostDomOnlyViewer::ID = 0;
179 INITIALIZE_PASS(PostDomOnlyViewer, "view-postdom-only",
180  "View postdominance tree of function "
181  "(with no function bodies)",
182  false, false)
183 
184 namespace {
185 struct DomPrinter : public DOTGraphTraitsPrinter<
186  DominatorTreeWrapperPass, false, DominatorTree *,
187  DominatorTreeWrapperPassAnalysisGraphTraits> {
188  static char ID;
189  DomPrinter()
191  DominatorTreeWrapperPassAnalysisGraphTraits>(
192  "dom", ID) {
194  }
195 };
196 
197 struct DomOnlyPrinter : public DOTGraphTraitsPrinter<
198  DominatorTreeWrapperPass, true, DominatorTree *,
199  DominatorTreeWrapperPassAnalysisGraphTraits> {
200  static char ID;
201  DomOnlyPrinter()
203  DominatorTreeWrapperPassAnalysisGraphTraits>(
204  "domonly", ID) {
206  }
207 };
208 
209 struct PostDomPrinter
210  : public DOTGraphTraitsPrinter<
211  PostDominatorTreeWrapperPass, false,
212  PostDominatorTree *,
213  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
214  static char ID;
215  PostDomPrinter() :
218  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
219  "postdom", ID) {
221  }
222 };
223 
224 struct PostDomOnlyPrinter
225  : public DOTGraphTraitsPrinter<
226  PostDominatorTreeWrapperPass, true,
227  PostDominatorTree *,
228  PostDominatorTreeWrapperPassAnalysisGraphTraits> {
229  static char ID;
230  PostDomOnlyPrinter() :
233  PostDominatorTreeWrapperPassAnalysisGraphTraits>(
234  "postdomonly", ID) {
236  }
237 };
238 } // end anonymous namespace
239 
240 
241 
242 char DomPrinter::ID = 0;
243 INITIALIZE_PASS(DomPrinter, "dot-dom",
244  "Print dominance tree of function to 'dot' file",
245  false, false)
246 
247 char DomOnlyPrinter::ID = 0;
248 INITIALIZE_PASS(DomOnlyPrinter, "dot-dom-only",
249  "Print dominance tree of function to 'dot' file "
250  "(with no function bodies)",
251  false, false)
252 
253 char PostDomPrinter::ID = 0;
254 INITIALIZE_PASS(PostDomPrinter, "dot-postdom",
255  "Print postdominance tree of function to 'dot' file",
256  false, false)
257 
258 char PostDomOnlyPrinter::ID = 0;
259 INITIALIZE_PASS(PostDomOnlyPrinter, "dot-postdom-only",
260  "Print postdominance tree of function to 'dot' file "
261  "(with no function bodies)",
262  false, false)
263 
264 // Create methods available outside of this file, to use them
265 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
266 // the link time optimization.
267 
269  return new DomPrinter();
270 }
271 
273  return new DomOnlyPrinter();
274 }
275 
277  return new DomViewer();
278 }
279 
281  return new DomOnlyViewer();
282 }
283 
285  return new PostDomPrinter();
286 }
287 
289  return new PostDomOnlyPrinter();
290 }
291 
293  return new PostDomViewer();
294 }
295 
297  return new PostDomOnlyViewer();
298 }
INITIALIZE_PASS
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:179
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::initializeDomPrinterPass
void initializeDomPrinterPass(PassRegistry &)
llvm::DOTGraphTraits< DomTreeNode * >::getNodeLabel
std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph)
Definition: DomPrinter.cpp:34
llvm::initializeDomOnlyPrinterPass
void initializeDomOnlyPrinterPass(PassRegistry &)
llvm::DOTGraphTraits< PostDominatorTree * >::getNodeLabel
std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G)
Definition: DomPrinter.cpp:77
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
to
Should compile to
Definition: README.txt:449
llvm::createPostDomOnlyViewerPass
FunctionPass * createPostDomOnlyViewerPass()
Definition: DomPrinter.cpp:296
llvm::initializePostDomOnlyPrinterPass
void initializePostDomOnlyPrinterPass(PassRegistry &)
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::ViewGraph
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, then cleanup.
Definition: GraphWriter.h:375
llvm::initializeDomOnlyViewerPass
void initializeDomOnlyViewerPass(PassRegistry &)
llvm::createPostDomViewerPass
FunctionPass * createPostDomViewerPass()
Definition: DomPrinter.cpp:292
llvm::DOTGraphTraitsViewer
Definition: DOTGraphTraitsPass.h:31
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::DOTGraphTraits< DomTreeNode * >
Definition: DomPrinter.cpp:29
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
PostDominators.h
llvm::DOTGraphTraitsPrinter
Definition: DOTGraphTraitsPass.h:73
llvm::PostDominatorTreeWrapperPass
Definition: PostDominators.h:73
llvm::initializeDomViewerPass
void initializeDomViewerPass(PassRegistry &)
false
Definition: StackSlotColoring.cpp:142
llvm::DOTGraphTraits< DominatorTree * >::getGraphName
static std::string getGraphName(DominatorTree *DT)
Definition: DomPrinter.cpp:57
llvm::createPostDomPrinterPass
FunctionPass * createPostDomPrinterPass()
Definition: DomPrinter.cpp:284
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:287
only
dot regions only
Definition: RegionPrinter.cpp:205
llvm::DOTGraphTraits
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
Definition: DOTGraphTraits.h:161
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::DOTGraphTraits< DomTreeNode * >::DOTGraphTraits
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:31
file
dot regions Print regions of function to dot file(with no function bodies)"
llvm::createDomOnlyPrinterPass
FunctionPass * createDomOnlyPrinterPass()
Definition: DomPrinter.cpp:272
DomPrinter.h
llvm::initializePostDomOnlyViewerPass
void initializePostDomOnlyViewerPass(PassRegistry &)
llvm::createDomOnlyViewerPass
FunctionPass * createDomOnlyViewerPass()
Definition: DomPrinter.cpp:280
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
llvm::DOTGraphTraits< DominatorTree * >::DOTGraphTraits
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:54
llvm::initializePostDomPrinterPass
void initializePostDomPrinterPass(PassRegistry &)
llvm::PostDominatorTreeWrapperPass::getPostDomTree
PostDominatorTree & getPostDomTree()
Definition: PostDominators.h:80
llvm::PostDominatorTree
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
Definition: PostDominators.h:28
llvm::DomTreeNodeBase< BasicBlock >
llvm::DominatorTree::viewGraph
void viewGraph()
Definition: DomPrinter.cpp:91
llvm::createPostDomOnlyPrinterPass
FunctionPass * createPostDomOnlyPrinterPass()
Definition: DomPrinter.cpp:288
llvm::tgtok::dot
@ dot
Definition: TGLexer.h:43
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::initializePostDomViewerPass
void initializePostDomViewerPass(PassRegistry &)
DOTGraphTraitsPass.h
llvm::DominatorTreeWrapperPass::getDomTree
DominatorTree & getDomTree()
Definition: Dominators.h:295
isSimple
static bool isSimple(Instruction *I)
Definition: SLPVectorizer.cpp:528
llvm::DOTGraphTraits< PostDominatorTree * >::DOTGraphTraits
DOTGraphTraits(bool isSimple=false)
Definition: DomPrinter.cpp:70
llvm::createDomViewerPass
FunctionPass * createDomViewerPass()
Definition: DomPrinter.cpp:276
llvm::DOTGraphTraits< PostDominatorTree * >::getGraphName
static std::string getGraphName(PostDominatorTree *DT)
Definition: DomPrinter.cpp:73
llvm::createDomPrinterPass
FunctionPass * createDomPrinterPass()
llvm::DefaultDOTGraphTraits::getNodeLabel
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...
Definition: DOTGraphTraits.h:71
llvm::DefaultDOTGraphTraits
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
Definition: DOTGraphTraits.h:28
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
InitializePasses.h
llvm::DOTGraphTraits< DominatorTree * >::getNodeLabel
std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G)
Definition: DomPrinter.cpp:61
of
Add support for conditional and other related patterns Instead of
Definition: README.txt:134
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
INITIALIZE_PASS
TargetPassConfig.
Definition: TargetPassConfig.cpp:359