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 // This call graph represents a dynamic method invocation as a null method node.
7 // A call graph may only have up to one null method node that represents all of
8 // the dynamic method invocations.
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_ANALYSIS_CALLGRAPH_H
13 #define LLVM_ANALYSIS_CALLGRAPH_H
25 vector<CallGraphNode*> CalledMethods;
27 CallGraphNode(const CallGraphNode &); // Do not implement
29 typedef vector<CallGraphNode*>::iterator iterator;
30 typedef vector<CallGraphNode*>::const_iterator const_iterator;
32 // getMethod - Return the method that this call graph node represents...
33 Method *getMethod() const { return Meth; }
35 inline iterator begin() { return CalledMethods.begin(); }
36 inline iterator end() { return CalledMethods.end(); }
37 inline const_iterator begin() const { return CalledMethods.begin(); }
38 inline const_iterator end() const { return CalledMethods.end(); }
39 inline unsigned size() const { return CalledMethods.size(); }
41 inline CallGraphNode *operator[](unsigned i) const { return CalledMethods[i];}
44 private: // Stuff to construct the node, used by CallGraph
45 friend class CallGraph;
47 // CallGraphNode ctor - Create a node for the specified method...
48 inline CallGraphNode(Method *M) : Meth(M) {}
50 // addCalledMethod add a method to the list of methods called by this one
51 void addCalledMethod(CallGraphNode *M) {
52 CalledMethods.push_back(M);
59 typedef map<const Method *, CallGraphNode *> MethodMapTy;
60 MethodMapTy MethodMap;
62 CallGraph(Module *TheModule);
64 typedef MethodMapTy::iterator iterator;
65 typedef MethodMapTy::const_iterator const_iterator;
67 inline const_iterator begin() const { return MethodMap.begin(); }
68 inline const_iterator end() const { return MethodMap.end(); }
70 inline const CallGraphNode *operator[](const Method *M) const {
71 const_iterator I = MethodMap.find(M);
72 assert(I != MethodMap.end() && "Method not in callgraph!");
76 private: // Implementation of CallGraph construction
78 // getNodeFor - Return the node for the specified method or create one if it
79 // does not already exist.
81 CallGraphNode *getNodeFor(Method *M);
83 // addToCallGraph - Add a method to the call graph, and link the node to all
84 // of the methods that it calls.
86 void addToCallGraph(Method *M);
90 } // end namespace cfg