Much improved pic jumptable codegen:
[oota-llvm.git] / lib / CodeGen / IntrinsicLowering.cpp
index 0a2f0d6a51713405e03c661a5ccd22af8c704d58..bd3d74d27ac82203590d07e42b49abea3c9e5733 100644 (file)
@@ -99,14 +99,65 @@ void IntrinsicLowering::AddPrototypes(Module &M) {
                               PointerType::get(Type::Int8Ty), Type::Int32Ty, 
                               TD.getIntPtrType(), (Type *)0);
         break;
-      case Intrinsic::sqrt_f32:
-      case Intrinsic::sqrt_f64:
-        if(I->arg_begin()->getType() == Type::FloatTy)
+      case Intrinsic::sqrt:
+        switch((int)I->arg_begin()->getType()->getTypeID()) {
+        case Type::FloatTyID:
           EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(),
                                Type::FloatTy);
-        else
+        case Type::DoubleTyID:
           EnsureFunctionExists(M, "sqrt", I->arg_begin(), I->arg_end(),
                                Type::DoubleTy);
+        case Type::X86_FP80TyID:
+        case Type::FP128TyID:
+        case Type::PPC_FP128TyID:
+          EnsureFunctionExists(M, "sqrtl", I->arg_begin(), I->arg_end(),
+                               I->arg_begin()->getType());
+        }
+        break;
+      case Intrinsic::sin:
+        switch((int)I->arg_begin()->getType()->getTypeID()) {
+        case Type::FloatTyID:
+          EnsureFunctionExists(M, "sinf", I->arg_begin(), I->arg_end(),
+                               Type::FloatTy);
+        case Type::DoubleTyID:
+          EnsureFunctionExists(M, "sin", I->arg_begin(), I->arg_end(),
+                               Type::DoubleTy);
+        case Type::X86_FP80TyID:
+        case Type::FP128TyID:
+        case Type::PPC_FP128TyID:
+          EnsureFunctionExists(M, "sinl", I->arg_begin(), I->arg_end(),
+                               I->arg_begin()->getType());
+        }
+        break;
+      case Intrinsic::cos:
+        switch((int)I->arg_begin()->getType()->getTypeID()) {
+        case Type::FloatTyID:
+          EnsureFunctionExists(M, "cosf", I->arg_begin(), I->arg_end(),
+                               Type::FloatTy);
+        case Type::DoubleTyID:
+          EnsureFunctionExists(M, "cos", I->arg_begin(), I->arg_end(),
+                               Type::DoubleTy);
+        case Type::X86_FP80TyID:
+        case Type::FP128TyID:
+        case Type::PPC_FP128TyID:
+          EnsureFunctionExists(M, "cosl", I->arg_begin(), I->arg_end(),
+                               I->arg_begin()->getType());
+        }
+        break;
+      case Intrinsic::pow:
+        switch((int)I->arg_begin()->getType()->getTypeID()) {
+        case Type::FloatTyID:
+          EnsureFunctionExists(M, "powf", I->arg_begin(), I->arg_end(),
+                               Type::FloatTy);
+        case Type::DoubleTyID:
+          EnsureFunctionExists(M, "pow", I->arg_begin(), I->arg_end(),
+                               Type::DoubleTy);
+        case Type::X86_FP80TyID:
+        case Type::FP128TyID:
+        case Type::PPC_FP128TyID:
+          EnsureFunctionExists(M, "powl", I->arg_begin(), I->arg_end(),
+                               I->arg_begin()->getType());
+        }
         break;
       }
 }
@@ -782,34 +833,27 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
                     MemsetFCache);
     break;
   }
-  case Intrinsic::sqrt_f32: {
+  case Intrinsic::sqrt: {
     static Constant *sqrtfFCache = 0;
-    ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(),
-                    Type::FloatTy, sqrtfFCache);
-    break;
-  }
-  case Intrinsic::sqrt_f64: {
     static Constant *sqrtFCache = 0;
-    ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(),
+    static Constant *sqrtLDCache = 0;
+    switch (CI->getOperand(1)->getType()->getTypeID()) {
+    default: assert(0 && "Invalid type in sqrt"); abort();
+    case Type::FloatTyID:
+      ReplaceCallWith("sqrtf", CI, CI->op_begin()+1, CI->op_end(),
+                    Type::FloatTy, sqrtfFCache);
+      break;
+    case Type::DoubleTyID:
+      ReplaceCallWith("sqrt", CI, CI->op_begin()+1, CI->op_end(),
                     Type::DoubleTy, sqrtFCache);
-    break;
-  }
-  case Intrinsic::sqrt_f80: {
-    static Constant *sqrtF80Cache = 0;
-    ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
-                    Type::X86_FP80Ty, sqrtF80Cache);
-    break;
-  }
-  case Intrinsic::sqrt_f128: {
-    static Constant *sqrtF128Cache = 0;
-    ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
-                    Type::FP128Ty, sqrtF128Cache);
-    break;
-  }
-  case Intrinsic::sqrt_ppcf128: {
-    static Constant *sqrtppcF128Cache = 0;
-    ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
-                    Type::PPC_FP128Ty, sqrtppcF128Cache);
+      break;
+    case Type::X86_FP80TyID:
+    case Type::FP128TyID:
+    case Type::PPC_FP128TyID:
+      ReplaceCallWith("sqrtl", CI, CI->op_begin()+1, CI->op_end(),
+                    CI->getOperand(1)->getType(), sqrtLDCache);
+      break;
+    }
     break;
   }
   }