Anders Carlsson | 1d8e521 | 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 | 5b12ab8 | 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 | 1d8e521 | 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 | |
| 14 | #include "CodeGenFunction.h" |
David Majnemer | ba3e5ec | 2015-03-13 18:26:17 +0000 | [diff] [blame] | 15 | #include "CGCXXABI.h" |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 16 | #include "CGObjCRuntime.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "CodeGenModule.h" |
| 18 | #include "TargetInfo.h" |
Chris Lattner | 1eec660 | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
Chris Lattner | 5abdec7 | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 21 | #include "clang/Basic/TargetBuiltins.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/Basic/TargetInfo.h" |
Mark Lacey | a8e7df3 | 2013-10-30 21:53:58 +0000 | [diff] [blame] | 23 | #include "clang/CodeGen/CGFunctionInfo.h" |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringExtras.h" |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 25 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 26 | #include "llvm/IR/DataLayout.h" |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 27 | #include "llvm/IR/InlineAsm.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 28 | #include "llvm/IR/Intrinsics.h" |
Kit Barton | 8246f28 | 2015-03-25 19:41:41 +0000 | [diff] [blame] | 29 | #include <sstream> |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 30 | |
Anders Carlsson | 1d8e521 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 31 | using namespace clang; |
| 32 | using namespace CodeGen; |
Anders Carlsson | a020c43 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 35 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 36 | /// "__builtin_fabsf", return a Function* for "fabsf". |
| 37 | llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, |
| 38 | unsigned BuiltinID) { |
| 39 | assert(Context.BuiltinInfo.isLibFunction(BuiltinID)); |
| 40 | |
| 41 | // Get the name, skip over the __builtin_ prefix (if necessary). |
| 42 | StringRef Name; |
| 43 | GlobalDecl D(FD); |
| 44 | |
| 45 | // If the builtin has been declared explicitly with an assembler label, |
| 46 | // use the mangled name. This differs from the plain label on platforms |
| 47 | // that prefix labels. |
| 48 | if (FD->hasAttr<AsmLabelAttr>()) |
| 49 | Name = getMangledName(D); |
| 50 | else |
| 51 | Name = Context.BuiltinInfo.GetName(BuiltinID) + 10; |
| 52 | |
| 53 | llvm::FunctionType *Ty = |
| 54 | cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType())); |
| 55 | |
| 56 | return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable=*/false); |
| 57 | } |
| 58 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 59 | /// Emit the conversions required to turn the given value into an |
| 60 | /// integer of the given size. |
| 61 | static Value *EmitToInt(CodeGenFunction &CGF, llvm::Value *V, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 62 | QualType T, llvm::IntegerType *IntType) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 63 | V = CGF.EmitToMemory(V, T); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 64 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 65 | if (V->getType()->isPointerTy()) |
| 66 | return CGF.Builder.CreatePtrToInt(V, IntType); |
| 67 | |
| 68 | assert(V->getType() == IntType); |
| 69 | return V; |
Chandler Carruth | bc8cab1 | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 70 | } |
| 71 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 72 | static Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 73 | QualType T, llvm::Type *ResultType) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 74 | V = CGF.EmitFromMemory(V, T); |
| 75 | |
| 76 | if (ResultType->isPointerTy()) |
| 77 | return CGF.Builder.CreateIntToPtr(V, ResultType); |
| 78 | |
| 79 | assert(V->getType() == ResultType); |
| 80 | return V; |
Chandler Carruth | bc8cab1 | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Daniel Dunbar | 4fab57d | 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. |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 85 | static Value *MakeBinaryAtomicValue(CodeGenFunction &CGF, |
| 86 | llvm::AtomicRMWInst::BinOp Kind, |
| 87 | const CallExpr *E) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 88 | QualType T = E->getType(); |
| 89 | assert(E->getArg(0)->getType()->isPointerType()); |
| 90 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 91 | E->getArg(0)->getType()->getPointeeType())); |
| 92 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 93 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 94 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 95 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 96 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 97 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 98 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 99 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 100 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 101 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 102 | llvm::Value *Args[2]; |
| 103 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 104 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 105 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 106 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 107 | |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 108 | llvm::Value *Result = |
| 109 | CGF.Builder.CreateAtomicRMW(Kind, Args[0], Args[1], |
| 110 | llvm::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 111 | return EmitFromInt(CGF, Result, T, ValueType); |
| 112 | } |
| 113 | |
| 114 | static RValue EmitBinaryAtomic(CodeGenFunction &CGF, |
| 115 | llvm::AtomicRMWInst::BinOp Kind, |
| 116 | const CallExpr *E) { |
| 117 | return RValue::get(MakeBinaryAtomicValue(CGF, Kind, E)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /// Utility to insert an atomic instruction based Instrinsic::ID and |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 121 | /// the expression node, where the return value is the result of the |
| 122 | /// operation. |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 123 | static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF, |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 124 | llvm::AtomicRMWInst::BinOp Kind, |
| 125 | const CallExpr *E, |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 126 | Instruction::BinaryOps Op, |
| 127 | bool Invert = false) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 128 | QualType T = E->getType(); |
| 129 | assert(E->getArg(0)->getType()->isPointerType()); |
| 130 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 131 | E->getArg(0)->getType()->getPointeeType())); |
| 132 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 133 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 134 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 135 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 136 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 137 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 138 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 139 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 140 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 141 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 142 | llvm::Value *Args[2]; |
| 143 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 144 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 145 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 146 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 147 | |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 148 | llvm::Value *Result = |
| 149 | CGF.Builder.CreateAtomicRMW(Kind, Args[0], Args[1], |
| 150 | llvm::SequentiallyConsistent); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 151 | Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 152 | if (Invert) |
| 153 | Result = CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result, |
| 154 | llvm::ConstantInt::get(IntType, -1)); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 155 | Result = EmitFromInt(CGF, Result, T, ValueType); |
| 156 | return RValue::get(Result); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 159 | /// @brief Utility to insert an atomic cmpxchg instruction. |
| 160 | /// |
| 161 | /// @param CGF The current codegen function. |
| 162 | /// @param E Builtin call expression to convert to cmpxchg. |
| 163 | /// arg0 - address to operate on |
| 164 | /// arg1 - value to compare with |
| 165 | /// arg2 - new value |
| 166 | /// @param ReturnBool Specifies whether to return success flag of |
| 167 | /// cmpxchg result or the old value. |
| 168 | /// |
| 169 | /// @returns result of cmpxchg, according to ReturnBool |
| 170 | static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E, |
| 171 | bool ReturnBool) { |
| 172 | QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType(); |
| 173 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
| 174 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
| 175 | |
| 176 | llvm::IntegerType *IntType = llvm::IntegerType::get( |
| 177 | CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); |
| 178 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
| 179 | |
| 180 | Value *Args[3]; |
| 181 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 182 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
| 183 | llvm::Type *ValueType = Args[1]->getType(); |
| 184 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 185 | Args[2] = EmitToInt(CGF, CGF.EmitScalarExpr(E->getArg(2)), T, IntType); |
| 186 | |
| 187 | Value *Pair = CGF.Builder.CreateAtomicCmpXchg(Args[0], Args[1], Args[2], |
| 188 | llvm::SequentiallyConsistent, |
| 189 | llvm::SequentiallyConsistent); |
| 190 | if (ReturnBool) |
| 191 | // Extract boolean success flag and zext it to int. |
| 192 | return CGF.Builder.CreateZExt(CGF.Builder.CreateExtractValue(Pair, 1), |
| 193 | CGF.ConvertType(E->getType())); |
| 194 | else |
| 195 | // Extract old value and emit it using the same type as compare value. |
| 196 | return EmitFromInt(CGF, CGF.Builder.CreateExtractValue(Pair, 0), T, |
| 197 | ValueType); |
| 198 | } |
| 199 | |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 200 | /// EmitFAbs - Emit a call to @llvm.fabs(). |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 201 | static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) { |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 202 | Value *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType()); |
| 203 | llvm::CallInst *Call = CGF.Builder.CreateCall(F, V); |
| 204 | Call->setDoesNotAccessMemory(); |
| 205 | return Call; |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 208 | /// Emit the computation of the sign bit for a floating point value. Returns |
| 209 | /// the i1 sign bit value. |
| 210 | static Value *EmitSignBit(CodeGenFunction &CGF, Value *V) { |
| 211 | LLVMContext &C = CGF.CGM.getLLVMContext(); |
| 212 | |
| 213 | llvm::Type *Ty = V->getType(); |
| 214 | int Width = Ty->getPrimitiveSizeInBits(); |
| 215 | llvm::Type *IntTy = llvm::IntegerType::get(C, Width); |
| 216 | V = CGF.Builder.CreateBitCast(V, IntTy); |
| 217 | if (Ty->isPPC_FP128Ty()) { |
| 218 | // The higher-order double comes first, and so we need to truncate the |
| 219 | // pair to extract the overall sign. The order of the pair is the same |
| 220 | // in both little- and big-Endian modes. |
| 221 | Width >>= 1; |
| 222 | IntTy = llvm::IntegerType::get(C, Width); |
| 223 | V = CGF.Builder.CreateTrunc(V, IntTy); |
| 224 | } |
| 225 | Value *Zero = llvm::Constant::getNullValue(IntTy); |
| 226 | return CGF.Builder.CreateICmpSLT(V, Zero); |
| 227 | } |
| 228 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 229 | static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *Fn, |
| 230 | const CallExpr *E, llvm::Value *calleeValue) { |
Alexey Samsonov | 70b9c01 | 2014-08-21 20:26:47 +0000 | [diff] [blame] | 231 | return CGF.EmitCall(E->getCallee()->getType(), calleeValue, E, |
| 232 | ReturnValueSlot(), Fn); |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 235 | /// \brief Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.* |
| 236 | /// depending on IntrinsicID. |
| 237 | /// |
| 238 | /// \arg CGF The current codegen function. |
| 239 | /// \arg IntrinsicID The ID for the Intrinsic we wish to generate. |
| 240 | /// \arg X The first argument to the llvm.*.with.overflow.*. |
| 241 | /// \arg Y The second argument to the llvm.*.with.overflow.*. |
| 242 | /// \arg Carry The carry returned by the llvm.*.with.overflow.*. |
| 243 | /// \returns The result (i.e. sum/product) returned by the intrinsic. |
| 244 | static llvm::Value *EmitOverflowIntrinsic(CodeGenFunction &CGF, |
| 245 | const llvm::Intrinsic::ID IntrinsicID, |
| 246 | llvm::Value *X, llvm::Value *Y, |
| 247 | llvm::Value *&Carry) { |
| 248 | // Make sure we have integers of the same width. |
| 249 | assert(X->getType() == Y->getType() && |
| 250 | "Arguments must be the same type. (Did you forget to make sure both " |
| 251 | "arguments have the same integer width?)"); |
| 252 | |
NAKAMURA Takumi | 7ab4fbf | 2013-01-13 11:26:44 +0000 | [diff] [blame] | 253 | llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 254 | llvm::Value *Tmp = CGF.Builder.CreateCall(Callee, {X, Y}); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 255 | Carry = CGF.Builder.CreateExtractValue(Tmp, 1); |
| 256 | return CGF.Builder.CreateExtractValue(Tmp, 0); |
| 257 | } |
| 258 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 259 | RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 260 | unsigned BuiltinID, const CallExpr *E, |
| 261 | ReturnValueSlot ReturnValue) { |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 262 | // See if we can constant fold this builtin. If so, don't emit it at all. |
Anders Carlsson | c968790 | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 263 | Expr::EvalResult Result; |
Eli Friedman | df88c54 | 2012-01-06 20:03:09 +0000 | [diff] [blame] | 264 | if (E->EvaluateAsRValue(Result, CGM.getContext()) && |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 265 | !Result.hasSideEffects()) { |
Anders Carlsson | c968790 | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 266 | if (Result.Val.isInt()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 267 | return RValue::get(llvm::ConstantInt::get(getLLVMContext(), |
Owen Anderson | b7a2fe6 | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 268 | Result.Val.getInt())); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 269 | if (Result.Val.isFloat()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 270 | return RValue::get(llvm::ConstantFP::get(getLLVMContext(), |
| 271 | Result.Val.getFloat())); |
Chris Lattner | a1518b1 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 272 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 274 | switch (BuiltinID) { |
| 275 | default: break; // Handle intrinsics and libm functions below. |
Chris Lattner | a97132a | 2008-10-06 07:26:43 +0000 | [diff] [blame] | 276 | case Builtin::BI__builtin___CFStringMakeConstantString: |
David Chisnall | 481e3a8 | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 277 | case Builtin::BI__builtin___NSStringMakeConstantString: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 278 | return RValue::get(CGM.EmitConstantExpr(E, E->getType(), nullptr)); |
Chris Lattner | 0bf6791 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 279 | case Builtin::BI__builtin_stdarg_start: |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 280 | case Builtin::BI__builtin_va_start: |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 281 | case Builtin::BI__va_start: |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 282 | case Builtin::BI__builtin_va_end: { |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 283 | Value *ArgValue = (BuiltinID == Builtin::BI__va_start) |
| 284 | ? EmitScalarExpr(E->getArg(0)) |
| 285 | : EmitVAListRef(E->getArg(0)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 286 | llvm::Type *DestType = Int8PtrTy; |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 287 | if (ArgValue->getType() != DestType) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | ArgValue = Builder.CreateBitCast(ArgValue, DestType, |
Daniel Dunbar | e59313a | 2009-07-26 09:28:40 +0000 | [diff] [blame] | 289 | ArgValue->getName().data()); |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 290 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ? |
Chris Lattner | 0bf6791 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 292 | Intrinsic::vaend : Intrinsic::vastart; |
Chris Lattner | b8be97e | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 293 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 294 | } |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 295 | case Builtin::BI__builtin_va_copy: { |
Eli Friedman | ddea0ad | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 296 | Value *DstPtr = EmitVAListRef(E->getArg(0)); |
| 297 | Value *SrcPtr = EmitVAListRef(E->getArg(1)); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 298 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 299 | llvm::Type *Type = Int8PtrTy; |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 300 | |
| 301 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 302 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 303 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), |
| 304 | {DstPtr, SrcPtr})); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 305 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 306 | case Builtin::BI__builtin_abs: |
Eli Friedman | 65499b4 | 2012-01-17 22:11:30 +0000 | [diff] [blame] | 307 | case Builtin::BI__builtin_labs: |
| 308 | case Builtin::BI__builtin_llabs: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 310 | |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 311 | Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | Value *CmpResult = |
| 313 | Builder.CreateICmpSGE(ArgValue, |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 314 | llvm::Constant::getNullValue(ArgValue->getType()), |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 315 | "abscond"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 316 | Value *Result = |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 317 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 318 | |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 319 | return RValue::get(Result); |
| 320 | } |
Reid Kleckner | 06ea7d6 | 2014-11-03 23:52:09 +0000 | [diff] [blame] | 321 | case Builtin::BI__builtin_fabs: |
| 322 | case Builtin::BI__builtin_fabsf: |
| 323 | case Builtin::BI__builtin_fabsl: { |
| 324 | Value *Arg1 = EmitScalarExpr(E->getArg(0)); |
| 325 | Value *Result = EmitFAbs(*this, Arg1); |
| 326 | return RValue::get(Result); |
| 327 | } |
Jan Vesely | b4379f9 | 2014-09-26 01:19:41 +0000 | [diff] [blame] | 328 | case Builtin::BI__builtin_fmod: |
| 329 | case Builtin::BI__builtin_fmodf: |
| 330 | case Builtin::BI__builtin_fmodl: { |
| 331 | Value *Arg1 = EmitScalarExpr(E->getArg(0)); |
| 332 | Value *Arg2 = EmitScalarExpr(E->getArg(1)); |
| 333 | Value *Result = Builder.CreateFRem(Arg1, Arg2, "fmod"); |
| 334 | return RValue::get(Result); |
| 335 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 336 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 337 | case Builtin::BI__builtin_conj: |
| 338 | case Builtin::BI__builtin_conjf: |
| 339 | case Builtin::BI__builtin_conjl: { |
| 340 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 341 | Value *Real = ComplexVal.first; |
| 342 | Value *Imag = ComplexVal.second; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 343 | Value *Zero = |
| 344 | Imag->getType()->isFPOrFPVectorTy() |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 345 | ? llvm::ConstantFP::getZeroValueForNegation(Imag->getType()) |
| 346 | : llvm::Constant::getNullValue(Imag->getType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 347 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 348 | Imag = Builder.CreateFSub(Zero, Imag, "sub"); |
| 349 | return RValue::getComplex(std::make_pair(Real, Imag)); |
| 350 | } |
| 351 | case Builtin::BI__builtin_creal: |
| 352 | case Builtin::BI__builtin_crealf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 353 | case Builtin::BI__builtin_creall: |
| 354 | case Builtin::BIcreal: |
| 355 | case Builtin::BIcrealf: |
| 356 | case Builtin::BIcreall: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 357 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 358 | return RValue::get(ComplexVal.first); |
| 359 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 360 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 361 | case Builtin::BI__builtin_cimag: |
| 362 | case Builtin::BI__builtin_cimagf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 363 | case Builtin::BI__builtin_cimagl: |
| 364 | case Builtin::BIcimag: |
| 365 | case Builtin::BIcimagf: |
| 366 | case Builtin::BIcimagl: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 367 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 368 | return RValue::get(ComplexVal.second); |
| 369 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 370 | |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 371 | case Builtin::BI__builtin_ctzs: |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 372 | case Builtin::BI__builtin_ctz: |
| 373 | case Builtin::BI__builtin_ctzl: |
| 374 | case Builtin::BI__builtin_ctzll: { |
| 375 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 377 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 378 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 379 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 380 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 381 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 382 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 383 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 384 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 385 | "cast"); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 386 | return RValue::get(Result); |
| 387 | } |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 388 | case Builtin::BI__builtin_clzs: |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 389 | case Builtin::BI__builtin_clz: |
| 390 | case Builtin::BI__builtin_clzl: |
| 391 | case Builtin::BI__builtin_clzll: { |
| 392 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 394 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 395 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 396 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 397 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 398 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 399 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 400 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 401 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 402 | "cast"); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 403 | return RValue::get(Result); |
| 404 | } |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 405 | case Builtin::BI__builtin_ffs: |
| 406 | case Builtin::BI__builtin_ffsl: |
| 407 | case Builtin::BI__builtin_ffsll: { |
| 408 | // ffs(x) -> x ? cttz(x) + 1 : 0 |
| 409 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 410 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 411 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 412 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 414 | llvm::Type *ResultType = ConvertType(E->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 415 | Value *Tmp = |
| 416 | Builder.CreateAdd(Builder.CreateCall(F, {ArgValue, Builder.getTrue()}), |
| 417 | llvm::ConstantInt::get(ArgType, 1)); |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 418 | Value *Zero = llvm::Constant::getNullValue(ArgType); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 419 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); |
| 420 | Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); |
| 421 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 422 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 423 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 424 | return RValue::get(Result); |
| 425 | } |
| 426 | case Builtin::BI__builtin_parity: |
| 427 | case Builtin::BI__builtin_parityl: |
| 428 | case Builtin::BI__builtin_parityll: { |
| 429 | // parity(x) -> ctpop(x) & 1 |
| 430 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 432 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 433 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 435 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 436 | Value *Tmp = Builder.CreateCall(F, ArgValue); |
| 437 | Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1)); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 438 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 439 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 440 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 441 | return RValue::get(Result); |
| 442 | } |
| 443 | case Builtin::BI__builtin_popcount: |
| 444 | case Builtin::BI__builtin_popcountl: |
| 445 | case Builtin::BI__builtin_popcountll: { |
| 446 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 448 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 449 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 451 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 452 | Value *Result = Builder.CreateCall(F, ArgValue); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 453 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 454 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 455 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 456 | return RValue::get(Result); |
| 457 | } |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 458 | case Builtin::BI__builtin_expect: { |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 459 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 460 | llvm::Type *ArgType = ArgValue->getType(); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 461 | |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 462 | Value *ExpectedValue = EmitScalarExpr(E->getArg(1)); |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 463 | // Don't generate llvm.expect on -O0 as the backend won't use it for |
| 464 | // anything. |
| 465 | // Note, we still IRGen ExpectedValue because it could have side-effects. |
| 466 | if (CGM.getCodeGenOpts().OptimizationLevel == 0) |
| 467 | return RValue::get(ArgValue); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 468 | |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 469 | Value *FnExpect = CGM.getIntrinsic(Intrinsic::expect, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 470 | Value *Result = |
| 471 | Builder.CreateCall(FnExpect, {ArgValue, ExpectedValue}, "expval"); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 472 | return RValue::get(Result); |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 473 | } |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 474 | case Builtin::BI__builtin_assume_aligned: { |
| 475 | Value *PtrValue = EmitScalarExpr(E->getArg(0)); |
| 476 | Value *OffsetValue = |
| 477 | (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr; |
| 478 | |
| 479 | Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); |
| 480 | ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue); |
| 481 | unsigned Alignment = (unsigned) AlignmentCI->getZExtValue(); |
| 482 | |
| 483 | EmitAlignmentAssumption(PtrValue, Alignment, OffsetValue); |
| 484 | return RValue::get(PtrValue); |
| 485 | } |
| 486 | case Builtin::BI__assume: |
| 487 | case Builtin::BI__builtin_assume: { |
| 488 | if (E->getArg(0)->HasSideEffects(getContext())) |
| 489 | return RValue::get(nullptr); |
| 490 | |
| 491 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 492 | Value *FnAssume = CGM.getIntrinsic(Intrinsic::assume); |
| 493 | return RValue::get(Builder.CreateCall(FnAssume, ArgValue)); |
| 494 | } |
Benjamin Kramer | a801f4a | 2012-10-06 14:42:22 +0000 | [diff] [blame] | 495 | case Builtin::BI__builtin_bswap16: |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 496 | case Builtin::BI__builtin_bswap32: |
| 497 | case Builtin::BI__builtin_bswap64: { |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 498 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 499 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 500 | Value *F = CGM.getIntrinsic(Intrinsic::bswap, ArgType); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 501 | return RValue::get(Builder.CreateCall(F, ArgValue)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | } |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 503 | case Builtin::BI__builtin_object_size: { |
Richard Smith | 01ade17 | 2012-05-23 04:13:20 +0000 | [diff] [blame] | 504 | // We rely on constant folding to deal with expressions with side effects. |
| 505 | assert(!E->getArg(0)->HasSideEffects(getContext()) && |
| 506 | "should have been constant folded"); |
| 507 | |
Mike Stump | 7a484dd | 2009-10-26 23:39:48 +0000 | [diff] [blame] | 508 | // We pass this builtin onto the optimizer so that it can |
| 509 | // figure out the object size in more complex cases. |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 510 | llvm::Type *ResType = ConvertType(E->getType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 511 | |
Eric Christopher | c879156 | 2009-12-23 03:49:37 +0000 | [diff] [blame] | 512 | // LLVM only supports 0 and 2, make sure that we pass along that |
| 513 | // as a boolean. |
| 514 | Value *Ty = EmitScalarExpr(E->getArg(1)); |
| 515 | ConstantInt *CI = dyn_cast<ConstantInt>(Ty); |
| 516 | assert(CI); |
| 517 | uint64_t val = CI->getZExtValue(); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 518 | CI = ConstantInt::get(Builder.getInt1Ty(), (val & 0x2) >> 1); |
Matt Arsenault | 2f15263 | 2013-10-07 19:00:18 +0000 | [diff] [blame] | 519 | // FIXME: Get right address space. |
| 520 | llvm::Type *Tys[] = { ResType, Builder.getInt8PtrTy(0) }; |
| 521 | Value *F = CGM.getIntrinsic(Intrinsic::objectsize, Tys); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 522 | return RValue::get( |
| 523 | Builder.CreateCall(F, {EmitScalarExpr(E->getArg(0)), CI})); |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 524 | } |
Daniel Dunbar | b725726 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 525 | case Builtin::BI__builtin_prefetch: { |
| 526 | Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); |
| 527 | // FIXME: Technically these constants should of type 'int', yes? |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 529 | llvm::ConstantInt::get(Int32Ty, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 531 | llvm::ConstantInt::get(Int32Ty, 3); |
Bruno Cardoso Lopes | 3b0297a | 2011-06-14 05:00:30 +0000 | [diff] [blame] | 532 | Value *Data = llvm::ConstantInt::get(Int32Ty, 1); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 533 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 534 | return RValue::get(Builder.CreateCall(F, {Address, RW, Locality, Data})); |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 535 | } |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 536 | case Builtin::BI__builtin_readcyclecounter: { |
| 537 | Value *F = CGM.getIntrinsic(Intrinsic::readcyclecounter); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 538 | return RValue::get(Builder.CreateCall(F, {})); |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 539 | } |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 540 | case Builtin::BI__builtin___clear_cache: { |
| 541 | Value *Begin = EmitScalarExpr(E->getArg(0)); |
| 542 | Value *End = EmitScalarExpr(E->getArg(1)); |
| 543 | Value *F = CGM.getIntrinsic(Intrinsic::clear_cache); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 544 | return RValue::get(Builder.CreateCall(F, {Begin, End})); |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 545 | } |
Daniel Dunbar | b725726 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 546 | case Builtin::BI__builtin_trap: { |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 547 | Value *F = CGM.getIntrinsic(Intrinsic::trap); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 548 | return RValue::get(Builder.CreateCall(F, {})); |
Daniel Dunbar | b725726 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 549 | } |
Nico Weber | ca496f3 | 2012-09-26 05:40:16 +0000 | [diff] [blame] | 550 | case Builtin::BI__debugbreak: { |
| 551 | Value *F = CGM.getIntrinsic(Intrinsic::debugtrap); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 552 | return RValue::get(Builder.CreateCall(F, {})); |
Nico Weber | ca496f3 | 2012-09-26 05:40:16 +0000 | [diff] [blame] | 553 | } |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 554 | case Builtin::BI__builtin_unreachable: { |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 555 | if (SanOpts.has(SanitizerKind::Unreachable)) { |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 556 | SanitizerScope SanScope(this); |
Alexey Samsonov | e396bfc | 2014-11-11 22:03:54 +0000 | [diff] [blame] | 557 | EmitCheck(std::make_pair(static_cast<llvm::Value *>(Builder.getFalse()), |
| 558 | SanitizerKind::Unreachable), |
| 559 | "builtin_unreachable", EmitCheckSourceLocation(E->getExprLoc()), |
| 560 | None); |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 561 | } else |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 562 | Builder.CreateUnreachable(); |
| 563 | |
| 564 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 565 | EmitBlock(createBasicBlock("unreachable.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 566 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 567 | return RValue::get(nullptr); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 568 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 569 | |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 570 | case Builtin::BI__builtin_powi: |
| 571 | case Builtin::BI__builtin_powif: |
Reid Kleckner | 1fcccdd | 2015-02-05 00:24:57 +0000 | [diff] [blame] | 572 | case Builtin::BI__builtin_powil: { |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 573 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 574 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 575 | llvm::Type *ArgType = Base->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 576 | Value *F = CGM.getIntrinsic(Intrinsic::powi, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 577 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 580 | case Builtin::BI__builtin_isgreater: |
| 581 | case Builtin::BI__builtin_isgreaterequal: |
| 582 | case Builtin::BI__builtin_isless: |
| 583 | case Builtin::BI__builtin_islessequal: |
| 584 | case Builtin::BI__builtin_islessgreater: |
| 585 | case Builtin::BI__builtin_isunordered: { |
| 586 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 587 | // floating point values. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 588 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 589 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 590 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 591 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 592 | default: llvm_unreachable("Unknown ordered comparison"); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 593 | case Builtin::BI__builtin_isgreater: |
| 594 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 595 | break; |
| 596 | case Builtin::BI__builtin_isgreaterequal: |
| 597 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 598 | break; |
| 599 | case Builtin::BI__builtin_isless: |
| 600 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 601 | break; |
| 602 | case Builtin::BI__builtin_islessequal: |
| 603 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 604 | break; |
| 605 | case Builtin::BI__builtin_islessgreater: |
| 606 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 607 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | case Builtin::BI__builtin_isunordered: |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 609 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 610 | break; |
| 611 | } |
| 612 | // ZExt bool to int type. |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 613 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()))); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 614 | } |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 615 | case Builtin::BI__builtin_isnan: { |
| 616 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 617 | V = Builder.CreateFCmpUNO(V, V, "cmp"); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 618 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 619 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 620 | |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 621 | case Builtin::BI__builtin_isinf: { |
| 622 | // isinf(x) --> fabs(x) == infinity |
| 623 | Value *V = EmitScalarExpr(E->getArg(0)); |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 624 | V = EmitFAbs(*this, V); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 625 | |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 626 | V = Builder.CreateFCmpOEQ(V, ConstantFP::getInfinity(V->getType()),"isinf"); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 627 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 628 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 629 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 630 | case Builtin::BI__builtin_isinf_sign: { |
| 631 | // isinf_sign(x) -> fabs(x) == infinity ? (signbit(x) ? -1 : 1) : 0 |
| 632 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 633 | Value *AbsArg = EmitFAbs(*this, Arg); |
| 634 | Value *IsInf = Builder.CreateFCmpOEQ( |
| 635 | AbsArg, ConstantFP::getInfinity(Arg->getType()), "isinf"); |
| 636 | Value *IsNeg = EmitSignBit(*this, Arg); |
| 637 | |
| 638 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 639 | Value *Zero = Constant::getNullValue(IntTy); |
| 640 | Value *One = ConstantInt::get(IntTy, 1); |
| 641 | Value *NegativeOne = ConstantInt::get(IntTy, -1); |
| 642 | Value *SignResult = Builder.CreateSelect(IsNeg, NegativeOne, One); |
| 643 | Value *Result = Builder.CreateSelect(IsInf, SignResult, Zero); |
| 644 | return RValue::get(Result); |
| 645 | } |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 646 | |
| 647 | case Builtin::BI__builtin_isnormal: { |
| 648 | // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min |
| 649 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 650 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
| 651 | |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 652 | Value *Abs = EmitFAbs(*this, V); |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 653 | Value *IsLessThanInf = |
| 654 | Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 655 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 656 | getContext().getFloatTypeSemantics(E->getArg(0)->getType())); |
| 657 | Value *IsNormal = |
| 658 | Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest), |
| 659 | "isnormal"); |
| 660 | V = Builder.CreateAnd(Eq, IsLessThanInf, "and"); |
| 661 | V = Builder.CreateAnd(V, IsNormal, "and"); |
| 662 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 663 | } |
| 664 | |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 665 | case Builtin::BI__builtin_isfinite: { |
Julien Lerouge | e0d5fad | 2011-09-09 22:46:39 +0000 | [diff] [blame] | 666 | // isfinite(x) --> x == x && fabs(x) != infinity; |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 667 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 668 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 669 | |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 670 | Value *Abs = EmitFAbs(*this, V); |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 671 | Value *IsNotInf = |
| 672 | Builder.CreateFCmpUNE(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 673 | |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 674 | V = Builder.CreateAnd(Eq, IsNotInf, "and"); |
| 675 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 676 | } |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 677 | |
| 678 | case Builtin::BI__builtin_fpclassify: { |
| 679 | Value *V = EmitScalarExpr(E->getArg(5)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 680 | llvm::Type *Ty = ConvertType(E->getArg(5)->getType()); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 681 | |
| 682 | // Create Result |
| 683 | BasicBlock *Begin = Builder.GetInsertBlock(); |
| 684 | BasicBlock *End = createBasicBlock("fpclassify_end", this->CurFn); |
| 685 | Builder.SetInsertPoint(End); |
| 686 | PHINode *Result = |
Jay Foad | 20c0f02 | 2011-03-30 11:28:58 +0000 | [diff] [blame] | 687 | Builder.CreatePHI(ConvertType(E->getArg(0)->getType()), 4, |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 688 | "fpclassify_result"); |
| 689 | |
| 690 | // if (V==0) return FP_ZERO |
| 691 | Builder.SetInsertPoint(Begin); |
| 692 | Value *IsZero = Builder.CreateFCmpOEQ(V, Constant::getNullValue(Ty), |
| 693 | "iszero"); |
| 694 | Value *ZeroLiteral = EmitScalarExpr(E->getArg(4)); |
| 695 | BasicBlock *NotZero = createBasicBlock("fpclassify_not_zero", this->CurFn); |
| 696 | Builder.CreateCondBr(IsZero, End, NotZero); |
| 697 | Result->addIncoming(ZeroLiteral, Begin); |
| 698 | |
| 699 | // if (V != V) return FP_NAN |
| 700 | Builder.SetInsertPoint(NotZero); |
| 701 | Value *IsNan = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 702 | Value *NanLiteral = EmitScalarExpr(E->getArg(0)); |
| 703 | BasicBlock *NotNan = createBasicBlock("fpclassify_not_nan", this->CurFn); |
| 704 | Builder.CreateCondBr(IsNan, End, NotNan); |
| 705 | Result->addIncoming(NanLiteral, NotZero); |
| 706 | |
| 707 | // if (fabs(V) == infinity) return FP_INFINITY |
| 708 | Builder.SetInsertPoint(NotNan); |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 709 | Value *VAbs = EmitFAbs(*this, V); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 710 | Value *IsInf = |
| 711 | Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(V->getType()), |
| 712 | "isinf"); |
| 713 | Value *InfLiteral = EmitScalarExpr(E->getArg(1)); |
| 714 | BasicBlock *NotInf = createBasicBlock("fpclassify_not_inf", this->CurFn); |
| 715 | Builder.CreateCondBr(IsInf, End, NotInf); |
| 716 | Result->addIncoming(InfLiteral, NotNan); |
| 717 | |
| 718 | // if (fabs(V) >= MIN_NORMAL) return FP_NORMAL else FP_SUBNORMAL |
| 719 | Builder.SetInsertPoint(NotInf); |
| 720 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 721 | getContext().getFloatTypeSemantics(E->getArg(5)->getType())); |
| 722 | Value *IsNormal = |
| 723 | Builder.CreateFCmpUGE(VAbs, ConstantFP::get(V->getContext(), Smallest), |
| 724 | "isnormal"); |
| 725 | Value *NormalResult = |
| 726 | Builder.CreateSelect(IsNormal, EmitScalarExpr(E->getArg(2)), |
| 727 | EmitScalarExpr(E->getArg(3))); |
| 728 | Builder.CreateBr(End); |
| 729 | Result->addIncoming(NormalResult, NotInf); |
| 730 | |
| 731 | // return Result |
| 732 | Builder.SetInsertPoint(End); |
| 733 | return RValue::get(Result); |
| 734 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 735 | |
Eli Friedman | f6bd150 | 2009-06-02 07:10:30 +0000 | [diff] [blame] | 736 | case Builtin::BIalloca: |
Reid Kleckner | 59e4a6f | 2013-11-13 22:58:53 +0000 | [diff] [blame] | 737 | case Builtin::BI_alloca: |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 738 | case Builtin::BI__builtin_alloca: { |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 739 | Value *Size = EmitScalarExpr(E->getArg(0)); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 740 | return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size)); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 741 | } |
Eli Friedman | d6ef69a | 2010-01-23 19:00:10 +0000 | [diff] [blame] | 742 | case Builtin::BIbzero: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 743 | case Builtin::BI__builtin_bzero: { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 744 | std::pair<llvm::Value*, unsigned> Dest = |
| 745 | EmitPointerWithAlignment(E->getArg(0)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 746 | Value *SizeVal = EmitScalarExpr(E->getArg(1)); |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 747 | EmitNonNullArgCheck(RValue::get(Dest.first), E->getArg(0)->getType(), |
| 748 | E->getArg(0)->getExprLoc(), FD, 0); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 749 | Builder.CreateMemSet(Dest.first, Builder.getInt8(0), SizeVal, |
| 750 | Dest.second, false); |
| 751 | return RValue::get(Dest.first); |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 752 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 753 | case Builtin::BImemcpy: |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 754 | case Builtin::BI__builtin_memcpy: { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 755 | std::pair<llvm::Value*, unsigned> Dest = |
| 756 | EmitPointerWithAlignment(E->getArg(0)); |
| 757 | std::pair<llvm::Value*, unsigned> Src = |
| 758 | EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 759 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 760 | unsigned Align = std::min(Dest.second, Src.second); |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 761 | EmitNonNullArgCheck(RValue::get(Dest.first), E->getArg(0)->getType(), |
| 762 | E->getArg(0)->getExprLoc(), FD, 0); |
| 763 | EmitNonNullArgCheck(RValue::get(Src.first), E->getArg(1)->getType(), |
| 764 | E->getArg(1)->getExprLoc(), FD, 1); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 765 | Builder.CreateMemCpy(Dest.first, Src.first, SizeVal, Align, false); |
| 766 | return RValue::get(Dest.first); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 767 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 768 | |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 769 | case Builtin::BI__builtin___memcpy_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 770 | // fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff cst1<=cst2. |
Richard Smith | caf3390 | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 771 | llvm::APSInt Size, DstSize; |
| 772 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 773 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 774 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 775 | if (Size.ugt(DstSize)) |
| 776 | break; |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 777 | std::pair<llvm::Value*, unsigned> Dest = |
| 778 | EmitPointerWithAlignment(E->getArg(0)); |
| 779 | std::pair<llvm::Value*, unsigned> Src = |
| 780 | EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 781 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 782 | unsigned Align = std::min(Dest.second, Src.second); |
| 783 | Builder.CreateMemCpy(Dest.first, Src.first, SizeVal, Align, false); |
| 784 | return RValue::get(Dest.first); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 785 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 786 | |
Fariborz Jahanian | 4a30307 | 2010-06-16 16:22:04 +0000 | [diff] [blame] | 787 | case Builtin::BI__builtin_objc_memmove_collectable: { |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 788 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 789 | Value *SrcAddr = EmitScalarExpr(E->getArg(1)); |
| 790 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 791 | CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 792 | Address, SrcAddr, SizeVal); |
| 793 | return RValue::get(Address); |
| 794 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 795 | |
| 796 | case Builtin::BI__builtin___memmove_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 797 | // fold __builtin_memmove_chk(x, y, cst1, cst2) to memmove iff cst1<=cst2. |
Richard Smith | caf3390 | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 798 | llvm::APSInt Size, DstSize; |
| 799 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 800 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 801 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 802 | if (Size.ugt(DstSize)) |
| 803 | break; |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 804 | std::pair<llvm::Value*, unsigned> Dest = |
| 805 | EmitPointerWithAlignment(E->getArg(0)); |
| 806 | std::pair<llvm::Value*, unsigned> Src = |
| 807 | EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 808 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 809 | unsigned Align = std::min(Dest.second, Src.second); |
| 810 | Builder.CreateMemMove(Dest.first, Src.first, SizeVal, Align, false); |
| 811 | return RValue::get(Dest.first); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 814 | case Builtin::BImemmove: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 815 | case Builtin::BI__builtin_memmove: { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 816 | std::pair<llvm::Value*, unsigned> Dest = |
| 817 | EmitPointerWithAlignment(E->getArg(0)); |
| 818 | std::pair<llvm::Value*, unsigned> Src = |
| 819 | EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 820 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 821 | unsigned Align = std::min(Dest.second, Src.second); |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 822 | EmitNonNullArgCheck(RValue::get(Dest.first), E->getArg(0)->getType(), |
| 823 | E->getArg(0)->getExprLoc(), FD, 0); |
| 824 | EmitNonNullArgCheck(RValue::get(Src.first), E->getArg(1)->getType(), |
| 825 | E->getArg(1)->getExprLoc(), FD, 1); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 826 | Builder.CreateMemMove(Dest.first, Src.first, SizeVal, Align, false); |
| 827 | return RValue::get(Dest.first); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 828 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 829 | case Builtin::BImemset: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 830 | case Builtin::BI__builtin_memset: { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 831 | std::pair<llvm::Value*, unsigned> Dest = |
| 832 | EmitPointerWithAlignment(E->getArg(0)); |
Benjamin Kramer | acc6b4e | 2010-12-30 00:13:21 +0000 | [diff] [blame] | 833 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 834 | Builder.getInt8Ty()); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 835 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 836 | EmitNonNullArgCheck(RValue::get(Dest.first), E->getArg(0)->getType(), |
| 837 | E->getArg(0)->getExprLoc(), FD, 0); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 838 | Builder.CreateMemSet(Dest.first, ByteVal, SizeVal, Dest.second, false); |
| 839 | return RValue::get(Dest.first); |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 840 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 841 | case Builtin::BI__builtin___memset_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 842 | // fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff cst1<=cst2. |
Richard Smith | caf3390 | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 843 | llvm::APSInt Size, DstSize; |
| 844 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 845 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 846 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 847 | if (Size.ugt(DstSize)) |
| 848 | break; |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 849 | std::pair<llvm::Value*, unsigned> Dest = |
| 850 | EmitPointerWithAlignment(E->getArg(0)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 851 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 852 | Builder.getInt8Ty()); |
| 853 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 854 | Builder.CreateMemSet(Dest.first, ByteVal, SizeVal, Dest.second, false); |
| 855 | return RValue::get(Dest.first); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 856 | } |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 857 | case Builtin::BI__builtin_dwarf_cfa: { |
| 858 | // The offset in bytes from the first argument to the CFA. |
| 859 | // |
| 860 | // Why on earth is this in the frontend? Is there any reason at |
| 861 | // all that the backend can't reasonably determine this while |
| 862 | // lowering llvm.eh.dwarf.cfa()? |
| 863 | // |
| 864 | // TODO: If there's a satisfactory reason, add a target hook for |
| 865 | // this instead of hard-coding 0, which is correct for most targets. |
| 866 | int32_t Offset = 0; |
| 867 | |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 868 | Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 869 | return RValue::get(Builder.CreateCall(F, |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 870 | llvm::ConstantInt::get(Int32Ty, Offset))); |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 871 | } |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 872 | case Builtin::BI__builtin_return_address: { |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 873 | Value *Depth = EmitScalarExpr(E->getArg(0)); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 874 | Depth = Builder.CreateIntCast(Depth, Int32Ty, false); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 875 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 876 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 877 | } |
| 878 | case Builtin::BI__builtin_frame_address: { |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 879 | Value *Depth = EmitScalarExpr(E->getArg(0)); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 880 | Depth = Builder.CreateIntCast(Depth, Int32Ty, false); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 881 | Value *F = CGM.getIntrinsic(Intrinsic::frameaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 882 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 883 | } |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 884 | case Builtin::BI__builtin_extract_return_addr: { |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 885 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 886 | Value *Result = getTargetHooks().decodeReturnAddress(*this, Address); |
| 887 | return RValue::get(Result); |
| 888 | } |
| 889 | case Builtin::BI__builtin_frob_return_addr: { |
| 890 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 891 | Value *Result = getTargetHooks().encodeReturnAddress(*this, Address); |
| 892 | return RValue::get(Result); |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 893 | } |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 894 | case Builtin::BI__builtin_dwarf_sp_column: { |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 895 | llvm::IntegerType *Ty |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 896 | = cast<llvm::IntegerType>(ConvertType(E->getType())); |
| 897 | int Column = getTargetHooks().getDwarfEHStackPointer(CGM); |
| 898 | if (Column == -1) { |
| 899 | CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column"); |
| 900 | return RValue::get(llvm::UndefValue::get(Ty)); |
| 901 | } |
| 902 | return RValue::get(llvm::ConstantInt::get(Ty, Column, true)); |
| 903 | } |
| 904 | case Builtin::BI__builtin_init_dwarf_reg_size_table: { |
| 905 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 906 | if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address)) |
| 907 | CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table"); |
| 908 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
| 909 | } |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 910 | case Builtin::BI__builtin_eh_return: { |
| 911 | Value *Int = EmitScalarExpr(E->getArg(0)); |
| 912 | Value *Ptr = EmitScalarExpr(E->getArg(1)); |
| 913 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 914 | llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType()); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 915 | assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && |
| 916 | "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); |
| 917 | Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 |
| 918 | ? Intrinsic::eh_return_i32 |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 919 | : Intrinsic::eh_return_i64); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 920 | Builder.CreateCall(F, {Int, Ptr}); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 921 | Builder.CreateUnreachable(); |
| 922 | |
| 923 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 924 | EmitBlock(createBasicBlock("builtin_eh_return.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 925 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 926 | return RValue::get(nullptr); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 927 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 928 | case Builtin::BI__builtin_unwind_init: { |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 929 | Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 930 | return RValue::get(Builder.CreateCall(F, {})); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 931 | } |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 932 | case Builtin::BI__builtin_extend_pointer: { |
| 933 | // Extends a pointer to the size of an _Unwind_Word, which is |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 934 | // uint64_t on all platforms. Generally this gets poked into a |
| 935 | // register and eventually used as an address, so if the |
| 936 | // addressing registers are wider than pointers and the platform |
| 937 | // doesn't implicitly ignore high-order bits when doing |
| 938 | // addressing, we need to make sure we zext / sext based on |
| 939 | // the platform's expectations. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 940 | // |
| 941 | // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 942 | |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 943 | // Cast the pointer to intptr_t. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 944 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 945 | Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast"); |
| 946 | |
| 947 | // If that's 64 bits, we're done. |
| 948 | if (IntPtrTy->getBitWidth() == 64) |
| 949 | return RValue::get(Result); |
| 950 | |
| 951 | // Otherwise, ask the codegen data what to do. |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 952 | if (getTargetHooks().extendPointerWithSExt()) |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 953 | return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext")); |
| 954 | else |
| 955 | return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 956 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 957 | case Builtin::BI__builtin_setjmp: { |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 958 | // Buffer is a void**. |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 959 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 960 | |
| 961 | // Store the frame pointer to the setjmp buffer. |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 962 | Value *FrameAddr = |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 963 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 964 | ConstantInt::get(Int32Ty, 0)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 965 | Builder.CreateStore(FrameAddr, Buf); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 966 | |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 967 | // Store the stack pointer to the setjmp buffer. |
| 968 | Value *StackAddr = |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 969 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::stacksave), {}); |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 970 | Value *StackSaveSlot = |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 971 | Builder.CreateGEP(Buf, ConstantInt::get(Int32Ty, 2)); |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 972 | Builder.CreateStore(StackAddr, StackSaveSlot); |
| 973 | |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 974 | // Call LLVM's EH setjmp, which is lightweight. |
| 975 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 976 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 977 | return RValue::get(Builder.CreateCall(F, Buf)); |
| 978 | } |
| 979 | case Builtin::BI__builtin_longjmp: { |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 980 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 981 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 982 | |
| 983 | // Call LLVM's EH longjmp, which is lightweight. |
| 984 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf); |
| 985 | |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 986 | // longjmp doesn't return; mark this as unreachable. |
| 987 | Builder.CreateUnreachable(); |
| 988 | |
| 989 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 990 | EmitBlock(createBasicBlock("longjmp.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 991 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 992 | return RValue::get(nullptr); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 993 | } |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 994 | case Builtin::BI__sync_fetch_and_add: |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 995 | case Builtin::BI__sync_fetch_and_sub: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 996 | case Builtin::BI__sync_fetch_and_or: |
| 997 | case Builtin::BI__sync_fetch_and_and: |
| 998 | case Builtin::BI__sync_fetch_and_xor: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 999 | case Builtin::BI__sync_fetch_and_nand: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1000 | case Builtin::BI__sync_add_and_fetch: |
| 1001 | case Builtin::BI__sync_sub_and_fetch: |
| 1002 | case Builtin::BI__sync_and_and_fetch: |
| 1003 | case Builtin::BI__sync_or_and_fetch: |
| 1004 | case Builtin::BI__sync_xor_and_fetch: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1005 | case Builtin::BI__sync_nand_and_fetch: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1006 | case Builtin::BI__sync_val_compare_and_swap: |
| 1007 | case Builtin::BI__sync_bool_compare_and_swap: |
| 1008 | case Builtin::BI__sync_lock_test_and_set: |
| 1009 | case Builtin::BI__sync_lock_release: |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1010 | case Builtin::BI__sync_swap: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1011 | llvm_unreachable("Shouldn't make it through sema"); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1012 | case Builtin::BI__sync_fetch_and_add_1: |
| 1013 | case Builtin::BI__sync_fetch_and_add_2: |
| 1014 | case Builtin::BI__sync_fetch_and_add_4: |
| 1015 | case Builtin::BI__sync_fetch_and_add_8: |
| 1016 | case Builtin::BI__sync_fetch_and_add_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1017 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Add, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1018 | case Builtin::BI__sync_fetch_and_sub_1: |
| 1019 | case Builtin::BI__sync_fetch_and_sub_2: |
| 1020 | case Builtin::BI__sync_fetch_and_sub_4: |
| 1021 | case Builtin::BI__sync_fetch_and_sub_8: |
| 1022 | case Builtin::BI__sync_fetch_and_sub_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1023 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Sub, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1024 | case Builtin::BI__sync_fetch_and_or_1: |
| 1025 | case Builtin::BI__sync_fetch_and_or_2: |
| 1026 | case Builtin::BI__sync_fetch_and_or_4: |
| 1027 | case Builtin::BI__sync_fetch_and_or_8: |
| 1028 | case Builtin::BI__sync_fetch_and_or_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1029 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Or, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1030 | case Builtin::BI__sync_fetch_and_and_1: |
| 1031 | case Builtin::BI__sync_fetch_and_and_2: |
| 1032 | case Builtin::BI__sync_fetch_and_and_4: |
| 1033 | case Builtin::BI__sync_fetch_and_and_8: |
| 1034 | case Builtin::BI__sync_fetch_and_and_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1035 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::And, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1036 | case Builtin::BI__sync_fetch_and_xor_1: |
| 1037 | case Builtin::BI__sync_fetch_and_xor_2: |
| 1038 | case Builtin::BI__sync_fetch_and_xor_4: |
| 1039 | case Builtin::BI__sync_fetch_and_xor_8: |
| 1040 | case Builtin::BI__sync_fetch_and_xor_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1041 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xor, E); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1042 | case Builtin::BI__sync_fetch_and_nand_1: |
| 1043 | case Builtin::BI__sync_fetch_and_nand_2: |
| 1044 | case Builtin::BI__sync_fetch_and_nand_4: |
| 1045 | case Builtin::BI__sync_fetch_and_nand_8: |
| 1046 | case Builtin::BI__sync_fetch_and_nand_16: |
| 1047 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Nand, E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1049 | // Clang extensions: not overloaded yet. |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1050 | case Builtin::BI__sync_fetch_and_min: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1051 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Min, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1052 | case Builtin::BI__sync_fetch_and_max: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1053 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Max, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1054 | case Builtin::BI__sync_fetch_and_umin: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1055 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMin, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1056 | case Builtin::BI__sync_fetch_and_umax: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1057 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMax, E); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1058 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1059 | case Builtin::BI__sync_add_and_fetch_1: |
| 1060 | case Builtin::BI__sync_add_and_fetch_2: |
| 1061 | case Builtin::BI__sync_add_and_fetch_4: |
| 1062 | case Builtin::BI__sync_add_and_fetch_8: |
| 1063 | case Builtin::BI__sync_add_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1064 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Add, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1065 | llvm::Instruction::Add); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1066 | case Builtin::BI__sync_sub_and_fetch_1: |
| 1067 | case Builtin::BI__sync_sub_and_fetch_2: |
| 1068 | case Builtin::BI__sync_sub_and_fetch_4: |
| 1069 | case Builtin::BI__sync_sub_and_fetch_8: |
| 1070 | case Builtin::BI__sync_sub_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1071 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Sub, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1072 | llvm::Instruction::Sub); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1073 | case Builtin::BI__sync_and_and_fetch_1: |
| 1074 | case Builtin::BI__sync_and_and_fetch_2: |
| 1075 | case Builtin::BI__sync_and_and_fetch_4: |
| 1076 | case Builtin::BI__sync_and_and_fetch_8: |
| 1077 | case Builtin::BI__sync_and_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1078 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::And, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1079 | llvm::Instruction::And); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1080 | case Builtin::BI__sync_or_and_fetch_1: |
| 1081 | case Builtin::BI__sync_or_and_fetch_2: |
| 1082 | case Builtin::BI__sync_or_and_fetch_4: |
| 1083 | case Builtin::BI__sync_or_and_fetch_8: |
| 1084 | case Builtin::BI__sync_or_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1085 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Or, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1086 | llvm::Instruction::Or); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1087 | case Builtin::BI__sync_xor_and_fetch_1: |
| 1088 | case Builtin::BI__sync_xor_and_fetch_2: |
| 1089 | case Builtin::BI__sync_xor_and_fetch_4: |
| 1090 | case Builtin::BI__sync_xor_and_fetch_8: |
| 1091 | case Builtin::BI__sync_xor_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1092 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Xor, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1093 | llvm::Instruction::Xor); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1094 | case Builtin::BI__sync_nand_and_fetch_1: |
| 1095 | case Builtin::BI__sync_nand_and_fetch_2: |
| 1096 | case Builtin::BI__sync_nand_and_fetch_4: |
| 1097 | case Builtin::BI__sync_nand_and_fetch_8: |
| 1098 | case Builtin::BI__sync_nand_and_fetch_16: |
| 1099 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Nand, E, |
| 1100 | llvm::Instruction::And, true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1102 | case Builtin::BI__sync_val_compare_and_swap_1: |
| 1103 | case Builtin::BI__sync_val_compare_and_swap_2: |
| 1104 | case Builtin::BI__sync_val_compare_and_swap_4: |
| 1105 | case Builtin::BI__sync_val_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1106 | case Builtin::BI__sync_val_compare_and_swap_16: |
| 1107 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, false)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1108 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1109 | case Builtin::BI__sync_bool_compare_and_swap_1: |
| 1110 | case Builtin::BI__sync_bool_compare_and_swap_2: |
| 1111 | case Builtin::BI__sync_bool_compare_and_swap_4: |
| 1112 | case Builtin::BI__sync_bool_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1113 | case Builtin::BI__sync_bool_compare_and_swap_16: |
| 1114 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, true)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1115 | |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1116 | case Builtin::BI__sync_swap_1: |
| 1117 | case Builtin::BI__sync_swap_2: |
| 1118 | case Builtin::BI__sync_swap_4: |
| 1119 | case Builtin::BI__sync_swap_8: |
| 1120 | case Builtin::BI__sync_swap_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1121 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1122 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1123 | case Builtin::BI__sync_lock_test_and_set_1: |
| 1124 | case Builtin::BI__sync_lock_test_and_set_2: |
| 1125 | case Builtin::BI__sync_lock_test_and_set_4: |
| 1126 | case Builtin::BI__sync_lock_test_and_set_8: |
| 1127 | case Builtin::BI__sync_lock_test_and_set_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1128 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Daniel Dunbar | 4ff562d | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 1129 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1130 | case Builtin::BI__sync_lock_release_1: |
| 1131 | case Builtin::BI__sync_lock_release_2: |
| 1132 | case Builtin::BI__sync_lock_release_4: |
| 1133 | case Builtin::BI__sync_lock_release_8: |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1134 | case Builtin::BI__sync_lock_release_16: { |
| 1135 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Eli Friedman | 84d2812 | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 1136 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 1137 | CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); |
Eli Friedman | fefe0d0 | 2012-03-16 01:48:04 +0000 | [diff] [blame] | 1138 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 1139 | StoreSize.getQuantity() * 8); |
| 1140 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1141 | llvm::StoreInst *Store = |
Eli Friedman | fefe0d0 | 2012-03-16 01:48:04 +0000 | [diff] [blame] | 1142 | Builder.CreateStore(llvm::Constant::getNullValue(ITy), Ptr); |
Eli Friedman | 84d2812 | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 1143 | Store->setAlignment(StoreSize.getQuantity()); |
| 1144 | Store->setAtomic(llvm::Release); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1145 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1146 | } |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1147 | |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1148 | case Builtin::BI__sync_synchronize: { |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1149 | // We assume this is supposed to correspond to a C++0x-style |
| 1150 | // sequentially-consistent fence (i.e. this is only usable for |
| 1151 | // synchonization, not device I/O or anything like that). This intrinsic |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1152 | // is really badly designed in the sense that in theory, there isn't |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1153 | // any way to safely use it... but in practice, it mostly works |
| 1154 | // to use it with non-atomic loads and stores to get acquire/release |
| 1155 | // semantics. |
| 1156 | Builder.CreateFence(llvm::SequentiallyConsistent); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1157 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1158 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1160 | case Builtin::BI__c11_atomic_is_lock_free: |
| 1161 | case Builtin::BI__atomic_is_lock_free: { |
| 1162 | // Call "bool __atomic_is_lock_free(size_t size, void *ptr)". For the |
| 1163 | // __c11 builtin, ptr is 0 (indicating a properly-aligned object), since |
| 1164 | // _Atomic(T) is always properly-aligned. |
| 1165 | const char *LibCallName = "__atomic_is_lock_free"; |
| 1166 | CallArgList Args; |
| 1167 | Args.add(RValue::get(EmitScalarExpr(E->getArg(0))), |
| 1168 | getContext().getSizeType()); |
| 1169 | if (BuiltinID == Builtin::BI__atomic_is_lock_free) |
| 1170 | Args.add(RValue::get(EmitScalarExpr(E->getArg(1))), |
| 1171 | getContext().VoidPtrTy); |
| 1172 | else |
| 1173 | Args.add(RValue::get(llvm::Constant::getNullValue(VoidPtrTy)), |
| 1174 | getContext().VoidPtrTy); |
| 1175 | const CGFunctionInfo &FuncInfo = |
John McCall | 8dda7b2 | 2012-07-07 06:41:13 +0000 | [diff] [blame] | 1176 | CGM.getTypes().arrangeFreeFunctionCall(E->getType(), Args, |
| 1177 | FunctionType::ExtInfo(), |
| 1178 | RequiredArgs::All); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1179 | llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FuncInfo); |
| 1180 | llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, LibCallName); |
| 1181 | return EmitCall(FuncInfo, Func, ReturnValueSlot(), Args); |
| 1182 | } |
| 1183 | |
| 1184 | case Builtin::BI__atomic_test_and_set: { |
| 1185 | // Look at the argument type to determine whether this is a volatile |
| 1186 | // operation. The parameter type is always volatile. |
| 1187 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 1188 | bool Volatile = |
| 1189 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 1190 | |
| 1191 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 1192 | unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1193 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 1194 | Value *NewVal = Builder.getInt8(1); |
| 1195 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 1196 | if (isa<llvm::ConstantInt>(Order)) { |
| 1197 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1198 | AtomicRMWInst *Result = nullptr; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1199 | switch (ord) { |
| 1200 | case 0: // memory_order_relaxed |
| 1201 | default: // invalid order |
| 1202 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1203 | Ptr, NewVal, |
| 1204 | llvm::Monotonic); |
| 1205 | break; |
| 1206 | case 1: // memory_order_consume |
| 1207 | case 2: // memory_order_acquire |
| 1208 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1209 | Ptr, NewVal, |
| 1210 | llvm::Acquire); |
| 1211 | break; |
| 1212 | case 3: // memory_order_release |
| 1213 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1214 | Ptr, NewVal, |
| 1215 | llvm::Release); |
| 1216 | break; |
| 1217 | case 4: // memory_order_acq_rel |
| 1218 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1219 | Ptr, NewVal, |
| 1220 | llvm::AcquireRelease); |
| 1221 | break; |
| 1222 | case 5: // memory_order_seq_cst |
| 1223 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1224 | Ptr, NewVal, |
| 1225 | llvm::SequentiallyConsistent); |
| 1226 | break; |
| 1227 | } |
| 1228 | Result->setVolatile(Volatile); |
| 1229 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 1230 | } |
| 1231 | |
| 1232 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1233 | |
| 1234 | llvm::BasicBlock *BBs[5] = { |
| 1235 | createBasicBlock("monotonic", CurFn), |
| 1236 | createBasicBlock("acquire", CurFn), |
| 1237 | createBasicBlock("release", CurFn), |
| 1238 | createBasicBlock("acqrel", CurFn), |
| 1239 | createBasicBlock("seqcst", CurFn) |
| 1240 | }; |
| 1241 | llvm::AtomicOrdering Orders[5] = { |
| 1242 | llvm::Monotonic, llvm::Acquire, llvm::Release, |
| 1243 | llvm::AcquireRelease, llvm::SequentiallyConsistent |
| 1244 | }; |
| 1245 | |
| 1246 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1247 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 1248 | |
| 1249 | Builder.SetInsertPoint(ContBB); |
| 1250 | PHINode *Result = Builder.CreatePHI(Int8Ty, 5, "was_set"); |
| 1251 | |
| 1252 | for (unsigned i = 0; i < 5; ++i) { |
| 1253 | Builder.SetInsertPoint(BBs[i]); |
| 1254 | AtomicRMWInst *RMW = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1255 | Ptr, NewVal, Orders[i]); |
| 1256 | RMW->setVolatile(Volatile); |
| 1257 | Result->addIncoming(RMW, BBs[i]); |
| 1258 | Builder.CreateBr(ContBB); |
| 1259 | } |
| 1260 | |
| 1261 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 1262 | SI->addCase(Builder.getInt32(1), BBs[1]); |
| 1263 | SI->addCase(Builder.getInt32(2), BBs[1]); |
| 1264 | SI->addCase(Builder.getInt32(3), BBs[2]); |
| 1265 | SI->addCase(Builder.getInt32(4), BBs[3]); |
| 1266 | SI->addCase(Builder.getInt32(5), BBs[4]); |
| 1267 | |
| 1268 | Builder.SetInsertPoint(ContBB); |
| 1269 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 1270 | } |
| 1271 | |
| 1272 | case Builtin::BI__atomic_clear: { |
| 1273 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 1274 | bool Volatile = |
| 1275 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 1276 | |
| 1277 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 1278 | unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1279 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 1280 | Value *NewVal = Builder.getInt8(0); |
| 1281 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 1282 | if (isa<llvm::ConstantInt>(Order)) { |
| 1283 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 1284 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
| 1285 | Store->setAlignment(1); |
| 1286 | switch (ord) { |
| 1287 | case 0: // memory_order_relaxed |
| 1288 | default: // invalid order |
| 1289 | Store->setOrdering(llvm::Monotonic); |
| 1290 | break; |
| 1291 | case 3: // memory_order_release |
| 1292 | Store->setOrdering(llvm::Release); |
| 1293 | break; |
| 1294 | case 5: // memory_order_seq_cst |
| 1295 | Store->setOrdering(llvm::SequentiallyConsistent); |
| 1296 | break; |
| 1297 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1298 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1302 | |
| 1303 | llvm::BasicBlock *BBs[3] = { |
| 1304 | createBasicBlock("monotonic", CurFn), |
| 1305 | createBasicBlock("release", CurFn), |
| 1306 | createBasicBlock("seqcst", CurFn) |
| 1307 | }; |
| 1308 | llvm::AtomicOrdering Orders[3] = { |
| 1309 | llvm::Monotonic, llvm::Release, llvm::SequentiallyConsistent |
| 1310 | }; |
| 1311 | |
| 1312 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1313 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 1314 | |
| 1315 | for (unsigned i = 0; i < 3; ++i) { |
| 1316 | Builder.SetInsertPoint(BBs[i]); |
| 1317 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
| 1318 | Store->setAlignment(1); |
| 1319 | Store->setOrdering(Orders[i]); |
| 1320 | Builder.CreateBr(ContBB); |
| 1321 | } |
| 1322 | |
| 1323 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 1324 | SI->addCase(Builder.getInt32(3), BBs[1]); |
| 1325 | SI->addCase(Builder.getInt32(5), BBs[2]); |
| 1326 | |
| 1327 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1328 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1331 | case Builtin::BI__atomic_thread_fence: |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 1332 | case Builtin::BI__atomic_signal_fence: |
| 1333 | case Builtin::BI__c11_atomic_thread_fence: |
| 1334 | case Builtin::BI__c11_atomic_signal_fence: { |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1335 | llvm::SynchronizationScope Scope; |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 1336 | if (BuiltinID == Builtin::BI__atomic_signal_fence || |
| 1337 | BuiltinID == Builtin::BI__c11_atomic_signal_fence) |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1338 | Scope = llvm::SingleThread; |
| 1339 | else |
| 1340 | Scope = llvm::CrossThread; |
| 1341 | Value *Order = EmitScalarExpr(E->getArg(0)); |
| 1342 | if (isa<llvm::ConstantInt>(Order)) { |
| 1343 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 1344 | switch (ord) { |
| 1345 | case 0: // memory_order_relaxed |
| 1346 | default: // invalid order |
| 1347 | break; |
| 1348 | case 1: // memory_order_consume |
| 1349 | case 2: // memory_order_acquire |
| 1350 | Builder.CreateFence(llvm::Acquire, Scope); |
| 1351 | break; |
| 1352 | case 3: // memory_order_release |
| 1353 | Builder.CreateFence(llvm::Release, Scope); |
| 1354 | break; |
| 1355 | case 4: // memory_order_acq_rel |
| 1356 | Builder.CreateFence(llvm::AcquireRelease, Scope); |
| 1357 | break; |
| 1358 | case 5: // memory_order_seq_cst |
| 1359 | Builder.CreateFence(llvm::SequentiallyConsistent, Scope); |
| 1360 | break; |
| 1361 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1362 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB; |
| 1366 | AcquireBB = createBasicBlock("acquire", CurFn); |
| 1367 | ReleaseBB = createBasicBlock("release", CurFn); |
| 1368 | AcqRelBB = createBasicBlock("acqrel", CurFn); |
| 1369 | SeqCstBB = createBasicBlock("seqcst", CurFn); |
| 1370 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1371 | |
| 1372 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1373 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, ContBB); |
| 1374 | |
| 1375 | Builder.SetInsertPoint(AcquireBB); |
| 1376 | Builder.CreateFence(llvm::Acquire, Scope); |
| 1377 | Builder.CreateBr(ContBB); |
| 1378 | SI->addCase(Builder.getInt32(1), AcquireBB); |
| 1379 | SI->addCase(Builder.getInt32(2), AcquireBB); |
| 1380 | |
| 1381 | Builder.SetInsertPoint(ReleaseBB); |
| 1382 | Builder.CreateFence(llvm::Release, Scope); |
| 1383 | Builder.CreateBr(ContBB); |
| 1384 | SI->addCase(Builder.getInt32(3), ReleaseBB); |
| 1385 | |
| 1386 | Builder.SetInsertPoint(AcqRelBB); |
| 1387 | Builder.CreateFence(llvm::AcquireRelease, Scope); |
| 1388 | Builder.CreateBr(ContBB); |
| 1389 | SI->addCase(Builder.getInt32(4), AcqRelBB); |
| 1390 | |
| 1391 | Builder.SetInsertPoint(SeqCstBB); |
| 1392 | Builder.CreateFence(llvm::SequentiallyConsistent, Scope); |
| 1393 | Builder.CreateBr(ContBB); |
| 1394 | SI->addCase(Builder.getInt32(5), SeqCstBB); |
| 1395 | |
| 1396 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1397 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1400 | // Library functions with special handling. |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1401 | case Builtin::BIsqrt: |
| 1402 | case Builtin::BIsqrtf: |
| 1403 | case Builtin::BIsqrtl: { |
Hal Finkel | 28b2ae3 | 2013-09-12 23:57:55 +0000 | [diff] [blame] | 1404 | // Transform a call to sqrt* into a @llvm.sqrt.* intrinsic call, but only |
| 1405 | // in finite- or unsafe-math mode (the intrinsic has different semantics |
| 1406 | // for handling negative numbers compared to the library function, so |
| 1407 | // -fmath-errno=0 is not enough). |
| 1408 | if (!FD->hasAttr<ConstAttr>()) |
| 1409 | break; |
| 1410 | if (!(CGM.getCodeGenOpts().UnsafeFPMath || |
| 1411 | CGM.getCodeGenOpts().NoNaNsFPMath)) |
| 1412 | break; |
| 1413 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 1414 | llvm::Type *ArgType = Arg0->getType(); |
| 1415 | Value *F = CGM.getIntrinsic(Intrinsic::sqrt, ArgType); |
| 1416 | return RValue::get(Builder.CreateCall(F, Arg0)); |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Reid Kleckner | 8a8c129 | 2015-02-05 00:18:01 +0000 | [diff] [blame] | 1419 | case Builtin::BI__builtin_pow: |
| 1420 | case Builtin::BI__builtin_powf: |
| 1421 | case Builtin::BI__builtin_powl: |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1422 | case Builtin::BIpow: |
| 1423 | case Builtin::BIpowf: |
| 1424 | case Builtin::BIpowl: { |
Eli Bendersky | c3496b0 | 2013-07-24 21:22:01 +0000 | [diff] [blame] | 1425 | // Transform a call to pow* into a @llvm.pow.* intrinsic call. |
| 1426 | if (!FD->hasAttr<ConstAttr>()) |
| 1427 | break; |
| 1428 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 1429 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
| 1430 | llvm::Type *ArgType = Base->getType(); |
| 1431 | Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1432 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1433 | } |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1434 | |
Cameron Zwarich | ae7bc98 | 2011-07-08 21:39:34 +0000 | [diff] [blame] | 1435 | case Builtin::BIfma: |
| 1436 | case Builtin::BIfmaf: |
| 1437 | case Builtin::BIfmal: |
| 1438 | case Builtin::BI__builtin_fma: |
| 1439 | case Builtin::BI__builtin_fmaf: |
| 1440 | case Builtin::BI__builtin_fmal: { |
| 1441 | // Rewrite fma to intrinsic. |
| 1442 | Value *FirstArg = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1443 | llvm::Type *ArgType = FirstArg->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1444 | Value *F = CGM.getIntrinsic(Intrinsic::fma, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1445 | return RValue::get( |
| 1446 | Builder.CreateCall(F, {FirstArg, EmitScalarExpr(E->getArg(1)), |
| 1447 | EmitScalarExpr(E->getArg(2))})); |
Cameron Zwarich | ae7bc98 | 2011-07-08 21:39:34 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1450 | case Builtin::BI__builtin_signbit: |
| 1451 | case Builtin::BI__builtin_signbitf: |
| 1452 | case Builtin::BI__builtin_signbitl: { |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 1453 | return RValue::get( |
| 1454 | Builder.CreateZExt(EmitSignBit(*this, EmitScalarExpr(E->getArg(0))), |
| 1455 | ConvertType(E->getType()))); |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1456 | } |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1457 | case Builtin::BI__builtin_annotation: { |
| 1458 | llvm::Value *AnnVal = EmitScalarExpr(E->getArg(0)); |
| 1459 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::annotation, |
| 1460 | AnnVal->getType()); |
| 1461 | |
| 1462 | // Get the annotation string, go through casts. Sema requires this to be a |
| 1463 | // non-wide string literal, potentially casted, so the cast<> is safe. |
| 1464 | const Expr *AnnotationStrExpr = E->getArg(1)->IgnoreParenCasts(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1465 | StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString(); |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1466 | return RValue::get(EmitAnnotationCall(F, AnnVal, Str, E->getExprLoc())); |
| 1467 | } |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1468 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1469 | case Builtin::BI__builtin_addcs: |
| 1470 | case Builtin::BI__builtin_addc: |
| 1471 | case Builtin::BI__builtin_addcl: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1472 | case Builtin::BI__builtin_addcll: |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1473 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1474 | case Builtin::BI__builtin_subcs: |
| 1475 | case Builtin::BI__builtin_subc: |
| 1476 | case Builtin::BI__builtin_subcl: |
| 1477 | case Builtin::BI__builtin_subcll: { |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1478 | |
| 1479 | // We translate all of these builtins from expressions of the form: |
| 1480 | // int x = ..., y = ..., carryin = ..., carryout, result; |
| 1481 | // result = __builtin_addc(x, y, carryin, &carryout); |
| 1482 | // |
| 1483 | // to LLVM IR of the form: |
| 1484 | // |
| 1485 | // %tmp1 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y) |
| 1486 | // %tmpsum1 = extractvalue {i32, i1} %tmp1, 0 |
| 1487 | // %carry1 = extractvalue {i32, i1} %tmp1, 1 |
| 1488 | // %tmp2 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %tmpsum1, |
| 1489 | // i32 %carryin) |
| 1490 | // %result = extractvalue {i32, i1} %tmp2, 0 |
| 1491 | // %carry2 = extractvalue {i32, i1} %tmp2, 1 |
| 1492 | // %tmp3 = or i1 %carry1, %carry2 |
| 1493 | // %tmp4 = zext i1 %tmp3 to i32 |
| 1494 | // store i32 %tmp4, i32* %carryout |
| 1495 | |
| 1496 | // Scalarize our inputs. |
| 1497 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 1498 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 1499 | llvm::Value *Carryin = EmitScalarExpr(E->getArg(2)); |
| 1500 | std::pair<llvm::Value*, unsigned> CarryOutPtr = |
| 1501 | EmitPointerWithAlignment(E->getArg(3)); |
| 1502 | |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1503 | // Decide if we are lowering to a uadd.with.overflow or usub.with.overflow. |
| 1504 | llvm::Intrinsic::ID IntrinsicId; |
| 1505 | switch (BuiltinID) { |
| 1506 | default: llvm_unreachable("Unknown multiprecision builtin id."); |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1507 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1508 | case Builtin::BI__builtin_addcs: |
| 1509 | case Builtin::BI__builtin_addc: |
| 1510 | case Builtin::BI__builtin_addcl: |
| 1511 | case Builtin::BI__builtin_addcll: |
| 1512 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 1513 | break; |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1514 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1515 | case Builtin::BI__builtin_subcs: |
| 1516 | case Builtin::BI__builtin_subc: |
| 1517 | case Builtin::BI__builtin_subcl: |
| 1518 | case Builtin::BI__builtin_subcll: |
| 1519 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 1520 | break; |
| 1521 | } |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1522 | |
| 1523 | // Construct our resulting LLVM IR expression. |
| 1524 | llvm::Value *Carry1; |
| 1525 | llvm::Value *Sum1 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 1526 | X, Y, Carry1); |
| 1527 | llvm::Value *Carry2; |
| 1528 | llvm::Value *Sum2 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 1529 | Sum1, Carryin, Carry2); |
| 1530 | llvm::Value *CarryOut = Builder.CreateZExt(Builder.CreateOr(Carry1, Carry2), |
| 1531 | X->getType()); |
| 1532 | llvm::StoreInst *CarryOutStore = Builder.CreateStore(CarryOut, |
| 1533 | CarryOutPtr.first); |
| 1534 | CarryOutStore->setAlignment(CarryOutPtr.second); |
| 1535 | return RValue::get(Sum2); |
| 1536 | } |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1537 | case Builtin::BI__builtin_uadd_overflow: |
| 1538 | case Builtin::BI__builtin_uaddl_overflow: |
| 1539 | case Builtin::BI__builtin_uaddll_overflow: |
| 1540 | case Builtin::BI__builtin_usub_overflow: |
| 1541 | case Builtin::BI__builtin_usubl_overflow: |
| 1542 | case Builtin::BI__builtin_usubll_overflow: |
| 1543 | case Builtin::BI__builtin_umul_overflow: |
| 1544 | case Builtin::BI__builtin_umull_overflow: |
| 1545 | case Builtin::BI__builtin_umulll_overflow: |
| 1546 | case Builtin::BI__builtin_sadd_overflow: |
| 1547 | case Builtin::BI__builtin_saddl_overflow: |
| 1548 | case Builtin::BI__builtin_saddll_overflow: |
| 1549 | case Builtin::BI__builtin_ssub_overflow: |
| 1550 | case Builtin::BI__builtin_ssubl_overflow: |
| 1551 | case Builtin::BI__builtin_ssubll_overflow: |
| 1552 | case Builtin::BI__builtin_smul_overflow: |
| 1553 | case Builtin::BI__builtin_smull_overflow: |
| 1554 | case Builtin::BI__builtin_smulll_overflow: { |
| 1555 | |
| 1556 | // We translate all of these builtins directly to the relevant llvm IR node. |
| 1557 | |
| 1558 | // Scalarize our inputs. |
| 1559 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 1560 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 1561 | std::pair<llvm::Value *, unsigned> SumOutPtr = |
| 1562 | EmitPointerWithAlignment(E->getArg(2)); |
| 1563 | |
| 1564 | // Decide which of the overflow intrinsics we are lowering to: |
| 1565 | llvm::Intrinsic::ID IntrinsicId; |
| 1566 | switch (BuiltinID) { |
| 1567 | default: llvm_unreachable("Unknown security overflow builtin id."); |
| 1568 | case Builtin::BI__builtin_uadd_overflow: |
| 1569 | case Builtin::BI__builtin_uaddl_overflow: |
| 1570 | case Builtin::BI__builtin_uaddll_overflow: |
| 1571 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 1572 | break; |
| 1573 | case Builtin::BI__builtin_usub_overflow: |
| 1574 | case Builtin::BI__builtin_usubl_overflow: |
| 1575 | case Builtin::BI__builtin_usubll_overflow: |
| 1576 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 1577 | break; |
| 1578 | case Builtin::BI__builtin_umul_overflow: |
| 1579 | case Builtin::BI__builtin_umull_overflow: |
| 1580 | case Builtin::BI__builtin_umulll_overflow: |
| 1581 | IntrinsicId = llvm::Intrinsic::umul_with_overflow; |
| 1582 | break; |
| 1583 | case Builtin::BI__builtin_sadd_overflow: |
| 1584 | case Builtin::BI__builtin_saddl_overflow: |
| 1585 | case Builtin::BI__builtin_saddll_overflow: |
| 1586 | IntrinsicId = llvm::Intrinsic::sadd_with_overflow; |
| 1587 | break; |
| 1588 | case Builtin::BI__builtin_ssub_overflow: |
| 1589 | case Builtin::BI__builtin_ssubl_overflow: |
| 1590 | case Builtin::BI__builtin_ssubll_overflow: |
| 1591 | IntrinsicId = llvm::Intrinsic::ssub_with_overflow; |
| 1592 | break; |
| 1593 | case Builtin::BI__builtin_smul_overflow: |
| 1594 | case Builtin::BI__builtin_smull_overflow: |
| 1595 | case Builtin::BI__builtin_smulll_overflow: |
| 1596 | IntrinsicId = llvm::Intrinsic::smul_with_overflow; |
| 1597 | break; |
| 1598 | } |
| 1599 | |
| 1600 | |
| 1601 | llvm::Value *Carry; |
| 1602 | llvm::Value *Sum = EmitOverflowIntrinsic(*this, IntrinsicId, X, Y, Carry); |
| 1603 | llvm::StoreInst *SumOutStore = Builder.CreateStore(Sum, SumOutPtr.first); |
| 1604 | SumOutStore->setAlignment(SumOutPtr.second); |
| 1605 | |
| 1606 | return RValue::get(Carry); |
| 1607 | } |
Richard Smith | 6cbd65d | 2013-07-11 02:27:57 +0000 | [diff] [blame] | 1608 | case Builtin::BI__builtin_addressof: |
| 1609 | return RValue::get(EmitLValue(E->getArg(0)).getAddress()); |
Richard Smith | 760520b | 2014-06-03 23:27:44 +0000 | [diff] [blame] | 1610 | case Builtin::BI__builtin_operator_new: |
| 1611 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 1612 | E->getArg(0), false); |
| 1613 | case Builtin::BI__builtin_operator_delete: |
| 1614 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 1615 | E->getArg(0), true); |
Nico Weber | 636fc09 | 2012-10-13 22:30:41 +0000 | [diff] [blame] | 1616 | case Builtin::BI__noop: |
Reid Kleckner | ed5d4ad | 2014-07-11 20:22:55 +0000 | [diff] [blame] | 1617 | // __noop always evaluates to an integer literal zero. |
| 1618 | return RValue::get(ConstantInt::get(IntTy, 0)); |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 1619 | case Builtin::BI__builtin_call_with_static_chain: { |
| 1620 | const CallExpr *Call = cast<CallExpr>(E->getArg(0)); |
| 1621 | const Expr *Chain = E->getArg(1); |
| 1622 | return EmitCall(Call->getCallee()->getType(), |
| 1623 | EmitScalarExpr(Call->getCallee()), Call, ReturnValue, |
| 1624 | Call->getCalleeDecl(), EmitScalarExpr(Chain)); |
| 1625 | } |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 1626 | case Builtin::BI_InterlockedExchange: |
| 1627 | case Builtin::BI_InterlockedExchangePointer: |
| 1628 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
| 1629 | case Builtin::BI_InterlockedCompareExchangePointer: { |
| 1630 | llvm::Type *RTy; |
| 1631 | llvm::IntegerType *IntType = |
| 1632 | IntegerType::get(getLLVMContext(), |
| 1633 | getContext().getTypeSize(E->getType())); |
| 1634 | llvm::Type *IntPtrType = IntType->getPointerTo(); |
| 1635 | |
| 1636 | llvm::Value *Destination = |
| 1637 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), IntPtrType); |
| 1638 | |
| 1639 | llvm::Value *Exchange = EmitScalarExpr(E->getArg(1)); |
| 1640 | RTy = Exchange->getType(); |
| 1641 | Exchange = Builder.CreatePtrToInt(Exchange, IntType); |
| 1642 | |
| 1643 | llvm::Value *Comparand = |
| 1644 | Builder.CreatePtrToInt(EmitScalarExpr(E->getArg(2)), IntType); |
| 1645 | |
| 1646 | auto Result = Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange, |
| 1647 | SequentiallyConsistent, |
| 1648 | SequentiallyConsistent); |
| 1649 | Result->setVolatile(true); |
| 1650 | |
| 1651 | return RValue::get(Builder.CreateIntToPtr(Builder.CreateExtractValue(Result, |
| 1652 | 0), |
| 1653 | RTy)); |
| 1654 | } |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1655 | case Builtin::BI_InterlockedCompareExchange: { |
| 1656 | AtomicCmpXchgInst *CXI = Builder.CreateAtomicCmpXchg( |
| 1657 | EmitScalarExpr(E->getArg(0)), |
| 1658 | EmitScalarExpr(E->getArg(2)), |
| 1659 | EmitScalarExpr(E->getArg(1)), |
Tim Northover | 0622b3a | 2014-03-11 10:49:03 +0000 | [diff] [blame] | 1660 | SequentiallyConsistent, |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1661 | SequentiallyConsistent); |
| 1662 | CXI->setVolatile(true); |
Tim Northover | b49b04b | 2014-06-13 14:24:59 +0000 | [diff] [blame] | 1663 | return RValue::get(Builder.CreateExtractValue(CXI, 0)); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1664 | } |
| 1665 | case Builtin::BI_InterlockedIncrement: { |
| 1666 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 1667 | AtomicRMWInst::Add, |
| 1668 | EmitScalarExpr(E->getArg(0)), |
| 1669 | ConstantInt::get(Int32Ty, 1), |
| 1670 | llvm::SequentiallyConsistent); |
| 1671 | RMWI->setVolatile(true); |
| 1672 | return RValue::get(Builder.CreateAdd(RMWI, ConstantInt::get(Int32Ty, 1))); |
| 1673 | } |
| 1674 | case Builtin::BI_InterlockedDecrement: { |
| 1675 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 1676 | AtomicRMWInst::Sub, |
| 1677 | EmitScalarExpr(E->getArg(0)), |
| 1678 | ConstantInt::get(Int32Ty, 1), |
| 1679 | llvm::SequentiallyConsistent); |
| 1680 | RMWI->setVolatile(true); |
| 1681 | return RValue::get(Builder.CreateSub(RMWI, ConstantInt::get(Int32Ty, 1))); |
| 1682 | } |
| 1683 | case Builtin::BI_InterlockedExchangeAdd: { |
| 1684 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 1685 | AtomicRMWInst::Add, |
| 1686 | EmitScalarExpr(E->getArg(0)), |
| 1687 | EmitScalarExpr(E->getArg(1)), |
| 1688 | llvm::SequentiallyConsistent); |
| 1689 | RMWI->setVolatile(true); |
| 1690 | return RValue::get(RMWI); |
| 1691 | } |
Saleem Abdulrasool | a25fbef | 2014-10-29 16:35:41 +0000 | [diff] [blame] | 1692 | case Builtin::BI__readfsdword: { |
| 1693 | Value *IntToPtr = |
| 1694 | Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), |
| 1695 | llvm::PointerType::get(CGM.Int32Ty, 257)); |
| 1696 | LoadInst *Load = |
| 1697 | Builder.CreateAlignedLoad(IntToPtr, /*Align=*/4, /*isVolatile=*/true); |
| 1698 | return RValue::get(Load); |
| 1699 | } |
Reid Kleckner | 1d59f99 | 2015-01-22 01:36:17 +0000 | [diff] [blame] | 1700 | |
| 1701 | case Builtin::BI__exception_code: |
| 1702 | case Builtin::BI_exception_code: |
| 1703 | return RValue::get(EmitSEHExceptionCode()); |
| 1704 | case Builtin::BI__exception_info: |
| 1705 | case Builtin::BI_exception_info: |
| 1706 | return RValue::get(EmitSEHExceptionInfo()); |
Reid Kleckner | aca01db | 2015-02-04 22:37:07 +0000 | [diff] [blame] | 1707 | case Builtin::BI__abnormal_termination: |
| 1708 | case Builtin::BI_abnormal_termination: |
| 1709 | return RValue::get(EmitSEHAbnormalTermination()); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1710 | case Builtin::BI_setjmpex: { |
| 1711 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 1712 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 1713 | llvm::AttributeSet ReturnsTwiceAttr = |
| 1714 | AttributeSet::get(getLLVMContext(), llvm::AttributeSet::FunctionIndex, |
| 1715 | llvm::Attribute::ReturnsTwice); |
| 1716 | llvm::Constant *SetJmpEx = CGM.CreateRuntimeFunction( |
| 1717 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
| 1718 | "_setjmpex", ReturnsTwiceAttr); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1719 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 1720 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1721 | llvm::Value *FrameAddr = |
| 1722 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 1723 | ConstantInt::get(Int32Ty, 0)); |
| 1724 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 1725 | llvm::CallSite CS = EmitRuntimeCallOrInvoke(SetJmpEx, Args); |
| 1726 | CS.setAttributes(ReturnsTwiceAttr); |
| 1727 | return RValue::get(CS.getInstruction()); |
| 1728 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1729 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1730 | } |
| 1731 | case Builtin::BI_setjmp: { |
| 1732 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 1733 | llvm::AttributeSet ReturnsTwiceAttr = |
| 1734 | AttributeSet::get(getLLVMContext(), llvm::AttributeSet::FunctionIndex, |
| 1735 | llvm::Attribute::ReturnsTwice); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1736 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 1737 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1738 | llvm::CallSite CS; |
| 1739 | if (getTarget().getTriple().getArch() == llvm::Triple::x86) { |
| 1740 | llvm::Type *ArgTypes[] = {Int8PtrTy, IntTy}; |
| 1741 | llvm::Constant *SetJmp3 = CGM.CreateRuntimeFunction( |
| 1742 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/true), |
| 1743 | "_setjmp3", ReturnsTwiceAttr); |
| 1744 | llvm::Value *Count = ConstantInt::get(IntTy, 0); |
| 1745 | llvm::Value *Args[] = {Buf, Count}; |
| 1746 | CS = EmitRuntimeCallOrInvoke(SetJmp3, Args); |
| 1747 | } else { |
| 1748 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 1749 | llvm::Constant *SetJmp = CGM.CreateRuntimeFunction( |
| 1750 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
| 1751 | "_setjmp", ReturnsTwiceAttr); |
| 1752 | llvm::Value *FrameAddr = |
| 1753 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 1754 | ConstantInt::get(Int32Ty, 0)); |
| 1755 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 1756 | CS = EmitRuntimeCallOrInvoke(SetJmp, Args); |
| 1757 | } |
| 1758 | CS.setAttributes(ReturnsTwiceAttr); |
| 1759 | return RValue::get(CS.getInstruction()); |
| 1760 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1761 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1762 | } |
David Majnemer | ba3e5ec | 2015-03-13 18:26:17 +0000 | [diff] [blame] | 1763 | |
| 1764 | case Builtin::BI__GetExceptionInfo: { |
| 1765 | if (llvm::GlobalVariable *GV = |
| 1766 | CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType())) |
| 1767 | return RValue::get(llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy)); |
| 1768 | break; |
| 1769 | } |
Nate Begeman | 6c59132 | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 1770 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 1772 | // If this is an alias for a lib function (e.g. __builtin_sin), emit |
| 1773 | // the call using the normal call path, but using the unmangled |
| 1774 | // version of the function name. |
| 1775 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) |
| 1776 | return emitLibraryCall(*this, FD, E, |
| 1777 | CGM.getBuiltinLibFunction(FD, BuiltinID)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1778 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 1779 | // If this is a predefined lib function (e.g. malloc), emit the call |
| 1780 | // using exactly the normal call path. |
| 1781 | if (getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
| 1782 | return emitLibraryCall(*this, FD, E, EmitScalarExpr(E->getCallee())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1784 | // See if we have a target specific intrinsic. |
Dale Johannesen | 621c351 | 2009-02-05 01:50:47 +0000 | [diff] [blame] | 1785 | const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1786 | Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; |
| 1787 | if (const char *Prefix = |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 1788 | llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch())) { |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1789 | IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name); |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 1790 | // NOTE we dont need to perform a compatibility flag check here since the |
| 1791 | // intrinsics are declared in Builtins*.def via LANGBUILTIN which filter the |
| 1792 | // MS builtins via ALL_MS_LANGUAGES and are filtered earlier. |
| 1793 | if (IntrinsicID == Intrinsic::not_intrinsic) |
| 1794 | IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix, Name); |
| 1795 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1796 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1797 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
| 1798 | SmallVector<Value*, 16> Args; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1799 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 1800 | // Find out if any arguments are required to be integer constant |
| 1801 | // expressions. |
| 1802 | unsigned ICEArguments = 0; |
| 1803 | ASTContext::GetBuiltinTypeError Error; |
| 1804 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 1805 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 1806 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1807 | Function *F = CGM.getIntrinsic(IntrinsicID); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1808 | llvm::FunctionType *FTy = F->getFunctionType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1809 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1810 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 1811 | Value *ArgValue; |
| 1812 | // If this is a normal argument, just emit it as a scalar. |
| 1813 | if ((ICEArguments & (1 << i)) == 0) { |
| 1814 | ArgValue = EmitScalarExpr(E->getArg(i)); |
| 1815 | } else { |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1816 | // If this is required to be a constant, constant fold it so that we |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 1817 | // know that the generated intrinsic gets a ConstantInt. |
| 1818 | llvm::APSInt Result; |
| 1819 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext()); |
| 1820 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 1821 | (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1822 | ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 1823 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1824 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1825 | // If the intrinsic arg type is different from the builtin arg type |
| 1826 | // we need to do a bit cast. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1827 | llvm::Type *PTy = FTy->getParamType(i); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1828 | if (PTy != ArgValue->getType()) { |
| 1829 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 1830 | "Must be able to losslessly bit cast to param"); |
| 1831 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 1832 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1833 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1834 | Args.push_back(ArgValue); |
| 1835 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1836 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1837 | Value *V = Builder.CreateCall(F, Args); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1838 | QualType BuiltinRetType = E->getType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 1840 | llvm::Type *RetTy = VoidTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1841 | if (!BuiltinRetType->isVoidType()) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 1842 | RetTy = ConvertType(BuiltinRetType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1844 | if (RetTy != V->getType()) { |
| 1845 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 1846 | "Must be able to losslessly bit cast result type"); |
| 1847 | V = Builder.CreateBitCast(V, RetTy); |
| 1848 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1849 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1850 | return RValue::get(V); |
| 1851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1852 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1853 | // See if we have a target specific builtin that needs to be lowered. |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1854 | if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1855 | return RValue::get(V); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1856 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 1857 | ErrorUnsupported(E, "builtin function"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 1859 | // Unknown builtin, for now just dump it out and return undef. |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 1860 | return GetUndefRValue(E->getType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1861 | } |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 1862 | |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1863 | Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, |
| 1864 | const CallExpr *E) { |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 1865 | switch (getTarget().getTriple().getArch()) { |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1866 | case llvm::Triple::arm: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1867 | case llvm::Triple::armeb: |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1868 | case llvm::Triple::thumb: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 1869 | case llvm::Triple::thumbeb: |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 1870 | return EmitARMBuiltinExpr(BuiltinID, E); |
Tim Northover | 25e8a67 | 2014-05-24 12:51:25 +0000 | [diff] [blame] | 1871 | case llvm::Triple::aarch64: |
| 1872 | case llvm::Triple::aarch64_be: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 1873 | return EmitAArch64BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1874 | case llvm::Triple::x86: |
| 1875 | case llvm::Triple::x86_64: |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1876 | return EmitX86BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1877 | case llvm::Triple::ppc: |
| 1878 | case llvm::Triple::ppc64: |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 1879 | case llvm::Triple::ppc64le: |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1880 | return EmitPPCBuiltinExpr(BuiltinID, E); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 1881 | case llvm::Triple::r600: |
Tom Stellard | d8e38a3 | 2015-01-06 20:34:47 +0000 | [diff] [blame] | 1882 | case llvm::Triple::amdgcn: |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 1883 | return EmitAMDGPUBuiltinExpr(BuiltinID, E); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 1884 | case llvm::Triple::systemz: |
| 1885 | return EmitSystemZBuiltinExpr(BuiltinID, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1886 | case llvm::Triple::nvptx: |
| 1887 | case llvm::Triple::nvptx64: |
| 1888 | return EmitNVPTXBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1889 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1890 | return nullptr; |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 1891 | } |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 1894 | static llvm::VectorType *GetNeonType(CodeGenFunction *CGF, |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1895 | NeonTypeFlags TypeFlags, |
| 1896 | bool V1Ty=false) { |
NAKAMURA Takumi | dabda6b | 2011-11-08 03:27:04 +0000 | [diff] [blame] | 1897 | int IsQuad = TypeFlags.isQuad(); |
| 1898 | switch (TypeFlags.getEltType()) { |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 1899 | case NeonTypeFlags::Int8: |
| 1900 | case NeonTypeFlags::Poly8: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1901 | return llvm::VectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 1902 | case NeonTypeFlags::Int16: |
| 1903 | case NeonTypeFlags::Poly16: |
| 1904 | case NeonTypeFlags::Float16: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1905 | return llvm::VectorType::get(CGF->Int16Ty, V1Ty ? 1 : (4 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 1906 | case NeonTypeFlags::Int32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1907 | return llvm::VectorType::get(CGF->Int32Ty, V1Ty ? 1 : (2 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 1908 | case NeonTypeFlags::Int64: |
Kevin Qin | caac85e | 2013-11-14 03:29:16 +0000 | [diff] [blame] | 1909 | case NeonTypeFlags::Poly64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1910 | return llvm::VectorType::get(CGF->Int64Ty, V1Ty ? 1 : (1 << IsQuad)); |
Kevin Qin | fb79d7f | 2013-12-10 06:49:01 +0000 | [diff] [blame] | 1911 | case NeonTypeFlags::Poly128: |
| 1912 | // FIXME: i128 and f128 doesn't get fully support in Clang and llvm. |
| 1913 | // There is a lot of i128 and f128 API missing. |
| 1914 | // so we use v16i8 to represent poly128 and get pattern matched. |
| 1915 | return llvm::VectorType::get(CGF->Int8Ty, 16); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 1916 | case NeonTypeFlags::Float32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1917 | return llvm::VectorType::get(CGF->FloatTy, V1Ty ? 1 : (2 << IsQuad)); |
Tim Northover | 2fe823a | 2013-08-01 09:23:19 +0000 | [diff] [blame] | 1918 | case NeonTypeFlags::Float64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 1919 | return llvm::VectorType::get(CGF->DoubleTy, V1Ty ? 1 : (1 << IsQuad)); |
David Blaikie | f47fa30 | 2012-01-17 02:30:50 +0000 | [diff] [blame] | 1920 | } |
Benjamin Kramer | 9b1dfe8 | 2013-09-26 16:36:08 +0000 | [diff] [blame] | 1921 | llvm_unreachable("Unknown vector element type!"); |
Nate Begeman | 5968eb2 | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
Bob Wilson | 210f6dd | 2010-12-07 22:40:02 +0000 | [diff] [blame] | 1924 | Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) { |
Nate Begeman | 4a04b46 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1925 | unsigned nElts = cast<llvm::VectorType>(V->getType())->getNumElements(); |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 1926 | Value* SV = llvm::ConstantVector::getSplat(nElts, C); |
Nate Begeman | 4a04b46 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 1927 | return Builder.CreateShuffleVector(V, V, SV, "lane"); |
| 1928 | } |
| 1929 | |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1930 | Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops, |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 1931 | const char *name, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1932 | unsigned shift, bool rightshift) { |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1933 | unsigned j = 0; |
| 1934 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 1935 | ai != ae; ++ai, ++j) |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 1936 | if (shift > 0 && shift == j) |
| 1937 | Ops[j] = EmitNeonShiftVector(Ops[j], ai->getType(), rightshift); |
| 1938 | else |
| 1939 | Ops[j] = Builder.CreateBitCast(Ops[j], ai->getType(), name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1940 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 1941 | return Builder.CreateCall(F, Ops, name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1944 | Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty, |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1945 | bool neg) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 1946 | int SV = cast<ConstantInt>(V)->getSExtValue(); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1947 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1948 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1949 | llvm::Constant *C = ConstantInt::get(VTy->getElementType(), neg ? -SV : SV); |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 1950 | return llvm::ConstantVector::getSplat(VTy->getNumElements(), C); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 1953 | // \brief Right-shift a vector by a constant. |
| 1954 | Value *CodeGenFunction::EmitNeonRShiftImm(Value *Vec, Value *Shift, |
| 1955 | llvm::Type *Ty, bool usgn, |
| 1956 | const char *name) { |
| 1957 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 1958 | |
| 1959 | int ShiftAmt = cast<ConstantInt>(Shift)->getSExtValue(); |
| 1960 | int EltSize = VTy->getScalarSizeInBits(); |
| 1961 | |
| 1962 | Vec = Builder.CreateBitCast(Vec, Ty); |
| 1963 | |
| 1964 | // lshr/ashr are undefined when the shift amount is equal to the vector |
| 1965 | // element size. |
| 1966 | if (ShiftAmt == EltSize) { |
| 1967 | if (usgn) { |
| 1968 | // Right-shifting an unsigned value by its size yields 0. |
| 1969 | llvm::Constant *Zero = ConstantInt::get(VTy->getElementType(), 0); |
| 1970 | return llvm::ConstantVector::getSplat(VTy->getNumElements(), Zero); |
| 1971 | } else { |
| 1972 | // Right-shifting a signed value by its size is equivalent |
| 1973 | // to a shift of size-1. |
| 1974 | --ShiftAmt; |
| 1975 | Shift = ConstantInt::get(VTy->getElementType(), ShiftAmt); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | Shift = EmitNeonShiftVector(Shift, Ty, false); |
| 1980 | if (usgn) |
| 1981 | return Builder.CreateLShr(Vec, Shift, name); |
| 1982 | else |
| 1983 | return Builder.CreateAShr(Vec, Shift, name); |
| 1984 | } |
| 1985 | |
Bob Wilson | 7b0d032 | 2010-08-27 17:14:29 +0000 | [diff] [blame] | 1986 | /// GetPointeeAlignment - Given an expression with a pointer type, find the |
| 1987 | /// alignment of the type referenced by the pointer. Skip over implicit |
| 1988 | /// casts. |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 1989 | std::pair<llvm::Value*, unsigned> |
| 1990 | CodeGenFunction::EmitPointerWithAlignment(const Expr *Addr) { |
| 1991 | assert(Addr->getType()->isPointerType()); |
| 1992 | Addr = Addr->IgnoreParens(); |
| 1993 | if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Addr)) { |
Eli Friedman | 504f9a2 | 2012-08-29 21:21:11 +0000 | [diff] [blame] | 1994 | if ((ICE->getCastKind() == CK_BitCast || ICE->getCastKind() == CK_NoOp) && |
| 1995 | ICE->getSubExpr()->getType()->isPointerType()) { |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1996 | std::pair<llvm::Value*, unsigned> Ptr = |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 1997 | EmitPointerWithAlignment(ICE->getSubExpr()); |
| 1998 | Ptr.first = Builder.CreateBitCast(Ptr.first, |
| 1999 | ConvertType(Addr->getType())); |
| 2000 | return Ptr; |
| 2001 | } else if (ICE->getCastKind() == CK_ArrayToPointerDecay) { |
| 2002 | LValue LV = EmitLValue(ICE->getSubExpr()); |
Eli Friedman | 5d14c48 | 2012-08-23 11:27:56 +0000 | [diff] [blame] | 2003 | unsigned Align = LV.getAlignment().getQuantity(); |
| 2004 | if (!Align) { |
| 2005 | // FIXME: Once LValues are fixed to always set alignment, |
| 2006 | // zap this code. |
| 2007 | QualType PtTy = ICE->getSubExpr()->getType(); |
| 2008 | if (!PtTy->isIncompleteType()) |
| 2009 | Align = getContext().getTypeAlignInChars(PtTy).getQuantity(); |
| 2010 | else |
| 2011 | Align = 1; |
| 2012 | } |
| 2013 | return std::make_pair(LV.getAddress(), Align); |
Chris Lattner | aaa18fa | 2012-03-04 00:52:12 +0000 | [diff] [blame] | 2014 | } |
Bob Wilson | 7b0d032 | 2010-08-27 17:14:29 +0000 | [diff] [blame] | 2015 | } |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 2016 | if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(Addr)) { |
| 2017 | if (UO->getOpcode() == UO_AddrOf) { |
| 2018 | LValue LV = EmitLValue(UO->getSubExpr()); |
Eli Friedman | 5d14c48 | 2012-08-23 11:27:56 +0000 | [diff] [blame] | 2019 | unsigned Align = LV.getAlignment().getQuantity(); |
| 2020 | if (!Align) { |
| 2021 | // FIXME: Once LValues are fixed to always set alignment, |
| 2022 | // zap this code. |
| 2023 | QualType PtTy = UO->getSubExpr()->getType(); |
| 2024 | if (!PtTy->isIncompleteType()) |
| 2025 | Align = getContext().getTypeAlignInChars(PtTy).getQuantity(); |
| 2026 | else |
| 2027 | Align = 1; |
| 2028 | } |
| 2029 | return std::make_pair(LV.getAddress(), Align); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 2030 | } |
| 2031 | } |
Jay Foad | b0f3344 | 2012-03-02 18:34:30 +0000 | [diff] [blame] | 2032 | |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 2033 | unsigned Align = 1; |
| 2034 | QualType PtTy = Addr->getType()->getPointeeType(); |
| 2035 | if (!PtTy->isIncompleteType()) |
| 2036 | Align = getContext().getTypeAlignInChars(PtTy).getQuantity(); |
| 2037 | |
| 2038 | return std::make_pair(EmitScalarExpr(Addr), Align); |
Bob Wilson | 7b0d032 | 2010-08-27 17:14:29 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2041 | enum { |
| 2042 | AddRetType = (1 << 0), |
| 2043 | Add1ArgType = (1 << 1), |
| 2044 | Add2ArgTypes = (1 << 2), |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2045 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2046 | VectorizeRetType = (1 << 3), |
| 2047 | VectorizeArgTypes = (1 << 4), |
| 2048 | |
| 2049 | InventFloatType = (1 << 5), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2050 | UnsignedAlts = (1 << 6), |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2051 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2052 | Use64BitVectors = (1 << 7), |
| 2053 | Use128BitVectors = (1 << 8), |
| 2054 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2055 | Vectorize1ArgType = Add1ArgType | VectorizeArgTypes, |
| 2056 | VectorRet = AddRetType | VectorizeRetType, |
| 2057 | VectorRetGetArgs01 = |
| 2058 | AddRetType | Add2ArgTypes | VectorizeRetType | VectorizeArgTypes, |
| 2059 | FpCmpzModifiers = |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 2060 | AddRetType | VectorizeRetType | Add1ArgType | InventFloatType |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2061 | }; |
| 2062 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2063 | struct NeonIntrinsicInfo { |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2064 | unsigned BuiltinID; |
| 2065 | unsigned LLVMIntrinsic; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2066 | unsigned AltLLVMIntrinsic; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2067 | const char *NameHint; |
| 2068 | unsigned TypeModifier; |
| 2069 | |
| 2070 | bool operator<(unsigned RHSBuiltinID) const { |
| 2071 | return BuiltinID < RHSBuiltinID; |
| 2072 | } |
| 2073 | }; |
| 2074 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2075 | #define NEONMAP0(NameBase) \ |
| 2076 | { NEON::BI__builtin_neon_ ## NameBase, 0, 0, #NameBase, 0 } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2077 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2078 | #define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier) \ |
| 2079 | { NEON:: BI__builtin_neon_ ## NameBase, \ |
| 2080 | Intrinsic::LLVMIntrinsic, 0, #NameBase, TypeModifier } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2081 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2082 | #define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier) \ |
| 2083 | { NEON:: BI__builtin_neon_ ## NameBase, \ |
| 2084 | Intrinsic::LLVMIntrinsic, Intrinsic::AltLLVMIntrinsic, \ |
| 2085 | #NameBase, TypeModifier } |
| 2086 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2087 | static NeonIntrinsicInfo ARMSIMDIntrinsicMap [] = { |
| 2088 | NEONMAP2(vabd_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 2089 | NEONMAP2(vabdq_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 2090 | NEONMAP1(vabs_v, arm_neon_vabs, 0), |
| 2091 | NEONMAP1(vabsq_v, arm_neon_vabs, 0), |
| 2092 | NEONMAP0(vaddhn_v), |
| 2093 | NEONMAP1(vaesdq_v, arm_neon_aesd, 0), |
| 2094 | NEONMAP1(vaeseq_v, arm_neon_aese, 0), |
| 2095 | NEONMAP1(vaesimcq_v, arm_neon_aesimc, 0), |
| 2096 | NEONMAP1(vaesmcq_v, arm_neon_aesmc, 0), |
| 2097 | NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType), |
| 2098 | NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType), |
| 2099 | NEONMAP1(vcage_v, arm_neon_vacge, 0), |
| 2100 | NEONMAP1(vcageq_v, arm_neon_vacge, 0), |
| 2101 | NEONMAP1(vcagt_v, arm_neon_vacgt, 0), |
| 2102 | NEONMAP1(vcagtq_v, arm_neon_vacgt, 0), |
| 2103 | NEONMAP1(vcale_v, arm_neon_vacge, 0), |
| 2104 | NEONMAP1(vcaleq_v, arm_neon_vacge, 0), |
| 2105 | NEONMAP1(vcalt_v, arm_neon_vacgt, 0), |
| 2106 | NEONMAP1(vcaltq_v, arm_neon_vacgt, 0), |
| 2107 | NEONMAP1(vcls_v, arm_neon_vcls, Add1ArgType), |
| 2108 | NEONMAP1(vclsq_v, arm_neon_vcls, Add1ArgType), |
| 2109 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 2110 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 2111 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 2112 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
| 2113 | NEONMAP1(vcvt_f16_v, arm_neon_vcvtfp2hf, 0), |
| 2114 | NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0), |
| 2115 | NEONMAP0(vcvt_f32_v), |
| 2116 | NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
| 2117 | NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 2118 | NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
| 2119 | NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 2120 | NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
| 2121 | NEONMAP0(vcvt_s32_v), |
| 2122 | NEONMAP0(vcvt_s64_v), |
| 2123 | NEONMAP0(vcvt_u32_v), |
| 2124 | NEONMAP0(vcvt_u64_v), |
| 2125 | NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0), |
| 2126 | NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0), |
| 2127 | NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0), |
| 2128 | NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0), |
| 2129 | NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0), |
| 2130 | NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0), |
| 2131 | NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0), |
| 2132 | NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0), |
| 2133 | NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0), |
| 2134 | NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0), |
| 2135 | NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0), |
| 2136 | NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0), |
| 2137 | NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0), |
| 2138 | NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0), |
| 2139 | NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0), |
| 2140 | NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0), |
| 2141 | NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0), |
| 2142 | NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0), |
| 2143 | NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0), |
| 2144 | NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0), |
| 2145 | NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0), |
| 2146 | NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0), |
| 2147 | NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0), |
| 2148 | NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0), |
| 2149 | NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0), |
| 2150 | NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0), |
| 2151 | NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0), |
| 2152 | NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0), |
| 2153 | NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0), |
| 2154 | NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0), |
| 2155 | NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0), |
| 2156 | NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0), |
| 2157 | NEONMAP0(vcvtq_f32_v), |
| 2158 | NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
| 2159 | NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 2160 | NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
| 2161 | NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 2162 | NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
| 2163 | NEONMAP0(vcvtq_s32_v), |
| 2164 | NEONMAP0(vcvtq_s64_v), |
| 2165 | NEONMAP0(vcvtq_u32_v), |
| 2166 | NEONMAP0(vcvtq_u64_v), |
| 2167 | NEONMAP0(vext_v), |
| 2168 | NEONMAP0(vextq_v), |
| 2169 | NEONMAP0(vfma_v), |
| 2170 | NEONMAP0(vfmaq_v), |
| 2171 | NEONMAP2(vhadd_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 2172 | NEONMAP2(vhaddq_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 2173 | NEONMAP2(vhsub_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 2174 | NEONMAP2(vhsubq_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 2175 | NEONMAP0(vld1_dup_v), |
| 2176 | NEONMAP1(vld1_v, arm_neon_vld1, 0), |
| 2177 | NEONMAP0(vld1q_dup_v), |
| 2178 | NEONMAP1(vld1q_v, arm_neon_vld1, 0), |
| 2179 | NEONMAP1(vld2_lane_v, arm_neon_vld2lane, 0), |
| 2180 | NEONMAP1(vld2_v, arm_neon_vld2, 0), |
| 2181 | NEONMAP1(vld2q_lane_v, arm_neon_vld2lane, 0), |
| 2182 | NEONMAP1(vld2q_v, arm_neon_vld2, 0), |
| 2183 | NEONMAP1(vld3_lane_v, arm_neon_vld3lane, 0), |
| 2184 | NEONMAP1(vld3_v, arm_neon_vld3, 0), |
| 2185 | NEONMAP1(vld3q_lane_v, arm_neon_vld3lane, 0), |
| 2186 | NEONMAP1(vld3q_v, arm_neon_vld3, 0), |
| 2187 | NEONMAP1(vld4_lane_v, arm_neon_vld4lane, 0), |
| 2188 | NEONMAP1(vld4_v, arm_neon_vld4, 0), |
| 2189 | NEONMAP1(vld4q_lane_v, arm_neon_vld4lane, 0), |
| 2190 | NEONMAP1(vld4q_v, arm_neon_vld4, 0), |
| 2191 | NEONMAP2(vmax_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2192 | NEONMAP1(vmaxnm_v, arm_neon_vmaxnm, Add1ArgType), |
| 2193 | NEONMAP1(vmaxnmq_v, arm_neon_vmaxnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2194 | NEONMAP2(vmaxq_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
| 2195 | NEONMAP2(vmin_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2196 | NEONMAP1(vminnm_v, arm_neon_vminnm, Add1ArgType), |
| 2197 | NEONMAP1(vminnmq_v, arm_neon_vminnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2198 | NEONMAP2(vminq_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
| 2199 | NEONMAP0(vmovl_v), |
| 2200 | NEONMAP0(vmovn_v), |
| 2201 | NEONMAP1(vmul_v, arm_neon_vmulp, Add1ArgType), |
| 2202 | NEONMAP0(vmull_v), |
| 2203 | NEONMAP1(vmulq_v, arm_neon_vmulp, Add1ArgType), |
| 2204 | NEONMAP2(vpadal_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 2205 | NEONMAP2(vpadalq_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 2206 | NEONMAP1(vpadd_v, arm_neon_vpadd, Add1ArgType), |
| 2207 | NEONMAP2(vpaddl_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 2208 | NEONMAP2(vpaddlq_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 2209 | NEONMAP1(vpaddq_v, arm_neon_vpadd, Add1ArgType), |
| 2210 | NEONMAP2(vpmax_v, arm_neon_vpmaxu, arm_neon_vpmaxs, Add1ArgType | UnsignedAlts), |
| 2211 | NEONMAP2(vpmin_v, arm_neon_vpminu, arm_neon_vpmins, Add1ArgType | UnsignedAlts), |
| 2212 | NEONMAP1(vqabs_v, arm_neon_vqabs, Add1ArgType), |
| 2213 | NEONMAP1(vqabsq_v, arm_neon_vqabs, Add1ArgType), |
| 2214 | NEONMAP2(vqadd_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 2215 | NEONMAP2(vqaddq_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 2216 | NEONMAP2(vqdmlal_v, arm_neon_vqdmull, arm_neon_vqadds, 0), |
| 2217 | NEONMAP2(vqdmlsl_v, arm_neon_vqdmull, arm_neon_vqsubs, 0), |
| 2218 | NEONMAP1(vqdmulh_v, arm_neon_vqdmulh, Add1ArgType), |
| 2219 | NEONMAP1(vqdmulhq_v, arm_neon_vqdmulh, Add1ArgType), |
| 2220 | NEONMAP1(vqdmull_v, arm_neon_vqdmull, Add1ArgType), |
| 2221 | NEONMAP2(vqmovn_v, arm_neon_vqmovnu, arm_neon_vqmovns, Add1ArgType | UnsignedAlts), |
| 2222 | NEONMAP1(vqmovun_v, arm_neon_vqmovnsu, Add1ArgType), |
| 2223 | NEONMAP1(vqneg_v, arm_neon_vqneg, Add1ArgType), |
| 2224 | NEONMAP1(vqnegq_v, arm_neon_vqneg, Add1ArgType), |
| 2225 | NEONMAP1(vqrdmulh_v, arm_neon_vqrdmulh, Add1ArgType), |
| 2226 | NEONMAP1(vqrdmulhq_v, arm_neon_vqrdmulh, Add1ArgType), |
| 2227 | NEONMAP2(vqrshl_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 2228 | NEONMAP2(vqrshlq_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 2229 | NEONMAP2(vqshl_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 2230 | NEONMAP2(vqshl_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
| 2231 | NEONMAP2(vqshlq_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 2232 | NEONMAP2(vqshlq_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2233 | NEONMAP1(vqshlu_n_v, arm_neon_vqshiftsu, 0), |
| 2234 | NEONMAP1(vqshluq_n_v, arm_neon_vqshiftsu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2235 | NEONMAP2(vqsub_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 2236 | NEONMAP2(vqsubq_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 2237 | NEONMAP1(vraddhn_v, arm_neon_vraddhn, Add1ArgType), |
| 2238 | NEONMAP2(vrecpe_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 2239 | NEONMAP2(vrecpeq_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 2240 | NEONMAP1(vrecps_v, arm_neon_vrecps, Add1ArgType), |
| 2241 | NEONMAP1(vrecpsq_v, arm_neon_vrecps, Add1ArgType), |
| 2242 | NEONMAP2(vrhadd_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
| 2243 | NEONMAP2(vrhaddq_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2244 | NEONMAP1(vrnd_v, arm_neon_vrintz, Add1ArgType), |
| 2245 | NEONMAP1(vrnda_v, arm_neon_vrinta, Add1ArgType), |
| 2246 | NEONMAP1(vrndaq_v, arm_neon_vrinta, Add1ArgType), |
| 2247 | NEONMAP1(vrndm_v, arm_neon_vrintm, Add1ArgType), |
| 2248 | NEONMAP1(vrndmq_v, arm_neon_vrintm, Add1ArgType), |
| 2249 | NEONMAP1(vrndn_v, arm_neon_vrintn, Add1ArgType), |
| 2250 | NEONMAP1(vrndnq_v, arm_neon_vrintn, Add1ArgType), |
| 2251 | NEONMAP1(vrndp_v, arm_neon_vrintp, Add1ArgType), |
| 2252 | NEONMAP1(vrndpq_v, arm_neon_vrintp, Add1ArgType), |
| 2253 | NEONMAP1(vrndq_v, arm_neon_vrintz, Add1ArgType), |
| 2254 | NEONMAP1(vrndx_v, arm_neon_vrintx, Add1ArgType), |
| 2255 | NEONMAP1(vrndxq_v, arm_neon_vrintx, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2256 | NEONMAP2(vrshl_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
| 2257 | NEONMAP2(vrshlq_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2258 | NEONMAP2(vrshr_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
| 2259 | NEONMAP2(vrshrq_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2260 | NEONMAP2(vrsqrte_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 2261 | NEONMAP2(vrsqrteq_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 2262 | NEONMAP1(vrsqrts_v, arm_neon_vrsqrts, Add1ArgType), |
| 2263 | NEONMAP1(vrsqrtsq_v, arm_neon_vrsqrts, Add1ArgType), |
| 2264 | NEONMAP1(vrsubhn_v, arm_neon_vrsubhn, Add1ArgType), |
| 2265 | NEONMAP1(vsha1su0q_v, arm_neon_sha1su0, 0), |
| 2266 | NEONMAP1(vsha1su1q_v, arm_neon_sha1su1, 0), |
| 2267 | NEONMAP1(vsha256h2q_v, arm_neon_sha256h2, 0), |
| 2268 | NEONMAP1(vsha256hq_v, arm_neon_sha256h, 0), |
| 2269 | NEONMAP1(vsha256su0q_v, arm_neon_sha256su0, 0), |
| 2270 | NEONMAP1(vsha256su1q_v, arm_neon_sha256su1, 0), |
| 2271 | NEONMAP0(vshl_n_v), |
| 2272 | NEONMAP2(vshl_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 2273 | NEONMAP0(vshll_n_v), |
| 2274 | NEONMAP0(vshlq_n_v), |
| 2275 | NEONMAP2(vshlq_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 2276 | NEONMAP0(vshr_n_v), |
| 2277 | NEONMAP0(vshrn_n_v), |
| 2278 | NEONMAP0(vshrq_n_v), |
| 2279 | NEONMAP1(vst1_v, arm_neon_vst1, 0), |
| 2280 | NEONMAP1(vst1q_v, arm_neon_vst1, 0), |
| 2281 | NEONMAP1(vst2_lane_v, arm_neon_vst2lane, 0), |
| 2282 | NEONMAP1(vst2_v, arm_neon_vst2, 0), |
| 2283 | NEONMAP1(vst2q_lane_v, arm_neon_vst2lane, 0), |
| 2284 | NEONMAP1(vst2q_v, arm_neon_vst2, 0), |
| 2285 | NEONMAP1(vst3_lane_v, arm_neon_vst3lane, 0), |
| 2286 | NEONMAP1(vst3_v, arm_neon_vst3, 0), |
| 2287 | NEONMAP1(vst3q_lane_v, arm_neon_vst3lane, 0), |
| 2288 | NEONMAP1(vst3q_v, arm_neon_vst3, 0), |
| 2289 | NEONMAP1(vst4_lane_v, arm_neon_vst4lane, 0), |
| 2290 | NEONMAP1(vst4_v, arm_neon_vst4, 0), |
| 2291 | NEONMAP1(vst4q_lane_v, arm_neon_vst4lane, 0), |
| 2292 | NEONMAP1(vst4q_v, arm_neon_vst4, 0), |
| 2293 | NEONMAP0(vsubhn_v), |
| 2294 | NEONMAP0(vtrn_v), |
| 2295 | NEONMAP0(vtrnq_v), |
| 2296 | NEONMAP0(vtst_v), |
| 2297 | NEONMAP0(vtstq_v), |
| 2298 | NEONMAP0(vuzp_v), |
| 2299 | NEONMAP0(vuzpq_v), |
| 2300 | NEONMAP0(vzip_v), |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 2301 | NEONMAP0(vzipq_v) |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2302 | }; |
| 2303 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2304 | static NeonIntrinsicInfo AArch64SIMDIntrinsicMap[] = { |
| 2305 | NEONMAP1(vabs_v, aarch64_neon_abs, 0), |
| 2306 | NEONMAP1(vabsq_v, aarch64_neon_abs, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2307 | NEONMAP0(vaddhn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2308 | NEONMAP1(vaesdq_v, aarch64_crypto_aesd, 0), |
| 2309 | NEONMAP1(vaeseq_v, aarch64_crypto_aese, 0), |
| 2310 | NEONMAP1(vaesimcq_v, aarch64_crypto_aesimc, 0), |
| 2311 | NEONMAP1(vaesmcq_v, aarch64_crypto_aesmc, 0), |
| 2312 | NEONMAP1(vcage_v, aarch64_neon_facge, 0), |
| 2313 | NEONMAP1(vcageq_v, aarch64_neon_facge, 0), |
| 2314 | NEONMAP1(vcagt_v, aarch64_neon_facgt, 0), |
| 2315 | NEONMAP1(vcagtq_v, aarch64_neon_facgt, 0), |
| 2316 | NEONMAP1(vcale_v, aarch64_neon_facge, 0), |
| 2317 | NEONMAP1(vcaleq_v, aarch64_neon_facge, 0), |
| 2318 | NEONMAP1(vcalt_v, aarch64_neon_facgt, 0), |
| 2319 | NEONMAP1(vcaltq_v, aarch64_neon_facgt, 0), |
| 2320 | NEONMAP1(vcls_v, aarch64_neon_cls, Add1ArgType), |
| 2321 | NEONMAP1(vclsq_v, aarch64_neon_cls, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2322 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 2323 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 2324 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 2325 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2326 | NEONMAP1(vcvt_f16_v, aarch64_neon_vcvtfp2hf, 0), |
| 2327 | NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2328 | NEONMAP0(vcvt_f32_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2329 | NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2330 | NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2331 | NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2332 | NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2333 | NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 2334 | NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2335 | NEONMAP0(vcvtq_f32_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2336 | NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2337 | NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2338 | NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2339 | NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2340 | NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 2341 | NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
| 2342 | NEONMAP1(vcvtx_f32_v, aarch64_neon_fcvtxn, AddRetType | Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2343 | NEONMAP0(vext_v), |
| 2344 | NEONMAP0(vextq_v), |
| 2345 | NEONMAP0(vfma_v), |
| 2346 | NEONMAP0(vfmaq_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2347 | NEONMAP2(vhadd_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 2348 | NEONMAP2(vhaddq_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 2349 | NEONMAP2(vhsub_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
| 2350 | NEONMAP2(vhsubq_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2351 | NEONMAP0(vmovl_v), |
| 2352 | NEONMAP0(vmovn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2353 | NEONMAP1(vmul_v, aarch64_neon_pmul, Add1ArgType), |
| 2354 | NEONMAP1(vmulq_v, aarch64_neon_pmul, Add1ArgType), |
| 2355 | NEONMAP1(vpadd_v, aarch64_neon_addp, Add1ArgType), |
| 2356 | NEONMAP2(vpaddl_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 2357 | NEONMAP2(vpaddlq_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 2358 | NEONMAP1(vpaddq_v, aarch64_neon_addp, Add1ArgType), |
| 2359 | NEONMAP1(vqabs_v, aarch64_neon_sqabs, Add1ArgType), |
| 2360 | NEONMAP1(vqabsq_v, aarch64_neon_sqabs, Add1ArgType), |
| 2361 | NEONMAP2(vqadd_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 2362 | NEONMAP2(vqaddq_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 2363 | NEONMAP2(vqdmlal_v, aarch64_neon_sqdmull, aarch64_neon_sqadd, 0), |
| 2364 | NEONMAP2(vqdmlsl_v, aarch64_neon_sqdmull, aarch64_neon_sqsub, 0), |
| 2365 | NEONMAP1(vqdmulh_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 2366 | NEONMAP1(vqdmulhq_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 2367 | NEONMAP1(vqdmull_v, aarch64_neon_sqdmull, Add1ArgType), |
| 2368 | NEONMAP2(vqmovn_v, aarch64_neon_uqxtn, aarch64_neon_sqxtn, Add1ArgType | UnsignedAlts), |
| 2369 | NEONMAP1(vqmovun_v, aarch64_neon_sqxtun, Add1ArgType), |
| 2370 | NEONMAP1(vqneg_v, aarch64_neon_sqneg, Add1ArgType), |
| 2371 | NEONMAP1(vqnegq_v, aarch64_neon_sqneg, Add1ArgType), |
| 2372 | NEONMAP1(vqrdmulh_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 2373 | NEONMAP1(vqrdmulhq_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 2374 | NEONMAP2(vqrshl_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 2375 | NEONMAP2(vqrshlq_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 2376 | NEONMAP2(vqshl_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl, UnsignedAlts), |
| 2377 | NEONMAP2(vqshl_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
| 2378 | NEONMAP2(vqshlq_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl,UnsignedAlts), |
| 2379 | NEONMAP2(vqshlq_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2380 | NEONMAP1(vqshlu_n_v, aarch64_neon_sqshlu, 0), |
| 2381 | NEONMAP1(vqshluq_n_v, aarch64_neon_sqshlu, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2382 | NEONMAP2(vqsub_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 2383 | NEONMAP2(vqsubq_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 2384 | NEONMAP1(vraddhn_v, aarch64_neon_raddhn, Add1ArgType), |
| 2385 | NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 2386 | NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 2387 | NEONMAP1(vrecps_v, aarch64_neon_frecps, Add1ArgType), |
| 2388 | NEONMAP1(vrecpsq_v, aarch64_neon_frecps, Add1ArgType), |
| 2389 | NEONMAP2(vrhadd_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 2390 | NEONMAP2(vrhaddq_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 2391 | NEONMAP2(vrshl_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
| 2392 | NEONMAP2(vrshlq_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2393 | NEONMAP2(vrshr_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
| 2394 | NEONMAP2(vrshrq_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2395 | NEONMAP2(vrsqrte_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 2396 | NEONMAP2(vrsqrteq_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 2397 | NEONMAP1(vrsqrts_v, aarch64_neon_frsqrts, Add1ArgType), |
| 2398 | NEONMAP1(vrsqrtsq_v, aarch64_neon_frsqrts, Add1ArgType), |
| 2399 | NEONMAP1(vrsubhn_v, aarch64_neon_rsubhn, Add1ArgType), |
| 2400 | NEONMAP1(vsha1su0q_v, aarch64_crypto_sha1su0, 0), |
| 2401 | NEONMAP1(vsha1su1q_v, aarch64_crypto_sha1su1, 0), |
| 2402 | NEONMAP1(vsha256h2q_v, aarch64_crypto_sha256h2, 0), |
| 2403 | NEONMAP1(vsha256hq_v, aarch64_crypto_sha256h, 0), |
| 2404 | NEONMAP1(vsha256su0q_v, aarch64_crypto_sha256su0, 0), |
| 2405 | NEONMAP1(vsha256su1q_v, aarch64_crypto_sha256su1, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2406 | NEONMAP0(vshl_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2407 | NEONMAP2(vshl_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2408 | NEONMAP0(vshll_n_v), |
| 2409 | NEONMAP0(vshlq_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2410 | NEONMAP2(vshlq_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2411 | NEONMAP0(vshr_n_v), |
| 2412 | NEONMAP0(vshrn_n_v), |
| 2413 | NEONMAP0(vshrq_n_v), |
| 2414 | NEONMAP0(vsubhn_v), |
| 2415 | NEONMAP0(vtst_v), |
| 2416 | NEONMAP0(vtstq_v), |
| 2417 | }; |
| 2418 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2419 | static NeonIntrinsicInfo AArch64SISDIntrinsicMap[] = { |
| 2420 | NEONMAP1(vabdd_f64, aarch64_sisd_fabd, Add1ArgType), |
| 2421 | NEONMAP1(vabds_f32, aarch64_sisd_fabd, Add1ArgType), |
| 2422 | NEONMAP1(vabsd_s64, aarch64_neon_abs, Add1ArgType), |
| 2423 | NEONMAP1(vaddlv_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 2424 | NEONMAP1(vaddlv_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 2425 | NEONMAP1(vaddlvq_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 2426 | NEONMAP1(vaddlvq_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 2427 | NEONMAP1(vaddv_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 2428 | NEONMAP1(vaddv_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 2429 | NEONMAP1(vaddv_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2430 | NEONMAP1(vaddvq_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 2431 | NEONMAP1(vaddvq_f64, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 2432 | NEONMAP1(vaddvq_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 2433 | NEONMAP1(vaddvq_s64, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 2434 | NEONMAP1(vaddvq_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2435 | NEONMAP1(vaddvq_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2436 | NEONMAP1(vcaged_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2437 | NEONMAP1(vcages_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2438 | NEONMAP1(vcagtd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2439 | NEONMAP1(vcagts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2440 | NEONMAP1(vcaled_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2441 | NEONMAP1(vcales_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2442 | NEONMAP1(vcaltd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2443 | NEONMAP1(vcalts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2444 | NEONMAP1(vcvtad_s64_f64, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 2445 | NEONMAP1(vcvtad_u64_f64, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 2446 | NEONMAP1(vcvtas_s32_f32, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 2447 | NEONMAP1(vcvtas_u32_f32, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 2448 | NEONMAP1(vcvtd_n_f64_s64, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 2449 | NEONMAP1(vcvtd_n_f64_u64, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 2450 | NEONMAP1(vcvtd_n_s64_f64, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 2451 | NEONMAP1(vcvtd_n_u64_f64, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 2452 | NEONMAP1(vcvtmd_s64_f64, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 2453 | NEONMAP1(vcvtmd_u64_f64, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 2454 | NEONMAP1(vcvtms_s32_f32, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 2455 | NEONMAP1(vcvtms_u32_f32, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 2456 | NEONMAP1(vcvtnd_s64_f64, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 2457 | NEONMAP1(vcvtnd_u64_f64, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 2458 | NEONMAP1(vcvtns_s32_f32, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 2459 | NEONMAP1(vcvtns_u32_f32, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 2460 | NEONMAP1(vcvtpd_s64_f64, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 2461 | NEONMAP1(vcvtpd_u64_f64, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 2462 | NEONMAP1(vcvtps_s32_f32, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 2463 | NEONMAP1(vcvtps_u32_f32, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 2464 | NEONMAP1(vcvts_n_f32_s32, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 2465 | NEONMAP1(vcvts_n_f32_u32, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 2466 | NEONMAP1(vcvts_n_s32_f32, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 2467 | NEONMAP1(vcvts_n_u32_f32, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 2468 | NEONMAP1(vcvtxd_f32_f64, aarch64_sisd_fcvtxn, 0), |
| 2469 | NEONMAP1(vmaxnmv_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2470 | NEONMAP1(vmaxnmvq_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2471 | NEONMAP1(vmaxnmvq_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2472 | NEONMAP1(vmaxv_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2473 | NEONMAP1(vmaxv_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 2474 | NEONMAP1(vmaxv_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 2475 | NEONMAP1(vmaxvq_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2476 | NEONMAP1(vmaxvq_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2477 | NEONMAP1(vmaxvq_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 2478 | NEONMAP1(vmaxvq_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 2479 | NEONMAP1(vminnmv_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2480 | NEONMAP1(vminnmvq_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2481 | NEONMAP1(vminnmvq_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2482 | NEONMAP1(vminv_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2483 | NEONMAP1(vminv_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 2484 | NEONMAP1(vminv_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 2485 | NEONMAP1(vminvq_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2486 | NEONMAP1(vminvq_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2487 | NEONMAP1(vminvq_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 2488 | NEONMAP1(vminvq_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 2489 | NEONMAP1(vmull_p64, aarch64_neon_pmull64, 0), |
| 2490 | NEONMAP1(vmulxd_f64, aarch64_neon_fmulx, Add1ArgType), |
| 2491 | NEONMAP1(vmulxs_f32, aarch64_neon_fmulx, Add1ArgType), |
| 2492 | NEONMAP1(vpaddd_s64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2493 | NEONMAP1(vpaddd_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2494 | NEONMAP1(vpmaxnmqd_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2495 | NEONMAP1(vpmaxnms_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2496 | NEONMAP1(vpmaxqd_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2497 | NEONMAP1(vpmaxs_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2498 | NEONMAP1(vpminnmqd_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2499 | NEONMAP1(vpminnms_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2500 | NEONMAP1(vpminqd_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2501 | NEONMAP1(vpmins_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2502 | NEONMAP1(vqabsb_s8, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 2503 | NEONMAP1(vqabsd_s64, aarch64_neon_sqabs, Add1ArgType), |
| 2504 | NEONMAP1(vqabsh_s16, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 2505 | NEONMAP1(vqabss_s32, aarch64_neon_sqabs, Add1ArgType), |
| 2506 | NEONMAP1(vqaddb_s8, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 2507 | NEONMAP1(vqaddb_u8, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 2508 | NEONMAP1(vqaddd_s64, aarch64_neon_sqadd, Add1ArgType), |
| 2509 | NEONMAP1(vqaddd_u64, aarch64_neon_uqadd, Add1ArgType), |
| 2510 | NEONMAP1(vqaddh_s16, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 2511 | NEONMAP1(vqaddh_u16, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 2512 | NEONMAP1(vqadds_s32, aarch64_neon_sqadd, Add1ArgType), |
| 2513 | NEONMAP1(vqadds_u32, aarch64_neon_uqadd, Add1ArgType), |
| 2514 | NEONMAP1(vqdmulhh_s16, aarch64_neon_sqdmulh, Vectorize1ArgType | Use64BitVectors), |
| 2515 | NEONMAP1(vqdmulhs_s32, aarch64_neon_sqdmulh, Add1ArgType), |
| 2516 | NEONMAP1(vqdmullh_s16, aarch64_neon_sqdmull, VectorRet | Use128BitVectors), |
| 2517 | NEONMAP1(vqdmulls_s32, aarch64_neon_sqdmulls_scalar, 0), |
| 2518 | NEONMAP1(vqmovnd_s64, aarch64_neon_scalar_sqxtn, AddRetType | Add1ArgType), |
| 2519 | NEONMAP1(vqmovnd_u64, aarch64_neon_scalar_uqxtn, AddRetType | Add1ArgType), |
| 2520 | NEONMAP1(vqmovnh_s16, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 2521 | NEONMAP1(vqmovnh_u16, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 2522 | NEONMAP1(vqmovns_s32, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 2523 | NEONMAP1(vqmovns_u32, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 2524 | NEONMAP1(vqmovund_s64, aarch64_neon_scalar_sqxtun, AddRetType | Add1ArgType), |
| 2525 | NEONMAP1(vqmovunh_s16, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 2526 | NEONMAP1(vqmovuns_s32, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 2527 | NEONMAP1(vqnegb_s8, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 2528 | NEONMAP1(vqnegd_s64, aarch64_neon_sqneg, Add1ArgType), |
| 2529 | NEONMAP1(vqnegh_s16, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 2530 | NEONMAP1(vqnegs_s32, aarch64_neon_sqneg, Add1ArgType), |
| 2531 | NEONMAP1(vqrdmulhh_s16, aarch64_neon_sqrdmulh, Vectorize1ArgType | Use64BitVectors), |
| 2532 | NEONMAP1(vqrdmulhs_s32, aarch64_neon_sqrdmulh, Add1ArgType), |
| 2533 | NEONMAP1(vqrshlb_s8, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2534 | NEONMAP1(vqrshlb_u8, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2535 | NEONMAP1(vqrshld_s64, aarch64_neon_sqrshl, Add1ArgType), |
| 2536 | NEONMAP1(vqrshld_u64, aarch64_neon_uqrshl, Add1ArgType), |
| 2537 | NEONMAP1(vqrshlh_s16, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2538 | NEONMAP1(vqrshlh_u16, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2539 | NEONMAP1(vqrshls_s32, aarch64_neon_sqrshl, Add1ArgType), |
| 2540 | NEONMAP1(vqrshls_u32, aarch64_neon_uqrshl, Add1ArgType), |
| 2541 | NEONMAP1(vqrshrnd_n_s64, aarch64_neon_sqrshrn, AddRetType), |
| 2542 | NEONMAP1(vqrshrnd_n_u64, aarch64_neon_uqrshrn, AddRetType), |
| 2543 | NEONMAP1(vqrshrnh_n_s16, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 2544 | NEONMAP1(vqrshrnh_n_u16, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 2545 | NEONMAP1(vqrshrns_n_s32, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 2546 | NEONMAP1(vqrshrns_n_u32, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 2547 | NEONMAP1(vqrshrund_n_s64, aarch64_neon_sqrshrun, AddRetType), |
| 2548 | NEONMAP1(vqrshrunh_n_s16, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 2549 | NEONMAP1(vqrshruns_n_s32, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 2550 | NEONMAP1(vqshlb_n_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2551 | NEONMAP1(vqshlb_n_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2552 | NEONMAP1(vqshlb_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2553 | NEONMAP1(vqshlb_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2554 | NEONMAP1(vqshld_s64, aarch64_neon_sqshl, Add1ArgType), |
| 2555 | NEONMAP1(vqshld_u64, aarch64_neon_uqshl, Add1ArgType), |
| 2556 | NEONMAP1(vqshlh_n_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2557 | NEONMAP1(vqshlh_n_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2558 | NEONMAP1(vqshlh_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2559 | NEONMAP1(vqshlh_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2560 | NEONMAP1(vqshls_n_s32, aarch64_neon_sqshl, Add1ArgType), |
| 2561 | NEONMAP1(vqshls_n_u32, aarch64_neon_uqshl, Add1ArgType), |
| 2562 | NEONMAP1(vqshls_s32, aarch64_neon_sqshl, Add1ArgType), |
| 2563 | NEONMAP1(vqshls_u32, aarch64_neon_uqshl, Add1ArgType), |
| 2564 | NEONMAP1(vqshlub_n_s8, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 2565 | NEONMAP1(vqshluh_n_s16, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 2566 | NEONMAP1(vqshlus_n_s32, aarch64_neon_sqshlu, Add1ArgType), |
| 2567 | NEONMAP1(vqshrnd_n_s64, aarch64_neon_sqshrn, AddRetType), |
| 2568 | NEONMAP1(vqshrnd_n_u64, aarch64_neon_uqshrn, AddRetType), |
| 2569 | NEONMAP1(vqshrnh_n_s16, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 2570 | NEONMAP1(vqshrnh_n_u16, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 2571 | NEONMAP1(vqshrns_n_s32, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 2572 | NEONMAP1(vqshrns_n_u32, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 2573 | NEONMAP1(vqshrund_n_s64, aarch64_neon_sqshrun, AddRetType), |
| 2574 | NEONMAP1(vqshrunh_n_s16, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 2575 | NEONMAP1(vqshruns_n_s32, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 2576 | NEONMAP1(vqsubb_s8, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 2577 | NEONMAP1(vqsubb_u8, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 2578 | NEONMAP1(vqsubd_s64, aarch64_neon_sqsub, Add1ArgType), |
| 2579 | NEONMAP1(vqsubd_u64, aarch64_neon_uqsub, Add1ArgType), |
| 2580 | NEONMAP1(vqsubh_s16, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 2581 | NEONMAP1(vqsubh_u16, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 2582 | NEONMAP1(vqsubs_s32, aarch64_neon_sqsub, Add1ArgType), |
| 2583 | NEONMAP1(vqsubs_u32, aarch64_neon_uqsub, Add1ArgType), |
| 2584 | NEONMAP1(vrecped_f64, aarch64_neon_frecpe, Add1ArgType), |
| 2585 | NEONMAP1(vrecpes_f32, aarch64_neon_frecpe, Add1ArgType), |
| 2586 | NEONMAP1(vrecpxd_f64, aarch64_neon_frecpx, Add1ArgType), |
| 2587 | NEONMAP1(vrecpxs_f32, aarch64_neon_frecpx, Add1ArgType), |
| 2588 | NEONMAP1(vrshld_s64, aarch64_neon_srshl, Add1ArgType), |
| 2589 | NEONMAP1(vrshld_u64, aarch64_neon_urshl, Add1ArgType), |
| 2590 | NEONMAP1(vrsqrted_f64, aarch64_neon_frsqrte, Add1ArgType), |
| 2591 | NEONMAP1(vrsqrtes_f32, aarch64_neon_frsqrte, Add1ArgType), |
| 2592 | NEONMAP1(vrsqrtsd_f64, aarch64_neon_frsqrts, Add1ArgType), |
| 2593 | NEONMAP1(vrsqrtss_f32, aarch64_neon_frsqrts, Add1ArgType), |
| 2594 | NEONMAP1(vsha1cq_u32, aarch64_crypto_sha1c, 0), |
| 2595 | NEONMAP1(vsha1h_u32, aarch64_crypto_sha1h, 0), |
| 2596 | NEONMAP1(vsha1mq_u32, aarch64_crypto_sha1m, 0), |
| 2597 | NEONMAP1(vsha1pq_u32, aarch64_crypto_sha1p, 0), |
| 2598 | NEONMAP1(vshld_s64, aarch64_neon_sshl, Add1ArgType), |
| 2599 | NEONMAP1(vshld_u64, aarch64_neon_ushl, Add1ArgType), |
| 2600 | NEONMAP1(vslid_n_s64, aarch64_neon_vsli, Vectorize1ArgType), |
| 2601 | NEONMAP1(vslid_n_u64, aarch64_neon_vsli, Vectorize1ArgType), |
| 2602 | NEONMAP1(vsqaddb_u8, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 2603 | NEONMAP1(vsqaddd_u64, aarch64_neon_usqadd, Add1ArgType), |
| 2604 | NEONMAP1(vsqaddh_u16, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 2605 | NEONMAP1(vsqadds_u32, aarch64_neon_usqadd, Add1ArgType), |
| 2606 | NEONMAP1(vsrid_n_s64, aarch64_neon_vsri, Vectorize1ArgType), |
| 2607 | NEONMAP1(vsrid_n_u64, aarch64_neon_vsri, Vectorize1ArgType), |
| 2608 | NEONMAP1(vuqaddb_s8, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 2609 | NEONMAP1(vuqaddd_s64, aarch64_neon_suqadd, Add1ArgType), |
| 2610 | NEONMAP1(vuqaddh_s16, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 2611 | NEONMAP1(vuqadds_s32, aarch64_neon_suqadd, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2612 | }; |
| 2613 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2614 | #undef NEONMAP0 |
| 2615 | #undef NEONMAP1 |
| 2616 | #undef NEONMAP2 |
| 2617 | |
| 2618 | static bool NEONSIMDIntrinsicsProvenSorted = false; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2619 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2620 | static bool AArch64SIMDIntrinsicsProvenSorted = false; |
| 2621 | static bool AArch64SISDIntrinsicsProvenSorted = false; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2622 | |
| 2623 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2624 | static const NeonIntrinsicInfo * |
Craig Topper | 00bbdcf | 2014-06-28 23:22:23 +0000 | [diff] [blame] | 2625 | findNeonIntrinsicInMap(ArrayRef<NeonIntrinsicInfo> IntrinsicMap, |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2626 | unsigned BuiltinID, bool &MapProvenSorted) { |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2627 | |
| 2628 | #ifndef NDEBUG |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2629 | if (!MapProvenSorted) { |
| 2630 | // FIXME: use std::is_sorted once C++11 is allowed |
| 2631 | for (unsigned i = 0; i < IntrinsicMap.size() - 1; ++i) |
| 2632 | assert(IntrinsicMap[i].BuiltinID <= IntrinsicMap[i + 1].BuiltinID); |
| 2633 | MapProvenSorted = true; |
| 2634 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2635 | #endif |
| 2636 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2637 | const NeonIntrinsicInfo *Builtin = |
| 2638 | std::lower_bound(IntrinsicMap.begin(), IntrinsicMap.end(), BuiltinID); |
| 2639 | |
| 2640 | if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID) |
| 2641 | return Builtin; |
| 2642 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2643 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | Function *CodeGenFunction::LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
| 2647 | unsigned Modifier, |
| 2648 | llvm::Type *ArgType, |
| 2649 | const CallExpr *E) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2650 | int VectorSize = 0; |
| 2651 | if (Modifier & Use64BitVectors) |
| 2652 | VectorSize = 64; |
| 2653 | else if (Modifier & Use128BitVectors) |
| 2654 | VectorSize = 128; |
| 2655 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2656 | // Return type. |
| 2657 | SmallVector<llvm::Type *, 3> Tys; |
| 2658 | if (Modifier & AddRetType) { |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 2659 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2660 | if (Modifier & VectorizeRetType) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2661 | Ty = llvm::VectorType::get( |
| 2662 | Ty, VectorSize ? VectorSize / Ty->getPrimitiveSizeInBits() : 1); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2663 | |
| 2664 | Tys.push_back(Ty); |
| 2665 | } |
| 2666 | |
| 2667 | // Arguments. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2668 | if (Modifier & VectorizeArgTypes) { |
| 2669 | int Elts = VectorSize ? VectorSize / ArgType->getPrimitiveSizeInBits() : 1; |
| 2670 | ArgType = llvm::VectorType::get(ArgType, Elts); |
| 2671 | } |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2672 | |
| 2673 | if (Modifier & (Add1ArgType | Add2ArgTypes)) |
| 2674 | Tys.push_back(ArgType); |
| 2675 | |
| 2676 | if (Modifier & Add2ArgTypes) |
| 2677 | Tys.push_back(ArgType); |
| 2678 | |
| 2679 | if (Modifier & InventFloatType) |
| 2680 | Tys.push_back(FloatTy); |
| 2681 | |
| 2682 | return CGM.getIntrinsic(IntrinsicID, Tys); |
| 2683 | } |
| 2684 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2685 | static Value *EmitCommonNeonSISDBuiltinExpr(CodeGenFunction &CGF, |
| 2686 | const NeonIntrinsicInfo &SISDInfo, |
| 2687 | SmallVectorImpl<Value *> &Ops, |
| 2688 | const CallExpr *E) { |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 2689 | unsigned BuiltinID = SISDInfo.BuiltinID; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2690 | unsigned int Int = SISDInfo.LLVMIntrinsic; |
| 2691 | unsigned Modifier = SISDInfo.TypeModifier; |
| 2692 | const char *s = SISDInfo.NameHint; |
| 2693 | |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 2694 | switch (BuiltinID) { |
| 2695 | case NEON::BI__builtin_neon_vcled_s64: |
| 2696 | case NEON::BI__builtin_neon_vcled_u64: |
| 2697 | case NEON::BI__builtin_neon_vcles_f32: |
| 2698 | case NEON::BI__builtin_neon_vcled_f64: |
| 2699 | case NEON::BI__builtin_neon_vcltd_s64: |
| 2700 | case NEON::BI__builtin_neon_vcltd_u64: |
| 2701 | case NEON::BI__builtin_neon_vclts_f32: |
| 2702 | case NEON::BI__builtin_neon_vcltd_f64: |
| 2703 | case NEON::BI__builtin_neon_vcales_f32: |
| 2704 | case NEON::BI__builtin_neon_vcaled_f64: |
| 2705 | case NEON::BI__builtin_neon_vcalts_f32: |
| 2706 | case NEON::BI__builtin_neon_vcaltd_f64: |
| 2707 | // Only one direction of comparisons actually exist, cmle is actually a cmge |
| 2708 | // with swapped operands. The table gives us the right intrinsic but we |
| 2709 | // still need to do the swap. |
| 2710 | std::swap(Ops[0], Ops[1]); |
| 2711 | break; |
| 2712 | } |
| 2713 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2714 | assert(Int && "Generic code assumes a valid intrinsic"); |
| 2715 | |
| 2716 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 2717 | const Expr *Arg = E->getArg(0); |
| 2718 | llvm::Type *ArgTy = CGF.ConvertType(Arg->getType()); |
| 2719 | Function *F = CGF.LookupNeonLLVMIntrinsic(Int, Modifier, ArgTy, E); |
| 2720 | |
| 2721 | int j = 0; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 2722 | ConstantInt *C0 = ConstantInt::get(CGF.SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2723 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 2724 | ai != ae; ++ai, ++j) { |
| 2725 | llvm::Type *ArgTy = ai->getType(); |
| 2726 | if (Ops[j]->getType()->getPrimitiveSizeInBits() == |
| 2727 | ArgTy->getPrimitiveSizeInBits()) |
| 2728 | continue; |
| 2729 | |
| 2730 | assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy()); |
| 2731 | // The constant argument to an _n_ intrinsic always has Int32Ty, so truncate |
| 2732 | // it before inserting. |
| 2733 | Ops[j] = |
| 2734 | CGF.Builder.CreateTruncOrBitCast(Ops[j], ArgTy->getVectorElementType()); |
| 2735 | Ops[j] = |
| 2736 | CGF.Builder.CreateInsertElement(UndefValue::get(ArgTy), Ops[j], C0); |
| 2737 | } |
| 2738 | |
| 2739 | Value *Result = CGF.EmitNeonCall(F, Ops, s); |
| 2740 | llvm::Type *ResultType = CGF.ConvertType(E->getType()); |
| 2741 | if (ResultType->getPrimitiveSizeInBits() < |
| 2742 | Result->getType()->getPrimitiveSizeInBits()) |
| 2743 | return CGF.Builder.CreateExtractElement(Result, C0); |
| 2744 | |
| 2745 | return CGF.Builder.CreateBitCast(Result, ResultType, s); |
| 2746 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2747 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2748 | Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( |
| 2749 | unsigned BuiltinID, unsigned LLVMIntrinsic, unsigned AltLLVMIntrinsic, |
| 2750 | const char *NameHint, unsigned Modifier, const CallExpr *E, |
| 2751 | SmallVectorImpl<llvm::Value *> &Ops, llvm::Value *Align) { |
| 2752 | // Get the last argument, which specifies the vector type. |
| 2753 | llvm::APSInt NeonTypeConst; |
| 2754 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 2755 | if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2756 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2757 | |
| 2758 | // Determine the type of this overloaded NEON intrinsic. |
| 2759 | NeonTypeFlags Type(NeonTypeConst.getZExtValue()); |
| 2760 | bool Usgn = Type.isUnsigned(); |
| 2761 | bool Quad = Type.isQuad(); |
| 2762 | |
| 2763 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 2764 | llvm::Type *Ty = VTy; |
| 2765 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2766 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2767 | |
| 2768 | unsigned Int = LLVMIntrinsic; |
| 2769 | if ((Modifier & UnsignedAlts) && !Usgn) |
| 2770 | Int = AltLLVMIntrinsic; |
| 2771 | |
| 2772 | switch (BuiltinID) { |
| 2773 | default: break; |
| 2774 | case NEON::BI__builtin_neon_vabs_v: |
| 2775 | case NEON::BI__builtin_neon_vabsq_v: |
| 2776 | if (VTy->getElementType()->isFloatingPointTy()) |
| 2777 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::fabs, Ty), Ops, "vabs"); |
| 2778 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), Ops, "vabs"); |
| 2779 | case NEON::BI__builtin_neon_vaddhn_v: { |
| 2780 | llvm::VectorType *SrcTy = |
| 2781 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 2782 | |
| 2783 | // %sum = add <4 x i32> %lhs, %rhs |
| 2784 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 2785 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 2786 | Ops[0] = Builder.CreateAdd(Ops[0], Ops[1], "vaddhn"); |
| 2787 | |
| 2788 | // %high = lshr <4 x i32> %sum, <i32 16, i32 16, i32 16, i32 16> |
| 2789 | Constant *ShiftAmt = ConstantInt::get(SrcTy->getElementType(), |
| 2790 | SrcTy->getScalarSizeInBits() / 2); |
| 2791 | ShiftAmt = ConstantVector::getSplat(VTy->getNumElements(), ShiftAmt); |
| 2792 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vaddhn"); |
| 2793 | |
| 2794 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 2795 | return Builder.CreateTrunc(Ops[0], VTy, "vaddhn"); |
| 2796 | } |
| 2797 | case NEON::BI__builtin_neon_vcale_v: |
| 2798 | case NEON::BI__builtin_neon_vcaleq_v: |
| 2799 | case NEON::BI__builtin_neon_vcalt_v: |
| 2800 | case NEON::BI__builtin_neon_vcaltq_v: |
| 2801 | std::swap(Ops[0], Ops[1]); |
| 2802 | case NEON::BI__builtin_neon_vcage_v: |
| 2803 | case NEON::BI__builtin_neon_vcageq_v: |
| 2804 | case NEON::BI__builtin_neon_vcagt_v: |
| 2805 | case NEON::BI__builtin_neon_vcagtq_v: { |
| 2806 | llvm::Type *VecFlt = llvm::VectorType::get( |
| 2807 | VTy->getScalarSizeInBits() == 32 ? FloatTy : DoubleTy, |
| 2808 | VTy->getNumElements()); |
| 2809 | llvm::Type *Tys[] = { VTy, VecFlt }; |
| 2810 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 2811 | return EmitNeonCall(F, Ops, NameHint); |
| 2812 | } |
| 2813 | case NEON::BI__builtin_neon_vclz_v: |
| 2814 | case NEON::BI__builtin_neon_vclzq_v: |
| 2815 | // We generate target-independent intrinsic, which needs a second argument |
| 2816 | // for whether or not clz of zero is undefined; on ARM it isn't. |
| 2817 | Ops.push_back(Builder.getInt1(getTarget().isCLZForZeroUndef())); |
| 2818 | break; |
| 2819 | case NEON::BI__builtin_neon_vcvt_f32_v: |
| 2820 | case NEON::BI__builtin_neon_vcvtq_f32_v: |
| 2821 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 2822 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float32, false, Quad)); |
| 2823 | return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 2824 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 2825 | case NEON::BI__builtin_neon_vcvt_n_f32_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2826 | case NEON::BI__builtin_neon_vcvt_n_f64_v: |
| 2827 | case NEON::BI__builtin_neon_vcvtq_n_f32_v: |
| 2828 | case NEON::BI__builtin_neon_vcvtq_n_f64_v: { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2829 | bool Double = |
| 2830 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 2831 | llvm::Type *FloatTy = |
| 2832 | GetNeonType(this, NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 2833 | : NeonTypeFlags::Float32, |
| 2834 | false, Quad)); |
| 2835 | llvm::Type *Tys[2] = { FloatTy, Ty }; |
| 2836 | Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 2837 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 2838 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 2839 | } |
| 2840 | case NEON::BI__builtin_neon_vcvt_n_s32_v: |
| 2841 | case NEON::BI__builtin_neon_vcvt_n_u32_v: |
| 2842 | case NEON::BI__builtin_neon_vcvt_n_s64_v: |
| 2843 | case NEON::BI__builtin_neon_vcvt_n_u64_v: |
| 2844 | case NEON::BI__builtin_neon_vcvtq_n_s32_v: |
| 2845 | case NEON::BI__builtin_neon_vcvtq_n_u32_v: |
| 2846 | case NEON::BI__builtin_neon_vcvtq_n_s64_v: |
| 2847 | case NEON::BI__builtin_neon_vcvtq_n_u64_v: { |
| 2848 | bool Double = |
| 2849 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 2850 | llvm::Type *FloatTy = |
| 2851 | GetNeonType(this, NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 2852 | : NeonTypeFlags::Float32, |
| 2853 | false, Quad)); |
| 2854 | llvm::Type *Tys[2] = { Ty, FloatTy }; |
| 2855 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 2856 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 2857 | } |
| 2858 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 2859 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 2860 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 2861 | case NEON::BI__builtin_neon_vcvt_u64_v: |
| 2862 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 2863 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 2864 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
| 2865 | case NEON::BI__builtin_neon_vcvtq_u64_v: { |
| 2866 | bool Double = |
| 2867 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 2868 | llvm::Type *FloatTy = |
| 2869 | GetNeonType(this, NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 2870 | : NeonTypeFlags::Float32, |
| 2871 | false, Quad)); |
| 2872 | Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy); |
| 2873 | return Usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt") |
| 2874 | : Builder.CreateFPToSI(Ops[0], Ty, "vcvt"); |
| 2875 | } |
| 2876 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 2877 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 2878 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 2879 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 2880 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 2881 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 2882 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 2883 | case NEON::BI__builtin_neon_vcvtaq_u64_v: |
| 2884 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 2885 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 2886 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 2887 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 2888 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 2889 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 2890 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 2891 | case NEON::BI__builtin_neon_vcvtnq_u64_v: |
| 2892 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 2893 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 2894 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 2895 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 2896 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 2897 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 2898 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 2899 | case NEON::BI__builtin_neon_vcvtpq_u64_v: |
| 2900 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 2901 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 2902 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 2903 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 2904 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 2905 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 2906 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 2907 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
| 2908 | bool Double = |
| 2909 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 2910 | llvm::Type *InTy = |
| 2911 | GetNeonType(this, |
| 2912 | NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 2913 | : NeonTypeFlags::Float32, false, Quad)); |
| 2914 | llvm::Type *Tys[2] = { Ty, InTy }; |
| 2915 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, NameHint); |
| 2916 | } |
| 2917 | case NEON::BI__builtin_neon_vext_v: |
| 2918 | case NEON::BI__builtin_neon_vextq_v: { |
| 2919 | int CV = cast<ConstantInt>(Ops[2])->getSExtValue(); |
| 2920 | SmallVector<Constant*, 16> Indices; |
| 2921 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
| 2922 | Indices.push_back(ConstantInt::get(Int32Ty, i+CV)); |
| 2923 | |
| 2924 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 2925 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 2926 | Value *SV = llvm::ConstantVector::get(Indices); |
| 2927 | return Builder.CreateShuffleVector(Ops[0], Ops[1], SV, "vext"); |
| 2928 | } |
| 2929 | case NEON::BI__builtin_neon_vfma_v: |
| 2930 | case NEON::BI__builtin_neon_vfmaq_v: { |
| 2931 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 2932 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 2933 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 2934 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 2935 | |
| 2936 | // NEON intrinsic puts accumulator first, unlike the LLVM fma. |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 2937 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2938 | } |
| 2939 | case NEON::BI__builtin_neon_vld1_v: |
| 2940 | case NEON::BI__builtin_neon_vld1q_v: |
| 2941 | Ops.push_back(Align); |
| 2942 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), Ops, "vld1"); |
| 2943 | case NEON::BI__builtin_neon_vld2_v: |
| 2944 | case NEON::BI__builtin_neon_vld2q_v: |
| 2945 | case NEON::BI__builtin_neon_vld3_v: |
| 2946 | case NEON::BI__builtin_neon_vld3q_v: |
| 2947 | case NEON::BI__builtin_neon_vld4_v: |
| 2948 | case NEON::BI__builtin_neon_vld4q_v: { |
| 2949 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Ty); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 2950 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2951 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 2952 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 2953 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 2954 | } |
| 2955 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 2956 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 2957 | Value *V = UndefValue::get(Ty); |
| 2958 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 2959 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 2960 | LoadInst *Ld = Builder.CreateLoad(Ops[0]); |
| 2961 | Ld->setAlignment(cast<ConstantInt>(Align)->getZExtValue()); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 2962 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2963 | Ops[0] = Builder.CreateInsertElement(V, Ld, CI); |
| 2964 | return EmitNeonSplat(Ops[0], CI); |
| 2965 | } |
| 2966 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 2967 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 2968 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 2969 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 2970 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 2971 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
| 2972 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Ty); |
| 2973 | for (unsigned I = 2; I < Ops.size() - 1; ++I) |
| 2974 | Ops[I] = Builder.CreateBitCast(Ops[I], Ty); |
| 2975 | Ops.push_back(Align); |
| 2976 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), NameHint); |
| 2977 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 2978 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 2979 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 2980 | } |
| 2981 | case NEON::BI__builtin_neon_vmovl_v: { |
| 2982 | llvm::Type *DTy =llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 2983 | Ops[0] = Builder.CreateBitCast(Ops[0], DTy); |
| 2984 | if (Usgn) |
| 2985 | return Builder.CreateZExt(Ops[0], Ty, "vmovl"); |
| 2986 | return Builder.CreateSExt(Ops[0], Ty, "vmovl"); |
| 2987 | } |
| 2988 | case NEON::BI__builtin_neon_vmovn_v: { |
| 2989 | llvm::Type *QTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 2990 | Ops[0] = Builder.CreateBitCast(Ops[0], QTy); |
| 2991 | return Builder.CreateTrunc(Ops[0], Ty, "vmovn"); |
| 2992 | } |
| 2993 | case NEON::BI__builtin_neon_vmull_v: |
| 2994 | // FIXME: the integer vmull operations could be emitted in terms of pure |
| 2995 | // LLVM IR (2 exts followed by a mul). Unfortunately LLVM has a habit of |
| 2996 | // hoisting the exts outside loops. Until global ISel comes along that can |
| 2997 | // see through such movement this leads to bad CodeGen. So we need an |
| 2998 | // intrinsic for now. |
| 2999 | Int = Usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls; |
| 3000 | Int = Type.isPoly() ? (unsigned)Intrinsic::arm_neon_vmullp : Int; |
| 3001 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 3002 | case NEON::BI__builtin_neon_vpadal_v: |
| 3003 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 3004 | // The source operand type has twice as many elements of half the size. |
| 3005 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 3006 | llvm::Type *EltTy = |
| 3007 | llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 3008 | llvm::Type *NarrowTy = |
| 3009 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 3010 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 3011 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, NameHint); |
| 3012 | } |
| 3013 | case NEON::BI__builtin_neon_vpaddl_v: |
| 3014 | case NEON::BI__builtin_neon_vpaddlq_v: { |
| 3015 | // The source operand type has twice as many elements of half the size. |
| 3016 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 3017 | llvm::Type *EltTy = llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 3018 | llvm::Type *NarrowTy = |
| 3019 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 3020 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 3021 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vpaddl"); |
| 3022 | } |
| 3023 | case NEON::BI__builtin_neon_vqdmlal_v: |
| 3024 | case NEON::BI__builtin_neon_vqdmlsl_v: { |
| 3025 | SmallVector<Value *, 2> MulOps(Ops.begin() + 1, Ops.end()); |
| 3026 | Value *Mul = EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), |
| 3027 | MulOps, "vqdmlal"); |
| 3028 | |
| 3029 | SmallVector<Value *, 2> AccumOps; |
| 3030 | AccumOps.push_back(Ops[0]); |
| 3031 | AccumOps.push_back(Mul); |
| 3032 | return EmitNeonCall(CGM.getIntrinsic(AltLLVMIntrinsic, Ty), |
| 3033 | AccumOps, NameHint); |
| 3034 | } |
| 3035 | case NEON::BI__builtin_neon_vqshl_n_v: |
| 3036 | case NEON::BI__builtin_neon_vqshlq_n_v: |
| 3037 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshl_n", |
| 3038 | 1, false); |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3039 | case NEON::BI__builtin_neon_vqshlu_n_v: |
| 3040 | case NEON::BI__builtin_neon_vqshluq_n_v: |
| 3041 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshlu_n", |
| 3042 | 1, false); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3043 | case NEON::BI__builtin_neon_vrecpe_v: |
| 3044 | case NEON::BI__builtin_neon_vrecpeq_v: |
| 3045 | case NEON::BI__builtin_neon_vrsqrte_v: |
| 3046 | case NEON::BI__builtin_neon_vrsqrteq_v: |
| 3047 | Int = Ty->isFPOrFPVectorTy() ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 3048 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, NameHint); |
| 3049 | |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3050 | case NEON::BI__builtin_neon_vrshr_n_v: |
| 3051 | case NEON::BI__builtin_neon_vrshrq_n_v: |
| 3052 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshr_n", |
| 3053 | 1, true); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3054 | case NEON::BI__builtin_neon_vshl_n_v: |
| 3055 | case NEON::BI__builtin_neon_vshlq_n_v: |
| 3056 | Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false); |
| 3057 | return Builder.CreateShl(Builder.CreateBitCast(Ops[0],Ty), Ops[1], |
| 3058 | "vshl_n"); |
| 3059 | case NEON::BI__builtin_neon_vshll_n_v: { |
| 3060 | llvm::Type *SrcTy = llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 3061 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3062 | if (Usgn) |
| 3063 | Ops[0] = Builder.CreateZExt(Ops[0], VTy); |
| 3064 | else |
| 3065 | Ops[0] = Builder.CreateSExt(Ops[0], VTy); |
| 3066 | Ops[1] = EmitNeonShiftVector(Ops[1], VTy, false); |
| 3067 | return Builder.CreateShl(Ops[0], Ops[1], "vshll_n"); |
| 3068 | } |
| 3069 | case NEON::BI__builtin_neon_vshrn_n_v: { |
| 3070 | llvm::Type *SrcTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3071 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3072 | Ops[1] = EmitNeonShiftVector(Ops[1], SrcTy, false); |
| 3073 | if (Usgn) |
| 3074 | Ops[0] = Builder.CreateLShr(Ops[0], Ops[1]); |
| 3075 | else |
| 3076 | Ops[0] = Builder.CreateAShr(Ops[0], Ops[1]); |
| 3077 | return Builder.CreateTrunc(Ops[0], Ty, "vshrn_n"); |
| 3078 | } |
| 3079 | case NEON::BI__builtin_neon_vshr_n_v: |
| 3080 | case NEON::BI__builtin_neon_vshrq_n_v: |
| 3081 | return EmitNeonRShiftImm(Ops[0], Ops[1], Ty, Usgn, "vshr_n"); |
| 3082 | case NEON::BI__builtin_neon_vst1_v: |
| 3083 | case NEON::BI__builtin_neon_vst1q_v: |
| 3084 | case NEON::BI__builtin_neon_vst2_v: |
| 3085 | case NEON::BI__builtin_neon_vst2q_v: |
| 3086 | case NEON::BI__builtin_neon_vst3_v: |
| 3087 | case NEON::BI__builtin_neon_vst3q_v: |
| 3088 | case NEON::BI__builtin_neon_vst4_v: |
| 3089 | case NEON::BI__builtin_neon_vst4q_v: |
| 3090 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 3091 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 3092 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 3093 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 3094 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 3095 | case NEON::BI__builtin_neon_vst4q_lane_v: |
| 3096 | Ops.push_back(Align); |
| 3097 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, ""); |
| 3098 | case NEON::BI__builtin_neon_vsubhn_v: { |
| 3099 | llvm::VectorType *SrcTy = |
| 3100 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3101 | |
| 3102 | // %sum = add <4 x i32> %lhs, %rhs |
| 3103 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3104 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 3105 | Ops[0] = Builder.CreateSub(Ops[0], Ops[1], "vsubhn"); |
| 3106 | |
| 3107 | // %high = lshr <4 x i32> %sum, <i32 16, i32 16, i32 16, i32 16> |
| 3108 | Constant *ShiftAmt = ConstantInt::get(SrcTy->getElementType(), |
| 3109 | SrcTy->getScalarSizeInBits() / 2); |
| 3110 | ShiftAmt = ConstantVector::getSplat(VTy->getNumElements(), ShiftAmt); |
| 3111 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vsubhn"); |
| 3112 | |
| 3113 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 3114 | return Builder.CreateTrunc(Ops[0], VTy, "vsubhn"); |
| 3115 | } |
| 3116 | case NEON::BI__builtin_neon_vtrn_v: |
| 3117 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 3118 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3119 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3120 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3121 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3122 | |
| 3123 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 3124 | SmallVector<Constant*, 16> Indices; |
| 3125 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 3126 | Indices.push_back(Builder.getInt32(i+vi)); |
| 3127 | Indices.push_back(Builder.getInt32(i+e+vi)); |
| 3128 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3129 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3130 | SV = llvm::ConstantVector::get(Indices); |
| 3131 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vtrn"); |
| 3132 | SV = Builder.CreateStore(SV, Addr); |
| 3133 | } |
| 3134 | return SV; |
| 3135 | } |
| 3136 | case NEON::BI__builtin_neon_vtst_v: |
| 3137 | case NEON::BI__builtin_neon_vtstq_v: { |
| 3138 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3139 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3140 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 3141 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
| 3142 | ConstantAggregateZero::get(Ty)); |
| 3143 | return Builder.CreateSExt(Ops[0], Ty, "vtst"); |
| 3144 | } |
| 3145 | case NEON::BI__builtin_neon_vuzp_v: |
| 3146 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 3147 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3148 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3149 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3150 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3151 | |
| 3152 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 3153 | SmallVector<Constant*, 16> Indices; |
| 3154 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
| 3155 | Indices.push_back(ConstantInt::get(Int32Ty, 2*i+vi)); |
| 3156 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3157 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3158 | SV = llvm::ConstantVector::get(Indices); |
| 3159 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vuzp"); |
| 3160 | SV = Builder.CreateStore(SV, Addr); |
| 3161 | } |
| 3162 | return SV; |
| 3163 | } |
| 3164 | case NEON::BI__builtin_neon_vzip_v: |
| 3165 | case NEON::BI__builtin_neon_vzipq_v: { |
| 3166 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3167 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3168 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3169 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3170 | |
| 3171 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 3172 | SmallVector<Constant*, 16> Indices; |
| 3173 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 3174 | Indices.push_back(ConstantInt::get(Int32Ty, (i + vi*e) >> 1)); |
| 3175 | Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e)); |
| 3176 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3177 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3178 | SV = llvm::ConstantVector::get(Indices); |
| 3179 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); |
| 3180 | SV = Builder.CreateStore(SV, Addr); |
| 3181 | } |
| 3182 | return SV; |
| 3183 | } |
| 3184 | } |
| 3185 | |
| 3186 | assert(Int && "Expected valid intrinsic number"); |
| 3187 | |
| 3188 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 3189 | Function *F = LookupNeonLLVMIntrinsic(Int, Modifier, Ty, E); |
| 3190 | |
| 3191 | Value *Result = EmitNeonCall(F, Ops, NameHint); |
| 3192 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 3193 | // AArch64 intrinsic one-element vector type cast to |
| 3194 | // scalar type expected by the builtin |
| 3195 | return Builder.CreateBitCast(Result, ResultType, NameHint); |
| 3196 | } |
| 3197 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3198 | Value *CodeGenFunction::EmitAArch64CompareBuiltinExpr( |
| 3199 | Value *Op, llvm::Type *Ty, const CmpInst::Predicate Fp, |
| 3200 | const CmpInst::Predicate Ip, const Twine &Name) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3201 | llvm::Type *OTy = Op->getType(); |
| 3202 | |
| 3203 | // FIXME: this is utterly horrific. We should not be looking at previous |
| 3204 | // codegen context to find out what needs doing. Unfortunately TableGen |
| 3205 | // currently gives us exactly the same calls for vceqz_f32 and vceqz_s32 |
| 3206 | // (etc). |
| 3207 | if (BitCastInst *BI = dyn_cast<BitCastInst>(Op)) |
| 3208 | OTy = BI->getOperand(0)->getType(); |
| 3209 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3210 | Op = Builder.CreateBitCast(Op, OTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3211 | if (OTy->getScalarType()->isFloatingPointTy()) { |
| 3212 | Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3213 | } else { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3214 | Op = Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3215 | } |
Hao Liu | f96fd37 | 2013-12-23 02:44:00 +0000 | [diff] [blame] | 3216 | return Builder.CreateSExt(Op, Ty, Name); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3219 | static Value *packTBLDVectorList(CodeGenFunction &CGF, ArrayRef<Value *> Ops, |
| 3220 | Value *ExtOp, Value *IndexOp, |
| 3221 | llvm::Type *ResTy, unsigned IntID, |
| 3222 | const char *Name) { |
| 3223 | SmallVector<Value *, 2> TblOps; |
| 3224 | if (ExtOp) |
| 3225 | TblOps.push_back(ExtOp); |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3226 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3227 | // Build a vector containing sequential number like (0, 1, 2, ..., 15) |
| 3228 | SmallVector<Constant*, 16> Indices; |
| 3229 | llvm::VectorType *TblTy = cast<llvm::VectorType>(Ops[0]->getType()); |
| 3230 | for (unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) { |
| 3231 | Indices.push_back(ConstantInt::get(CGF.Int32Ty, 2*i)); |
| 3232 | Indices.push_back(ConstantInt::get(CGF.Int32Ty, 2*i+1)); |
| 3233 | } |
| 3234 | Value *SV = llvm::ConstantVector::get(Indices); |
| 3235 | |
| 3236 | int PairPos = 0, End = Ops.size() - 1; |
| 3237 | while (PairPos < End) { |
| 3238 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
| 3239 | Ops[PairPos+1], SV, Name)); |
| 3240 | PairPos += 2; |
| 3241 | } |
| 3242 | |
| 3243 | // If there's an odd number of 64-bit lookup table, fill the high 64-bit |
| 3244 | // of the 128-bit lookup table with zero. |
| 3245 | if (PairPos == End) { |
| 3246 | Value *ZeroTbl = ConstantAggregateZero::get(TblTy); |
| 3247 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
| 3248 | ZeroTbl, SV, Name)); |
| 3249 | } |
| 3250 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3251 | Function *TblF; |
| 3252 | TblOps.push_back(IndexOp); |
Tim Northover | b44e080 | 2014-02-26 11:55:15 +0000 | [diff] [blame] | 3253 | TblF = CGF.CGM.getIntrinsic(IntID, ResTy); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3254 | |
| 3255 | return CGF.EmitNeonCall(TblF, TblOps, Name); |
| 3256 | } |
| 3257 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3258 | Value *CodeGenFunction::GetValueForARMHint(unsigned BuiltinID) { |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3259 | switch (BuiltinID) { |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3260 | default: |
| 3261 | return nullptr; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 3262 | case ARM::BI__builtin_arm_nop: |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3263 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3264 | llvm::ConstantInt::get(Int32Ty, 0)); |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3265 | case ARM::BI__builtin_arm_yield: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3266 | case ARM::BI__yield: |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3267 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3268 | llvm::ConstantInt::get(Int32Ty, 1)); |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3269 | case ARM::BI__builtin_arm_wfe: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3270 | case ARM::BI__wfe: |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3271 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3272 | llvm::ConstantInt::get(Int32Ty, 2)); |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3273 | case ARM::BI__builtin_arm_wfi: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3274 | case ARM::BI__wfi: |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3275 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3276 | llvm::ConstantInt::get(Int32Ty, 3)); |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3277 | case ARM::BI__builtin_arm_sev: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3278 | case ARM::BI__sev: |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3279 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3280 | llvm::ConstantInt::get(Int32Ty, 4)); |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3281 | case ARM::BI__builtin_arm_sevl: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3282 | case ARM::BI__sevl: |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3283 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3284 | llvm::ConstantInt::get(Int32Ty, 5)); |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 3285 | } |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3286 | } |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 3287 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 3288 | // Generates the IR for the read/write special register builtin, |
| 3289 | // ValueType is the type of the value that is to be written or read, |
| 3290 | // RegisterType is the type of the register being written to or read from. |
| 3291 | static Value *EmitSpecialRegisterBuiltin(CodeGenFunction &CGF, |
| 3292 | const CallExpr *E, |
| 3293 | llvm::Type *RegisterType, |
| 3294 | llvm::Type *ValueType, bool IsRead) { |
| 3295 | // write and register intrinsics only support 32 and 64 bit operations. |
| 3296 | assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64)) |
| 3297 | && "Unsupported size for register."); |
| 3298 | |
| 3299 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 3300 | CodeGen::CodeGenModule &CGM = CGF.CGM; |
| 3301 | LLVMContext &Context = CGM.getLLVMContext(); |
| 3302 | |
| 3303 | const Expr *SysRegStrExpr = E->getArg(0)->IgnoreParenCasts(); |
| 3304 | StringRef SysReg = cast<StringLiteral>(SysRegStrExpr)->getString(); |
| 3305 | |
| 3306 | llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) }; |
| 3307 | llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops); |
| 3308 | llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName); |
| 3309 | |
| 3310 | llvm::Type *Types[] = { RegisterType }; |
| 3311 | |
| 3312 | bool MixedTypes = RegisterType->isIntegerTy(64) && ValueType->isIntegerTy(32); |
| 3313 | assert(!(RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64)) |
| 3314 | && "Can't fit 64-bit value in 32-bit register"); |
| 3315 | |
| 3316 | if (IsRead) { |
| 3317 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types); |
| 3318 | llvm::Value *Call = Builder.CreateCall(F, Metadata); |
| 3319 | |
| 3320 | if (MixedTypes) |
| 3321 | // Read into 64 bit register and then truncate result to 32 bit. |
| 3322 | return Builder.CreateTrunc(Call, ValueType); |
| 3323 | |
| 3324 | if (ValueType->isPointerTy()) |
| 3325 | // Have i32/i64 result (Call) but want to return a VoidPtrTy (i8*). |
| 3326 | return Builder.CreateIntToPtr(Call, ValueType); |
| 3327 | |
| 3328 | return Call; |
| 3329 | } |
| 3330 | |
| 3331 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types); |
| 3332 | llvm::Value *ArgValue = CGF.EmitScalarExpr(E->getArg(1)); |
| 3333 | if (MixedTypes) { |
| 3334 | // Extend 32 bit write value to 64 bit to pass to write. |
| 3335 | ArgValue = Builder.CreateZExt(ArgValue, RegisterType); |
| 3336 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 3337 | } |
| 3338 | |
| 3339 | if (ValueType->isPointerTy()) { |
| 3340 | // Have VoidPtrTy ArgValue but want to return an i32/i64. |
| 3341 | ArgValue = Builder.CreatePtrToInt(ArgValue, RegisterType); |
| 3342 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 3343 | } |
| 3344 | |
| 3345 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 3346 | } |
| 3347 | |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3348 | /// Return true if BuiltinID is an overloaded Neon intrinsic with an extra |
| 3349 | /// argument that specifies the vector type. |
| 3350 | static bool HasExtraNeonArgument(unsigned BuiltinID) { |
| 3351 | switch (BuiltinID) { |
| 3352 | default: break; |
| 3353 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 3354 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 3355 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 3356 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 3357 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 3358 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 3359 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 3360 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 3361 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 3362 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 3363 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 3364 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 3365 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 3366 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 3367 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 3368 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 3369 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 3370 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 3371 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 3372 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 3373 | case NEON::BI__builtin_neon_vsha1h_u32: |
| 3374 | case NEON::BI__builtin_neon_vsha1cq_u32: |
| 3375 | case NEON::BI__builtin_neon_vsha1pq_u32: |
| 3376 | case NEON::BI__builtin_neon_vsha1mq_u32: |
| 3377 | case ARM::BI_MoveToCoprocessor: |
| 3378 | case ARM::BI_MoveToCoprocessor2: |
| 3379 | return false; |
| 3380 | } |
| 3381 | return true; |
| 3382 | } |
| 3383 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3384 | Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
| 3385 | const CallExpr *E) { |
| 3386 | if (auto Hint = GetValueForARMHint(BuiltinID)) |
| 3387 | return Hint; |
Saleem Abdulrasool | 38ed6de | 2014-05-02 06:53:57 +0000 | [diff] [blame] | 3388 | |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 3389 | if (BuiltinID == ARM::BI__emit) { |
| 3390 | bool IsThumb = getTarget().getTriple().getArch() == llvm::Triple::thumb; |
| 3391 | llvm::FunctionType *FTy = |
| 3392 | llvm::FunctionType::get(VoidTy, /*Variadic=*/false); |
| 3393 | |
| 3394 | APSInt Value; |
| 3395 | if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext())) |
| 3396 | llvm_unreachable("Sema will ensure that the parameter is constant"); |
| 3397 | |
| 3398 | uint64_t ZExtValue = Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue(); |
| 3399 | |
| 3400 | llvm::InlineAsm *Emit = |
| 3401 | IsThumb ? InlineAsm::get(FTy, ".inst.n 0x" + utohexstr(ZExtValue), "", |
| 3402 | /*SideEffects=*/true) |
| 3403 | : InlineAsm::get(FTy, ".inst 0x" + utohexstr(ZExtValue), "", |
| 3404 | /*SideEffects=*/true); |
| 3405 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3406 | return Builder.CreateCall(Emit, {}); |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
Yi Kong | 1d268af | 2014-08-26 12:48:06 +0000 | [diff] [blame] | 3409 | if (BuiltinID == ARM::BI__builtin_arm_dbg) { |
| 3410 | Value *Option = EmitScalarExpr(E->getArg(0)); |
| 3411 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_dbg), Option); |
| 3412 | } |
| 3413 | |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 3414 | if (BuiltinID == ARM::BI__builtin_arm_prefetch) { |
| 3415 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 3416 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 3417 | Value *IsData = EmitScalarExpr(E->getArg(2)); |
| 3418 | |
| 3419 | // Locality is not supported on ARM target |
| 3420 | Value *Locality = llvm::ConstantInt::get(Int32Ty, 3); |
| 3421 | |
| 3422 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3423 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 3424 | } |
| 3425 | |
Jim Grosbach | 171ec34 | 2014-06-16 21:55:58 +0000 | [diff] [blame] | 3426 | if (BuiltinID == ARM::BI__builtin_arm_rbit) { |
| 3427 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_rbit), |
| 3428 | EmitScalarExpr(E->getArg(0)), |
| 3429 | "rbit"); |
| 3430 | } |
| 3431 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3432 | if (BuiltinID == ARM::BI__clear_cache) { |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 3433 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
Rafael Espindola | a54062e | 2010-06-07 17:26:50 +0000 | [diff] [blame] | 3434 | const FunctionDecl *FD = E->getDirectCallee(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3435 | SmallVector<Value*, 2> Ops; |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 3436 | for (unsigned i = 0; i < 2; i++) |
Eric Christopher | cf5e83b | 2011-03-14 20:30:34 +0000 | [diff] [blame] | 3437 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 3438 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 3439 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3440 | StringRef Name = FD->getName(); |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 3441 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3442 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3443 | |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3444 | if (BuiltinID == ARM::BI__builtin_arm_ldrexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3445 | ((BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 3446 | BuiltinID == ARM::BI__builtin_arm_ldaex) && |
Saleem Abdulrasool | e700cab | 2014-07-05 20:10:05 +0000 | [diff] [blame] | 3447 | getContext().getTypeSize(E->getType()) == 64) || |
| 3448 | BuiltinID == ARM::BI__ldrexd) { |
| 3449 | Function *F; |
| 3450 | |
| 3451 | switch (BuiltinID) { |
| 3452 | default: llvm_unreachable("unexpected builtin"); |
| 3453 | case ARM::BI__builtin_arm_ldaex: |
| 3454 | F = CGM.getIntrinsic(Intrinsic::arm_ldaexd); |
| 3455 | break; |
| 3456 | case ARM::BI__builtin_arm_ldrexd: |
| 3457 | case ARM::BI__builtin_arm_ldrex: |
| 3458 | case ARM::BI__ldrexd: |
| 3459 | F = CGM.getIntrinsic(Intrinsic::arm_ldrexd); |
| 3460 | break; |
| 3461 | } |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3462 | |
| 3463 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3464 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 3465 | "ldrexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3466 | |
| 3467 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 3468 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 3469 | Val0 = Builder.CreateZExt(Val0, Int64Ty); |
| 3470 | Val1 = Builder.CreateZExt(Val1, Int64Ty); |
| 3471 | |
| 3472 | Value *ShiftCst = llvm::ConstantInt::get(Int64Ty, 32); |
| 3473 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3474 | Val = Builder.CreateOr(Val, Val1); |
| 3475 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3478 | if (BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 3479 | BuiltinID == ARM::BI__builtin_arm_ldaex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3480 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 3481 | |
| 3482 | QualType Ty = E->getType(); |
| 3483 | llvm::Type *RealResTy = ConvertType(Ty); |
| 3484 | llvm::Type *IntResTy = llvm::IntegerType::get(getLLVMContext(), |
| 3485 | getContext().getTypeSize(Ty)); |
| 3486 | LoadAddr = Builder.CreateBitCast(LoadAddr, IntResTy->getPointerTo()); |
| 3487 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3488 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_ldaex |
| 3489 | ? Intrinsic::arm_ldaex |
| 3490 | : Intrinsic::arm_ldrex, |
| 3491 | LoadAddr->getType()); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3492 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldrex"); |
| 3493 | |
| 3494 | if (RealResTy->isPointerTy()) |
| 3495 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 3496 | else { |
| 3497 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 3498 | return Builder.CreateBitCast(Val, RealResTy); |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | if (BuiltinID == ARM::BI__builtin_arm_strexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3503 | ((BuiltinID == ARM::BI__builtin_arm_stlex || |
| 3504 | BuiltinID == ARM::BI__builtin_arm_strex) && |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3505 | getContext().getTypeSize(E->getArg(0)->getType()) == 64)) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3506 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 3507 | ? Intrinsic::arm_stlexd |
| 3508 | : Intrinsic::arm_strexd); |
Reid Kleckner | ee7cf84 | 2014-12-01 22:02:27 +0000 | [diff] [blame] | 3509 | llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty, nullptr); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3510 | |
Juergen Ributzka | c6ab1f8 | 2013-08-19 22:20:37 +0000 | [diff] [blame] | 3511 | Value *Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3512 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 3513 | Builder.CreateStore(Val, Tmp); |
| 3514 | |
| 3515 | Value *LdPtr = Builder.CreateBitCast(Tmp,llvm::PointerType::getUnqual(STy)); |
| 3516 | Val = Builder.CreateLoad(LdPtr); |
| 3517 | |
| 3518 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 3519 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3520 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3521 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "strexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3524 | if (BuiltinID == ARM::BI__builtin_arm_strex || |
| 3525 | BuiltinID == ARM::BI__builtin_arm_stlex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3526 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 3527 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 3528 | |
| 3529 | QualType Ty = E->getArg(0)->getType(); |
| 3530 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 3531 | getContext().getTypeSize(Ty)); |
| 3532 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 3533 | |
| 3534 | if (StoreVal->getType()->isPointerTy()) |
| 3535 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int32Ty); |
| 3536 | else { |
| 3537 | StoreVal = Builder.CreateBitCast(StoreVal, StoreTy); |
| 3538 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int32Ty); |
| 3539 | } |
| 3540 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3541 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 3542 | ? Intrinsic::arm_stlex |
| 3543 | : Intrinsic::arm_strex, |
| 3544 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3545 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "strex"); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | if (BuiltinID == ARM::BI__builtin_arm_clrex) { |
| 3549 | Function *F = CGM.getIntrinsic(Intrinsic::arm_clrex); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3550 | return Builder.CreateCall(F, {}); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 3553 | // CRC32 |
| 3554 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 3555 | switch (BuiltinID) { |
| 3556 | case ARM::BI__builtin_arm_crc32b: |
| 3557 | CRCIntrinsicID = Intrinsic::arm_crc32b; break; |
| 3558 | case ARM::BI__builtin_arm_crc32cb: |
| 3559 | CRCIntrinsicID = Intrinsic::arm_crc32cb; break; |
| 3560 | case ARM::BI__builtin_arm_crc32h: |
| 3561 | CRCIntrinsicID = Intrinsic::arm_crc32h; break; |
| 3562 | case ARM::BI__builtin_arm_crc32ch: |
| 3563 | CRCIntrinsicID = Intrinsic::arm_crc32ch; break; |
| 3564 | case ARM::BI__builtin_arm_crc32w: |
| 3565 | case ARM::BI__builtin_arm_crc32d: |
| 3566 | CRCIntrinsicID = Intrinsic::arm_crc32w; break; |
| 3567 | case ARM::BI__builtin_arm_crc32cw: |
| 3568 | case ARM::BI__builtin_arm_crc32cd: |
| 3569 | CRCIntrinsicID = Intrinsic::arm_crc32cw; break; |
| 3570 | } |
| 3571 | |
| 3572 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 3573 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 3574 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 3575 | |
| 3576 | // crc32{c,}d intrinsics are implemnted as two calls to crc32{c,}w |
| 3577 | // intrinsics, hence we need different codegen for these cases. |
| 3578 | if (BuiltinID == ARM::BI__builtin_arm_crc32d || |
| 3579 | BuiltinID == ARM::BI__builtin_arm_crc32cd) { |
| 3580 | Value *C1 = llvm::ConstantInt::get(Int64Ty, 32); |
| 3581 | Value *Arg1a = Builder.CreateTruncOrBitCast(Arg1, Int32Ty); |
| 3582 | Value *Arg1b = Builder.CreateLShr(Arg1, C1); |
| 3583 | Arg1b = Builder.CreateTruncOrBitCast(Arg1b, Int32Ty); |
| 3584 | |
| 3585 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3586 | Value *Res = Builder.CreateCall(F, {Arg0, Arg1a}); |
| 3587 | return Builder.CreateCall(F, {Res, Arg1b}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 3588 | } else { |
| 3589 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, Int32Ty); |
| 3590 | |
| 3591 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3592 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 3593 | } |
| 3594 | } |
| 3595 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 3596 | if (BuiltinID == ARM::BI__builtin_arm_rsr || |
| 3597 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 3598 | BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 3599 | BuiltinID == ARM::BI__builtin_arm_wsr || |
| 3600 | BuiltinID == ARM::BI__builtin_arm_wsr64 || |
| 3601 | BuiltinID == ARM::BI__builtin_arm_wsrp) { |
| 3602 | |
| 3603 | bool IsRead = BuiltinID == ARM::BI__builtin_arm_rsr || |
| 3604 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 3605 | BuiltinID == ARM::BI__builtin_arm_rsrp; |
| 3606 | |
| 3607 | bool IsPointerBuiltin = BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 3608 | BuiltinID == ARM::BI__builtin_arm_wsrp; |
| 3609 | |
| 3610 | bool Is64Bit = BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 3611 | BuiltinID == ARM::BI__builtin_arm_wsr64; |
| 3612 | |
| 3613 | llvm::Type *ValueType; |
| 3614 | llvm::Type *RegisterType; |
| 3615 | if (IsPointerBuiltin) { |
| 3616 | ValueType = VoidPtrTy; |
| 3617 | RegisterType = Int32Ty; |
| 3618 | } else if (Is64Bit) { |
| 3619 | ValueType = RegisterType = Int64Ty; |
| 3620 | } else { |
| 3621 | ValueType = RegisterType = Int32Ty; |
| 3622 | } |
| 3623 | |
| 3624 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 3625 | } |
| 3626 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 3627 | // Find out if any arguments are required to be integer constant |
| 3628 | // expressions. |
| 3629 | unsigned ICEArguments = 0; |
| 3630 | ASTContext::GetBuiltinTypeError Error; |
| 3631 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 3632 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 3633 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3634 | SmallVector<Value*, 4> Ops; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3635 | llvm::Value *Align = nullptr; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3636 | bool HasExtraArg = HasExtraNeonArgument(BuiltinID); |
| 3637 | unsigned NumArgs = E->getNumArgs() - (HasExtraArg ? 1 : 0); |
| 3638 | for (unsigned i = 0, e = NumArgs; i != e; i++) { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3639 | if (i == 0) { |
| 3640 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3641 | case NEON::BI__builtin_neon_vld1_v: |
| 3642 | case NEON::BI__builtin_neon_vld1q_v: |
| 3643 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 3644 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 3645 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 3646 | case NEON::BI__builtin_neon_vld1q_dup_v: |
| 3647 | case NEON::BI__builtin_neon_vst1_v: |
| 3648 | case NEON::BI__builtin_neon_vst1q_v: |
| 3649 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 3650 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 3651 | case NEON::BI__builtin_neon_vst2_v: |
| 3652 | case NEON::BI__builtin_neon_vst2q_v: |
| 3653 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 3654 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 3655 | case NEON::BI__builtin_neon_vst3_v: |
| 3656 | case NEON::BI__builtin_neon_vst3q_v: |
| 3657 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 3658 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 3659 | case NEON::BI__builtin_neon_vst4_v: |
| 3660 | case NEON::BI__builtin_neon_vst4q_v: |
| 3661 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 3662 | case NEON::BI__builtin_neon_vst4q_lane_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3663 | // Get the alignment for the argument in addition to the value; |
| 3664 | // we'll use it later. |
| 3665 | std::pair<llvm::Value*, unsigned> Src = |
| 3666 | EmitPointerWithAlignment(E->getArg(0)); |
| 3667 | Ops.push_back(Src.first); |
| 3668 | Align = Builder.getInt32(Src.second); |
| 3669 | continue; |
| 3670 | } |
| 3671 | } |
| 3672 | if (i == 1) { |
| 3673 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3674 | case NEON::BI__builtin_neon_vld2_v: |
| 3675 | case NEON::BI__builtin_neon_vld2q_v: |
| 3676 | case NEON::BI__builtin_neon_vld3_v: |
| 3677 | case NEON::BI__builtin_neon_vld3q_v: |
| 3678 | case NEON::BI__builtin_neon_vld4_v: |
| 3679 | case NEON::BI__builtin_neon_vld4q_v: |
| 3680 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 3681 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 3682 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 3683 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 3684 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 3685 | case NEON::BI__builtin_neon_vld4q_lane_v: |
| 3686 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 3687 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 3688 | case NEON::BI__builtin_neon_vld4_dup_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3689 | // Get the alignment for the argument in addition to the value; |
| 3690 | // we'll use it later. |
| 3691 | std::pair<llvm::Value*, unsigned> Src = |
| 3692 | EmitPointerWithAlignment(E->getArg(1)); |
| 3693 | Ops.push_back(Src.first); |
| 3694 | Align = Builder.getInt32(Src.second); |
| 3695 | continue; |
| 3696 | } |
| 3697 | } |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 3698 | |
| 3699 | if ((ICEArguments & (1 << i)) == 0) { |
| 3700 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 3701 | } else { |
| 3702 | // If this is required to be a constant, constant fold it so that we know |
| 3703 | // that the generated intrinsic gets a ConstantInt. |
| 3704 | llvm::APSInt Result; |
| 3705 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 3706 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
| 3707 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 3708 | } |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3709 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3710 | |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 3711 | switch (BuiltinID) { |
| 3712 | default: break; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3713 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3714 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 3715 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 3716 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 3717 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 3718 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 3719 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 3720 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 3721 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 3722 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 3723 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3724 | return Builder.CreateExtractElement(Ops[0], Ops[1], "vget_lane"); |
| 3725 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3726 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 3727 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 3728 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 3729 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 3730 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 3731 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 3732 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 3733 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 3734 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 3735 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 3736 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 3737 | |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 3738 | case NEON::BI__builtin_neon_vsha1h_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 3739 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1h), Ops, |
| 3740 | "vsha1h"); |
| 3741 | case NEON::BI__builtin_neon_vsha1cq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 3742 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1c), Ops, |
| 3743 | "vsha1h"); |
| 3744 | case NEON::BI__builtin_neon_vsha1pq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 3745 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1p), Ops, |
| 3746 | "vsha1h"); |
| 3747 | case NEON::BI__builtin_neon_vsha1mq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 3748 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1m), Ops, |
| 3749 | "vsha1h"); |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3750 | |
| 3751 | // The ARM _MoveToCoprocessor builtins put the input register value as |
| 3752 | // the first argument, but the LLVM intrinsic expects it as the third one. |
| 3753 | case ARM::BI_MoveToCoprocessor: |
| 3754 | case ARM::BI_MoveToCoprocessor2: { |
| 3755 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI_MoveToCoprocessor ? |
| 3756 | Intrinsic::arm_mcr : Intrinsic::arm_mcr2); |
| 3757 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0], |
| 3758 | Ops[3], Ops[4], Ops[5]}); |
| 3759 | } |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | // Get the last argument, which specifies the vector type. |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3763 | assert(HasExtraArg); |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3764 | llvm::APSInt Result; |
| 3765 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 3766 | if (!Arg->isIntegerConstantExpr(Result, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3767 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3768 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 3769 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f || |
| 3770 | BuiltinID == ARM::BI__builtin_arm_vcvtr_d) { |
| 3771 | // Determine the overloaded type of this builtin. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 3772 | llvm::Type *Ty; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 3773 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 3774 | Ty = FloatTy; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 3775 | else |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 3776 | Ty = DoubleTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3777 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 3778 | // Determine whether this is an unsigned conversion or not. |
| 3779 | bool usgn = Result.getZExtValue() == 1; |
| 3780 | unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr; |
| 3781 | |
| 3782 | // Call the appropriate intrinsic. |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3783 | Function *F = CGM.getIntrinsic(Int, Ty); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 3784 | return Builder.CreateCall(F, Ops, "vcvtr"); |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 3785 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3786 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 3787 | // Determine the type of this overloaded NEON intrinsic. |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 3788 | NeonTypeFlags Type(Result.getZExtValue()); |
| 3789 | bool usgn = Type.isUnsigned(); |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 3790 | bool rightShift = false; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3791 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 3792 | llvm::VectorType *VTy = GetNeonType(this, Type); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 3793 | llvm::Type *Ty = VTy; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3794 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3795 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3796 | |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 3797 | // Many NEON builtins have identical semantics and uses in ARM and |
| 3798 | // AArch64. Emit these in a single function. |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 3799 | auto IntrinsicMap = makeArrayRef(ARMSIMDIntrinsicMap); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3800 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
| 3801 | IntrinsicMap, BuiltinID, NEONSIMDIntrinsicsProvenSorted); |
| 3802 | if (Builtin) |
| 3803 | return EmitCommonNeonBuiltinExpr( |
| 3804 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
| 3805 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, Align); |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 3806 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3807 | unsigned Int; |
| 3808 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3809 | default: return nullptr; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3810 | case NEON::BI__builtin_neon_vld1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 3811 | // Handle 64-bit integer elements as a special case. Use shuffles of |
| 3812 | // one-element vectors to avoid poor code for i64 in the backend. |
| 3813 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 3814 | // Extract the other lane. |
| 3815 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3816 | int Lane = cast<ConstantInt>(Ops[2])->getZExtValue(); |
| 3817 | Value *SV = llvm::ConstantVector::get(ConstantInt::get(Int32Ty, 1-Lane)); |
| 3818 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
| 3819 | // Load the value as a one-element vector. |
| 3820 | Ty = llvm::VectorType::get(VTy->getElementType(), 1); |
| 3821 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Ty); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3822 | Value *Ld = Builder.CreateCall(F, {Ops[0], Align}); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 3823 | // Combine them. |
| 3824 | SmallVector<Constant*, 2> Indices; |
| 3825 | Indices.push_back(ConstantInt::get(Int32Ty, 1-Lane)); |
| 3826 | Indices.push_back(ConstantInt::get(Int32Ty, Lane)); |
| 3827 | SV = llvm::ConstantVector::get(Indices); |
| 3828 | return Builder.CreateShuffleVector(Ops[1], Ld, SV, "vld1q_lane"); |
| 3829 | } |
| 3830 | // fall through |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3831 | case NEON::BI__builtin_neon_vld1_lane_v: { |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3832 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3833 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 3834 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 3835 | LoadInst *Ld = Builder.CreateLoad(Ops[0]); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 3836 | Ld->setAlignment(cast<ConstantInt>(Align)->getZExtValue()); |
| 3837 | return Builder.CreateInsertElement(Ops[1], Ld, Ops[2], "vld1_lane"); |
| 3838 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3839 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 3840 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 3841 | case NEON::BI__builtin_neon_vld4_dup_v: { |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 3842 | // Handle 64-bit elements as a special-case. There is no "dup" needed. |
| 3843 | if (VTy->getElementType()->getPrimitiveSizeInBits() == 64) { |
| 3844 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3845 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3846 | Int = Intrinsic::arm_neon_vld2; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 3847 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3848 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3849 | Int = Intrinsic::arm_neon_vld3; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 3850 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3851 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3852 | Int = Intrinsic::arm_neon_vld4; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 3853 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3854 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 3855 | } |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3856 | Function *F = CGM.getIntrinsic(Int, Ty); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3857 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, "vld_dup"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 3858 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 3859 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3860 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 3861 | } |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3862 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3863 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3864 | Int = Intrinsic::arm_neon_vld2lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3865 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3866 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3867 | Int = Intrinsic::arm_neon_vld3lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3868 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3869 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3870 | Int = Intrinsic::arm_neon_vld4lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3871 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3872 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3873 | } |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3874 | Function *F = CGM.getIntrinsic(Int, Ty); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 3875 | llvm::StructType *STy = cast<llvm::StructType>(F->getReturnType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3876 | |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3877 | SmallVector<Value*, 6> Args; |
| 3878 | Args.push_back(Ops[1]); |
| 3879 | Args.append(STy->getNumElements(), UndefValue::get(Ty)); |
| 3880 | |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 3881 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3882 | Args.push_back(CI); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3883 | Args.push_back(Align); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3884 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 3885 | Ops[1] = Builder.CreateCall(F, Args, "vld_dup"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 3886 | // splat lane 0 to all elts in each vector of the result. |
| 3887 | for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { |
| 3888 | Value *Val = Builder.CreateExtractValue(Ops[1], i); |
| 3889 | Value *Elt = Builder.CreateBitCast(Val, Ty); |
| 3890 | Elt = EmitNeonSplat(Elt, CI); |
| 3891 | Elt = Builder.CreateBitCast(Elt, Val->getType()); |
| 3892 | Ops[1] = Builder.CreateInsertValue(Ops[1], Elt, i); |
| 3893 | } |
| 3894 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 3895 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3896 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 3897 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3898 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3899 | Int = |
| 3900 | usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3901 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 3902 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3903 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3904 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 3905 | Ops, "vqrshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3906 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 3907 | Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3908 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 3909 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3910 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3911 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 3912 | Ops, "vqshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3913 | case NEON::BI__builtin_neon_vrecpe_v: |
| 3914 | case NEON::BI__builtin_neon_vrecpeq_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3915 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecpe, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3916 | Ops, "vrecpe"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3917 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3918 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrshiftn, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 3919 | Ops, "vrshrn_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3920 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 3921 | case NEON::BI__builtin_neon_vrsraq_n_v: |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 3922 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3923 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3924 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, true); |
| 3925 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3926 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Ty), {Ops[1], Ops[2]}); |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 3927 | return Builder.CreateAdd(Ops[0], Ops[1], "vrsra_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3928 | case NEON::BI__builtin_neon_vsri_n_v: |
| 3929 | case NEON::BI__builtin_neon_vsriq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 3930 | rightShift = true; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3931 | case NEON::BI__builtin_neon_vsli_n_v: |
| 3932 | case NEON::BI__builtin_neon_vsliq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 3933 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, rightShift); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 3934 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftins, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3935 | Ops, "vsli_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3936 | case NEON::BI__builtin_neon_vsra_n_v: |
| 3937 | case NEON::BI__builtin_neon_vsraq_n_v: |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3938 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 3939 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3940 | return Builder.CreateAdd(Ops[0], Ops[1]); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3941 | case NEON::BI__builtin_neon_vst1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 3942 | // Handle 64-bit integer elements as a special case. Use a shuffle to get |
| 3943 | // a one-element vector and avoid poor code for i64 in the backend. |
| 3944 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 3945 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3946 | Value *SV = llvm::ConstantVector::get(cast<llvm::Constant>(Ops[2])); |
| 3947 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3948 | Ops[2] = Align; |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 3949 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst1, |
| 3950 | Ops[1]->getType()), Ops); |
| 3951 | } |
| 3952 | // fall through |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3953 | case NEON::BI__builtin_neon_vst1_lane_v: { |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3954 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3955 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 3956 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 3957 | StoreInst *St = Builder.CreateStore(Ops[1], |
| 3958 | Builder.CreateBitCast(Ops[0], Ty)); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 3959 | St->setAlignment(cast<ConstantInt>(Align)->getZExtValue()); |
| 3960 | return St; |
| 3961 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3962 | case NEON::BI__builtin_neon_vtbl1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3963 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1), |
| 3964 | Ops, "vtbl1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3965 | case NEON::BI__builtin_neon_vtbl2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3966 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl2), |
| 3967 | Ops, "vtbl2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3968 | case NEON::BI__builtin_neon_vtbl3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3969 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl3), |
| 3970 | Ops, "vtbl3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3971 | case NEON::BI__builtin_neon_vtbl4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3972 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl4), |
| 3973 | Ops, "vtbl4"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3974 | case NEON::BI__builtin_neon_vtbx1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3975 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx1), |
| 3976 | Ops, "vtbx1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3977 | case NEON::BI__builtin_neon_vtbx2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3978 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx2), |
| 3979 | Ops, "vtbx2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3980 | case NEON::BI__builtin_neon_vtbx3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3981 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx3), |
| 3982 | Ops, "vtbx3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3983 | case NEON::BI__builtin_neon_vtbx4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 3984 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx4), |
| 3985 | Ops, "vtbx4"); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3989 | static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID, |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3990 | const CallExpr *E, |
| 3991 | SmallVectorImpl<Value *> &Ops) { |
| 3992 | unsigned int Int = 0; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3993 | const char *s = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3994 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3995 | switch (BuiltinID) { |
| 3996 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3997 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3998 | case NEON::BI__builtin_neon_vtbl1_v: |
| 3999 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 4000 | case NEON::BI__builtin_neon_vqtbl1q_v: |
| 4001 | case NEON::BI__builtin_neon_vtbl2_v: |
| 4002 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 4003 | case NEON::BI__builtin_neon_vqtbl2q_v: |
| 4004 | case NEON::BI__builtin_neon_vtbl3_v: |
| 4005 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 4006 | case NEON::BI__builtin_neon_vqtbl3q_v: |
| 4007 | case NEON::BI__builtin_neon_vtbl4_v: |
| 4008 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 4009 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4010 | break; |
| 4011 | case NEON::BI__builtin_neon_vtbx1_v: |
| 4012 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 4013 | case NEON::BI__builtin_neon_vqtbx1q_v: |
| 4014 | case NEON::BI__builtin_neon_vtbx2_v: |
| 4015 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 4016 | case NEON::BI__builtin_neon_vqtbx2q_v: |
| 4017 | case NEON::BI__builtin_neon_vtbx3_v: |
| 4018 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 4019 | case NEON::BI__builtin_neon_vqtbx3q_v: |
| 4020 | case NEON::BI__builtin_neon_vtbx4_v: |
| 4021 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 4022 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4023 | break; |
| 4024 | } |
| 4025 | |
| 4026 | assert(E->getNumArgs() >= 3); |
| 4027 | |
| 4028 | // Get the last argument, which specifies the vector type. |
| 4029 | llvm::APSInt Result; |
| 4030 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 4031 | if (!Arg->isIntegerConstantExpr(Result, CGF.getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4032 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4033 | |
| 4034 | // Determine the type of this overloaded NEON intrinsic. |
| 4035 | NeonTypeFlags Type(Result.getZExtValue()); |
| 4036 | llvm::VectorType *VTy = GetNeonType(&CGF, Type); |
| 4037 | llvm::Type *Ty = VTy; |
| 4038 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4039 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4040 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4041 | unsigned nElts = VTy->getNumElements(); |
| 4042 | |
| 4043 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 4044 | |
| 4045 | // AArch64 scalar builtins are not overloaded, they do not have an extra |
| 4046 | // argument that specifies the vector type, need to handle each case. |
| 4047 | SmallVector<Value *, 2> TblOps; |
| 4048 | switch (BuiltinID) { |
| 4049 | case NEON::BI__builtin_neon_vtbl1_v: { |
| 4050 | TblOps.push_back(Ops[0]); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4051 | return packTBLDVectorList(CGF, TblOps, nullptr, Ops[1], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4052 | Intrinsic::aarch64_neon_tbl1, "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4053 | } |
| 4054 | case NEON::BI__builtin_neon_vtbl2_v: { |
| 4055 | TblOps.push_back(Ops[0]); |
| 4056 | TblOps.push_back(Ops[1]); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4057 | return packTBLDVectorList(CGF, TblOps, nullptr, Ops[2], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4058 | Intrinsic::aarch64_neon_tbl1, "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4059 | } |
| 4060 | case NEON::BI__builtin_neon_vtbl3_v: { |
| 4061 | TblOps.push_back(Ops[0]); |
| 4062 | TblOps.push_back(Ops[1]); |
| 4063 | TblOps.push_back(Ops[2]); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4064 | return packTBLDVectorList(CGF, TblOps, nullptr, Ops[3], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4065 | Intrinsic::aarch64_neon_tbl2, "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4066 | } |
| 4067 | case NEON::BI__builtin_neon_vtbl4_v: { |
| 4068 | TblOps.push_back(Ops[0]); |
| 4069 | TblOps.push_back(Ops[1]); |
| 4070 | TblOps.push_back(Ops[2]); |
| 4071 | TblOps.push_back(Ops[3]); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4072 | return packTBLDVectorList(CGF, TblOps, nullptr, Ops[4], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4073 | Intrinsic::aarch64_neon_tbl2, "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4074 | } |
| 4075 | case NEON::BI__builtin_neon_vtbx1_v: { |
| 4076 | TblOps.push_back(Ops[1]); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4077 | Value *TblRes = packTBLDVectorList(CGF, TblOps, nullptr, Ops[2], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4078 | Intrinsic::aarch64_neon_tbl1, "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4079 | |
| 4080 | llvm::Constant *Eight = ConstantInt::get(VTy->getElementType(), 8); |
| 4081 | Value* EightV = llvm::ConstantVector::getSplat(nElts, Eight); |
| 4082 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[2], EightV); |
| 4083 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 4084 | |
| 4085 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 4086 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 4087 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 4088 | } |
| 4089 | case NEON::BI__builtin_neon_vtbx2_v: { |
| 4090 | TblOps.push_back(Ops[1]); |
| 4091 | TblOps.push_back(Ops[2]); |
| 4092 | return packTBLDVectorList(CGF, TblOps, Ops[0], Ops[3], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4093 | Intrinsic::aarch64_neon_tbx1, "vtbx1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4094 | } |
| 4095 | case NEON::BI__builtin_neon_vtbx3_v: { |
| 4096 | TblOps.push_back(Ops[1]); |
| 4097 | TblOps.push_back(Ops[2]); |
| 4098 | TblOps.push_back(Ops[3]); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4099 | Value *TblRes = packTBLDVectorList(CGF, TblOps, nullptr, Ops[4], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4100 | Intrinsic::aarch64_neon_tbl2, "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4101 | |
| 4102 | llvm::Constant *TwentyFour = ConstantInt::get(VTy->getElementType(), 24); |
| 4103 | Value* TwentyFourV = llvm::ConstantVector::getSplat(nElts, TwentyFour); |
| 4104 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[4], |
| 4105 | TwentyFourV); |
| 4106 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 4107 | |
| 4108 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 4109 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 4110 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 4111 | } |
| 4112 | case NEON::BI__builtin_neon_vtbx4_v: { |
| 4113 | TblOps.push_back(Ops[1]); |
| 4114 | TblOps.push_back(Ops[2]); |
| 4115 | TblOps.push_back(Ops[3]); |
| 4116 | TblOps.push_back(Ops[4]); |
| 4117 | return packTBLDVectorList(CGF, TblOps, Ops[0], Ops[5], Ty, |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4118 | Intrinsic::aarch64_neon_tbx2, "vtbx2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4119 | } |
| 4120 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 4121 | case NEON::BI__builtin_neon_vqtbl1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4122 | Int = Intrinsic::aarch64_neon_tbl1; s = "vtbl1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4123 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 4124 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4125 | Int = Intrinsic::aarch64_neon_tbl2; s = "vtbl2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4126 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 4127 | case NEON::BI__builtin_neon_vqtbl3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4128 | Int = Intrinsic::aarch64_neon_tbl3; s = "vtbl3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4129 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 4130 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4131 | Int = Intrinsic::aarch64_neon_tbl4; s = "vtbl4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4132 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 4133 | case NEON::BI__builtin_neon_vqtbx1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4134 | Int = Intrinsic::aarch64_neon_tbx1; s = "vtbx1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4135 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 4136 | case NEON::BI__builtin_neon_vqtbx2q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4137 | Int = Intrinsic::aarch64_neon_tbx2; s = "vtbx2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4138 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 4139 | case NEON::BI__builtin_neon_vqtbx3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4140 | Int = Intrinsic::aarch64_neon_tbx3; s = "vtbx3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4141 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 4142 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4143 | Int = Intrinsic::aarch64_neon_tbx4; s = "vtbx4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | if (!Int) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4148 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4149 | |
| 4150 | Function *F = CGF.CGM.getIntrinsic(Int, Ty); |
| 4151 | return CGF.EmitNeonCall(F, Ops, s); |
| 4152 | } |
| 4153 | |
| 4154 | Value *CodeGenFunction::vectorWrapScalar16(Value *Op) { |
| 4155 | llvm::Type *VTy = llvm::VectorType::get(Int16Ty, 4); |
| 4156 | Op = Builder.CreateBitCast(Op, Int16Ty); |
| 4157 | Value *V = UndefValue::get(VTy); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4158 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4159 | Op = Builder.CreateInsertElement(V, Op, CI); |
| 4160 | return Op; |
| 4161 | } |
| 4162 | |
| 4163 | Value *CodeGenFunction::vectorWrapScalar8(Value *Op) { |
| 4164 | llvm::Type *VTy = llvm::VectorType::get(Int8Ty, 8); |
| 4165 | Op = Builder.CreateBitCast(Op, Int8Ty); |
| 4166 | Value *V = UndefValue::get(VTy); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4167 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4168 | Op = Builder.CreateInsertElement(V, Op, CI); |
| 4169 | return Op; |
| 4170 | } |
| 4171 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4172 | Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, |
| 4173 | const CallExpr *E) { |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 4174 | unsigned HintID = static_cast<unsigned>(-1); |
| 4175 | switch (BuiltinID) { |
| 4176 | default: break; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 4177 | case AArch64::BI__builtin_arm_nop: |
| 4178 | HintID = 0; |
| 4179 | break; |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 4180 | case AArch64::BI__builtin_arm_yield: |
| 4181 | HintID = 1; |
| 4182 | break; |
| 4183 | case AArch64::BI__builtin_arm_wfe: |
| 4184 | HintID = 2; |
| 4185 | break; |
| 4186 | case AArch64::BI__builtin_arm_wfi: |
| 4187 | HintID = 3; |
| 4188 | break; |
| 4189 | case AArch64::BI__builtin_arm_sev: |
| 4190 | HintID = 4; |
| 4191 | break; |
| 4192 | case AArch64::BI__builtin_arm_sevl: |
| 4193 | HintID = 5; |
| 4194 | break; |
| 4195 | } |
| 4196 | |
| 4197 | if (HintID != static_cast<unsigned>(-1)) { |
| 4198 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hint); |
| 4199 | return Builder.CreateCall(F, llvm::ConstantInt::get(Int32Ty, HintID)); |
| 4200 | } |
| 4201 | |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 4202 | if (BuiltinID == AArch64::BI__builtin_arm_prefetch) { |
| 4203 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 4204 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 4205 | Value *CacheLevel = EmitScalarExpr(E->getArg(2)); |
| 4206 | Value *RetentionPolicy = EmitScalarExpr(E->getArg(3)); |
| 4207 | Value *IsData = EmitScalarExpr(E->getArg(4)); |
| 4208 | |
| 4209 | Value *Locality = nullptr; |
| 4210 | if (cast<llvm::ConstantInt>(RetentionPolicy)->isZero()) { |
| 4211 | // Temporal fetch, needs to convert cache level to locality. |
| 4212 | Locality = llvm::ConstantInt::get(Int32Ty, |
| 4213 | -cast<llvm::ConstantInt>(CacheLevel)->getValue() + 3); |
| 4214 | } else { |
| 4215 | // Streaming fetch. |
| 4216 | Locality = llvm::ConstantInt::get(Int32Ty, 0); |
| 4217 | } |
| 4218 | |
| 4219 | // FIXME: We need AArch64 specific LLVM intrinsic if we want to specify |
| 4220 | // PLDL3STRM or PLDL2STRM. |
| 4221 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4222 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
Jim Grosbach | 7914082 | 2014-06-16 21:56:02 +0000 | [diff] [blame] | 4225 | if (BuiltinID == AArch64::BI__builtin_arm_rbit) { |
| 4226 | assert((getContext().getTypeSize(E->getType()) == 32) && |
| 4227 | "rbit of unusual size!"); |
| 4228 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 4229 | return Builder.CreateCall( |
| 4230 | CGM.getIntrinsic(Intrinsic::aarch64_rbit, Arg->getType()), Arg, "rbit"); |
| 4231 | } |
| 4232 | if (BuiltinID == AArch64::BI__builtin_arm_rbit64) { |
| 4233 | assert((getContext().getTypeSize(E->getType()) == 64) && |
| 4234 | "rbit of unusual size!"); |
| 4235 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 4236 | return Builder.CreateCall( |
| 4237 | CGM.getIntrinsic(Intrinsic::aarch64_rbit, Arg->getType()), Arg, "rbit"); |
| 4238 | } |
| 4239 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4240 | if (BuiltinID == AArch64::BI__clear_cache) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4241 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
| 4242 | const FunctionDecl *FD = E->getDirectCallee(); |
| 4243 | SmallVector<Value*, 2> Ops; |
| 4244 | for (unsigned i = 0; i < 2; i++) |
| 4245 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 4246 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 4247 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
| 4248 | StringRef Name = FD->getName(); |
| 4249 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
| 4250 | } |
| 4251 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4252 | if ((BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 4253 | BuiltinID == AArch64::BI__builtin_arm_ldaex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4254 | getContext().getTypeSize(E->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4255 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 4256 | ? Intrinsic::aarch64_ldaxp |
| 4257 | : Intrinsic::aarch64_ldxp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4258 | |
| 4259 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
| 4260 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 4261 | "ldxp"); |
| 4262 | |
| 4263 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 4264 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 4265 | llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128); |
| 4266 | Val0 = Builder.CreateZExt(Val0, Int128Ty); |
| 4267 | Val1 = Builder.CreateZExt(Val1, Int128Ty); |
| 4268 | |
| 4269 | Value *ShiftCst = llvm::ConstantInt::get(Int128Ty, 64); |
| 4270 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
| 4271 | Val = Builder.CreateOr(Val, Val1); |
| 4272 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4273 | } else if (BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 4274 | BuiltinID == AArch64::BI__builtin_arm_ldaex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4275 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 4276 | |
| 4277 | QualType Ty = E->getType(); |
| 4278 | llvm::Type *RealResTy = ConvertType(Ty); |
| 4279 | llvm::Type *IntResTy = llvm::IntegerType::get(getLLVMContext(), |
| 4280 | getContext().getTypeSize(Ty)); |
| 4281 | LoadAddr = Builder.CreateBitCast(LoadAddr, IntResTy->getPointerTo()); |
| 4282 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4283 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 4284 | ? Intrinsic::aarch64_ldaxr |
| 4285 | : Intrinsic::aarch64_ldxr, |
| 4286 | LoadAddr->getType()); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4287 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldxr"); |
| 4288 | |
| 4289 | if (RealResTy->isPointerTy()) |
| 4290 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 4291 | |
| 4292 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 4293 | return Builder.CreateBitCast(Val, RealResTy); |
| 4294 | } |
| 4295 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4296 | if ((BuiltinID == AArch64::BI__builtin_arm_strex || |
| 4297 | BuiltinID == AArch64::BI__builtin_arm_stlex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4298 | getContext().getTypeSize(E->getArg(0)->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4299 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 4300 | ? Intrinsic::aarch64_stlxp |
| 4301 | : Intrinsic::aarch64_stxp); |
Reid Kleckner | ee7cf84 | 2014-12-01 22:02:27 +0000 | [diff] [blame] | 4302 | llvm::Type *STy = llvm::StructType::get(Int64Ty, Int64Ty, nullptr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4303 | |
| 4304 | Value *One = llvm::ConstantInt::get(Int32Ty, 1); |
| 4305 | Value *Tmp = Builder.CreateAlloca(ConvertType(E->getArg(0)->getType()), |
| 4306 | One); |
| 4307 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 4308 | Builder.CreateStore(Val, Tmp); |
| 4309 | |
| 4310 | Value *LdPtr = Builder.CreateBitCast(Tmp,llvm::PointerType::getUnqual(STy)); |
| 4311 | Val = Builder.CreateLoad(LdPtr); |
| 4312 | |
| 4313 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 4314 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
| 4315 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), |
| 4316 | Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4317 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "stxp"); |
| 4318 | } |
| 4319 | |
| 4320 | if (BuiltinID == AArch64::BI__builtin_arm_strex || |
| 4321 | BuiltinID == AArch64::BI__builtin_arm_stlex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4322 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 4323 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 4324 | |
| 4325 | QualType Ty = E->getArg(0)->getType(); |
| 4326 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 4327 | getContext().getTypeSize(Ty)); |
| 4328 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 4329 | |
| 4330 | if (StoreVal->getType()->isPointerTy()) |
| 4331 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int64Ty); |
| 4332 | else { |
| 4333 | StoreVal = Builder.CreateBitCast(StoreVal, StoreTy); |
| 4334 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int64Ty); |
| 4335 | } |
| 4336 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4337 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 4338 | ? Intrinsic::aarch64_stlxr |
| 4339 | : Intrinsic::aarch64_stxr, |
| 4340 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4341 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4342 | } |
| 4343 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4344 | if (BuiltinID == AArch64::BI__builtin_arm_clrex) { |
| 4345 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4346 | return Builder.CreateCall(F, {}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | // CRC32 |
| 4350 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 4351 | switch (BuiltinID) { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4352 | case AArch64::BI__builtin_arm_crc32b: |
| 4353 | CRCIntrinsicID = Intrinsic::aarch64_crc32b; break; |
| 4354 | case AArch64::BI__builtin_arm_crc32cb: |
| 4355 | CRCIntrinsicID = Intrinsic::aarch64_crc32cb; break; |
| 4356 | case AArch64::BI__builtin_arm_crc32h: |
| 4357 | CRCIntrinsicID = Intrinsic::aarch64_crc32h; break; |
| 4358 | case AArch64::BI__builtin_arm_crc32ch: |
| 4359 | CRCIntrinsicID = Intrinsic::aarch64_crc32ch; break; |
| 4360 | case AArch64::BI__builtin_arm_crc32w: |
| 4361 | CRCIntrinsicID = Intrinsic::aarch64_crc32w; break; |
| 4362 | case AArch64::BI__builtin_arm_crc32cw: |
| 4363 | CRCIntrinsicID = Intrinsic::aarch64_crc32cw; break; |
| 4364 | case AArch64::BI__builtin_arm_crc32d: |
| 4365 | CRCIntrinsicID = Intrinsic::aarch64_crc32x; break; |
| 4366 | case AArch64::BI__builtin_arm_crc32cd: |
| 4367 | CRCIntrinsicID = Intrinsic::aarch64_crc32cx; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 4371 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 4372 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 4373 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
| 4374 | |
| 4375 | llvm::Type *DataTy = F->getFunctionType()->getParamType(1); |
| 4376 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, DataTy); |
| 4377 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4378 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4379 | } |
| 4380 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4381 | if (BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 4382 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 4383 | BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 4384 | BuiltinID == AArch64::BI__builtin_arm_wsr || |
| 4385 | BuiltinID == AArch64::BI__builtin_arm_wsr64 || |
| 4386 | BuiltinID == AArch64::BI__builtin_arm_wsrp) { |
| 4387 | |
| 4388 | bool IsRead = BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 4389 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 4390 | BuiltinID == AArch64::BI__builtin_arm_rsrp; |
| 4391 | |
| 4392 | bool IsPointerBuiltin = BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 4393 | BuiltinID == AArch64::BI__builtin_arm_wsrp; |
| 4394 | |
| 4395 | bool Is64Bit = BuiltinID != AArch64::BI__builtin_arm_rsr && |
| 4396 | BuiltinID != AArch64::BI__builtin_arm_wsr; |
| 4397 | |
| 4398 | llvm::Type *ValueType; |
| 4399 | llvm::Type *RegisterType = Int64Ty; |
| 4400 | if (IsPointerBuiltin) { |
| 4401 | ValueType = VoidPtrTy; |
| 4402 | } else if (Is64Bit) { |
| 4403 | ValueType = Int64Ty; |
| 4404 | } else { |
| 4405 | ValueType = Int32Ty; |
| 4406 | } |
| 4407 | |
| 4408 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 4409 | } |
| 4410 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4411 | // Find out if any arguments are required to be integer constant |
| 4412 | // expressions. |
| 4413 | unsigned ICEArguments = 0; |
| 4414 | ASTContext::GetBuiltinTypeError Error; |
| 4415 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 4416 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 4417 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4418 | llvm::SmallVector<Value*, 4> Ops; |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4419 | for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++) { |
| 4420 | if ((ICEArguments & (1 << i)) == 0) { |
| 4421 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 4422 | } else { |
| 4423 | // If this is required to be a constant, constant fold it so that we know |
| 4424 | // that the generated intrinsic gets a ConstantInt. |
| 4425 | llvm::APSInt Result; |
| 4426 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 4427 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 4428 | (void)IsConst; |
| 4429 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 4430 | } |
| 4431 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4432 | |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 4433 | auto SISDMap = makeArrayRef(AArch64SISDIntrinsicMap); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4434 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4435 | SISDMap, BuiltinID, AArch64SISDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4436 | |
| 4437 | if (Builtin) { |
| 4438 | Ops.push_back(EmitScalarExpr(E->getArg(E->getNumArgs() - 1))); |
| 4439 | Value *Result = EmitCommonNeonSISDBuiltinExpr(*this, *Builtin, Ops, E); |
| 4440 | assert(Result && "SISD intrinsic should have been handled"); |
| 4441 | return Result; |
| 4442 | } |
| 4443 | |
| 4444 | llvm::APSInt Result; |
| 4445 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 4446 | NeonTypeFlags Type(0); |
| 4447 | if (Arg->isIntegerConstantExpr(Result, getContext())) |
| 4448 | // Determine the type of this overloaded NEON intrinsic. |
| 4449 | Type = NeonTypeFlags(Result.getZExtValue()); |
| 4450 | |
| 4451 | bool usgn = Type.isUnsigned(); |
| 4452 | bool quad = Type.isQuad(); |
| 4453 | |
| 4454 | // Handle non-overloaded intrinsics first. |
| 4455 | switch (BuiltinID) { |
| 4456 | default: break; |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 4457 | case NEON::BI__builtin_neon_vldrq_p128: { |
| 4458 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 4459 | Value *Ptr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int128PTy); |
| 4460 | return Builder.CreateLoad(Ptr); |
| 4461 | } |
| 4462 | case NEON::BI__builtin_neon_vstrq_p128: { |
| 4463 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 4464 | Value *Ptr = Builder.CreateBitCast(Ops[0], Int128PTy); |
| 4465 | return Builder.CreateStore(EmitScalarExpr(E->getArg(1)), Ptr); |
| 4466 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4467 | case NEON::BI__builtin_neon_vcvts_u32_f32: |
| 4468 | case NEON::BI__builtin_neon_vcvtd_u64_f64: |
| 4469 | usgn = true; |
| 4470 | // FALL THROUGH |
| 4471 | case NEON::BI__builtin_neon_vcvts_s32_f32: |
| 4472 | case NEON::BI__builtin_neon_vcvtd_s64_f64: { |
| 4473 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4474 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 4475 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 4476 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 4477 | Ops[0] = Builder.CreateBitCast(Ops[0], FTy); |
| 4478 | if (usgn) |
| 4479 | return Builder.CreateFPToUI(Ops[0], InTy); |
| 4480 | return Builder.CreateFPToSI(Ops[0], InTy); |
| 4481 | } |
| 4482 | case NEON::BI__builtin_neon_vcvts_f32_u32: |
| 4483 | case NEON::BI__builtin_neon_vcvtd_f64_u64: |
| 4484 | usgn = true; |
| 4485 | // FALL THROUGH |
| 4486 | case NEON::BI__builtin_neon_vcvts_f32_s32: |
| 4487 | case NEON::BI__builtin_neon_vcvtd_f64_s64: { |
| 4488 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4489 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 4490 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 4491 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 4492 | Ops[0] = Builder.CreateBitCast(Ops[0], InTy); |
| 4493 | if (usgn) |
| 4494 | return Builder.CreateUIToFP(Ops[0], FTy); |
| 4495 | return Builder.CreateSIToFP(Ops[0], FTy); |
| 4496 | } |
| 4497 | case NEON::BI__builtin_neon_vpaddd_s64: { |
| 4498 | llvm::Type *Ty = |
| 4499 | llvm::VectorType::get(llvm::Type::getInt64Ty(getLLVMContext()), 2); |
| 4500 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 4501 | // The vector is v2f64, so make sure it's bitcast to that. |
| 4502 | Vec = Builder.CreateBitCast(Vec, Ty, "v2i64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4503 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 4504 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4505 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 4506 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 4507 | // Pairwise addition of a v2f64 into a scalar f64. |
| 4508 | return Builder.CreateAdd(Op0, Op1, "vpaddd"); |
| 4509 | } |
| 4510 | case NEON::BI__builtin_neon_vpaddd_f64: { |
| 4511 | llvm::Type *Ty = |
| 4512 | llvm::VectorType::get(llvm::Type::getDoubleTy(getLLVMContext()), 2); |
| 4513 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 4514 | // The vector is v2f64, so make sure it's bitcast to that. |
| 4515 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4516 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 4517 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4518 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 4519 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 4520 | // Pairwise addition of a v2f64 into a scalar f64. |
| 4521 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 4522 | } |
| 4523 | case NEON::BI__builtin_neon_vpadds_f32: { |
| 4524 | llvm::Type *Ty = |
| 4525 | llvm::VectorType::get(llvm::Type::getFloatTy(getLLVMContext()), 2); |
| 4526 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 4527 | // The vector is v2f32, so make sure it's bitcast to that. |
| 4528 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f32"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4529 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 4530 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4531 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 4532 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 4533 | // Pairwise addition of a v2f32 into a scalar f32. |
| 4534 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 4535 | } |
| 4536 | case NEON::BI__builtin_neon_vceqzd_s64: |
| 4537 | case NEON::BI__builtin_neon_vceqzd_f64: |
| 4538 | case NEON::BI__builtin_neon_vceqzs_f32: |
| 4539 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4540 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4541 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4542 | ICmpInst::FCMP_OEQ, ICmpInst::ICMP_EQ, "vceqz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4543 | case NEON::BI__builtin_neon_vcgezd_s64: |
| 4544 | case NEON::BI__builtin_neon_vcgezd_f64: |
| 4545 | case NEON::BI__builtin_neon_vcgezs_f32: |
| 4546 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4547 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4548 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4549 | ICmpInst::FCMP_OGE, ICmpInst::ICMP_SGE, "vcgez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4550 | case NEON::BI__builtin_neon_vclezd_s64: |
| 4551 | case NEON::BI__builtin_neon_vclezd_f64: |
| 4552 | case NEON::BI__builtin_neon_vclezs_f32: |
| 4553 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4554 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4555 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4556 | ICmpInst::FCMP_OLE, ICmpInst::ICMP_SLE, "vclez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4557 | case NEON::BI__builtin_neon_vcgtzd_s64: |
| 4558 | case NEON::BI__builtin_neon_vcgtzd_f64: |
| 4559 | case NEON::BI__builtin_neon_vcgtzs_f32: |
| 4560 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4561 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4562 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4563 | ICmpInst::FCMP_OGT, ICmpInst::ICMP_SGT, "vcgtz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4564 | case NEON::BI__builtin_neon_vcltzd_s64: |
| 4565 | case NEON::BI__builtin_neon_vcltzd_f64: |
| 4566 | case NEON::BI__builtin_neon_vcltzs_f32: |
| 4567 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4568 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4569 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4570 | ICmpInst::FCMP_OLT, ICmpInst::ICMP_SLT, "vcltz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4571 | |
| 4572 | case NEON::BI__builtin_neon_vceqzd_u64: { |
| 4573 | llvm::Type *Ty = llvm::Type::getInt64Ty(getLLVMContext()); |
| 4574 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4575 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4576 | Ops[0] = Builder.CreateICmp(llvm::ICmpInst::ICMP_EQ, Ops[0], |
| 4577 | llvm::Constant::getNullValue(Ty)); |
| 4578 | return Builder.CreateSExt(Ops[0], Ty, "vceqzd"); |
| 4579 | } |
| 4580 | case NEON::BI__builtin_neon_vceqd_f64: |
| 4581 | case NEON::BI__builtin_neon_vcled_f64: |
| 4582 | case NEON::BI__builtin_neon_vcltd_f64: |
| 4583 | case NEON::BI__builtin_neon_vcged_f64: |
| 4584 | case NEON::BI__builtin_neon_vcgtd_f64: { |
| 4585 | llvm::CmpInst::Predicate P; |
| 4586 | switch (BuiltinID) { |
| 4587 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 4588 | case NEON::BI__builtin_neon_vceqd_f64: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 4589 | case NEON::BI__builtin_neon_vcled_f64: P = llvm::FCmpInst::FCMP_OLE; break; |
| 4590 | case NEON::BI__builtin_neon_vcltd_f64: P = llvm::FCmpInst::FCMP_OLT; break; |
| 4591 | case NEON::BI__builtin_neon_vcged_f64: P = llvm::FCmpInst::FCMP_OGE; break; |
| 4592 | case NEON::BI__builtin_neon_vcgtd_f64: P = llvm::FCmpInst::FCMP_OGT; break; |
| 4593 | } |
| 4594 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4595 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 4596 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 4597 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 4598 | return Builder.CreateSExt(Ops[0], Int64Ty, "vcmpd"); |
| 4599 | } |
| 4600 | case NEON::BI__builtin_neon_vceqs_f32: |
| 4601 | case NEON::BI__builtin_neon_vcles_f32: |
| 4602 | case NEON::BI__builtin_neon_vclts_f32: |
| 4603 | case NEON::BI__builtin_neon_vcges_f32: |
| 4604 | case NEON::BI__builtin_neon_vcgts_f32: { |
| 4605 | llvm::CmpInst::Predicate P; |
| 4606 | switch (BuiltinID) { |
| 4607 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 4608 | case NEON::BI__builtin_neon_vceqs_f32: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 4609 | case NEON::BI__builtin_neon_vcles_f32: P = llvm::FCmpInst::FCMP_OLE; break; |
| 4610 | case NEON::BI__builtin_neon_vclts_f32: P = llvm::FCmpInst::FCMP_OLT; break; |
| 4611 | case NEON::BI__builtin_neon_vcges_f32: P = llvm::FCmpInst::FCMP_OGE; break; |
| 4612 | case NEON::BI__builtin_neon_vcgts_f32: P = llvm::FCmpInst::FCMP_OGT; break; |
| 4613 | } |
| 4614 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4615 | Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy); |
| 4616 | Ops[1] = Builder.CreateBitCast(Ops[1], FloatTy); |
| 4617 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 4618 | return Builder.CreateSExt(Ops[0], Int32Ty, "vcmpd"); |
| 4619 | } |
| 4620 | case NEON::BI__builtin_neon_vceqd_s64: |
| 4621 | case NEON::BI__builtin_neon_vceqd_u64: |
| 4622 | case NEON::BI__builtin_neon_vcgtd_s64: |
| 4623 | case NEON::BI__builtin_neon_vcgtd_u64: |
| 4624 | case NEON::BI__builtin_neon_vcltd_s64: |
| 4625 | case NEON::BI__builtin_neon_vcltd_u64: |
| 4626 | case NEON::BI__builtin_neon_vcged_u64: |
| 4627 | case NEON::BI__builtin_neon_vcged_s64: |
| 4628 | case NEON::BI__builtin_neon_vcled_u64: |
| 4629 | case NEON::BI__builtin_neon_vcled_s64: { |
| 4630 | llvm::CmpInst::Predicate P; |
| 4631 | switch (BuiltinID) { |
| 4632 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 4633 | case NEON::BI__builtin_neon_vceqd_s64: |
| 4634 | case NEON::BI__builtin_neon_vceqd_u64:P = llvm::ICmpInst::ICMP_EQ;break; |
| 4635 | case NEON::BI__builtin_neon_vcgtd_s64:P = llvm::ICmpInst::ICMP_SGT;break; |
| 4636 | case NEON::BI__builtin_neon_vcgtd_u64:P = llvm::ICmpInst::ICMP_UGT;break; |
| 4637 | case NEON::BI__builtin_neon_vcltd_s64:P = llvm::ICmpInst::ICMP_SLT;break; |
| 4638 | case NEON::BI__builtin_neon_vcltd_u64:P = llvm::ICmpInst::ICMP_ULT;break; |
| 4639 | case NEON::BI__builtin_neon_vcged_u64:P = llvm::ICmpInst::ICMP_UGE;break; |
| 4640 | case NEON::BI__builtin_neon_vcged_s64:P = llvm::ICmpInst::ICMP_SGE;break; |
| 4641 | case NEON::BI__builtin_neon_vcled_u64:P = llvm::ICmpInst::ICMP_ULE;break; |
| 4642 | case NEON::BI__builtin_neon_vcled_s64:P = llvm::ICmpInst::ICMP_SLE;break; |
| 4643 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4644 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4645 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 4646 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4647 | Ops[0] = Builder.CreateICmp(P, Ops[0], Ops[1]); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4648 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4649 | } |
| 4650 | case NEON::BI__builtin_neon_vtstd_s64: |
| 4651 | case NEON::BI__builtin_neon_vtstd_u64: { |
| 4652 | llvm::Type *Ty = llvm::Type::getInt64Ty(getLLVMContext()); |
| 4653 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4654 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4655 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4656 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 4657 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
| 4658 | llvm::Constant::getNullValue(Ty)); |
| 4659 | return Builder.CreateSExt(Ops[0], Ty, "vtstd"); |
| 4660 | } |
| 4661 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 4662 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 4663 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 4664 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 4665 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 4666 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 4667 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 4668 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 4669 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 4670 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 4671 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 4672 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 4673 | case NEON::BI__builtin_neon_vset_lane_f64: |
| 4674 | // The vector type needs a cast for the v1f64 variant. |
| 4675 | Ops[1] = Builder.CreateBitCast(Ops[1], |
| 4676 | llvm::VectorType::get(DoubleTy, 1)); |
| 4677 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 4678 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 4679 | case NEON::BI__builtin_neon_vsetq_lane_f64: |
| 4680 | // The vector type needs a cast for the v2f64 variant. |
| 4681 | Ops[1] = Builder.CreateBitCast(Ops[1], |
| 4682 | llvm::VectorType::get(llvm::Type::getDoubleTy(getLLVMContext()), 2)); |
| 4683 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 4684 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 4685 | |
| 4686 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 4687 | case NEON::BI__builtin_neon_vdupb_lane_i8: |
| 4688 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4689 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8)); |
| 4690 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4691 | "vget_lane"); |
| 4692 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 4693 | case NEON::BI__builtin_neon_vdupb_laneq_i8: |
| 4694 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4695 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16)); |
| 4696 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4697 | "vgetq_lane"); |
| 4698 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 4699 | case NEON::BI__builtin_neon_vduph_lane_i16: |
| 4700 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4701 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4)); |
| 4702 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4703 | "vget_lane"); |
| 4704 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 4705 | case NEON::BI__builtin_neon_vduph_laneq_i16: |
| 4706 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4707 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8)); |
| 4708 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4709 | "vgetq_lane"); |
| 4710 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 4711 | case NEON::BI__builtin_neon_vdups_lane_i32: |
| 4712 | Ops[0] = Builder.CreateBitCast( |
| 4713 | Ops[0], |
| 4714 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 32), 2)); |
| 4715 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4716 | "vget_lane"); |
| 4717 | case NEON::BI__builtin_neon_vdups_lane_f32: |
| 4718 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4719 | llvm::VectorType::get(llvm::Type::getFloatTy(getLLVMContext()), 2)); |
| 4720 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4721 | "vdups_lane"); |
| 4722 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 4723 | case NEON::BI__builtin_neon_vdups_laneq_i32: |
| 4724 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4725 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 32), 4)); |
| 4726 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4727 | "vgetq_lane"); |
| 4728 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 4729 | case NEON::BI__builtin_neon_vdupd_lane_i64: |
| 4730 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4731 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 64), 1)); |
| 4732 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4733 | "vget_lane"); |
| 4734 | case NEON::BI__builtin_neon_vdupd_lane_f64: |
| 4735 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4736 | llvm::VectorType::get(llvm::Type::getDoubleTy(getLLVMContext()), 1)); |
| 4737 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4738 | "vdupd_lane"); |
| 4739 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 4740 | case NEON::BI__builtin_neon_vdupd_laneq_i64: |
| 4741 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4742 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 64), 2)); |
| 4743 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4744 | "vgetq_lane"); |
| 4745 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 4746 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4747 | llvm::VectorType::get(llvm::Type::getFloatTy(getLLVMContext()), 2)); |
| 4748 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4749 | "vget_lane"); |
| 4750 | case NEON::BI__builtin_neon_vget_lane_f64: |
| 4751 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4752 | llvm::VectorType::get(llvm::Type::getDoubleTy(getLLVMContext()), 1)); |
| 4753 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4754 | "vget_lane"); |
| 4755 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 4756 | case NEON::BI__builtin_neon_vdups_laneq_f32: |
| 4757 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4758 | llvm::VectorType::get(llvm::Type::getFloatTy(getLLVMContext()), 4)); |
| 4759 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4760 | "vgetq_lane"); |
| 4761 | case NEON::BI__builtin_neon_vgetq_lane_f64: |
| 4762 | case NEON::BI__builtin_neon_vdupd_laneq_f64: |
| 4763 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 4764 | llvm::VectorType::get(llvm::Type::getDoubleTy(getLLVMContext()), 2)); |
| 4765 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 4766 | "vgetq_lane"); |
| 4767 | case NEON::BI__builtin_neon_vaddd_s64: |
| 4768 | case NEON::BI__builtin_neon_vaddd_u64: |
| 4769 | return Builder.CreateAdd(Ops[0], EmitScalarExpr(E->getArg(1)), "vaddd"); |
| 4770 | case NEON::BI__builtin_neon_vsubd_s64: |
| 4771 | case NEON::BI__builtin_neon_vsubd_u64: |
| 4772 | return Builder.CreateSub(Ops[0], EmitScalarExpr(E->getArg(1)), "vsubd"); |
| 4773 | case NEON::BI__builtin_neon_vqdmlalh_s16: |
| 4774 | case NEON::BI__builtin_neon_vqdmlslh_s16: { |
| 4775 | SmallVector<Value *, 2> ProductOps; |
| 4776 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 4777 | ProductOps.push_back(vectorWrapScalar16(EmitScalarExpr(E->getArg(2)))); |
| 4778 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4779 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4780 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4781 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4782 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 4783 | |
| 4784 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlalh_s16 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4785 | ? Intrinsic::aarch64_neon_sqadd |
| 4786 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4787 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int32Ty), Ops, "vqdmlXl"); |
| 4788 | } |
| 4789 | case NEON::BI__builtin_neon_vqshlud_n_s64: { |
| 4790 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4791 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4792 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqshlu, Int64Ty), |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 4793 | Ops, "vqshlu_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4794 | } |
| 4795 | case NEON::BI__builtin_neon_vqshld_n_u64: |
| 4796 | case NEON::BI__builtin_neon_vqshld_n_s64: { |
| 4797 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vqshld_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4798 | ? Intrinsic::aarch64_neon_uqshl |
| 4799 | : Intrinsic::aarch64_neon_sqshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4800 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4801 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 4802 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vqshl_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4803 | } |
| 4804 | case NEON::BI__builtin_neon_vrshrd_n_u64: |
| 4805 | case NEON::BI__builtin_neon_vrshrd_n_s64: { |
| 4806 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4807 | ? Intrinsic::aarch64_neon_urshl |
| 4808 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4809 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 4810 | int SV = cast<ConstantInt>(Ops[1])->getSExtValue(); |
| 4811 | Ops[1] = ConstantInt::get(Int64Ty, -SV); |
| 4812 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vrshr_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4813 | } |
| 4814 | case NEON::BI__builtin_neon_vrsrad_n_u64: |
| 4815 | case NEON::BI__builtin_neon_vrsrad_n_s64: { |
| 4816 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrsrad_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4817 | ? Intrinsic::aarch64_neon_urshl |
| 4818 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4819 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
| 4820 | Ops.push_back(Builder.CreateNeg(EmitScalarExpr(E->getArg(2)))); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4821 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Int64Ty), |
| 4822 | {Ops[1], Builder.CreateSExt(Ops[2], Int64Ty)}); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4823 | return Builder.CreateAdd(Ops[0], Builder.CreateBitCast(Ops[1], Int64Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4824 | } |
| 4825 | case NEON::BI__builtin_neon_vshld_n_s64: |
| 4826 | case NEON::BI__builtin_neon_vshld_n_u64: { |
| 4827 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 4828 | return Builder.CreateShl( |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 4829 | Ops[0], ConstantInt::get(Int64Ty, Amt->getZExtValue()), "shld_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4830 | } |
| 4831 | case NEON::BI__builtin_neon_vshrd_n_s64: { |
| 4832 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 4833 | return Builder.CreateAShr( |
| 4834 | Ops[0], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 4835 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 4836 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4837 | } |
| 4838 | case NEON::BI__builtin_neon_vshrd_n_u64: { |
| 4839 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 4840 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 4841 | // Right-shifting an unsigned value by its size yields 0. |
| 4842 | if (ShiftAmt == 64) |
| 4843 | return ConstantInt::get(Int64Ty, 0); |
| 4844 | return Builder.CreateLShr(Ops[0], ConstantInt::get(Int64Ty, ShiftAmt), |
| 4845 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4846 | } |
| 4847 | case NEON::BI__builtin_neon_vsrad_n_s64: { |
| 4848 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
| 4849 | Ops[1] = Builder.CreateAShr( |
| 4850 | Ops[1], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 4851 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 4852 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4853 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 4854 | } |
| 4855 | case NEON::BI__builtin_neon_vsrad_n_u64: { |
| 4856 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 4857 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 4858 | // Right-shifting an unsigned value by its size yields 0. |
| 4859 | // As Op + 0 = Op, return Ops[0] directly. |
| 4860 | if (ShiftAmt == 64) |
| 4861 | return Ops[0]; |
| 4862 | Ops[1] = Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, ShiftAmt), |
| 4863 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4864 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 4865 | } |
| 4866 | case NEON::BI__builtin_neon_vqdmlalh_lane_s16: |
| 4867 | case NEON::BI__builtin_neon_vqdmlalh_laneq_s16: |
| 4868 | case NEON::BI__builtin_neon_vqdmlslh_lane_s16: |
| 4869 | case NEON::BI__builtin_neon_vqdmlslh_laneq_s16: { |
| 4870 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 4871 | "lane"); |
| 4872 | SmallVector<Value *, 2> ProductOps; |
| 4873 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 4874 | ProductOps.push_back(vectorWrapScalar16(Ops[2])); |
| 4875 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4876 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4877 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4878 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4879 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 4880 | Ops.pop_back(); |
| 4881 | |
| 4882 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlalh_lane_s16 || |
| 4883 | BuiltinID == NEON::BI__builtin_neon_vqdmlalh_laneq_s16) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4884 | ? Intrinsic::aarch64_neon_sqadd |
| 4885 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4886 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int32Ty), Ops, "vqdmlXl"); |
| 4887 | } |
| 4888 | case NEON::BI__builtin_neon_vqdmlals_s32: |
| 4889 | case NEON::BI__builtin_neon_vqdmlsls_s32: { |
| 4890 | SmallVector<Value *, 2> ProductOps; |
| 4891 | ProductOps.push_back(Ops[1]); |
| 4892 | ProductOps.push_back(EmitScalarExpr(E->getArg(2))); |
| 4893 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4894 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4895 | ProductOps, "vqdmlXl"); |
| 4896 | |
| 4897 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlals_s32 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4898 | ? Intrinsic::aarch64_neon_sqadd |
| 4899 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4900 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int64Ty), Ops, "vqdmlXl"); |
| 4901 | } |
| 4902 | case NEON::BI__builtin_neon_vqdmlals_lane_s32: |
| 4903 | case NEON::BI__builtin_neon_vqdmlals_laneq_s32: |
| 4904 | case NEON::BI__builtin_neon_vqdmlsls_lane_s32: |
| 4905 | case NEON::BI__builtin_neon_vqdmlsls_laneq_s32: { |
| 4906 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 4907 | "lane"); |
| 4908 | SmallVector<Value *, 2> ProductOps; |
| 4909 | ProductOps.push_back(Ops[1]); |
| 4910 | ProductOps.push_back(Ops[2]); |
| 4911 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4912 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4913 | ProductOps, "vqdmlXl"); |
| 4914 | Ops.pop_back(); |
| 4915 | |
| 4916 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlals_lane_s32 || |
| 4917 | BuiltinID == NEON::BI__builtin_neon_vqdmlals_laneq_s32) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4918 | ? Intrinsic::aarch64_neon_sqadd |
| 4919 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4920 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int64Ty), Ops, "vqdmlXl"); |
| 4921 | } |
| 4922 | } |
| 4923 | |
| 4924 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 4925 | llvm::Type *Ty = VTy; |
| 4926 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4927 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4928 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4929 | // Not all intrinsics handled by the common case work for AArch64 yet, so only |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4930 | // defer to common code if it's been added to our special map. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4931 | Builtin = findNeonIntrinsicInMap(AArch64SIMDIntrinsicMap, BuiltinID, |
| 4932 | AArch64SIMDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4933 | |
| 4934 | if (Builtin) |
| 4935 | return EmitCommonNeonBuiltinExpr( |
| 4936 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4937 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, nullptr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4938 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4939 | if (Value *V = EmitAArch64TblBuiltinExpr(*this, BuiltinID, E, Ops)) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4940 | return V; |
| 4941 | |
| 4942 | unsigned Int; |
| 4943 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4944 | default: return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4945 | case NEON::BI__builtin_neon_vbsl_v: |
| 4946 | case NEON::BI__builtin_neon_vbslq_v: { |
| 4947 | llvm::Type *BitTy = llvm::VectorType::getInteger(VTy); |
| 4948 | Ops[0] = Builder.CreateBitCast(Ops[0], BitTy, "vbsl"); |
| 4949 | Ops[1] = Builder.CreateBitCast(Ops[1], BitTy, "vbsl"); |
| 4950 | Ops[2] = Builder.CreateBitCast(Ops[2], BitTy, "vbsl"); |
| 4951 | |
| 4952 | Ops[1] = Builder.CreateAnd(Ops[0], Ops[1], "vbsl"); |
| 4953 | Ops[2] = Builder.CreateAnd(Builder.CreateNot(Ops[0]), Ops[2], "vbsl"); |
| 4954 | Ops[0] = Builder.CreateOr(Ops[1], Ops[2], "vbsl"); |
| 4955 | return Builder.CreateBitCast(Ops[0], Ty); |
| 4956 | } |
| 4957 | case NEON::BI__builtin_neon_vfma_lane_v: |
| 4958 | case NEON::BI__builtin_neon_vfmaq_lane_v: { // Only used for FP types |
| 4959 | // The ARM builtins (and instructions) have the addend as the first |
| 4960 | // operand, but the 'fma' intrinsics have it last. Swap it around here. |
| 4961 | Value *Addend = Ops[0]; |
| 4962 | Value *Multiplicand = Ops[1]; |
| 4963 | Value *LaneSource = Ops[2]; |
| 4964 | Ops[0] = Multiplicand; |
| 4965 | Ops[1] = LaneSource; |
| 4966 | Ops[2] = Addend; |
| 4967 | |
| 4968 | // Now adjust things to handle the lane access. |
| 4969 | llvm::Type *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v ? |
| 4970 | llvm::VectorType::get(VTy->getElementType(), VTy->getNumElements() / 2) : |
| 4971 | VTy; |
| 4972 | llvm::Constant *cst = cast<Constant>(Ops[3]); |
| 4973 | Value *SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), cst); |
| 4974 | Ops[1] = Builder.CreateBitCast(Ops[1], SourceTy); |
| 4975 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV, "lane"); |
| 4976 | |
| 4977 | Ops.pop_back(); |
| 4978 | Int = Intrinsic::fma; |
| 4979 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmla"); |
| 4980 | } |
| 4981 | case NEON::BI__builtin_neon_vfma_laneq_v: { |
| 4982 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 4983 | // v1f64 fma should be mapped to Neon scalar f64 fma |
| 4984 | if (VTy && VTy->getElementType() == DoubleTy) { |
| 4985 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 4986 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 4987 | llvm::Type *VTy = GetNeonType(this, |
| 4988 | NeonTypeFlags(NeonTypeFlags::Float64, false, true)); |
| 4989 | Ops[2] = Builder.CreateBitCast(Ops[2], VTy); |
| 4990 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
| 4991 | Value *F = CGM.getIntrinsic(Intrinsic::fma, DoubleTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4992 | Value *Result = Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4993 | return Builder.CreateBitCast(Result, Ty); |
| 4994 | } |
| 4995 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 4996 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4997 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4998 | |
| 4999 | llvm::Type *STy = llvm::VectorType::get(VTy->getElementType(), |
| 5000 | VTy->getNumElements() * 2); |
| 5001 | Ops[2] = Builder.CreateBitCast(Ops[2], STy); |
| 5002 | Value* SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), |
| 5003 | cast<ConstantInt>(Ops[3])); |
| 5004 | Ops[2] = Builder.CreateShuffleVector(Ops[2], Ops[2], SV, "lane"); |
| 5005 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5006 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5007 | } |
| 5008 | case NEON::BI__builtin_neon_vfmaq_laneq_v: { |
| 5009 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5010 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5011 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5012 | |
| 5013 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 5014 | Ops[2] = EmitNeonSplat(Ops[2], cast<ConstantInt>(Ops[3])); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5015 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5016 | } |
| 5017 | case NEON::BI__builtin_neon_vfmas_lane_f32: |
| 5018 | case NEON::BI__builtin_neon_vfmas_laneq_f32: |
| 5019 | case NEON::BI__builtin_neon_vfmad_lane_f64: |
| 5020 | case NEON::BI__builtin_neon_vfmad_laneq_f64: { |
| 5021 | Ops.push_back(EmitScalarExpr(E->getArg(3))); |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5022 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5023 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5024 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5025 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5026 | } |
| 5027 | case NEON::BI__builtin_neon_vfms_v: |
| 5028 | case NEON::BI__builtin_neon_vfmsq_v: { // Only used for FP types |
| 5029 | // FIXME: probably remove when we no longer support aarch64_simd.h |
| 5030 | // (arm_neon.h delegates to vfma). |
| 5031 | |
| 5032 | // The ARM builtins (and instructions) have the addend as the first |
| 5033 | // operand, but the 'fma' intrinsics have it last. Swap it around here. |
| 5034 | Value *Subtrahend = Ops[0]; |
| 5035 | Value *Multiplicand = Ops[2]; |
| 5036 | Ops[0] = Multiplicand; |
| 5037 | Ops[2] = Subtrahend; |
| 5038 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 5039 | Ops[1] = Builder.CreateFNeg(Ops[1]); |
| 5040 | Int = Intrinsic::fma; |
| 5041 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmls"); |
| 5042 | } |
| 5043 | case NEON::BI__builtin_neon_vmull_v: |
| 5044 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5045 | Int = usgn ? Intrinsic::aarch64_neon_umull : Intrinsic::aarch64_neon_smull; |
| 5046 | if (Type.isPoly()) Int = Intrinsic::aarch64_neon_pmull; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5047 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 5048 | case NEON::BI__builtin_neon_vmax_v: |
| 5049 | case NEON::BI__builtin_neon_vmaxq_v: |
| 5050 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5051 | Int = usgn ? Intrinsic::aarch64_neon_umax : Intrinsic::aarch64_neon_smax; |
| 5052 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmax; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5053 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmax"); |
| 5054 | case NEON::BI__builtin_neon_vmin_v: |
| 5055 | case NEON::BI__builtin_neon_vminq_v: |
| 5056 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5057 | Int = usgn ? Intrinsic::aarch64_neon_umin : Intrinsic::aarch64_neon_smin; |
| 5058 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmin; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5059 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmin"); |
| 5060 | case NEON::BI__builtin_neon_vabd_v: |
| 5061 | case NEON::BI__builtin_neon_vabdq_v: |
| 5062 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5063 | Int = usgn ? Intrinsic::aarch64_neon_uabd : Intrinsic::aarch64_neon_sabd; |
| 5064 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fabd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5065 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vabd"); |
| 5066 | case NEON::BI__builtin_neon_vpadal_v: |
| 5067 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 5068 | unsigned ArgElts = VTy->getNumElements(); |
| 5069 | llvm::IntegerType *EltTy = cast<IntegerType>(VTy->getElementType()); |
| 5070 | unsigned BitWidth = EltTy->getBitWidth(); |
| 5071 | llvm::Type *ArgTy = llvm::VectorType::get( |
| 5072 | llvm::IntegerType::get(getLLVMContext(), BitWidth/2), 2*ArgElts); |
| 5073 | llvm::Type* Tys[2] = { VTy, ArgTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5074 | Int = usgn ? Intrinsic::aarch64_neon_uaddlp : Intrinsic::aarch64_neon_saddlp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5075 | SmallVector<llvm::Value*, 1> TmpOps; |
| 5076 | TmpOps.push_back(Ops[1]); |
| 5077 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 5078 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vpadal"); |
| 5079 | llvm::Value *addend = Builder.CreateBitCast(Ops[0], tmp->getType()); |
| 5080 | return Builder.CreateAdd(tmp, addend); |
| 5081 | } |
| 5082 | case NEON::BI__builtin_neon_vpmin_v: |
| 5083 | case NEON::BI__builtin_neon_vpminq_v: |
| 5084 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5085 | Int = usgn ? Intrinsic::aarch64_neon_uminp : Intrinsic::aarch64_neon_sminp; |
| 5086 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fminp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5087 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmin"); |
| 5088 | case NEON::BI__builtin_neon_vpmax_v: |
| 5089 | case NEON::BI__builtin_neon_vpmaxq_v: |
| 5090 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5091 | Int = usgn ? Intrinsic::aarch64_neon_umaxp : Intrinsic::aarch64_neon_smaxp; |
| 5092 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmaxp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5093 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmax"); |
| 5094 | case NEON::BI__builtin_neon_vminnm_v: |
| 5095 | case NEON::BI__builtin_neon_vminnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5096 | Int = Intrinsic::aarch64_neon_fminnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5097 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vminnm"); |
| 5098 | case NEON::BI__builtin_neon_vmaxnm_v: |
| 5099 | case NEON::BI__builtin_neon_vmaxnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5100 | Int = Intrinsic::aarch64_neon_fmaxnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5101 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmaxnm"); |
| 5102 | case NEON::BI__builtin_neon_vrecpss_f32: { |
| 5103 | llvm::Type *f32Type = llvm::Type::getFloatTy(getLLVMContext()); |
| 5104 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5105 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, f32Type), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5106 | Ops, "vrecps"); |
| 5107 | } |
| 5108 | case NEON::BI__builtin_neon_vrecpsd_f64: { |
| 5109 | llvm::Type *f64Type = llvm::Type::getDoubleTy(getLLVMContext()); |
| 5110 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5111 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, f64Type), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5112 | Ops, "vrecps"); |
| 5113 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5114 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5115 | Int = Intrinsic::aarch64_neon_sqshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5116 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrun_n"); |
| 5117 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5118 | Int = Intrinsic::aarch64_neon_sqrshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5119 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrun_n"); |
| 5120 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5121 | Int = usgn ? Intrinsic::aarch64_neon_uqshrn : Intrinsic::aarch64_neon_sqshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5122 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n"); |
| 5123 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5124 | Int = Intrinsic::aarch64_neon_rshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5125 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshrn_n"); |
| 5126 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5127 | Int = usgn ? Intrinsic::aarch64_neon_uqrshrn : Intrinsic::aarch64_neon_sqrshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5128 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n"); |
| 5129 | case NEON::BI__builtin_neon_vrnda_v: |
| 5130 | case NEON::BI__builtin_neon_vrndaq_v: { |
| 5131 | Int = Intrinsic::round; |
| 5132 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnda"); |
| 5133 | } |
| 5134 | case NEON::BI__builtin_neon_vrndi_v: |
| 5135 | case NEON::BI__builtin_neon_vrndiq_v: { |
| 5136 | Int = Intrinsic::nearbyint; |
| 5137 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndi"); |
| 5138 | } |
| 5139 | case NEON::BI__builtin_neon_vrndm_v: |
| 5140 | case NEON::BI__builtin_neon_vrndmq_v: { |
| 5141 | Int = Intrinsic::floor; |
| 5142 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndm"); |
| 5143 | } |
| 5144 | case NEON::BI__builtin_neon_vrndn_v: |
| 5145 | case NEON::BI__builtin_neon_vrndnq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5146 | Int = Intrinsic::aarch64_neon_frintn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5147 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndn"); |
| 5148 | } |
| 5149 | case NEON::BI__builtin_neon_vrndp_v: |
| 5150 | case NEON::BI__builtin_neon_vrndpq_v: { |
| 5151 | Int = Intrinsic::ceil; |
| 5152 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndp"); |
| 5153 | } |
| 5154 | case NEON::BI__builtin_neon_vrndx_v: |
| 5155 | case NEON::BI__builtin_neon_vrndxq_v: { |
| 5156 | Int = Intrinsic::rint; |
| 5157 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndx"); |
| 5158 | } |
| 5159 | case NEON::BI__builtin_neon_vrnd_v: |
| 5160 | case NEON::BI__builtin_neon_vrndq_v: { |
| 5161 | Int = Intrinsic::trunc; |
| 5162 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndz"); |
| 5163 | } |
| 5164 | case NEON::BI__builtin_neon_vceqz_v: |
| 5165 | case NEON::BI__builtin_neon_vceqzq_v: |
| 5166 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OEQ, |
| 5167 | ICmpInst::ICMP_EQ, "vceqz"); |
| 5168 | case NEON::BI__builtin_neon_vcgez_v: |
| 5169 | case NEON::BI__builtin_neon_vcgezq_v: |
| 5170 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGE, |
| 5171 | ICmpInst::ICMP_SGE, "vcgez"); |
| 5172 | case NEON::BI__builtin_neon_vclez_v: |
| 5173 | case NEON::BI__builtin_neon_vclezq_v: |
| 5174 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLE, |
| 5175 | ICmpInst::ICMP_SLE, "vclez"); |
| 5176 | case NEON::BI__builtin_neon_vcgtz_v: |
| 5177 | case NEON::BI__builtin_neon_vcgtzq_v: |
| 5178 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGT, |
| 5179 | ICmpInst::ICMP_SGT, "vcgtz"); |
| 5180 | case NEON::BI__builtin_neon_vcltz_v: |
| 5181 | case NEON::BI__builtin_neon_vcltzq_v: |
| 5182 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLT, |
| 5183 | ICmpInst::ICMP_SLT, "vcltz"); |
| 5184 | case NEON::BI__builtin_neon_vcvt_f64_v: |
| 5185 | case NEON::BI__builtin_neon_vcvtq_f64_v: |
| 5186 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5187 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float64, false, quad)); |
| 5188 | return usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 5189 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 5190 | case NEON::BI__builtin_neon_vcvt_f64_f32: { |
| 5191 | assert(Type.getEltType() == NeonTypeFlags::Float64 && quad && |
| 5192 | "unexpected vcvt_f64_f32 builtin"); |
| 5193 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float32, false, false); |
| 5194 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 5195 | |
| 5196 | return Builder.CreateFPExt(Ops[0], Ty, "vcvt"); |
| 5197 | } |
| 5198 | case NEON::BI__builtin_neon_vcvt_f32_f64: { |
| 5199 | assert(Type.getEltType() == NeonTypeFlags::Float32 && |
| 5200 | "unexpected vcvt_f32_f64 builtin"); |
| 5201 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float64, false, true); |
| 5202 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 5203 | |
| 5204 | return Builder.CreateFPTrunc(Ops[0], Ty, "vcvt"); |
| 5205 | } |
| 5206 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 5207 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 5208 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 5209 | case NEON::BI__builtin_neon_vcvt_u64_v: |
| 5210 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 5211 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 5212 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
| 5213 | case NEON::BI__builtin_neon_vcvtq_u64_v: { |
| 5214 | bool Double = |
| 5215 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 5216 | llvm::Type *InTy = |
| 5217 | GetNeonType(this, |
| 5218 | NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 5219 | : NeonTypeFlags::Float32, false, quad)); |
| 5220 | Ops[0] = Builder.CreateBitCast(Ops[0], InTy); |
| 5221 | if (usgn) |
| 5222 | return Builder.CreateFPToUI(Ops[0], Ty); |
| 5223 | return Builder.CreateFPToSI(Ops[0], Ty); |
| 5224 | } |
| 5225 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 5226 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 5227 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 5228 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 5229 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 5230 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 5231 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 5232 | case NEON::BI__builtin_neon_vcvtaq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5233 | Int = usgn ? Intrinsic::aarch64_neon_fcvtau : Intrinsic::aarch64_neon_fcvtas; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5234 | bool Double = |
| 5235 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 5236 | llvm::Type *InTy = |
| 5237 | GetNeonType(this, |
| 5238 | NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 5239 | : NeonTypeFlags::Float32, false, quad)); |
| 5240 | llvm::Type *Tys[2] = { Ty, InTy }; |
| 5241 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvta"); |
| 5242 | } |
| 5243 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 5244 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 5245 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 5246 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 5247 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 5248 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 5249 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 5250 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5251 | Int = usgn ? Intrinsic::aarch64_neon_fcvtmu : Intrinsic::aarch64_neon_fcvtms; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5252 | bool Double = |
| 5253 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 5254 | llvm::Type *InTy = |
| 5255 | GetNeonType(this, |
| 5256 | NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 5257 | : NeonTypeFlags::Float32, false, quad)); |
| 5258 | llvm::Type *Tys[2] = { Ty, InTy }; |
| 5259 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtm"); |
| 5260 | } |
| 5261 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 5262 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 5263 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 5264 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 5265 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 5266 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 5267 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 5268 | case NEON::BI__builtin_neon_vcvtnq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5269 | Int = usgn ? Intrinsic::aarch64_neon_fcvtnu : Intrinsic::aarch64_neon_fcvtns; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5270 | bool Double = |
| 5271 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 5272 | llvm::Type *InTy = |
| 5273 | GetNeonType(this, |
| 5274 | NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 5275 | : NeonTypeFlags::Float32, false, quad)); |
| 5276 | llvm::Type *Tys[2] = { Ty, InTy }; |
| 5277 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtn"); |
| 5278 | } |
| 5279 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 5280 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 5281 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 5282 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 5283 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 5284 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 5285 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 5286 | case NEON::BI__builtin_neon_vcvtpq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5287 | Int = usgn ? Intrinsic::aarch64_neon_fcvtpu : Intrinsic::aarch64_neon_fcvtps; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5288 | bool Double = |
| 5289 | (cast<llvm::IntegerType>(VTy->getElementType())->getBitWidth() == 64); |
| 5290 | llvm::Type *InTy = |
| 5291 | GetNeonType(this, |
| 5292 | NeonTypeFlags(Double ? NeonTypeFlags::Float64 |
| 5293 | : NeonTypeFlags::Float32, false, quad)); |
| 5294 | llvm::Type *Tys[2] = { Ty, InTy }; |
| 5295 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtp"); |
| 5296 | } |
| 5297 | case NEON::BI__builtin_neon_vmulx_v: |
| 5298 | case NEON::BI__builtin_neon_vmulxq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5299 | Int = Intrinsic::aarch64_neon_fmulx; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5300 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmulx"); |
| 5301 | } |
| 5302 | case NEON::BI__builtin_neon_vmul_lane_v: |
| 5303 | case NEON::BI__builtin_neon_vmul_laneq_v: { |
| 5304 | // v1f64 vmul_lane should be mapped to Neon scalar mul lane |
| 5305 | bool Quad = false; |
| 5306 | if (BuiltinID == NEON::BI__builtin_neon_vmul_laneq_v) |
| 5307 | Quad = true; |
| 5308 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5309 | llvm::Type *VTy = GetNeonType(this, |
| 5310 | NeonTypeFlags(NeonTypeFlags::Float64, false, Quad)); |
| 5311 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 5312 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2], "extract"); |
| 5313 | Value *Result = Builder.CreateFMul(Ops[0], Ops[1]); |
| 5314 | return Builder.CreateBitCast(Result, Ty); |
| 5315 | } |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5316 | case NEON::BI__builtin_neon_vnegd_s64: |
| 5317 | return Builder.CreateNeg(EmitScalarExpr(E->getArg(0)), "vnegd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5318 | case NEON::BI__builtin_neon_vpmaxnm_v: |
| 5319 | case NEON::BI__builtin_neon_vpmaxnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5320 | Int = Intrinsic::aarch64_neon_fmaxnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5321 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmaxnm"); |
| 5322 | } |
| 5323 | case NEON::BI__builtin_neon_vpminnm_v: |
| 5324 | case NEON::BI__builtin_neon_vpminnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5325 | Int = Intrinsic::aarch64_neon_fminnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5326 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpminnm"); |
| 5327 | } |
| 5328 | case NEON::BI__builtin_neon_vsqrt_v: |
| 5329 | case NEON::BI__builtin_neon_vsqrtq_v: { |
| 5330 | Int = Intrinsic::sqrt; |
| 5331 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5332 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqrt"); |
| 5333 | } |
| 5334 | case NEON::BI__builtin_neon_vrbit_v: |
| 5335 | case NEON::BI__builtin_neon_vrbitq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5336 | Int = Intrinsic::aarch64_neon_rbit; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5337 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrbit"); |
| 5338 | } |
| 5339 | case NEON::BI__builtin_neon_vaddv_u8: |
| 5340 | // FIXME: These are handled by the AArch64 scalar code. |
| 5341 | usgn = true; |
| 5342 | // FALLTHROUGH |
| 5343 | case NEON::BI__builtin_neon_vaddv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5344 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5345 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5346 | VTy = |
| 5347 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5348 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5349 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5350 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
| 5351 | return Builder.CreateTrunc(Ops[0], |
| 5352 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5353 | } |
| 5354 | case NEON::BI__builtin_neon_vaddv_u16: |
| 5355 | usgn = true; |
| 5356 | // FALLTHROUGH |
| 5357 | case NEON::BI__builtin_neon_vaddv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5358 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5359 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5360 | VTy = |
| 5361 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5362 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5363 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5364 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
| 5365 | return Builder.CreateTrunc(Ops[0], |
| 5366 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5367 | } |
| 5368 | case NEON::BI__builtin_neon_vaddvq_u8: |
| 5369 | usgn = true; |
| 5370 | // FALLTHROUGH |
| 5371 | case NEON::BI__builtin_neon_vaddvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5372 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5373 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5374 | VTy = |
| 5375 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5376 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5377 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5378 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
| 5379 | return Builder.CreateTrunc(Ops[0], |
| 5380 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5381 | } |
| 5382 | case NEON::BI__builtin_neon_vaddvq_u16: |
| 5383 | usgn = true; |
| 5384 | // FALLTHROUGH |
| 5385 | case NEON::BI__builtin_neon_vaddvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5386 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5387 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5388 | VTy = |
| 5389 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5390 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5391 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5392 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
| 5393 | return Builder.CreateTrunc(Ops[0], |
| 5394 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5395 | } |
| 5396 | case NEON::BI__builtin_neon_vmaxv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5397 | Int = Intrinsic::aarch64_neon_umaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5398 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5399 | VTy = |
| 5400 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5401 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5402 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5403 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5404 | return Builder.CreateTrunc(Ops[0], |
| 5405 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5406 | } |
| 5407 | case NEON::BI__builtin_neon_vmaxv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5408 | Int = Intrinsic::aarch64_neon_umaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5409 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5410 | VTy = |
| 5411 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5412 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5413 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5414 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5415 | return Builder.CreateTrunc(Ops[0], |
| 5416 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5417 | } |
| 5418 | case NEON::BI__builtin_neon_vmaxvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5419 | Int = Intrinsic::aarch64_neon_umaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5420 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5421 | VTy = |
| 5422 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5423 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5424 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5425 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5426 | return Builder.CreateTrunc(Ops[0], |
| 5427 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5428 | } |
| 5429 | case NEON::BI__builtin_neon_vmaxvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5430 | Int = Intrinsic::aarch64_neon_umaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5431 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5432 | VTy = |
| 5433 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5434 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5435 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5436 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5437 | return Builder.CreateTrunc(Ops[0], |
| 5438 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5439 | } |
| 5440 | case NEON::BI__builtin_neon_vmaxv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5441 | Int = Intrinsic::aarch64_neon_smaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5442 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5443 | VTy = |
| 5444 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5445 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5446 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5447 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5448 | return Builder.CreateTrunc(Ops[0], |
| 5449 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5450 | } |
| 5451 | case NEON::BI__builtin_neon_vmaxv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5452 | Int = Intrinsic::aarch64_neon_smaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5453 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5454 | VTy = |
| 5455 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5456 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5457 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5458 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5459 | return Builder.CreateTrunc(Ops[0], |
| 5460 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5461 | } |
| 5462 | case NEON::BI__builtin_neon_vmaxvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5463 | Int = Intrinsic::aarch64_neon_smaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5464 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5465 | VTy = |
| 5466 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5467 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5468 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5469 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5470 | return Builder.CreateTrunc(Ops[0], |
| 5471 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5472 | } |
| 5473 | case NEON::BI__builtin_neon_vmaxvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5474 | Int = Intrinsic::aarch64_neon_smaxv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5475 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5476 | VTy = |
| 5477 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5478 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5479 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5480 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 5481 | return Builder.CreateTrunc(Ops[0], |
| 5482 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5483 | } |
| 5484 | case NEON::BI__builtin_neon_vminv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5485 | Int = Intrinsic::aarch64_neon_uminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5486 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5487 | VTy = |
| 5488 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5489 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5490 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5491 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5492 | return Builder.CreateTrunc(Ops[0], |
| 5493 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5494 | } |
| 5495 | case NEON::BI__builtin_neon_vminv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5496 | Int = Intrinsic::aarch64_neon_uminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5497 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5498 | VTy = |
| 5499 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5500 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5501 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5502 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5503 | return Builder.CreateTrunc(Ops[0], |
| 5504 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5505 | } |
| 5506 | case NEON::BI__builtin_neon_vminvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5507 | Int = Intrinsic::aarch64_neon_uminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5508 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5509 | VTy = |
| 5510 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5511 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5512 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5513 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5514 | return Builder.CreateTrunc(Ops[0], |
| 5515 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5516 | } |
| 5517 | case NEON::BI__builtin_neon_vminvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5518 | Int = Intrinsic::aarch64_neon_uminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5519 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5520 | VTy = |
| 5521 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5522 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5523 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5524 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5525 | return Builder.CreateTrunc(Ops[0], |
| 5526 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5527 | } |
| 5528 | case NEON::BI__builtin_neon_vminv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5529 | Int = Intrinsic::aarch64_neon_sminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5530 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5531 | VTy = |
| 5532 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5533 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5534 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5535 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5536 | return Builder.CreateTrunc(Ops[0], |
| 5537 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5538 | } |
| 5539 | case NEON::BI__builtin_neon_vminv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5540 | Int = Intrinsic::aarch64_neon_sminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5541 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5542 | VTy = |
| 5543 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5544 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5545 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5546 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5547 | return Builder.CreateTrunc(Ops[0], |
| 5548 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5549 | } |
| 5550 | case NEON::BI__builtin_neon_vminvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5551 | Int = Intrinsic::aarch64_neon_sminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5552 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5553 | VTy = |
| 5554 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5555 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5556 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5557 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5558 | return Builder.CreateTrunc(Ops[0], |
| 5559 | llvm::IntegerType::get(getLLVMContext(), 8)); |
| 5560 | } |
| 5561 | case NEON::BI__builtin_neon_vminvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5562 | Int = Intrinsic::aarch64_neon_sminv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5563 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5564 | VTy = |
| 5565 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5566 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5567 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5568 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 5569 | return Builder.CreateTrunc(Ops[0], |
| 5570 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5571 | } |
| 5572 | case NEON::BI__builtin_neon_vmul_n_f64: { |
| 5573 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5574 | Value *RHS = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), DoubleTy); |
| 5575 | return Builder.CreateFMul(Ops[0], RHS); |
| 5576 | } |
| 5577 | case NEON::BI__builtin_neon_vaddlv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5578 | Int = Intrinsic::aarch64_neon_uaddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5579 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5580 | VTy = |
| 5581 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5582 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5583 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5584 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5585 | return Builder.CreateTrunc(Ops[0], |
| 5586 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5587 | } |
| 5588 | case NEON::BI__builtin_neon_vaddlv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5589 | Int = Intrinsic::aarch64_neon_uaddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5590 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5591 | VTy = |
| 5592 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5593 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5594 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5595 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5596 | } |
| 5597 | case NEON::BI__builtin_neon_vaddlvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5598 | Int = Intrinsic::aarch64_neon_uaddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5599 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5600 | VTy = |
| 5601 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5602 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5603 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5604 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5605 | return Builder.CreateTrunc(Ops[0], |
| 5606 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5607 | } |
| 5608 | case NEON::BI__builtin_neon_vaddlvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5609 | Int = Intrinsic::aarch64_neon_uaddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5610 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5611 | VTy = |
| 5612 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5613 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5614 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5615 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5616 | } |
| 5617 | case NEON::BI__builtin_neon_vaddlv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5618 | Int = Intrinsic::aarch64_neon_saddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5619 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5620 | VTy = |
| 5621 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 8); |
| 5622 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5623 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5624 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5625 | return Builder.CreateTrunc(Ops[0], |
| 5626 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5627 | } |
| 5628 | case NEON::BI__builtin_neon_vaddlv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5629 | Int = Intrinsic::aarch64_neon_saddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5630 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5631 | VTy = |
| 5632 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 4); |
| 5633 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5634 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5635 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5636 | } |
| 5637 | case NEON::BI__builtin_neon_vaddlvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5638 | Int = Intrinsic::aarch64_neon_saddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5639 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5640 | VTy = |
| 5641 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 8), 16); |
| 5642 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5643 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5644 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5645 | return Builder.CreateTrunc(Ops[0], |
| 5646 | llvm::IntegerType::get(getLLVMContext(), 16)); |
| 5647 | } |
| 5648 | case NEON::BI__builtin_neon_vaddlvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5649 | Int = Intrinsic::aarch64_neon_saddlv; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5650 | Ty = llvm::IntegerType::get(getLLVMContext(), 32); |
| 5651 | VTy = |
| 5652 | llvm::VectorType::get(llvm::IntegerType::get(getLLVMContext(), 16), 8); |
| 5653 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5654 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5655 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5656 | } |
| 5657 | case NEON::BI__builtin_neon_vsri_n_v: |
| 5658 | case NEON::BI__builtin_neon_vsriq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5659 | Int = Intrinsic::aarch64_neon_vsri; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5660 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 5661 | return EmitNeonCall(Intrin, Ops, "vsri_n"); |
| 5662 | } |
| 5663 | case NEON::BI__builtin_neon_vsli_n_v: |
| 5664 | case NEON::BI__builtin_neon_vsliq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5665 | Int = Intrinsic::aarch64_neon_vsli; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5666 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 5667 | return EmitNeonCall(Intrin, Ops, "vsli_n"); |
| 5668 | } |
| 5669 | case NEON::BI__builtin_neon_vsra_n_v: |
| 5670 | case NEON::BI__builtin_neon_vsraq_n_v: |
| 5671 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5672 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
| 5673 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 5674 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 5675 | case NEON::BI__builtin_neon_vrsraq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5676 | Int = usgn ? Intrinsic::aarch64_neon_urshl : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5677 | SmallVector<llvm::Value*,2> TmpOps; |
| 5678 | TmpOps.push_back(Ops[1]); |
| 5679 | TmpOps.push_back(Ops[2]); |
| 5680 | Function* F = CGM.getIntrinsic(Int, Ty); |
| 5681 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vrshr_n", 1, true); |
| 5682 | Ops[0] = Builder.CreateBitCast(Ops[0], VTy); |
| 5683 | return Builder.CreateAdd(Ops[0], tmp); |
| 5684 | } |
| 5685 | // FIXME: Sharing loads & stores with 32-bit is complicated by the absence |
| 5686 | // of an Align parameter here. |
| 5687 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 5688 | case NEON::BI__builtin_neon_vld1q_x2_v: |
| 5689 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 5690 | case NEON::BI__builtin_neon_vld1q_x3_v: |
| 5691 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 5692 | case NEON::BI__builtin_neon_vld1q_x4_v: { |
| 5693 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 5694 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5695 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 5696 | unsigned Int; |
| 5697 | switch (BuiltinID) { |
| 5698 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 5699 | case NEON::BI__builtin_neon_vld1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5700 | Int = Intrinsic::aarch64_neon_ld1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5701 | break; |
| 5702 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 5703 | case NEON::BI__builtin_neon_vld1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5704 | Int = Intrinsic::aarch64_neon_ld1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5705 | break; |
| 5706 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 5707 | case NEON::BI__builtin_neon_vld1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5708 | Int = Intrinsic::aarch64_neon_ld1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5709 | break; |
| 5710 | } |
| 5711 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 5712 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld1xN"); |
| 5713 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5714 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5715 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5716 | } |
| 5717 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 5718 | case NEON::BI__builtin_neon_vst1q_x2_v: |
| 5719 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 5720 | case NEON::BI__builtin_neon_vst1q_x3_v: |
| 5721 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 5722 | case NEON::BI__builtin_neon_vst1q_x4_v: { |
| 5723 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 5724 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 5725 | unsigned Int; |
| 5726 | switch (BuiltinID) { |
| 5727 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 5728 | case NEON::BI__builtin_neon_vst1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5729 | Int = Intrinsic::aarch64_neon_st1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5730 | break; |
| 5731 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 5732 | case NEON::BI__builtin_neon_vst1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5733 | Int = Intrinsic::aarch64_neon_st1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5734 | break; |
| 5735 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 5736 | case NEON::BI__builtin_neon_vst1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5737 | Int = Intrinsic::aarch64_neon_st1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5738 | break; |
| 5739 | } |
| 5740 | SmallVector<Value *, 4> IntOps(Ops.begin()+1, Ops.end()); |
| 5741 | IntOps.push_back(Ops[0]); |
| 5742 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), IntOps, ""); |
| 5743 | } |
| 5744 | case NEON::BI__builtin_neon_vld1_v: |
| 5745 | case NEON::BI__builtin_neon_vld1q_v: |
| 5746 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
| 5747 | return Builder.CreateLoad(Ops[0]); |
| 5748 | case NEON::BI__builtin_neon_vst1_v: |
| 5749 | case NEON::BI__builtin_neon_vst1q_v: |
| 5750 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
| 5751 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 5752 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5753 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 5754 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 5755 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5756 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5757 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5758 | Ops[0] = Builder.CreateLoad(Ops[0]); |
| 5759 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane"); |
| 5760 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 5761 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 5762 | Value *V = UndefValue::get(Ty); |
| 5763 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5764 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5765 | Ops[0] = Builder.CreateLoad(Ops[0]); |
Michael J. Spencer | 5ce2668 | 2014-06-02 19:48:59 +0000 | [diff] [blame] | 5766 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5767 | Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI); |
| 5768 | return EmitNeonSplat(Ops[0], CI); |
| 5769 | } |
| 5770 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 5771 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 5772 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5773 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 5774 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5775 | return Builder.CreateStore(Ops[1], Builder.CreateBitCast(Ops[0], Ty)); |
| 5776 | case NEON::BI__builtin_neon_vld2_v: |
| 5777 | case NEON::BI__builtin_neon_vld2q_v: { |
| 5778 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 5779 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5780 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5781 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5782 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 5783 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 5784 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 5785 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5786 | } |
| 5787 | case NEON::BI__builtin_neon_vld3_v: |
| 5788 | case NEON::BI__builtin_neon_vld3q_v: { |
| 5789 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 5790 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5791 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5792 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5793 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 5794 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 5795 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 5796 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5797 | } |
| 5798 | case NEON::BI__builtin_neon_vld4_v: |
| 5799 | case NEON::BI__builtin_neon_vld4q_v: { |
| 5800 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 5801 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5802 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5803 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5804 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 5805 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 5806 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 5807 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5808 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 5809 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 5810 | case NEON::BI__builtin_neon_vld2q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5811 | llvm::Type *PTy = |
| 5812 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5813 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5814 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5815 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5816 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 5817 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 5818 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 5819 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5820 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 5821 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 5822 | case NEON::BI__builtin_neon_vld3q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5823 | llvm::Type *PTy = |
| 5824 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5825 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5826 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5827 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5828 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 5829 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 5830 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 5831 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5832 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 5833 | case NEON::BI__builtin_neon_vld4_dup_v: |
| 5834 | case NEON::BI__builtin_neon_vld4q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5835 | llvm::Type *PTy = |
| 5836 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5837 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5838 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5839 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5840 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 5841 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 5842 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 5843 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5844 | } |
| 5845 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 5846 | case NEON::BI__builtin_neon_vld2q_lane_v: { |
| 5847 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5848 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5849 | Ops.push_back(Ops[1]); |
| 5850 | Ops.erase(Ops.begin()+1); |
| 5851 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5852 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 5853 | Ops[3] = Builder.CreateZExt(Ops[3], |
| 5854 | llvm::IntegerType::get(getLLVMContext(), 64)); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 5855 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld2_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5856 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5857 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5858 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5859 | } |
| 5860 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 5861 | case NEON::BI__builtin_neon_vld3q_lane_v: { |
| 5862 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5863 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5864 | Ops.push_back(Ops[1]); |
| 5865 | Ops.erase(Ops.begin()+1); |
| 5866 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5867 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 5868 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 5869 | Ops[4] = Builder.CreateZExt(Ops[4], |
| 5870 | llvm::IntegerType::get(getLLVMContext(), 64)); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 5871 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld3_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5872 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5873 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5874 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5875 | } |
| 5876 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 5877 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
| 5878 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5879 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5880 | Ops.push_back(Ops[1]); |
| 5881 | Ops.erase(Ops.begin()+1); |
| 5882 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5883 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 5884 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 5885 | Ops[4] = Builder.CreateBitCast(Ops[4], Ty); |
| 5886 | Ops[5] = Builder.CreateZExt(Ops[5], |
| 5887 | llvm::IntegerType::get(getLLVMContext(), 64)); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 5888 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld4_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5889 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5890 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5891 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 5892 | } |
| 5893 | case NEON::BI__builtin_neon_vst2_v: |
| 5894 | case NEON::BI__builtin_neon_vst2q_v: { |
| 5895 | Ops.push_back(Ops[0]); |
| 5896 | Ops.erase(Ops.begin()); |
| 5897 | llvm::Type *Tys[2] = { VTy, Ops[2]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5898 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5899 | Ops, ""); |
| 5900 | } |
| 5901 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 5902 | case NEON::BI__builtin_neon_vst2q_lane_v: { |
| 5903 | Ops.push_back(Ops[0]); |
| 5904 | Ops.erase(Ops.begin()); |
| 5905 | Ops[2] = Builder.CreateZExt(Ops[2], |
| 5906 | llvm::IntegerType::get(getLLVMContext(), 64)); |
| 5907 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5908 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5909 | Ops, ""); |
| 5910 | } |
| 5911 | case NEON::BI__builtin_neon_vst3_v: |
| 5912 | case NEON::BI__builtin_neon_vst3q_v: { |
| 5913 | Ops.push_back(Ops[0]); |
| 5914 | Ops.erase(Ops.begin()); |
| 5915 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5916 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5917 | Ops, ""); |
| 5918 | } |
| 5919 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 5920 | case NEON::BI__builtin_neon_vst3q_lane_v: { |
| 5921 | Ops.push_back(Ops[0]); |
| 5922 | Ops.erase(Ops.begin()); |
| 5923 | Ops[3] = Builder.CreateZExt(Ops[3], |
| 5924 | llvm::IntegerType::get(getLLVMContext(), 64)); |
| 5925 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5926 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5927 | Ops, ""); |
| 5928 | } |
| 5929 | case NEON::BI__builtin_neon_vst4_v: |
| 5930 | case NEON::BI__builtin_neon_vst4q_v: { |
| 5931 | Ops.push_back(Ops[0]); |
| 5932 | Ops.erase(Ops.begin()); |
| 5933 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5934 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5935 | Ops, ""); |
| 5936 | } |
| 5937 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 5938 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 5939 | Ops.push_back(Ops[0]); |
| 5940 | Ops.erase(Ops.begin()); |
| 5941 | Ops[4] = Builder.CreateZExt(Ops[4], |
| 5942 | llvm::IntegerType::get(getLLVMContext(), 64)); |
| 5943 | llvm::Type *Tys[2] = { VTy, Ops[5]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5944 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5945 | Ops, ""); |
| 5946 | } |
| 5947 | case NEON::BI__builtin_neon_vtrn_v: |
| 5948 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 5949 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 5950 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5951 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5952 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5953 | |
| 5954 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 5955 | SmallVector<Constant*, 16> Indices; |
| 5956 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 5957 | Indices.push_back(ConstantInt::get(Int32Ty, i+vi)); |
| 5958 | Indices.push_back(ConstantInt::get(Int32Ty, i+e+vi)); |
| 5959 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 5960 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5961 | SV = llvm::ConstantVector::get(Indices); |
| 5962 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vtrn"); |
| 5963 | SV = Builder.CreateStore(SV, Addr); |
| 5964 | } |
| 5965 | return SV; |
| 5966 | } |
| 5967 | case NEON::BI__builtin_neon_vuzp_v: |
| 5968 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 5969 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 5970 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5971 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5972 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5973 | |
| 5974 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 5975 | SmallVector<Constant*, 16> Indices; |
| 5976 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
| 5977 | Indices.push_back(ConstantInt::get(Int32Ty, 2*i+vi)); |
| 5978 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 5979 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5980 | SV = llvm::ConstantVector::get(Indices); |
| 5981 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vuzp"); |
| 5982 | SV = Builder.CreateStore(SV, Addr); |
| 5983 | } |
| 5984 | return SV; |
| 5985 | } |
| 5986 | case NEON::BI__builtin_neon_vzip_v: |
| 5987 | case NEON::BI__builtin_neon_vzipq_v: { |
| 5988 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 5989 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5990 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5991 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5992 | |
| 5993 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 5994 | SmallVector<Constant*, 16> Indices; |
| 5995 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 5996 | Indices.push_back(ConstantInt::get(Int32Ty, (i + vi*e) >> 1)); |
| 5997 | Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e)); |
| 5998 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 5999 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6000 | SV = llvm::ConstantVector::get(Indices); |
| 6001 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); |
| 6002 | SV = Builder.CreateStore(SV, Addr); |
| 6003 | } |
| 6004 | return SV; |
| 6005 | } |
| 6006 | case NEON::BI__builtin_neon_vqtbl1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6007 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6008 | Ops, "vtbl1"); |
| 6009 | } |
| 6010 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6011 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6012 | Ops, "vtbl2"); |
| 6013 | } |
| 6014 | case NEON::BI__builtin_neon_vqtbl3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6015 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6016 | Ops, "vtbl3"); |
| 6017 | } |
| 6018 | case NEON::BI__builtin_neon_vqtbl4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6019 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6020 | Ops, "vtbl4"); |
| 6021 | } |
| 6022 | case NEON::BI__builtin_neon_vqtbx1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6023 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6024 | Ops, "vtbx1"); |
| 6025 | } |
| 6026 | case NEON::BI__builtin_neon_vqtbx2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6027 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6028 | Ops, "vtbx2"); |
| 6029 | } |
| 6030 | case NEON::BI__builtin_neon_vqtbx3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6031 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6032 | Ops, "vtbx3"); |
| 6033 | } |
| 6034 | case NEON::BI__builtin_neon_vqtbx4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6035 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6036 | Ops, "vtbx4"); |
| 6037 | } |
| 6038 | case NEON::BI__builtin_neon_vsqadd_v: |
| 6039 | case NEON::BI__builtin_neon_vsqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6040 | Int = Intrinsic::aarch64_neon_usqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6041 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqadd"); |
| 6042 | } |
| 6043 | case NEON::BI__builtin_neon_vuqadd_v: |
| 6044 | case NEON::BI__builtin_neon_vuqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6045 | Int = Intrinsic::aarch64_neon_suqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6046 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vuqadd"); |
| 6047 | } |
| 6048 | } |
| 6049 | } |
| 6050 | |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6051 | llvm::Value *CodeGenFunction:: |
Bill Wendling | f1a3fca | 2012-02-22 09:30:11 +0000 | [diff] [blame] | 6052 | BuildVector(ArrayRef<llvm::Value*> Ops) { |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6053 | assert((Ops.size() & (Ops.size() - 1)) == 0 && |
| 6054 | "Not a power-of-two sized vector!"); |
| 6055 | bool AllConstants = true; |
| 6056 | for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i) |
| 6057 | AllConstants &= isa<Constant>(Ops[i]); |
| 6058 | |
| 6059 | // If this is a constant vector, create a ConstantVector. |
| 6060 | if (AllConstants) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 6061 | SmallVector<llvm::Constant*, 16> CstOps; |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6062 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
| 6063 | CstOps.push_back(cast<Constant>(Ops[i])); |
| 6064 | return llvm::ConstantVector::get(CstOps); |
| 6065 | } |
| 6066 | |
| 6067 | // Otherwise, insertelement the values to build the vector. |
| 6068 | Value *Result = |
| 6069 | llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size())); |
| 6070 | |
| 6071 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 6072 | Result = Builder.CreateInsertElement(Result, Ops[i], Builder.getInt32(i)); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6073 | |
| 6074 | return Result; |
| 6075 | } |
| 6076 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6077 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 6078 | const CallExpr *E) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6079 | SmallVector<Value*, 4> Ops; |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 6080 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 6081 | // Find out if any arguments are required to be integer constant expressions. |
| 6082 | unsigned ICEArguments = 0; |
| 6083 | ASTContext::GetBuiltinTypeError Error; |
| 6084 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 6085 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 6086 | |
| 6087 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { |
| 6088 | // If this is a normal argument, just emit it as a scalar. |
| 6089 | if ((ICEArguments & (1 << i)) == 0) { |
| 6090 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 6091 | continue; |
| 6092 | } |
| 6093 | |
| 6094 | // If this is required to be a constant, constant fold it so that we know |
| 6095 | // that the generated intrinsic gets a ConstantInt. |
| 6096 | llvm::APSInt Result; |
| 6097 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 6098 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6099 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 6100 | } |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 6101 | |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 6102 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6103 | default: return nullptr; |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame^] | 6104 | case X86::BI__builtin_cpu_supports: { |
| 6105 | const Expr *FeatureExpr = E->getArg(0)->IgnoreParenCasts(); |
| 6106 | StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString(); |
| 6107 | |
| 6108 | // TODO: When/if this becomes more than x86 specific then use a TargetInfo |
| 6109 | // based mapping. |
| 6110 | // Processor features and mapping to processor feature value. |
| 6111 | enum X86Features { |
| 6112 | CMOV = 0, |
| 6113 | MMX, |
| 6114 | POPCNT, |
| 6115 | SSE, |
| 6116 | SSE2, |
| 6117 | SSE3, |
| 6118 | SSSE3, |
| 6119 | SSE4_1, |
| 6120 | SSE4_2, |
| 6121 | AVX, |
| 6122 | AVX2, |
| 6123 | SSE4_A, |
| 6124 | FMA4, |
| 6125 | XOP, |
| 6126 | FMA, |
| 6127 | AVX512F, |
| 6128 | BMI, |
| 6129 | BMI2, |
| 6130 | MAX |
| 6131 | }; |
| 6132 | |
| 6133 | X86Features Feature = StringSwitch<X86Features>(FeatureStr) |
| 6134 | .Case("cmov", X86Features::CMOV) |
| 6135 | .Case("mmx", X86Features::MMX) |
| 6136 | .Case("popcnt", X86Features::POPCNT) |
| 6137 | .Case("sse", X86Features::SSE) |
| 6138 | .Case("sse2", X86Features::SSE2) |
| 6139 | .Case("sse3", X86Features::SSE3) |
| 6140 | .Case("sse4.1", X86Features::SSE4_1) |
| 6141 | .Case("sse4.2", X86Features::SSE4_2) |
| 6142 | .Case("avx", X86Features::AVX) |
| 6143 | .Case("avx2", X86Features::AVX2) |
| 6144 | .Case("sse4a", X86Features::SSE4_A) |
| 6145 | .Case("fma4", X86Features::FMA4) |
| 6146 | .Case("xop", X86Features::XOP) |
| 6147 | .Case("fma", X86Features::FMA) |
| 6148 | .Case("avx512f", X86Features::AVX512F) |
| 6149 | .Case("bmi", X86Features::BMI) |
| 6150 | .Case("bmi2", X86Features::BMI2) |
| 6151 | .Default(X86Features::MAX); |
| 6152 | assert(Feature != X86Features::MAX && "Invalid feature!"); |
| 6153 | |
| 6154 | // Matching the struct layout from the compiler-rt/libgcc structure that is |
| 6155 | // filled in: |
| 6156 | // unsigned int __cpu_vendor; |
| 6157 | // unsigned int __cpu_type; |
| 6158 | // unsigned int __cpu_subtype; |
| 6159 | // unsigned int __cpu_features[1]; |
| 6160 | llvm::Type *STy = llvm::StructType::get( |
| 6161 | Int32Ty, Int32Ty, Int32Ty, llvm::ArrayType::get(Int32Ty, 1), nullptr); |
| 6162 | |
| 6163 | // Grab the global __cpu_model. |
| 6164 | llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); |
| 6165 | |
| 6166 | // Grab the first (0th) element from the field __cpu_features off of the |
| 6167 | // global in the struct STy. |
| 6168 | Value *Idxs[] = { |
| 6169 | ConstantInt::get(Int32Ty, 0), |
| 6170 | ConstantInt::get(Int32Ty, 3), |
| 6171 | ConstantInt::get(Int32Ty, 0) |
| 6172 | }; |
| 6173 | Value *CpuFeatures = Builder.CreateGEP(STy, CpuModel, Idxs); |
| 6174 | Value *Features = Builder.CreateLoad(CpuFeatures); |
| 6175 | |
| 6176 | // Check the value of the bit corresponding to the feature requested. |
| 6177 | Value *Bitset = Builder.CreateAnd( |
| 6178 | Features, llvm::ConstantInt::get(Int32Ty, 1 << Feature)); |
| 6179 | return Builder.CreateICmpNE(Bitset, llvm::ConstantInt::get(Int32Ty, 0)); |
| 6180 | } |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 6181 | case X86::BI_mm_prefetch: { |
| 6182 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 6183 | Value *RW = ConstantInt::get(Int32Ty, 0); |
| 6184 | Value *Locality = EmitScalarExpr(E->getArg(1)); |
| 6185 | Value *Data = ConstantInt::get(Int32Ty, 1); |
| 6186 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6187 | return Builder.CreateCall(F, {Address, RW, Locality, Data}); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 6188 | } |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6189 | case X86::BI__builtin_ia32_vec_init_v8qi: |
| 6190 | case X86::BI__builtin_ia32_vec_init_v4hi: |
| 6191 | case X86::BI__builtin_ia32_vec_init_v2si: |
| 6192 | return Builder.CreateBitCast(BuildVector(Ops), |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6193 | llvm::Type::getX86_MMXTy(getLLVMContext())); |
Argyrios Kyrtzidis | 073c9cb | 2010-10-10 03:19:11 +0000 | [diff] [blame] | 6194 | case X86::BI__builtin_ia32_vec_ext_v2si: |
| 6195 | return Builder.CreateExtractElement(Ops[0], |
| 6196 | llvm::ConstantInt::get(Ops[1]->getType(), 0)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6197 | case X86::BI__builtin_ia32_ldmxcsr: { |
Juergen Ributzka | c6ab1f8 | 2013-08-19 22:20:37 +0000 | [diff] [blame] | 6198 | Value *Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6199 | Builder.CreateStore(Ops[0], Tmp); |
| 6200 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
Juergen Ributzka | c6ab1f8 | 2013-08-19 22:20:37 +0000 | [diff] [blame] | 6201 | Builder.CreateBitCast(Tmp, Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6202 | } |
| 6203 | case X86::BI__builtin_ia32_stmxcsr: { |
Juergen Ributzka | 53e2f27 | 2013-08-19 23:08:53 +0000 | [diff] [blame] | 6204 | Value *Tmp = CreateMemTemp(E->getType()); |
Ted Kremenek | c14efa7 | 2011-08-17 21:04:19 +0000 | [diff] [blame] | 6205 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
Juergen Ributzka | c6ab1f8 | 2013-08-19 22:20:37 +0000 | [diff] [blame] | 6206 | Builder.CreateBitCast(Tmp, Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6207 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 6208 | } |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6209 | case X86::BI__builtin_ia32_storehps: |
| 6210 | case X86::BI__builtin_ia32_storelps: { |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 6211 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(Int64Ty); |
| 6212 | llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6213 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6214 | // cast val v2i64 |
| 6215 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6216 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6217 | // extract (0, 1) |
| 6218 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6219 | llvm::Value *Idx = llvm::ConstantInt::get(SizeTy, Index); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6220 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 6221 | |
| 6222 | // cast pointer to i64 & store |
| 6223 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
| 6224 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 6225 | } |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6226 | case X86::BI__builtin_ia32_palignr128: |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6227 | case X86::BI__builtin_ia32_palignr256: { |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6228 | unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6229 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6230 | unsigned NumElts = |
| 6231 | cast<llvm::VectorType>(Ops[0]->getType())->getNumElements(); |
| 6232 | assert(NumElts % 16 == 0); |
| 6233 | unsigned NumLanes = NumElts / 16; |
| 6234 | unsigned NumLaneElts = NumElts / NumLanes; |
| 6235 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6236 | // If palignr is shifting the pair of vectors more than the size of two |
| 6237 | // lanes, emit zero. |
| 6238 | if (ShiftVal >= (2 * NumLaneElts)) |
| 6239 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6240 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6241 | // If palignr is shifting the pair of input vectors more than one lane, |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 6242 | // but less than two lanes, convert to shifting in zeroes. |
| 6243 | if (ShiftVal > NumLaneElts) { |
| 6244 | ShiftVal -= NumLaneElts; |
| 6245 | Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType()); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6246 | } |
| 6247 | |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 6248 | SmallVector<llvm::Constant*, 32> Indices; |
| 6249 | // 256-bit palignr operates on 128-bit lanes so we need to handle that |
| 6250 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
| 6251 | for (unsigned i = 0; i != NumLaneElts; ++i) { |
| 6252 | unsigned Idx = ShiftVal + i; |
| 6253 | if (Idx >= NumLaneElts) |
| 6254 | Idx += NumElts - NumLaneElts; // End of lane, switch operand. |
| 6255 | Indices.push_back(llvm::ConstantInt::get(Int32Ty, Idx + l)); |
| 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | Value* SV = llvm::ConstantVector::get(Indices); |
| 6260 | return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr"); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6261 | } |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6262 | case X86::BI__builtin_ia32_pslldqi256: { |
| 6263 | // Shift value is in bits so divide by 8. |
| 6264 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() >> 3; |
| 6265 | |
| 6266 | // If pslldq is shifting the vector more than 15 bytes, emit zero. |
| 6267 | if (shiftVal >= 16) |
| 6268 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
| 6269 | |
| 6270 | SmallVector<llvm::Constant*, 32> Indices; |
| 6271 | // 256-bit pslldq operates on 128-bit lanes so we need to handle that |
| 6272 | for (unsigned l = 0; l != 32; l += 16) { |
| 6273 | for (unsigned i = 0; i != 16; ++i) { |
| 6274 | unsigned Idx = 32 + i - shiftVal; |
| 6275 | if (Idx < 32) Idx -= 16; // end of lane, switch operand. |
| 6276 | Indices.push_back(llvm::ConstantInt::get(Int32Ty, Idx + l)); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | llvm::Type *VecTy = llvm::VectorType::get(Int8Ty, 32); |
| 6281 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 6282 | Value *Zero = llvm::Constant::getNullValue(VecTy); |
| 6283 | |
| 6284 | Value *SV = llvm::ConstantVector::get(Indices); |
| 6285 | SV = Builder.CreateShuffleVector(Zero, Ops[0], SV, "pslldq"); |
| 6286 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6287 | return Builder.CreateBitCast(SV, ResultType, "cast"); |
| 6288 | } |
| 6289 | case X86::BI__builtin_ia32_psrldqi256: { |
| 6290 | // Shift value is in bits so divide by 8. |
| 6291 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() >> 3; |
| 6292 | |
| 6293 | // If psrldq is shifting the vector more than 15 bytes, emit zero. |
| 6294 | if (shiftVal >= 16) |
| 6295 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
| 6296 | |
| 6297 | SmallVector<llvm::Constant*, 32> Indices; |
| 6298 | // 256-bit psrldq operates on 128-bit lanes so we need to handle that |
| 6299 | for (unsigned l = 0; l != 32; l += 16) { |
| 6300 | for (unsigned i = 0; i != 16; ++i) { |
| 6301 | unsigned Idx = i + shiftVal; |
| 6302 | if (Idx >= 16) Idx += 16; // end of lane, switch operand. |
| 6303 | Indices.push_back(llvm::ConstantInt::get(Int32Ty, Idx + l)); |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | llvm::Type *VecTy = llvm::VectorType::get(Int8Ty, 32); |
| 6308 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 6309 | Value *Zero = llvm::Constant::getNullValue(VecTy); |
| 6310 | |
| 6311 | Value *SV = llvm::ConstantVector::get(Indices); |
| 6312 | SV = Builder.CreateShuffleVector(Ops[0], Zero, SV, "psrldq"); |
| 6313 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6314 | return Builder.CreateBitCast(SV, ResultType, "cast"); |
| 6315 | } |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6316 | case X86::BI__builtin_ia32_movntps: |
Craig Topper | c83dff0 | 2012-05-07 06:25:45 +0000 | [diff] [blame] | 6317 | case X86::BI__builtin_ia32_movntps256: |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6318 | case X86::BI__builtin_ia32_movntpd: |
Craig Topper | c83dff0 | 2012-05-07 06:25:45 +0000 | [diff] [blame] | 6319 | case X86::BI__builtin_ia32_movntpd256: |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6320 | case X86::BI__builtin_ia32_movntdq: |
Craig Topper | c83dff0 | 2012-05-07 06:25:45 +0000 | [diff] [blame] | 6321 | case X86::BI__builtin_ia32_movntdq256: |
Eli Friedman | f9d8c6c | 2013-09-23 23:38:39 +0000 | [diff] [blame] | 6322 | case X86::BI__builtin_ia32_movnti: |
| 6323 | case X86::BI__builtin_ia32_movnti64: { |
Duncan P. N. Exon Smith | fb49491 | 2014-12-09 18:39:32 +0000 | [diff] [blame] | 6324 | llvm::MDNode *Node = llvm::MDNode::get( |
| 6325 | getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1))); |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6326 | |
| 6327 | // Convert the type of the pointer to a pointer to the stored type. |
| 6328 | Value *BC = Builder.CreateBitCast(Ops[0], |
| 6329 | llvm::PointerType::getUnqual(Ops[1]->getType()), |
| 6330 | "cast"); |
| 6331 | StoreInst *SI = Builder.CreateStore(Ops[1], BC); |
| 6332 | SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); |
Eli Friedman | f9d8c6c | 2013-09-23 23:38:39 +0000 | [diff] [blame] | 6333 | |
| 6334 | // If the operand is an integer, we can't assume alignment. Otherwise, |
| 6335 | // assume natural alignment. |
| 6336 | QualType ArgTy = E->getArg(1)->getType(); |
| 6337 | unsigned Align; |
| 6338 | if (ArgTy->isIntegerType()) |
| 6339 | Align = 1; |
| 6340 | else |
| 6341 | Align = getContext().getTypeSizeInChars(ArgTy).getQuantity(); |
| 6342 | SI->setAlignment(Align); |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6343 | return SI; |
| 6344 | } |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 6345 | // 3DNow! |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 6346 | case X86::BI__builtin_ia32_pswapdsf: |
| 6347 | case X86::BI__builtin_ia32_pswapdsi: { |
Chandler Carruth | a2a5410 | 2012-02-20 07:35:45 +0000 | [diff] [blame] | 6348 | llvm::Type *MMXTy = llvm::Type::getX86_MMXTy(getLLVMContext()); |
| 6349 | Ops[0] = Builder.CreateBitCast(Ops[0], MMXTy, "cast"); |
Craig Topper | d2f814d | 2015-02-16 21:30:08 +0000 | [diff] [blame] | 6350 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_3dnowa_pswapd); |
| 6351 | return Builder.CreateCall(F, Ops, "pswapd"); |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 6352 | } |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6353 | case X86::BI__builtin_ia32_rdrand16_step: |
| 6354 | case X86::BI__builtin_ia32_rdrand32_step: |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 6355 | case X86::BI__builtin_ia32_rdrand64_step: |
| 6356 | case X86::BI__builtin_ia32_rdseed16_step: |
| 6357 | case X86::BI__builtin_ia32_rdseed32_step: |
| 6358 | case X86::BI__builtin_ia32_rdseed64_step: { |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6359 | Intrinsic::ID ID; |
| 6360 | switch (BuiltinID) { |
| 6361 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6362 | case X86::BI__builtin_ia32_rdrand16_step: |
| 6363 | ID = Intrinsic::x86_rdrand_16; |
| 6364 | break; |
| 6365 | case X86::BI__builtin_ia32_rdrand32_step: |
| 6366 | ID = Intrinsic::x86_rdrand_32; |
| 6367 | break; |
| 6368 | case X86::BI__builtin_ia32_rdrand64_step: |
| 6369 | ID = Intrinsic::x86_rdrand_64; |
| 6370 | break; |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 6371 | case X86::BI__builtin_ia32_rdseed16_step: |
| 6372 | ID = Intrinsic::x86_rdseed_16; |
| 6373 | break; |
| 6374 | case X86::BI__builtin_ia32_rdseed32_step: |
| 6375 | ID = Intrinsic::x86_rdseed_32; |
| 6376 | break; |
| 6377 | case X86::BI__builtin_ia32_rdseed64_step: |
| 6378 | ID = Intrinsic::x86_rdseed_64; |
| 6379 | break; |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6382 | Value *Call = Builder.CreateCall(CGM.getIntrinsic(ID), {}); |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6383 | Builder.CreateStore(Builder.CreateExtractValue(Call, 0), Ops[0]); |
| 6384 | return Builder.CreateExtractValue(Call, 1); |
| 6385 | } |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 6386 | // SSE comparison intrisics |
| 6387 | case X86::BI__builtin_ia32_cmpeqps: |
| 6388 | case X86::BI__builtin_ia32_cmpltps: |
| 6389 | case X86::BI__builtin_ia32_cmpleps: |
| 6390 | case X86::BI__builtin_ia32_cmpunordps: |
| 6391 | case X86::BI__builtin_ia32_cmpneqps: |
| 6392 | case X86::BI__builtin_ia32_cmpnltps: |
| 6393 | case X86::BI__builtin_ia32_cmpnleps: |
| 6394 | case X86::BI__builtin_ia32_cmpordps: |
| 6395 | case X86::BI__builtin_ia32_cmpeqss: |
| 6396 | case X86::BI__builtin_ia32_cmpltss: |
| 6397 | case X86::BI__builtin_ia32_cmpless: |
| 6398 | case X86::BI__builtin_ia32_cmpunordss: |
| 6399 | case X86::BI__builtin_ia32_cmpneqss: |
| 6400 | case X86::BI__builtin_ia32_cmpnltss: |
| 6401 | case X86::BI__builtin_ia32_cmpnless: |
| 6402 | case X86::BI__builtin_ia32_cmpordss: |
| 6403 | case X86::BI__builtin_ia32_cmpeqpd: |
| 6404 | case X86::BI__builtin_ia32_cmpltpd: |
| 6405 | case X86::BI__builtin_ia32_cmplepd: |
| 6406 | case X86::BI__builtin_ia32_cmpunordpd: |
| 6407 | case X86::BI__builtin_ia32_cmpneqpd: |
| 6408 | case X86::BI__builtin_ia32_cmpnltpd: |
| 6409 | case X86::BI__builtin_ia32_cmpnlepd: |
| 6410 | case X86::BI__builtin_ia32_cmpordpd: |
| 6411 | case X86::BI__builtin_ia32_cmpeqsd: |
| 6412 | case X86::BI__builtin_ia32_cmpltsd: |
| 6413 | case X86::BI__builtin_ia32_cmplesd: |
| 6414 | case X86::BI__builtin_ia32_cmpunordsd: |
| 6415 | case X86::BI__builtin_ia32_cmpneqsd: |
| 6416 | case X86::BI__builtin_ia32_cmpnltsd: |
| 6417 | case X86::BI__builtin_ia32_cmpnlesd: |
| 6418 | case X86::BI__builtin_ia32_cmpordsd: |
| 6419 | // These exist so that the builtin that takes an immediate can be bounds |
| 6420 | // checked by clang to avoid passing bad immediates to the backend. Since |
| 6421 | // AVX has a larger immediate than SSE we would need separate builtins to |
| 6422 | // do the different bounds checking. Rather than create a clang specific |
| 6423 | // SSE only builtin, this implements eight separate builtins to match gcc |
| 6424 | // implementation. |
| 6425 | |
| 6426 | // Choose the immediate. |
| 6427 | unsigned Imm; |
| 6428 | switch (BuiltinID) { |
| 6429 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6430 | case X86::BI__builtin_ia32_cmpeqps: |
| 6431 | case X86::BI__builtin_ia32_cmpeqss: |
| 6432 | case X86::BI__builtin_ia32_cmpeqpd: |
| 6433 | case X86::BI__builtin_ia32_cmpeqsd: |
| 6434 | Imm = 0; |
| 6435 | break; |
| 6436 | case X86::BI__builtin_ia32_cmpltps: |
| 6437 | case X86::BI__builtin_ia32_cmpltss: |
| 6438 | case X86::BI__builtin_ia32_cmpltpd: |
| 6439 | case X86::BI__builtin_ia32_cmpltsd: |
| 6440 | Imm = 1; |
| 6441 | break; |
| 6442 | case X86::BI__builtin_ia32_cmpleps: |
| 6443 | case X86::BI__builtin_ia32_cmpless: |
| 6444 | case X86::BI__builtin_ia32_cmplepd: |
| 6445 | case X86::BI__builtin_ia32_cmplesd: |
| 6446 | Imm = 2; |
| 6447 | break; |
| 6448 | case X86::BI__builtin_ia32_cmpunordps: |
| 6449 | case X86::BI__builtin_ia32_cmpunordss: |
| 6450 | case X86::BI__builtin_ia32_cmpunordpd: |
| 6451 | case X86::BI__builtin_ia32_cmpunordsd: |
| 6452 | Imm = 3; |
| 6453 | break; |
| 6454 | case X86::BI__builtin_ia32_cmpneqps: |
| 6455 | case X86::BI__builtin_ia32_cmpneqss: |
| 6456 | case X86::BI__builtin_ia32_cmpneqpd: |
| 6457 | case X86::BI__builtin_ia32_cmpneqsd: |
| 6458 | Imm = 4; |
| 6459 | break; |
| 6460 | case X86::BI__builtin_ia32_cmpnltps: |
| 6461 | case X86::BI__builtin_ia32_cmpnltss: |
| 6462 | case X86::BI__builtin_ia32_cmpnltpd: |
| 6463 | case X86::BI__builtin_ia32_cmpnltsd: |
| 6464 | Imm = 5; |
| 6465 | break; |
| 6466 | case X86::BI__builtin_ia32_cmpnleps: |
| 6467 | case X86::BI__builtin_ia32_cmpnless: |
| 6468 | case X86::BI__builtin_ia32_cmpnlepd: |
| 6469 | case X86::BI__builtin_ia32_cmpnlesd: |
| 6470 | Imm = 6; |
| 6471 | break; |
| 6472 | case X86::BI__builtin_ia32_cmpordps: |
| 6473 | case X86::BI__builtin_ia32_cmpordss: |
| 6474 | case X86::BI__builtin_ia32_cmpordpd: |
| 6475 | case X86::BI__builtin_ia32_cmpordsd: |
| 6476 | Imm = 7; |
| 6477 | break; |
| 6478 | } |
| 6479 | |
| 6480 | // Choose the intrinsic ID. |
| 6481 | const char *name; |
| 6482 | Intrinsic::ID ID; |
| 6483 | switch (BuiltinID) { |
| 6484 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6485 | case X86::BI__builtin_ia32_cmpeqps: |
| 6486 | case X86::BI__builtin_ia32_cmpltps: |
| 6487 | case X86::BI__builtin_ia32_cmpleps: |
| 6488 | case X86::BI__builtin_ia32_cmpunordps: |
| 6489 | case X86::BI__builtin_ia32_cmpneqps: |
| 6490 | case X86::BI__builtin_ia32_cmpnltps: |
| 6491 | case X86::BI__builtin_ia32_cmpnleps: |
| 6492 | case X86::BI__builtin_ia32_cmpordps: |
| 6493 | name = "cmpps"; |
| 6494 | ID = Intrinsic::x86_sse_cmp_ps; |
| 6495 | break; |
| 6496 | case X86::BI__builtin_ia32_cmpeqss: |
| 6497 | case X86::BI__builtin_ia32_cmpltss: |
| 6498 | case X86::BI__builtin_ia32_cmpless: |
| 6499 | case X86::BI__builtin_ia32_cmpunordss: |
| 6500 | case X86::BI__builtin_ia32_cmpneqss: |
| 6501 | case X86::BI__builtin_ia32_cmpnltss: |
| 6502 | case X86::BI__builtin_ia32_cmpnless: |
| 6503 | case X86::BI__builtin_ia32_cmpordss: |
| 6504 | name = "cmpss"; |
| 6505 | ID = Intrinsic::x86_sse_cmp_ss; |
| 6506 | break; |
| 6507 | case X86::BI__builtin_ia32_cmpeqpd: |
| 6508 | case X86::BI__builtin_ia32_cmpltpd: |
| 6509 | case X86::BI__builtin_ia32_cmplepd: |
| 6510 | case X86::BI__builtin_ia32_cmpunordpd: |
| 6511 | case X86::BI__builtin_ia32_cmpneqpd: |
| 6512 | case X86::BI__builtin_ia32_cmpnltpd: |
| 6513 | case X86::BI__builtin_ia32_cmpnlepd: |
| 6514 | case X86::BI__builtin_ia32_cmpordpd: |
| 6515 | name = "cmppd"; |
| 6516 | ID = Intrinsic::x86_sse2_cmp_pd; |
| 6517 | break; |
| 6518 | case X86::BI__builtin_ia32_cmpeqsd: |
| 6519 | case X86::BI__builtin_ia32_cmpltsd: |
| 6520 | case X86::BI__builtin_ia32_cmplesd: |
| 6521 | case X86::BI__builtin_ia32_cmpunordsd: |
| 6522 | case X86::BI__builtin_ia32_cmpneqsd: |
| 6523 | case X86::BI__builtin_ia32_cmpnltsd: |
| 6524 | case X86::BI__builtin_ia32_cmpnlesd: |
| 6525 | case X86::BI__builtin_ia32_cmpordsd: |
| 6526 | name = "cmpsd"; |
| 6527 | ID = Intrinsic::x86_sse2_cmp_sd; |
| 6528 | break; |
| 6529 | } |
| 6530 | |
| 6531 | Ops.push_back(llvm::ConstantInt::get(Int8Ty, Imm)); |
| 6532 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 6533 | return Builder.CreateCall(F, Ops, name); |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 6534 | } |
| 6535 | } |
| 6536 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 6537 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6538 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 6539 | const CallExpr *E) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6540 | SmallVector<Value*, 4> Ops; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6541 | |
| 6542 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 6543 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 6544 | |
| 6545 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 6546 | |
| 6547 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6548 | default: return nullptr; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6549 | |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6550 | // vec_ld, vec_lvsl, vec_lvsr |
| 6551 | case PPC::BI__builtin_altivec_lvx: |
| 6552 | case PPC::BI__builtin_altivec_lvxl: |
| 6553 | case PPC::BI__builtin_altivec_lvebx: |
| 6554 | case PPC::BI__builtin_altivec_lvehx: |
| 6555 | case PPC::BI__builtin_altivec_lvewx: |
| 6556 | case PPC::BI__builtin_altivec_lvsl: |
| 6557 | case PPC::BI__builtin_altivec_lvsr: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6558 | case PPC::BI__builtin_vsx_lxvd2x: |
| 6559 | case PPC::BI__builtin_vsx_lxvw4x: |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6560 | { |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6561 | Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6562 | |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 6563 | Ops[0] = Builder.CreateGEP(Ops[1], Ops[0]); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6564 | Ops.pop_back(); |
| 6565 | |
| 6566 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6567 | default: llvm_unreachable("Unsupported ld/lvsl/lvsr intrinsic!"); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6568 | case PPC::BI__builtin_altivec_lvx: |
| 6569 | ID = Intrinsic::ppc_altivec_lvx; |
| 6570 | break; |
| 6571 | case PPC::BI__builtin_altivec_lvxl: |
| 6572 | ID = Intrinsic::ppc_altivec_lvxl; |
| 6573 | break; |
| 6574 | case PPC::BI__builtin_altivec_lvebx: |
| 6575 | ID = Intrinsic::ppc_altivec_lvebx; |
| 6576 | break; |
| 6577 | case PPC::BI__builtin_altivec_lvehx: |
| 6578 | ID = Intrinsic::ppc_altivec_lvehx; |
| 6579 | break; |
| 6580 | case PPC::BI__builtin_altivec_lvewx: |
| 6581 | ID = Intrinsic::ppc_altivec_lvewx; |
| 6582 | break; |
| 6583 | case PPC::BI__builtin_altivec_lvsl: |
| 6584 | ID = Intrinsic::ppc_altivec_lvsl; |
| 6585 | break; |
| 6586 | case PPC::BI__builtin_altivec_lvsr: |
| 6587 | ID = Intrinsic::ppc_altivec_lvsr; |
| 6588 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6589 | case PPC::BI__builtin_vsx_lxvd2x: |
| 6590 | ID = Intrinsic::ppc_vsx_lxvd2x; |
| 6591 | break; |
| 6592 | case PPC::BI__builtin_vsx_lxvw4x: |
| 6593 | ID = Intrinsic::ppc_vsx_lxvw4x; |
| 6594 | break; |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6595 | } |
| 6596 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 6597 | return Builder.CreateCall(F, Ops, ""); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6600 | // vec_st |
| 6601 | case PPC::BI__builtin_altivec_stvx: |
| 6602 | case PPC::BI__builtin_altivec_stvxl: |
| 6603 | case PPC::BI__builtin_altivec_stvebx: |
| 6604 | case PPC::BI__builtin_altivec_stvehx: |
| 6605 | case PPC::BI__builtin_altivec_stvewx: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6606 | case PPC::BI__builtin_vsx_stxvd2x: |
| 6607 | case PPC::BI__builtin_vsx_stxvw4x: |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6608 | { |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6609 | Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 6610 | Ops[1] = Builder.CreateGEP(Ops[2], Ops[1]); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6611 | Ops.pop_back(); |
| 6612 | |
| 6613 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6614 | default: llvm_unreachable("Unsupported st intrinsic!"); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6615 | case PPC::BI__builtin_altivec_stvx: |
| 6616 | ID = Intrinsic::ppc_altivec_stvx; |
| 6617 | break; |
| 6618 | case PPC::BI__builtin_altivec_stvxl: |
| 6619 | ID = Intrinsic::ppc_altivec_stvxl; |
| 6620 | break; |
| 6621 | case PPC::BI__builtin_altivec_stvebx: |
| 6622 | ID = Intrinsic::ppc_altivec_stvebx; |
| 6623 | break; |
| 6624 | case PPC::BI__builtin_altivec_stvehx: |
| 6625 | ID = Intrinsic::ppc_altivec_stvehx; |
| 6626 | break; |
| 6627 | case PPC::BI__builtin_altivec_stvewx: |
| 6628 | ID = Intrinsic::ppc_altivec_stvewx; |
| 6629 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6630 | case PPC::BI__builtin_vsx_stxvd2x: |
| 6631 | ID = Intrinsic::ppc_vsx_stxvd2x; |
| 6632 | break; |
| 6633 | case PPC::BI__builtin_vsx_stxvw4x: |
| 6634 | ID = Intrinsic::ppc_vsx_stxvw4x; |
| 6635 | break; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6636 | } |
| 6637 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 6638 | return Builder.CreateCall(F, Ops, ""); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6639 | } |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 6640 | case PPC::BI__builtin_vsx_xvrspip: |
| 6641 | case PPC::BI__builtin_vsx_xvrdpip: |
| 6642 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6643 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6644 | ID = Intrinsic::ceil; |
| 6645 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 6646 | return Builder.CreateCall(F, X); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6647 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6648 | } |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 6649 | |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6650 | // Emit an intrinsic that has 1 float or double. |
| 6651 | static Value *emitUnaryFPBuiltin(CodeGenFunction &CGF, |
| 6652 | const CallExpr *E, |
| 6653 | unsigned IntrinsicID) { |
| 6654 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 6655 | |
| 6656 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 6657 | return CGF.Builder.CreateCall(F, Src0); |
| 6658 | } |
| 6659 | |
| 6660 | // Emit an intrinsic that has 3 float or double operands. |
| 6661 | static Value *emitTernaryFPBuiltin(CodeGenFunction &CGF, |
| 6662 | const CallExpr *E, |
| 6663 | unsigned IntrinsicID) { |
| 6664 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 6665 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 6666 | llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); |
| 6667 | |
| 6668 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6669 | return CGF.Builder.CreateCall(F, {Src0, Src1, Src2}); |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6670 | } |
| 6671 | |
Matt Arsenault | dbb8491 | 2014-08-15 17:44:32 +0000 | [diff] [blame] | 6672 | // Emit an intrinsic that has 1 float or double operand, and 1 integer. |
| 6673 | static Value *emitFPIntBuiltin(CodeGenFunction &CGF, |
| 6674 | const CallExpr *E, |
| 6675 | unsigned IntrinsicID) { |
| 6676 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 6677 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 6678 | |
| 6679 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6680 | return CGF.Builder.CreateCall(F, {Src0, Src1}); |
Matt Arsenault | dbb8491 | 2014-08-15 17:44:32 +0000 | [diff] [blame] | 6681 | } |
| 6682 | |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6683 | Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, |
| 6684 | const CallExpr *E) { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 6685 | switch (BuiltinID) { |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6686 | case AMDGPU::BI__builtin_amdgpu_div_scale: |
| 6687 | case AMDGPU::BI__builtin_amdgpu_div_scalef: { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 6688 | // Translate from the intrinsics's struct return to the builtin's out |
| 6689 | // argument. |
| 6690 | |
| 6691 | std::pair<llvm::Value *, unsigned> FlagOutPtr |
| 6692 | = EmitPointerWithAlignment(E->getArg(3)); |
| 6693 | |
| 6694 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 6695 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 6696 | llvm::Value *Z = EmitScalarExpr(E->getArg(2)); |
| 6697 | |
| 6698 | llvm::Value *Callee = CGM.getIntrinsic(Intrinsic::AMDGPU_div_scale, |
| 6699 | X->getType()); |
| 6700 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6701 | llvm::Value *Tmp = Builder.CreateCall(Callee, {X, Y, Z}); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 6702 | |
| 6703 | llvm::Value *Result = Builder.CreateExtractValue(Tmp, 0); |
| 6704 | llvm::Value *Flag = Builder.CreateExtractValue(Tmp, 1); |
| 6705 | |
| 6706 | llvm::Type *RealFlagType |
| 6707 | = FlagOutPtr.first->getType()->getPointerElementType(); |
| 6708 | |
| 6709 | llvm::Value *FlagExt = Builder.CreateZExt(Flag, RealFlagType); |
| 6710 | llvm::StoreInst *FlagStore = Builder.CreateStore(FlagExt, FlagOutPtr.first); |
| 6711 | FlagStore->setAlignment(FlagOutPtr.second); |
| 6712 | return Result; |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6713 | } |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6714 | case AMDGPU::BI__builtin_amdgpu_div_fmas: |
| 6715 | case AMDGPU::BI__builtin_amdgpu_div_fmasf: { |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 6716 | llvm::Value *Src0 = EmitScalarExpr(E->getArg(0)); |
| 6717 | llvm::Value *Src1 = EmitScalarExpr(E->getArg(1)); |
| 6718 | llvm::Value *Src2 = EmitScalarExpr(E->getArg(2)); |
| 6719 | llvm::Value *Src3 = EmitScalarExpr(E->getArg(3)); |
| 6720 | |
| 6721 | llvm::Value *F = CGM.getIntrinsic(Intrinsic::AMDGPU_div_fmas, |
| 6722 | Src0->getType()); |
| 6723 | llvm::Value *Src3ToBool = Builder.CreateIsNotNull(Src3); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6724 | return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool}); |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 6725 | } |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6726 | case AMDGPU::BI__builtin_amdgpu_div_fixup: |
| 6727 | case AMDGPU::BI__builtin_amdgpu_div_fixupf: |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6728 | return emitTernaryFPBuiltin(*this, E, Intrinsic::AMDGPU_div_fixup); |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6729 | case AMDGPU::BI__builtin_amdgpu_trig_preop: |
| 6730 | case AMDGPU::BI__builtin_amdgpu_trig_preopf: |
Matt Arsenault | dbb8491 | 2014-08-15 17:44:32 +0000 | [diff] [blame] | 6731 | return emitFPIntBuiltin(*this, E, Intrinsic::AMDGPU_trig_preop); |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6732 | case AMDGPU::BI__builtin_amdgpu_rcp: |
| 6733 | case AMDGPU::BI__builtin_amdgpu_rcpf: |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6734 | return emitUnaryFPBuiltin(*this, E, Intrinsic::AMDGPU_rcp); |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6735 | case AMDGPU::BI__builtin_amdgpu_rsq: |
| 6736 | case AMDGPU::BI__builtin_amdgpu_rsqf: |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6737 | return emitUnaryFPBuiltin(*this, E, Intrinsic::AMDGPU_rsq); |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6738 | case AMDGPU::BI__builtin_amdgpu_rsq_clamped: |
| 6739 | case AMDGPU::BI__builtin_amdgpu_rsq_clampedf: |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6740 | return emitUnaryFPBuiltin(*this, E, Intrinsic::AMDGPU_rsq_clamped); |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6741 | case AMDGPU::BI__builtin_amdgpu_ldexp: |
| 6742 | case AMDGPU::BI__builtin_amdgpu_ldexpf: |
Matt Arsenault | dbb8491 | 2014-08-15 17:44:32 +0000 | [diff] [blame] | 6743 | return emitFPIntBuiltin(*this, E, Intrinsic::AMDGPU_ldexp); |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 6744 | case AMDGPU::BI__builtin_amdgpu_class: |
| 6745 | case AMDGPU::BI__builtin_amdgpu_classf: |
Matt Arsenault | 6365ffe | 2015-01-06 23:14:57 +0000 | [diff] [blame] | 6746 | return emitFPIntBuiltin(*this, E, Intrinsic::AMDGPU_class); |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 6747 | default: |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 6748 | return nullptr; |
| 6749 | } |
| 6750 | } |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6751 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6752 | /// Handle a SystemZ function in which the final argument is a pointer |
| 6753 | /// to an int that receives the post-instruction CC value. At the LLVM level |
| 6754 | /// this is represented as a function that returns a {result, cc} pair. |
| 6755 | static Value *EmitSystemZIntrinsicWithCC(CodeGenFunction &CGF, |
| 6756 | unsigned IntrinsicID, |
| 6757 | const CallExpr *E) { |
| 6758 | unsigned NumArgs = E->getNumArgs() - 1; |
| 6759 | SmallVector<Value *, 8> Args(NumArgs); |
| 6760 | for (unsigned I = 0; I < NumArgs; ++I) |
| 6761 | Args[I] = CGF.EmitScalarExpr(E->getArg(I)); |
| 6762 | Value *CCPtr = CGF.EmitScalarExpr(E->getArg(NumArgs)); |
| 6763 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID); |
| 6764 | Value *Call = CGF.Builder.CreateCall(F, Args); |
| 6765 | Value *CC = CGF.Builder.CreateExtractValue(Call, 1); |
| 6766 | CGF.Builder.CreateStore(CC, CCPtr); |
| 6767 | return CGF.Builder.CreateExtractValue(Call, 0); |
| 6768 | } |
| 6769 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6770 | Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID, |
| 6771 | const CallExpr *E) { |
| 6772 | switch (BuiltinID) { |
| 6773 | case SystemZ::BI__builtin_tbegin: { |
| 6774 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 6775 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 6776 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6777 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6778 | } |
| 6779 | case SystemZ::BI__builtin_tbegin_nofloat: { |
| 6780 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 6781 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 6782 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin_nofloat); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6783 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6784 | } |
| 6785 | case SystemZ::BI__builtin_tbeginc: { |
| 6786 | Value *TDB = llvm::ConstantPointerNull::get(Int8PtrTy); |
| 6787 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff08); |
| 6788 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbeginc); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6789 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6790 | } |
| 6791 | case SystemZ::BI__builtin_tabort: { |
| 6792 | Value *Data = EmitScalarExpr(E->getArg(0)); |
| 6793 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tabort); |
| 6794 | return Builder.CreateCall(F, Builder.CreateSExt(Data, Int64Ty, "tabort")); |
| 6795 | } |
| 6796 | case SystemZ::BI__builtin_non_tx_store: { |
| 6797 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 6798 | Value *Data = EmitScalarExpr(E->getArg(1)); |
| 6799 | Value *F = CGM.getIntrinsic(Intrinsic::s390_ntstg); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6800 | return Builder.CreateCall(F, {Data, Address}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6801 | } |
| 6802 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6803 | // Vector builtins. Note that most vector builtins are mapped automatically |
| 6804 | // to target-specific LLVM intrinsics. The ones handled specially here can |
| 6805 | // be represented via standard LLVM IR, which is preferable to enable common |
| 6806 | // LLVM optimizations. |
| 6807 | |
| 6808 | case SystemZ::BI__builtin_s390_vpopctb: |
| 6809 | case SystemZ::BI__builtin_s390_vpopcth: |
| 6810 | case SystemZ::BI__builtin_s390_vpopctf: |
| 6811 | case SystemZ::BI__builtin_s390_vpopctg: { |
| 6812 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6813 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6814 | Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 6815 | return Builder.CreateCall(F, X); |
| 6816 | } |
| 6817 | |
| 6818 | case SystemZ::BI__builtin_s390_vclzb: |
| 6819 | case SystemZ::BI__builtin_s390_vclzh: |
| 6820 | case SystemZ::BI__builtin_s390_vclzf: |
| 6821 | case SystemZ::BI__builtin_s390_vclzg: { |
| 6822 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6823 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6824 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 6825 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6826 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6827 | } |
| 6828 | |
| 6829 | case SystemZ::BI__builtin_s390_vctzb: |
| 6830 | case SystemZ::BI__builtin_s390_vctzh: |
| 6831 | case SystemZ::BI__builtin_s390_vctzf: |
| 6832 | case SystemZ::BI__builtin_s390_vctzg: { |
| 6833 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6834 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6835 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 6836 | Function *F = CGM.getIntrinsic(Intrinsic::cttz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6837 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | case SystemZ::BI__builtin_s390_vfsqdb: { |
| 6841 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6842 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6843 | Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType); |
| 6844 | return Builder.CreateCall(F, X); |
| 6845 | } |
| 6846 | case SystemZ::BI__builtin_s390_vfmadb: { |
| 6847 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6848 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6849 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 6850 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 6851 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6852 | return Builder.CreateCall(F, {X, Y, Z}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6853 | } |
| 6854 | case SystemZ::BI__builtin_s390_vfmsdb: { |
| 6855 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6856 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6857 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 6858 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 6859 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 6860 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6861 | return Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6862 | } |
| 6863 | case SystemZ::BI__builtin_s390_vflpdb: { |
| 6864 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6865 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6866 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 6867 | return Builder.CreateCall(F, X); |
| 6868 | } |
| 6869 | case SystemZ::BI__builtin_s390_vflndb: { |
| 6870 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6871 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6872 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 6873 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 6874 | return Builder.CreateFSub(Zero, Builder.CreateCall(F, X), "sub"); |
| 6875 | } |
| 6876 | case SystemZ::BI__builtin_s390_vfidb: { |
| 6877 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6878 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6879 | // Constant-fold the M4 and M5 mask arguments. |
| 6880 | llvm::APSInt M4, M5; |
| 6881 | bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext()); |
| 6882 | bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext()); |
| 6883 | assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?"); |
| 6884 | (void)IsConstM4; (void)IsConstM5; |
| 6885 | // Check whether this instance of vfidb can be represented via a LLVM |
| 6886 | // standard intrinsic. We only support some combinations of M4 and M5. |
| 6887 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 6888 | switch (M4.getZExtValue()) { |
| 6889 | default: break; |
| 6890 | case 0: // IEEE-inexact exception allowed |
| 6891 | switch (M5.getZExtValue()) { |
| 6892 | default: break; |
| 6893 | case 0: ID = Intrinsic::rint; break; |
| 6894 | } |
| 6895 | break; |
| 6896 | case 4: // IEEE-inexact exception suppressed |
| 6897 | switch (M5.getZExtValue()) { |
| 6898 | default: break; |
| 6899 | case 0: ID = Intrinsic::nearbyint; break; |
| 6900 | case 1: ID = Intrinsic::round; break; |
| 6901 | case 5: ID = Intrinsic::trunc; break; |
| 6902 | case 6: ID = Intrinsic::ceil; break; |
| 6903 | case 7: ID = Intrinsic::floor; break; |
| 6904 | } |
| 6905 | break; |
| 6906 | } |
| 6907 | if (ID != Intrinsic::not_intrinsic) { |
| 6908 | Function *F = CGM.getIntrinsic(ID, ResultType); |
| 6909 | return Builder.CreateCall(F, X); |
| 6910 | } |
| 6911 | Function *F = CGM.getIntrinsic(Intrinsic::s390_vfidb); |
| 6912 | Value *M4Value = llvm::ConstantInt::get(getLLVMContext(), M4); |
| 6913 | Value *M5Value = llvm::ConstantInt::get(getLLVMContext(), M5); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6914 | return Builder.CreateCall(F, {X, M4Value, M5Value}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | // Vector intrisincs that output the post-instruction CC value. |
| 6918 | |
| 6919 | #define INTRINSIC_WITH_CC(NAME) \ |
| 6920 | case SystemZ::BI__builtin_##NAME: \ |
| 6921 | return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E) |
| 6922 | |
| 6923 | INTRINSIC_WITH_CC(s390_vpkshs); |
| 6924 | INTRINSIC_WITH_CC(s390_vpksfs); |
| 6925 | INTRINSIC_WITH_CC(s390_vpksgs); |
| 6926 | |
| 6927 | INTRINSIC_WITH_CC(s390_vpklshs); |
| 6928 | INTRINSIC_WITH_CC(s390_vpklsfs); |
| 6929 | INTRINSIC_WITH_CC(s390_vpklsgs); |
| 6930 | |
| 6931 | INTRINSIC_WITH_CC(s390_vceqbs); |
| 6932 | INTRINSIC_WITH_CC(s390_vceqhs); |
| 6933 | INTRINSIC_WITH_CC(s390_vceqfs); |
| 6934 | INTRINSIC_WITH_CC(s390_vceqgs); |
| 6935 | |
| 6936 | INTRINSIC_WITH_CC(s390_vchbs); |
| 6937 | INTRINSIC_WITH_CC(s390_vchhs); |
| 6938 | INTRINSIC_WITH_CC(s390_vchfs); |
| 6939 | INTRINSIC_WITH_CC(s390_vchgs); |
| 6940 | |
| 6941 | INTRINSIC_WITH_CC(s390_vchlbs); |
| 6942 | INTRINSIC_WITH_CC(s390_vchlhs); |
| 6943 | INTRINSIC_WITH_CC(s390_vchlfs); |
| 6944 | INTRINSIC_WITH_CC(s390_vchlgs); |
| 6945 | |
| 6946 | INTRINSIC_WITH_CC(s390_vfaebs); |
| 6947 | INTRINSIC_WITH_CC(s390_vfaehs); |
| 6948 | INTRINSIC_WITH_CC(s390_vfaefs); |
| 6949 | |
| 6950 | INTRINSIC_WITH_CC(s390_vfaezbs); |
| 6951 | INTRINSIC_WITH_CC(s390_vfaezhs); |
| 6952 | INTRINSIC_WITH_CC(s390_vfaezfs); |
| 6953 | |
| 6954 | INTRINSIC_WITH_CC(s390_vfeebs); |
| 6955 | INTRINSIC_WITH_CC(s390_vfeehs); |
| 6956 | INTRINSIC_WITH_CC(s390_vfeefs); |
| 6957 | |
| 6958 | INTRINSIC_WITH_CC(s390_vfeezbs); |
| 6959 | INTRINSIC_WITH_CC(s390_vfeezhs); |
| 6960 | INTRINSIC_WITH_CC(s390_vfeezfs); |
| 6961 | |
| 6962 | INTRINSIC_WITH_CC(s390_vfenebs); |
| 6963 | INTRINSIC_WITH_CC(s390_vfenehs); |
| 6964 | INTRINSIC_WITH_CC(s390_vfenefs); |
| 6965 | |
| 6966 | INTRINSIC_WITH_CC(s390_vfenezbs); |
| 6967 | INTRINSIC_WITH_CC(s390_vfenezhs); |
| 6968 | INTRINSIC_WITH_CC(s390_vfenezfs); |
| 6969 | |
| 6970 | INTRINSIC_WITH_CC(s390_vistrbs); |
| 6971 | INTRINSIC_WITH_CC(s390_vistrhs); |
| 6972 | INTRINSIC_WITH_CC(s390_vistrfs); |
| 6973 | |
| 6974 | INTRINSIC_WITH_CC(s390_vstrcbs); |
| 6975 | INTRINSIC_WITH_CC(s390_vstrchs); |
| 6976 | INTRINSIC_WITH_CC(s390_vstrcfs); |
| 6977 | |
| 6978 | INTRINSIC_WITH_CC(s390_vstrczbs); |
| 6979 | INTRINSIC_WITH_CC(s390_vstrczhs); |
| 6980 | INTRINSIC_WITH_CC(s390_vstrczfs); |
| 6981 | |
| 6982 | INTRINSIC_WITH_CC(s390_vfcedbs); |
| 6983 | INTRINSIC_WITH_CC(s390_vfchdbs); |
| 6984 | INTRINSIC_WITH_CC(s390_vfchedbs); |
| 6985 | |
| 6986 | INTRINSIC_WITH_CC(s390_vftcidb); |
| 6987 | |
| 6988 | #undef INTRINSIC_WITH_CC |
| 6989 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 6990 | default: |
| 6991 | return nullptr; |
| 6992 | } |
| 6993 | } |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 6994 | |
| 6995 | Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, |
| 6996 | const CallExpr *E) { |
| 6997 | switch (BuiltinID) { |
| 6998 | case NVPTX::BI__nvvm_atom_add_gen_i: |
| 6999 | case NVPTX::BI__nvvm_atom_add_gen_l: |
| 7000 | case NVPTX::BI__nvvm_atom_add_gen_ll: |
| 7001 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Add, E); |
| 7002 | |
| 7003 | case NVPTX::BI__nvvm_atom_sub_gen_i: |
| 7004 | case NVPTX::BI__nvvm_atom_sub_gen_l: |
| 7005 | case NVPTX::BI__nvvm_atom_sub_gen_ll: |
| 7006 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Sub, E); |
| 7007 | |
| 7008 | case NVPTX::BI__nvvm_atom_and_gen_i: |
| 7009 | case NVPTX::BI__nvvm_atom_and_gen_l: |
| 7010 | case NVPTX::BI__nvvm_atom_and_gen_ll: |
| 7011 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::And, E); |
| 7012 | |
| 7013 | case NVPTX::BI__nvvm_atom_or_gen_i: |
| 7014 | case NVPTX::BI__nvvm_atom_or_gen_l: |
| 7015 | case NVPTX::BI__nvvm_atom_or_gen_ll: |
| 7016 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Or, E); |
| 7017 | |
| 7018 | case NVPTX::BI__nvvm_atom_xor_gen_i: |
| 7019 | case NVPTX::BI__nvvm_atom_xor_gen_l: |
| 7020 | case NVPTX::BI__nvvm_atom_xor_gen_ll: |
| 7021 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xor, E); |
| 7022 | |
| 7023 | case NVPTX::BI__nvvm_atom_xchg_gen_i: |
| 7024 | case NVPTX::BI__nvvm_atom_xchg_gen_l: |
| 7025 | case NVPTX::BI__nvvm_atom_xchg_gen_ll: |
| 7026 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xchg, E); |
| 7027 | |
| 7028 | case NVPTX::BI__nvvm_atom_max_gen_i: |
| 7029 | case NVPTX::BI__nvvm_atom_max_gen_l: |
| 7030 | case NVPTX::BI__nvvm_atom_max_gen_ll: |
| 7031 | case NVPTX::BI__nvvm_atom_max_gen_ui: |
| 7032 | case NVPTX::BI__nvvm_atom_max_gen_ul: |
| 7033 | case NVPTX::BI__nvvm_atom_max_gen_ull: |
| 7034 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Max, E); |
| 7035 | |
| 7036 | case NVPTX::BI__nvvm_atom_min_gen_i: |
| 7037 | case NVPTX::BI__nvvm_atom_min_gen_l: |
| 7038 | case NVPTX::BI__nvvm_atom_min_gen_ll: |
| 7039 | case NVPTX::BI__nvvm_atom_min_gen_ui: |
| 7040 | case NVPTX::BI__nvvm_atom_min_gen_ul: |
| 7041 | case NVPTX::BI__nvvm_atom_min_gen_ull: |
| 7042 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Min, E); |
| 7043 | |
| 7044 | case NVPTX::BI__nvvm_atom_cas_gen_i: |
| 7045 | case NVPTX::BI__nvvm_atom_cas_gen_l: |
| 7046 | case NVPTX::BI__nvvm_atom_cas_gen_ll: |
| 7047 | return MakeAtomicCmpXchgValue(*this, E, true); |
| 7048 | |
| 7049 | case NVPTX::BI__nvvm_atom_add_gen_f: { |
| 7050 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 7051 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 7052 | // atomicrmw only deals with integer arguments so we need to use |
| 7053 | // LLVM's nvvm_atomic_load_add_f32 intrinsic for that. |
| 7054 | Value *FnALAF32 = |
| 7055 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_add_f32, Ptr->getType()); |
| 7056 | return Builder.CreateCall(FnALAF32, {Ptr, Val}); |
| 7057 | } |
| 7058 | |
| 7059 | default: |
| 7060 | return nullptr; |
| 7061 | } |
| 7062 | } |