LLVM 17.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
24
25using namespace llvm;
26
27
28void 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
44namespace {
45struct LegacyDominatorTreeWrapperPassAnalysisGraphTraits {
46 static DominatorTree *getGraph(DominatorTreeWrapperPass *DTWP) {
47 return &DTWP->getDomTree();
48 }
49};
50
51struct DomViewerWrapperPass
53 DominatorTreeWrapperPass, false, DominatorTree *,
54 LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
55 static char ID;
56 DomViewerWrapperPass()
59 LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("dom", ID) {
61 }
62};
63
64struct DomOnlyViewerWrapperPass
66 DominatorTreeWrapperPass, true, DominatorTree *,
67 LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
68 static char ID;
69 DomOnlyViewerWrapperPass()
72 LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("domonly", ID) {
74 }
75};
76
77struct LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits {
78 static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
79 return &PDTWP->getPostDomTree();
80 }
81};
82
83struct PostDomViewerWrapperPass
85 PostDominatorTreeWrapperPass, false, PostDominatorTree *,
86 LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits> {
87 static char ID;
88 PostDomViewerWrapperPass()
91 LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits>("postdom",
92 ID) {
94 }
95};
96
97struct 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
113char DomViewerWrapperPass::ID = 0;
114INITIALIZE_PASS(DomViewerWrapperPass, "view-dom",
115 "View dominance tree of function", false, false)
116
117char DomOnlyViewerWrapperPass::ID = 0;
118INITIALIZE_PASS(DomOnlyViewerWrapperPass, "view-dom-only",
119 "View dominance tree of function (with no function bodies)",
120 false, false)
121
122char PostDomViewerWrapperPass::ID = 0;
123INITIALIZE_PASS(PostDomViewerWrapperPass, "view-postdom",
124 "View postdominance tree of function", false, false)
125
126char PostDomOnlyViewerWrapperPass::ID = 0;
127INITIALIZE_PASS(PostDomOnlyViewerWrapperPass, "view-postdom-only",
128 "View postdominance tree of function "
129 "(with no function bodies)",
130 false, false)
131
132namespace {
133struct DomPrinterWrapperPass
135 DominatorTreeWrapperPass, false, DominatorTree *,
136 LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
137 static char ID;
138 DomPrinterWrapperPass()
141 LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("dom", ID) {
143 }
144};
145
146struct DomOnlyPrinterWrapperPass
148 DominatorTreeWrapperPass, true, DominatorTree *,
149 LegacyDominatorTreeWrapperPassAnalysisGraphTraits> {
150 static char ID;
151 DomOnlyPrinterWrapperPass()
154 LegacyDominatorTreeWrapperPassAnalysisGraphTraits>("domonly", ID) {
156 }
157};
158
159struct PostDomPrinterWrapperPass
161 PostDominatorTreeWrapperPass, false, PostDominatorTree *,
162 LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits> {
163 static char ID;
164 PostDomPrinterWrapperPass()
167 LegacyPostDominatorTreeWrapperPassAnalysisGraphTraits>("postdom",
168 ID) {
170 }
171};
172
173struct 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
189char DomPrinterWrapperPass::ID = 0;
190INITIALIZE_PASS(DomPrinterWrapperPass, "dot-dom",
191 "Print dominance tree of function to 'dot' file", false, false)
192
193char DomOnlyPrinterWrapperPass::ID = 0;
194INITIALIZE_PASS(DomOnlyPrinterWrapperPass, "dot-dom-only",
195 "Print dominance tree of function to 'dot' file "
196 "(with no function bodies)",
197 false, false)
198
199char PostDomPrinterWrapperPass::ID = 0;
200INITIALIZE_PASS(PostDomPrinterWrapperPass, "dot-postdom",
201 "Print postdominance tree of function to 'dot' file", false,
202 false)
203
204char PostDomOnlyPrinterWrapperPass::ID = 0;
205INITIALIZE_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}
basic Basic Alias true
std::string Name
print Print MemDeps of function
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
dot regions only
dot regions Print regions of function to dot file(with no function bodies)"
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:314
DominatorTree & getDomTree()
Definition: Dominators.h:322
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
TargetPassConfig.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createDomOnlyPrinterWrapperPassPass()
Definition: DomPrinter.cpp:218
FunctionPass * createPostDomOnlyViewerWrapperPassPass()
Definition: DomPrinter.cpp:242
void initializeDomPrinterWrapperPassPass(PassRegistry &)
void initializePostDomViewerWrapperPassPass(PassRegistry &)
FunctionPass * createPostDomViewerWrapperPassPass()
Definition: DomPrinter.cpp:238
FunctionPass * createPostDomOnlyPrinterWrapperPassPass()
Definition: DomPrinter.cpp:234
void initializeDomViewerWrapperPassPass(PassRegistry &)
void initializePostDomOnlyPrinterWrapperPassPass(PassRegistry &)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void initializeDomOnlyPrinterWrapperPassPass(PassRegistry &)
FunctionPass * createDomOnlyViewerWrapperPassPass()
Definition: DomPrinter.cpp:226
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
void initializePostDomPrinterWrapperPassPass(PassRegistry &)
void initializeDomOnlyViewerWrapperPassPass(PassRegistry &)
FunctionPass * createPostDomPrinterWrapperPassPass()
Definition: DomPrinter.cpp:230
FunctionPass * createDomPrinterWrapperPassPass()
FunctionPass * createDomViewerWrapperPassPass()
Definition: DomPrinter.cpp:222
void initializePostDomOnlyViewerWrapperPassPass(PassRegistry &)
PostDominatorTree & getPostDomTree()