13#ifndef LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
14#define LLVM_ANALYSIS_DOTGRAPHTRAITSPASS_H
19#include <unordered_set>
21static std::unordered_set<std::string>
nameObj;
28template <
typename Result,
typename GraphT = Result *>
30 static GraphT
getGraph(Result R) {
return &R; }
33template <
typename GraphT>
39 GraphName +
" for '" +
F.getName() +
"' function");
42template <
typename AnalysisT,
bool IsSimple,
43 typename GraphT =
typename AnalysisT::Result *,
44 typename AnalysisGraphTraitsT =
45 DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
47 :
PassInfoMixin<DOTGraphTraitsViewer<AnalysisT, IsSimple, GraphT,
48 AnalysisGraphTraitsT>> {
58 const typename AnalysisT::Result &Result) {
63 auto &Result =
FAM.getResult<AnalysisT>(
F);
67 GraphT Graph = AnalysisGraphTraitsT::getGraph(Result);
90 if (FN.length() > len)
92 auto strLen = FN.length();
104template <
typename GraphT>
107 std::string Filename =
Name.str() +
"." +
F.getName().str();
109 Filename = Filename +
".dot";
112 errs() <<
"Writing '" << Filename <<
"'...";
119 GraphName +
" for '" +
F.getName() +
"' function");
121 errs() <<
" error opening file for writing!";
125template <
typename AnalysisT,
bool IsSimple,
126 typename GraphT =
typename AnalysisT::Result *,
127 typename AnalysisGraphTraitsT =
128 DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
130 :
PassInfoMixin<DOTGraphTraitsPrinter<AnalysisT, IsSimple, GraphT,
131 AnalysisGraphTraitsT>> {
141 const typename AnalysisT::Result &Result) {
146 auto &Result =
FAM.getResult<AnalysisT>(
F);
150 GraphT Graph = AnalysisGraphTraitsT::getGraph(Result);
176template <
typename AnalysisT,
typename GraphT = AnalysisT *>
181template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
182 typename AnalysisGraphTraitsT =
183 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
200 auto &
Analysis = getAnalysis<AnalysisT>();
205 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
220template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
221 typename AnalysisGraphTraitsT =
222 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
239 auto &
Analysis = getAnalysis<AnalysisT>();
244 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
259template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
260 typename AnalysisGraphTraitsT =
261 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
268 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
285template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
286 typename AnalysisGraphTraitsT =
287 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
294 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
296 std::string Filename = Name +
".dot";
299 errs() <<
"Writing '" << Filename <<
"'...";
307 errs() <<
" error opening file for writing!";
322template <
typename GraphT>
324 std::string FileNamePrefix,
bool IsSimple) {
325 std::string Filename = FileNamePrefix +
"." +
F.getName().str();
327 Filename = Filename +
".dot";
330 errs() <<
"Writing '" << Filename <<
"'...";
334 std::string Title = GraphName +
" for '" +
F.getName().str() +
"' function";
339 errs() <<
" error opening file for writing!";
block Block Frequency Analysis
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static std::unordered_set< std::string > nameObj
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.
static void shortenFileName(std::string &FN, unsigned char len=250)
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.