[llvm-commits] CVS: llvm/lib/Analysis/IPA/CallGraph.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Jan 14 12:03:27 PST 2006



Changes in directory llvm/lib/Analysis/IPA:

CallGraph.cpp updated: 1.50 -> 1.51
---
Log message:

Add a new CallGraph::getOrInsertFunction for clients to use when updating
the callgraph.


---
Diffs of the changes:  (+19 -16)

 CallGraph.cpp |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)


Index: llvm/lib/Analysis/IPA/CallGraph.cpp
diff -u llvm/lib/Analysis/IPA/CallGraph.cpp:1.50 llvm/lib/Analysis/IPA/CallGraph.cpp:1.51
--- llvm/lib/Analysis/IPA/CallGraph.cpp:1.50	Sat Jan 14 13:17:02 2006
+++ llvm/lib/Analysis/IPA/CallGraph.cpp	Sat Jan 14 14:03:00 2006
@@ -56,7 +56,7 @@
     destroy();
     CallGraph::initialize(M);
     
-    ExternalCallingNode = getNodeFor(0);
+    ExternalCallingNode = getOrInsertFunction(0);
     CallsExternalNode = new CallGraphNode(0);
     Root = 0;
   
@@ -107,24 +107,12 @@
   //===---------------------------------------------------------------------
   // 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 @@
     for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; ++I){
       if (Instruction *Inst = dyn_cast<Instruction>(*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<GlobalValue>(*I)) {
@@ -158,7 +147,8 @@
              I != E; ++I)
           if (Instruction *Inst = dyn_cast<Instruction>(*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 @@
   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<Function*>(F));
+}
+
+
+
 void CallGraph::stub() {}
 
 void CallGraphNode::print(std::ostream &OS) const {






More information about the llvm-commits mailing list