+
+ /// removeAllCalledFunctions - As the name implies, this removes all edges
+ /// from this CallGraphNode to any functions it calls.
+ void removeAllCalledFunctions() {
+ CalledFunctions.clear();
+ }
+
+ /// addCalledFunction - Add a function to the list of functions called by this
+ /// one.
+ void addCalledFunction(CallSite CS, CallGraphNode *M) {
+ CalledFunctions.push_back(std::make_pair(CS, M));
+ }
+
+ /// removeCallEdgeFor - This method removes the edge in the node for the
+ /// specified call site. Note that this method takes linear time, so it
+ /// should be used sparingly.
+ void removeCallEdgeFor(CallSite CS);
+
+ /// removeAnyCallEdgeTo - This method removes all call edges from this node
+ /// to the specified callee function. This takes more time to execute than
+ /// removeCallEdgeTo, so it should not be used unless necessary.
+ void removeAnyCallEdgeTo(CallGraphNode *Callee);
+
+ /// removeOneAbstractEdgeTo - Remove one edge associated with a null callsite
+ /// from this node to the specified callee function.
+ void removeOneAbstractEdgeTo(CallGraphNode *Callee);
+
+ /// replaceCallSite - Make the edge in the node for Old CallSite be for
+ /// New CallSite instead. Note that this method takes linear time, so it
+ /// should be used sparingly.
+ void replaceCallSite(CallSite Old, CallSite New);
+
+ friend class CallGraph;
+
+ // CallGraphNode ctor - Create a node for the specified function.
+ inline CallGraphNode(Function *f) : F(f) {}
+};
+
+//===----------------------------------------------------------------------===//
+// GraphTraits specializations for call graphs so that they can be treated as
+// graphs by the generic graph algorithms.
+//
+
+// Provide graph traits for tranversing call graphs using standard graph
+// traversals.
+template <> struct GraphTraits<CallGraphNode*> {
+ typedef CallGraphNode NodeType;
+
+ typedef std::pair<CallSite, CallGraphNode*> CGNPairTy;
+ typedef std::pointer_to_unary_function<CGNPairTy, CallGraphNode*> CGNDerefFun;
+
+ static NodeType *getEntryNode(CallGraphNode *CGN) { return CGN; }
+
+ typedef mapped_iterator<NodeType::iterator, CGNDerefFun> ChildIteratorType;
+
+ static inline ChildIteratorType child_begin(NodeType *N) {
+ return map_iterator(N->begin(), CGNDerefFun(CGNDeref));
+ }
+ static inline ChildIteratorType child_end (NodeType *N) {
+ return map_iterator(N->end(), CGNDerefFun(CGNDeref));
+ }
+
+ static CallGraphNode *CGNDeref(CGNPairTy P) {
+ return P.second;
+ }
+
+};
+
+template <> struct GraphTraits<const CallGraphNode*> {
+ typedef const CallGraphNode NodeType;
+ typedef NodeType::const_iterator ChildIteratorType;
+
+ static NodeType *getEntryNode(const CallGraphNode *CGN) { return CGN; }
+ static inline ChildIteratorType child_begin(NodeType *N) { return N->begin();}
+ static inline ChildIteratorType child_end (NodeType *N) { return N->end(); }
+};
+
+template<> struct GraphTraits<CallGraph*> : public GraphTraits<CallGraphNode*> {
+ static NodeType *getEntryNode(CallGraph *CGN) {
+ return CGN->getExternalCallingNode(); // 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(PairTy P) {
+ return *P.second;
+ }
+};
+
+template<> struct GraphTraits<const CallGraph*> :
+ public GraphTraits<const CallGraphNode*> {
+ static NodeType *getEntryNode(const CallGraph *CGN) {
+ return CGN->getExternalCallingNode();
+ }
+ // 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(); }