API change for {BinaryOperator|CmpInst|CastInst}::create*() --> Create. Legacy interf...
[oota-llvm.git] / lib / VMCore / AutoUpgrade.cpp
index 4d0eb1ca0b0f1a32ddd81d0452e796b95af509a2..bed8fee8bbeb2a38966efe7cae1f14837416377e 100644 (file)
@@ -16,8 +16,9 @@
 #include "llvm/Function.h"
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
-#include "llvm/ParameterAttributes.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/ADT/SmallVector.h"
+#include <cstring>
 using namespace llvm;
 
 
@@ -121,7 +122,7 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
     if (Name.compare(5,10,"x86.mmx.ps",10) == 0 &&
         (Name.compare(13,4,"psll", 4) == 0 ||
          Name.compare(13,4,"psra", 4) == 0 ||
-         Name.compare(13,4,"psrl", 4) == 0)) {
+         Name.compare(13,4,"psrl", 4) == 0) && Name[17] != 'i') {
       
       const llvm::Type *VT = VectorType::get(IntegerType::get(64), 1);
       
@@ -215,7 +216,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
     return;
   }
 
-  switch(NewFn->getIntrinsicID()) {
+  switch (NewFn->getIntrinsicID()) {
   default:  assert(0 && "Unknown function for CallInst upgrade.");
   case Intrinsic::x86_mmx_psll_d:
   case Intrinsic::x86_mmx_psll_q:
@@ -225,19 +226,19 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
   case Intrinsic::x86_mmx_psrl_d:
   case Intrinsic::x86_mmx_psrl_q:
   case Intrinsic::x86_mmx_psrl_w: {
-    SmallVector<Value*, 2> Operands;
+    Value *Operands[2];
     
-    Operands.push_back(CI->getOperand(1));
+    Operands[0] = CI->getOperand(1);
     
     // Cast the second parameter to the correct type.
     BitCastInst *BC = new BitCastInst(CI->getOperand(2), 
                                       NewFn->getFunctionType()->getParamType(1),
                                       "upgraded", CI);
-    Operands.push_back(BC);
+    Operands[1] = BC;
     
     //  Construct a new CallInst
-    CallInst *NewCI = new CallInst(NewFn, Operands.begin(), Operands.end()
-                                   "upgraded."+CI->getName(), CI);
+    CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+2
+                                       "upgraded."+CI->getName(), CI);
     NewCI->setTailCall(CI->isTailCall());
     NewCI->setCallingConv(CI->getCallingConv());
     
@@ -253,27 +254,25 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
   }        
   case Intrinsic::ctlz:
   case Intrinsic::ctpop:
-  case Intrinsic::cttz:
+  case Intrinsic::cttz: {
     //  Build a small vector of the 1..(N-1) operands, which are the 
     //  parameters.
-    SmallVector<Value*, 8>   Operands(CI->op_begin()+1, CI->op_end());
+    SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end());
 
     //  Construct a new CallInst
-    CallInst *NewCI = new CallInst(NewFn, Operands.begin(), Operands.end(), 
-                                   "upgraded."+CI->getName(), CI);
+    CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(),
+                                       "upgraded."+CI->getName(), CI);
     NewCI->setTailCall(CI->isTailCall());
     NewCI->setCallingConv(CI->getCallingConv());
 
     //  Handle any uses of the old CallInst.
     if (!CI->use_empty()) {
       //  Check for sign extend parameter attributes on the return values.
-      bool SrcSExt = NewFn->getParamAttrs() &&
-                     NewFn->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
-      bool DestSExt = F->getParamAttrs() &&
-                      F->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
+      bool SrcSExt = NewFn->getParamAttrs().paramHasAttr(0, ParamAttr::SExt);
+      bool DestSExt = F->getParamAttrs().paramHasAttr(0, ParamAttr::SExt);
       
       //  Construct an appropriate cast from the new return type to the old.
-      CastInst *RetCast = CastInst::create(
+      CastInst *RetCast = CastInst::Create(
                             CastInst::getCastOpcode(NewCI, SrcSExt,
                                                     F->getReturnType(),
                                                     DestSExt),
@@ -288,7 +287,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
 
     //  Clean up the old call now that it has been completely upgraded.
     CI->eraseFromParent();
-    break;
+  }
+  break;
   }
 }