CMake: removed lib/VMCore/DebugInfoBuilder.cpp.
[oota-llvm.git] / lib / VMCore / AutoUpgrade.cpp
index 7b6369208c1db806a342d2d170e8afb8f24d6653..abad7af79be09502f1e6a8c2fdcc8954089b64da 100644 (file)
@@ -39,6 +39,44 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
   Module *M = F->getParent();
   switch (Name[5]) {
   default: break;
+  case 'a':
+    // This upgrades the llvm.atomic.lcs, llvm.atomic.las, llvm.atomic.lss,
+    // and atomics with default address spaces to their new names to their new
+    // function name (e.g. llvm.atomic.add.i32 => llvm.atomic.add.i32.p0i32)
+    if (Name.compare(5,7,"atomic.",7) == 0) {
+      if (Name.compare(12,3,"lcs",3) == 0) {
+        std::string::size_type delim = Name.find('.',12);
+        F->setName("llvm.atomic.cmp.swap" + Name.substr(delim) +
+                   ".p0" + Name.substr(delim+1));
+        NewFn = F;
+        return true;
+      }
+      else if (Name.compare(12,3,"las",3) == 0) {
+        std::string::size_type delim = Name.find('.',12);
+        F->setName("llvm.atomic.load.add"+Name.substr(delim)
+                   + ".p0" + Name.substr(delim+1));
+        NewFn = F;
+        return true;
+      }
+      else if (Name.compare(12,3,"lss",3) == 0) {
+        std::string::size_type delim = Name.find('.',12);
+        F->setName("llvm.atomic.load.sub"+Name.substr(delim)
+                   + ".p0" + Name.substr(delim+1));
+        NewFn = F;
+        return true;
+      }
+      else if (Name.rfind(".p") == std::string::npos) {
+        // We don't have an address space qualifier so this has be upgraded
+        // to the new name.  Copy the type name at the end of the intrinsic
+        // and add to it
+        std::string::size_type delim = Name.find_last_of('.');
+        assert(delim != std::string::npos && "can not find type");
+        F->setName(Name + ".p0" + Name.substr(delim+1));
+        NewFn = F;
+        return true;
+      }
+    }
+    break;
   case 'b':
     //  This upgrades the name of the llvm.bswap intrinsic function to only use 
     //  a single type name for overloading. We only care about the old format
@@ -180,7 +218,7 @@ bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) {
   if (NewFn)
     F = NewFn;
   if (unsigned id = F->getIntrinsicID(true))
-    F->setParamAttrs(Intrinsic::getParamAttrs((Intrinsic::ID)id));
+    F->setAttributes(Intrinsic::getAttributes((Intrinsic::ID)id));
   return Upgraded;
 }
 
@@ -345,8 +383,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
     //  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().paramHasAttr(0, ParamAttr::SExt);
-      bool DestSExt = F->getParamAttrs().paramHasAttr(0, ParamAttr::SExt);
+      bool SrcSExt = NewFn->getAttributes().paramHasAttr(0, Attribute::SExt);
+      bool DestSExt = F->getAttributes().paramHasAttr(0, Attribute::SExt);
       
       //  Construct an appropriate cast from the new return type to the old.
       CastInst *RetCast = CastInst::Create(
@@ -390,28 +428,3 @@ void llvm::UpgradeCallsToIntrinsic(Function* F) {
     }
   }
 }
-
-/// This is an auto-upgrade hook for mutiple-value return statements.
-/// This function auto-upgrades all such return statements in the given
-/// function to use aggregate return values built with insertvalue
-/// instructions.
-void llvm::UpgradeMultipleReturnValues(Function *CurrentFunction) {
-  for (Function::iterator I = CurrentFunction->begin(),
-       E = CurrentFunction->end(); I != E; ++I) {
-    BasicBlock *BB = I;
-    if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
-      unsigned NumVals = RI->getNumOperands();
-      if (NumVals > 1) {
-        std::vector<const Type *> Types(NumVals);
-        for (unsigned i = 0; i != NumVals; ++i)
-          Types[i] = RI->getOperand(i)->getType();
-        const Type *ReturnType = StructType::get(Types);
-        Value *RV = UndefValue::get(ReturnType);
-        for (unsigned i = 0; i != NumVals; ++i)
-          RV = InsertValueInst::Create(RV, RI->getOperand(i), i, "mrv", RI);
-        ReturnInst::Create(RV, RI);
-        RI->eraseFromParent();
-      }
-    }
-  }
-}