Cast instruction not inserted into basic block.
authorJim Laskey <jlaskey@mac.com>
Sat, 25 Mar 2006 18:40:47 +0000 (18:40 +0000)
committerJim Laskey <jlaskey@mac.com>
Sat, 25 Mar 2006 18:40:47 +0000 (18:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27122 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AutoUpgrade.cpp

index af4417e0f0bd851b2511a88188e4756fb55eadff..b7b481157c89577648339fa20832a5b44906067d 100644 (file)
@@ -201,51 +201,15 @@ Function *llvm::UpgradeIntrinsicFunction(Function* F) {
 
 // CastArg - Perform the appropriate cast of an upgraded argument.
 //
-static Value *CastArg(Value *Arg, const Type *Ty) {
+static Value *CastArg(Value *Arg, const Type *Ty, Instruction *InsertBefore) {
   if (Constant *C = dyn_cast<Constant>(Arg)) {
     return ConstantExpr::getCast(C, Ty);
   } else {
-    return new CastInst(Arg, Ty, "autoupgrade_cast");
+    Value *Cast = new CastInst(Arg, Ty, "autoupgrade_cast", InsertBefore);
+    return Cast;
   }
 }
 
-Instruction* llvm::MakeUpgradedCall(Function *F, 
-                                    const std::vector<Value*> &Params,
-                                    BasicBlock *BB, bool isTailCall,
-                                    unsigned CallingConv) {
-  assert(F && "Need a Function to make a CallInst");
-  assert(BB && "Need a BasicBlock to make a CallInst");
-
-  // Convert the params
-  bool signedArg = false;
-  std::vector<Value*> Oprnds;
-  for (std::vector<Value*>::const_iterator PI = Params.begin(), 
-       PE = Params.end(); PI != PE; ++PI) {
-    const Type* opTy = (*PI)->getType();
-    if (opTy->isSigned()) {
-      signedArg = true;
-      Value *cast = CastArg(*PI, opTy->getUnsignedVersion());
-      if (Instruction *I = dyn_cast<Instruction>(cast))
-        BB->getInstList().push_back(I);
-      Oprnds.push_back(cast);
-    }
-    else
-      Oprnds.push_back(*PI);
-  }
-
-  Instruction *result = new CallInst(F, Oprnds);
-  if (result->getType() != Type::VoidTy) result->setName("autoupgrade_call");
-  if (isTailCall) cast<CallInst>(result)->setTailCall();
-  if (CallingConv) cast<CallInst>(result)->setCallingConv(CallingConv);
-  if (signedArg) {
-    const Type* newTy = F->getReturnType()->getUnsignedVersion();
-    CastInst* final = new CastInst(result, newTy, "autoupgrade_uncast");
-    BB->getInstList().push_back(result);
-    result = final;
-  }
-  return result;
-}
-
 // UpgradeIntrinsicCall - In the BC reader, change a call to an intrinsic to be
 // a call to an upgraded intrinsic.  We may have to permute the order or promote
 // some arguments with a cast.
@@ -265,7 +229,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
       if (p) {
         Value *V = CI->getOperand(p);
         if (V->getType() != NewFnTy->getParamType(i))
-          V = CastArg(V, NewFnTy->getParamType(i));
+          V = CastArg(V, NewFnTy->getParamType(i), CI);
         Oprnds.push_back(V);
       } else
         Oprnds.push_back(UndefValue::get(NewFnTy->getParamType(i)));
@@ -276,7 +240,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
     for (unsigned i = 0; i != N; ++i) {
       Value *V = CI->getOperand(i + 1);
       if (V->getType() != NewFnTy->getParamType(i))
-        V = CastArg(V, NewFnTy->getParamType(i));
+        V = CastArg(V, NewFnTy->getParamType(i), CI);
       Oprnds.push_back(V);
     }
   }