Unbreak autouprade of llvm.sqrt, simplify some code.
authorChris Lattner <sabre@nondot.org>
Fri, 3 Mar 2006 16:31:22 +0000 (16:31 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 3 Mar 2006 16:31:22 +0000 (16:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26506 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AutoUpgrade.cpp

index de9d91044c8071c942db098650a6119a387dc2b3..55cde239933bee0d72104d460632d2502e6e80c5 100644 (file)
 #include "llvm/Intrinsics.h"
 #include "llvm/SymbolTable.h"
 #include <iostream>
-
 using namespace llvm;
 
-// Utility function for getting the correct suffix given a type
-static inline const char *getTypeSuffix(const Type* Ty) {
-  switch (Ty->getTypeID()) {
-  case Type::ULongTyID:   return ".i64";
-  case Type::UIntTyID:    return ".i32";
-  case Type::UShortTyID:  return ".i16";
-  case Type::UByteTyID:   return ".i8";
-  case Type::FloatTyID:   return ".f32";
-  case Type::DoubleTyID:  return ".f64";
-  default:                break;                        
-  }
-  return 0;
-}
-
 static Function *getUpgradedUnaryFn(Function *F) {
-  std::string Name = F->getName()+getTypeSuffix(F->getReturnType());
+  const std::string &Name = F->getName();
   Module *M = F->getParent();
   switch (F->getReturnType()->getTypeID()) {
   default: return 0;
   case Type::UByteTyID:
   case Type::SByteTyID:
-    return M->getOrInsertFunction(Name, 
+    return M->getOrInsertFunction(Name+".i8"
                                   Type::UByteTy, Type::UByteTy, NULL);
   case Type::UShortTyID:
   case Type::ShortTyID:
-    return M->getOrInsertFunction(Name, 
+    return M->getOrInsertFunction(Name+".i16"
                                   Type::UShortTy, Type::UShortTy, NULL);
   case Type::UIntTyID:
   case Type::IntTyID:
-    return M->getOrInsertFunction(Name, 
+    return M->getOrInsertFunction(Name+".i32"
                                   Type::UIntTy, Type::UIntTy, NULL);
   case Type::ULongTyID:
   case Type::LongTyID:
-    return M->getOrInsertFunction(Name
+    return M->getOrInsertFunction(Name+".i64",
                                   Type::ULongTy, Type::ULongTy, NULL);
-}
+  case Type::FloatTyID:
+    return M->getOrInsertFunction(Name+".f32",
+                                  Type::FloatTy, Type::FloatTy, NULL);
+  case Type::DoubleTyID:
+    return M->getOrInsertFunction(Name+".f64",
+                                  Type::DoubleTy, Type::DoubleTy, NULL);
+  }
 }
 
 static Function *getUpgradedIntrinsic(Function *F) {
@@ -107,23 +98,6 @@ static Function *getUpgradedIntrinsic(Function *F) {
   return 0;
 }
 
-// This assumes the Function is one of the intrinsics we upgraded.
-static inline const Type* getTypeFromFunction(Function *F) {
-  const Type* Ty = F->getReturnType();
-  if (Ty->isFloatingPoint())
-    return Ty;
-  if (Ty->isSigned())
-    return Ty->getUnsignedVersion();
-  if (Ty->isInteger())
-    return Ty;
-  if (Ty == Type::BoolTy) {
-    Function::const_arg_iterator ArgIt = F->arg_begin();
-    if (ArgIt != F->arg_end()) 
-      return ArgIt->getType();
-  }
-  return 0;
-}
-
 // UpgradeIntrinsicFunction - Convert overloaded intrinsic function names to
 // their non-overloaded variants by appending the appropriate suffix based on
 // the argument types.