2013-04-08 18:41:23 +00:00
|
|
|
//===- CallPrinter.cpp - DOT printer for call graph -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines '-dot-callgraph', which emit a callgraph.<fnname>.dot
|
|
|
|
// containing the call graph of a module.
|
|
|
|
//
|
|
|
|
// There is also a pass available to directly call dotty ('-view-callgraph').
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/CallPrinter.h"
|
2017-06-10 13:44:06 +00:00
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/Analysis/DOTGraphTraitsPass.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
template <> struct DOTGraphTraits<CallGraph *> : public DefaultDOTGraphTraits {
|
|
|
|
DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
|
2013-04-08 18:41:23 +00:00
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
static std::string getGraphName(CallGraph *Graph) { return "Call graph"; }
|
2013-04-08 18:41:23 +00:00
|
|
|
|
|
|
|
std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
|
|
|
|
if (Function *Func = Node->getFunction())
|
|
|
|
return Func->getName();
|
|
|
|
|
|
|
|
return "external node";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
struct AnalysisCallGraphWrapperPassTraits {
|
|
|
|
static CallGraph *getGraph(CallGraphWrapperPass *P) {
|
|
|
|
return &P->getCallGraph();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-05 14:21:36 +00:00
|
|
|
} // end llvm namespace
|
2013-04-08 18:41:23 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct CallGraphViewer
|
2014-11-24 09:08:18 +00:00
|
|
|
: public DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits> {
|
2013-04-08 18:41:23 +00:00
|
|
|
static char ID;
|
|
|
|
|
|
|
|
CallGraphViewer()
|
2014-11-24 09:08:18 +00:00
|
|
|
: DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits>(
|
|
|
|
"callgraph", ID) {
|
2013-04-08 18:41:23 +00:00
|
|
|
initializeCallGraphViewerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
struct CallGraphDOTPrinter : public DOTGraphTraitsModulePrinter<
|
2014-11-24 09:08:18 +00:00
|
|
|
CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits> {
|
2013-04-08 18:41:23 +00:00
|
|
|
static char ID;
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
CallGraphDOTPrinter()
|
2014-11-24 09:08:18 +00:00
|
|
|
: DOTGraphTraitsModulePrinter<CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits>(
|
|
|
|
"callgraph", ID) {
|
2016-07-23 20:41:05 +00:00
|
|
|
initializeCallGraphDOTPrinterPass(*PassRegistry::getPassRegistry());
|
2013-04-08 18:41:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char CallGraphViewer::ID = 0;
|
2014-11-24 09:08:18 +00:00
|
|
|
INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false,
|
|
|
|
false)
|
2013-04-08 18:41:23 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
char CallGraphDOTPrinter::ID = 0;
|
|
|
|
INITIALIZE_PASS(CallGraphDOTPrinter, "dot-callgraph",
|
2014-11-24 09:08:18 +00:00
|
|
|
"Print call graph to 'dot' file", false, false)
|
2013-04-08 18:41:23 +00:00
|
|
|
|
|
|
|
// Create methods available outside of this file, to use them
|
|
|
|
// "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
|
|
|
|
// the link time optimization.
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
ModulePass *llvm::createCallGraphViewerPass() { return new CallGraphViewer(); }
|
2013-04-08 18:41:23 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
ModulePass *llvm::createCallGraphDOTPrinterPass() {
|
|
|
|
return new CallGraphDOTPrinter();
|
2013-04-08 18:41:23 +00:00
|
|
|
}
|