LLVM  8.0.1
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 {
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 CallGraphDOTPrinter : public DOTGraphTraitsModulePrinter<
62  CallGraphWrapperPass, true, CallGraph *,
63  AnalysisCallGraphWrapperPassTraits> {
64  static char ID;
65 
66  CallGraphDOTPrinter()
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 
81 INITIALIZE_PASS(CallGraphDOTPrinter, "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 CallGraphDOTPrinter();
92 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:24
INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false, false) char CallGraphDOTPrinter INITIALIZE_PASS(CallGraphDOTPrinter, "dot-callgraph", "Print call graph to 'dot' file", false, false) ModulePass *llvm
Definition: CallPrinter.cpp:81
A node in the call graph for a module.
Definition: CallGraph.h:165
ModulePass * createCallGraphDOTPrinterPass()
Definition: CallPrinter.cpp:90
static bool isSimple(Instruction *I)
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)
void initializeCallGraphViewerPass(PassRegistry &)
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:324
std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph)
Definition: CallPrinter.cpp:30
void initializeCallGraphDOTPrinterPass(PassRegistry &)
const CallGraph & getCallGraph() const
The internal CallGraph around which the rest of this interface is wrapped.
Definition: CallGraph.h:335
Function * getFunction() const
Returns the function that this call graph node represents.
Definition: CallGraph.h:188
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to &#39;dot...
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:74
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:225
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
static CallGraph * getGraph(CallGraphWrapperPass *P)
Definition: CallPrinter.cpp:39
ModulePass * createCallGraphViewerPass()