X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FIntrinsicLowering.cpp;h=7c549bc9a184357aafbe940d75603ead151d283f;hb=49c18cce976c158e86f54c681dff21bb81640fb8;hp=bd3c8c71f5b221c1b5efc707b85a2a939c29ba39;hpb=7cbd8a3e92221437048b484d5ef9c0a22d0f8c58;p=oota-llvm.git diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index bd3c8c71f5b..7c549bc9a18 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -34,6 +34,25 @@ static void EnsureFunctionExists(Module &M, const char *Name, M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false)); } +static void EnsureFPIntrinsicsExist(Module &M, Module::iterator I, + const char *FName, + const char *DName, const char *LDName) { + // Insert definitions for all the floating point types. + switch((int)I->arg_begin()->getType()->getTypeID()) { + case Type::FloatTyID: + EnsureFunctionExists(M, FName, I->arg_begin(), I->arg_end(), + Type::FloatTy); + case Type::DoubleTyID: + EnsureFunctionExists(M, DName, I->arg_begin(), I->arg_end(), + Type::DoubleTy); + case Type::X86_FP80TyID: + case Type::FP128TyID: + case Type::PPC_FP128TyID: + EnsureFunctionExists(M, LDName, I->arg_begin(), I->arg_end(), + I->arg_begin()->getType()); + } +} + /// ReplaceCallWith - This function is used when we want to lower an intrinsic /// call to a call of an external function. This handles hard cases such as /// when there was already a prototype for the external function, and if that @@ -101,64 +120,31 @@ void IntrinsicLowering::AddPrototypes(Module &M) { TD.getIntPtrType(), (Type *)0); break; case Intrinsic::sqrt: - switch((int)I->arg_begin()->getType()->getTypeID()) { - case Type::FloatTyID: - EnsureFunctionExists(M, "sqrtf", I->arg_begin(), I->arg_end(), - Type::FloatTy); - 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()); - } + EnsureFPIntrinsicsExist(M, I, "sqrtf", "sqrt", "sqrtl"); 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()); - } + EnsureFPIntrinsicsExist(M, I, "sinf", "sin", "sinl"); 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()); - } + EnsureFPIntrinsicsExist(M, I, "cosf", "cos", "cosl"); 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()); - } + EnsureFPIntrinsicsExist(M, I, "powf", "pow", "powl"); + break; + case Intrinsic::log: + EnsureFPIntrinsicsExist(M, I, "logf", "log", "logl"); + break; + case Intrinsic::log2: + EnsureFPIntrinsicsExist(M, I, "log2f", "log2", "log2l"); + break; + case Intrinsic::log10: + EnsureFPIntrinsicsExist(M, I, "log10f", "log10", "log10l"); + break; + case Intrinsic::exp: + EnsureFPIntrinsicsExist(M, I, "expf", "exp", "expl"); + break; + case Intrinsic::exp2: + EnsureFPIntrinsicsExist(M, I, "exp2f", "exp2", "exp2l"); break; } } @@ -643,6 +629,28 @@ static Instruction *LowerPartSet(CallInst *CI) { return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI); } +static void ReplaceFPIntrinsicWithCall(CallInst *CI, Constant *FCache, + Constant *DCache, Constant *LDCache, + const char *Fname, const char *Dname, + const char *LDname) { + switch (CI->getOperand(1)->getType()->getTypeID()) { + default: assert(0 && "Invalid type in intrinsic"); abort(); + case Type::FloatTyID: + ReplaceCallWith(Fname, CI, CI->op_begin()+1, CI->op_end(), + Type::FloatTy, FCache); + break; + case Type::DoubleTyID: + ReplaceCallWith(Dname, CI, CI->op_begin()+1, CI->op_end(), + Type::DoubleTy, DCache); + break; + case Type::X86_FP80TyID: + case Type::FP128TyID: + case Type::PPC_FP128TyID: + ReplaceCallWith(LDname, CI, CI->op_begin()+1, CI->op_end(), + CI->getOperand(1)->getType(), LDCache); + break; + } +} void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { Function *Callee = CI->getCalledFunction(); @@ -835,26 +843,59 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { break; } case Intrinsic::sqrt: { - static Constant *sqrtfFCache = 0; static Constant *sqrtFCache = 0; + static Constant *sqrtDCache = 0; 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 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; - } + ReplaceFPIntrinsicWithCall(CI, sqrtFCache, sqrtDCache, sqrtLDCache, + "sqrtf", "sqrt", "sqrtl"); + break; + } + case Intrinsic::log: { + static Constant *logFCache = 0; + static Constant *logDCache = 0; + static Constant *logLDCache = 0; + ReplaceFPIntrinsicWithCall(CI, logFCache, logDCache, logLDCache, + "logf", "log", "logl"); + break; + } + case Intrinsic::log2: { + static Constant *log2FCache = 0; + static Constant *log2DCache = 0; + static Constant *log2LDCache = 0; + ReplaceFPIntrinsicWithCall(CI, log2FCache, log2DCache, log2LDCache, + "log2f", "log2", "log2l"); + break; + } + case Intrinsic::log10: { + static Constant *log10FCache = 0; + static Constant *log10DCache = 0; + static Constant *log10LDCache = 0; + ReplaceFPIntrinsicWithCall(CI, log10FCache, log10DCache, log10LDCache, + "log10f", "log10", "log10l"); + break; + } + case Intrinsic::exp: { + static Constant *expFCache = 0; + static Constant *expDCache = 0; + static Constant *expLDCache = 0; + ReplaceFPIntrinsicWithCall(CI, expFCache, expDCache, expLDCache, + "expf", "exp", "expl"); + break; + } + case Intrinsic::exp2: { + static Constant *exp2FCache = 0; + static Constant *exp2DCache = 0; + static Constant *exp2LDCache = 0; + ReplaceFPIntrinsicWithCall(CI, exp2FCache, exp2DCache, exp2LDCache, + "exp2f", "exp2", "exp2l"); + break; + } + case Intrinsic::pow: { + static Constant *powFCache = 0; + static Constant *powDCache = 0; + static Constant *powLDCache = 0; + ReplaceFPIntrinsicWithCall(CI, powFCache, powDCache, powLDCache, + "powf", "pow", "powl"); break; } case Intrinsic::flt_rounds: