27 template <
class ArgIt>
29 ArgIt ArgBegin, ArgIt ArgEnd,
32 std::vector<Type *> ParamTys;
33 for (ArgIt
I = ArgBegin;
I != ArgEnd; ++
I)
34 ParamTys.push_back(
I->getType());
40 const char *DName,
const char *LDName) {
42 switch((
int)Fn->
arg_begin()->getType()->getTypeID()) {
64 template <
class ArgIt>
66 ArgIt ArgBegin, ArgIt ArgEnd,
72 std::vector<Type *> ParamTys;
73 for (ArgIt
I = ArgBegin;
I != ArgEnd; ++
I)
74 ParamTys.push_back((*I)->getType());
80 CallInst *NewCI = Builder.CreateCall(FCache, Args);
88 #if defined(_MSC_VER) && defined(setjmp) && \
89 !defined(setjmp_undefined_for_msvc)
90 # pragma push_macro("setjmp")
92 # define setjmp_undefined_for_msvc
98 if (
I->isDeclaration() && !
I->use_empty())
99 switch (
I->getIntrinsicID()) {
101 case Intrinsic::setjmp:
105 case Intrinsic::longjmp:
109 case Intrinsic::siglongjmp:
113 case Intrinsic::memcpy:
120 case Intrinsic::memmove:
127 case Intrinsic::memset:
134 case Intrinsic::sqrt:
149 case Intrinsic::log2:
152 case Intrinsic::log10:
158 case Intrinsic::exp2:
180 V = Builder.CreateOr(Tmp1, Tmp2,
"bswap.i16");
192 Tmp3 = Builder.CreateAnd(Tmp3,
195 Tmp2 = Builder.CreateAnd(Tmp2,
198 Tmp4 = Builder.CreateOr(Tmp4, Tmp3,
"bswap.or1");
199 Tmp2 = Builder.CreateOr(Tmp2, Tmp1,
"bswap.or2");
200 V = Builder.CreateOr(Tmp4, Tmp2,
"bswap.i32");
214 Value* Tmp3 = Builder.CreateLShr(V,
217 Value* Tmp2 = Builder.CreateLShr(V,
220 Value* Tmp1 = Builder.CreateLShr(V,
223 Tmp7 = Builder.CreateAnd(Tmp7,
225 0xFF000000000000ULL),
227 Tmp6 = Builder.CreateAnd(Tmp6,
231 Tmp5 = Builder.CreateAnd(Tmp5,
235 Tmp4 = Builder.CreateAnd(Tmp4,
239 Tmp3 = Builder.CreateAnd(Tmp3,
243 Tmp2 = Builder.CreateAnd(Tmp2,
247 Tmp8 = Builder.CreateOr(Tmp8, Tmp7,
"bswap.or1");
248 Tmp6 = Builder.CreateOr(Tmp6, Tmp5,
"bswap.or2");
249 Tmp4 = Builder.CreateOr(Tmp4, Tmp3,
"bswap.or3");
250 Tmp2 = Builder.CreateOr(Tmp2, Tmp1,
"bswap.or4");
251 Tmp8 = Builder.CreateOr(Tmp8, Tmp6,
"bswap.or5");
252 Tmp4 = Builder.CreateOr(Tmp4, Tmp2,
"bswap.or6");
253 V = Builder.CreateOr(Tmp8, Tmp4,
"bswap.i64");
265 static const uint64_t MaskValues[6] = {
266 0x5555555555555555ULL, 0x3333333333333333ULL,
267 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
268 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
274 unsigned WordSize = (BitSize + 63) / 64;
277 for (
unsigned n = 0; n < WordSize; ++n) {
278 Value *PartValue = V;
279 for (
unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
282 Value *LHS = Builder.CreateAnd(PartValue, MaskCst,
"cppop.and1");
283 Value *VShift = Builder.CreateLShr(PartValue,
286 Value *RHS = Builder.CreateAnd(VShift, MaskCst,
"cppop.and2");
287 PartValue = Builder.CreateAdd(LHS, RHS,
"ctpop.step");
289 Count = Builder.CreateAdd(PartValue, Count,
"ctpop.part");
307 for (
unsigned i = 1; i < BitSize; i <<= 1) {
309 ShVal = Builder.CreateLShr(V, ShVal,
"ctlz.sh");
310 V = Builder.CreateOr(V, ShVal,
"ctlz.step");
313 V = Builder.CreateNot(V);
319 const char *LDname) {
345 assert(Callee &&
"Cannot lower an indirect call!");
356 case Intrinsic::expect: {
367 case Intrinsic::setjmp: {
374 case Intrinsic::sigsetjmp:
379 case Intrinsic::longjmp: {
385 case Intrinsic::siglongjmp: {
391 case Intrinsic::ctpop:
395 case Intrinsic::bswap:
399 case Intrinsic::ctlz:
403 case Intrinsic::cttz: {
406 Value *NotSrc = Builder.CreateNot(Src);
409 SrcM1 = Builder.CreateSub(Src, SrcM1);
415 case Intrinsic::stacksave:
416 case Intrinsic::stackrestore: {
418 errs() <<
"WARNING: this target does not support the llvm.stack"
420 "save" :
"restore") <<
" intrinsic.\n";
427 case Intrinsic::returnaddress:
428 case Intrinsic::frameaddress:
429 errs() <<
"WARNING: this target does not support the llvm."
431 "return" :
"frame") <<
"address intrinsic.\n";
433 cast<PointerType>(CI->
getType())));
439 case Intrinsic::pcmarker:
441 case Intrinsic::readcyclecounter: {
442 errs() <<
"WARNING: this target does not support the llvm.readcyclecoun"
443 <<
"ter intrinsic. It is being lowered to a constant 0\n";
448 case Intrinsic::dbg_declare:
451 case Intrinsic::eh_typeid_for:
456 case Intrinsic::annotation:
457 case Intrinsic::ptr_annotation:
462 case Intrinsic::assume:
463 case Intrinsic::var_annotation:
466 case Intrinsic::memcpy: {
477 case Intrinsic::memmove: {
488 case Intrinsic::memset: {
503 case Intrinsic::sqrt: {
507 case Intrinsic::log: {
511 case Intrinsic::log2: {
515 case Intrinsic::log10: {
519 case Intrinsic::exp: {
523 case Intrinsic::exp2: {
527 case Intrinsic::pow: {
531 case Intrinsic::sin: {
535 case Intrinsic::cos: {
539 case Intrinsic::floor: {
543 case Intrinsic::ceil: {
547 case Intrinsic::trunc: {
551 case Intrinsic::round: {
555 case Intrinsic::copysign: {
559 case Intrinsic::flt_rounds:
564 case Intrinsic::invariant_start:
565 case Intrinsic::lifetime_start:
569 case Intrinsic::invariant_end:
570 case Intrinsic::lifetime_end:
576 "Lowering should have eliminated any uses of the intrinsic call!");
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
static Type * getDoubleTy(LLVMContext &C)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
A Module instance is used to store all the information related to an LLVM module. ...
static CallInst * ReplaceCallWith(const char *NewFn, CallInst *CI, ArgIt ArgBegin, ArgIt ArgEnd, Type *RetTy)
ReplaceCallWith - This function is used when we want to lower an intrinsic call to a call of an exter...
2: 32-bit floating point type
CallInst - This class represents a function call, abstracting a target machine's calling convention...
const Function * getParent() const
Return the enclosing method, or null if none.
4: 80-bit floating point type (X87)
static IntegerType * getInt64Ty(LLVMContext &C)
static void EnsureFPIntrinsicsExist(Module &M, Function *Fn, const char *FName, const char *DName, const char *LDName)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Return a constant reference to the value's name.
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static Type * getFloatTy(LLVMContext &C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumArgOperands() const
getNumArgOperands - Return the number of call arguments.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static void EnsureFunctionExists(Module &M, const char *Name, ArgIt ArgBegin, ArgIt ArgEnd, Type *RetTy)
static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname, const char *Dname, const char *LDname)
void setName(const Twine &Name)
Change the name of the value.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
TypeID getTypeID() const
getTypeID - Return the type id for the type.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static Value * LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP)
LowerBSWAP - Emit the code to lower bswap of V before the specified instruction IP.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Type * getVoidTy(LLVMContext &C)
6: 128-bit floating point type (two 64-bits, PowerPC)
Value * getOperand(unsigned i) const
Class to represent integer types.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static Value * LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP)
LowerCTPOP - Emit the code to lower ctpop of V before the specified instruction IP.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
void AddPrototypes(Module &M)
AddPrototypes - This method, if called, causes all of the prototypes that might be needed by an intri...
static Value * LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP)
LowerCTLZ - Emit the code to lower ctlz of V before the specified instruction IP. ...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Function * getCalledFunction() const
getCalledFunction - Return the function called, or null if this is an indirect function invocation...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static bool LowerToByteSwap(CallInst *CI)
LowerToByteSwap - Replace a call instruction into a call to bswap intrinsic.
static IntegerType * getInt32Ty(LLVMContext &C)
void LowerIntrinsicCall(CallInst *CI)
LowerIntrinsicCall - This method replaces a call with the LLVM function which should be used to imple...
3: 64-bit floating point type
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
const BasicBlock * getParent() const
LLVMContext & getContext() const
Get the global data context.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
5: 128-bit floating point type (112-bit mantissa)