LLVM API Documentation
00001 //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the IntrinsicLowering class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Constants.h" 00015 #include "llvm/DerivedTypes.h" 00016 #include "llvm/Module.h" 00017 #include "llvm/Type.h" 00018 #include "llvm/CodeGen/IntrinsicLowering.h" 00019 #include "llvm/Support/IRBuilder.h" 00020 #include "llvm/Support/ErrorHandling.h" 00021 #include "llvm/Target/TargetData.h" 00022 #include "llvm/ADT/SmallVector.h" 00023 using namespace llvm; 00024 00025 template <class ArgIt> 00026 static void EnsureFunctionExists(Module &M, const char *Name, 00027 ArgIt ArgBegin, ArgIt ArgEnd, 00028 const Type *RetTy) { 00029 // Insert a correctly-typed definition now. 00030 std::vector<const Type *> ParamTys; 00031 for (ArgIt I = ArgBegin; I != ArgEnd; ++I) 00032 ParamTys.push_back(I->getType()); 00033 M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false)); 00034 } 00035 00036 static void EnsureFPIntrinsicsExist(Module &M, Function *Fn, 00037 const char *FName, 00038 const char *DName, const char *LDName) { 00039 // Insert definitions for all the floating point types. 00040 switch((int)Fn->arg_begin()->getType()->getTypeID()) { 00041 case Type::FloatTyID: 00042 EnsureFunctionExists(M, FName, Fn->arg_begin(), Fn->arg_end(), 00043 Type::getFloatTy(M.getContext())); 00044 break; 00045 case Type::DoubleTyID: 00046 EnsureFunctionExists(M, DName, Fn->arg_begin(), Fn->arg_end(), 00047 Type::getDoubleTy(M.getContext())); 00048 break; 00049 case Type::X86_FP80TyID: 00050 case Type::FP128TyID: 00051 case Type::PPC_FP128TyID: 00052 EnsureFunctionExists(M, LDName, Fn->arg_begin(), Fn->arg_end(), 00053 Fn->arg_begin()->getType()); 00054 break; 00055 } 00056 } 00057 00058 /// ReplaceCallWith - This function is used when we want to lower an intrinsic 00059 /// call to a call of an external function. This handles hard cases such as 00060 /// when there was already a prototype for the external function, and if that 00061 /// prototype doesn't match the arguments we expect to pass in. 00062 template <class ArgIt> 00063 static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI, 00064 ArgIt ArgBegin, ArgIt ArgEnd, 00065 const Type *RetTy) { 00066 // If we haven't already looked up this function, check to see if the 00067 // program already contains a function with this name. 00068 Module *M = CI->getParent()->getParent()->getParent(); 00069 // Get or insert the definition now. 00070 std::vector<const Type *> ParamTys; 00071 for (ArgIt I = ArgBegin; I != ArgEnd; ++I) 00072 ParamTys.push_back((*I)->getType()); 00073 Constant* FCache = M->getOrInsertFunction(NewFn, 00074 FunctionType::get(RetTy, ParamTys, false)); 00075 00076 IRBuilder<> Builder(CI->getParent(), CI); 00077 SmallVector<Value *, 8> Args(ArgBegin, ArgEnd); 00078 CallInst *NewCI = Builder.CreateCall(FCache, Args.begin(), Args.end()); 00079 NewCI->setName(CI->getName()); 00080 if (!CI->use_empty()) 00081 CI->replaceAllUsesWith(NewCI); 00082 return NewCI; 00083 } 00084 00085 void IntrinsicLowering::AddPrototypes(Module &M) { 00086 LLVMContext &Context = M.getContext(); 00087 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) 00088 if (I->isDeclaration() && !I->use_empty()) 00089 switch (I->getIntrinsicID()) { 00090 default: break; 00091 case Intrinsic::setjmp: 00092 EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(), 00093 Type::getInt32Ty(M.getContext())); 00094 break; 00095 case Intrinsic::longjmp: 00096 EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(), 00097 Type::getVoidTy(M.getContext())); 00098 break; 00099 case Intrinsic::siglongjmp: 00100 EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(), 00101 Type::getVoidTy(M.getContext())); 00102 break; 00103 case Intrinsic::memcpy: 00104 M.getOrInsertFunction("memcpy", 00105 PointerType::getUnqual(Type::getInt8Ty(Context)), 00106 PointerType::getUnqual(Type::getInt8Ty(Context)), 00107 PointerType::getUnqual(Type::getInt8Ty(Context)), 00108 TD.getIntPtrType(Context), (Type *)0); 00109 break; 00110 case Intrinsic::memmove: 00111 M.getOrInsertFunction("memmove", 00112 PointerType::getUnqual(Type::getInt8Ty(Context)), 00113 PointerType::getUnqual(Type::getInt8Ty(Context)), 00114 PointerType::getUnqual(Type::getInt8Ty(Context)), 00115 TD.getIntPtrType(Context), (Type *)0); 00116 break; 00117 case Intrinsic::memset: 00118 M.getOrInsertFunction("memset", 00119 PointerType::getUnqual(Type::getInt8Ty(Context)), 00120 PointerType::getUnqual(Type::getInt8Ty(Context)), 00121 Type::getInt32Ty(M.getContext()), 00122 TD.getIntPtrType(Context), (Type *)0); 00123 break; 00124 case Intrinsic::sqrt: 00125 EnsureFPIntrinsicsExist(M, I, "sqrtf", "sqrt", "sqrtl"); 00126 break; 00127 case Intrinsic::sin: 00128 EnsureFPIntrinsicsExist(M, I, "sinf", "sin", "sinl"); 00129 break; 00130 case Intrinsic::cos: 00131 EnsureFPIntrinsicsExist(M, I, "cosf", "cos", "cosl"); 00132 break; 00133 case Intrinsic::pow: 00134 EnsureFPIntrinsicsExist(M, I, "powf", "pow", "powl"); 00135 break; 00136 case Intrinsic::log: 00137 EnsureFPIntrinsicsExist(M, I, "logf", "log", "logl"); 00138 break; 00139 case Intrinsic::log2: 00140 EnsureFPIntrinsicsExist(M, I, "log2f", "log2", "log2l"); 00141 break; 00142 case Intrinsic::log10: 00143 EnsureFPIntrinsicsExist(M, I, "log10f", "log10", "log10l"); 00144 break; 00145 case Intrinsic::exp: 00146 EnsureFPIntrinsicsExist(M, I, "expf", "exp", "expl"); 00147 break; 00148 case Intrinsic::exp2: 00149 EnsureFPIntrinsicsExist(M, I, "exp2f", "exp2", "exp2l"); 00150 break; 00151 } 00152 } 00153 00154 /// LowerBSWAP - Emit the code to lower bswap of V before the specified 00155 /// instruction IP. 00156 static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) { 00157 assert(V->getType()->isInteger() && "Can't bswap a non-integer type!"); 00158 00159 unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); 00160 00161 IRBuilder<> Builder(IP->getParent(), IP); 00162 00163 switch(BitSize) { 00164 default: llvm_unreachable("Unhandled type size of value to byteswap!"); 00165 case 16: { 00166 Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), 00167 "bswap.2"); 00168 Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), 00169 "bswap.1"); 00170 V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16"); 00171 break; 00172 } 00173 case 32: { 00174 Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), 00175 "bswap.4"); 00176 Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), 00177 "bswap.3"); 00178 Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), 00179 "bswap.2"); 00180 Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24), 00181 "bswap.1"); 00182 Tmp3 = Builder.CreateAnd(Tmp3, 00183 ConstantInt::get(Type::getInt32Ty(Context), 0xFF0000), 00184 "bswap.and3"); 00185 Tmp2 = Builder.CreateAnd(Tmp2, 00186 ConstantInt::get(Type::getInt32Ty(Context), 0xFF00), 00187 "bswap.and2"); 00188 Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1"); 00189 Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2"); 00190 V = Builder.CreateOr(Tmp4, Tmp2, "bswap.i32"); 00191 break; 00192 } 00193 case 64: { 00194 Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56), 00195 "bswap.8"); 00196 Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40), 00197 "bswap.7"); 00198 Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), 00199 "bswap.6"); 00200 Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), 00201 "bswap.5"); 00202 Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), 00203 "bswap.4"); 00204 Value* Tmp3 = Builder.CreateLShr(V, 00205 ConstantInt::get(V->getType(), 24), 00206 "bswap.3"); 00207 Value* Tmp2 = Builder.CreateLShr(V, 00208 ConstantInt::get(V->getType(), 40), 00209 "bswap.2"); 00210 Value* Tmp1 = Builder.CreateLShr(V, 00211 ConstantInt::get(V->getType(), 56), 00212 "bswap.1"); 00213 Tmp7 = Builder.CreateAnd(Tmp7, 00214 ConstantInt::get(Type::getInt64Ty(Context), 00215 0xFF000000000000ULL), 00216 "bswap.and7"); 00217 Tmp6 = Builder.CreateAnd(Tmp6, 00218 ConstantInt::get(Type::getInt64Ty(Context), 00219 0xFF0000000000ULL), 00220 "bswap.and6"); 00221 Tmp5 = Builder.CreateAnd(Tmp5, 00222 ConstantInt::get(Type::getInt64Ty(Context), 00223 0xFF00000000ULL), 00224 "bswap.and5"); 00225 Tmp4 = Builder.CreateAnd(Tmp4, 00226 ConstantInt::get(Type::getInt64Ty(Context), 00227 0xFF000000ULL), 00228 "bswap.and4"); 00229 Tmp3 = Builder.CreateAnd(Tmp3, 00230 ConstantInt::get(Type::getInt64Ty(Context), 00231 0xFF0000ULL), 00232 "bswap.and3"); 00233 Tmp2 = Builder.CreateAnd(Tmp2, 00234 ConstantInt::get(Type::getInt64Ty(Context), 00235 0xFF00ULL), 00236 "bswap.and2"); 00237 Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1"); 00238 Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2"); 00239 Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or3"); 00240 Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or4"); 00241 Tmp8 = Builder.CreateOr(Tmp8, Tmp6, "bswap.or5"); 00242 Tmp4 = Builder.CreateOr(Tmp4, Tmp2, "bswap.or6"); 00243 V = Builder.CreateOr(Tmp8, Tmp4, "bswap.i64"); 00244 break; 00245 } 00246 } 00247 return V; 00248 } 00249 00250 /// LowerCTPOP - Emit the code to lower ctpop of V before the specified 00251 /// instruction IP. 00252 static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) { 00253 assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!"); 00254 00255 static const uint64_t MaskValues[6] = { 00256 0x5555555555555555ULL, 0x3333333333333333ULL, 00257 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, 00258 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL 00259 }; 00260 00261 IRBuilder<> Builder(IP->getParent(), IP); 00262 00263 unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); 00264 unsigned WordSize = (BitSize + 63) / 64; 00265 Value *Count = ConstantInt::get(V->getType(), 0); 00266 00267 for (unsigned n = 0; n < WordSize; ++n) { 00268 Value *PartValue = V; 00269 for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize); 00270 i <<= 1, ++ct) { 00271 Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]); 00272 Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1"); 00273 Value *VShift = Builder.CreateLShr(PartValue, 00274 ConstantInt::get(V->getType(), i), 00275 "ctpop.sh"); 00276 Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2"); 00277 PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step"); 00278 } 00279 Count = Builder.CreateAdd(PartValue, Count, "ctpop.part"); 00280 if (BitSize > 64) { 00281 V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64), 00282 "ctpop.part.sh"); 00283 BitSize -= 64; 00284 } 00285 } 00286 00287 return Count; 00288 } 00289 00290 /// LowerCTLZ - Emit the code to lower ctlz of V before the specified 00291 /// instruction IP. 00292 static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) { 00293 00294 IRBuilder<> Builder(IP->getParent(), IP); 00295 00296 unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); 00297 for (unsigned i = 1; i < BitSize; i <<= 1) { 00298 Value *ShVal = ConstantInt::get(V->getType(), i); 00299 ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh"); 00300 V = Builder.CreateOr(V, ShVal, "ctlz.step"); 00301 } 00302 00303 V = Builder.CreateNot(V); 00304 return LowerCTPOP(Context, V, IP); 00305 } 00306 00307 static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname, 00308 const char *Dname, 00309 const char *LDname) { 00310 switch (CI->getOperand(1)->getType()->getTypeID()) { 00311 default: llvm_unreachable("Invalid type in intrinsic"); 00312 case Type::FloatTyID: 00313 ReplaceCallWith(Fname, CI, CI->op_begin() + 1, CI->op_end(), 00314 Type::getFloatTy(CI->getContext())); 00315 break; 00316 case Type::DoubleTyID: 00317 ReplaceCallWith(Dname, CI, CI->op_begin() + 1, CI->op_end(), 00318 Type::getDoubleTy(CI->getContext())); 00319 break; 00320 case Type::X86_FP80TyID: 00321 case Type::FP128TyID: 00322 case Type::PPC_FP128TyID: 00323 ReplaceCallWith(LDname, CI, CI->op_begin() + 1, CI->op_end(), 00324 CI->getOperand(1)->getType()); 00325 break; 00326 } 00327 } 00328 00329 void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { 00330 IRBuilder<> Builder(CI->getParent(), CI); 00331 LLVMContext &Context = CI->getContext(); 00332 00333 Function *Callee = CI->getCalledFunction(); 00334 assert(Callee && "Cannot lower an indirect call!"); 00335 00336 switch (Callee->getIntrinsicID()) { 00337 case Intrinsic::not_intrinsic: 00338 llvm_report_error("Cannot lower a call to a non-intrinsic function '"+ 00339 Callee->getName() + "'!"); 00340 default: 00341 llvm_report_error("Code generator does not support intrinsic function '"+ 00342 Callee->getName()+"'!"); 00343 00344 // The setjmp/longjmp intrinsics should only exist in the code if it was 00345 // never optimized (ie, right out of the CFE), or if it has been hacked on 00346 // by the lowerinvoke pass. In both cases, the right thing to do is to 00347 // convert the call to an explicit setjmp or longjmp call. 00348 case Intrinsic::setjmp: { 00349 Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin() + 1, CI->op_end(), 00350 Type::getInt32Ty(Context)); 00351 if (CI->getType() != Type::getVoidTy(Context)) 00352 CI->replaceAllUsesWith(V); 00353 break; 00354 } 00355 case Intrinsic::sigsetjmp: 00356 if (CI->getType() != Type::getVoidTy(Context)) 00357 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); 00358 break; 00359 00360 case Intrinsic::longjmp: { 00361 ReplaceCallWith("longjmp", CI, CI->op_begin() + 1, CI->op_end(), 00362 Type::getVoidTy(Context)); 00363 break; 00364 } 00365 00366 case Intrinsic::siglongjmp: { 00367 // Insert the call to abort 00368 ReplaceCallWith("abort", CI, CI->op_end(), CI->op_end(), 00369 Type::getVoidTy(Context)); 00370 break; 00371 } 00372 case Intrinsic::ctpop: 00373 CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getOperand(1), CI)); 00374 break; 00375 00376 case Intrinsic::bswap: 00377 CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getOperand(1), CI)); 00378 break; 00379 00380 case Intrinsic::ctlz: 00381 CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getOperand(1), CI)); 00382 break; 00383 00384 case Intrinsic::cttz: { 00385 // cttz(x) -> ctpop(~X & (X-1)) 00386 Value *Src = CI->getOperand(1); 00387 Value *NotSrc = Builder.CreateNot(Src); 00388 NotSrc->setName(Src->getName() + ".not"); 00389 Value *SrcM1 = ConstantInt::get(Src->getType(), 1); 00390 SrcM1 = Builder.CreateSub(Src, SrcM1); 00391 Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI); 00392 CI->replaceAllUsesWith(Src); 00393 break; 00394 } 00395 00396 case Intrinsic::stacksave: 00397 case Intrinsic::stackrestore: { 00398 if (!Warned) 00399 cerr << "WARNING: this target does not support the llvm.stack" 00400 << (Callee->getIntrinsicID() == Intrinsic::stacksave ? 00401 "save" : "restore") << " intrinsic.\n"; 00402 Warned = true; 00403 if (Callee->getIntrinsicID() == Intrinsic::stacksave) 00404 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); 00405 break; 00406 } 00407 00408 case Intrinsic::returnaddress: 00409 case Intrinsic::frameaddress: 00410 cerr << "WARNING: this target does not support the llvm." 00411 << (Callee->getIntrinsicID() == Intrinsic::returnaddress ? 00412 "return" : "frame") << "address intrinsic.\n"; 00413 CI->replaceAllUsesWith(ConstantPointerNull::get( 00414 cast<PointerType>(CI->getType()))); 00415 break; 00416 00417 case Intrinsic::prefetch: 00418 break; // Simply strip out prefetches on unsupported architectures 00419 00420 case Intrinsic::pcmarker: 00421 break; // Simply strip out pcmarker on unsupported architectures 00422 case Intrinsic::readcyclecounter: { 00423 cerr << "WARNING: this target does not support the llvm.readcyclecoun" 00424 << "ter intrinsic. It is being lowered to a constant 0\n"; 00425 CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0)); 00426 break; 00427 } 00428 00429 case Intrinsic::dbg_stoppoint: 00430 case Intrinsic::dbg_region_start: 00431 case Intrinsic::dbg_region_end: 00432 case Intrinsic::dbg_func_start: 00433 case Intrinsic::dbg_declare: 00434 break; // Simply strip out debugging intrinsics 00435 00436 case Intrinsic::eh_exception: 00437 case Intrinsic::eh_selector_i32: 00438 case Intrinsic::eh_selector_i64: 00439 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); 00440 break; 00441 00442 case Intrinsic::eh_typeid_for_i32: 00443 case Intrinsic::eh_typeid_for_i64: 00444 // Return something different to eh_selector. 00445 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); 00446 break; 00447 00448 case Intrinsic::var_annotation: 00449 break; // Strip out annotate intrinsic 00450 00451 case Intrinsic::memcpy: { 00452 const IntegerType *IntPtr = TD.getIntPtrType(Context); 00453 Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr, 00454 /* isSigned */ false); 00455 Value *Ops[3]; 00456 Ops[0] = CI->getOperand(1); 00457 Ops[1] = CI->getOperand(2); 00458 Ops[2] = Size; 00459 ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getOperand(1)->getType()); 00460 break; 00461 } 00462 case Intrinsic::memmove: { 00463 const IntegerType *IntPtr = TD.getIntPtrType(Context); 00464 Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr, 00465 /* isSigned */ false); 00466 Value *Ops[3]; 00467 Ops[0] = CI->getOperand(1); 00468 Ops[1] = CI->getOperand(2); 00469 Ops[2] = Size; 00470 ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getOperand(1)->getType()); 00471 break; 00472 } 00473 case Intrinsic::memset: { 00474 const IntegerType *IntPtr = TD.getIntPtrType(Context); 00475 Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr, 00476 /* isSigned */ false); 00477 Value *Ops[3]; 00478 Ops[0] = CI->getOperand(1); 00479 // Extend the amount to i32. 00480 Ops[1] = Builder.CreateIntCast(CI->getOperand(2), Type::getInt32Ty(Context), 00481 /* isSigned */ false); 00482 Ops[2] = Size; 00483 ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(1)->getType()); 00484 break; 00485 } 00486 case Intrinsic::sqrt: { 00487 ReplaceFPIntrinsicWithCall(CI, "sqrtf", "sqrt", "sqrtl"); 00488 break; 00489 } 00490 case Intrinsic::log: { 00491 ReplaceFPIntrinsicWithCall(CI, "logf", "log", "logl"); 00492 break; 00493 } 00494 case Intrinsic::log2: { 00495 ReplaceFPIntrinsicWithCall(CI, "log2f", "log2", "log2l"); 00496 break; 00497 } 00498 case Intrinsic::log10: { 00499 ReplaceFPIntrinsicWithCall(CI, "log10f", "log10", "log10l"); 00500 break; 00501 } 00502 case Intrinsic::exp: { 00503 ReplaceFPIntrinsicWithCall(CI, "expf", "exp", "expl"); 00504 break; 00505 } 00506 case Intrinsic::exp2: { 00507 ReplaceFPIntrinsicWithCall(CI, "exp2f", "exp2", "exp2l"); 00508 break; 00509 } 00510 case Intrinsic::pow: { 00511 ReplaceFPIntrinsicWithCall(CI, "powf", "pow", "powl"); 00512 break; 00513 } 00514 case Intrinsic::flt_rounds: 00515 // Lower to "round to the nearest" 00516 if (CI->getType() != Type::getVoidTy(Context)) 00517 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); 00518 break; 00519 } 00520 00521 assert(CI->use_empty() && 00522 "Lowering should have eliminated any uses of the intrinsic call!"); 00523 CI->eraseFromParent(); 00524 }