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);
91 FN = FN.substr(0, len);
93 auto strLen = FN.length();
96 FN = FN.substr(0, --len);
105template <
typename GraphT>
108 std::string Filename =
Name.str() +
"." +
F.getName().str();
110 Filename = Filename +
".dot";
113 errs() <<
"Writing '" << Filename <<
"'...";
120 GraphName +
" for '" +
F.getName() +
"' function");
122 errs() <<
" error opening file for writing!";
126template <
typename AnalysisT,
bool IsSimple,
127 typename GraphT =
typename AnalysisT::Result *,
128 typename AnalysisGraphTraitsT =
129 DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
131 :
PassInfoMixin<DOTGraphTraitsPrinter<AnalysisT, IsSimple, GraphT,
132 AnalysisGraphTraitsT>> {
142 const typename AnalysisT::Result &Result) {
147 auto &Result =
FAM.getResult<AnalysisT>(
F);
151 GraphT Graph = AnalysisGraphTraitsT::getGraph(Result);
177template <
typename AnalysisT,
typename GraphT = AnalysisT *>
182template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
183 typename AnalysisGraphTraitsT =
184 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
201 auto &
Analysis = getAnalysis<AnalysisT>();
206 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
221template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
222 typename AnalysisGraphTraitsT =
223 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
240 auto &
Analysis = getAnalysis<AnalysisT>();
245 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
260template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
261 typename AnalysisGraphTraitsT =
262 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
269 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
286template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
287 typename AnalysisGraphTraitsT =
288 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
295 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
297 std::string Filename = Name +
".dot";
300 errs() <<
"Writing '" << Filename <<
"'...";
308 errs() <<
" error opening file for writing!";
323template <
typename GraphT>
325 std::string FileNamePrefix,
bool IsSimple) {
326 std::string Filename = FileNamePrefix +
"." +
F.getName().str();
328 Filename = Filename +
".dot";
331 errs() <<
"Writing '" << Filename <<
"'...";
335 std::string Title = GraphName +
" for '" +
F.getName().str() +
"' function";
340 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.