MEGAPATCH checkin.

For details, See: docs/2002-06-25-MegaPatchInfo.txt


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2779 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp
index 9eb6e54..6cb901b 100644
--- a/lib/Transforms/IPO/FunctionResolution.cpp
+++ b/lib/Transforms/IPO/FunctionResolution.cpp
@@ -13,8 +13,6 @@
 
 #include "llvm/Transforms/CleanupGCCOutput.h"
 #include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Pass.h"
@@ -34,7 +32,7 @@
   struct FunctionResolvingPass : public Pass {
     const char *getPassName() const { return "Resolve Functions"; }
 
-    bool run(Module *M);
+    bool run(Module &M);
   };
 }
 
@@ -50,12 +48,10 @@
     Dest->getFunctionType()->getParamTypes();
   BasicBlock *BB = CI->getParent();
 
-  // Get an iterator to where we want to insert cast instructions if the
+  // Keep an iterator to where we want to insert cast instructions if the
   // argument types don't agree.
   //
-  BasicBlock::iterator BBI = find(BB->begin(), BB->end(), CI);
-  assert(BBI != BB->end() && "CallInst not in parent block?");
-
+  BasicBlock::iterator BBI = CI;
   assert(CI->getNumOperands()-1 == ParamTys.size() &&
          "Function calls resolved funny somehow, incompatible number of args");
 
@@ -68,7 +64,7 @@
 
     if (V->getType() != ParamTys[i-1]) { // Must insert a cast...
       Instruction *Cast = new CastInst(V, ParamTys[i-1]);
-      BBI = BB->getInstList().insert(BBI, Cast)+1;
+      BBI = ++BB->getInstList().insert(BBI, Cast);
       V = Cast;
     }
 
@@ -80,7 +76,7 @@
   // Replace the old call instruction with a new call instruction that calls
   // the real function.
   //
-  BBI = BB->getInstList().insert(BBI, NewCall)+1;
+  BBI = ++BB->getInstList().insert(BBI, NewCall);
 
   // Remove the old call instruction from the program...
   BB->getInstList().remove(BBI);
@@ -110,8 +106,8 @@
 }
 
 
-bool FunctionResolvingPass::run(Module *M) {
-  SymbolTable *ST = M->getSymbolTable();
+bool FunctionResolvingPass::run(Module &M) {
+  SymbolTable *ST = M.getSymbolTable();
   if (!ST) return false;
 
   std::map<string, vector<Function*> > Functions;
@@ -151,9 +147,8 @@
         // warnings... here we will actually DCE the function so that it isn't
         // used later.
         //
-        if (Functions[i]->use_size() == 0) {
-          M->getFunctionList().remove(Functions[i]);
-          delete Functions[i];
+        if (Functions[i]->use_empty()) {
+          M.getFunctionList().erase(Functions[i]);
           Functions.erase(Functions.begin()+i);
           Changed = true;
           ++NumResolved;