LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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<>
27  DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
28 
29  static std::string getGraphName(CallGraph *Graph) {
30  return "Call graph";
31  }
32 
33  std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
34  if (Function *Func = Node->getFunction())
35  return Func->getName();
36 
37  return "external node";
38  }
39 };
40 
41 } // end llvm namespace
42 
43 namespace {
44 
45 struct CallGraphViewer
46  : public DOTGraphTraitsModuleViewer<CallGraph, true> {
47  static char ID;
48 
49  CallGraphViewer()
50  : DOTGraphTraitsModuleViewer<CallGraph, true>("callgraph", ID) {
52  }
53 };
54 
55 struct CallGraphPrinter
56  : public DOTGraphTraitsModulePrinter<CallGraph, true> {
57  static char ID;
58 
59  CallGraphPrinter()
60  : DOTGraphTraitsModulePrinter<CallGraph, true>("callgraph", ID) {
62  }
63 };
64 
65 } // end anonymous namespace
66 
67 char CallGraphViewer::ID = 0;
68 INITIALIZE_PASS(CallGraphViewer, "view-callgraph",
69  "View call graph",
70  false, false)
71 
72 char CallGraphPrinter::ID = 0;
73 INITIALIZE_PASS(CallGraphPrinter, "dot-callgraph",
74  "Print call graph to 'dot' file",
75  false, false)
76 
77 // Create methods available outside of this file, to use them
78 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
79 // the link time optimization.
80 
82  return new CallGraphViewer();
83 }
84 
86  return new CallGraphPrinter();
87 }
static PassRegistry * getPassRegistry()
Function * getFunction() const
Definition: CallGraph.h:212
void initializeCallGraphPrinterPass(PassRegistry &)
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
#define false
Definition: ConvertUTF.c:64
DOTGraphTraits(bool isSimple=false)
Definition: CallPrinter.cpp:27
static std::string getGraphName(CallGraph *Graph)
Definition: CallPrinter.cpp:29
#define true
Definition: ConvertUTF.c:65
void initializeCallGraphViewerPass(PassRegistry &)
std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph)
Definition: CallPrinter.cpp:33
ModulePass * createCallGraphPrinterPass()
Definition: CallPrinter.cpp:85
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:73
ModulePass * createCallGraphViewerPass()