X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FIntrinsicLowering.cpp;h=5c0484f2a7ffa96923b885d586769078058acbb8;hb=e984e504b5f3090ab270cbdab02638ac3a2afb21;hp=ad6feb49180283ec2b34f4cd2a1b9d17f28298da;hpb=976e2da081519d3438da6bf8e5ae7b25cc3433e4;p=oota-llvm.git diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index ad6feb49180..5c0484f2a7f 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -20,6 +20,7 @@ #include "llvm/Support/Streams.h" #include "llvm/Target/TargetData.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" using namespace llvm; template @@ -53,8 +54,8 @@ static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI, FunctionType::get(RetTy, ParamTys, false)); } - SmallVector Operands(ArgBegin, ArgEnd); - CallInst *NewCI = new CallInst(FCache, &Operands[0], Operands.size(), + SmallVector Args(ArgBegin, ArgEnd); + CallInst *NewCI = new CallInst(FCache, Args.begin(), Args.end(), CI->getName(), CI); if (!CI->use_empty()) CI->replaceAllUsesWith(NewCI); @@ -80,32 +81,84 @@ void IntrinsicLowering::AddPrototypes(Module &M) { break; case Intrinsic::memcpy_i32: case Intrinsic::memcpy_i64: - M.getOrInsertFunction("memcpy", PointerType::get(Type::Int8Ty), - PointerType::get(Type::Int8Ty), - PointerType::get(Type::Int8Ty), + M.getOrInsertFunction("memcpy", PointerType::getUnqual(Type::Int8Ty), + PointerType::getUnqual(Type::Int8Ty), + PointerType::getUnqual(Type::Int8Ty), TD.getIntPtrType(), (Type *)0); break; case Intrinsic::memmove_i32: case Intrinsic::memmove_i64: - M.getOrInsertFunction("memmove", PointerType::get(Type::Int8Ty), - PointerType::get(Type::Int8Ty), - PointerType::get(Type::Int8Ty), + M.getOrInsertFunction("memmove", PointerType::getUnqual(Type::Int8Ty), + PointerType::getUnqual(Type::Int8Ty), + PointerType::getUnqual(Type::Int8Ty), TD.getIntPtrType(), (Type *)0); break; case Intrinsic::memset_i32: case Intrinsic::memset_i64: - M.getOrInsertFunction("memset", PointerType::get(Type::Int8Ty), - PointerType::get(Type::Int8Ty), Type::Int32Ty, + M.getOrInsertFunction("memset", PointerType::getUnqual(Type::Int8Ty), + PointerType::getUnqual(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; } } @@ -231,7 +284,7 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) { } } - return CastInst::createIntegerCast(Count, Type::Int32Ty, false, "ctpop", IP); + return Count; } /// LowerCTLZ - Emit the code to lower ctlz of V before the specified @@ -421,7 +474,7 @@ static Instruction *LowerPartSelect(CallInst *CI) { CI->getOperand(2), CI->getOperand(3) }; - return new CallInst(F, Args, sizeof(Args)/sizeof(Args[0]), CI->getName(), CI); + return new CallInst(F, Args, array_endof(Args), CI->getName(), CI); } /// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes @@ -587,7 +640,7 @@ static Instruction *LowerPartSet(CallInst *CI) { CI->getOperand(3), CI->getOperand(4) }; - return new CallInst(F, Args, sizeof(Args)/sizeof(Args[0]), CI->getName(), CI); + return new CallInst(F, Args, array_endof(Args), CI->getName(), CI); } @@ -706,11 +759,23 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::dbg_region_end: case Intrinsic::dbg_func_start: case Intrinsic::dbg_declare: + break; // Simply strip out debugging intrinsics + case Intrinsic::eh_exception: - case Intrinsic::eh_selector: - case Intrinsic::eh_filter: - break; // Simply strip out debugging and eh intrinsics + case Intrinsic::eh_selector_i32: + case Intrinsic::eh_selector_i64: + CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); + break; + case Intrinsic::eh_typeid_for_i32: + case Intrinsic::eh_typeid_for_i64: + // Return something different to eh_selector. + CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); + break; + + case Intrinsic::var_annotation: + break; // Strip out annotate intrinsic + case Intrinsic::memcpy_i32: case Intrinsic::memcpy_i64: { static Constant *MemcpyFCache = 0; @@ -769,18 +834,34 @@ 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 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; } + case Intrinsic::flt_rounds: + // Lower to "round to the nearest" + if (CI->getType() != Type::VoidTy) + CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); + break; } assert(CI->use_empty() &&