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