2004-06-20 15:49:54 +08:00
|
|
|
//===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
|
2005-04-22 06:36:52 +08:00
|
|
|
//
|
2004-06-20 15:49:54 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:36:52 +08:00
|
|
|
//
|
2004-06-20 15:49:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-11-16 02:00:10 +08:00
|
|
|
// This file implements the IntrinsicLowering class.
|
2004-06-20 15:49:54 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-29 20:38:19 +08:00
|
|
|
#include "llvm/CodeGen/IntrinsicLowering.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-03-04 19:01:28 +08:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2009-07-11 21:10:19 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-23 14:03:38 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2004-06-20 15:49:54 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
template <class ArgIt>
|
2007-01-07 16:12:01 +08:00
|
|
|
static void EnsureFunctionExists(Module &M, const char *Name,
|
|
|
|
ArgIt ArgBegin, ArgIt ArgEnd,
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *RetTy) {
|
2007-01-07 16:12:01 +08:00
|
|
|
// Insert a correctly-typed definition now.
|
2011-07-12 22:06:48 +08:00
|
|
|
std::vector<Type *> ParamTys;
|
2004-06-20 15:49:54 +08:00
|
|
|
for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
|
|
|
|
ParamTys.push_back(I->getType());
|
2007-01-07 16:12:01 +08:00
|
|
|
M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false));
|
2004-06-20 15:49:54 +08:00
|
|
|
}
|
|
|
|
|
2015-10-10 03:07:41 +08:00
|
|
|
static void EnsureFPIntrinsicsExist(Module &M, Function &Fn,
|
2009-02-08 06:37:06 +08:00
|
|
|
const char *FName,
|
|
|
|
const char *DName, const char *LDName) {
|
2008-09-23 03:51:58 +08:00
|
|
|
// Insert definitions for all the floating point types.
|
2015-10-10 03:07:41 +08:00
|
|
|
switch((int)Fn.arg_begin()->getType()->getTypeID()) {
|
2008-09-23 03:51:58 +08:00
|
|
|
case Type::FloatTyID:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFunctionExists(M, FName, Fn.arg_begin(), Fn.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getFloatTy(M.getContext()));
|
2009-02-08 06:37:06 +08:00
|
|
|
break;
|
2008-09-23 03:51:58 +08:00
|
|
|
case Type::DoubleTyID:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFunctionExists(M, DName, Fn.arg_begin(), Fn.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getDoubleTy(M.getContext()));
|
2009-02-08 06:37:06 +08:00
|
|
|
break;
|
2008-09-23 03:51:58 +08:00
|
|
|
case Type::X86_FP80TyID:
|
|
|
|
case Type::FP128TyID:
|
|
|
|
case Type::PPC_FP128TyID:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFunctionExists(M, LDName, Fn.arg_begin(), Fn.arg_end(),
|
|
|
|
Fn.arg_begin()->getType());
|
2009-02-08 06:37:06 +08:00
|
|
|
break;
|
2008-09-23 03:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 02:34:45 +08:00
|
|
|
/// 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, but that prototype doesn't match the
|
|
|
|
/// arguments we expect to pass in.
|
2004-06-20 15:49:54 +08:00
|
|
|
template <class ArgIt>
|
|
|
|
static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
|
2007-01-07 16:12:01 +08:00
|
|
|
ArgIt ArgBegin, ArgIt ArgEnd,
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *RetTy) {
|
2009-06-27 04:33:47 +08:00
|
|
|
// If we haven't already looked up this function, check to see if the
|
|
|
|
// program already contains a function with this name.
|
2015-12-15 01:24:23 +08:00
|
|
|
Module *M = CI->getModule();
|
2009-06-27 04:33:47 +08:00
|
|
|
// Get or insert the definition now.
|
2011-07-12 22:06:48 +08:00
|
|
|
std::vector<Type *> ParamTys;
|
2009-06-27 04:33:47 +08:00
|
|
|
for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
|
|
|
|
ParamTys.push_back((*I)->getType());
|
|
|
|
Constant* FCache = M->getOrInsertFunction(NewFn,
|
|
|
|
FunctionType::get(RetTy, ParamTys, false));
|
2004-06-20 15:49:54 +08:00
|
|
|
|
2015-10-10 03:13:58 +08:00
|
|
|
IRBuilder<> Builder(CI->getParent(), CI->getIterator());
|
2007-08-01 11:43:44 +08:00
|
|
|
SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
|
2011-07-15 16:37:34 +08:00
|
|
|
CallInst *NewCI = Builder.CreateCall(FCache, Args);
|
2009-05-13 04:27:44 +08:00
|
|
|
NewCI->setName(CI->getName());
|
2007-01-07 16:12:01 +08:00
|
|
|
if (!CI->use_empty())
|
|
|
|
CI->replaceAllUsesWith(NewCI);
|
2004-06-20 15:49:54 +08:00
|
|
|
return NewCI;
|
|
|
|
}
|
|
|
|
|
2010-05-11 14:17:44 +08:00
|
|
|
// VisualStudio defines setjmp as _setjmp
|
2010-09-25 03:48:47 +08:00
|
|
|
#if defined(_MSC_VER) && defined(setjmp) && \
|
|
|
|
!defined(setjmp_undefined_for_msvc)
|
|
|
|
# pragma push_macro("setjmp")
|
|
|
|
# undef setjmp
|
|
|
|
# define setjmp_undefined_for_msvc
|
2010-05-11 14:17:44 +08:00
|
|
|
#endif
|
|
|
|
|
2006-11-16 02:00:10 +08:00
|
|
|
void IntrinsicLowering::AddPrototypes(Module &M) {
|
2009-08-14 05:58:54 +08:00
|
|
|
LLVMContext &Context = M.getContext();
|
2015-10-10 03:07:41 +08:00
|
|
|
for (auto &F : M)
|
|
|
|
if (F.isDeclaration() && !F.use_empty())
|
|
|
|
switch (F.getIntrinsicID()) {
|
2004-06-20 15:49:54 +08:00
|
|
|
default: break;
|
|
|
|
case Intrinsic::setjmp:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFunctionExists(M, "setjmp", F.arg_begin(), F.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getInt32Ty(M.getContext()));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::longjmp:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFunctionExists(M, "longjmp", F.arg_begin(), F.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getVoidTy(M.getContext()));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::siglongjmp:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFunctionExists(M, "abort", F.arg_end(), F.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getVoidTy(M.getContext()));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
2008-11-22 00:42:48 +08:00
|
|
|
case Intrinsic::memcpy:
|
2017-04-07 04:23:57 +08:00
|
|
|
M.getOrInsertFunction("memcpy",
|
|
|
|
Type::getInt8PtrTy(Context),
|
|
|
|
Type::getInt8PtrTy(Context),
|
|
|
|
Type::getInt8PtrTy(Context),
|
2017-04-11 23:01:18 +08:00
|
|
|
DL.getIntPtrType(Context));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
2008-11-22 00:42:48 +08:00
|
|
|
case Intrinsic::memmove:
|
2017-04-07 04:23:57 +08:00
|
|
|
M.getOrInsertFunction("memmove",
|
|
|
|
Type::getInt8PtrTy(Context),
|
|
|
|
Type::getInt8PtrTy(Context),
|
|
|
|
Type::getInt8PtrTy(Context),
|
2017-04-11 23:01:18 +08:00
|
|
|
DL.getIntPtrType(Context));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
2008-11-22 00:42:48 +08:00
|
|
|
case Intrinsic::memset:
|
2017-04-07 04:23:57 +08:00
|
|
|
M.getOrInsertFunction("memset",
|
|
|
|
Type::getInt8PtrTy(Context),
|
|
|
|
Type::getInt8PtrTy(Context),
|
|
|
|
Type::getInt32Ty(M.getContext()),
|
2017-04-11 23:01:18 +08:00
|
|
|
DL.getIntPtrType(Context));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
2007-10-03 01:43:59 +08:00
|
|
|
case Intrinsic::sqrt:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "sqrtf", "sqrt", "sqrtl");
|
2005-04-30 12:07:50 +08:00
|
|
|
break;
|
2007-10-16 06:07:31 +08:00
|
|
|
case Intrinsic::sin:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "sinf", "sin", "sinl");
|
2007-10-16 06:07:31 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::cos:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "cosf", "cos", "cosl");
|
2007-10-16 06:07:31 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::pow:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "powf", "pow", "powl");
|
2007-10-16 06:07:31 +08:00
|
|
|
break;
|
2008-09-04 08:47:13 +08:00
|
|
|
case Intrinsic::log:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "logf", "log", "logl");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::log2:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "log2f", "log2", "log2l");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::log10:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "log10f", "log10", "log10l");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::exp:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "expf", "exp", "expl");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
case Intrinsic::exp2:
|
2015-10-10 03:07:41 +08:00
|
|
|
EnsureFPIntrinsicsExist(M, F, "exp2f", "exp2", "exp2l");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
2004-06-20 15:49:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 02:34:45 +08:00
|
|
|
/// Emit the code to lower bswap of V before the specified instruction IP.
|
2009-07-15 07:09:55 +08:00
|
|
|
static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) {
|
2017-11-30 19:06:22 +08:00
|
|
|
assert(V->getType()->isIntOrIntVectorTy() && "Can't bswap a non-integer type!");
|
2006-01-16 15:57:00 +08:00
|
|
|
|
2017-11-30 19:06:22 +08:00
|
|
|
unsigned BitSize = V->getType()->getScalarSizeInBits();
|
2015-10-10 03:13:58 +08:00
|
|
|
|
|
|
|
IRBuilder<> Builder(IP);
|
2009-05-13 04:27:44 +08:00
|
|
|
|
2006-01-16 15:57:00 +08:00
|
|
|
switch(BitSize) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Unhandled type size of value to byteswap!");
|
2006-01-16 15:57:00 +08:00
|
|
|
case 16: {
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.2");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.1");
|
|
|
|
V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16");
|
2006-01-16 15:57:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 32: {
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.4");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.3");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.2");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.1");
|
2009-07-15 07:09:55 +08:00
|
|
|
Tmp3 = Builder.CreateAnd(Tmp3,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(), 0xFF0000),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.and3");
|
2009-07-15 07:09:55 +08:00
|
|
|
Tmp2 = Builder.CreateAnd(Tmp2,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(), 0xFF00),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.and2");
|
|
|
|
Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
|
|
|
|
Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
|
|
|
|
V = Builder.CreateOr(Tmp4, Tmp2, "bswap.i32");
|
2006-01-16 15:57:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 64: {
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.8");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.7");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.6");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.5");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.4");
|
2009-07-15 07:09:55 +08:00
|
|
|
Value* Tmp3 = Builder.CreateLShr(V,
|
2009-07-25 07:12:02 +08:00
|
|
|
ConstantInt::get(V->getType(), 24),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.3");
|
2009-07-15 07:09:55 +08:00
|
|
|
Value* Tmp2 = Builder.CreateLShr(V,
|
2009-07-25 07:12:02 +08:00
|
|
|
ConstantInt::get(V->getType(), 40),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.2");
|
2009-07-15 07:09:55 +08:00
|
|
|
Value* Tmp1 = Builder.CreateLShr(V,
|
2009-07-25 07:12:02 +08:00
|
|
|
ConstantInt::get(V->getType(), 56),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.1");
|
|
|
|
Tmp7 = Builder.CreateAnd(Tmp7,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(),
|
2009-05-13 04:27:44 +08:00
|
|
|
0xFF000000000000ULL),
|
|
|
|
"bswap.and7");
|
|
|
|
Tmp6 = Builder.CreateAnd(Tmp6,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(),
|
2009-05-13 04:27:44 +08:00
|
|
|
0xFF0000000000ULL),
|
|
|
|
"bswap.and6");
|
|
|
|
Tmp5 = Builder.CreateAnd(Tmp5,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(),
|
2009-08-14 05:58:54 +08:00
|
|
|
0xFF00000000ULL),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.and5");
|
|
|
|
Tmp4 = Builder.CreateAnd(Tmp4,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(),
|
2009-08-14 05:58:54 +08:00
|
|
|
0xFF000000ULL),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.and4");
|
|
|
|
Tmp3 = Builder.CreateAnd(Tmp3,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(),
|
2009-08-14 05:58:54 +08:00
|
|
|
0xFF0000ULL),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.and3");
|
|
|
|
Tmp2 = Builder.CreateAnd(Tmp2,
|
2017-11-30 19:06:22 +08:00
|
|
|
ConstantInt::get(V->getType(),
|
2009-08-14 05:58:54 +08:00
|
|
|
0xFF00ULL),
|
2009-05-13 04:27:44 +08:00
|
|
|
"bswap.and2");
|
|
|
|
Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
|
|
|
|
Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2");
|
|
|
|
Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or3");
|
|
|
|
Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or4");
|
|
|
|
Tmp8 = Builder.CreateOr(Tmp8, Tmp6, "bswap.or5");
|
|
|
|
Tmp4 = Builder.CreateOr(Tmp4, Tmp2, "bswap.or6");
|
|
|
|
V = Builder.CreateOr(Tmp8, Tmp4, "bswap.i64");
|
2006-01-16 15:57:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2017-12-16 02:34:45 +08:00
|
|
|
/// Emit the code to lower ctpop of V before the specified instruction IP.
|
2009-07-15 07:09:55 +08:00
|
|
|
static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) {
|
2010-02-16 00:12:20 +08:00
|
|
|
assert(V->getType()->isIntegerTy() && "Can't ctpop a non-integer type!");
|
2005-05-12 03:42:05 +08:00
|
|
|
|
|
|
|
static const uint64_t MaskValues[6] = {
|
|
|
|
0x5555555555555555ULL, 0x3333333333333333ULL,
|
|
|
|
0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
|
|
|
|
0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
|
|
|
|
};
|
|
|
|
|
2015-10-10 03:13:58 +08:00
|
|
|
IRBuilder<> Builder(IP);
|
2009-05-13 04:27:44 +08:00
|
|
|
|
2005-05-12 04:24:12 +08:00
|
|
|
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
|
2007-06-02 12:10:33 +08:00
|
|
|
unsigned WordSize = (BitSize + 63) / 64;
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *Count = ConstantInt::get(V->getType(), 0);
|
2006-11-08 14:47:33 +08:00
|
|
|
|
2007-06-02 12:10:33 +08:00
|
|
|
for (unsigned n = 0; n < WordSize; ++n) {
|
|
|
|
Value *PartValue = V;
|
|
|
|
for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
|
|
|
|
i <<= 1, ++ct) {
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
|
2009-05-13 04:27:44 +08:00
|
|
|
Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1");
|
|
|
|
Value *VShift = Builder.CreateLShr(PartValue,
|
2009-07-25 07:12:02 +08:00
|
|
|
ConstantInt::get(V->getType(), i),
|
2009-05-13 04:27:44 +08:00
|
|
|
"ctpop.sh");
|
|
|
|
Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2");
|
|
|
|
PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step");
|
2007-06-02 12:10:33 +08:00
|
|
|
}
|
2009-05-13 04:27:44 +08:00
|
|
|
Count = Builder.CreateAdd(PartValue, Count, "ctpop.part");
|
2007-06-02 12:10:33 +08:00
|
|
|
if (BitSize > 64) {
|
2009-07-25 07:12:02 +08:00
|
|
|
V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64),
|
2009-05-13 04:27:44 +08:00
|
|
|
"ctpop.part.sh");
|
2007-06-02 12:10:33 +08:00
|
|
|
BitSize -= 64;
|
|
|
|
}
|
2005-05-12 03:42:05 +08:00
|
|
|
}
|
|
|
|
|
2007-08-07 00:36:18 +08:00
|
|
|
return Count;
|
2005-05-12 03:42:05 +08:00
|
|
|
}
|
|
|
|
|
2017-12-16 02:34:45 +08:00
|
|
|
/// Emit the code to lower ctlz of V before the specified instruction IP.
|
2009-07-15 07:09:55 +08:00
|
|
|
static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) {
|
2005-05-12 04:24:12 +08:00
|
|
|
|
2015-10-10 03:13:58 +08:00
|
|
|
IRBuilder<> Builder(IP);
|
2009-05-13 04:27:44 +08:00
|
|
|
|
2005-05-12 04:24:12 +08:00
|
|
|
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
|
2007-06-02 12:10:33 +08:00
|
|
|
for (unsigned i = 1; i < BitSize; i <<= 1) {
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *ShVal = ConstantInt::get(V->getType(), i);
|
2009-05-13 04:27:44 +08:00
|
|
|
ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh");
|
|
|
|
V = Builder.CreateOr(V, ShVal, "ctlz.step");
|
2005-05-12 04:24:12 +08:00
|
|
|
}
|
|
|
|
|
2009-05-13 04:27:44 +08:00
|
|
|
V = Builder.CreateNot(V);
|
2009-07-15 07:09:55 +08:00
|
|
|
return LowerCTPOP(Context, V, IP);
|
2005-05-12 04:24:12 +08:00
|
|
|
}
|
|
|
|
|
2009-06-27 04:33:47 +08:00
|
|
|
static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname,
|
|
|
|
const char *Dname,
|
2008-09-23 04:51:30 +08:00
|
|
|
const char *LDname) {
|
2010-06-25 17:03:52 +08:00
|
|
|
CallSite CS(CI);
|
|
|
|
switch (CI->getArgOperand(0)->getType()->getTypeID()) {
|
2009-07-15 00:55:14 +08:00
|
|
|
default: llvm_unreachable("Invalid type in intrinsic");
|
2008-09-23 04:51:30 +08:00
|
|
|
case Type::FloatTyID:
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith(Fname, CI, CS.arg_begin(), CS.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getFloatTy(CI->getContext()));
|
2008-09-23 04:51:30 +08:00
|
|
|
break;
|
|
|
|
case Type::DoubleTyID:
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith(Dname, CI, CS.arg_begin(), CS.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getDoubleTy(CI->getContext()));
|
2008-09-23 04:51:30 +08:00
|
|
|
break;
|
|
|
|
case Type::X86_FP80TyID:
|
|
|
|
case Type::FP128TyID:
|
|
|
|
case Type::PPC_FP128TyID:
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith(LDname, CI, CS.arg_begin(), CS.arg_end(),
|
|
|
|
CI->getArgOperand(0)->getType());
|
2008-09-23 04:51:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-05 07:48:25 +08:00
|
|
|
|
2006-11-16 02:00:10 +08:00
|
|
|
void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
2015-10-10 03:13:58 +08:00
|
|
|
IRBuilder<> Builder(CI);
|
2009-07-22 08:24:57 +08:00
|
|
|
LLVMContext &Context = CI->getContext();
|
2009-05-13 04:27:44 +08:00
|
|
|
|
2010-04-15 09:51:59 +08:00
|
|
|
const Function *Callee = CI->getCalledFunction();
|
2004-06-20 15:49:54 +08:00
|
|
|
assert(Callee && "Cannot lower an indirect call!");
|
2005-04-22 06:36:52 +08:00
|
|
|
|
2010-06-25 17:03:52 +08:00
|
|
|
CallSite CS(CI);
|
2004-06-20 15:49:54 +08:00
|
|
|
switch (Callee->getIntrinsicID()) {
|
|
|
|
case Intrinsic::not_intrinsic:
|
2010-04-08 06:58:41 +08:00
|
|
|
report_fatal_error("Cannot lower a call to a non-intrinsic function '"+
|
2009-07-11 21:10:19 +08:00
|
|
|
Callee->getName() + "'!");
|
2004-06-20 15:49:54 +08:00
|
|
|
default:
|
2010-04-08 06:58:41 +08:00
|
|
|
report_fatal_error("Code generator does not support intrinsic function '"+
|
2009-07-11 21:10:19 +08:00
|
|
|
Callee->getName()+"'!");
|
2004-06-20 15:49:54 +08:00
|
|
|
|
2011-07-07 02:22:43 +08:00
|
|
|
case Intrinsic::expect: {
|
|
|
|
// Just replace __builtin_expect(exp, c) with EXP.
|
|
|
|
Value *V = CI->getArgOperand(0);
|
|
|
|
CI->replaceAllUsesWith(V);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-20 15:49:54 +08:00
|
|
|
// The setjmp/longjmp intrinsics should only exist in the code if it was
|
|
|
|
// never optimized (ie, right out of the CFE), or if it has been hacked on
|
|
|
|
// by the lowerinvoke pass. In both cases, the right thing to do is to
|
|
|
|
// convert the call to an explicit setjmp or longjmp call.
|
|
|
|
case Intrinsic::setjmp: {
|
2010-06-25 17:03:52 +08:00
|
|
|
Value *V = ReplaceCallWith("setjmp", CI, CS.arg_begin(), CS.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getInt32Ty(Context));
|
2010-01-05 21:12:22 +08:00
|
|
|
if (!CI->getType()->isVoidTy())
|
2004-06-20 15:49:54 +08:00
|
|
|
CI->replaceAllUsesWith(V);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-22 06:36:52 +08:00
|
|
|
case Intrinsic::sigsetjmp:
|
2010-01-05 21:12:22 +08:00
|
|
|
if (!CI->getType()->isVoidTy())
|
2009-08-01 04:28:14 +08:00
|
|
|
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Intrinsic::longjmp: {
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith("longjmp", CI, CS.arg_begin(), CS.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getVoidTy(Context));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Intrinsic::siglongjmp: {
|
|
|
|
// Insert the call to abort
|
2010-06-30 20:39:23 +08:00
|
|
|
ReplaceCallWith("abort", CI, CS.arg_end(), CS.arg_end(),
|
2009-08-14 05:58:54 +08:00
|
|
|
Type::getVoidTy(Context));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-04-01 15:35:23 +08:00
|
|
|
case Intrinsic::ctpop:
|
2010-06-25 17:03:52 +08:00
|
|
|
CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getArgOperand(0), CI));
|
For PR411:
This patch is an incremental step towards supporting a flat symbol table.
It de-overloads the intrinsic functions by providing type-specific intrinsics
and arranging for automatically upgrading from the old overloaded name to
the new non-overloaded name. Specifically:
llvm.isunordered -> llvm.isunordered.f32, llvm.isunordered.f64
llvm.sqrt -> llvm.sqrt.f32, llvm.sqrt.f64
llvm.ctpop -> llvm.ctpop.i8, llvm.ctpop.i16, llvm.ctpop.i32, llvm.ctpop.i64
llvm.ctlz -> llvm.ctlz.i8, llvm.ctlz.i16, llvm.ctlz.i32, llvm.ctlz.i64
llvm.cttz -> llvm.cttz.i8, llvm.cttz.i16, llvm.cttz.i32, llvm.cttz.i64
New code should not use the overloaded intrinsic names. Warnings will be
emitted if they are used.
llvm-svn: 25366
2006-01-17 05:12:35 +08:00
|
|
|
break;
|
|
|
|
|
2007-04-01 15:35:23 +08:00
|
|
|
case Intrinsic::bswap:
|
2010-06-25 17:03:52 +08:00
|
|
|
CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getArgOperand(0), CI));
|
2006-01-16 15:57:00 +08:00
|
|
|
break;
|
|
|
|
|
2007-04-01 15:35:23 +08:00
|
|
|
case Intrinsic::ctlz:
|
2010-06-25 17:03:52 +08:00
|
|
|
CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getArgOperand(0), CI));
|
2005-05-04 01:19:30 +08:00
|
|
|
break;
|
2006-01-16 15:57:00 +08:00
|
|
|
|
2007-04-01 15:35:23 +08:00
|
|
|
case Intrinsic::cttz: {
|
2005-05-12 04:02:14 +08:00
|
|
|
// cttz(x) -> ctpop(~X & (X-1))
|
2010-06-25 17:03:52 +08:00
|
|
|
Value *Src = CI->getArgOperand(0);
|
2009-05-13 04:27:44 +08:00
|
|
|
Value *NotSrc = Builder.CreateNot(Src);
|
|
|
|
NotSrc->setName(Src->getName() + ".not");
|
2009-07-25 07:12:02 +08:00
|
|
|
Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
|
2009-05-13 04:27:44 +08:00
|
|
|
SrcM1 = Builder.CreateSub(Src, SrcM1);
|
2009-07-22 08:24:57 +08:00
|
|
|
Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
|
2005-05-04 01:19:30 +08:00
|
|
|
CI->replaceAllUsesWith(Src);
|
|
|
|
break;
|
|
|
|
}
|
2004-06-20 15:49:54 +08:00
|
|
|
|
2006-01-13 10:22:08 +08:00
|
|
|
case Intrinsic::stacksave:
|
2013-02-09 05:48:29 +08:00
|
|
|
case Intrinsic::stackrestore: {
|
2006-01-13 10:22:08 +08:00
|
|
|
if (!Warned)
|
2013-02-09 05:48:29 +08:00
|
|
|
errs() << "WARNING: this target does not support the llvm.stack"
|
|
|
|
<< (Callee->getIntrinsicID() == Intrinsic::stacksave ?
|
|
|
|
"save" : "restore") << " intrinsic.\n";
|
2006-01-13 10:22:08 +08:00
|
|
|
Warned = true;
|
2013-02-09 05:48:29 +08:00
|
|
|
if (Callee->getIntrinsicID() == Intrinsic::stacksave)
|
|
|
|
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
|
2006-01-13 10:22:08 +08:00
|
|
|
break;
|
2013-02-09 05:48:29 +08:00
|
|
|
}
|
2006-01-13 10:22:08 +08:00
|
|
|
|
2015-12-01 19:40:55 +08:00
|
|
|
case Intrinsic::get_dynamic_area_offset:
|
|
|
|
errs() << "WARNING: this target does not support the custom llvm.get."
|
|
|
|
"dynamic.area.offset. It is being lowered to a constant 0\n";
|
|
|
|
// Just lower it to a constant 0 because for most targets
|
|
|
|
// @llvm.get.dynamic.area.offset is lowered to zero.
|
|
|
|
CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 0));
|
|
|
|
break;
|
2004-06-20 15:49:54 +08:00
|
|
|
case Intrinsic::returnaddress:
|
|
|
|
case Intrinsic::frameaddress:
|
2013-02-09 05:48:29 +08:00
|
|
|
errs() << "WARNING: this target does not support the llvm."
|
|
|
|
<< (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
|
|
|
|
"return" : "frame") << "address intrinsic.\n";
|
2016-10-13 06:13:19 +08:00
|
|
|
CI->replaceAllUsesWith(
|
|
|
|
ConstantPointerNull::get(cast<PointerType>(CI->getType())));
|
|
|
|
break;
|
|
|
|
case Intrinsic::addressofreturnaddress:
|
|
|
|
errs() << "WARNING: this target does not support the "
|
|
|
|
"llvm.addressofreturnaddress intrinsic.\n";
|
|
|
|
CI->replaceAllUsesWith(
|
|
|
|
ConstantPointerNull::get(cast<PointerType>(CI->getType())));
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
|
2005-03-01 03:27:23 +08:00
|
|
|
case Intrinsic::prefetch:
|
|
|
|
break; // Simply strip out prefetches on unsupported architectures
|
|
|
|
|
2005-03-29 04:05:49 +08:00
|
|
|
case Intrinsic::pcmarker:
|
|
|
|
break; // Simply strip out pcmarker on unsupported architectures
|
2013-02-09 05:48:29 +08:00
|
|
|
case Intrinsic::readcyclecounter: {
|
|
|
|
errs() << "WARNING: this target does not support the llvm.readcyclecoun"
|
|
|
|
<< "ter intrinsic. It is being lowered to a constant 0\n";
|
2009-08-14 05:58:54 +08:00
|
|
|
CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0));
|
2005-11-12 00:47:30 +08:00
|
|
|
break;
|
2013-02-09 05:48:29 +08:00
|
|
|
}
|
2005-03-29 04:05:49 +08:00
|
|
|
|
2006-03-24 02:06:46 +08:00
|
|
|
case Intrinsic::dbg_declare:
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
|
|
|
case Intrinsic::dbg_label:
|
2007-07-06 22:46:23 +08:00
|
|
|
break; // Simply strip out debugging intrinsics
|
|
|
|
|
2009-10-15 00:11:37 +08:00
|
|
|
case Intrinsic::eh_typeid_for:
|
2007-07-06 22:46:23 +08:00
|
|
|
// Return something different to eh_selector.
|
2009-07-25 07:12:02 +08:00
|
|
|
CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
|
2007-07-06 22:46:23 +08:00
|
|
|
break;
|
2004-06-20 15:49:54 +08:00
|
|
|
|
2013-05-21 22:37:16 +08:00
|
|
|
case Intrinsic::annotation:
|
|
|
|
case Intrinsic::ptr_annotation:
|
|
|
|
// Just drop the annotation, but forward the value
|
|
|
|
CI->replaceAllUsesWith(CI->getOperand(0));
|
|
|
|
break;
|
|
|
|
|
2014-07-26 05:13:35 +08:00
|
|
|
case Intrinsic::assume:
|
2007-06-16 06:26:58 +08:00
|
|
|
case Intrinsic::var_annotation:
|
2014-07-26 05:13:35 +08:00
|
|
|
break; // Strip out these intrinsics
|
|
|
|
|
2008-11-22 00:42:48 +08:00
|
|
|
case Intrinsic::memcpy: {
|
2014-02-18 23:33:12 +08:00
|
|
|
Type *IntPtr = DL.getIntPtrType(Context);
|
2010-06-25 17:03:52 +08:00
|
|
|
Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
|
2009-05-13 04:27:44 +08:00
|
|
|
/* isSigned */ false);
|
2007-02-07 03:06:38 +08:00
|
|
|
Value *Ops[3];
|
2010-06-25 17:03:52 +08:00
|
|
|
Ops[0] = CI->getArgOperand(0);
|
|
|
|
Ops[1] = CI->getArgOperand(1);
|
2007-02-07 03:06:38 +08:00
|
|
|
Ops[2] = Size;
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-22 00:42:48 +08:00
|
|
|
case Intrinsic::memmove: {
|
2014-02-18 23:33:12 +08:00
|
|
|
Type *IntPtr = DL.getIntPtrType(Context);
|
2010-06-25 17:03:52 +08:00
|
|
|
Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
|
2009-05-13 04:27:44 +08:00
|
|
|
/* isSigned */ false);
|
2007-02-07 03:06:38 +08:00
|
|
|
Value *Ops[3];
|
2010-06-25 17:03:52 +08:00
|
|
|
Ops[0] = CI->getArgOperand(0);
|
|
|
|
Ops[1] = CI->getArgOperand(1);
|
2007-02-07 03:06:38 +08:00
|
|
|
Ops[2] = Size;
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
|
2007-02-07 03:06:38 +08:00
|
|
|
break;
|
2006-11-27 09:05:10 +08:00
|
|
|
}
|
2008-11-22 00:42:48 +08:00
|
|
|
case Intrinsic::memset: {
|
2013-11-10 12:46:57 +08:00
|
|
|
Value *Op0 = CI->getArgOperand(0);
|
2014-02-18 23:33:12 +08:00
|
|
|
Type *IntPtr = DL.getIntPtrType(Op0->getType());
|
2010-06-25 17:03:52 +08:00
|
|
|
Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
|
2009-05-13 04:27:44 +08:00
|
|
|
/* isSigned */ false);
|
2007-02-07 03:06:38 +08:00
|
|
|
Value *Ops[3];
|
2013-11-10 12:46:57 +08:00
|
|
|
Ops[0] = Op0;
|
2007-02-07 03:06:38 +08:00
|
|
|
// Extend the amount to i32.
|
2010-07-22 18:37:47 +08:00
|
|
|
Ops[1] = Builder.CreateIntCast(CI->getArgOperand(1),
|
|
|
|
Type::getInt32Ty(Context),
|
2009-05-13 04:27:44 +08:00
|
|
|
/* isSigned */ false);
|
2007-02-07 03:06:38 +08:00
|
|
|
Ops[2] = Size;
|
2010-06-25 17:03:52 +08:00
|
|
|
ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
|
2004-06-20 15:49:54 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-10-03 01:43:59 +08:00
|
|
|
case Intrinsic::sqrt: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "sqrtf", "sqrt", "sqrtl");
|
2007-09-29 02:06:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-09-04 08:47:13 +08:00
|
|
|
case Intrinsic::log: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "logf", "log", "logl");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::log2: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "log2f", "log2", "log2l");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::log10: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "log10f", "log10", "log10l");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::exp: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "expf", "exp", "expl");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::exp2: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "exp2f", "exp2", "exp2l");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::pow: {
|
2009-06-27 04:33:47 +08:00
|
|
|
ReplaceFPIntrinsicWithCall(CI, "powf", "pow", "powl");
|
2008-09-04 08:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-08-08 23:00:12 +08:00
|
|
|
case Intrinsic::sin: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "sinf", "sin", "sinl");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::cos: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "cosf", "cos", "cosl");
|
|
|
|
break;
|
|
|
|
}
|
2014-08-31 02:33:35 +08:00
|
|
|
case Intrinsic::floor: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "floorf", "floor", "floorl");
|
|
|
|
break;
|
|
|
|
}
|
2014-08-08 23:00:12 +08:00
|
|
|
case Intrinsic::ceil: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "ceilf", "ceil", "ceill");
|
|
|
|
break;
|
|
|
|
}
|
2014-08-31 02:33:35 +08:00
|
|
|
case Intrinsic::trunc: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "truncf", "trunc", "truncl");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::round: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "roundf", "round", "roundl");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Intrinsic::copysign: {
|
|
|
|
ReplaceFPIntrinsicWithCall(CI, "copysignf", "copysign", "copysignl");
|
|
|
|
break;
|
|
|
|
}
|
2007-11-16 07:25:33 +08:00
|
|
|
case Intrinsic::flt_rounds:
|
|
|
|
// Lower to "round to the nearest"
|
2010-01-05 21:12:22 +08:00
|
|
|
if (!CI->getType()->isVoidTy())
|
2009-07-25 07:12:02 +08:00
|
|
|
CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
|
2007-11-16 07:25:33 +08:00
|
|
|
break;
|
2009-11-10 17:08:09 +08:00
|
|
|
case Intrinsic::invariant_start:
|
|
|
|
case Intrinsic::lifetime_start:
|
|
|
|
// Discard region information.
|
|
|
|
CI->replaceAllUsesWith(UndefValue::get(CI->getType()));
|
|
|
|
break;
|
|
|
|
case Intrinsic::invariant_end:
|
|
|
|
case Intrinsic::lifetime_end:
|
|
|
|
// Discard region information.
|
|
|
|
break;
|
2004-06-20 15:49:54 +08:00
|
|
|
}
|
2005-04-22 06:36:52 +08:00
|
|
|
|
2004-06-20 15:49:54 +08:00
|
|
|
assert(CI->use_empty() &&
|
|
|
|
"Lowering should have eliminated any uses of the intrinsic call!");
|
2005-05-12 03:42:05 +08:00
|
|
|
CI->eraseFromParent();
|
2004-06-20 15:49:54 +08:00
|
|
|
}
|
2011-01-08 09:24:27 +08:00
|
|
|
|
|
|
|
bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) {
|
|
|
|
// Verify this is a simple bswap.
|
|
|
|
if (CI->getNumArgOperands() != 1 ||
|
|
|
|
CI->getType() != CI->getArgOperand(0)->getType() ||
|
|
|
|
!CI->getType()->isIntegerTy())
|
|
|
|
return false;
|
|
|
|
|
2011-07-12 22:06:48 +08:00
|
|
|
IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
|
2011-01-08 09:24:27 +08:00
|
|
|
if (!Ty)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Okay, we can do this xform, do so now.
|
2015-12-15 01:24:23 +08:00
|
|
|
Module *M = CI->getModule();
|
2011-07-15 01:45:39 +08:00
|
|
|
Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
|
2011-01-08 09:24:27 +08:00
|
|
|
|
|
|
|
Value *Op = CI->getArgOperand(0);
|
|
|
|
Op = CallInst::Create(Int, Op, CI->getName(), CI);
|
|
|
|
|
|
|
|
CI->replaceAllUsesWith(Op);
|
|
|
|
CI->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|