[llvm-commits] CVS: llvm/tools/analyze/GraphPrinters.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Nov 3 20:56:01 PST 2002
Changes in directory llvm/tools/analyze:
GraphPrinters.cpp updated: 1.1 -> 1.2
---
Log message:
Implement a new -print-callgraph analysis that turns a callgraph into a dot
graph
---
Diffs of the changes:
Index: llvm/tools/analyze/GraphPrinters.cpp
diff -u llvm/tools/analyze/GraphPrinters.cpp:1.1 llvm/tools/analyze/GraphPrinters.cpp:1.2
--- llvm/tools/analyze/GraphPrinters.cpp:1.1 Mon Oct 7 13:38:01 2002
+++ llvm/tools/analyze/GraphPrinters.cpp Sun Nov 3 20:55:30 2002
@@ -10,10 +10,15 @@
#include "Support/GraphWriter.h"
#include "llvm/Pass.h"
#include "llvm/iTerminators.h"
+#include "llvm/Analysis/CallGraph.h"
#include "llvm/Support/CFG.h"
#include <sstream>
#include <fstream>
+//===----------------------------------------------------------------------===//
+// Control Flow Graph Printer
+//===----------------------------------------------------------------------===//
+
template<>
struct DOTGraphTraits<Function*> : public DefaultDOTGraphTraits {
static std::string getGraphName(Function *F) {
@@ -70,7 +75,6 @@
namespace {
struct CFGPrinter : public FunctionPass {
- Function *F;
virtual bool runOnFunction(Function &Func) {
WriteGraphToFile(std::cerr, "cfg."+Func.getName(), &Func);
return false;
@@ -85,4 +89,44 @@
RegisterAnalysis<CFGPrinter> P1("print-cfg",
"Print CFG of function to 'dot' file");
+};
+
+
+
+//===----------------------------------------------------------------------===//
+// Call Graph Printer
+//===----------------------------------------------------------------------===//
+
+template<>
+struct DOTGraphTraits<CallGraph*> : public DefaultDOTGraphTraits {
+ static std::string getGraphName(CallGraph *F) {
+ return "Call Graph";
+ }
+
+ static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
+ if (Node->getFunction())
+ return Node->getFunction()->getName();
+ else
+ return "Indirect call node";
+ }
+};
+
+
+namespace {
+ struct CallGraphPrinter : public Pass {
+ virtual bool run(Module &M) {
+ WriteGraphToFile(std::cerr, "callgraph", &getAnalysis<CallGraph>());
+ return false;
+ }
+
+ void print(std::ostream &OS) const {}
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequired<CallGraph>();
+ AU.setPreservesAll();
+ }
+ };
+
+ RegisterAnalysis<CallGraphPrinter> P2("print-callgraph",
+ "Print Call Graph to 'dot' file");
};
More information about the llvm-commits
mailing list