[llvm-commits] CVS: llvm/include/llvm/Analysis/CallGraph.h

Chris Lattner lattner at cs.uiuc.edu
Sun Nov 3 20:54:01 PST 2002


Changes in directory llvm/include/llvm/Analysis:

CallGraph.h updated: 1.23 -> 1.24

---
Log message:

Implement methods needed to print out call graph


---
Diffs of the changes:

Index: llvm/include/llvm/Analysis/CallGraph.h
diff -u llvm/include/llvm/Analysis/CallGraph.h:1.23 llvm/include/llvm/Analysis/CallGraph.h:1.24
--- llvm/include/llvm/Analysis/CallGraph.h:1.23	Sun Nov  3 18:21:18 2002
+++ llvm/include/llvm/Analysis/CallGraph.h	Sun Nov  3 20:53:39 2002
@@ -42,6 +42,7 @@
 #define LLVM_ANALYSIS_CALLGRAPH_H
 
 #include "Support/GraphTraits.h"
+#include "Support/STLExtras.h"
 #include "llvm/Pass.h"
 class Function;
 class Module;
@@ -242,18 +243,36 @@
   static inline ChildIteratorType child_end  (NodeType *N) { return N->end(); }
 };
 
-
-template<> struct GraphTraits<CallGraph*> :
-  public GraphTraits<CallGraphNode*> {
+template<> struct GraphTraits<CallGraph*> : public GraphTraits<CallGraphNode*> {
   static NodeType *getEntryNode(CallGraph *CGN) {
     return CGN->getExternalNode();  // Start at the external node!
   }
+  typedef std::pair<const Function*, CallGraphNode*> PairTy;
+  typedef std::pointer_to_unary_function<PairTy, CallGraphNode&> DerefFun;
+
+  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
+  typedef mapped_iterator<CallGraph::iterator, DerefFun> nodes_iterator;
+  static nodes_iterator nodes_begin(CallGraph *CG) {
+    return map_iterator(CG->begin(), DerefFun(CGdereference));
+  }
+  static nodes_iterator nodes_end  (CallGraph *CG) {
+    return map_iterator(CG->end(), DerefFun(CGdereference));
+  }
+
+  static CallGraphNode &CGdereference (std::pair<const Function*,
+                                       CallGraphNode*> P) {
+    return *P.second;
+  }
 };
 template<> struct GraphTraits<const CallGraph*> :
   public GraphTraits<const CallGraphNode*> {
   static NodeType *getEntryNode(const CallGraph *CGN) {
     return CGN->getExternalNode();
   }
+  // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
+  typedef CallGraph::const_iterator nodes_iterator;
+  static nodes_iterator nodes_begin(const CallGraph *CG) { return CG->begin(); }
+  static nodes_iterator nodes_end  (const CallGraph *CG) { return CG->end(); }
 };
 
 #endif





More information about the llvm-commits mailing list