It was pointed out that DEBUG() is only available with -debug.
[oota-llvm.git] / lib / Analysis / IPA / CallGraph.cpp
index 29b8ed4a7f0fbd3a945cb74f1a57226403615598..78bb735ffa23aa84610125ac260ad575fa32803d 100644 (file)
@@ -19,8 +19,6 @@
 #include <iostream>
 using namespace llvm;
 
-void llvm::BasicCallGraphStub() {}
-
 static bool isOnlyADirectCall(Function *F, CallSite CS) {
   if (!CS.getInstruction()) return false;
   for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E; ++I)
@@ -56,7 +54,7 @@ public:
     destroy();
     CallGraph::initialize(M);
     
-    ExternalCallingNode = getNodeFor(0);
+    ExternalCallingNode = getOrInsertFunction(0);
     CallsExternalNode = new CallGraphNode(0);
     Root = 0;
   
@@ -107,24 +105,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 +136,8 @@ private:
     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 +145,8 @@ private:
              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,7 +243,16 @@ void CallGraph::changeFunction(Function *OldF, Function *NewF) {
   FunctionMap.erase(I);
 }
 
-void CallGraph::stub() {}
+// 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 CallGraphNode::print(std::ostream &OS) const {
   if (Function *F = getFunction())
@@ -294,3 +291,6 @@ void CallGraphNode::removeAnyCallEdgeTo(CallGraphNode *Callee) {
       --i; --e;
     }
 }
+
+// Enuse that users of CallGraph.h also link with this file
+DEFINING_FILE_FOR(CallGraph)