Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 1 | //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Builtin calls as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 14 | #include "TargetInfo.h" |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 15 | #include "CodeGenFunction.h" |
| 16 | #include "CodeGenModule.h" |
Fariborz Jahanian | 55bcace | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 17 | #include "CGObjCRuntime.h" |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Chris Lattner | 1f32999 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 19 | #include "clang/AST/APValue.h" |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 21 | #include "clang/AST/Decl.h" |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 22 | #include "clang/Basic/TargetBuiltins.h" |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 23 | #include "llvm/Intrinsics.h" |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetData.h" |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | using namespace CodeGen; |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 29 | static void EmitMemoryBarrier(CodeGenFunction &CGF, |
| 30 | bool LoadLoad, bool LoadStore, |
| 31 | bool StoreLoad, bool StoreStore, |
| 32 | bool Device) { |
| 33 | Value *True = llvm::ConstantInt::getTrue(CGF.getLLVMContext()); |
| 34 | Value *False = llvm::ConstantInt::getFalse(CGF.getLLVMContext()); |
| 35 | Value *C[5] = { LoadLoad ? True : False, |
| 36 | LoadStore ? True : False, |
| 37 | StoreLoad ? True : False, |
| 38 | StoreStore ? True : False, |
| 39 | Device ? True : False }; |
| 40 | CGF.Builder.CreateCall(CGF.CGM.getIntrinsic(Intrinsic::memory_barrier), |
| 41 | C, C + 5); |
| 42 | } |
| 43 | |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 44 | static Value *EmitCastToInt(CodeGenFunction &CGF, |
| 45 | const llvm::Type *ToType, Value *Val) { |
| 46 | if (Val->getType()->isPointerTy()) { |
| 47 | return CGF.Builder.CreatePtrToInt(Val, ToType); |
| 48 | } |
| 49 | assert(Val->getType()->isIntegerTy() && |
| 50 | "Used a non-integer and non-pointer type with atomic builtin"); |
| 51 | assert(Val->getType()->getScalarSizeInBits() <= |
| 52 | ToType->getScalarSizeInBits() && "Integer type too small"); |
| 53 | return CGF.Builder.CreateSExtOrBitCast(Val, ToType); |
| 54 | } |
| 55 | |
| 56 | static Value *EmitCastFromInt(CodeGenFunction &CGF, QualType ToQualType, |
| 57 | Value *Val) { |
| 58 | const llvm::Type *ToType = CGF.ConvertType(ToQualType); |
| 59 | if (ToType->isPointerTy()) { |
| 60 | return CGF.Builder.CreateIntToPtr(Val, ToType); |
| 61 | } |
| 62 | assert(Val->getType()->isIntegerTy() && |
| 63 | "Used a non-integer and non-pointer type with atomic builtin"); |
| 64 | assert(Val->getType()->getScalarSizeInBits() >= |
| 65 | ToType->getScalarSizeInBits() && "Integer type too small"); |
| 66 | return CGF.Builder.CreateTruncOrBitCast(Val, ToType); |
| 67 | } |
| 68 | |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 69 | // The atomic builtins are also full memory barriers. This is a utility for |
| 70 | // wrapping a call to the builtins with memory barriers. |
| 71 | static Value *EmitCallWithBarrier(CodeGenFunction &CGF, Value *Fn, |
| 72 | Value **ArgBegin, Value **ArgEnd) { |
| 73 | // FIXME: We need a target hook for whether this applies to device memory or |
| 74 | // not. |
| 75 | bool Device = true; |
| 76 | |
| 77 | // Create barriers both before and after the call. |
| 78 | EmitMemoryBarrier(CGF, true, true, true, true, Device); |
| 79 | Value *Result = CGF.Builder.CreateCall(Fn, ArgBegin, ArgEnd); |
| 80 | EmitMemoryBarrier(CGF, true, true, true, true, Device); |
| 81 | return Result; |
| 82 | } |
| 83 | |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 84 | /// Utility to insert an atomic instruction based on Instrinsic::ID |
| 85 | /// and the expression node. |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 86 | static RValue EmitBinaryAtomic(CodeGenFunction &CGF, |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 87 | Intrinsic::ID Id, const CallExpr *E) { |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 88 | const llvm::Type *ValueType = |
| 89 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 90 | CGF.getContext().getTypeSize(E->getType())); |
| 91 | const llvm::Type *PtrType = ValueType->getPointerTo(); |
| 92 | const llvm::Type *IntrinsicTypes[2] = { ValueType, PtrType }; |
| 93 | Value *AtomF = CGF.CGM.getIntrinsic(Id, IntrinsicTypes, 2); |
| 94 | |
| 95 | Value *Args[2] = { CGF.Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)), |
| 96 | PtrType), |
| 97 | EmitCastToInt(CGF, ValueType, |
| 98 | CGF.EmitScalarExpr(E->getArg(1))) }; |
| 99 | return RValue::get(EmitCastFromInt(CGF, E->getType(), |
| 100 | EmitCallWithBarrier(CGF, AtomF, Args, |
| 101 | Args + 2))); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /// Utility to insert an atomic instruction based Instrinsic::ID and |
| 105 | // the expression node, where the return value is the result of the |
| 106 | // operation. |
Chris Lattner | 420b118 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 107 | static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF, |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 108 | Intrinsic::ID Id, const CallExpr *E, |
| 109 | Instruction::BinaryOps Op) { |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 110 | const llvm::Type *ValueType = |
| 111 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 112 | CGF.getContext().getTypeSize(E->getType())); |
| 113 | const llvm::Type *PtrType = ValueType->getPointerTo(); |
| 114 | const llvm::Type *IntrinsicTypes[2] = { ValueType, PtrType }; |
| 115 | Value *AtomF = CGF.CGM.getIntrinsic(Id, IntrinsicTypes, 2); |
| 116 | |
| 117 | Value *Args[2] = { CGF.Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)), |
| 118 | PtrType), |
| 119 | EmitCastToInt(CGF, ValueType, |
| 120 | CGF.EmitScalarExpr(E->getArg(1))) }; |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 121 | Value *Result = EmitCallWithBarrier(CGF, AtomF, Args, Args + 2); |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 122 | return RValue::get(EmitCastFromInt(CGF, E->getType(), |
| 123 | CGF.Builder.CreateBinOp(Op, Result, |
| 124 | Args[1]))); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Chris Lattner | 420b118 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 127 | /// EmitFAbs - Emit a call to fabs/fabsf/fabsl, depending on the type of ValTy, |
| 128 | /// which must be a scalar floating point type. |
| 129 | static Value *EmitFAbs(CodeGenFunction &CGF, Value *V, QualType ValTy) { |
| 130 | const BuiltinType *ValTyP = ValTy->getAs<BuiltinType>(); |
| 131 | assert(ValTyP && "isn't scalar fp type!"); |
| 132 | |
| 133 | StringRef FnName; |
| 134 | switch (ValTyP->getKind()) { |
| 135 | default: assert(0 && "Isn't a scalar fp type!"); |
| 136 | case BuiltinType::Float: FnName = "fabsf"; break; |
| 137 | case BuiltinType::Double: FnName = "fabs"; break; |
| 138 | case BuiltinType::LongDouble: FnName = "fabsl"; break; |
| 139 | } |
| 140 | |
| 141 | // The prototype is something that takes and returns whatever V's type is. |
| 142 | std::vector<const llvm::Type*> Args; |
| 143 | Args.push_back(V->getType()); |
| 144 | llvm::FunctionType *FT = llvm::FunctionType::get(V->getType(), Args, false); |
| 145 | llvm::Value *Fn = CGF.CGM.CreateRuntimeFunction(FT, FnName); |
| 146 | |
| 147 | return CGF.Builder.CreateCall(Fn, V, "abs"); |
| 148 | } |
| 149 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 151 | unsigned BuiltinID, const CallExpr *E) { |
Chris Lattner | 564ea2a | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 152 | // See if we can constant fold this builtin. If so, don't emit it at all. |
Anders Carlsson | f35d35a | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 153 | Expr::EvalResult Result; |
Chris Lattner | 6ee7aa1 | 2008-11-16 21:24:15 +0000 | [diff] [blame] | 154 | if (E->Evaluate(Result, CGM.getContext())) { |
Anders Carlsson | f35d35a | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 155 | if (Result.Val.isInt()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | return RValue::get(llvm::ConstantInt::get(VMContext, |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 157 | Result.Val.getInt())); |
Eli Friedman | 3941b18 | 2009-01-25 01:54:01 +0000 | [diff] [blame] | 158 | else if (Result.Val.isFloat()) |
Owen Anderson | bc0a222 | 2009-07-27 21:00:51 +0000 | [diff] [blame] | 159 | return RValue::get(ConstantFP::get(VMContext, Result.Val.getFloat())); |
Chris Lattner | 1f32999 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 160 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 161 | |
Chris Lattner | 564ea2a | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 162 | switch (BuiltinID) { |
| 163 | default: break; // Handle intrinsics and libm functions below. |
Chris Lattner | 506ff88 | 2008-10-06 07:26:43 +0000 | [diff] [blame] | 164 | case Builtin::BI__builtin___CFStringMakeConstantString: |
David Chisnall | 0d13f6f | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 165 | case Builtin::BI__builtin___NSStringMakeConstantString: |
Anders Carlsson | e9352cc | 2009-04-08 04:48:15 +0000 | [diff] [blame] | 166 | return RValue::get(CGM.EmitConstantExpr(E, E->getType(), 0)); |
Chris Lattner | 6a705f0 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 167 | case Builtin::BI__builtin_stdarg_start: |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 168 | case Builtin::BI__builtin_va_start: |
| 169 | case Builtin::BI__builtin_va_end: { |
Daniel Dunbar | 0785570 | 2009-02-11 22:25:55 +0000 | [diff] [blame] | 170 | Value *ArgValue = EmitVAListRef(E->getArg(0)); |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 171 | const llvm::Type *DestType = llvm::Type::getInt8PtrTy(VMContext); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 172 | if (ArgValue->getType() != DestType) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | ArgValue = Builder.CreateBitCast(ArgValue, DestType, |
Daniel Dunbar | b27ffbe | 2009-07-26 09:28:40 +0000 | [diff] [blame] | 174 | ArgValue->getName().data()); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 175 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ? |
Chris Lattner | 6a705f0 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 177 | Intrinsic::vaend : Intrinsic::vastart; |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 178 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 179 | } |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 180 | case Builtin::BI__builtin_va_copy: { |
Eli Friedman | 4fd0aa5 | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 181 | Value *DstPtr = EmitVAListRef(E->getArg(0)); |
| 182 | Value *SrcPtr = EmitVAListRef(E->getArg(1)); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 183 | |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 184 | const llvm::Type *Type = llvm::Type::getInt8PtrTy(VMContext); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 185 | |
| 186 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 187 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame] | 189 | DstPtr, SrcPtr)); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 190 | } |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 191 | case Builtin::BI__builtin_abs: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 192 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 193 | |
Chris Lattner | 9a847f5 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 194 | Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | Value *CmpResult = |
| 196 | Builder.CreateICmpSGE(ArgValue, |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 197 | llvm::Constant::getNullValue(ArgValue->getType()), |
Chris Lattner | 9a847f5 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 198 | "abscond"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | Value *Result = |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 200 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 201 | |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 202 | return RValue::get(Result); |
| 203 | } |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 204 | case Builtin::BI__builtin_ctz: |
| 205 | case Builtin::BI__builtin_ctzl: |
| 206 | case Builtin::BI__builtin_ctzll: { |
| 207 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 208 | |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 209 | const llvm::Type *ArgType = ArgValue->getType(); |
| 210 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); |
| 211 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | const llvm::Type *ResultType = ConvertType(E->getType()); |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 213 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 214 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 215 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 216 | "cast"); |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 217 | return RValue::get(Result); |
| 218 | } |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 219 | case Builtin::BI__builtin_clz: |
| 220 | case Builtin::BI__builtin_clzl: |
| 221 | case Builtin::BI__builtin_clzll: { |
| 222 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 223 | |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 224 | const llvm::Type *ArgType = ArgValue->getType(); |
| 225 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1); |
| 226 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 227 | const llvm::Type *ResultType = ConvertType(E->getType()); |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 228 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 229 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 230 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 231 | "cast"); |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 232 | return RValue::get(Result); |
| 233 | } |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 234 | case Builtin::BI__builtin_ffs: |
| 235 | case Builtin::BI__builtin_ffsl: |
| 236 | case Builtin::BI__builtin_ffsll: { |
| 237 | // ffs(x) -> x ? cttz(x) + 1 : 0 |
| 238 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 239 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 240 | const llvm::Type *ArgType = ArgValue->getType(); |
| 241 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 242 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 243 | const llvm::Type *ResultType = ConvertType(E->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 244 | Value *Tmp = Builder.CreateAdd(Builder.CreateCall(F, ArgValue, "tmp"), |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 245 | llvm::ConstantInt::get(ArgType, 1), "tmp"); |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 246 | Value *Zero = llvm::Constant::getNullValue(ArgType); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 247 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); |
| 248 | Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); |
| 249 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 250 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 251 | "cast"); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 252 | return RValue::get(Result); |
| 253 | } |
| 254 | case Builtin::BI__builtin_parity: |
| 255 | case Builtin::BI__builtin_parityl: |
| 256 | case Builtin::BI__builtin_parityll: { |
| 257 | // parity(x) -> ctpop(x) & 1 |
| 258 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 259 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 260 | const llvm::Type *ArgType = ArgValue->getType(); |
| 261 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 263 | const llvm::Type *ResultType = ConvertType(E->getType()); |
| 264 | Value *Tmp = Builder.CreateCall(F, ArgValue, "tmp"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 265 | Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1), |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 266 | "tmp"); |
| 267 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 268 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 269 | "cast"); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 270 | return RValue::get(Result); |
| 271 | } |
| 272 | case Builtin::BI__builtin_popcount: |
| 273 | case Builtin::BI__builtin_popcountl: |
| 274 | case Builtin::BI__builtin_popcountll: { |
| 275 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 277 | const llvm::Type *ArgType = ArgValue->getType(); |
| 278 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 279 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 280 | const llvm::Type *ResultType = ConvertType(E->getType()); |
| 281 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 282 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 283 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 284 | "cast"); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 285 | return RValue::get(Result); |
| 286 | } |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 287 | case Builtin::BI__builtin_expect: |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 288 | // FIXME: pass expect through to LLVM |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 289 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 290 | case Builtin::BI__builtin_bswap32: |
| 291 | case Builtin::BI__builtin_bswap64: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 292 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 293 | const llvm::Type *ArgType = ArgValue->getType(); |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 294 | Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 295 | return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 296 | } |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 297 | case Builtin::BI__builtin_object_size: { |
Mike Stump | b16d32f | 2009-10-26 23:39:48 +0000 | [diff] [blame] | 298 | // We pass this builtin onto the optimizer so that it can |
| 299 | // figure out the object size in more complex cases. |
Mike Stump | c4c9045 | 2009-10-27 22:09:17 +0000 | [diff] [blame] | 300 | const llvm::Type *ResType[] = { |
| 301 | ConvertType(E->getType()) |
| 302 | }; |
Eric Christopher | fee667f | 2009-12-23 03:49:37 +0000 | [diff] [blame] | 303 | |
| 304 | // LLVM only supports 0 and 2, make sure that we pass along that |
| 305 | // as a boolean. |
| 306 | Value *Ty = EmitScalarExpr(E->getArg(1)); |
| 307 | ConstantInt *CI = dyn_cast<ConstantInt>(Ty); |
| 308 | assert(CI); |
| 309 | uint64_t val = CI->getZExtValue(); |
| 310 | CI = ConstantInt::get(llvm::Type::getInt1Ty(VMContext), (val & 0x2) >> 1); |
| 311 | |
Mike Stump | c4c9045 | 2009-10-27 22:09:17 +0000 | [diff] [blame] | 312 | Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType, 1); |
| 313 | return RValue::get(Builder.CreateCall2(F, |
| 314 | EmitScalarExpr(E->getArg(0)), |
Eric Christopher | fee667f | 2009-12-23 03:49:37 +0000 | [diff] [blame] | 315 | CI)); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 316 | } |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 317 | case Builtin::BI__builtin_prefetch: { |
| 318 | Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); |
| 319 | // FIXME: Technically these constants should of type 'int', yes? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 320 | RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 321 | llvm::ConstantInt::get(Int32Ty, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 323 | llvm::ConstantInt::get(Int32Ty, 3); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 324 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); |
| 325 | return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 326 | } |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 327 | case Builtin::BI__builtin_trap: { |
| 328 | Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0); |
| 329 | return RValue::get(Builder.CreateCall(F)); |
| 330 | } |
Chris Lattner | 21190d5 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 331 | case Builtin::BI__builtin_unreachable: { |
Mike Stump | fba565d | 2009-12-16 03:07:12 +0000 | [diff] [blame] | 332 | if (CatchUndefined && HaveInsertPoint()) |
| 333 | EmitBranch(getTrapBB()); |
Chris Lattner | 21190d5 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 334 | Value *V = Builder.CreateUnreachable(); |
| 335 | Builder.ClearInsertionPoint(); |
| 336 | return RValue::get(V); |
| 337 | } |
| 338 | |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 339 | case Builtin::BI__builtin_powi: |
| 340 | case Builtin::BI__builtin_powif: |
| 341 | case Builtin::BI__builtin_powil: { |
| 342 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 343 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 344 | const llvm::Type *ArgType = Base->getType(); |
| 345 | Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1); |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 346 | return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); |
| 347 | } |
| 348 | |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 349 | case Builtin::BI__builtin_isgreater: |
| 350 | case Builtin::BI__builtin_isgreaterequal: |
| 351 | case Builtin::BI__builtin_isless: |
| 352 | case Builtin::BI__builtin_islessequal: |
| 353 | case Builtin::BI__builtin_islessgreater: |
| 354 | case Builtin::BI__builtin_isunordered: { |
| 355 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 356 | // floating point values. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 358 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 360 | switch (BuiltinID) { |
| 361 | default: assert(0 && "Unknown ordered comparison"); |
| 362 | case Builtin::BI__builtin_isgreater: |
| 363 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 364 | break; |
| 365 | case Builtin::BI__builtin_isgreaterequal: |
| 366 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 367 | break; |
| 368 | case Builtin::BI__builtin_isless: |
| 369 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 370 | break; |
| 371 | case Builtin::BI__builtin_islessequal: |
| 372 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 373 | break; |
| 374 | case Builtin::BI__builtin_islessgreater: |
| 375 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 376 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | case Builtin::BI__builtin_isunordered: |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 378 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 379 | break; |
| 380 | } |
| 381 | // ZExt bool to int type. |
| 382 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()), |
| 383 | "tmp")); |
| 384 | } |
Eli Friedman | d613989 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 385 | case Builtin::BI__builtin_isnan: { |
| 386 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 387 | V = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 388 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()), "tmp")); |
| 389 | } |
Chris Lattner | 420b118 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 390 | |
| 391 | case Builtin::BI__builtin_isinf: { |
| 392 | // isinf(x) --> fabs(x) == infinity |
| 393 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 394 | V = EmitFAbs(*this, V, E->getArg(0)->getType()); |
| 395 | |
| 396 | V = Builder.CreateFCmpOEQ(V, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 397 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()), "tmp")); |
| 398 | } |
Chris Lattner | 58ae5b4 | 2010-05-06 06:13:53 +0000 | [diff] [blame] | 399 | |
| 400 | // TODO: BI__builtin_isinf_sign |
| 401 | // isinf_sign(x) -> isinf(x) ? (signbit(x) ? -1 : 1) : 0 |
Benjamin Kramer | 6349ce9 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 402 | |
| 403 | case Builtin::BI__builtin_isnormal: { |
| 404 | // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min |
| 405 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 406 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
| 407 | |
| 408 | Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType()); |
| 409 | Value *IsLessThanInf = |
| 410 | Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 411 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 412 | getContext().getFloatTypeSemantics(E->getArg(0)->getType())); |
| 413 | Value *IsNormal = |
| 414 | Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest), |
| 415 | "isnormal"); |
| 416 | V = Builder.CreateAnd(Eq, IsLessThanInf, "and"); |
| 417 | V = Builder.CreateAnd(V, IsNormal, "and"); |
| 418 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 419 | } |
| 420 | |
Chris Lattner | ed07415 | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 421 | case Builtin::BI__builtin_isfinite: { |
| 422 | // isfinite(x) --> x == x && fabs(x) != infinity; } |
| 423 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 424 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
| 425 | |
| 426 | Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType()); |
| 427 | Value *IsNotInf = |
| 428 | Builder.CreateFCmpUNE(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 429 | |
| 430 | V = Builder.CreateAnd(Eq, IsNotInf, "and"); |
| 431 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 432 | } |
Benjamin Kramer | 7867f1a | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 433 | |
| 434 | case Builtin::BI__builtin_fpclassify: { |
| 435 | Value *V = EmitScalarExpr(E->getArg(5)); |
| 436 | const llvm::Type *Ty = ConvertType(E->getArg(5)->getType()); |
| 437 | |
| 438 | // Create Result |
| 439 | BasicBlock *Begin = Builder.GetInsertBlock(); |
| 440 | BasicBlock *End = createBasicBlock("fpclassify_end", this->CurFn); |
| 441 | Builder.SetInsertPoint(End); |
| 442 | PHINode *Result = |
| 443 | Builder.CreatePHI(ConvertType(E->getArg(0)->getType()), |
| 444 | "fpclassify_result"); |
| 445 | |
| 446 | // if (V==0) return FP_ZERO |
| 447 | Builder.SetInsertPoint(Begin); |
| 448 | Value *IsZero = Builder.CreateFCmpOEQ(V, Constant::getNullValue(Ty), |
| 449 | "iszero"); |
| 450 | Value *ZeroLiteral = EmitScalarExpr(E->getArg(4)); |
| 451 | BasicBlock *NotZero = createBasicBlock("fpclassify_not_zero", this->CurFn); |
| 452 | Builder.CreateCondBr(IsZero, End, NotZero); |
| 453 | Result->addIncoming(ZeroLiteral, Begin); |
| 454 | |
| 455 | // if (V != V) return FP_NAN |
| 456 | Builder.SetInsertPoint(NotZero); |
| 457 | Value *IsNan = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 458 | Value *NanLiteral = EmitScalarExpr(E->getArg(0)); |
| 459 | BasicBlock *NotNan = createBasicBlock("fpclassify_not_nan", this->CurFn); |
| 460 | Builder.CreateCondBr(IsNan, End, NotNan); |
| 461 | Result->addIncoming(NanLiteral, NotZero); |
| 462 | |
| 463 | // if (fabs(V) == infinity) return FP_INFINITY |
| 464 | Builder.SetInsertPoint(NotNan); |
| 465 | Value *VAbs = EmitFAbs(*this, V, E->getArg(5)->getType()); |
| 466 | Value *IsInf = |
| 467 | Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(V->getType()), |
| 468 | "isinf"); |
| 469 | Value *InfLiteral = EmitScalarExpr(E->getArg(1)); |
| 470 | BasicBlock *NotInf = createBasicBlock("fpclassify_not_inf", this->CurFn); |
| 471 | Builder.CreateCondBr(IsInf, End, NotInf); |
| 472 | Result->addIncoming(InfLiteral, NotNan); |
| 473 | |
| 474 | // if (fabs(V) >= MIN_NORMAL) return FP_NORMAL else FP_SUBNORMAL |
| 475 | Builder.SetInsertPoint(NotInf); |
| 476 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 477 | getContext().getFloatTypeSemantics(E->getArg(5)->getType())); |
| 478 | Value *IsNormal = |
| 479 | Builder.CreateFCmpUGE(VAbs, ConstantFP::get(V->getContext(), Smallest), |
| 480 | "isnormal"); |
| 481 | Value *NormalResult = |
| 482 | Builder.CreateSelect(IsNormal, EmitScalarExpr(E->getArg(2)), |
| 483 | EmitScalarExpr(E->getArg(3))); |
| 484 | Builder.CreateBr(End); |
| 485 | Result->addIncoming(NormalResult, NotInf); |
| 486 | |
| 487 | // return Result |
| 488 | Builder.SetInsertPoint(End); |
| 489 | return RValue::get(Result); |
| 490 | } |
Chris Lattner | ed07415 | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 491 | |
Eli Friedman | b52fe9c | 2009-06-02 07:10:30 +0000 | [diff] [blame] | 492 | case Builtin::BIalloca: |
Chris Lattner | 9e800e3 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 493 | case Builtin::BI__builtin_alloca: { |
Chris Lattner | 9e800e3 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 494 | Value *Size = EmitScalarExpr(E->getArg(0)); |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 495 | return RValue::get(Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), Size, "tmp")); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 496 | } |
Eli Friedman | e6dddfd | 2010-01-23 19:00:10 +0000 | [diff] [blame] | 497 | case Builtin::BIbzero: |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 498 | case Builtin::BI__builtin_bzero: { |
| 499 | Value *Address = EmitScalarExpr(E->getArg(0)); |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 500 | Value *SizeVal = EmitScalarExpr(E->getArg(1)); |
| 501 | Builder.CreateCall5(CGM.getMemSetFn(Address->getType(), SizeVal->getType()), |
| 502 | Address, |
| 503 | llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0), |
| 504 | SizeVal, |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 505 | llvm::ConstantInt::get(Int32Ty, 1), |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 506 | llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 507 | return RValue::get(Address); |
Chris Lattner | 9e800e3 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 508 | } |
Eli Friedman | e6ec205 | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 509 | case Builtin::BImemcpy: |
Eli Friedman | d4b32e4 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 510 | case Builtin::BI__builtin_memcpy: { |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 511 | Value *Address = EmitScalarExpr(E->getArg(0)); |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 512 | Value *SrcAddr = EmitScalarExpr(E->getArg(1)); |
| 513 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
| 514 | Builder.CreateCall5(CGM.getMemCpyFn(Address->getType(), SrcAddr->getType(), |
| 515 | SizeVal->getType()), |
| 516 | Address, SrcAddr, SizeVal, |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 517 | llvm::ConstantInt::get(Int32Ty, 1), |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 518 | llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 519 | return RValue::get(Address); |
| 520 | } |
Fariborz Jahanian | 55bcace | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 521 | |
Fariborz Jahanian | 8e2eab2 | 2010-06-16 16:22:04 +0000 | [diff] [blame] | 522 | case Builtin::BI__builtin_objc_memmove_collectable: { |
Fariborz Jahanian | 55bcace | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 523 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 524 | Value *SrcAddr = EmitScalarExpr(E->getArg(1)); |
| 525 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
| 526 | CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, |
| 527 | Address, SrcAddr, SizeVal); |
| 528 | return RValue::get(Address); |
| 529 | } |
| 530 | |
Eli Friedman | e6ec205 | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 531 | case Builtin::BImemmove: |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 532 | case Builtin::BI__builtin_memmove: { |
| 533 | Value *Address = EmitScalarExpr(E->getArg(0)); |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 534 | Value *SrcAddr = EmitScalarExpr(E->getArg(1)); |
| 535 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
| 536 | Builder.CreateCall5(CGM.getMemMoveFn(Address->getType(), SrcAddr->getType(), |
| 537 | SizeVal->getType()), |
| 538 | Address, SrcAddr, SizeVal, |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 539 | llvm::ConstantInt::get(Int32Ty, 1), |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 540 | llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 541 | return RValue::get(Address); |
| 542 | } |
Eli Friedman | e6ec205 | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 543 | case Builtin::BImemset: |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 544 | case Builtin::BI__builtin_memset: { |
| 545 | Value *Address = EmitScalarExpr(E->getArg(0)); |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 546 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
| 547 | Builder.CreateCall5(CGM.getMemSetFn(Address->getType(), SizeVal->getType()), |
| 548 | Address, |
| 549 | Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 550 | llvm::Type::getInt8Ty(VMContext)), |
| 551 | SizeVal, |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 552 | llvm::ConstantInt::get(Int32Ty, 1), |
Mon P Wang | 3ecd785 | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 553 | llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 554 | return RValue::get(Address); |
Eli Friedman | d4b32e4 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 555 | } |
John McCall | fb17a56 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 556 | case Builtin::BI__builtin_dwarf_cfa: { |
| 557 | // The offset in bytes from the first argument to the CFA. |
| 558 | // |
| 559 | // Why on earth is this in the frontend? Is there any reason at |
| 560 | // all that the backend can't reasonably determine this while |
| 561 | // lowering llvm.eh.dwarf.cfa()? |
| 562 | // |
| 563 | // TODO: If there's a satisfactory reason, add a target hook for |
| 564 | // this instead of hard-coding 0, which is correct for most targets. |
| 565 | int32_t Offset = 0; |
| 566 | |
| 567 | Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa, 0, 0); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 568 | return RValue::get(Builder.CreateCall(F, |
| 569 | llvm::ConstantInt::get(Int32Ty, Offset))); |
John McCall | fb17a56 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 570 | } |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 571 | case Builtin::BI__builtin_return_address: { |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 572 | Value *Depth = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 573 | Depth = Builder.CreateIntCast(Depth, Int32Ty, false, "tmp"); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 574 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 575 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 576 | } |
| 577 | case Builtin::BI__builtin_frame_address: { |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 578 | Value *Depth = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 579 | Depth = Builder.CreateIntCast(Depth, Int32Ty, false, "tmp"); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 580 | Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 581 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 582 | } |
Eli Friedman | 3b660ef | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 583 | case Builtin::BI__builtin_extract_return_addr: { |
John McCall | 492c4f9 | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 584 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 585 | Value *Result = getTargetHooks().decodeReturnAddress(*this, Address); |
| 586 | return RValue::get(Result); |
| 587 | } |
| 588 | case Builtin::BI__builtin_frob_return_addr: { |
| 589 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 590 | Value *Result = getTargetHooks().encodeReturnAddress(*this, Address); |
| 591 | return RValue::get(Result); |
Eli Friedman | 3b660ef | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 592 | } |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 593 | case Builtin::BI__builtin_dwarf_sp_column: { |
| 594 | const llvm::IntegerType *Ty |
| 595 | = cast<llvm::IntegerType>(ConvertType(E->getType())); |
| 596 | int Column = getTargetHooks().getDwarfEHStackPointer(CGM); |
| 597 | if (Column == -1) { |
| 598 | CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column"); |
| 599 | return RValue::get(llvm::UndefValue::get(Ty)); |
| 600 | } |
| 601 | return RValue::get(llvm::ConstantInt::get(Ty, Column, true)); |
| 602 | } |
| 603 | case Builtin::BI__builtin_init_dwarf_reg_size_table: { |
| 604 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 605 | if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address)) |
| 606 | CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table"); |
| 607 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
| 608 | } |
John McCall | 7ada111 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 609 | case Builtin::BI__builtin_eh_return: { |
| 610 | Value *Int = EmitScalarExpr(E->getArg(0)); |
| 611 | Value *Ptr = EmitScalarExpr(E->getArg(1)); |
| 612 | |
| 613 | const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType()); |
| 614 | assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && |
| 615 | "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); |
| 616 | Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 |
| 617 | ? Intrinsic::eh_return_i32 |
| 618 | : Intrinsic::eh_return_i64, |
| 619 | 0, 0); |
| 620 | Builder.CreateCall2(F, Int, Ptr); |
| 621 | Value *V = Builder.CreateUnreachable(); |
| 622 | Builder.ClearInsertionPoint(); |
| 623 | return RValue::get(V); |
| 624 | } |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 625 | case Builtin::BI__builtin_unwind_init: { |
| 626 | Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init, 0, 0); |
| 627 | return RValue::get(Builder.CreateCall(F)); |
| 628 | } |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 629 | case Builtin::BI__builtin_extend_pointer: { |
| 630 | // Extends a pointer to the size of an _Unwind_Word, which is |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 631 | // uint64_t on all platforms. Generally this gets poked into a |
| 632 | // register and eventually used as an address, so if the |
| 633 | // addressing registers are wider than pointers and the platform |
| 634 | // doesn't implicitly ignore high-order bits when doing |
| 635 | // addressing, we need to make sure we zext / sext based on |
| 636 | // the platform's expectations. |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 637 | // |
| 638 | // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 639 | |
| 640 | LLVMContext &C = CGM.getLLVMContext(); |
| 641 | |
| 642 | // Cast the pointer to intptr_t. |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 643 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 644 | const llvm::IntegerType *IntPtrTy = CGM.getTargetData().getIntPtrType(C); |
| 645 | Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast"); |
| 646 | |
| 647 | // If that's 64 bits, we're done. |
| 648 | if (IntPtrTy->getBitWidth() == 64) |
| 649 | return RValue::get(Result); |
| 650 | |
| 651 | // Otherwise, ask the codegen data what to do. |
John McCall | 492c4f9 | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 652 | if (getTargetHooks().extendPointerWithSExt()) |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 653 | return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext")); |
| 654 | else |
| 655 | return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 656 | } |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 657 | case Builtin::BI__builtin_setjmp: { |
John McCall | 78673d9 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 658 | // Buffer is a void**. |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 659 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | 78673d9 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 660 | |
| 661 | // Store the frame pointer to the setjmp buffer. |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 662 | Value *FrameAddr = |
John McCall | 78673d9 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 663 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 664 | ConstantInt::get(Int32Ty, 0)); |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 665 | Builder.CreateStore(FrameAddr, Buf); |
John McCall | 78673d9 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 666 | |
Jim Grosbach | 6d172e2 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 667 | // Store the stack pointer to the setjmp buffer. |
| 668 | Value *StackAddr = |
| 669 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::stacksave)); |
| 670 | Value *StackSaveSlot = |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 671 | Builder.CreateGEP(Buf, ConstantInt::get(Int32Ty, 2)); |
Jim Grosbach | 6d172e2 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 672 | Builder.CreateStore(StackAddr, StackSaveSlot); |
| 673 | |
John McCall | 78673d9 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 674 | // Call LLVM's EH setjmp, which is lightweight. |
| 675 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp); |
| 676 | Buf = Builder.CreateBitCast(Buf, llvm::Type::getInt8PtrTy(VMContext)); |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 677 | return RValue::get(Builder.CreateCall(F, Buf)); |
| 678 | } |
| 679 | case Builtin::BI__builtin_longjmp: { |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 680 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | 78673d9 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 681 | Buf = Builder.CreateBitCast(Buf, llvm::Type::getInt8PtrTy(VMContext)); |
| 682 | |
| 683 | // Call LLVM's EH longjmp, which is lightweight. |
| 684 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf); |
| 685 | |
| 686 | // longjmp doesn't return; mark this as unreachable |
| 687 | Value *V = Builder.CreateUnreachable(); |
| 688 | Builder.ClearInsertionPoint(); |
| 689 | return RValue::get(V); |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 690 | } |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 691 | case Builtin::BI__sync_fetch_and_add: |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 692 | case Builtin::BI__sync_fetch_and_sub: |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 693 | case Builtin::BI__sync_fetch_and_or: |
| 694 | case Builtin::BI__sync_fetch_and_and: |
| 695 | case Builtin::BI__sync_fetch_and_xor: |
| 696 | case Builtin::BI__sync_add_and_fetch: |
| 697 | case Builtin::BI__sync_sub_and_fetch: |
| 698 | case Builtin::BI__sync_and_and_fetch: |
| 699 | case Builtin::BI__sync_or_and_fetch: |
| 700 | case Builtin::BI__sync_xor_and_fetch: |
| 701 | case Builtin::BI__sync_val_compare_and_swap: |
| 702 | case Builtin::BI__sync_bool_compare_and_swap: |
| 703 | case Builtin::BI__sync_lock_test_and_set: |
| 704 | case Builtin::BI__sync_lock_release: |
| 705 | assert(0 && "Shouldn't make it through sema"); |
| 706 | case Builtin::BI__sync_fetch_and_add_1: |
| 707 | case Builtin::BI__sync_fetch_and_add_2: |
| 708 | case Builtin::BI__sync_fetch_and_add_4: |
| 709 | case Builtin::BI__sync_fetch_and_add_8: |
| 710 | case Builtin::BI__sync_fetch_and_add_16: |
| 711 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_add, E); |
| 712 | case Builtin::BI__sync_fetch_and_sub_1: |
| 713 | case Builtin::BI__sync_fetch_and_sub_2: |
| 714 | case Builtin::BI__sync_fetch_and_sub_4: |
| 715 | case Builtin::BI__sync_fetch_and_sub_8: |
| 716 | case Builtin::BI__sync_fetch_and_sub_16: |
Mon P Wang | 09b6bf5 | 2008-06-25 08:21:36 +0000 | [diff] [blame] | 717 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_sub, E); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 718 | case Builtin::BI__sync_fetch_and_or_1: |
| 719 | case Builtin::BI__sync_fetch_and_or_2: |
| 720 | case Builtin::BI__sync_fetch_and_or_4: |
| 721 | case Builtin::BI__sync_fetch_and_or_8: |
| 722 | case Builtin::BI__sync_fetch_and_or_16: |
| 723 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E); |
| 724 | case Builtin::BI__sync_fetch_and_and_1: |
| 725 | case Builtin::BI__sync_fetch_and_and_2: |
| 726 | case Builtin::BI__sync_fetch_and_and_4: |
| 727 | case Builtin::BI__sync_fetch_and_and_8: |
| 728 | case Builtin::BI__sync_fetch_and_and_16: |
| 729 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E); |
| 730 | case Builtin::BI__sync_fetch_and_xor_1: |
| 731 | case Builtin::BI__sync_fetch_and_xor_2: |
| 732 | case Builtin::BI__sync_fetch_and_xor_4: |
| 733 | case Builtin::BI__sync_fetch_and_xor_8: |
| 734 | case Builtin::BI__sync_fetch_and_xor_16: |
| 735 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 736 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 737 | // Clang extensions: not overloaded yet. |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 738 | case Builtin::BI__sync_fetch_and_min: |
| 739 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E); |
| 740 | case Builtin::BI__sync_fetch_and_max: |
| 741 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E); |
| 742 | case Builtin::BI__sync_fetch_and_umin: |
| 743 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E); |
| 744 | case Builtin::BI__sync_fetch_and_umax: |
| 745 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 746 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 747 | case Builtin::BI__sync_add_and_fetch_1: |
| 748 | case Builtin::BI__sync_add_and_fetch_2: |
| 749 | case Builtin::BI__sync_add_and_fetch_4: |
| 750 | case Builtin::BI__sync_add_and_fetch_8: |
| 751 | case Builtin::BI__sync_add_and_fetch_16: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_add, E, |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 753 | llvm::Instruction::Add); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 754 | case Builtin::BI__sync_sub_and_fetch_1: |
| 755 | case Builtin::BI__sync_sub_and_fetch_2: |
| 756 | case Builtin::BI__sync_sub_and_fetch_4: |
| 757 | case Builtin::BI__sync_sub_and_fetch_8: |
| 758 | case Builtin::BI__sync_sub_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 759 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_sub, E, |
| 760 | llvm::Instruction::Sub); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 761 | case Builtin::BI__sync_and_and_fetch_1: |
| 762 | case Builtin::BI__sync_and_and_fetch_2: |
| 763 | case Builtin::BI__sync_and_and_fetch_4: |
| 764 | case Builtin::BI__sync_and_and_fetch_8: |
| 765 | case Builtin::BI__sync_and_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 766 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_and, E, |
| 767 | llvm::Instruction::And); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 768 | case Builtin::BI__sync_or_and_fetch_1: |
| 769 | case Builtin::BI__sync_or_and_fetch_2: |
| 770 | case Builtin::BI__sync_or_and_fetch_4: |
| 771 | case Builtin::BI__sync_or_and_fetch_8: |
| 772 | case Builtin::BI__sync_or_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 773 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_or, E, |
| 774 | llvm::Instruction::Or); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 775 | case Builtin::BI__sync_xor_and_fetch_1: |
| 776 | case Builtin::BI__sync_xor_and_fetch_2: |
| 777 | case Builtin::BI__sync_xor_and_fetch_4: |
| 778 | case Builtin::BI__sync_xor_and_fetch_8: |
| 779 | case Builtin::BI__sync_xor_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 780 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_xor, E, |
| 781 | llvm::Instruction::Xor); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 782 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 783 | case Builtin::BI__sync_val_compare_and_swap_1: |
| 784 | case Builtin::BI__sync_val_compare_and_swap_2: |
| 785 | case Builtin::BI__sync_val_compare_and_swap_4: |
| 786 | case Builtin::BI__sync_val_compare_and_swap_8: |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 787 | case Builtin::BI__sync_val_compare_and_swap_16: { |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 788 | const llvm::Type *ValueType = |
| 789 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 790 | CGF.getContext().getTypeSize(E->getType())); |
| 791 | const llvm::Type *PtrType = ValueType->getPointerTo(); |
| 792 | const llvm::Type *IntrinsicTypes[2] = { ValueType, PtrType }; |
| 793 | Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, |
| 794 | IntrinsicTypes, 2); |
| 795 | |
| 796 | Value *Args[3] = { Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)), |
| 797 | PtrType), |
| 798 | EmitCastToInt(CGF, ValueType, |
| 799 | CGF.EmitScalarExpr(E->getArg(1))), |
| 800 | EmitCastToInt(CGF, ValueType, |
| 801 | CGF.EmitScalarExpr(E->getArg(2))) }; |
| 802 | return RValue::get(EmitCastFromInt(CGF, E->getType(), |
| 803 | EmitCallWithBarrier(CGF, AtomF, Args, |
| 804 | Args + 3))); |
Anders Carlsson | 89799cf | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 805 | } |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 806 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 807 | case Builtin::BI__sync_bool_compare_and_swap_1: |
| 808 | case Builtin::BI__sync_bool_compare_and_swap_2: |
| 809 | case Builtin::BI__sync_bool_compare_and_swap_4: |
| 810 | case Builtin::BI__sync_bool_compare_and_swap_8: |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 811 | case Builtin::BI__sync_bool_compare_and_swap_16: { |
Chandler Carruth | db4325b | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 812 | const llvm::Type *ValueType = |
| 813 | llvm::IntegerType::get( |
| 814 | CGF.getLLVMContext(), |
| 815 | CGF.getContext().getTypeSize(E->getArg(1)->getType())); |
| 816 | const llvm::Type *PtrType = ValueType->getPointerTo(); |
| 817 | const llvm::Type *IntrinsicTypes[2] = { ValueType, PtrType }; |
| 818 | Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, |
| 819 | IntrinsicTypes, 2); |
| 820 | |
| 821 | Value *Args[3] = { Builder.CreateBitCast(CGF.EmitScalarExpr(E->getArg(0)), |
| 822 | PtrType), |
| 823 | EmitCastToInt(CGF, ValueType, |
| 824 | CGF.EmitScalarExpr(E->getArg(1))), |
| 825 | EmitCastToInt(CGF, ValueType, |
| 826 | CGF.EmitScalarExpr(E->getArg(2))) }; |
| 827 | Value *OldVal = Args[1]; |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 828 | Value *PrevVal = EmitCallWithBarrier(*this, AtomF, Args, Args + 3); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 829 | Value *Result = Builder.CreateICmpEQ(PrevVal, OldVal); |
| 830 | // zext bool to int. |
| 831 | return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType()))); |
| 832 | } |
| 833 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 834 | case Builtin::BI__sync_lock_test_and_set_1: |
| 835 | case Builtin::BI__sync_lock_test_and_set_2: |
| 836 | case Builtin::BI__sync_lock_test_and_set_4: |
| 837 | case Builtin::BI__sync_lock_test_and_set_8: |
| 838 | case Builtin::BI__sync_lock_test_and_set_16: |
Nate Begeman | 7ea2e3f | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 839 | return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E); |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 840 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 841 | case Builtin::BI__sync_lock_release_1: |
| 842 | case Builtin::BI__sync_lock_release_2: |
| 843 | case Builtin::BI__sync_lock_release_4: |
| 844 | case Builtin::BI__sync_lock_release_8: |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 845 | case Builtin::BI__sync_lock_release_16: { |
| 846 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 847 | const llvm::Type *ElTy = |
| 848 | cast<llvm::PointerType>(Ptr->getType())->getElementType(); |
Daniel Dunbar | 007b567 | 2009-11-29 21:11:47 +0000 | [diff] [blame] | 849 | llvm::StoreInst *Store = |
| 850 | Builder.CreateStore(llvm::Constant::getNullValue(ElTy), Ptr); |
| 851 | Store->setVolatile(true); |
Daniel Dunbar | eb4f81e | 2009-05-27 23:45:33 +0000 | [diff] [blame] | 852 | return RValue::get(0); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 853 | } |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 854 | |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 855 | case Builtin::BI__sync_synchronize: { |
Daniel Dunbar | cb61a7b | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 856 | // We assume like gcc appears to, that this only applies to cached memory. |
| 857 | EmitMemoryBarrier(*this, true, true, true, true, false); |
Daniel Dunbar | eb4f81e | 2009-05-27 23:45:33 +0000 | [diff] [blame] | 858 | return RValue::get(0); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 859 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | |
Tanya Lattner | 0b57164 | 2010-01-16 01:21:14 +0000 | [diff] [blame] | 861 | case Builtin::BI__builtin_llvm_memory_barrier: { |
| 862 | Value *C[5] = { |
| 863 | EmitScalarExpr(E->getArg(0)), |
| 864 | EmitScalarExpr(E->getArg(1)), |
| 865 | EmitScalarExpr(E->getArg(2)), |
| 866 | EmitScalarExpr(E->getArg(3)), |
| 867 | EmitScalarExpr(E->getArg(4)) |
| 868 | }; |
| 869 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::memory_barrier), C, C + 5); |
| 870 | return RValue::get(0); |
| 871 | } |
| 872 | |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 873 | // Library functions with special handling. |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 874 | case Builtin::BIsqrt: |
| 875 | case Builtin::BIsqrtf: |
| 876 | case Builtin::BIsqrtl: { |
John McCall | beb4128 | 2010-04-07 08:20:20 +0000 | [diff] [blame] | 877 | // TODO: there is currently no set of optimizer flags |
| 878 | // sufficient for us to rewrite sqrt to @llvm.sqrt. |
| 879 | // -fmath-errno=0 is not good enough; we need finiteness. |
| 880 | // We could probably precondition the call with an ult |
| 881 | // against 0, but is that worth the complexity? |
| 882 | break; |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | case Builtin::BIpow: |
| 886 | case Builtin::BIpowf: |
| 887 | case Builtin::BIpowl: { |
| 888 | // Rewrite sqrt to intrinsic if allowed. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 889 | if (!FD->hasAttr<ConstAttr>()) |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 890 | break; |
| 891 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 892 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
| 893 | const llvm::Type *ArgType = Base->getType(); |
| 894 | Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1); |
| 895 | return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); |
| 896 | } |
Eli Friedman | ba68b08 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 897 | |
| 898 | case Builtin::BI__builtin_signbit: |
| 899 | case Builtin::BI__builtin_signbitf: |
| 900 | case Builtin::BI__builtin_signbitl: { |
| 901 | LLVMContext &C = CGM.getLLVMContext(); |
| 902 | |
| 903 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 904 | const llvm::Type *ArgTy = Arg->getType(); |
| 905 | if (ArgTy->isPPC_FP128Ty()) |
| 906 | break; // FIXME: I'm not sure what the right implementation is here. |
| 907 | int ArgWidth = ArgTy->getPrimitiveSizeInBits(); |
| 908 | const llvm::Type *ArgIntTy = llvm::IntegerType::get(C, ArgWidth); |
| 909 | Value *BCArg = Builder.CreateBitCast(Arg, ArgIntTy); |
| 910 | Value *ZeroCmp = llvm::Constant::getNullValue(ArgIntTy); |
| 911 | Value *Result = Builder.CreateICmpSLT(BCArg, ZeroCmp); |
| 912 | return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType()))); |
| 913 | } |
Nate Begeman | 7ea2e3f | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 914 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 915 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 916 | // If this is an alias for a libm function (e.g. __builtin_sin) turn it into |
| 917 | // that function. |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 918 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID) || |
| 919 | getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 920 | return EmitCall(E->getCallee()->getType(), |
| 921 | CGM.getBuiltinLibFunction(FD, BuiltinID), |
Anders Carlsson | d2490a9 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 922 | ReturnValueSlot(), |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 923 | E->arg_begin(), E->arg_end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 925 | // See if we have a target specific intrinsic. |
Dale Johannesen | a6f80ef | 2009-02-05 01:50:47 +0000 | [diff] [blame] | 926 | const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 927 | Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; |
| 928 | if (const char *Prefix = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | llvm::Triple::getArchTypePrefix(Target.getTriple().getArch())) |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 930 | IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 932 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
| 933 | SmallVector<Value*, 16> Args; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 935 | Function *F = CGM.getIntrinsic(IntrinsicID); |
| 936 | const llvm::FunctionType *FTy = F->getFunctionType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 937 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 938 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
| 939 | Value *ArgValue = EmitScalarExpr(E->getArg(i)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 940 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 941 | // If the intrinsic arg type is different from the builtin arg type |
| 942 | // we need to do a bit cast. |
| 943 | const llvm::Type *PTy = FTy->getParamType(i); |
| 944 | if (PTy != ArgValue->getType()) { |
| 945 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 946 | "Must be able to losslessly bit cast to param"); |
| 947 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 948 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 949 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 950 | Args.push_back(ArgValue); |
| 951 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 952 | |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 953 | Value *V = Builder.CreateCall(F, Args.data(), Args.data() + Args.size()); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 954 | QualType BuiltinRetType = E->getType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 956 | const llvm::Type *RetTy = llvm::Type::getVoidTy(VMContext); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 957 | if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 959 | if (RetTy != V->getType()) { |
| 960 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 961 | "Must be able to losslessly bit cast result type"); |
| 962 | V = Builder.CreateBitCast(V, RetTy); |
| 963 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 965 | return RValue::get(V); |
| 966 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 968 | // See if we have a target specific builtin that needs to be lowered. |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 969 | if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 970 | return RValue::get(V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 972 | ErrorUnsupported(E, "builtin function"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 974 | // Unknown builtin, for now just dump it out and return undef. |
| 975 | if (hasAggregateLLVMType(E->getType())) |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 976 | return RValue::getAggregate(CreateMemTemp(E->getType())); |
Owen Anderson | 03e2050 | 2009-07-30 23:11:26 +0000 | [diff] [blame] | 977 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 978 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 979 | |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 980 | Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, |
| 981 | const CallExpr *E) { |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 982 | switch (Target.getTriple().getArch()) { |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 983 | case llvm::Triple::arm: |
| 984 | case llvm::Triple::thumb: |
| 985 | return EmitARMBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 986 | case llvm::Triple::x86: |
| 987 | case llvm::Triple::x86_64: |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 988 | return EmitX86BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 989 | case llvm::Triple::ppc: |
| 990 | case llvm::Triple::ppc64: |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 991 | return EmitPPCBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 992 | default: |
| 993 | return 0; |
| 994 | } |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 995 | } |
| 996 | |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 997 | const llvm::VectorType *GetNeonType(LLVMContext &C, unsigned type, bool q) { |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 998 | switch (type) { |
| 999 | default: break; |
| 1000 | case 0: |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1001 | case 5: return llvm::VectorType::get(llvm::Type::getInt8Ty(C), 8 << (int)q); |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1002 | case 6: |
| 1003 | case 7: |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1004 | case 1: return llvm::VectorType::get(llvm::Type::getInt16Ty(C),4 << (int)q); |
| 1005 | case 2: return llvm::VectorType::get(llvm::Type::getInt32Ty(C),2 << (int)q); |
| 1006 | case 3: return llvm::VectorType::get(llvm::Type::getInt64Ty(C),1 << (int)q); |
| 1007 | case 4: return llvm::VectorType::get(llvm::Type::getFloatTy(C),2 << (int)q); |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1008 | }; |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1012 | Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) { |
| 1013 | unsigned nElts = cast<llvm::VectorType>(V->getType())->getNumElements(); |
| 1014 | SmallVector<Constant*, 16> Indices(nElts, C); |
| 1015 | Value* SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 1016 | return Builder.CreateShuffleVector(V, V, SV, "lane"); |
| 1017 | } |
| 1018 | |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1019 | Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops, |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1020 | const char *name, bool splat, |
| 1021 | unsigned shift, bool rightshift) { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1022 | unsigned j = 0; |
| 1023 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 1024 | ai != ae; ++ai, ++j) |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1025 | if (shift > 0 && shift == j) |
| 1026 | Ops[j] = EmitNeonShiftVector(Ops[j], ai->getType(), rightshift); |
| 1027 | else |
| 1028 | Ops[j] = Builder.CreateBitCast(Ops[j], ai->getType(), name); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1029 | |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1030 | if (splat) { |
| 1031 | Ops[j-1] = EmitNeonSplat(Ops[j-1], cast<Constant>(Ops[j])); |
| 1032 | Ops.resize(j); |
| 1033 | } |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1034 | return Builder.CreateCall(F, Ops.begin(), Ops.end(), name); |
| 1035 | } |
| 1036 | |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1037 | Value *CodeGenFunction::EmitNeonShiftVector(Value *V, const llvm::Type *Ty, |
| 1038 | bool neg) { |
| 1039 | ConstantInt *CI = cast<ConstantInt>(V); |
| 1040 | int SV = CI->getSExtValue(); |
| 1041 | |
| 1042 | const llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 1043 | llvm::Constant *C = ConstantInt::get(VTy->getElementType(), neg ? -SV : SV); |
| 1044 | SmallVector<llvm::Constant*, 16> CV(VTy->getNumElements(), C); |
| 1045 | return llvm::ConstantVector::get(CV.begin(), CV.size()); |
| 1046 | } |
| 1047 | |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1048 | Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
| 1049 | const CallExpr *E) { |
Rafael Espindola | e140af3 | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 1050 | if (BuiltinID == ARM::BI__clear_cache) { |
Rafael Espindola | 79ba509 | 2010-06-07 17:26:50 +0000 | [diff] [blame] | 1051 | const FunctionDecl *FD = E->getDirectCallee(); |
| 1052 | Value *a = EmitScalarExpr(E->getArg(0)); |
| 1053 | Value *b = EmitScalarExpr(E->getArg(1)); |
| 1054 | const llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 1055 | const llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
| 1056 | llvm::StringRef Name = FD->getName(); |
| 1057 | return Builder.CreateCall2(CGM.CreateRuntimeFunction(FTy, Name), |
| 1058 | a, b); |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1059 | } |
Rafael Espindola | e140af3 | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 1060 | |
Rafael Espindola | e140af3 | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 1061 | // Determine the type of this overloaded NEON intrinsic. |
| 1062 | assert(BuiltinID > ARM::BI__builtin_thread_pointer); |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1063 | |
| 1064 | llvm::SmallVector<Value*, 4> Ops; |
Rafael Espindola | e140af3 | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 1065 | for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++) |
| 1066 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 1067 | |
| 1068 | llvm::APSInt Result; |
| 1069 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 1070 | if (!Arg->isIntegerConstantExpr(Result, getContext())) |
| 1071 | return 0; |
| 1072 | |
| 1073 | unsigned type = Result.getZExtValue(); |
| 1074 | bool usgn = type & 0x08; |
| 1075 | bool quad = type & 0x10; |
Nate Begeman | 0d15c53 | 2010-06-13 04:47:52 +0000 | [diff] [blame] | 1076 | bool poly = (type & 0x7) == 5 || (type & 0x7) == 6; |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1077 | bool splat = false; |
Rafael Espindola | e140af3 | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 1078 | |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1079 | const llvm::VectorType *VTy = GetNeonType(VMContext, type & 0x7, quad); |
| 1080 | const llvm::Type *Ty = VTy; |
Rafael Espindola | e140af3 | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 1081 | if (!Ty) |
| 1082 | return 0; |
| 1083 | |
| 1084 | unsigned Int; |
| 1085 | switch (BuiltinID) { |
| 1086 | default: return 0; |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1087 | case ARM::BI__builtin_neon_vaba_v: |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1088 | case ARM::BI__builtin_neon_vabaq_v: |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1089 | Int = usgn ? Intrinsic::arm_neon_vabau : Intrinsic::arm_neon_vabas; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1090 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vaba"); |
| 1091 | case ARM::BI__builtin_neon_vabal_v: |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1092 | Int = usgn ? Intrinsic::arm_neon_vabalu : Intrinsic::arm_neon_vabals; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1093 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vabal"); |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1094 | case ARM::BI__builtin_neon_vabd_v: |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1095 | case ARM::BI__builtin_neon_vabdq_v: |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1096 | Int = usgn ? Intrinsic::arm_neon_vabdu : Intrinsic::arm_neon_vabds; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1097 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vabd"); |
| 1098 | case ARM::BI__builtin_neon_vabdl_v: |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1099 | Int = usgn ? Intrinsic::arm_neon_vabdlu : Intrinsic::arm_neon_vabdls; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1100 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vabdl"); |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1101 | case ARM::BI__builtin_neon_vabs_v: |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1102 | case ARM::BI__builtin_neon_vabsq_v: |
| 1103 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vabs, &Ty, 1), |
| 1104 | Ops, "vabs"); |
| 1105 | case ARM::BI__builtin_neon_vaddhn_v: |
| 1106 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vaddhn, &Ty, 1), |
| 1107 | Ops, "vaddhn"); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1108 | case ARM::BI__builtin_neon_vaddl_v: |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1109 | Int = usgn ? Intrinsic::arm_neon_vaddlu : Intrinsic::arm_neon_vaddls; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1110 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vaddl"); |
| 1111 | case ARM::BI__builtin_neon_vaddw_v: |
Nate Begeman | 998622c | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1112 | Int = usgn ? Intrinsic::arm_neon_vaddws : Intrinsic::arm_neon_vaddwu; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1113 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vaddw"); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1114 | case ARM::BI__builtin_neon_vcale_v: |
| 1115 | std::swap(Ops[0], Ops[1]); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1116 | case ARM::BI__builtin_neon_vcage_v: { |
| 1117 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacged, &Ty, 1); |
| 1118 | return EmitNeonCall(F, Ops, "vcage"); |
| 1119 | } |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1120 | case ARM::BI__builtin_neon_vcaleq_v: |
| 1121 | std::swap(Ops[0], Ops[1]); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1122 | case ARM::BI__builtin_neon_vcageq_v: { |
| 1123 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacgeq, &Ty, 1); |
| 1124 | return EmitNeonCall(F, Ops, "vcage"); |
| 1125 | } |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1126 | case ARM::BI__builtin_neon_vcalt_v: |
| 1127 | std::swap(Ops[0], Ops[1]); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1128 | case ARM::BI__builtin_neon_vcagt_v: { |
| 1129 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacgtd, &Ty, 1); |
| 1130 | return EmitNeonCall(F, Ops, "vcagt"); |
| 1131 | } |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1132 | case ARM::BI__builtin_neon_vcaltq_v: |
| 1133 | std::swap(Ops[0], Ops[1]); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1134 | case ARM::BI__builtin_neon_vcagtq_v: { |
| 1135 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacgtq, &Ty, 1); |
| 1136 | return EmitNeonCall(F, Ops, "vcagt"); |
| 1137 | } |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1138 | case ARM::BI__builtin_neon_vcls_v: |
| 1139 | case ARM::BI__builtin_neon_vclsq_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1140 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vcls, &Ty, 1); |
| 1141 | return EmitNeonCall(F, Ops, "vcls"); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1142 | } |
| 1143 | case ARM::BI__builtin_neon_vclz_v: |
| 1144 | case ARM::BI__builtin_neon_vclzq_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1145 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vclz, &Ty, 1); |
| 1146 | return EmitNeonCall(F, Ops, "vclz"); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1147 | } |
| 1148 | case ARM::BI__builtin_neon_vcnt_v: |
| 1149 | case ARM::BI__builtin_neon_vcntq_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1150 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vcnt, &Ty, 1); |
| 1151 | return EmitNeonCall(F, Ops, "vcnt"); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1152 | } |
| 1153 | // FIXME: intrinsics for f16<->f32 convert missing from ARM target. |
| 1154 | case ARM::BI__builtin_neon_vcvt_f32_v: |
| 1155 | case ARM::BI__builtin_neon_vcvtq_f32_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1156 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1157 | Ty = GetNeonType(VMContext, 4, quad); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1158 | return usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 1159 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 1160 | } |
| 1161 | case ARM::BI__builtin_neon_vcvt_s32_v: |
| 1162 | case ARM::BI__builtin_neon_vcvt_u32_v: |
| 1163 | case ARM::BI__builtin_neon_vcvtq_s32_v: |
| 1164 | case ARM::BI__builtin_neon_vcvtq_u32_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1165 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(VMContext, 4, quad)); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1166 | return usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt") |
| 1167 | : Builder.CreateFPToSI(Ops[0], Ty, "vcvt"); |
| 1168 | } |
| 1169 | case ARM::BI__builtin_neon_vcvt_n_f32_v: |
| 1170 | case ARM::BI__builtin_neon_vcvtq_n_f32_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1171 | const llvm::Type *Tys[2] = { GetNeonType(VMContext, 4, quad), Ty }; |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1172 | Int = usgn ? Intrinsic::arm_neon_vcvtfxu2fp : Intrinsic::arm_neon_vcvtfxs2fp; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1173 | Function *F = CGM.getIntrinsic(Int, Tys, 2); |
| 1174 | return EmitNeonCall(F, Ops, "vcvt_n"); |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1175 | } |
| 1176 | case ARM::BI__builtin_neon_vcvt_n_s32_v: |
| 1177 | case ARM::BI__builtin_neon_vcvt_n_u32_v: |
| 1178 | case ARM::BI__builtin_neon_vcvtq_n_s32_v: |
| 1179 | case ARM::BI__builtin_neon_vcvtq_n_u32_v: { |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1180 | const llvm::Type *Tys[2] = { Ty, GetNeonType(VMContext, 4, quad) }; |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1181 | Int = usgn ? Intrinsic::arm_neon_vcvtfp2fxu : Intrinsic::arm_neon_vcvtfp2fxs; |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1182 | Function *F = CGM.getIntrinsic(Int, Tys, 2); |
| 1183 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 1184 | } |
| 1185 | case ARM::BI__builtin_neon_vext_v: |
| 1186 | case ARM::BI__builtin_neon_vextq_v: { |
| 1187 | ConstantInt *C = dyn_cast<ConstantInt>(Ops[2]); |
| 1188 | int CV = C->getSExtValue(); |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1189 | SmallVector<Constant*, 16> Indices; |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1190 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1191 | Indices.push_back(ConstantInt::get(Int32Ty, i+CV)); |
Nate Begeman | 30d9171 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1192 | |
| 1193 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1194 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 1195 | Value* SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1196 | return Builder.CreateShuffleVector(Ops[0], Ops[1], SV, "vext"); |
| 1197 | } |
Nate Begeman | 95450f6 | 2010-06-09 05:30:26 +0000 | [diff] [blame] | 1198 | case ARM::BI__builtin_neon_vget_lane_i8: |
| 1199 | case ARM::BI__builtin_neon_vget_lane_i16: |
| 1200 | case ARM::BI__builtin_neon_vget_lane_i32: |
| 1201 | case ARM::BI__builtin_neon_vget_lane_i64: |
| 1202 | case ARM::BI__builtin_neon_vget_lane_f32: |
| 1203 | case ARM::BI__builtin_neon_vgetq_lane_i8: |
| 1204 | case ARM::BI__builtin_neon_vgetq_lane_i16: |
| 1205 | case ARM::BI__builtin_neon_vgetq_lane_i32: |
| 1206 | case ARM::BI__builtin_neon_vgetq_lane_i64: |
| 1207 | case ARM::BI__builtin_neon_vgetq_lane_f32: |
Nate Begeman | df98e1d | 2010-06-09 18:04:15 +0000 | [diff] [blame] | 1208 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 1209 | "vget_lane"); |
| 1210 | case ARM::BI__builtin_neon_vhadd_v: |
| 1211 | case ARM::BI__builtin_neon_vhaddq_v: |
| 1212 | Int = usgn ? Intrinsic::arm_neon_vhaddu : Intrinsic::arm_neon_vhadds; |
| 1213 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vhadd"); |
| 1214 | case ARM::BI__builtin_neon_vhsub_v: |
| 1215 | case ARM::BI__builtin_neon_vhsubq_v: |
| 1216 | Int = usgn ? Intrinsic::arm_neon_vhsubu : Intrinsic::arm_neon_vhsubs; |
| 1217 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vhsub"); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1218 | case ARM::BI__builtin_neon_vld1_v: |
| 1219 | case ARM::BI__builtin_neon_vld1q_v: |
| 1220 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vld1, &Ty, 1), |
| 1221 | Ops, "vld1"); |
| 1222 | case ARM::BI__builtin_neon_vld1_lane_v: |
| 1223 | case ARM::BI__builtin_neon_vld1q_lane_v: |
| 1224 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 1225 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 1226 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1227 | Ops[0] = Builder.CreateLoad(Ops[0]); |
| 1228 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane"); |
| 1229 | case ARM::BI__builtin_neon_vld1_dup_v: |
| 1230 | case ARM::BI__builtin_neon_vld1q_dup_v: { |
| 1231 | Value *V = UndefValue::get(Ty); |
| 1232 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 1233 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1234 | Ops[0] = Builder.CreateLoad(Ops[0]); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1235 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1236 | Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI); |
| 1237 | return EmitNeonSplat(Ops[0], CI); |
| 1238 | } |
| 1239 | case ARM::BI__builtin_neon_vld2_v: |
| 1240 | case ARM::BI__builtin_neon_vld2q_v: { |
| 1241 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld2, &Ty, 1); |
| 1242 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 1243 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1244 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1245 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1246 | } |
| 1247 | case ARM::BI__builtin_neon_vld3_v: |
| 1248 | case ARM::BI__builtin_neon_vld3q_v: { |
| 1249 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld3, &Ty, 1); |
| 1250 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 1251 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1252 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1253 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1254 | } |
| 1255 | case ARM::BI__builtin_neon_vld4_v: |
| 1256 | case ARM::BI__builtin_neon_vld4q_v: { |
| 1257 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld4, &Ty, 1); |
| 1258 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 1259 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1260 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1261 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1262 | } |
| 1263 | case ARM::BI__builtin_neon_vld2_lane_v: |
| 1264 | case ARM::BI__builtin_neon_vld2q_lane_v: { |
| 1265 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld2lane, &Ty, 1); |
| 1266 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 1267 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 1268 | Ops[1] = Builder.CreateCall(F, Ops.begin() + 1, Ops.end(), "vld2_lane"); |
| 1269 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1270 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1271 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1272 | } |
| 1273 | case ARM::BI__builtin_neon_vld3_lane_v: |
| 1274 | case ARM::BI__builtin_neon_vld3q_lane_v: { |
| 1275 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld3lane, &Ty, 1); |
| 1276 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 1277 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 1278 | Ops[4] = Builder.CreateBitCast(Ops[4], Ty); |
| 1279 | Ops[1] = Builder.CreateCall(F, Ops.begin() + 1, Ops.end(), "vld3_lane"); |
| 1280 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1281 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1282 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1283 | } |
| 1284 | case ARM::BI__builtin_neon_vld4_lane_v: |
| 1285 | case ARM::BI__builtin_neon_vld4q_lane_v: { |
| 1286 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld4lane, &Ty, 1); |
| 1287 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 1288 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 1289 | Ops[4] = Builder.CreateBitCast(Ops[4], Ty); |
| 1290 | Ops[5] = Builder.CreateBitCast(Ops[5], Ty); |
| 1291 | Ops[1] = Builder.CreateCall(F, Ops.begin() + 1, Ops.end(), "vld3_lane"); |
| 1292 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1293 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1294 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1295 | } |
| 1296 | case ARM::BI__builtin_neon_vld2_dup_v: |
| 1297 | case ARM::BI__builtin_neon_vld3_dup_v: |
| 1298 | case ARM::BI__builtin_neon_vld4_dup_v: { |
| 1299 | switch (BuiltinID) { |
| 1300 | case ARM::BI__builtin_neon_vld2_dup_v: |
| 1301 | Int = Intrinsic::arm_neon_vld2lane; |
| 1302 | break; |
| 1303 | case ARM::BI__builtin_neon_vld3_dup_v: |
| 1304 | Int = Intrinsic::arm_neon_vld2lane; |
| 1305 | break; |
| 1306 | case ARM::BI__builtin_neon_vld4_dup_v: |
| 1307 | Int = Intrinsic::arm_neon_vld2lane; |
| 1308 | break; |
| 1309 | default: assert(0 && "unknown vld_dup intrinsic?"); |
| 1310 | } |
| 1311 | Function *F = CGM.getIntrinsic(Int, &Ty, 1); |
| 1312 | const llvm::StructType *STy = cast<llvm::StructType>(F->getReturnType()); |
| 1313 | |
| 1314 | SmallVector<Value*, 6> Args; |
| 1315 | Args.push_back(Ops[1]); |
| 1316 | Args.append(STy->getNumElements(), UndefValue::get(Ty)); |
| 1317 | |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1318 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1319 | Args.push_back(CI); |
| 1320 | |
| 1321 | Ops[1] = Builder.CreateCall(F, Args.begin(), Args.end(), "vld_dup"); |
| 1322 | // splat lane 0 to all elts in each vector of the result. |
| 1323 | for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { |
| 1324 | Value *Val = Builder.CreateExtractValue(Ops[1], i); |
| 1325 | Value *Elt = Builder.CreateBitCast(Val, Ty); |
| 1326 | Elt = EmitNeonSplat(Elt, CI); |
| 1327 | Elt = Builder.CreateBitCast(Elt, Val->getType()); |
| 1328 | Ops[1] = Builder.CreateInsertValue(Ops[1], Elt, i); |
| 1329 | } |
| 1330 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1331 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1332 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1333 | } |
Nate Begeman | df98e1d | 2010-06-09 18:04:15 +0000 | [diff] [blame] | 1334 | case ARM::BI__builtin_neon_vmax_v: |
| 1335 | case ARM::BI__builtin_neon_vmaxq_v: |
| 1336 | Int = usgn ? Intrinsic::arm_neon_vmaxu : Intrinsic::arm_neon_vmaxs; |
| 1337 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vmax"); |
| 1338 | case ARM::BI__builtin_neon_vmin_v: |
| 1339 | case ARM::BI__builtin_neon_vminq_v: |
| 1340 | Int = usgn ? Intrinsic::arm_neon_vminu : Intrinsic::arm_neon_vmins; |
| 1341 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vmin"); |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1342 | case ARM::BI__builtin_neon_vmlal_lane_v: |
| 1343 | splat = true; |
Nate Begeman | df98e1d | 2010-06-09 18:04:15 +0000 | [diff] [blame] | 1344 | case ARM::BI__builtin_neon_vmlal_v: |
| 1345 | Int = usgn ? Intrinsic::arm_neon_vmlalu : Intrinsic::arm_neon_vmlals; |
Nate Begeman | d075c01 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1346 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vmlal", splat); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1347 | case ARM::BI__builtin_neon_vmlsl_lane_v: |
| 1348 | splat = true; |
| 1349 | case ARM::BI__builtin_neon_vmlsl_v: |
| 1350 | Int = usgn ? Intrinsic::arm_neon_vmlslu : Intrinsic::arm_neon_vmlsls; |
| 1351 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vmlsl", splat); |
Nate Begeman | df98e1d | 2010-06-09 18:04:15 +0000 | [diff] [blame] | 1352 | case ARM::BI__builtin_neon_vmovl_v: |
| 1353 | Int = usgn ? Intrinsic::arm_neon_vmovlu : Intrinsic::arm_neon_vmovls; |
| 1354 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vmovl"); |
| 1355 | case ARM::BI__builtin_neon_vmovn_v: |
| 1356 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vmovn, &Ty, 1), |
| 1357 | Ops, "vmovn"); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1358 | case ARM::BI__builtin_neon_vmull_lane_v: |
| 1359 | splat = true; |
| 1360 | case ARM::BI__builtin_neon_vmull_v: |
| 1361 | Int = usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls; |
| 1362 | Int = poly ? (unsigned)Intrinsic::arm_neon_vmullp : Int; |
| 1363 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vmlal", splat); |
Nate Begeman | df98e1d | 2010-06-09 18:04:15 +0000 | [diff] [blame] | 1364 | case ARM::BI__builtin_neon_vpadal_v: |
| 1365 | case ARM::BI__builtin_neon_vpadalq_v: |
| 1366 | Int = usgn ? Intrinsic::arm_neon_vpadalu : Intrinsic::arm_neon_vpadals; |
| 1367 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vpadal"); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1368 | case ARM::BI__builtin_neon_vpadd_v: |
| 1369 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vpadd, &Ty, 1), |
| 1370 | Ops, "vpadd"); |
| 1371 | case ARM::BI__builtin_neon_vpaddl_v: |
| 1372 | case ARM::BI__builtin_neon_vpaddlq_v: |
| 1373 | Int = usgn ? Intrinsic::arm_neon_vpaddlu : Intrinsic::arm_neon_vpaddls; |
| 1374 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vpaddl"); |
| 1375 | case ARM::BI__builtin_neon_vpmax_v: |
| 1376 | Int = usgn ? Intrinsic::arm_neon_vpmaxu : Intrinsic::arm_neon_vpmaxs; |
| 1377 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vpmax"); |
| 1378 | case ARM::BI__builtin_neon_vpmin_v: |
| 1379 | Int = usgn ? Intrinsic::arm_neon_vpminu : Intrinsic::arm_neon_vpmins; |
| 1380 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vpmin"); |
| 1381 | case ARM::BI__builtin_neon_vqabs_v: |
| 1382 | case ARM::BI__builtin_neon_vqabsq_v: |
| 1383 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqabs, &Ty, 1), |
| 1384 | Ops, "vqabs"); |
| 1385 | case ARM::BI__builtin_neon_vqadd_v: |
| 1386 | case ARM::BI__builtin_neon_vqaddq_v: |
| 1387 | Int = usgn ? Intrinsic::arm_neon_vqaddu : Intrinsic::arm_neon_vqadds; |
| 1388 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqadd"); |
| 1389 | case ARM::BI__builtin_neon_vqdmlal_lane_v: |
| 1390 | splat = true; |
| 1391 | case ARM::BI__builtin_neon_vqdmlal_v: |
| 1392 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmlal, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1393 | Ops, "vqdmlal", splat); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1394 | case ARM::BI__builtin_neon_vqdmlsl_lane_v: |
| 1395 | splat = true; |
| 1396 | case ARM::BI__builtin_neon_vqdmlsl_v: |
| 1397 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmlsl, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1398 | Ops, "vqdmlsl", splat); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1399 | case ARM::BI__builtin_neon_vqdmulh_lane_v: |
| 1400 | case ARM::BI__builtin_neon_vqdmulhq_lane_v: |
| 1401 | splat = true; |
| 1402 | case ARM::BI__builtin_neon_vqdmulh_v: |
| 1403 | case ARM::BI__builtin_neon_vqdmulhq_v: |
| 1404 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmulh, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1405 | Ops, "vqdmulh", splat); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1406 | case ARM::BI__builtin_neon_vqdmull_lane_v: |
| 1407 | splat = true; |
| 1408 | case ARM::BI__builtin_neon_vqdmull_v: |
| 1409 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmull, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1410 | Ops, "vqdmull", splat); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1411 | case ARM::BI__builtin_neon_vqmovn_v: |
| 1412 | Int = usgn ? Intrinsic::arm_neon_vqmovnu : Intrinsic::arm_neon_vqmovns; |
| 1413 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqmovn"); |
| 1414 | case ARM::BI__builtin_neon_vqmovun_v: |
| 1415 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqmovnsu, &Ty, 1), |
| 1416 | Ops, "vqdmull"); |
| 1417 | case ARM::BI__builtin_neon_vqneg_v: |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1418 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqneg, &Ty, 1), |
| 1419 | Ops, "vqneg"); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1420 | case ARM::BI__builtin_neon_vqrdmulh_lane_v: |
| 1421 | case ARM::BI__builtin_neon_vqrdmulhq_lane_v: |
| 1422 | splat = true; |
| 1423 | case ARM::BI__builtin_neon_vqrdmulh_v: |
| 1424 | case ARM::BI__builtin_neon_vqrdmulhq_v: |
| 1425 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrdmulh, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1426 | Ops, "vqrdmulh", splat); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1427 | case ARM::BI__builtin_neon_vqrshl_v: |
| 1428 | case ARM::BI__builtin_neon_vqrshlq_v: |
| 1429 | Int = usgn ? Intrinsic::arm_neon_vqrshiftu : Intrinsic::arm_neon_vqrshifts; |
| 1430 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqrshl"); |
| 1431 | case ARM::BI__builtin_neon_vqrshrn_n_v: |
| 1432 | Int = usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns; |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1433 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqrshrn_n", false, |
| 1434 | 1, true); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1435 | case ARM::BI__builtin_neon_vqrshrun_n_v: |
| 1436 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrshiftnsu, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1437 | Ops, "vqrshrun_n", false, 1, true); |
| 1438 | case ARM::BI__builtin_neon_vqshl_v: |
| 1439 | case ARM::BI__builtin_neon_vqshlq_v: |
| 1440 | Int = usgn ? Intrinsic::arm_neon_vqshiftu : Intrinsic::arm_neon_vqshifts; |
| 1441 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqshl"); |
| 1442 | case ARM::BI__builtin_neon_vqshl_n_v: |
| 1443 | case ARM::BI__builtin_neon_vqshlq_n_v: |
| 1444 | Int = usgn ? Intrinsic::arm_neon_vqshiftu : Intrinsic::arm_neon_vqshifts; |
| 1445 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqshl_n", false, |
| 1446 | 1, false); |
| 1447 | case ARM::BI__builtin_neon_vqshlu_n_v: |
| 1448 | case ARM::BI__builtin_neon_vqshluq_n_v: |
| 1449 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftsu, &Ty, 1), |
| 1450 | Ops, "vqshlu", 1, false); |
| 1451 | case ARM::BI__builtin_neon_vqshrn_n_v: |
| 1452 | Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns; |
| 1453 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqshrn_n", false, |
| 1454 | 1, true); |
| 1455 | case ARM::BI__builtin_neon_vqshrun_n_v: |
| 1456 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftnsu, &Ty, 1), |
| 1457 | Ops, "vqshrun_n", false, 1, true); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1458 | case ARM::BI__builtin_neon_vqsub_v: |
| 1459 | case ARM::BI__builtin_neon_vqsubq_v: |
| 1460 | Int = usgn ? Intrinsic::arm_neon_vqsubu : Intrinsic::arm_neon_vqsubs; |
| 1461 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vqsub"); |
| 1462 | case ARM::BI__builtin_neon_vraddhn_v: |
| 1463 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vraddhn, &Ty, 1), |
| 1464 | Ops, "vraddhn"); |
| 1465 | case ARM::BI__builtin_neon_vrecpe_v: |
| 1466 | case ARM::BI__builtin_neon_vrecpeq_v: |
| 1467 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecpe, &Ty, 1), |
| 1468 | Ops, "vrecpe"); |
| 1469 | case ARM::BI__builtin_neon_vrecps_v: |
| 1470 | case ARM::BI__builtin_neon_vrecpsq_v: |
| 1471 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecps, &Ty, 1), |
| 1472 | Ops, "vrecps"); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1473 | case ARM::BI__builtin_neon_vrhadd_v: |
| 1474 | case ARM::BI__builtin_neon_vrhaddq_v: |
| 1475 | Int = usgn ? Intrinsic::arm_neon_vrhaddu : Intrinsic::arm_neon_vrhadds; |
| 1476 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vrhadd"); |
Nate Begeman | 5af93ef | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 1477 | case ARM::BI__builtin_neon_vrshl_v: |
| 1478 | case ARM::BI__builtin_neon_vrshlq_v: |
| 1479 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
| 1480 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vrshl"); |
| 1481 | case ARM::BI__builtin_neon_vrshrn_n_v: |
Nate Begeman | 5af93ef | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 1482 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrshiftn, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1483 | Ops, "vrshrn_n", false, 1, true); |
Nate Begeman | 5af93ef | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 1484 | case ARM::BI__builtin_neon_vrshr_n_v: |
| 1485 | case ARM::BI__builtin_neon_vrshrq_n_v: |
Nate Begeman | 5af93ef | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 1486 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1487 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vrshr_n", false, |
| 1488 | 1, true); |
Nate Begeman | 5af93ef | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 1489 | case ARM::BI__builtin_neon_vrsqrte_v: |
| 1490 | case ARM::BI__builtin_neon_vrsqrteq_v: |
| 1491 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrsqrte, &Ty, 1), |
| 1492 | Ops, "vrsqrte"); |
| 1493 | case ARM::BI__builtin_neon_vrsqrts_v: |
| 1494 | case ARM::BI__builtin_neon_vrsqrtsq_v: |
| 1495 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrsqrts, &Ty, 1), |
| 1496 | Ops, "vrsqrts"); |
| 1497 | case ARM::BI__builtin_neon_vrsra_n_v: |
| 1498 | case ARM::BI__builtin_neon_vrsraq_n_v: |
| 1499 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1500 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 1501 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, true); |
| 1502 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
| 1503 | Ops[1] = Builder.CreateCall2(CGM.getIntrinsic(Int, &Ty, 1), Ops[1], Ops[2]); |
| 1504 | return Builder.CreateAdd(Ops[0], Ops[1], "vrsra_n"); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1505 | case ARM::BI__builtin_neon_vrsubhn_v: |
| 1506 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrsubhn, &Ty, 1), |
| 1507 | Ops, "vrsubhn"); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1508 | case ARM::BI__builtin_neon_vset_lane_i8: |
| 1509 | case ARM::BI__builtin_neon_vset_lane_i16: |
| 1510 | case ARM::BI__builtin_neon_vset_lane_i32: |
| 1511 | case ARM::BI__builtin_neon_vset_lane_i64: |
| 1512 | case ARM::BI__builtin_neon_vset_lane_f32: |
| 1513 | case ARM::BI__builtin_neon_vsetq_lane_i8: |
| 1514 | case ARM::BI__builtin_neon_vsetq_lane_i16: |
| 1515 | case ARM::BI__builtin_neon_vsetq_lane_i32: |
| 1516 | case ARM::BI__builtin_neon_vsetq_lane_i64: |
| 1517 | case ARM::BI__builtin_neon_vsetq_lane_f32: |
| 1518 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 1519 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1520 | case ARM::BI__builtin_neon_vshl_v: |
| 1521 | case ARM::BI__builtin_neon_vshlq_v: |
| 1522 | Int = usgn ? Intrinsic::arm_neon_vshiftu : Intrinsic::arm_neon_vshifts; |
| 1523 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vshl"); |
| 1524 | case ARM::BI__builtin_neon_vshll_n_v: |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1525 | Int = usgn ? Intrinsic::arm_neon_vshiftlu : Intrinsic::arm_neon_vshiftls; |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1526 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vshll", false, 1); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1527 | case ARM::BI__builtin_neon_vshl_n_v: |
| 1528 | case ARM::BI__builtin_neon_vshlq_n_v: |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1529 | Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false); |
| 1530 | return Builder.CreateShl(Builder.CreateBitCast(Ops[0],Ty), Ops[1], "vshl_n"); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1531 | case ARM::BI__builtin_neon_vshrn_n_v: |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1532 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftn, &Ty, 1), |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1533 | Ops, "vshrn_n", false, 1, true); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1534 | case ARM::BI__builtin_neon_vshr_n_v: |
| 1535 | case ARM::BI__builtin_neon_vshrq_n_v: |
| 1536 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1537 | Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1538 | if (usgn) |
| 1539 | return Builder.CreateLShr(Ops[0], Ops[1], "vshr_n"); |
| 1540 | else |
| 1541 | return Builder.CreateAShr(Ops[0], Ops[1], "vshr_n"); |
| 1542 | case ARM::BI__builtin_neon_vsri_n_v: |
| 1543 | case ARM::BI__builtin_neon_vsriq_n_v: |
| 1544 | poly = true; |
| 1545 | case ARM::BI__builtin_neon_vsli_n_v: |
| 1546 | case ARM::BI__builtin_neon_vsliq_n_v: |
| 1547 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, poly); |
| 1548 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftins, &Ty, 1), |
| 1549 | Ops, "vsli_n"); |
| 1550 | case ARM::BI__builtin_neon_vsra_n_v: |
| 1551 | case ARM::BI__builtin_neon_vsraq_n_v: |
| 1552 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1553 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Nate Begeman | 61eecf5 | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1554 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, false); |
Nate Begeman | 464ccb6 | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1555 | if (usgn) |
| 1556 | Ops[1] = Builder.CreateLShr(Ops[1], Ops[2], "vsra_n"); |
| 1557 | else |
| 1558 | Ops[1] = Builder.CreateAShr(Ops[1], Ops[2], "vsra_n"); |
| 1559 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 1560 | case ARM::BI__builtin_neon_vst1_v: |
| 1561 | case ARM::BI__builtin_neon_vst1q_v: |
| 1562 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst1, &Ty, 1), |
| 1563 | Ops, ""); |
| 1564 | case ARM::BI__builtin_neon_vst1_lane_v: |
| 1565 | case ARM::BI__builtin_neon_vst1q_lane_v: |
| 1566 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 1567 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 1568 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 1569 | return Builder.CreateStore(Ops[1], Builder.CreateBitCast(Ops[0], Ty)); |
| 1570 | case ARM::BI__builtin_neon_vst2_v: |
| 1571 | case ARM::BI__builtin_neon_vst2q_v: |
| 1572 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst2, &Ty, 1), |
| 1573 | Ops, ""); |
| 1574 | case ARM::BI__builtin_neon_vst2_lane_v: |
| 1575 | case ARM::BI__builtin_neon_vst2q_lane_v: |
| 1576 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst2lane, &Ty, 1), |
| 1577 | Ops, ""); |
| 1578 | case ARM::BI__builtin_neon_vst3_v: |
| 1579 | case ARM::BI__builtin_neon_vst3q_v: |
| 1580 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst3, &Ty, 1), |
| 1581 | Ops, ""); |
| 1582 | case ARM::BI__builtin_neon_vst3_lane_v: |
| 1583 | case ARM::BI__builtin_neon_vst3q_lane_v: |
| 1584 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst3lane, &Ty, 1), |
| 1585 | Ops, ""); |
| 1586 | case ARM::BI__builtin_neon_vst4_v: |
| 1587 | case ARM::BI__builtin_neon_vst4q_v: |
| 1588 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst4, &Ty, 1), |
| 1589 | Ops, ""); |
| 1590 | case ARM::BI__builtin_neon_vst4_lane_v: |
| 1591 | case ARM::BI__builtin_neon_vst4q_lane_v: |
| 1592 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst4lane, &Ty, 1), |
| 1593 | Ops, ""); |
Nate Begeman | 548f7da | 2010-06-10 18:11:55 +0000 | [diff] [blame] | 1594 | case ARM::BI__builtin_neon_vsubhn_v: |
| 1595 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vsubhn, &Ty, 1), |
| 1596 | Ops, "vsubhn"); |
| 1597 | case ARM::BI__builtin_neon_vsubl_v: |
| 1598 | Int = usgn ? Intrinsic::arm_neon_vsublu : Intrinsic::arm_neon_vsubls; |
| 1599 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vsubl"); |
| 1600 | case ARM::BI__builtin_neon_vsubw_v: |
| 1601 | Int = usgn ? Intrinsic::arm_neon_vsubws : Intrinsic::arm_neon_vsubwu; |
| 1602 | return EmitNeonCall(CGM.getIntrinsic(Int, &Ty, 1), Ops, "vsubw"); |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1603 | case ARM::BI__builtin_neon_vtbl1_v: |
| 1604 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1), |
| 1605 | Ops, "vtbl1"); |
| 1606 | case ARM::BI__builtin_neon_vtbl2_v: |
| 1607 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl2), |
| 1608 | Ops, "vtbl2"); |
| 1609 | case ARM::BI__builtin_neon_vtbl3_v: |
| 1610 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl3), |
| 1611 | Ops, "vtbl3"); |
| 1612 | case ARM::BI__builtin_neon_vtbl4_v: |
| 1613 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl4), |
| 1614 | Ops, "vtbl4"); |
| 1615 | case ARM::BI__builtin_neon_vtbx1_v: |
| 1616 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx1), |
| 1617 | Ops, "vtbx1"); |
| 1618 | case ARM::BI__builtin_neon_vtbx2_v: |
| 1619 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx2), |
| 1620 | Ops, "vtbx2"); |
| 1621 | case ARM::BI__builtin_neon_vtbx3_v: |
| 1622 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx3), |
| 1623 | Ops, "vtbx3"); |
| 1624 | case ARM::BI__builtin_neon_vtbx4_v: |
| 1625 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx4), |
| 1626 | Ops, "vtbx4"); |
| 1627 | case ARM::BI__builtin_neon_vtst_v: |
| 1628 | case ARM::BI__builtin_neon_vtstq_v: { |
| 1629 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 1630 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 1631 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 1632 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
| 1633 | ConstantAggregateZero::get(Ty)); |
| 1634 | return Builder.CreateSExt(Ops[0], Ty, "vtst"); |
| 1635 | } |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1636 | case ARM::BI__builtin_neon_vtrn_v: |
| 1637 | case ARM::BI__builtin_neon_vtrnq_v: { |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1638 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1639 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1640 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1641 | Value *SV; |
| 1642 | |
| 1643 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 1644 | SmallVector<Constant*, 16> Indices; |
| 1645 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1646 | Indices.push_back(ConstantInt::get(Int32Ty, i+vi)); |
| 1647 | Indices.push_back(ConstantInt::get(Int32Ty, i+e+vi)); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1648 | } |
| 1649 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi); |
| 1650 | SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 1651 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vtrn"); |
| 1652 | SV = Builder.CreateStore(SV, Addr); |
| 1653 | } |
| 1654 | return SV; |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1655 | } |
| 1656 | case ARM::BI__builtin_neon_vuzp_v: |
| 1657 | case ARM::BI__builtin_neon_vuzpq_v: { |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1658 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1659 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1660 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1661 | Value *SV; |
| 1662 | |
| 1663 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 1664 | SmallVector<Constant*, 16> Indices; |
| 1665 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1666 | Indices.push_back(ConstantInt::get(Int32Ty, 2*i+vi)); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1667 | |
| 1668 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi); |
| 1669 | SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 1670 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vuzp"); |
| 1671 | SV = Builder.CreateStore(SV, Addr); |
| 1672 | } |
| 1673 | return SV; |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1674 | } |
| 1675 | case ARM::BI__builtin_neon_vzip_v: |
| 1676 | case ARM::BI__builtin_neon_vzipq_v: { |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1677 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
Nate Begeman | 1c2a88c | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 1678 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1679 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1680 | Value *SV; |
| 1681 | |
| 1682 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 1683 | SmallVector<Constant*, 16> Indices; |
| 1684 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1685 | Indices.push_back(ConstantInt::get(Int32Ty, (i >> 1))); |
| 1686 | Indices.push_back(ConstantInt::get(Int32Ty, (i >> 1)+e)); |
Nate Begeman | 4be5430 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 1687 | } |
| 1688 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi); |
| 1689 | SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 1690 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); |
| 1691 | SV = Builder.CreateStore(SV, Addr); |
| 1692 | } |
| 1693 | return SV; |
Nate Begeman | 9eb65a5 | 2010-06-08 00:17:19 +0000 | [diff] [blame] | 1694 | } |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1695 | } |
| 1696 | } |
| 1697 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1698 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 1699 | const CallExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1700 | |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1701 | llvm::SmallVector<Value*, 4> Ops; |
| 1702 | |
| 1703 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 1704 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 1705 | |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 1706 | switch (BuiltinID) { |
Anders Carlsson | 46a26b0 | 2007-12-09 23:39:18 +0000 | [diff] [blame] | 1707 | default: return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | case X86::BI__builtin_ia32_pslldi128: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1709 | case X86::BI__builtin_ia32_psllqi128: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1710 | case X86::BI__builtin_ia32_psllwi128: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1711 | case X86::BI__builtin_ia32_psradi128: |
| 1712 | case X86::BI__builtin_ia32_psrawi128: |
| 1713 | case X86::BI__builtin_ia32_psrldi128: |
| 1714 | case X86::BI__builtin_ia32_psrlqi128: |
| 1715 | case X86::BI__builtin_ia32_psrlwi128: { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1716 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty, "zext"); |
| 1717 | const llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 2); |
| 1718 | llvm::Value *Zero = llvm::ConstantInt::get(Int32Ty, 0); |
Owen Anderson | 03e2050 | 2009-07-30 23:11:26 +0000 | [diff] [blame] | 1719 | Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1720 | Ops[1], Zero, "insert"); |
| 1721 | Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); |
| 1722 | const char *name = 0; |
| 1723 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1724 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1725 | switch (BuiltinID) { |
| 1726 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 1727 | case X86::BI__builtin_ia32_pslldi128: |
| 1728 | name = "pslldi"; |
| 1729 | ID = Intrinsic::x86_sse2_psll_d; |
| 1730 | break; |
| 1731 | case X86::BI__builtin_ia32_psllqi128: |
| 1732 | name = "psllqi"; |
| 1733 | ID = Intrinsic::x86_sse2_psll_q; |
| 1734 | break; |
| 1735 | case X86::BI__builtin_ia32_psllwi128: |
| 1736 | name = "psllwi"; |
| 1737 | ID = Intrinsic::x86_sse2_psll_w; |
| 1738 | break; |
| 1739 | case X86::BI__builtin_ia32_psradi128: |
| 1740 | name = "psradi"; |
| 1741 | ID = Intrinsic::x86_sse2_psra_d; |
| 1742 | break; |
| 1743 | case X86::BI__builtin_ia32_psrawi128: |
| 1744 | name = "psrawi"; |
| 1745 | ID = Intrinsic::x86_sse2_psra_w; |
| 1746 | break; |
| 1747 | case X86::BI__builtin_ia32_psrldi128: |
| 1748 | name = "psrldi"; |
| 1749 | ID = Intrinsic::x86_sse2_psrl_d; |
| 1750 | break; |
| 1751 | case X86::BI__builtin_ia32_psrlqi128: |
| 1752 | name = "psrlqi"; |
| 1753 | ID = Intrinsic::x86_sse2_psrl_q; |
| 1754 | break; |
| 1755 | case X86::BI__builtin_ia32_psrlwi128: |
| 1756 | name = "psrlwi"; |
| 1757 | ID = Intrinsic::x86_sse2_psrl_w; |
| 1758 | break; |
| 1759 | } |
| 1760 | llvm::Function *F = CGM.getIntrinsic(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1761 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1762 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1763 | case X86::BI__builtin_ia32_pslldi: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1764 | case X86::BI__builtin_ia32_psllqi: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1765 | case X86::BI__builtin_ia32_psllwi: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1766 | case X86::BI__builtin_ia32_psradi: |
| 1767 | case X86::BI__builtin_ia32_psrawi: |
| 1768 | case X86::BI__builtin_ia32_psrldi: |
| 1769 | case X86::BI__builtin_ia32_psrlqi: |
| 1770 | case X86::BI__builtin_ia32_psrlwi: { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1771 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty, "zext"); |
| 1772 | const llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 1); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1773 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1774 | const char *name = 0; |
| 1775 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1776 | |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1777 | switch (BuiltinID) { |
| 1778 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 1779 | case X86::BI__builtin_ia32_pslldi: |
| 1780 | name = "pslldi"; |
| 1781 | ID = Intrinsic::x86_mmx_psll_d; |
| 1782 | break; |
| 1783 | case X86::BI__builtin_ia32_psllqi: |
| 1784 | name = "psllqi"; |
| 1785 | ID = Intrinsic::x86_mmx_psll_q; |
| 1786 | break; |
| 1787 | case X86::BI__builtin_ia32_psllwi: |
| 1788 | name = "psllwi"; |
| 1789 | ID = Intrinsic::x86_mmx_psll_w; |
| 1790 | break; |
| 1791 | case X86::BI__builtin_ia32_psradi: |
| 1792 | name = "psradi"; |
| 1793 | ID = Intrinsic::x86_mmx_psra_d; |
| 1794 | break; |
| 1795 | case X86::BI__builtin_ia32_psrawi: |
| 1796 | name = "psrawi"; |
| 1797 | ID = Intrinsic::x86_mmx_psra_w; |
| 1798 | break; |
| 1799 | case X86::BI__builtin_ia32_psrldi: |
| 1800 | name = "psrldi"; |
| 1801 | ID = Intrinsic::x86_mmx_psrl_d; |
| 1802 | break; |
| 1803 | case X86::BI__builtin_ia32_psrlqi: |
| 1804 | name = "psrlqi"; |
| 1805 | ID = Intrinsic::x86_mmx_psrl_q; |
| 1806 | break; |
| 1807 | case X86::BI__builtin_ia32_psrlwi: |
| 1808 | name = "psrlwi"; |
| 1809 | ID = Intrinsic::x86_mmx_psrl_w; |
| 1810 | break; |
| 1811 | } |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 1812 | llvm::Function *F = CGM.getIntrinsic(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1813 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 1814 | } |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 1815 | case X86::BI__builtin_ia32_cmpps: { |
| 1816 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps); |
| 1817 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpps"); |
| 1818 | } |
| 1819 | case X86::BI__builtin_ia32_cmpss: { |
| 1820 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss); |
| 1821 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpss"); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 1822 | } |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1823 | case X86::BI__builtin_ia32_ldmxcsr: { |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 1824 | const llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(VMContext); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1825 | Value *One = llvm::ConstantInt::get(Int32Ty, 1); |
| 1826 | Value *Tmp = Builder.CreateAlloca(Int32Ty, One, "tmp"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1827 | Builder.CreateStore(Ops[0], Tmp); |
| 1828 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame] | 1829 | Builder.CreateBitCast(Tmp, PtrTy)); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1830 | } |
| 1831 | case X86::BI__builtin_ia32_stmxcsr: { |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 1832 | const llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(VMContext); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1833 | Value *One = llvm::ConstantInt::get(Int32Ty, 1); |
| 1834 | Value *Tmp = Builder.CreateAlloca(Int32Ty, One, "tmp"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1835 | One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame] | 1836 | Builder.CreateBitCast(Tmp, PtrTy)); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1837 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 1838 | } |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 1839 | case X86::BI__builtin_ia32_cmppd: { |
| 1840 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd); |
| 1841 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmppd"); |
| 1842 | } |
| 1843 | case X86::BI__builtin_ia32_cmpsd: { |
| 1844 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd); |
| 1845 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpsd"); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 1846 | } |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1847 | case X86::BI__builtin_ia32_storehps: |
| 1848 | case X86::BI__builtin_ia32_storelps: { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1849 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(Int64Ty); |
| 1850 | llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1852 | // cast val v2i64 |
| 1853 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1854 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1855 | // extract (0, 1) |
| 1856 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1857 | llvm::Value *Idx = llvm::ConstantInt::get(Int32Ty, Index); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 1858 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 1859 | |
| 1860 | // cast pointer to i64 & store |
| 1861 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
| 1862 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 1863 | } |
Eric Christopher | 91b5927 | 2009-12-01 05:00:51 +0000 | [diff] [blame] | 1864 | case X86::BI__builtin_ia32_palignr: { |
Eric Christopher | e57aa9e | 2010-04-15 01:43:08 +0000 | [diff] [blame] | 1865 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
| 1866 | |
| 1867 | // If palignr is shifting the pair of input vectors less than 9 bytes, |
| 1868 | // emit a shuffle instruction. |
| 1869 | if (shiftVal <= 8) { |
Eric Christopher | e57aa9e | 2010-04-15 01:43:08 +0000 | [diff] [blame] | 1870 | llvm::SmallVector<llvm::Constant*, 8> Indices; |
| 1871 | for (unsigned i = 0; i != 8; ++i) |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1872 | Indices.push_back(llvm::ConstantInt::get(Int32Ty, shiftVal + i)); |
Eric Christopher | e57aa9e | 2010-04-15 01:43:08 +0000 | [diff] [blame] | 1873 | |
| 1874 | Value* SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 1875 | return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr"); |
| 1876 | } |
| 1877 | |
| 1878 | // If palignr is shifting the pair of input vectors more than 8 but less |
| 1879 | // than 16 bytes, emit a logical right shift of the destination. |
| 1880 | if (shiftVal < 16) { |
| 1881 | // MMX has these as 1 x i64 vectors for some odd optimization reasons. |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1882 | const llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 1); |
Eric Christopher | e57aa9e | 2010-04-15 01:43:08 +0000 | [diff] [blame] | 1883 | |
| 1884 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 1885 | Ops[1] = llvm::ConstantInt::get(VecTy, (shiftVal-8) * 8); |
| 1886 | |
| 1887 | // create i32 constant |
| 1888 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_mmx_psrl_q); |
| 1889 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + 2, "palignr"); |
| 1890 | } |
| 1891 | |
| 1892 | // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. |
| 1893 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Nate Begeman | c3420ff | 2009-12-14 05:15:02 +0000 | [diff] [blame] | 1894 | } |
| 1895 | case X86::BI__builtin_ia32_palignr128: { |
Nate Begeman | ce5818a | 2009-12-14 04:57:03 +0000 | [diff] [blame] | 1896 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
| 1897 | |
| 1898 | // If palignr is shifting the pair of input vectors less than 17 bytes, |
| 1899 | // emit a shuffle instruction. |
| 1900 | if (shiftVal <= 16) { |
Nate Begeman | ce5818a | 2009-12-14 04:57:03 +0000 | [diff] [blame] | 1901 | llvm::SmallVector<llvm::Constant*, 16> Indices; |
| 1902 | for (unsigned i = 0; i != 16; ++i) |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1903 | Indices.push_back(llvm::ConstantInt::get(Int32Ty, shiftVal + i)); |
Nate Begeman | ce5818a | 2009-12-14 04:57:03 +0000 | [diff] [blame] | 1904 | |
| 1905 | Value* SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 1906 | return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr"); |
| 1907 | } |
| 1908 | |
| 1909 | // If palignr is shifting the pair of input vectors more than 16 but less |
| 1910 | // than 32 bytes, emit a logical right shift of the destination. |
| 1911 | if (shiftVal < 32) { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1912 | const llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2); |
Nate Begeman | ce5818a | 2009-12-14 04:57:03 +0000 | [diff] [blame] | 1913 | |
| 1914 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1915 | Ops[1] = llvm::ConstantInt::get(Int32Ty, (shiftVal-16) * 8); |
Nate Begeman | ce5818a | 2009-12-14 04:57:03 +0000 | [diff] [blame] | 1916 | |
| 1917 | // create i32 constant |
| 1918 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_psrl_dq); |
| 1919 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + 2, "palignr"); |
| 1920 | } |
| 1921 | |
| 1922 | // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. |
| 1923 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Eric Christopher | 91b5927 | 2009-12-01 05:00:51 +0000 | [diff] [blame] | 1924 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1928 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 1929 | const CallExpr *E) { |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1930 | llvm::SmallVector<Value*, 4> Ops; |
| 1931 | |
| 1932 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 1933 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 1934 | |
| 1935 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 1936 | |
| 1937 | switch (BuiltinID) { |
| 1938 | default: return 0; |
| 1939 | |
Anton Korobeynikov | 4d3a7b0 | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 1940 | // vec_ld, vec_lvsl, vec_lvsr |
| 1941 | case PPC::BI__builtin_altivec_lvx: |
| 1942 | case PPC::BI__builtin_altivec_lvxl: |
| 1943 | case PPC::BI__builtin_altivec_lvebx: |
| 1944 | case PPC::BI__builtin_altivec_lvehx: |
| 1945 | case PPC::BI__builtin_altivec_lvewx: |
| 1946 | case PPC::BI__builtin_altivec_lvsl: |
| 1947 | case PPC::BI__builtin_altivec_lvsr: |
| 1948 | { |
| 1949 | Ops[1] = Builder.CreateBitCast(Ops[1], llvm::Type::getInt8PtrTy(VMContext)); |
| 1950 | |
| 1951 | Ops[0] = Builder.CreateGEP(Ops[1], Ops[0], "tmp"); |
| 1952 | Ops.pop_back(); |
| 1953 | |
| 1954 | switch (BuiltinID) { |
| 1955 | default: assert(0 && "Unsupported ld/lvsl/lvsr intrinsic!"); |
| 1956 | case PPC::BI__builtin_altivec_lvx: |
| 1957 | ID = Intrinsic::ppc_altivec_lvx; |
| 1958 | break; |
| 1959 | case PPC::BI__builtin_altivec_lvxl: |
| 1960 | ID = Intrinsic::ppc_altivec_lvxl; |
| 1961 | break; |
| 1962 | case PPC::BI__builtin_altivec_lvebx: |
| 1963 | ID = Intrinsic::ppc_altivec_lvebx; |
| 1964 | break; |
| 1965 | case PPC::BI__builtin_altivec_lvehx: |
| 1966 | ID = Intrinsic::ppc_altivec_lvehx; |
| 1967 | break; |
| 1968 | case PPC::BI__builtin_altivec_lvewx: |
| 1969 | ID = Intrinsic::ppc_altivec_lvewx; |
| 1970 | break; |
| 1971 | case PPC::BI__builtin_altivec_lvsl: |
| 1972 | ID = Intrinsic::ppc_altivec_lvsl; |
| 1973 | break; |
| 1974 | case PPC::BI__builtin_altivec_lvsr: |
| 1975 | ID = Intrinsic::ppc_altivec_lvsr; |
| 1976 | break; |
| 1977 | } |
| 1978 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 1979 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), ""); |
| 1980 | } |
| 1981 | |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1982 | // vec_st |
| 1983 | case PPC::BI__builtin_altivec_stvx: |
| 1984 | case PPC::BI__builtin_altivec_stvxl: |
| 1985 | case PPC::BI__builtin_altivec_stvebx: |
| 1986 | case PPC::BI__builtin_altivec_stvehx: |
| 1987 | case PPC::BI__builtin_altivec_stvewx: |
| 1988 | { |
| 1989 | Ops[2] = Builder.CreateBitCast(Ops[2], llvm::Type::getInt8PtrTy(VMContext)); |
Anton Korobeynikov | 4d3a7b0 | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 1990 | Ops[1] = Builder.CreateGEP(Ops[2], Ops[1], "tmp"); |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1991 | Ops.pop_back(); |
| 1992 | |
| 1993 | switch (BuiltinID) { |
Anton Korobeynikov | 4d3a7b0 | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 1994 | default: assert(0 && "Unsupported st intrinsic!"); |
Chris Lattner | dd17394 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 1995 | case PPC::BI__builtin_altivec_stvx: |
| 1996 | ID = Intrinsic::ppc_altivec_stvx; |
| 1997 | break; |
| 1998 | case PPC::BI__builtin_altivec_stvxl: |
| 1999 | ID = Intrinsic::ppc_altivec_stvxl; |
| 2000 | break; |
| 2001 | case PPC::BI__builtin_altivec_stvebx: |
| 2002 | ID = Intrinsic::ppc_altivec_stvebx; |
| 2003 | break; |
| 2004 | case PPC::BI__builtin_altivec_stvehx: |
| 2005 | ID = Intrinsic::ppc_altivec_stvehx; |
| 2006 | break; |
| 2007 | case PPC::BI__builtin_altivec_stvewx: |
| 2008 | ID = Intrinsic::ppc_altivec_stvewx; |
| 2009 | break; |
| 2010 | } |
| 2011 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 2012 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), ""); |
| 2013 | } |
| 2014 | } |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 2015 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2016 | } |