Non-functionality change just to make it more clear what is going on
[oota-llvm.git] / lib / Transforms / IPO / FunctionResolution.cpp
index 2306df999db67e16ce89c9767ca541a267eb4da6..bf65c49bf9ec3af3ca8bf4b03f596ddc4875d629 100644 (file)
@@ -18,8 +18,7 @@
 #include "llvm/Pass.h"
 #include "llvm/iOther.h"
 #include "llvm/Constant.h"
-#include "Support/StatisticReporter.h"
-#include <iostream>
+#include "Support/Statistic.h"
 #include <algorithm>
 
 using std::vector;
@@ -27,7 +26,7 @@ using std::string;
 using std::cerr;
 
 namespace {
-  Statistic<>NumResolved("funcresolve\t- Number of varargs functions resolved");
+  Statistic<>NumResolved("funcresolve", "Number of varargs functions resolved");
 
   struct FunctionResolvingPass : public Pass {
     bool run(Module &M);
@@ -61,27 +60,23 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
   for (unsigned i = 1; i < CI->getNumOperands(); ++i) {
     Value *V = CI->getOperand(i);
 
-    if (V->getType() != ParamTys[i-1]) { // Must insert a cast...
-      Instruction *Cast = new CastInst(V, ParamTys[i-1]);
-      BBI = ++BB->getInstList().insert(BBI, Cast);
-      V = Cast;
-    }
+    if (V->getType() != ParamTys[i-1])  // Must insert a cast...
+      V = new CastInst(V, ParamTys[i-1], "argcast", BBI);
 
     Params.push_back(V);
   }
 
-  Instruction *NewCall = new CallInst(Dest, Params);
-
   // Replace the old call instruction with a new call instruction that calls
   // the real function.
   //
-  BBI = ++BB->getInstList().insert(BBI, NewCall);
+  Instruction *NewCall = new CallInst(Dest, Params, "", BBI);
 
   // Remove the old call instruction from the program...
   BB->getInstList().remove(BBI);
 
   // Transfer the name over...
-  NewCall->setName(CI->getName());
+  if (NewCall->getType() != Type::VoidTy)
+    NewCall->setName(CI->getName());
 
   // Replace uses of the old instruction with the appropriate values...
   //
@@ -104,11 +99,10 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
     // value of the function is actually USED.
     //
     if (!CI->use_empty()) {
+      // Insert the new cast instruction...
       CastInst *NewCast = new CastInst(NewCall, CI->getType(),
-                                       NewCall->getName());
+                                       NewCall->getName(), BBI);
       CI->replaceAllUsesWith(NewCast);
-      // Insert the new cast instruction...
-      BB->getInstList().insert(BBI, NewCast);
     }
   }