1 //===- llvm/Analysis/CallGraph.h - Build a Module's call graph ---*- C++ -*--=//
3 // This interface is used to build and manipulate a call graph, which is a very
4 // useful tool for interprocedural optimization.
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
9 #define LLVM_ANALYSIS_CALLGRAPH_H
21 vector<CallGraphNode*> CalledMethods;
23 CallGraphNode(const CallGraphNode &); // Do not implement
25 typedef vector<CallGraphNode*>::iterator iterator;
26 typedef vector<CallGraphNode*>::const_iterator const_iterator;
28 // getMethod - Return the method that this call graph node represents...
29 Method *getMethod() const { return Meth; }
31 inline iterator begin() { return CalledMethods.begin(); }
32 inline iterator end() { return CalledMethods.end(); }
33 inline const_iterator begin() const { return CalledMethods.begin(); }
34 inline const_iterator end() const { return CalledMethods.end(); }
35 inline unsigned size() const { return CalledMethods.size(); }
37 inline CallGraphNode *operator[](unsigned i) const { return CalledMethods[i];}
40 private: // Stuff to construct the node, used by CallGraph
41 friend class CallGraph;
43 // CallGraphNode ctor - Create a node for the specified method...
44 inline CallGraphNode(Method *M) : Meth(M) {}
46 // addCalledMethod add a method to the list of methods called by this one
47 void addCalledMethod(CallGraphNode *M) {
48 CalledMethods.push_back(M);
55 typedef map<const Method *, CallGraphNode *> MethodMapTy;
56 MethodMapTy MethodMap;
58 CallGraph(Module *TheModule);
60 typedef MethodMapTy::iterator iterator;
61 typedef MethodMapTy::const_iterator const_iterator;
63 inline const_iterator begin() const { return MethodMap.begin(); }
64 inline const_iterator end() const { return MethodMap.end(); }
66 inline const CallGraphNode *operator[](const Method *M) const {
67 const_iterator I = MethodMap.find(M);
68 assert(I != MethodMap.end() && "Method not in callgraph!");
72 private: // Implementation of CallGraph construction
74 // getNodeFor - Return the node for the specified method or create one if it
75 // does not already exist.
77 CallGraphNode *getNodeFor(Method *M);
79 // addToCallGraph - Add a method to the call graph, and link the node to all
80 // of the methods that it calls.
82 void addToCallGraph(Method *M);
86 } // end namespace cfg