13#ifndef LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
14#define LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
25template <
typename Result,
typename GraphT = Result *>
27 static GraphT
getGraph(Result R) {
return &R; }
30template <
typename GraphT>
36 GraphName +
" for '" +
F.getName() +
"' function");
39template <
typename AnalysisT,
bool IsSimple,
40 typename GraphT =
typename AnalysisT::Result *,
41 typename AnalysisGraphTraitsT =
42 DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
44 :
PassInfoMixin<DOTGraphTraitsViewer<AnalysisT, IsSimple, GraphT,
45 AnalysisGraphTraitsT>> {
55 const typename AnalysisT::Result &Result) {
60 auto &Result =
FAM.getResult<AnalysisT>(
F);
64 GraphT Graph = AnalysisGraphTraitsT::getGraph(Result);
86template <
typename GraphT>
89 std::string Filename =
Name.str() +
"." +
F.getName().str() +
".dot";
92 errs() <<
"Writing '" << Filename <<
"'...";
99 GraphName +
" for '" +
F.getName() +
"' function");
101 errs() <<
" error opening file for writing!";
105template <
typename AnalysisT,
bool IsSimple,
106 typename GraphT =
typename AnalysisT::Result *,
107 typename AnalysisGraphTraitsT =
108 DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
110 :
PassInfoMixin<DOTGraphTraitsPrinter<AnalysisT, IsSimple, GraphT,
111 AnalysisGraphTraitsT>> {
121 const typename AnalysisT::Result &Result) {
126 auto &Result =
FAM.getResult<AnalysisT>(
F);
130 GraphT Graph = AnalysisGraphTraitsT::getGraph(Result);
156template <
typename AnalysisT,
typename GraphT = AnalysisT *>
161template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
162 typename AnalysisGraphTraitsT =
163 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
180 auto &
Analysis = getAnalysis<AnalysisT>();
185 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
200template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
201 typename AnalysisGraphTraitsT =
202 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
219 auto &
Analysis = getAnalysis<AnalysisT>();
224 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
239template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
240 typename AnalysisGraphTraitsT =
241 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
248 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
265template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
266 typename AnalysisGraphTraitsT =
267 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
274 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
275 std::string Filename = Name +
".dot";
278 errs() <<
"Writing '" << Filename <<
"'...";
286 errs() <<
" error opening file for writing!";
301template <
typename GraphT>
303 std::string FileNamePrefix,
bool IsSimple) {
304 std::string Filename = FileNamePrefix +
"." +
F.getName().str() +
".dot";
307 errs() <<
"Writing '" << Filename <<
"'...";
311 std::string Title = GraphName +
" for '" +
F.getName().str() +
"' function";
316 errs() <<
" error opening file for writing!";
block Block Frequency Analysis
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
FunctionAnalysisManager FAM
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
DOTGraphTraitsModulePrinterWrapperPass(StringRef GraphName, char &ID)
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
DOTGraphTraitsModuleViewerWrapperPass(StringRef GraphName, char &ID)
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
DOTGraphTraitsPrinterWrapperPass(StringRef GraphName, char &ID)
virtual bool processFunction(Function &F, AnalysisT &Analysis)
Return true if this function should be processed.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
virtual bool processFunction(Function &F, AnalysisT &Analysis)
Return true if this function should be processed.
DOTGraphTraitsViewerWrapperPass(StringRef GraphName, char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
FunctionPass class - This class is used to implement most global optimizations.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
StringRef - Represent a constant reference to a string, i.e.
A raw_ostream that writes to a file descriptor.
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
This is an optimization pass for GlobalISel generic memory operations.
void viewGraphForFunction(Function &F, GraphT Graph, StringRef Name, bool IsSimple)
raw_ostream & WriteGraph(raw_ostream &O, const GraphType &G, bool ShortNames=false, const Twine &Title="")
void WriteDOTGraphToFile(Function &F, GraphT &&Graph, std::string FileNamePrefix, bool IsSimple)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void printGraphForFunction(Function &F, GraphT Graph, StringRef Name, bool IsSimple)
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.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
~DOTGraphTraitsPrinter()
Avoid compiler warning "has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]" in der...
virtual bool processFunction(Function &F, const typename AnalysisT::Result &Result)
Return true if this function should be processed.
DOTGraphTraitsPrinter(StringRef GraphName)
~DOTGraphTraitsViewer()
Avoid compiler warning "has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]" in der...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
DOTGraphTraitsViewer(StringRef GraphName)
virtual bool processFunction(Function &F, const typename AnalysisT::Result &Result)
Return true if this function should be processed.
Default traits class for extracting a graph from an analysis pass.
static GraphT getGraph(Result R)
static std::string getGraphName(const GraphType &)
getGraphName - Return the label for the graph as a whole.
Default traits class for extracting a graph from an analysis pass.
static GraphT getGraph(AnalysisT *A)
A CRTP mix-in to automatically provide informational APIs needed for passes.