annotate llvm/lib/Analysis/CallPrinter.cpp @ 220:42394fc6a535

Added tag llvm12 for changeset 0572611fdcc8
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:13:43 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===- CallPrinter.cpp - DOT printer for call graph -----------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // This file defines '-dot-callgraph', which emit a callgraph.<fnname>.dot
anatofuz
parents:
diff changeset
10 // containing the call graph of a module.
anatofuz
parents:
diff changeset
11 //
anatofuz
parents:
diff changeset
12 // There is also a pass available to directly call dotty ('-view-callgraph').
anatofuz
parents:
diff changeset
13 //
anatofuz
parents:
diff changeset
14 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 #include "llvm/Analysis/CallPrinter.h"
anatofuz
parents:
diff changeset
17 #include "llvm/Analysis/CallGraph.h"
anatofuz
parents:
diff changeset
18 #include "llvm/Analysis/DOTGraphTraitsPass.h"
anatofuz
parents:
diff changeset
19 #include "llvm/InitializePasses.h"
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 using namespace llvm;
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 namespace llvm {
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 template <> struct DOTGraphTraits<CallGraph *> : public DefaultDOTGraphTraits {
anatofuz
parents:
diff changeset
26 DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 static std::string getGraphName(CallGraph *Graph) { return "Call graph"; }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
anatofuz
parents:
diff changeset
31 if (Function *Func = Node->getFunction())
anatofuz
parents:
diff changeset
32 return std::string(Func->getName());
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 return "external node";
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36 };
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 struct AnalysisCallGraphWrapperPassTraits {
anatofuz
parents:
diff changeset
39 static CallGraph *getGraph(CallGraphWrapperPass *P) {
anatofuz
parents:
diff changeset
40 return &P->getCallGraph();
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42 };
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 } // end llvm namespace
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 namespace {
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 struct CallGraphViewer
anatofuz
parents:
diff changeset
49 : public DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
anatofuz
parents:
diff changeset
50 AnalysisCallGraphWrapperPassTraits> {
anatofuz
parents:
diff changeset
51 static char ID;
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 CallGraphViewer()
anatofuz
parents:
diff changeset
54 : DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
anatofuz
parents:
diff changeset
55 AnalysisCallGraphWrapperPassTraits>(
anatofuz
parents:
diff changeset
56 "callgraph", ID) {
anatofuz
parents:
diff changeset
57 initializeCallGraphViewerPass(*PassRegistry::getPassRegistry());
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59 };
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 struct CallGraphDOTPrinter : public DOTGraphTraitsModulePrinter<
anatofuz
parents:
diff changeset
62 CallGraphWrapperPass, true, CallGraph *,
anatofuz
parents:
diff changeset
63 AnalysisCallGraphWrapperPassTraits> {
anatofuz
parents:
diff changeset
64 static char ID;
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 CallGraphDOTPrinter()
anatofuz
parents:
diff changeset
67 : DOTGraphTraitsModulePrinter<CallGraphWrapperPass, true, CallGraph *,
anatofuz
parents:
diff changeset
68 AnalysisCallGraphWrapperPassTraits>(
anatofuz
parents:
diff changeset
69 "callgraph", ID) {
anatofuz
parents:
diff changeset
70 initializeCallGraphDOTPrinterPass(*PassRegistry::getPassRegistry());
anatofuz
parents:
diff changeset
71 }
anatofuz
parents:
diff changeset
72 };
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 } // end anonymous namespace
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 char CallGraphViewer::ID = 0;
anatofuz
parents:
diff changeset
77 INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false,
anatofuz
parents:
diff changeset
78 false)
anatofuz
parents:
diff changeset
79
anatofuz
parents:
diff changeset
80 char CallGraphDOTPrinter::ID = 0;
anatofuz
parents:
diff changeset
81 INITIALIZE_PASS(CallGraphDOTPrinter, "dot-callgraph",
anatofuz
parents:
diff changeset
82 "Print call graph to 'dot' file", false, false)
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84 // Create methods available outside of this file, to use them
anatofuz
parents:
diff changeset
85 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
anatofuz
parents:
diff changeset
86 // the link time optimization.
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 ModulePass *llvm::createCallGraphViewerPass() { return new CallGraphViewer(); }
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 ModulePass *llvm::createCallGraphDOTPrinterPass() {
anatofuz
parents:
diff changeset
91 return new CallGraphDOTPrinter();
anatofuz
parents:
diff changeset
92 }