LLVM  3.7.0
CallPrinter.cpp
Go to the documentation of this file.
1 //===- CallPrinter.cpp - DOT printer for call graph -----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines '-dot-callgraph', which emit a callgraph.<fnname>.dot
11 // containing the call graph of a module.
12 //
13 // There is also a pass available to directly call dotty ('-view-callgraph').
14 //
15 //===----------------------------------------------------------------------===//
16 
20 
21 using namespace llvm;
22 
23 namespace llvm {
24 
25 template <> struct DOTGraphTraits<CallGraph *> : public DefaultDOTGraphTraits {
26  DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
27 
28  static std::string getGraphName(CallGraph *Graph) { return "Call graph"; }
29 
30  std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
31  if (Function *Func = Node->getFunction())
32  return Func->getName();
33 
34  return "external node";
35  }
36 };
37 
40  return &P->getCallGraph();
41  }
42 };
43 
44 } // end llvm namespace
45 
46 namespace {
47 
48 struct CallGraphViewer
49  : public DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
50  AnalysisCallGraphWrapperPassTraits> {
51  static char ID;
52 
53  CallGraphViewer()
56  "callgraph", ID) {
58  }
59 };
60 
61 struct CallGraphPrinter : public DOTGraphTraitsModulePrinter<
62  CallGraphWrapperPass, true, CallGraph *,
63  AnalysisCallGraphWrapperPassTraits> {
64  static char ID;
65 
66  CallGraphPrinter()
69  "callgraph", ID) {
71  }
72 };
73 
74 } // end anonymous namespace
75 
76 char CallGraphViewer::ID = 0;
77 INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false,
78  false)
79 
80 char CallGraphPrinter::ID = 0;
81 INITIALIZE_PASS(CallGraphPrinter, "dot-callgraph",
82  "Print call graph to 'dot' file", false, false)
83 
84 // Create methods available outside of this file, to use them
85 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
86 // the link time optimization.
87 
88 ModulePass *llvm::createCallGraphViewerPass() { return new CallGraphViewer(); }
89 
91  return new CallGraphPrinter();
92 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void Print(const Unit &U, const char *PrintAfter="")
Definition: FuzzerUtil.cpp:23
A node in the call graph for a module.
Definition: CallGraph.h:166
Function * getFunction() const
Returns the function that this call graph node represents.
Definition: CallGraph.h:186
void initializeCallGraphPrinterPass(PassRegistry &)
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If Reload the main corpus periodically to get new units discovered by other processes Read the given input file
#define false
Definition: ConvertUTF.c:65
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
DOTGraphTraits(bool isSimple=false)
Definition: CallPrinter.cpp:26
static std::string getGraphName(CallGraph *Graph)
Definition: CallPrinter.cpp:28
#define P(N)
#define true
Definition: ConvertUTF.c:66
void initializeCallGraphViewerPass(PassRegistry &)
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:316
std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph)
Definition: CallPrinter.cpp:30
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:75
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:236
const CallGraph & getCallGraph() const
The internal CallGraph around which the rest of this interface is wrapped.
Definition: CallGraph.h:327
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
ModulePass * createCallGraphPrinterPass()
Definition: CallPrinter.cpp:90
INITIALIZE_PASS(CallGraphViewer,"view-callgraph","View call graph", false, false) char CallGraphPrinter INITIALIZE_PASS(CallGraphPrinter,"dot-callgraph","Print call graph to 'dot' file", false, false) ModulePass *llvm
Definition: CallPrinter.cpp:81
static CallGraph * getGraph(CallGraphWrapperPass *P)
Definition: CallPrinter.cpp:39
ModulePass * createCallGraphViewerPass()