LLVM  10.0.0svn
CallPrinter.cpp
Go to the documentation of this file.
1 //===- CallPrinter.cpp - DOT printer for call graph -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines '-dot-callgraph', which emit a callgraph.<fnname>.dot
10 // containing the call graph of a module.
11 //
12 // There is also a pass available to directly call dotty ('-view-callgraph').
13 //
14 //===----------------------------------------------------------------------===//
15 
19 
20 using namespace llvm;
21 
22 namespace llvm {
23 
24 template <> struct DOTGraphTraits<CallGraph *> : public DefaultDOTGraphTraits {
26 
27  static std::string getGraphName(CallGraph *Graph) { return "Call graph"; }
28 
29  std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
30  if (Function *Func = Node->getFunction())
31  return Func->getName();
32 
33  return "external node";
34  }
35 };
36 
39  return &P->getCallGraph();
40  }
41 };
42 
43 } // end llvm namespace
44 
45 namespace {
46 
47 struct CallGraphViewer
48  : public DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
49  AnalysisCallGraphWrapperPassTraits> {
50  static char ID;
51 
52  CallGraphViewer()
55  "callgraph", ID) {
57  }
58 };
59 
60 struct CallGraphDOTPrinter : public DOTGraphTraitsModulePrinter<
61  CallGraphWrapperPass, true, CallGraph *,
62  AnalysisCallGraphWrapperPassTraits> {
63  static char ID;
64 
65  CallGraphDOTPrinter()
68  "callgraph", ID) {
70  }
71 };
72 
73 } // end anonymous namespace
74 
75 char CallGraphViewer::ID = 0;
76 INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false,
77  false)
78 
80 INITIALIZE_PASS(CallGraphDOTPrinter, "dot-callgraph",
81  "Print call graph to 'dot' file", false, false)
82 
83 // Create methods available outside of this file, to use them
84 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
85 // the link time optimization.
86 
87 ModulePass *llvm::createCallGraphViewerPass() { return new CallGraphViewer(); }
88 
90  return new CallGraphDOTPrinter();
91 }
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:23
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:80
A node in the call graph for a module.
Definition: CallGraph.h:164
ModulePass * createCallGraphDOTPrinterPass()
Definition: CallPrinter.cpp:89
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:25
static std::string getGraphName(CallGraph *Graph)
Definition: CallPrinter.cpp:27
#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:29
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:187
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:73
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
static CallGraph * getGraph(CallGraphWrapperPass *P)
Definition: CallPrinter.cpp:38
ModulePass * createCallGraphViewerPass()