LLVM  15.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 
28 void DominatorTree::viewGraph(const Twine &Name, const Twine &Title) {
29 #ifndef NDEBUG
30  ViewGraph(this, Name, false, Title);
31 #else
32  errs() << "DomTree dump not available, build with DEBUG\n";
33 #endif // NDEBUG
34 }
35 
37 #ifndef NDEBUG
38  this->viewGraph("domtree", "Dominator Tree for function");
39 #else
40  errs() << "DomTree dump not available, build with DEBUG\n";
41 #endif // NDEBUG
42 }
43 
44 namespace {
45 struct LegacyDominatorTreeWrapperPassAnalysisGraphTraits {
46  static DominatorTree *getGraph(DominatorTreeWrapperPass *DTWP) {
47  return &DTWP->getDomTree();
48  }
49 };
50 
51 struct DomViewerWrapperPass
53  DominatorTreeWrapperPass, false, DominatorTree *,
54  LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
55  static char ID;
56  DomViewerWrapperPass()
59  LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("dom", ID) {
61  }
62 };
63 
64 struct DomOnlyViewerWrapperPass
66  DominatorTreeWrapperPass, true, DominatorTree *,
67  LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
68  static char ID;
69  DomOnlyViewerWrapperPass()
72  LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("domonly", ID) {
74  }
75 };
76 
77 struct LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits {
78  static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
79  return &PDTWP->getPostDomTree();
80  }
81 };
82 
83 struct PostDomViewerWrapperPass
85  PostDominatorTreeWrapperPass, false, PostDominatorTree *,
86  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits> {
87  static char ID;
88  PostDomViewerWrapperPass()
91  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits>("postdom",
92  ID) {
94  }
95 };
96 
97 struct PostDomOnlyViewerWrapperPass
99  PostDominatorTreeWrapperPass, true, PostDominatorTree *,
100  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits> {
101  static char ID;
102  PostDomOnlyViewerWrapperPass()
105  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits>(
106  "postdomonly", ID) {
109  }
110 };
111 } // end anonymous namespace
112 
113 char DomViewerWrapperPass::ID = 0;
114 INITIALIZE_PASS(DomViewerWrapperPass, "view-dom",
115  "View dominance tree of function", false, false)
116 
117 char DomOnlyViewerWrapperPass::ID = 0;
118 INITIALIZE_PASS(DomOnlyViewerWrapperPass, "view-dom-only",
119  "View dominance tree of function (with no function bodies)",
120  false, false)
121 
122 char PostDomViewerWrapperPass::ID = 0;
123 INITIALIZE_PASS(PostDomViewerWrapperPass, "view-postdom",
124  "View postdominance tree of function", false, false)
125 
126 char PostDomOnlyViewerWrapperPass::ID = 0;
127 INITIALIZE_PASS(PostDomOnlyViewerWrapperPass, "view-postdom-only",
128  "View postdominance tree of function "
129  "(with no function bodies)",
130  false, false)
131 
132 namespace {
133 struct DomPrinterWrapperPass
135  DominatorTreeWrapperPass, false, DominatorTree *,
136  LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
137  static char ID;
138  DomPrinterWrapperPass()
141  LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("dom", ID) {
143  }
144 };
145 
146 struct DomOnlyPrinterWrapperPass
148  DominatorTreeWrapperPass, true, DominatorTree *,
149  LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
150  static char ID;
151  DomOnlyPrinterWrapperPass()
154  LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("domonly", ID) {
156  }
157 };
158 
159 struct PostDomPrinterWrapperPass
161  PostDominatorTreeWrapperPass, false, PostDominatorTree *,
162  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits> {
163  static char ID;
164  PostDomPrinterWrapperPass()
167  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits>("postdom",
168  ID) {
170  }
171 };
172 
173 struct PostDomOnlyPrinterWrapperPass
175  PostDominatorTreeWrapperPass, true, PostDominatorTree *,
176  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits> {
177  static char ID;
178  PostDomOnlyPrinterWrapperPass()
181  LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits>(
182  "postdomonly", ID) {
185  }
186 };
187 } // end anonymous namespace
188 
190 INITIALIZE_PASS(DomPrinterWrapperPass, "dot-dom",
191  "Print dominance tree of function to 'dot' file", false, false)
192 
193 char DomOnlyPrinterWrapperPass::ID = 0;
194 INITIALIZE_PASS(DomOnlyPrinterWrapperPass, "dot-dom-only",
195  "Print dominance tree of function to 'dot' file "
196  "(with no function bodies)",
197  false, false)
198 
199 char PostDomPrinterWrapperPass::ID = 0;
200 INITIALIZE_PASS(PostDomPrinterWrapperPass, "dot-postdom",
201  "Print postdominance tree of function to 'dot' file", false,
202  false)
203 
204 char PostDomOnlyPrinterWrapperPass::ID = 0;
205 INITIALIZE_PASS(PostDomOnlyPrinterWrapperPass, "dot-postdom-only",
206  "Print postdominance tree of function to 'dot' file "
207  "(with no function bodies)",
208  false, false)
209 
210 // Create methods available outside of this file, to use them
211 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
212 // the link time optimization.
213 
215  return new DomPrinterWrapperPass();
216 }
217 
219  return new DomOnlyPrinterWrapperPass();
220 }
221 
223  return new DomViewerWrapperPass();
224 }
225 
227  return new DomOnlyViewerWrapperPass();
228 }
229 
231  return new PostDomPrinterWrapperPass();
232 }
233 
235  return new PostDomOnlyPrinterWrapperPass();
236 }
237 
239  return new PostDomViewerWrapperPass();
240 }
241 
243  return new PostDomOnlyViewerWrapperPass();
244 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::createPostDomOnlyPrinterWrapperPassPass
FunctionPass * createPostDomOnlyPrinterWrapperPassPass()
Definition: DomPrinter.cpp:234
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
to
Should compile to
Definition: README.txt:449
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1909
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
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:427
llvm::createPostDomPrinterWrapperPassPass
FunctionPass * createPostDomPrinterWrapperPassPass()
Definition: DomPrinter.cpp:230
llvm::initializePostDomViewerWrapperPassPass
void initializePostDomViewerWrapperPassPass(PassRegistry &)
llvm::initializePostDomPrinterWrapperPassPass
void initializePostDomPrinterWrapperPassPass(PassRegistry &)
llvm::createDomViewerWrapperPassPass
FunctionPass * createDomViewerWrapperPassPass()
Definition: DomPrinter.cpp:222
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::initializePostDomOnlyPrinterWrapperPassPass
void initializePostDomOnlyPrinterWrapperPassPass(PassRegistry &)
llvm::PostDominatorTreeWrapperPass
Definition: PostDominators.h:73
false
Definition: StackSlotColoring.cpp:141
llvm::createDomOnlyPrinterWrapperPassPass
FunctionPass * createDomOnlyPrinterWrapperPassPass()
Definition: DomPrinter.cpp:218
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:302
only
dot regions only
Definition: RegionPrinter.cpp:194
llvm::createPostDomViewerWrapperPassPass
FunctionPass * createPostDomViewerWrapperPassPass()
Definition: DomPrinter.cpp:238
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::initializeDomOnlyPrinterWrapperPassPass
void initializeDomOnlyPrinterWrapperPassPass(PassRegistry &)
llvm::initializePostDomOnlyViewerWrapperPassPass
void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &)
file
dot regions Print regions of function to dot file(with no function bodies)"
INITIALIZE_PASS
INITIALIZE_PASS(DomViewerWrapperPass, "view-dom", "View dominance tree of function", false, false) char DomOnlyViewerWrapperPass INITIALIZE_PASS(DomOnlyViewerWrapperPass, "view-dom-only", "View dominance tree of function (with no function bodies)", false, false) char PostDomViewerWrapperPass INITIALIZE_PASS(PostDomViewerWrapperPass, "view-postdom", "View postdominance tree of function", false, false) char PostDomOnlyViewerWrapperPass INITIALIZE_PASS(PostDomOnlyViewerWrapperPass, "view-postdom-only", "View postdominance tree of function " "(with no function bodies)", false, false) namespace
Definition: DomPrinter.cpp:127
llvm::initializeDomViewerWrapperPassPass
void initializeDomViewerWrapperPassPass(PassRegistry &)
DomPrinter.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::initializeDomOnlyViewerWrapperPassPass
void initializeDomOnlyViewerWrapperPassPass(PassRegistry &)
llvm::createDomPrinterWrapperPassPass
FunctionPass * createDomPrinterWrapperPassPass()
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::DominatorTree::viewGraph
void viewGraph()
Definition: DomPrinter.cpp:36
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:50
DOTGraphTraitsPass.h
llvm::DominatorTreeWrapperPass::getDomTree
DominatorTree & getDomTree()
Definition: Dominators.h:310
llvm::createPostDomOnlyViewerWrapperPassPass
FunctionPass * createPostDomOnlyViewerWrapperPassPass()
Definition: DomPrinter.cpp:242
llvm::initializeDomPrinterWrapperPassPass
void initializeDomPrinterWrapperPassPass(PassRegistry &)
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
llvm::DOTGraphTraitsViewerWrapperPass
Definition: DOTGraphTraitsPass.h:164
InitializePasses.h
llvm::DOTGraphTraitsPrinterWrapperPass
Definition: DOTGraphTraitsPass.h:203
llvm::createDomOnlyViewerWrapperPassPass
FunctionPass * createDomOnlyViewerWrapperPassPass()
Definition: DomPrinter.cpp:226
of
Add support for conditional and other related patterns Instead of
Definition: README.txt:134
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
INITIALIZE_PASS
TargetPassConfig.
Definition: TargetPassConfig.cpp:367