From c54b1c1f8b7cf7419b2843d54e9da6c8c15e0dd0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 14 Jan 2006 20:03:00 +0000 Subject: [PATCH] Add a new CallGraph::getOrInsertFunction for clients to use when updating the callgraph. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25317 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/IPA/CallGraph.cpp | 35 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp index 29b8ed4a7f0..9089afe1a97 100644 --- a/lib/Analysis/IPA/CallGraph.cpp +++ b/lib/Analysis/IPA/CallGraph.cpp @@ -56,7 +56,7 @@ public: destroy(); CallGraph::initialize(M); - ExternalCallingNode = getNodeFor(0); + ExternalCallingNode = getOrInsertFunction(0); CallsExternalNode = new CallGraphNode(0); Root = 0; @@ -107,24 +107,12 @@ private: //===--------------------------------------------------------------------- // Implementation of CallGraph construction // - // getNodeFor - Return the node for the specified function or create one if it - // does not already exist. - // - - CallGraphNode *getNodeFor(Function *F) { - CallGraphNode *&CGN = FunctionMap[F]; - if (CGN) return CGN; - assert((!F || F->getParent() == Mod) && "Function not in current module!"); - return CGN = new CallGraphNode(F); - } - - // // addToCallGraph - Add a function to the call graph, and link the node to all // of the functions that it calls. // void addToCallGraph(Function *F) { - CallGraphNode *Node = getNodeFor(F); + CallGraphNode *Node = getOrInsertFunction(F); // If this function has external linkage, anything could call it... if (!F->hasInternalLinkage()) { @@ -150,7 +138,8 @@ private: for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; ++I){ if (Instruction *Inst = dyn_cast(*I)) { if (isOnlyADirectCall(F, CallSite::get(Inst))) - getNodeFor(Inst->getParent()->getParent())->addCalledFunction(Node); + getOrInsertFunction(Inst->getParent()->getParent()) + ->addCalledFunction(Node); else isUsedExternally = true; } else if (GlobalValue *GV = dyn_cast(*I)) { @@ -158,7 +147,8 @@ private: I != E; ++I) if (Instruction *Inst = dyn_cast(*I)) { if (isOnlyADirectCall(F, CallSite::get(Inst))) - getNodeFor(Inst->getParent()->getParent())->addCalledFunction(Node); + getOrInsertFunction(Inst->getParent()->getParent()) + ->addCalledFunction(Node); else isUsedExternally = true; } else { @@ -255,6 +245,19 @@ void CallGraph::changeFunction(Function *OldF, Function *NewF) { FunctionMap.erase(I); } +// getOrInsertFunction - This method is identical to calling operator[], but +// it will insert a new CallGraphNode for the specified function if one does +// not already exist. +CallGraphNode *CallGraph::getOrInsertFunction(const Function *F) { + CallGraphNode *&CGN = FunctionMap[F]; + if (CGN) return CGN; + + assert((!F || F->getParent() == Mod) && "Function not in current module!"); + return CGN = new CallGraphNode(const_cast(F)); +} + + + void CallGraph::stub() {} void CallGraphNode::print(std::ostream &OS) const { -- 2.34.1