DONT_BUILD_RELINKED is gone and implied by BUILD_ARCHIVE now
[oota-llvm.git] / lib / Analysis / IPA / CallGraph.cpp
index 8025ab2d9acdeab812b796fabe766ad1ccffc2cd..3caafd923339c57a1fc2c8da4c699c8cf7c8ade8 100644 (file)
@@ -1,10 +1,10 @@
 //===- CallGraph.cpp - Build a Module's call graph ------------------------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 //  This file implements the CallGraph class.
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/CallGraph.h"
-#include "llvm/Constants.h"     // Remove when ConstantPointerRefs are gone
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
 #include "llvm/Support/CallSite.h"
-#include "Support/STLExtras.h"
+#include "llvm/ADT/STLExtras.h"
 #include <iostream>
 using namespace llvm;
 
@@ -58,7 +57,7 @@ void CallGraph::addToCallGraph(Function *F) {
         Root = Node;          // Found a main, keep track of it!
     }
   }
-  
+
   // If this function is not defined in this translation unit, it could call
   // anything.
   if (F->isExternal() && !F->getIntrinsicID())
@@ -100,7 +99,7 @@ void CallGraph::addToCallGraph(Function *F) {
     }
 }
 
-bool CallGraph::run(Module &M) {
+bool CallGraph::runOnModule(Module &M) {
   destroy();
 
   Mod = &M;
@@ -114,7 +113,7 @@ bool CallGraph::run(Module &M) {
 
   // If we didn't find a main function, use the external call graph node
   if (Root == 0) Root = ExternalCallingNode;
-  
+
   return false;
 }
 
@@ -149,7 +148,7 @@ void CallGraph::print(std::ostream &OS, const Module *M) const {
     OS << F->getName() << "\n";
   else
     OS << "<<null function: 0x" << getRoot() << ">>\n";
-  
+
   for (CallGraph::const_iterator I = begin(), E = end(); I != E; ++I)
     I->second->print(OS);
 }
@@ -163,14 +162,6 @@ void CallGraph::dump() const {
 // Implementations of public modification methods
 //
 
-// Functions to keep a call graph up to date with a function that has been
-// modified
-//
-void CallGraph::addFunctionToModule(Function *F) {
-  assert(0 && "not implemented");
-  abort();
-}
-
 // removeFunctionFromModule - Unlink the function from this module, returning
 // it.  Because this removes the function from the module, the call graph node
 // is destroyed.  This is only valid if the function does not call any other
@@ -188,6 +179,21 @@ Function *CallGraph::removeFunctionFromModule(CallGraphNode *CGN) {
   return F;
 }
 
+// changeFunction - This method changes the function associated with this
+// CallGraphNode, for use by transformations that need to change the prototype
+// of a Function (thus they must create a new Function and move the old code
+// over).
+void CallGraph::changeFunction(Function *OldF, Function *NewF) {
+  iterator I = FunctionMap.find(OldF);
+  CallGraphNode *&New = FunctionMap[NewF];
+  assert(I != FunctionMap.end() && I->second && !New &&
+         "OldF didn't exist in CG or NewF already does!");
+  New = I->second;
+  New->F = NewF;
+  FunctionMap.erase(I);
+}
+
+
 void CallGraph::stub() {}
 
 void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
@@ -199,3 +205,15 @@ void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
     }
   }
 }
+
+// removeAnyCallEdgeTo - This method removes any 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 CallGraphNode::removeAnyCallEdgeTo(CallGraphNode *Callee) {
+  for (unsigned i = 0, e = CalledFunctions.size(); i != e; ++i)
+    if (CalledFunctions[i] == Callee) {
+      CalledFunctions[i] = CalledFunctions.back();
+      CalledFunctions.pop_back();
+      --i; --e;
+    }
+}