2013-01-11 17:28:14 +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/CallGraph.h"
|
|
|
|
#include "llvm/Analysis/CallPrinter.h"
|
|
|
|
#include "llvm/Analysis/DOTGraphTraitsPass.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2013-11-26 03:45:26 +00:00
|
|
|
template <> struct DOTGraphTraits<CallGraph *> : public DefaultDOTGraphTraits {
|
|
|
|
DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
|
2013-01-11 17:28:14 +00:00
|
|
|
|
2013-11-26 03:45:26 +00:00
|
|
|
static std::string getGraphName(CallGraph *Graph) { return "Call graph"; }
|
2013-01-11 17:28:14 +00:00
|
|
|
|
|
|
|
std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
|
|
|
|
if (Function *Func = Node->getFunction())
|
|
|
|
return Func->getName();
|
|
|
|
|
|
|
|
return "external node";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-26 04:19:30 +00:00
|
|
|
struct AnalysisCallGraphWrapperPassTraits {
|
|
|
|
static CallGraph *getGraph(CallGraphWrapperPass *P) {
|
|
|
|
return &P->getCallGraph();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-11 17:28:14 +00:00
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-11-26 04:19:30 +00:00
|
|
|
struct CallGraphViewer
|
|
|
|
: public DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits> {
|
2013-01-11 17:28:14 +00:00
|
|
|
static char ID;
|
|
|
|
|
|
|
|
CallGraphViewer()
|
2013-11-26 04:19:30 +00:00
|
|
|
: DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits>(
|
|
|
|
"callgraph", ID) {
|
2013-01-11 17:28:14 +00:00
|
|
|
initializeCallGraphViewerPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-26 04:19:30 +00:00
|
|
|
struct CallGraphPrinter : public DOTGraphTraitsModulePrinter<
|
|
|
|
CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits> {
|
2013-01-11 17:28:14 +00:00
|
|
|
static char ID;
|
|
|
|
|
|
|
|
CallGraphPrinter()
|
2013-11-26 04:19:30 +00:00
|
|
|
: DOTGraphTraitsModulePrinter<CallGraphWrapperPass, true, CallGraph *,
|
|
|
|
AnalysisCallGraphWrapperPassTraits>(
|
|
|
|
"callgraph", ID) {
|
2013-11-26 03:45:26 +00:00
|
|
|
initializeCallGraphPrinterPass(*PassRegistry::getPassRegistry());
|
2013-01-11 17:28:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
char CallGraphViewer::ID = 0;
|
2013-11-26 03:45:26 +00:00
|
|
|
INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false,
|
|
|
|
false)
|
2013-01-11 17:28:14 +00:00
|
|
|
|
|
|
|
char CallGraphPrinter::ID = 0;
|
|
|
|
INITIALIZE_PASS(CallGraphPrinter, "dot-callgraph",
|
2013-11-26 03:45:26 +00:00
|
|
|
"Print call graph to 'dot' file", false, false)
|
2013-01-11 17:28:14 +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.
|
|
|
|
|
2013-11-26 03:45:26 +00:00
|
|
|
ModulePass *llvm::createCallGraphViewerPass() { return new CallGraphViewer(); }
|
2013-01-11 17:28:14 +00:00
|
|
|
|
|
|
|
ModulePass *llvm::createCallGraphPrinterPass() {
|
|
|
|
return new CallGraphPrinter();
|
|
|
|
}
|