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();
101template <
typename GraphT>
104 std::string Filename =
Name.str() +
"." +
F.getName().str();
106 Filename = Filename +
".dot";
109 errs() <<
"Writing '" << Filename <<
"'...";
116 GraphName +
" for '" +
F.getName() +
"' function");
118 errs() <<
" error opening file for writing!";
122template <
typename AnalysisT,
bool IsSimple,
123 typename GraphT =
typename AnalysisT::Result *,
124 typename AnalysisGraphTraitsT =
125 DefaultAnalysisGraphTraits<typename AnalysisT::Result &, GraphT>>
127 :
PassInfoMixin<DOTGraphTraitsPrinter<AnalysisT, IsSimple, GraphT,
128 AnalysisGraphTraitsT>> {
138 const typename AnalysisT::Result &Result) {
143 auto &Result =
FAM.getResult<AnalysisT>(
F);
147 GraphT Graph = AnalysisGraphTraitsT::getGraph(Result);
173template <
typename AnalysisT,
typename GraphT = AnalysisT *>
178template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
179 typename AnalysisGraphTraitsT =
180 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
197 auto &
Analysis = getAnalysis<AnalysisT>();
202 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
217template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
218 typename AnalysisGraphTraitsT =
219 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
236 auto &
Analysis = getAnalysis<AnalysisT>();
241 GraphT Graph = AnalysisGraphTraitsT::getGraph(&
Analysis);
256template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
257 typename AnalysisGraphTraitsT =
258 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
265 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
282template <
typename AnalysisT,
bool IsSimple,
typename GraphT = AnalysisT *,
283 typename AnalysisGraphTraitsT =
284 LegacyDefaultAnalysisGraphTraits<AnalysisT, GraphT>>
291 GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
293 std::string Filename = Name +
".dot";
296 errs() <<
"Writing '" << Filename <<
"'...";
304 errs() <<
" error opening file for writing!";
319template <
typename GraphT>
321 std::string FileNamePrefix,
bool IsSimple) {
322 std::string Filename = FileNamePrefix +
"." +
F.getName().str();
324 Filename = Filename +
".dot";
327 errs() <<
"Writing '" << Filename <<
"'...";
331 std::string Title = GraphName +
" for '" +
F.getName().str() +
"' function";
336 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.