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 |
Eric Christopher | 02d5d86 | 2015-08-06 01:01:12 +0000 | [diff] [blame] | 51 | Name = Context.BuiltinInfo.getName(BuiltinID) + 10; |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 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 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 108 | llvm::Value *Result = CGF.Builder.CreateAtomicRMW( |
| 109 | Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 110 | return EmitFromInt(CGF, Result, T, ValueType); |
| 111 | } |
| 112 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 113 | static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) { |
| 114 | Value *Val = CGF.EmitScalarExpr(E->getArg(0)); |
| 115 | Value *Address = CGF.EmitScalarExpr(E->getArg(1)); |
| 116 | |
| 117 | // Convert the type of the pointer to a pointer to the stored type. |
| 118 | Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); |
| 119 | Value *BC = CGF.Builder.CreateBitCast( |
| 120 | Address, llvm::PointerType::getUnqual(Val->getType()), "cast"); |
| 121 | LValue LV = CGF.MakeNaturalAlignAddrLValue(BC, E->getArg(0)->getType()); |
| 122 | LV.setNontemporal(true); |
| 123 | CGF.EmitStoreOfScalar(Val, LV, false); |
| 124 | return nullptr; |
| 125 | } |
| 126 | |
| 127 | static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) { |
| 128 | Value *Address = CGF.EmitScalarExpr(E->getArg(0)); |
| 129 | |
| 130 | LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType()); |
| 131 | LV.setNontemporal(true); |
| 132 | return CGF.EmitLoadOfScalar(LV, E->getExprLoc()); |
| 133 | } |
| 134 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 135 | static RValue EmitBinaryAtomic(CodeGenFunction &CGF, |
| 136 | llvm::AtomicRMWInst::BinOp Kind, |
| 137 | const CallExpr *E) { |
| 138 | return RValue::get(MakeBinaryAtomicValue(CGF, Kind, E)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /// Utility to insert an atomic instruction based Instrinsic::ID and |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 142 | /// the expression node, where the return value is the result of the |
| 143 | /// operation. |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 144 | static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF, |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 145 | llvm::AtomicRMWInst::BinOp Kind, |
| 146 | const CallExpr *E, |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 147 | Instruction::BinaryOps Op, |
| 148 | bool Invert = false) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 149 | QualType T = E->getType(); |
| 150 | assert(E->getArg(0)->getType()->isPointerType()); |
| 151 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 152 | E->getArg(0)->getType()->getPointeeType())); |
| 153 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 154 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 155 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 156 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 157 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 158 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 159 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 160 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 161 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 162 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 163 | llvm::Value *Args[2]; |
| 164 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 165 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 166 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 167 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 168 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 169 | llvm::Value *Result = CGF.Builder.CreateAtomicRMW( |
| 170 | Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 171 | Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 172 | if (Invert) |
| 173 | Result = CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result, |
| 174 | llvm::ConstantInt::get(IntType, -1)); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 175 | Result = EmitFromInt(CGF, Result, T, ValueType); |
| 176 | return RValue::get(Result); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 179 | /// @brief Utility to insert an atomic cmpxchg instruction. |
| 180 | /// |
| 181 | /// @param CGF The current codegen function. |
| 182 | /// @param E Builtin call expression to convert to cmpxchg. |
| 183 | /// arg0 - address to operate on |
| 184 | /// arg1 - value to compare with |
| 185 | /// arg2 - new value |
| 186 | /// @param ReturnBool Specifies whether to return success flag of |
| 187 | /// cmpxchg result or the old value. |
| 188 | /// |
| 189 | /// @returns result of cmpxchg, according to ReturnBool |
| 190 | static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E, |
| 191 | bool ReturnBool) { |
| 192 | QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType(); |
| 193 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
| 194 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
| 195 | |
| 196 | llvm::IntegerType *IntType = llvm::IntegerType::get( |
| 197 | CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); |
| 198 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
| 199 | |
| 200 | Value *Args[3]; |
| 201 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 202 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
| 203 | llvm::Type *ValueType = Args[1]->getType(); |
| 204 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 205 | Args[2] = EmitToInt(CGF, CGF.EmitScalarExpr(E->getArg(2)), T, IntType); |
| 206 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 207 | Value *Pair = CGF.Builder.CreateAtomicCmpXchg( |
| 208 | Args[0], Args[1], Args[2], llvm::AtomicOrdering::SequentiallyConsistent, |
| 209 | llvm::AtomicOrdering::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 210 | if (ReturnBool) |
| 211 | // Extract boolean success flag and zext it to int. |
| 212 | return CGF.Builder.CreateZExt(CGF.Builder.CreateExtractValue(Pair, 1), |
| 213 | CGF.ConvertType(E->getType())); |
| 214 | else |
| 215 | // Extract old value and emit it using the same type as compare value. |
| 216 | return EmitFromInt(CGF, CGF.Builder.CreateExtractValue(Pair, 0), T, |
| 217 | ValueType); |
| 218 | } |
| 219 | |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 220 | /// EmitFAbs - Emit a call to @llvm.fabs(). |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 221 | static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) { |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 222 | Value *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType()); |
| 223 | llvm::CallInst *Call = CGF.Builder.CreateCall(F, V); |
| 224 | Call->setDoesNotAccessMemory(); |
| 225 | return Call; |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 228 | /// Emit the computation of the sign bit for a floating point value. Returns |
| 229 | /// the i1 sign bit value. |
| 230 | static Value *EmitSignBit(CodeGenFunction &CGF, Value *V) { |
| 231 | LLVMContext &C = CGF.CGM.getLLVMContext(); |
| 232 | |
| 233 | llvm::Type *Ty = V->getType(); |
| 234 | int Width = Ty->getPrimitiveSizeInBits(); |
| 235 | llvm::Type *IntTy = llvm::IntegerType::get(C, Width); |
| 236 | V = CGF.Builder.CreateBitCast(V, IntTy); |
| 237 | if (Ty->isPPC_FP128Ty()) { |
Petar Jovanovic | 73d1044 | 2015-11-06 14:52:46 +0000 | [diff] [blame] | 238 | // We want the sign bit of the higher-order double. The bitcast we just |
| 239 | // did works as if the double-double was stored to memory and then |
| 240 | // read as an i128. The "store" will put the higher-order double in the |
| 241 | // lower address in both little- and big-Endian modes, but the "load" |
| 242 | // will treat those bits as a different part of the i128: the low bits in |
| 243 | // little-Endian, the high bits in big-Endian. Therefore, on big-Endian |
| 244 | // we need to shift the high bits down to the low before truncating. |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 245 | Width >>= 1; |
Petar Jovanovic | 73d1044 | 2015-11-06 14:52:46 +0000 | [diff] [blame] | 246 | if (CGF.getTarget().isBigEndian()) { |
| 247 | Value *ShiftCst = llvm::ConstantInt::get(IntTy, Width); |
| 248 | V = CGF.Builder.CreateLShr(V, ShiftCst); |
| 249 | } |
| 250 | // We are truncating value in order to extract the higher-order |
| 251 | // double, which we will be using to extract the sign from. |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 252 | IntTy = llvm::IntegerType::get(C, Width); |
| 253 | V = CGF.Builder.CreateTrunc(V, IntTy); |
| 254 | } |
| 255 | Value *Zero = llvm::Constant::getNullValue(IntTy); |
| 256 | return CGF.Builder.CreateICmpSLT(V, Zero); |
| 257 | } |
| 258 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 259 | static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *Fn, |
| 260 | const CallExpr *E, llvm::Value *calleeValue) { |
Alexey Samsonov | 70b9c01 | 2014-08-21 20:26:47 +0000 | [diff] [blame] | 261 | return CGF.EmitCall(E->getCallee()->getType(), calleeValue, E, |
| 262 | ReturnValueSlot(), Fn); |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 265 | /// \brief Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.* |
| 266 | /// depending on IntrinsicID. |
| 267 | /// |
| 268 | /// \arg CGF The current codegen function. |
| 269 | /// \arg IntrinsicID The ID for the Intrinsic we wish to generate. |
| 270 | /// \arg X The first argument to the llvm.*.with.overflow.*. |
| 271 | /// \arg Y The second argument to the llvm.*.with.overflow.*. |
| 272 | /// \arg Carry The carry returned by the llvm.*.with.overflow.*. |
| 273 | /// \returns The result (i.e. sum/product) returned by the intrinsic. |
| 274 | static llvm::Value *EmitOverflowIntrinsic(CodeGenFunction &CGF, |
| 275 | const llvm::Intrinsic::ID IntrinsicID, |
| 276 | llvm::Value *X, llvm::Value *Y, |
| 277 | llvm::Value *&Carry) { |
| 278 | // Make sure we have integers of the same width. |
| 279 | assert(X->getType() == Y->getType() && |
| 280 | "Arguments must be the same type. (Did you forget to make sure both " |
| 281 | "arguments have the same integer width?)"); |
| 282 | |
NAKAMURA Takumi | 7ab4fbf | 2013-01-13 11:26:44 +0000 | [diff] [blame] | 283 | llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 284 | llvm::Value *Tmp = CGF.Builder.CreateCall(Callee, {X, Y}); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 285 | Carry = CGF.Builder.CreateExtractValue(Tmp, 1); |
| 286 | return CGF.Builder.CreateExtractValue(Tmp, 0); |
| 287 | } |
| 288 | |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 289 | // Emit a simple mangled intrinsic that has 1 argument and a return type |
| 290 | // matching the argument type. |
| 291 | static Value *emitUnaryBuiltin(CodeGenFunction &CGF, |
| 292 | const CallExpr *E, |
| 293 | unsigned IntrinsicID) { |
| 294 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 295 | |
| 296 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 297 | return CGF.Builder.CreateCall(F, Src0); |
| 298 | } |
| 299 | |
| 300 | // Emit an intrinsic that has 3 float or double operands. |
| 301 | static Value *emitTernaryFPBuiltin(CodeGenFunction &CGF, |
| 302 | const CallExpr *E, |
| 303 | unsigned IntrinsicID) { |
| 304 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 305 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 306 | llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); |
| 307 | |
| 308 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 309 | return CGF.Builder.CreateCall(F, {Src0, Src1, Src2}); |
| 310 | } |
| 311 | |
| 312 | // Emit an intrinsic that has 1 float or double operand, and 1 integer. |
| 313 | static Value *emitFPIntBuiltin(CodeGenFunction &CGF, |
| 314 | const CallExpr *E, |
| 315 | unsigned IntrinsicID) { |
| 316 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 317 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 318 | |
| 319 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 320 | return CGF.Builder.CreateCall(F, {Src0, Src1}); |
| 321 | } |
| 322 | |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 323 | namespace { |
| 324 | struct WidthAndSignedness { |
| 325 | unsigned Width; |
| 326 | bool Signed; |
| 327 | }; |
| 328 | } |
| 329 | |
| 330 | static WidthAndSignedness |
| 331 | getIntegerWidthAndSignedness(const clang::ASTContext &context, |
| 332 | const clang::QualType Type) { |
| 333 | assert(Type->isIntegerType() && "Given type is not an integer."); |
| 334 | unsigned Width = Type->isBooleanType() ? 1 : context.getTypeInfo(Type).Width; |
| 335 | bool Signed = Type->isSignedIntegerType(); |
| 336 | return {Width, Signed}; |
| 337 | } |
| 338 | |
| 339 | // Given one or more integer types, this function produces an integer type that |
| 340 | // encompasses them: any value in one of the given types could be expressed in |
| 341 | // the encompassing type. |
| 342 | static struct WidthAndSignedness |
| 343 | EncompassingIntegerType(ArrayRef<struct WidthAndSignedness> Types) { |
| 344 | assert(Types.size() > 0 && "Empty list of types."); |
| 345 | |
| 346 | // If any of the given types is signed, we must return a signed type. |
| 347 | bool Signed = false; |
| 348 | for (const auto &Type : Types) { |
| 349 | Signed |= Type.Signed; |
| 350 | } |
| 351 | |
| 352 | // The encompassing type must have a width greater than or equal to the width |
| 353 | // of the specified types. Aditionally, if the encompassing type is signed, |
| 354 | // its width must be strictly greater than the width of any unsigned types |
| 355 | // given. |
| 356 | unsigned Width = 0; |
| 357 | for (const auto &Type : Types) { |
| 358 | unsigned MinWidth = Type.Width + (Signed && !Type.Signed); |
| 359 | if (Width < MinWidth) { |
| 360 | Width = MinWidth; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | return {Width, Signed}; |
| 365 | } |
| 366 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 367 | Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) { |
| 368 | llvm::Type *DestType = Int8PtrTy; |
| 369 | if (ArgValue->getType() != DestType) |
| 370 | ArgValue = |
| 371 | Builder.CreateBitCast(ArgValue, DestType, ArgValue->getName().data()); |
| 372 | |
| 373 | Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend; |
| 374 | return Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue); |
| 375 | } |
| 376 | |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 377 | /// Checks if using the result of __builtin_object_size(p, @p From) in place of |
| 378 | /// __builtin_object_size(p, @p To) is correct |
| 379 | static bool areBOSTypesCompatible(int From, int To) { |
| 380 | // Note: Our __builtin_object_size implementation currently treats Type=0 and |
| 381 | // Type=2 identically. Encoding this implementation detail here may make |
| 382 | // improving __builtin_object_size difficult in the future, so it's omitted. |
| 383 | return From == To || (From == 0 && To == 1) || (From == 3 && To == 2); |
| 384 | } |
| 385 | |
| 386 | static llvm::Value * |
| 387 | getDefaultBuiltinObjectSizeResult(unsigned Type, llvm::IntegerType *ResType) { |
| 388 | return ConstantInt::get(ResType, (Type & 2) ? 0 : -1, /*isSigned=*/true); |
| 389 | } |
| 390 | |
| 391 | llvm::Value * |
| 392 | CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, |
| 393 | llvm::IntegerType *ResType) { |
| 394 | uint64_t ObjectSize; |
| 395 | if (!E->tryEvaluateObjectSize(ObjectSize, getContext(), Type)) |
| 396 | return emitBuiltinObjectSize(E, Type, ResType); |
| 397 | return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); |
| 398 | } |
| 399 | |
| 400 | /// Returns a Value corresponding to the size of the given expression. |
| 401 | /// This Value may be either of the following: |
| 402 | /// - A llvm::Argument (if E is a param with the pass_object_size attribute on |
| 403 | /// it) |
| 404 | /// - A call to the @llvm.objectsize intrinsic |
| 405 | llvm::Value * |
| 406 | CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type, |
| 407 | llvm::IntegerType *ResType) { |
| 408 | // We need to reference an argument if the pointer is a parameter with the |
| 409 | // pass_object_size attribute. |
| 410 | if (auto *D = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) { |
| 411 | auto *Param = dyn_cast<ParmVarDecl>(D->getDecl()); |
| 412 | auto *PS = D->getDecl()->getAttr<PassObjectSizeAttr>(); |
| 413 | if (Param != nullptr && PS != nullptr && |
| 414 | areBOSTypesCompatible(PS->getType(), Type)) { |
| 415 | auto Iter = SizeArguments.find(Param); |
| 416 | assert(Iter != SizeArguments.end()); |
| 417 | |
| 418 | const ImplicitParamDecl *D = Iter->second; |
| 419 | auto DIter = LocalDeclMap.find(D); |
| 420 | assert(DIter != LocalDeclMap.end()); |
| 421 | |
| 422 | return EmitLoadOfScalar(DIter->second, /*volatile=*/false, |
| 423 | getContext().getSizeType(), E->getLocStart()); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | // LLVM can't handle Type=3 appropriately, and __builtin_object_size shouldn't |
| 428 | // evaluate E for side-effects. In either case, we shouldn't lower to |
| 429 | // @llvm.objectsize. |
| 430 | if (Type == 3 || E->HasSideEffects(getContext())) |
| 431 | return getDefaultBuiltinObjectSizeResult(Type, ResType); |
| 432 | |
| 433 | // LLVM only supports 0 and 2, make sure that we pass along that |
| 434 | // as a boolean. |
| 435 | auto *CI = ConstantInt::get(Builder.getInt1Ty(), (Type & 2) >> 1); |
| 436 | // FIXME: Get right address space. |
| 437 | llvm::Type *Tys[] = {ResType, Builder.getInt8PtrTy(0)}; |
| 438 | Value *F = CGM.getIntrinsic(Intrinsic::objectsize, Tys); |
| 439 | return Builder.CreateCall(F, {EmitScalarExpr(E), CI}); |
| 440 | } |
| 441 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 443 | unsigned BuiltinID, const CallExpr *E, |
| 444 | ReturnValueSlot ReturnValue) { |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 445 | // 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] | 446 | Expr::EvalResult Result; |
Eli Friedman | df88c54 | 2012-01-06 20:03:09 +0000 | [diff] [blame] | 447 | if (E->EvaluateAsRValue(Result, CGM.getContext()) && |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 448 | !Result.hasSideEffects()) { |
Anders Carlsson | c968790 | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 449 | if (Result.Val.isInt()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 450 | return RValue::get(llvm::ConstantInt::get(getLLVMContext(), |
Owen Anderson | b7a2fe6 | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 451 | Result.Val.getInt())); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 452 | if (Result.Val.isFloat()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 453 | return RValue::get(llvm::ConstantFP::get(getLLVMContext(), |
| 454 | Result.Val.getFloat())); |
Chris Lattner | a1518b1 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 455 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 457 | switch (BuiltinID) { |
| 458 | default: break; // Handle intrinsics and libm functions below. |
Chris Lattner | a97132a | 2008-10-06 07:26:43 +0000 | [diff] [blame] | 459 | case Builtin::BI__builtin___CFStringMakeConstantString: |
David Chisnall | 481e3a8 | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 460 | case Builtin::BI__builtin___NSStringMakeConstantString: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 461 | return RValue::get(CGM.EmitConstantExpr(E, E->getType(), nullptr)); |
Chris Lattner | 0bf6791 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 462 | case Builtin::BI__builtin_stdarg_start: |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 463 | case Builtin::BI__builtin_va_start: |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 464 | case Builtin::BI__va_start: |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 465 | case Builtin::BI__builtin_va_end: |
| 466 | return RValue::get( |
| 467 | EmitVAStartEnd(BuiltinID == Builtin::BI__va_start |
| 468 | ? EmitScalarExpr(E->getArg(0)) |
| 469 | : EmitVAListRef(E->getArg(0)).getPointer(), |
| 470 | BuiltinID != Builtin::BI__builtin_va_end)); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 471 | case Builtin::BI__builtin_va_copy: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 472 | Value *DstPtr = EmitVAListRef(E->getArg(0)).getPointer(); |
| 473 | Value *SrcPtr = EmitVAListRef(E->getArg(1)).getPointer(); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 474 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 475 | llvm::Type *Type = Int8PtrTy; |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 476 | |
| 477 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 478 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 479 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), |
| 480 | {DstPtr, SrcPtr})); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 481 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 482 | case Builtin::BI__builtin_abs: |
Eli Friedman | 65499b4 | 2012-01-17 22:11:30 +0000 | [diff] [blame] | 483 | case Builtin::BI__builtin_labs: |
| 484 | case Builtin::BI__builtin_llabs: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 486 | |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 487 | Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | Value *CmpResult = |
| 489 | Builder.CreateICmpSGE(ArgValue, |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 490 | llvm::Constant::getNullValue(ArgValue->getType()), |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 491 | "abscond"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | Value *Result = |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 493 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 494 | |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 495 | return RValue::get(Result); |
| 496 | } |
Reid Kleckner | 06ea7d6 | 2014-11-03 23:52:09 +0000 | [diff] [blame] | 497 | case Builtin::BI__builtin_fabs: |
| 498 | case Builtin::BI__builtin_fabsf: |
| 499 | case Builtin::BI__builtin_fabsl: { |
| 500 | Value *Arg1 = EmitScalarExpr(E->getArg(0)); |
| 501 | Value *Result = EmitFAbs(*this, Arg1); |
| 502 | return RValue::get(Result); |
| 503 | } |
Jan Vesely | b4379f9 | 2014-09-26 01:19:41 +0000 | [diff] [blame] | 504 | case Builtin::BI__builtin_fmod: |
| 505 | case Builtin::BI__builtin_fmodf: |
| 506 | case Builtin::BI__builtin_fmodl: { |
| 507 | Value *Arg1 = EmitScalarExpr(E->getArg(0)); |
| 508 | Value *Arg2 = EmitScalarExpr(E->getArg(1)); |
| 509 | Value *Result = Builder.CreateFRem(Arg1, Arg2, "fmod"); |
| 510 | return RValue::get(Result); |
| 511 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 512 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 513 | case Builtin::BI__builtin_conj: |
| 514 | case Builtin::BI__builtin_conjf: |
| 515 | case Builtin::BI__builtin_conjl: { |
| 516 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 517 | Value *Real = ComplexVal.first; |
| 518 | Value *Imag = ComplexVal.second; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 519 | Value *Zero = |
| 520 | Imag->getType()->isFPOrFPVectorTy() |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 521 | ? llvm::ConstantFP::getZeroValueForNegation(Imag->getType()) |
| 522 | : llvm::Constant::getNullValue(Imag->getType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 523 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 524 | Imag = Builder.CreateFSub(Zero, Imag, "sub"); |
| 525 | return RValue::getComplex(std::make_pair(Real, Imag)); |
| 526 | } |
| 527 | case Builtin::BI__builtin_creal: |
| 528 | case Builtin::BI__builtin_crealf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 529 | case Builtin::BI__builtin_creall: |
| 530 | case Builtin::BIcreal: |
| 531 | case Builtin::BIcrealf: |
| 532 | case Builtin::BIcreall: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 533 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 534 | return RValue::get(ComplexVal.first); |
| 535 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 536 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 537 | case Builtin::BI__builtin_cimag: |
| 538 | case Builtin::BI__builtin_cimagf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 539 | case Builtin::BI__builtin_cimagl: |
| 540 | case Builtin::BIcimag: |
| 541 | case Builtin::BIcimagf: |
| 542 | case Builtin::BIcimagl: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 543 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 544 | return RValue::get(ComplexVal.second); |
| 545 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 546 | |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 547 | case Builtin::BI__builtin_ctzs: |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 548 | case Builtin::BI__builtin_ctz: |
| 549 | case Builtin::BI__builtin_ctzl: |
| 550 | case Builtin::BI__builtin_ctzll: { |
| 551 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 553 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 554 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 555 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 556 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 557 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 558 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 559 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 560 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 561 | "cast"); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 562 | return RValue::get(Result); |
| 563 | } |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 564 | case Builtin::BI__builtin_clzs: |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 565 | case Builtin::BI__builtin_clz: |
| 566 | case Builtin::BI__builtin_clzl: |
| 567 | case Builtin::BI__builtin_clzll: { |
| 568 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 570 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 571 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 572 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 573 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 574 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 575 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 576 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 577 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 578 | "cast"); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 579 | return RValue::get(Result); |
| 580 | } |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 581 | case Builtin::BI__builtin_ffs: |
| 582 | case Builtin::BI__builtin_ffsl: |
| 583 | case Builtin::BI__builtin_ffsll: { |
| 584 | // ffs(x) -> x ? cttz(x) + 1 : 0 |
| 585 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 587 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 588 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 589 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 590 | llvm::Type *ResultType = ConvertType(E->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 591 | Value *Tmp = |
| 592 | Builder.CreateAdd(Builder.CreateCall(F, {ArgValue, Builder.getTrue()}), |
| 593 | llvm::ConstantInt::get(ArgType, 1)); |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 594 | Value *Zero = llvm::Constant::getNullValue(ArgType); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 595 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); |
| 596 | Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); |
| 597 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 598 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 599 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 600 | return RValue::get(Result); |
| 601 | } |
| 602 | case Builtin::BI__builtin_parity: |
| 603 | case Builtin::BI__builtin_parityl: |
| 604 | case Builtin::BI__builtin_parityll: { |
| 605 | // parity(x) -> ctpop(x) & 1 |
| 606 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 608 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 609 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 611 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 612 | Value *Tmp = Builder.CreateCall(F, ArgValue); |
| 613 | Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1)); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 614 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 615 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 616 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 617 | return RValue::get(Result); |
| 618 | } |
| 619 | case Builtin::BI__builtin_popcount: |
| 620 | case Builtin::BI__builtin_popcountl: |
| 621 | case Builtin::BI__builtin_popcountll: { |
| 622 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 624 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 625 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 627 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 628 | Value *Result = Builder.CreateCall(F, ArgValue); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 629 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 630 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 631 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 632 | return RValue::get(Result); |
| 633 | } |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 634 | case Builtin::BI__builtin_unpredictable: { |
| 635 | // Always return the argument of __builtin_unpredictable. LLVM does not |
| 636 | // handle this builtin. Metadata for this builtin should be added directly |
| 637 | // to instructions such as branches or switches that use it. |
| 638 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
| 639 | } |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 640 | case Builtin::BI__builtin_expect: { |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 641 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 642 | llvm::Type *ArgType = ArgValue->getType(); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 643 | |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 644 | Value *ExpectedValue = EmitScalarExpr(E->getArg(1)); |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 645 | // Don't generate llvm.expect on -O0 as the backend won't use it for |
| 646 | // anything. |
| 647 | // Note, we still IRGen ExpectedValue because it could have side-effects. |
| 648 | if (CGM.getCodeGenOpts().OptimizationLevel == 0) |
| 649 | return RValue::get(ArgValue); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 650 | |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 651 | Value *FnExpect = CGM.getIntrinsic(Intrinsic::expect, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 652 | Value *Result = |
| 653 | Builder.CreateCall(FnExpect, {ArgValue, ExpectedValue}, "expval"); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 654 | return RValue::get(Result); |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 655 | } |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 656 | case Builtin::BI__builtin_assume_aligned: { |
| 657 | Value *PtrValue = EmitScalarExpr(E->getArg(0)); |
| 658 | Value *OffsetValue = |
| 659 | (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr; |
| 660 | |
| 661 | Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); |
| 662 | ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue); |
| 663 | unsigned Alignment = (unsigned) AlignmentCI->getZExtValue(); |
| 664 | |
| 665 | EmitAlignmentAssumption(PtrValue, Alignment, OffsetValue); |
| 666 | return RValue::get(PtrValue); |
| 667 | } |
| 668 | case Builtin::BI__assume: |
| 669 | case Builtin::BI__builtin_assume: { |
| 670 | if (E->getArg(0)->HasSideEffects(getContext())) |
| 671 | return RValue::get(nullptr); |
| 672 | |
| 673 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 674 | Value *FnAssume = CGM.getIntrinsic(Intrinsic::assume); |
| 675 | return RValue::get(Builder.CreateCall(FnAssume, ArgValue)); |
| 676 | } |
Benjamin Kramer | a801f4a | 2012-10-06 14:42:22 +0000 | [diff] [blame] | 677 | case Builtin::BI__builtin_bswap16: |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 678 | case Builtin::BI__builtin_bswap32: |
| 679 | case Builtin::BI__builtin_bswap64: { |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 680 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bswap)); |
| 681 | } |
Matt Arsenault | 08087c5 | 2016-03-23 22:14:43 +0000 | [diff] [blame] | 682 | case Builtin::BI__builtin_bitreverse8: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 683 | case Builtin::BI__builtin_bitreverse16: |
| 684 | case Builtin::BI__builtin_bitreverse32: |
| 685 | case Builtin::BI__builtin_bitreverse64: { |
| 686 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bitreverse)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | } |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 688 | case Builtin::BI__builtin_object_size: { |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 689 | unsigned Type = |
| 690 | E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue(); |
| 691 | auto *ResType = cast<llvm::IntegerType>(ConvertType(E->getType())); |
Richard Smith | 01ade17 | 2012-05-23 04:13:20 +0000 | [diff] [blame] | 692 | |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 693 | // We pass this builtin onto the optimizer so that it can figure out the |
| 694 | // object size in more complex cases. |
| 695 | return RValue::get(emitBuiltinObjectSize(E->getArg(0), Type, ResType)); |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 696 | } |
Daniel Dunbar | b725726 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 697 | case Builtin::BI__builtin_prefetch: { |
| 698 | Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); |
| 699 | // FIXME: Technically these constants should of type 'int', yes? |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 701 | llvm::ConstantInt::get(Int32Ty, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 702 | Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 703 | llvm::ConstantInt::get(Int32Ty, 3); |
Bruno Cardoso Lopes | 3b0297a | 2011-06-14 05:00:30 +0000 | [diff] [blame] | 704 | Value *Data = llvm::ConstantInt::get(Int32Ty, 1); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 705 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 706 | return RValue::get(Builder.CreateCall(F, {Address, RW, Locality, Data})); |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 707 | } |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 708 | case Builtin::BI__builtin_readcyclecounter: { |
| 709 | Value *F = CGM.getIntrinsic(Intrinsic::readcyclecounter); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 710 | return RValue::get(Builder.CreateCall(F)); |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 711 | } |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 712 | case Builtin::BI__builtin___clear_cache: { |
| 713 | Value *Begin = EmitScalarExpr(E->getArg(0)); |
| 714 | Value *End = EmitScalarExpr(E->getArg(1)); |
| 715 | Value *F = CGM.getIntrinsic(Intrinsic::clear_cache); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 716 | return RValue::get(Builder.CreateCall(F, {Begin, End})); |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 717 | } |
Akira Hatanaka | 85365cd | 2015-07-02 22:15:41 +0000 | [diff] [blame] | 718 | case Builtin::BI__builtin_trap: |
| 719 | return RValue::get(EmitTrapCall(Intrinsic::trap)); |
| 720 | case Builtin::BI__debugbreak: |
| 721 | return RValue::get(EmitTrapCall(Intrinsic::debugtrap)); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 722 | case Builtin::BI__builtin_unreachable: { |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 723 | if (SanOpts.has(SanitizerKind::Unreachable)) { |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 724 | SanitizerScope SanScope(this); |
Alexey Samsonov | e396bfc | 2014-11-11 22:03:54 +0000 | [diff] [blame] | 725 | EmitCheck(std::make_pair(static_cast<llvm::Value *>(Builder.getFalse()), |
| 726 | SanitizerKind::Unreachable), |
| 727 | "builtin_unreachable", EmitCheckSourceLocation(E->getExprLoc()), |
| 728 | None); |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 729 | } else |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 730 | Builder.CreateUnreachable(); |
| 731 | |
| 732 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 733 | EmitBlock(createBasicBlock("unreachable.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 734 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 735 | return RValue::get(nullptr); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 736 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 737 | |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 738 | case Builtin::BI__builtin_powi: |
| 739 | case Builtin::BI__builtin_powif: |
Reid Kleckner | 1fcccdd | 2015-02-05 00:24:57 +0000 | [diff] [blame] | 740 | case Builtin::BI__builtin_powil: { |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 741 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 742 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 743 | llvm::Type *ArgType = Base->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 744 | Value *F = CGM.getIntrinsic(Intrinsic::powi, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 745 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 748 | case Builtin::BI__builtin_isgreater: |
| 749 | case Builtin::BI__builtin_isgreaterequal: |
| 750 | case Builtin::BI__builtin_isless: |
| 751 | case Builtin::BI__builtin_islessequal: |
| 752 | case Builtin::BI__builtin_islessgreater: |
| 753 | case Builtin::BI__builtin_isunordered: { |
| 754 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 755 | // floating point values. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 757 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 759 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 760 | default: llvm_unreachable("Unknown ordered comparison"); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 761 | case Builtin::BI__builtin_isgreater: |
| 762 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 763 | break; |
| 764 | case Builtin::BI__builtin_isgreaterequal: |
| 765 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 766 | break; |
| 767 | case Builtin::BI__builtin_isless: |
| 768 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 769 | break; |
| 770 | case Builtin::BI__builtin_islessequal: |
| 771 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 772 | break; |
| 773 | case Builtin::BI__builtin_islessgreater: |
| 774 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 775 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | case Builtin::BI__builtin_isunordered: |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 777 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 778 | break; |
| 779 | } |
| 780 | // ZExt bool to int type. |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 781 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()))); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 782 | } |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 783 | case Builtin::BI__builtin_isnan: { |
| 784 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 785 | V = Builder.CreateFCmpUNO(V, V, "cmp"); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 786 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 787 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 788 | |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 789 | case Builtin::BI__builtin_isinf: { |
| 790 | // isinf(x) --> fabs(x) == infinity |
| 791 | Value *V = EmitScalarExpr(E->getArg(0)); |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 792 | V = EmitFAbs(*this, V); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 793 | |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 794 | V = Builder.CreateFCmpOEQ(V, ConstantFP::getInfinity(V->getType()),"isinf"); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 795 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 796 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 797 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 798 | case Builtin::BI__builtin_isinf_sign: { |
| 799 | // isinf_sign(x) -> fabs(x) == infinity ? (signbit(x) ? -1 : 1) : 0 |
| 800 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 801 | Value *AbsArg = EmitFAbs(*this, Arg); |
| 802 | Value *IsInf = Builder.CreateFCmpOEQ( |
| 803 | AbsArg, ConstantFP::getInfinity(Arg->getType()), "isinf"); |
| 804 | Value *IsNeg = EmitSignBit(*this, Arg); |
| 805 | |
| 806 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 807 | Value *Zero = Constant::getNullValue(IntTy); |
| 808 | Value *One = ConstantInt::get(IntTy, 1); |
| 809 | Value *NegativeOne = ConstantInt::get(IntTy, -1); |
| 810 | Value *SignResult = Builder.CreateSelect(IsNeg, NegativeOne, One); |
| 811 | Value *Result = Builder.CreateSelect(IsInf, SignResult, Zero); |
| 812 | return RValue::get(Result); |
| 813 | } |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 814 | |
| 815 | case Builtin::BI__builtin_isnormal: { |
| 816 | // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min |
| 817 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 818 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
| 819 | |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 820 | Value *Abs = EmitFAbs(*this, V); |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 821 | Value *IsLessThanInf = |
| 822 | Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 823 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 824 | getContext().getFloatTypeSemantics(E->getArg(0)->getType())); |
| 825 | Value *IsNormal = |
| 826 | Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest), |
| 827 | "isnormal"); |
| 828 | V = Builder.CreateAnd(Eq, IsLessThanInf, "and"); |
| 829 | V = Builder.CreateAnd(V, IsNormal, "and"); |
| 830 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 831 | } |
| 832 | |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 833 | case Builtin::BI__builtin_isfinite: { |
Julien Lerouge | e0d5fad | 2011-09-09 22:46:39 +0000 | [diff] [blame] | 834 | // isfinite(x) --> x == x && fabs(x) != infinity; |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 835 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 836 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 837 | |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 838 | Value *Abs = EmitFAbs(*this, V); |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 839 | Value *IsNotInf = |
| 840 | Builder.CreateFCmpUNE(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 841 | |
Chris Lattner | dbff4bf | 2010-05-06 06:04:13 +0000 | [diff] [blame] | 842 | V = Builder.CreateAnd(Eq, IsNotInf, "and"); |
| 843 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 844 | } |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 845 | |
| 846 | case Builtin::BI__builtin_fpclassify: { |
| 847 | Value *V = EmitScalarExpr(E->getArg(5)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 848 | llvm::Type *Ty = ConvertType(E->getArg(5)->getType()); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 849 | |
| 850 | // Create Result |
| 851 | BasicBlock *Begin = Builder.GetInsertBlock(); |
| 852 | BasicBlock *End = createBasicBlock("fpclassify_end", this->CurFn); |
| 853 | Builder.SetInsertPoint(End); |
| 854 | PHINode *Result = |
Jay Foad | 20c0f02 | 2011-03-30 11:28:58 +0000 | [diff] [blame] | 855 | Builder.CreatePHI(ConvertType(E->getArg(0)->getType()), 4, |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 856 | "fpclassify_result"); |
| 857 | |
| 858 | // if (V==0) return FP_ZERO |
| 859 | Builder.SetInsertPoint(Begin); |
| 860 | Value *IsZero = Builder.CreateFCmpOEQ(V, Constant::getNullValue(Ty), |
| 861 | "iszero"); |
| 862 | Value *ZeroLiteral = EmitScalarExpr(E->getArg(4)); |
| 863 | BasicBlock *NotZero = createBasicBlock("fpclassify_not_zero", this->CurFn); |
| 864 | Builder.CreateCondBr(IsZero, End, NotZero); |
| 865 | Result->addIncoming(ZeroLiteral, Begin); |
| 866 | |
| 867 | // if (V != V) return FP_NAN |
| 868 | Builder.SetInsertPoint(NotZero); |
| 869 | Value *IsNan = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 870 | Value *NanLiteral = EmitScalarExpr(E->getArg(0)); |
| 871 | BasicBlock *NotNan = createBasicBlock("fpclassify_not_nan", this->CurFn); |
| 872 | Builder.CreateCondBr(IsNan, End, NotNan); |
| 873 | Result->addIncoming(NanLiteral, NotZero); |
| 874 | |
| 875 | // if (fabs(V) == infinity) return FP_INFINITY |
| 876 | Builder.SetInsertPoint(NotNan); |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 877 | Value *VAbs = EmitFAbs(*this, V); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 878 | Value *IsInf = |
| 879 | Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(V->getType()), |
| 880 | "isinf"); |
| 881 | Value *InfLiteral = EmitScalarExpr(E->getArg(1)); |
| 882 | BasicBlock *NotInf = createBasicBlock("fpclassify_not_inf", this->CurFn); |
| 883 | Builder.CreateCondBr(IsInf, End, NotInf); |
| 884 | Result->addIncoming(InfLiteral, NotNan); |
| 885 | |
| 886 | // if (fabs(V) >= MIN_NORMAL) return FP_NORMAL else FP_SUBNORMAL |
| 887 | Builder.SetInsertPoint(NotInf); |
| 888 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 889 | getContext().getFloatTypeSemantics(E->getArg(5)->getType())); |
| 890 | Value *IsNormal = |
| 891 | Builder.CreateFCmpUGE(VAbs, ConstantFP::get(V->getContext(), Smallest), |
| 892 | "isnormal"); |
| 893 | Value *NormalResult = |
| 894 | Builder.CreateSelect(IsNormal, EmitScalarExpr(E->getArg(2)), |
| 895 | EmitScalarExpr(E->getArg(3))); |
| 896 | Builder.CreateBr(End); |
| 897 | Result->addIncoming(NormalResult, NotInf); |
| 898 | |
| 899 | // return Result |
| 900 | Builder.SetInsertPoint(End); |
| 901 | return RValue::get(Result); |
| 902 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 903 | |
Eli Friedman | f6bd150 | 2009-06-02 07:10:30 +0000 | [diff] [blame] | 904 | case Builtin::BIalloca: |
Reid Kleckner | 59e4a6f | 2013-11-13 22:58:53 +0000 | [diff] [blame] | 905 | case Builtin::BI_alloca: |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 906 | case Builtin::BI__builtin_alloca: { |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 907 | Value *Size = EmitScalarExpr(E->getArg(0)); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 908 | return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size)); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 909 | } |
Eli Friedman | d6ef69a | 2010-01-23 19:00:10 +0000 | [diff] [blame] | 910 | case Builtin::BIbzero: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 911 | case Builtin::BI__builtin_bzero: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 912 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 913 | Value *SizeVal = EmitScalarExpr(E->getArg(1)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 914 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 915 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 916 | Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false); |
| 917 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 918 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 919 | case Builtin::BImemcpy: |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 920 | case Builtin::BI__builtin_memcpy: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 921 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 922 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 923 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 924 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 925 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 926 | EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 927 | E->getArg(1)->getExprLoc(), FD, 1); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 928 | Builder.CreateMemCpy(Dest, Src, SizeVal, false); |
| 929 | return RValue::get(Dest.getPointer()); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 930 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 931 | |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 932 | case Builtin::BI__builtin___memcpy_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 933 | // 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] | 934 | llvm::APSInt Size, DstSize; |
| 935 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 936 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 937 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 938 | if (Size.ugt(DstSize)) |
| 939 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 940 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 941 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 942 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 943 | Builder.CreateMemCpy(Dest, Src, SizeVal, false); |
| 944 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 945 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 946 | |
Fariborz Jahanian | 4a30307 | 2010-06-16 16:22:04 +0000 | [diff] [blame] | 947 | case Builtin::BI__builtin_objc_memmove_collectable: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 948 | Address DestAddr = EmitPointerWithAlignment(E->getArg(0)); |
| 949 | Address SrcAddr = EmitPointerWithAlignment(E->getArg(1)); |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 950 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 951 | CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 952 | DestAddr, SrcAddr, SizeVal); |
| 953 | return RValue::get(DestAddr.getPointer()); |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 954 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 955 | |
| 956 | case Builtin::BI__builtin___memmove_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 957 | // 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] | 958 | llvm::APSInt Size, DstSize; |
| 959 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 960 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 961 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 962 | if (Size.ugt(DstSize)) |
| 963 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 964 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 965 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 966 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 967 | Builder.CreateMemMove(Dest, Src, SizeVal, false); |
| 968 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 971 | case Builtin::BImemmove: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 972 | case Builtin::BI__builtin_memmove: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 973 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 974 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 975 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 976 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 977 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 978 | EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 979 | E->getArg(1)->getExprLoc(), FD, 1); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 980 | Builder.CreateMemMove(Dest, Src, SizeVal, false); |
| 981 | return RValue::get(Dest.getPointer()); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 982 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 983 | case Builtin::BImemset: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 984 | case Builtin::BI__builtin_memset: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 985 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Benjamin Kramer | acc6b4e | 2010-12-30 00:13:21 +0000 | [diff] [blame] | 986 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 987 | Builder.getInt8Ty()); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 988 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 989 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 990 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 991 | Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); |
| 992 | return RValue::get(Dest.getPointer()); |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 993 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 994 | case Builtin::BI__builtin___memset_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 995 | // 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] | 996 | llvm::APSInt Size, DstSize; |
| 997 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 998 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 999 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1000 | if (Size.ugt(DstSize)) |
| 1001 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1002 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1003 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 1004 | Builder.getInt8Ty()); |
| 1005 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1006 | Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); |
| 1007 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1008 | } |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 1009 | case Builtin::BI__builtin_dwarf_cfa: { |
| 1010 | // The offset in bytes from the first argument to the CFA. |
| 1011 | // |
| 1012 | // Why on earth is this in the frontend? Is there any reason at |
| 1013 | // all that the backend can't reasonably determine this while |
| 1014 | // lowering llvm.eh.dwarf.cfa()? |
| 1015 | // |
| 1016 | // TODO: If there's a satisfactory reason, add a target hook for |
| 1017 | // this instead of hard-coding 0, which is correct for most targets. |
| 1018 | int32_t Offset = 0; |
| 1019 | |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1020 | Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1021 | return RValue::get(Builder.CreateCall(F, |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1022 | llvm::ConstantInt::get(Int32Ty, Offset))); |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 1023 | } |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1024 | case Builtin::BI__builtin_return_address: { |
David Majnemer | 6cd3591 | 2015-07-25 05:57:24 +0000 | [diff] [blame] | 1025 | Value *Depth = |
| 1026 | CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy, this); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1027 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 1028 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1029 | } |
| 1030 | case Builtin::BI__builtin_frame_address: { |
David Majnemer | 6cd3591 | 2015-07-25 05:57:24 +0000 | [diff] [blame] | 1031 | Value *Depth = |
| 1032 | CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy, this); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1033 | Value *F = CGM.getIntrinsic(Intrinsic::frameaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 1034 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1035 | } |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 1036 | case Builtin::BI__builtin_extract_return_addr: { |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1037 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1038 | Value *Result = getTargetHooks().decodeReturnAddress(*this, Address); |
| 1039 | return RValue::get(Result); |
| 1040 | } |
| 1041 | case Builtin::BI__builtin_frob_return_addr: { |
| 1042 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1043 | Value *Result = getTargetHooks().encodeReturnAddress(*this, Address); |
| 1044 | return RValue::get(Result); |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 1045 | } |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 1046 | case Builtin::BI__builtin_dwarf_sp_column: { |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1047 | llvm::IntegerType *Ty |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 1048 | = cast<llvm::IntegerType>(ConvertType(E->getType())); |
| 1049 | int Column = getTargetHooks().getDwarfEHStackPointer(CGM); |
| 1050 | if (Column == -1) { |
| 1051 | CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column"); |
| 1052 | return RValue::get(llvm::UndefValue::get(Ty)); |
| 1053 | } |
| 1054 | return RValue::get(llvm::ConstantInt::get(Ty, Column, true)); |
| 1055 | } |
| 1056 | case Builtin::BI__builtin_init_dwarf_reg_size_table: { |
| 1057 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1058 | if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address)) |
| 1059 | CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table"); |
| 1060 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
| 1061 | } |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1062 | case Builtin::BI__builtin_eh_return: { |
| 1063 | Value *Int = EmitScalarExpr(E->getArg(0)); |
| 1064 | Value *Ptr = EmitScalarExpr(E->getArg(1)); |
| 1065 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1066 | llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType()); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1067 | assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && |
| 1068 | "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); |
| 1069 | Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 |
| 1070 | ? Intrinsic::eh_return_i32 |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1071 | : Intrinsic::eh_return_i64); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1072 | Builder.CreateCall(F, {Int, Ptr}); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1073 | Builder.CreateUnreachable(); |
| 1074 | |
| 1075 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1076 | EmitBlock(createBasicBlock("builtin_eh_return.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1077 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1078 | return RValue::get(nullptr); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1079 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1080 | case Builtin::BI__builtin_unwind_init: { |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1081 | Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1082 | return RValue::get(Builder.CreateCall(F)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1083 | } |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1084 | case Builtin::BI__builtin_extend_pointer: { |
| 1085 | // Extends a pointer to the size of an _Unwind_Word, which is |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1086 | // uint64_t on all platforms. Generally this gets poked into a |
| 1087 | // register and eventually used as an address, so if the |
| 1088 | // addressing registers are wider than pointers and the platform |
| 1089 | // doesn't implicitly ignore high-order bits when doing |
| 1090 | // addressing, we need to make sure we zext / sext based on |
| 1091 | // the platform's expectations. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1092 | // |
| 1093 | // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1094 | |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1095 | // Cast the pointer to intptr_t. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1096 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1097 | Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast"); |
| 1098 | |
| 1099 | // If that's 64 bits, we're done. |
| 1100 | if (IntPtrTy->getBitWidth() == 64) |
| 1101 | return RValue::get(Result); |
| 1102 | |
| 1103 | // Otherwise, ask the codegen data what to do. |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1104 | if (getTargetHooks().extendPointerWithSExt()) |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1105 | return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext")); |
| 1106 | else |
| 1107 | return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1108 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1109 | case Builtin::BI__builtin_setjmp: { |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1110 | // Buffer is a void**. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1111 | Address Buf = EmitPointerWithAlignment(E->getArg(0)); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1112 | |
| 1113 | // Store the frame pointer to the setjmp buffer. |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1114 | Value *FrameAddr = |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1115 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1116 | ConstantInt::get(Int32Ty, 0)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1117 | Builder.CreateStore(FrameAddr, Buf); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1118 | |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 1119 | // Store the stack pointer to the setjmp buffer. |
| 1120 | Value *StackAddr = |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1121 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::stacksave)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1122 | Address StackSaveSlot = |
| 1123 | Builder.CreateConstInBoundsGEP(Buf, 2, getPointerSize()); |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 1124 | Builder.CreateStore(StackAddr, StackSaveSlot); |
| 1125 | |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1126 | // Call LLVM's EH setjmp, which is lightweight. |
| 1127 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1128 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1129 | return RValue::get(Builder.CreateCall(F, Buf.getPointer())); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1130 | } |
| 1131 | case Builtin::BI__builtin_longjmp: { |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1132 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1133 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1134 | |
| 1135 | // Call LLVM's EH longjmp, which is lightweight. |
| 1136 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf); |
| 1137 | |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1138 | // longjmp doesn't return; mark this as unreachable. |
| 1139 | Builder.CreateUnreachable(); |
| 1140 | |
| 1141 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1142 | EmitBlock(createBasicBlock("longjmp.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1143 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1144 | return RValue::get(nullptr); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1145 | } |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1146 | case Builtin::BI__sync_fetch_and_add: |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1147 | case Builtin::BI__sync_fetch_and_sub: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1148 | case Builtin::BI__sync_fetch_and_or: |
| 1149 | case Builtin::BI__sync_fetch_and_and: |
| 1150 | case Builtin::BI__sync_fetch_and_xor: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1151 | case Builtin::BI__sync_fetch_and_nand: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1152 | case Builtin::BI__sync_add_and_fetch: |
| 1153 | case Builtin::BI__sync_sub_and_fetch: |
| 1154 | case Builtin::BI__sync_and_and_fetch: |
| 1155 | case Builtin::BI__sync_or_and_fetch: |
| 1156 | case Builtin::BI__sync_xor_and_fetch: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1157 | case Builtin::BI__sync_nand_and_fetch: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1158 | case Builtin::BI__sync_val_compare_and_swap: |
| 1159 | case Builtin::BI__sync_bool_compare_and_swap: |
| 1160 | case Builtin::BI__sync_lock_test_and_set: |
| 1161 | case Builtin::BI__sync_lock_release: |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1162 | case Builtin::BI__sync_swap: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1163 | llvm_unreachable("Shouldn't make it through sema"); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1164 | case Builtin::BI__sync_fetch_and_add_1: |
| 1165 | case Builtin::BI__sync_fetch_and_add_2: |
| 1166 | case Builtin::BI__sync_fetch_and_add_4: |
| 1167 | case Builtin::BI__sync_fetch_and_add_8: |
| 1168 | case Builtin::BI__sync_fetch_and_add_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1169 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Add, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1170 | case Builtin::BI__sync_fetch_and_sub_1: |
| 1171 | case Builtin::BI__sync_fetch_and_sub_2: |
| 1172 | case Builtin::BI__sync_fetch_and_sub_4: |
| 1173 | case Builtin::BI__sync_fetch_and_sub_8: |
| 1174 | case Builtin::BI__sync_fetch_and_sub_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1175 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Sub, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1176 | case Builtin::BI__sync_fetch_and_or_1: |
| 1177 | case Builtin::BI__sync_fetch_and_or_2: |
| 1178 | case Builtin::BI__sync_fetch_and_or_4: |
| 1179 | case Builtin::BI__sync_fetch_and_or_8: |
| 1180 | case Builtin::BI__sync_fetch_and_or_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1181 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Or, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1182 | case Builtin::BI__sync_fetch_and_and_1: |
| 1183 | case Builtin::BI__sync_fetch_and_and_2: |
| 1184 | case Builtin::BI__sync_fetch_and_and_4: |
| 1185 | case Builtin::BI__sync_fetch_and_and_8: |
| 1186 | case Builtin::BI__sync_fetch_and_and_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1187 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::And, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1188 | case Builtin::BI__sync_fetch_and_xor_1: |
| 1189 | case Builtin::BI__sync_fetch_and_xor_2: |
| 1190 | case Builtin::BI__sync_fetch_and_xor_4: |
| 1191 | case Builtin::BI__sync_fetch_and_xor_8: |
| 1192 | case Builtin::BI__sync_fetch_and_xor_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1193 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xor, E); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1194 | case Builtin::BI__sync_fetch_and_nand_1: |
| 1195 | case Builtin::BI__sync_fetch_and_nand_2: |
| 1196 | case Builtin::BI__sync_fetch_and_nand_4: |
| 1197 | case Builtin::BI__sync_fetch_and_nand_8: |
| 1198 | case Builtin::BI__sync_fetch_and_nand_16: |
| 1199 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Nand, E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1200 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1201 | // Clang extensions: not overloaded yet. |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1202 | case Builtin::BI__sync_fetch_and_min: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1203 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Min, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1204 | case Builtin::BI__sync_fetch_and_max: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1205 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Max, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1206 | case Builtin::BI__sync_fetch_and_umin: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1207 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMin, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1208 | case Builtin::BI__sync_fetch_and_umax: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1209 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMax, E); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1210 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1211 | case Builtin::BI__sync_add_and_fetch_1: |
| 1212 | case Builtin::BI__sync_add_and_fetch_2: |
| 1213 | case Builtin::BI__sync_add_and_fetch_4: |
| 1214 | case Builtin::BI__sync_add_and_fetch_8: |
| 1215 | case Builtin::BI__sync_add_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1216 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Add, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1217 | llvm::Instruction::Add); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1218 | case Builtin::BI__sync_sub_and_fetch_1: |
| 1219 | case Builtin::BI__sync_sub_and_fetch_2: |
| 1220 | case Builtin::BI__sync_sub_and_fetch_4: |
| 1221 | case Builtin::BI__sync_sub_and_fetch_8: |
| 1222 | case Builtin::BI__sync_sub_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1223 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Sub, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1224 | llvm::Instruction::Sub); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1225 | case Builtin::BI__sync_and_and_fetch_1: |
| 1226 | case Builtin::BI__sync_and_and_fetch_2: |
| 1227 | case Builtin::BI__sync_and_and_fetch_4: |
| 1228 | case Builtin::BI__sync_and_and_fetch_8: |
| 1229 | case Builtin::BI__sync_and_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1230 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::And, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1231 | llvm::Instruction::And); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1232 | case Builtin::BI__sync_or_and_fetch_1: |
| 1233 | case Builtin::BI__sync_or_and_fetch_2: |
| 1234 | case Builtin::BI__sync_or_and_fetch_4: |
| 1235 | case Builtin::BI__sync_or_and_fetch_8: |
| 1236 | case Builtin::BI__sync_or_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1237 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Or, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1238 | llvm::Instruction::Or); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1239 | case Builtin::BI__sync_xor_and_fetch_1: |
| 1240 | case Builtin::BI__sync_xor_and_fetch_2: |
| 1241 | case Builtin::BI__sync_xor_and_fetch_4: |
| 1242 | case Builtin::BI__sync_xor_and_fetch_8: |
| 1243 | case Builtin::BI__sync_xor_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1244 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Xor, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1245 | llvm::Instruction::Xor); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1246 | case Builtin::BI__sync_nand_and_fetch_1: |
| 1247 | case Builtin::BI__sync_nand_and_fetch_2: |
| 1248 | case Builtin::BI__sync_nand_and_fetch_4: |
| 1249 | case Builtin::BI__sync_nand_and_fetch_8: |
| 1250 | case Builtin::BI__sync_nand_and_fetch_16: |
| 1251 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Nand, E, |
| 1252 | llvm::Instruction::And, true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1253 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1254 | case Builtin::BI__sync_val_compare_and_swap_1: |
| 1255 | case Builtin::BI__sync_val_compare_and_swap_2: |
| 1256 | case Builtin::BI__sync_val_compare_and_swap_4: |
| 1257 | case Builtin::BI__sync_val_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1258 | case Builtin::BI__sync_val_compare_and_swap_16: |
| 1259 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, false)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1260 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1261 | case Builtin::BI__sync_bool_compare_and_swap_1: |
| 1262 | case Builtin::BI__sync_bool_compare_and_swap_2: |
| 1263 | case Builtin::BI__sync_bool_compare_and_swap_4: |
| 1264 | case Builtin::BI__sync_bool_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1265 | case Builtin::BI__sync_bool_compare_and_swap_16: |
| 1266 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, true)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1267 | |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1268 | case Builtin::BI__sync_swap_1: |
| 1269 | case Builtin::BI__sync_swap_2: |
| 1270 | case Builtin::BI__sync_swap_4: |
| 1271 | case Builtin::BI__sync_swap_8: |
| 1272 | case Builtin::BI__sync_swap_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1273 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1274 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1275 | case Builtin::BI__sync_lock_test_and_set_1: |
| 1276 | case Builtin::BI__sync_lock_test_and_set_2: |
| 1277 | case Builtin::BI__sync_lock_test_and_set_4: |
| 1278 | case Builtin::BI__sync_lock_test_and_set_8: |
| 1279 | case Builtin::BI__sync_lock_test_and_set_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1280 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Daniel Dunbar | 4ff562d | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 1281 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1282 | case Builtin::BI__sync_lock_release_1: |
| 1283 | case Builtin::BI__sync_lock_release_2: |
| 1284 | case Builtin::BI__sync_lock_release_4: |
| 1285 | case Builtin::BI__sync_lock_release_8: |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1286 | case Builtin::BI__sync_lock_release_16: { |
| 1287 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Eli Friedman | 84d2812 | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 1288 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 1289 | CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); |
Eli Friedman | fefe0d0 | 2012-03-16 01:48:04 +0000 | [diff] [blame] | 1290 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 1291 | StoreSize.getQuantity() * 8); |
| 1292 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1293 | llvm::StoreInst *Store = |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1294 | Builder.CreateAlignedStore(llvm::Constant::getNullValue(ITy), Ptr, |
| 1295 | StoreSize); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1296 | Store->setAtomic(llvm::AtomicOrdering::Release); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1297 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1298 | } |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1299 | |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1300 | case Builtin::BI__sync_synchronize: { |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1301 | // We assume this is supposed to correspond to a C++0x-style |
| 1302 | // sequentially-consistent fence (i.e. this is only usable for |
| 1303 | // synchonization, not device I/O or anything like that). This intrinsic |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1304 | // 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] | 1305 | // any way to safely use it... but in practice, it mostly works |
| 1306 | // to use it with non-atomic loads and stores to get acquire/release |
| 1307 | // semantics. |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1308 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1309 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1310 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1311 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 1312 | case Builtin::BI__builtin_nontemporal_load: |
| 1313 | return RValue::get(EmitNontemporalLoad(*this, E)); |
| 1314 | case Builtin::BI__builtin_nontemporal_store: |
| 1315 | return RValue::get(EmitNontemporalStore(*this, E)); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1316 | case Builtin::BI__c11_atomic_is_lock_free: |
| 1317 | case Builtin::BI__atomic_is_lock_free: { |
| 1318 | // Call "bool __atomic_is_lock_free(size_t size, void *ptr)". For the |
| 1319 | // __c11 builtin, ptr is 0 (indicating a properly-aligned object), since |
| 1320 | // _Atomic(T) is always properly-aligned. |
| 1321 | const char *LibCallName = "__atomic_is_lock_free"; |
| 1322 | CallArgList Args; |
| 1323 | Args.add(RValue::get(EmitScalarExpr(E->getArg(0))), |
| 1324 | getContext().getSizeType()); |
| 1325 | if (BuiltinID == Builtin::BI__atomic_is_lock_free) |
| 1326 | Args.add(RValue::get(EmitScalarExpr(E->getArg(1))), |
| 1327 | getContext().VoidPtrTy); |
| 1328 | else |
| 1329 | Args.add(RValue::get(llvm::Constant::getNullValue(VoidPtrTy)), |
| 1330 | getContext().VoidPtrTy); |
| 1331 | const CGFunctionInfo &FuncInfo = |
John McCall | c56a8b3 | 2016-03-11 04:30:31 +0000 | [diff] [blame] | 1332 | CGM.getTypes().arrangeBuiltinFunctionCall(E->getType(), Args); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1333 | llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FuncInfo); |
| 1334 | llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, LibCallName); |
| 1335 | return EmitCall(FuncInfo, Func, ReturnValueSlot(), Args); |
| 1336 | } |
| 1337 | |
| 1338 | case Builtin::BI__atomic_test_and_set: { |
| 1339 | // Look at the argument type to determine whether this is a volatile |
| 1340 | // operation. The parameter type is always volatile. |
| 1341 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 1342 | bool Volatile = |
| 1343 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 1344 | |
| 1345 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 1346 | unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1347 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 1348 | Value *NewVal = Builder.getInt8(1); |
| 1349 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 1350 | if (isa<llvm::ConstantInt>(Order)) { |
| 1351 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1352 | AtomicRMWInst *Result = nullptr; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1353 | switch (ord) { |
| 1354 | case 0: // memory_order_relaxed |
| 1355 | default: // invalid order |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1356 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1357 | llvm::AtomicOrdering::Monotonic); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1358 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1359 | case 1: // memory_order_consume |
| 1360 | case 2: // memory_order_acquire |
| 1361 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1362 | llvm::AtomicOrdering::Acquire); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1363 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1364 | case 3: // memory_order_release |
| 1365 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1366 | llvm::AtomicOrdering::Release); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1367 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1368 | case 4: // memory_order_acq_rel |
| 1369 | |
| 1370 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1371 | llvm::AtomicOrdering::AcquireRelease); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1372 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1373 | case 5: // memory_order_seq_cst |
| 1374 | Result = Builder.CreateAtomicRMW( |
| 1375 | llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1376 | llvm::AtomicOrdering::SequentiallyConsistent); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1377 | break; |
| 1378 | } |
| 1379 | Result->setVolatile(Volatile); |
| 1380 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 1381 | } |
| 1382 | |
| 1383 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1384 | |
| 1385 | llvm::BasicBlock *BBs[5] = { |
| 1386 | createBasicBlock("monotonic", CurFn), |
| 1387 | createBasicBlock("acquire", CurFn), |
| 1388 | createBasicBlock("release", CurFn), |
| 1389 | createBasicBlock("acqrel", CurFn), |
| 1390 | createBasicBlock("seqcst", CurFn) |
| 1391 | }; |
| 1392 | llvm::AtomicOrdering Orders[5] = { |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1393 | llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Acquire, |
| 1394 | llvm::AtomicOrdering::Release, llvm::AtomicOrdering::AcquireRelease, |
| 1395 | llvm::AtomicOrdering::SequentiallyConsistent}; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1396 | |
| 1397 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1398 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 1399 | |
| 1400 | Builder.SetInsertPoint(ContBB); |
| 1401 | PHINode *Result = Builder.CreatePHI(Int8Ty, 5, "was_set"); |
| 1402 | |
| 1403 | for (unsigned i = 0; i < 5; ++i) { |
| 1404 | Builder.SetInsertPoint(BBs[i]); |
| 1405 | AtomicRMWInst *RMW = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1406 | Ptr, NewVal, Orders[i]); |
| 1407 | RMW->setVolatile(Volatile); |
| 1408 | Result->addIncoming(RMW, BBs[i]); |
| 1409 | Builder.CreateBr(ContBB); |
| 1410 | } |
| 1411 | |
| 1412 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 1413 | SI->addCase(Builder.getInt32(1), BBs[1]); |
| 1414 | SI->addCase(Builder.getInt32(2), BBs[1]); |
| 1415 | SI->addCase(Builder.getInt32(3), BBs[2]); |
| 1416 | SI->addCase(Builder.getInt32(4), BBs[3]); |
| 1417 | SI->addCase(Builder.getInt32(5), BBs[4]); |
| 1418 | |
| 1419 | Builder.SetInsertPoint(ContBB); |
| 1420 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 1421 | } |
| 1422 | |
| 1423 | case Builtin::BI__atomic_clear: { |
| 1424 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 1425 | bool Volatile = |
| 1426 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 1427 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1428 | Address Ptr = EmitPointerWithAlignment(E->getArg(0)); |
| 1429 | unsigned AddrSpace = Ptr.getPointer()->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1430 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 1431 | Value *NewVal = Builder.getInt8(0); |
| 1432 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 1433 | if (isa<llvm::ConstantInt>(Order)) { |
| 1434 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 1435 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1436 | switch (ord) { |
| 1437 | case 0: // memory_order_relaxed |
| 1438 | default: // invalid order |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1439 | Store->setOrdering(llvm::AtomicOrdering::Monotonic); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | case 3: // memory_order_release |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1442 | Store->setOrdering(llvm::AtomicOrdering::Release); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1443 | break; |
| 1444 | case 5: // memory_order_seq_cst |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1445 | Store->setOrdering(llvm::AtomicOrdering::SequentiallyConsistent); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1446 | break; |
| 1447 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1448 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1452 | |
| 1453 | llvm::BasicBlock *BBs[3] = { |
| 1454 | createBasicBlock("monotonic", CurFn), |
| 1455 | createBasicBlock("release", CurFn), |
| 1456 | createBasicBlock("seqcst", CurFn) |
| 1457 | }; |
| 1458 | llvm::AtomicOrdering Orders[3] = { |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1459 | llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Release, |
| 1460 | llvm::AtomicOrdering::SequentiallyConsistent}; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1461 | |
| 1462 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1463 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 1464 | |
| 1465 | for (unsigned i = 0; i < 3; ++i) { |
| 1466 | Builder.SetInsertPoint(BBs[i]); |
| 1467 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1468 | Store->setOrdering(Orders[i]); |
| 1469 | Builder.CreateBr(ContBB); |
| 1470 | } |
| 1471 | |
| 1472 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 1473 | SI->addCase(Builder.getInt32(3), BBs[1]); |
| 1474 | SI->addCase(Builder.getInt32(5), BBs[2]); |
| 1475 | |
| 1476 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1477 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1480 | case Builtin::BI__atomic_thread_fence: |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 1481 | case Builtin::BI__atomic_signal_fence: |
| 1482 | case Builtin::BI__c11_atomic_thread_fence: |
| 1483 | case Builtin::BI__c11_atomic_signal_fence: { |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1484 | llvm::SynchronizationScope Scope; |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 1485 | if (BuiltinID == Builtin::BI__atomic_signal_fence || |
| 1486 | BuiltinID == Builtin::BI__c11_atomic_signal_fence) |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1487 | Scope = llvm::SingleThread; |
| 1488 | else |
| 1489 | Scope = llvm::CrossThread; |
| 1490 | Value *Order = EmitScalarExpr(E->getArg(0)); |
| 1491 | if (isa<llvm::ConstantInt>(Order)) { |
| 1492 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 1493 | switch (ord) { |
| 1494 | case 0: // memory_order_relaxed |
| 1495 | default: // invalid order |
| 1496 | break; |
| 1497 | case 1: // memory_order_consume |
| 1498 | case 2: // memory_order_acquire |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1499 | Builder.CreateFence(llvm::AtomicOrdering::Acquire, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | case 3: // memory_order_release |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1502 | Builder.CreateFence(llvm::AtomicOrdering::Release, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1503 | break; |
| 1504 | case 4: // memory_order_acq_rel |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1505 | Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | case 5: // memory_order_seq_cst |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1508 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, |
| 1509 | Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1510 | break; |
| 1511 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1512 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB; |
| 1516 | AcquireBB = createBasicBlock("acquire", CurFn); |
| 1517 | ReleaseBB = createBasicBlock("release", CurFn); |
| 1518 | AcqRelBB = createBasicBlock("acqrel", CurFn); |
| 1519 | SeqCstBB = createBasicBlock("seqcst", CurFn); |
| 1520 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1521 | |
| 1522 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1523 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, ContBB); |
| 1524 | |
| 1525 | Builder.SetInsertPoint(AcquireBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1526 | Builder.CreateFence(llvm::AtomicOrdering::Acquire, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1527 | Builder.CreateBr(ContBB); |
| 1528 | SI->addCase(Builder.getInt32(1), AcquireBB); |
| 1529 | SI->addCase(Builder.getInt32(2), AcquireBB); |
| 1530 | |
| 1531 | Builder.SetInsertPoint(ReleaseBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1532 | Builder.CreateFence(llvm::AtomicOrdering::Release, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1533 | Builder.CreateBr(ContBB); |
| 1534 | SI->addCase(Builder.getInt32(3), ReleaseBB); |
| 1535 | |
| 1536 | Builder.SetInsertPoint(AcqRelBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1537 | Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1538 | Builder.CreateBr(ContBB); |
| 1539 | SI->addCase(Builder.getInt32(4), AcqRelBB); |
| 1540 | |
| 1541 | Builder.SetInsertPoint(SeqCstBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1542 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1543 | Builder.CreateBr(ContBB); |
| 1544 | SI->addCase(Builder.getInt32(5), SeqCstBB); |
| 1545 | |
| 1546 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1547 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1550 | // Library functions with special handling. |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1551 | case Builtin::BIsqrt: |
| 1552 | case Builtin::BIsqrtf: |
| 1553 | case Builtin::BIsqrtl: { |
Hal Finkel | 28b2ae3 | 2013-09-12 23:57:55 +0000 | [diff] [blame] | 1554 | // Transform a call to sqrt* into a @llvm.sqrt.* intrinsic call, but only |
| 1555 | // in finite- or unsafe-math mode (the intrinsic has different semantics |
| 1556 | // for handling negative numbers compared to the library function, so |
| 1557 | // -fmath-errno=0 is not enough). |
| 1558 | if (!FD->hasAttr<ConstAttr>()) |
| 1559 | break; |
| 1560 | if (!(CGM.getCodeGenOpts().UnsafeFPMath || |
| 1561 | CGM.getCodeGenOpts().NoNaNsFPMath)) |
| 1562 | break; |
| 1563 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 1564 | llvm::Type *ArgType = Arg0->getType(); |
| 1565 | Value *F = CGM.getIntrinsic(Intrinsic::sqrt, ArgType); |
| 1566 | return RValue::get(Builder.CreateCall(F, Arg0)); |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Reid Kleckner | 8a8c129 | 2015-02-05 00:18:01 +0000 | [diff] [blame] | 1569 | case Builtin::BI__builtin_pow: |
| 1570 | case Builtin::BI__builtin_powf: |
| 1571 | case Builtin::BI__builtin_powl: |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1572 | case Builtin::BIpow: |
| 1573 | case Builtin::BIpowf: |
| 1574 | case Builtin::BIpowl: { |
Eli Bendersky | c3496b0 | 2013-07-24 21:22:01 +0000 | [diff] [blame] | 1575 | // Transform a call to pow* into a @llvm.pow.* intrinsic call. |
| 1576 | if (!FD->hasAttr<ConstAttr>()) |
| 1577 | break; |
| 1578 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 1579 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
| 1580 | llvm::Type *ArgType = Base->getType(); |
| 1581 | Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1582 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1583 | } |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1584 | |
Cameron Zwarich | ae7bc98 | 2011-07-08 21:39:34 +0000 | [diff] [blame] | 1585 | case Builtin::BIfma: |
| 1586 | case Builtin::BIfmaf: |
| 1587 | case Builtin::BIfmal: |
| 1588 | case Builtin::BI__builtin_fma: |
| 1589 | case Builtin::BI__builtin_fmaf: |
| 1590 | case Builtin::BI__builtin_fmal: { |
| 1591 | // Rewrite fma to intrinsic. |
| 1592 | Value *FirstArg = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1593 | llvm::Type *ArgType = FirstArg->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1594 | Value *F = CGM.getIntrinsic(Intrinsic::fma, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1595 | return RValue::get( |
| 1596 | Builder.CreateCall(F, {FirstArg, EmitScalarExpr(E->getArg(1)), |
| 1597 | EmitScalarExpr(E->getArg(2))})); |
Cameron Zwarich | ae7bc98 | 2011-07-08 21:39:34 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1600 | case Builtin::BI__builtin_signbit: |
| 1601 | case Builtin::BI__builtin_signbitf: |
| 1602 | case Builtin::BI__builtin_signbitl: { |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 1603 | return RValue::get( |
| 1604 | Builder.CreateZExt(EmitSignBit(*this, EmitScalarExpr(E->getArg(0))), |
| 1605 | ConvertType(E->getType()))); |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1606 | } |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1607 | case Builtin::BI__builtin_annotation: { |
| 1608 | llvm::Value *AnnVal = EmitScalarExpr(E->getArg(0)); |
| 1609 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::annotation, |
| 1610 | AnnVal->getType()); |
| 1611 | |
| 1612 | // Get the annotation string, go through casts. Sema requires this to be a |
| 1613 | // non-wide string literal, potentially casted, so the cast<> is safe. |
| 1614 | const Expr *AnnotationStrExpr = E->getArg(1)->IgnoreParenCasts(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1615 | StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString(); |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1616 | return RValue::get(EmitAnnotationCall(F, AnnVal, Str, E->getExprLoc())); |
| 1617 | } |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1618 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1619 | case Builtin::BI__builtin_addcs: |
| 1620 | case Builtin::BI__builtin_addc: |
| 1621 | case Builtin::BI__builtin_addcl: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1622 | case Builtin::BI__builtin_addcll: |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1623 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1624 | case Builtin::BI__builtin_subcs: |
| 1625 | case Builtin::BI__builtin_subc: |
| 1626 | case Builtin::BI__builtin_subcl: |
| 1627 | case Builtin::BI__builtin_subcll: { |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1628 | |
| 1629 | // We translate all of these builtins from expressions of the form: |
| 1630 | // int x = ..., y = ..., carryin = ..., carryout, result; |
| 1631 | // result = __builtin_addc(x, y, carryin, &carryout); |
| 1632 | // |
| 1633 | // to LLVM IR of the form: |
| 1634 | // |
| 1635 | // %tmp1 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y) |
| 1636 | // %tmpsum1 = extractvalue {i32, i1} %tmp1, 0 |
| 1637 | // %carry1 = extractvalue {i32, i1} %tmp1, 1 |
| 1638 | // %tmp2 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %tmpsum1, |
| 1639 | // i32 %carryin) |
| 1640 | // %result = extractvalue {i32, i1} %tmp2, 0 |
| 1641 | // %carry2 = extractvalue {i32, i1} %tmp2, 1 |
| 1642 | // %tmp3 = or i1 %carry1, %carry2 |
| 1643 | // %tmp4 = zext i1 %tmp3 to i32 |
| 1644 | // store i32 %tmp4, i32* %carryout |
| 1645 | |
| 1646 | // Scalarize our inputs. |
| 1647 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 1648 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 1649 | llvm::Value *Carryin = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1650 | Address CarryOutPtr = EmitPointerWithAlignment(E->getArg(3)); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1651 | |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1652 | // Decide if we are lowering to a uadd.with.overflow or usub.with.overflow. |
| 1653 | llvm::Intrinsic::ID IntrinsicId; |
| 1654 | switch (BuiltinID) { |
| 1655 | default: llvm_unreachable("Unknown multiprecision builtin id."); |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1656 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1657 | case Builtin::BI__builtin_addcs: |
| 1658 | case Builtin::BI__builtin_addc: |
| 1659 | case Builtin::BI__builtin_addcl: |
| 1660 | case Builtin::BI__builtin_addcll: |
| 1661 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 1662 | break; |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1663 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1664 | case Builtin::BI__builtin_subcs: |
| 1665 | case Builtin::BI__builtin_subc: |
| 1666 | case Builtin::BI__builtin_subcl: |
| 1667 | case Builtin::BI__builtin_subcll: |
| 1668 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 1669 | break; |
| 1670 | } |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1671 | |
| 1672 | // Construct our resulting LLVM IR expression. |
| 1673 | llvm::Value *Carry1; |
| 1674 | llvm::Value *Sum1 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 1675 | X, Y, Carry1); |
| 1676 | llvm::Value *Carry2; |
| 1677 | llvm::Value *Sum2 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 1678 | Sum1, Carryin, Carry2); |
| 1679 | llvm::Value *CarryOut = Builder.CreateZExt(Builder.CreateOr(Carry1, Carry2), |
| 1680 | X->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1681 | Builder.CreateStore(CarryOut, CarryOutPtr); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1682 | return RValue::get(Sum2); |
| 1683 | } |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 1684 | |
| 1685 | case Builtin::BI__builtin_add_overflow: |
| 1686 | case Builtin::BI__builtin_sub_overflow: |
| 1687 | case Builtin::BI__builtin_mul_overflow: { |
| 1688 | const clang::Expr *LeftArg = E->getArg(0); |
| 1689 | const clang::Expr *RightArg = E->getArg(1); |
| 1690 | const clang::Expr *ResultArg = E->getArg(2); |
| 1691 | |
| 1692 | clang::QualType ResultQTy = |
| 1693 | ResultArg->getType()->castAs<PointerType>()->getPointeeType(); |
| 1694 | |
| 1695 | WidthAndSignedness LeftInfo = |
| 1696 | getIntegerWidthAndSignedness(CGM.getContext(), LeftArg->getType()); |
| 1697 | WidthAndSignedness RightInfo = |
| 1698 | getIntegerWidthAndSignedness(CGM.getContext(), RightArg->getType()); |
| 1699 | WidthAndSignedness ResultInfo = |
| 1700 | getIntegerWidthAndSignedness(CGM.getContext(), ResultQTy); |
| 1701 | WidthAndSignedness EncompassingInfo = |
| 1702 | EncompassingIntegerType({LeftInfo, RightInfo, ResultInfo}); |
| 1703 | |
| 1704 | llvm::Type *EncompassingLLVMTy = |
| 1705 | llvm::IntegerType::get(CGM.getLLVMContext(), EncompassingInfo.Width); |
| 1706 | |
| 1707 | llvm::Type *ResultLLVMTy = CGM.getTypes().ConvertType(ResultQTy); |
| 1708 | |
| 1709 | llvm::Intrinsic::ID IntrinsicId; |
| 1710 | switch (BuiltinID) { |
| 1711 | default: |
| 1712 | llvm_unreachable("Unknown overflow builtin id."); |
| 1713 | case Builtin::BI__builtin_add_overflow: |
| 1714 | IntrinsicId = EncompassingInfo.Signed |
| 1715 | ? llvm::Intrinsic::sadd_with_overflow |
| 1716 | : llvm::Intrinsic::uadd_with_overflow; |
| 1717 | break; |
| 1718 | case Builtin::BI__builtin_sub_overflow: |
| 1719 | IntrinsicId = EncompassingInfo.Signed |
| 1720 | ? llvm::Intrinsic::ssub_with_overflow |
| 1721 | : llvm::Intrinsic::usub_with_overflow; |
| 1722 | break; |
| 1723 | case Builtin::BI__builtin_mul_overflow: |
| 1724 | IntrinsicId = EncompassingInfo.Signed |
| 1725 | ? llvm::Intrinsic::smul_with_overflow |
| 1726 | : llvm::Intrinsic::umul_with_overflow; |
| 1727 | break; |
| 1728 | } |
| 1729 | |
| 1730 | llvm::Value *Left = EmitScalarExpr(LeftArg); |
| 1731 | llvm::Value *Right = EmitScalarExpr(RightArg); |
| 1732 | Address ResultPtr = EmitPointerWithAlignment(ResultArg); |
| 1733 | |
| 1734 | // Extend each operand to the encompassing type. |
| 1735 | Left = Builder.CreateIntCast(Left, EncompassingLLVMTy, LeftInfo.Signed); |
| 1736 | Right = Builder.CreateIntCast(Right, EncompassingLLVMTy, RightInfo.Signed); |
| 1737 | |
| 1738 | // Perform the operation on the extended values. |
| 1739 | llvm::Value *Overflow, *Result; |
| 1740 | Result = EmitOverflowIntrinsic(*this, IntrinsicId, Left, Right, Overflow); |
| 1741 | |
| 1742 | if (EncompassingInfo.Width > ResultInfo.Width) { |
| 1743 | // The encompassing type is wider than the result type, so we need to |
| 1744 | // truncate it. |
| 1745 | llvm::Value *ResultTrunc = Builder.CreateTrunc(Result, ResultLLVMTy); |
| 1746 | |
| 1747 | // To see if the truncation caused an overflow, we will extend |
| 1748 | // the result and then compare it to the original result. |
| 1749 | llvm::Value *ResultTruncExt = Builder.CreateIntCast( |
| 1750 | ResultTrunc, EncompassingLLVMTy, ResultInfo.Signed); |
| 1751 | llvm::Value *TruncationOverflow = |
| 1752 | Builder.CreateICmpNE(Result, ResultTruncExt); |
| 1753 | |
| 1754 | Overflow = Builder.CreateOr(Overflow, TruncationOverflow); |
| 1755 | Result = ResultTrunc; |
| 1756 | } |
| 1757 | |
| 1758 | // Finally, store the result using the pointer. |
| 1759 | bool isVolatile = |
| 1760 | ResultArg->getType()->getPointeeType().isVolatileQualified(); |
| 1761 | Builder.CreateStore(EmitToMemory(Result, ResultQTy), ResultPtr, isVolatile); |
| 1762 | |
| 1763 | return RValue::get(Overflow); |
| 1764 | } |
| 1765 | |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1766 | case Builtin::BI__builtin_uadd_overflow: |
| 1767 | case Builtin::BI__builtin_uaddl_overflow: |
| 1768 | case Builtin::BI__builtin_uaddll_overflow: |
| 1769 | case Builtin::BI__builtin_usub_overflow: |
| 1770 | case Builtin::BI__builtin_usubl_overflow: |
| 1771 | case Builtin::BI__builtin_usubll_overflow: |
| 1772 | case Builtin::BI__builtin_umul_overflow: |
| 1773 | case Builtin::BI__builtin_umull_overflow: |
| 1774 | case Builtin::BI__builtin_umulll_overflow: |
| 1775 | case Builtin::BI__builtin_sadd_overflow: |
| 1776 | case Builtin::BI__builtin_saddl_overflow: |
| 1777 | case Builtin::BI__builtin_saddll_overflow: |
| 1778 | case Builtin::BI__builtin_ssub_overflow: |
| 1779 | case Builtin::BI__builtin_ssubl_overflow: |
| 1780 | case Builtin::BI__builtin_ssubll_overflow: |
| 1781 | case Builtin::BI__builtin_smul_overflow: |
| 1782 | case Builtin::BI__builtin_smull_overflow: |
| 1783 | case Builtin::BI__builtin_smulll_overflow: { |
| 1784 | |
| 1785 | // We translate all of these builtins directly to the relevant llvm IR node. |
| 1786 | |
| 1787 | // Scalarize our inputs. |
| 1788 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 1789 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1790 | Address SumOutPtr = EmitPointerWithAlignment(E->getArg(2)); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1791 | |
| 1792 | // Decide which of the overflow intrinsics we are lowering to: |
| 1793 | llvm::Intrinsic::ID IntrinsicId; |
| 1794 | switch (BuiltinID) { |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 1795 | default: llvm_unreachable("Unknown overflow builtin id."); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1796 | case Builtin::BI__builtin_uadd_overflow: |
| 1797 | case Builtin::BI__builtin_uaddl_overflow: |
| 1798 | case Builtin::BI__builtin_uaddll_overflow: |
| 1799 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 1800 | break; |
| 1801 | case Builtin::BI__builtin_usub_overflow: |
| 1802 | case Builtin::BI__builtin_usubl_overflow: |
| 1803 | case Builtin::BI__builtin_usubll_overflow: |
| 1804 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 1805 | break; |
| 1806 | case Builtin::BI__builtin_umul_overflow: |
| 1807 | case Builtin::BI__builtin_umull_overflow: |
| 1808 | case Builtin::BI__builtin_umulll_overflow: |
| 1809 | IntrinsicId = llvm::Intrinsic::umul_with_overflow; |
| 1810 | break; |
| 1811 | case Builtin::BI__builtin_sadd_overflow: |
| 1812 | case Builtin::BI__builtin_saddl_overflow: |
| 1813 | case Builtin::BI__builtin_saddll_overflow: |
| 1814 | IntrinsicId = llvm::Intrinsic::sadd_with_overflow; |
| 1815 | break; |
| 1816 | case Builtin::BI__builtin_ssub_overflow: |
| 1817 | case Builtin::BI__builtin_ssubl_overflow: |
| 1818 | case Builtin::BI__builtin_ssubll_overflow: |
| 1819 | IntrinsicId = llvm::Intrinsic::ssub_with_overflow; |
| 1820 | break; |
| 1821 | case Builtin::BI__builtin_smul_overflow: |
| 1822 | case Builtin::BI__builtin_smull_overflow: |
| 1823 | case Builtin::BI__builtin_smulll_overflow: |
| 1824 | IntrinsicId = llvm::Intrinsic::smul_with_overflow; |
| 1825 | break; |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | llvm::Value *Carry; |
| 1830 | llvm::Value *Sum = EmitOverflowIntrinsic(*this, IntrinsicId, X, Y, Carry); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1831 | Builder.CreateStore(Sum, SumOutPtr); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1832 | |
| 1833 | return RValue::get(Carry); |
| 1834 | } |
Richard Smith | 6cbd65d | 2013-07-11 02:27:57 +0000 | [diff] [blame] | 1835 | case Builtin::BI__builtin_addressof: |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1836 | return RValue::get(EmitLValue(E->getArg(0)).getPointer()); |
Richard Smith | 760520b | 2014-06-03 23:27:44 +0000 | [diff] [blame] | 1837 | case Builtin::BI__builtin_operator_new: |
| 1838 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 1839 | E->getArg(0), false); |
| 1840 | case Builtin::BI__builtin_operator_delete: |
| 1841 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 1842 | E->getArg(0), true); |
Nico Weber | 636fc09 | 2012-10-13 22:30:41 +0000 | [diff] [blame] | 1843 | case Builtin::BI__noop: |
Reid Kleckner | ed5d4ad | 2014-07-11 20:22:55 +0000 | [diff] [blame] | 1844 | // __noop always evaluates to an integer literal zero. |
| 1845 | return RValue::get(ConstantInt::get(IntTy, 0)); |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 1846 | case Builtin::BI__builtin_call_with_static_chain: { |
| 1847 | const CallExpr *Call = cast<CallExpr>(E->getArg(0)); |
| 1848 | const Expr *Chain = E->getArg(1); |
| 1849 | return EmitCall(Call->getCallee()->getType(), |
| 1850 | EmitScalarExpr(Call->getCallee()), Call, ReturnValue, |
| 1851 | Call->getCalleeDecl(), EmitScalarExpr(Chain)); |
| 1852 | } |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 1853 | case Builtin::BI_InterlockedExchange: |
| 1854 | case Builtin::BI_InterlockedExchangePointer: |
| 1855 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
| 1856 | case Builtin::BI_InterlockedCompareExchangePointer: { |
| 1857 | llvm::Type *RTy; |
| 1858 | llvm::IntegerType *IntType = |
| 1859 | IntegerType::get(getLLVMContext(), |
| 1860 | getContext().getTypeSize(E->getType())); |
| 1861 | llvm::Type *IntPtrType = IntType->getPointerTo(); |
| 1862 | |
| 1863 | llvm::Value *Destination = |
| 1864 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), IntPtrType); |
| 1865 | |
| 1866 | llvm::Value *Exchange = EmitScalarExpr(E->getArg(1)); |
| 1867 | RTy = Exchange->getType(); |
| 1868 | Exchange = Builder.CreatePtrToInt(Exchange, IntType); |
| 1869 | |
| 1870 | llvm::Value *Comparand = |
| 1871 | Builder.CreatePtrToInt(EmitScalarExpr(E->getArg(2)), IntType); |
| 1872 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1873 | auto Result = |
| 1874 | Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange, |
| 1875 | AtomicOrdering::SequentiallyConsistent, |
| 1876 | AtomicOrdering::SequentiallyConsistent); |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 1877 | Result->setVolatile(true); |
| 1878 | |
| 1879 | return RValue::get(Builder.CreateIntToPtr(Builder.CreateExtractValue(Result, |
| 1880 | 0), |
| 1881 | RTy)); |
| 1882 | } |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1883 | case Builtin::BI_InterlockedCompareExchange: { |
| 1884 | AtomicCmpXchgInst *CXI = Builder.CreateAtomicCmpXchg( |
| 1885 | EmitScalarExpr(E->getArg(0)), |
| 1886 | EmitScalarExpr(E->getArg(2)), |
| 1887 | EmitScalarExpr(E->getArg(1)), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1888 | AtomicOrdering::SequentiallyConsistent, |
| 1889 | AtomicOrdering::SequentiallyConsistent); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1890 | CXI->setVolatile(true); |
Tim Northover | b49b04b | 2014-06-13 14:24:59 +0000 | [diff] [blame] | 1891 | return RValue::get(Builder.CreateExtractValue(CXI, 0)); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1892 | } |
| 1893 | case Builtin::BI_InterlockedIncrement: { |
| 1894 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 1895 | AtomicRMWInst::Add, |
| 1896 | EmitScalarExpr(E->getArg(0)), |
| 1897 | ConstantInt::get(Int32Ty, 1), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1898 | llvm::AtomicOrdering::SequentiallyConsistent); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1899 | RMWI->setVolatile(true); |
| 1900 | return RValue::get(Builder.CreateAdd(RMWI, ConstantInt::get(Int32Ty, 1))); |
| 1901 | } |
| 1902 | case Builtin::BI_InterlockedDecrement: { |
| 1903 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 1904 | AtomicRMWInst::Sub, |
| 1905 | EmitScalarExpr(E->getArg(0)), |
| 1906 | ConstantInt::get(Int32Ty, 1), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1907 | llvm::AtomicOrdering::SequentiallyConsistent); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1908 | RMWI->setVolatile(true); |
| 1909 | return RValue::get(Builder.CreateSub(RMWI, ConstantInt::get(Int32Ty, 1))); |
| 1910 | } |
| 1911 | case Builtin::BI_InterlockedExchangeAdd: { |
| 1912 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 1913 | AtomicRMWInst::Add, |
| 1914 | EmitScalarExpr(E->getArg(0)), |
| 1915 | EmitScalarExpr(E->getArg(1)), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame^] | 1916 | llvm::AtomicOrdering::SequentiallyConsistent); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 1917 | RMWI->setVolatile(true); |
| 1918 | return RValue::get(RMWI); |
| 1919 | } |
Saleem Abdulrasool | a25fbef | 2014-10-29 16:35:41 +0000 | [diff] [blame] | 1920 | case Builtin::BI__readfsdword: { |
| 1921 | Value *IntToPtr = |
| 1922 | Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), |
| 1923 | llvm::PointerType::get(CGM.Int32Ty, 257)); |
| 1924 | LoadInst *Load = |
| 1925 | Builder.CreateAlignedLoad(IntToPtr, /*Align=*/4, /*isVolatile=*/true); |
| 1926 | return RValue::get(Load); |
| 1927 | } |
Reid Kleckner | 1d59f99 | 2015-01-22 01:36:17 +0000 | [diff] [blame] | 1928 | |
| 1929 | case Builtin::BI__exception_code: |
| 1930 | case Builtin::BI_exception_code: |
| 1931 | return RValue::get(EmitSEHExceptionCode()); |
| 1932 | case Builtin::BI__exception_info: |
| 1933 | case Builtin::BI_exception_info: |
| 1934 | return RValue::get(EmitSEHExceptionInfo()); |
Reid Kleckner | aca01db | 2015-02-04 22:37:07 +0000 | [diff] [blame] | 1935 | case Builtin::BI__abnormal_termination: |
| 1936 | case Builtin::BI_abnormal_termination: |
| 1937 | return RValue::get(EmitSEHAbnormalTermination()); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1938 | case Builtin::BI_setjmpex: { |
| 1939 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 1940 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 1941 | llvm::AttributeSet ReturnsTwiceAttr = |
| 1942 | AttributeSet::get(getLLVMContext(), llvm::AttributeSet::FunctionIndex, |
| 1943 | llvm::Attribute::ReturnsTwice); |
| 1944 | llvm::Constant *SetJmpEx = CGM.CreateRuntimeFunction( |
| 1945 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
| 1946 | "_setjmpex", ReturnsTwiceAttr); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1947 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 1948 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1949 | llvm::Value *FrameAddr = |
| 1950 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 1951 | ConstantInt::get(Int32Ty, 0)); |
| 1952 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 1953 | llvm::CallSite CS = EmitRuntimeCallOrInvoke(SetJmpEx, Args); |
| 1954 | CS.setAttributes(ReturnsTwiceAttr); |
| 1955 | return RValue::get(CS.getInstruction()); |
| 1956 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1957 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1958 | } |
| 1959 | case Builtin::BI_setjmp: { |
| 1960 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 1961 | llvm::AttributeSet ReturnsTwiceAttr = |
| 1962 | AttributeSet::get(getLLVMContext(), llvm::AttributeSet::FunctionIndex, |
| 1963 | llvm::Attribute::ReturnsTwice); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1964 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 1965 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1966 | llvm::CallSite CS; |
| 1967 | if (getTarget().getTriple().getArch() == llvm::Triple::x86) { |
| 1968 | llvm::Type *ArgTypes[] = {Int8PtrTy, IntTy}; |
| 1969 | llvm::Constant *SetJmp3 = CGM.CreateRuntimeFunction( |
| 1970 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/true), |
| 1971 | "_setjmp3", ReturnsTwiceAttr); |
| 1972 | llvm::Value *Count = ConstantInt::get(IntTy, 0); |
| 1973 | llvm::Value *Args[] = {Buf, Count}; |
| 1974 | CS = EmitRuntimeCallOrInvoke(SetJmp3, Args); |
| 1975 | } else { |
| 1976 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 1977 | llvm::Constant *SetJmp = CGM.CreateRuntimeFunction( |
| 1978 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
| 1979 | "_setjmp", ReturnsTwiceAttr); |
| 1980 | llvm::Value *FrameAddr = |
| 1981 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 1982 | ConstantInt::get(Int32Ty, 0)); |
| 1983 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 1984 | CS = EmitRuntimeCallOrInvoke(SetJmp, Args); |
| 1985 | } |
| 1986 | CS.setAttributes(ReturnsTwiceAttr); |
| 1987 | return RValue::get(CS.getInstruction()); |
| 1988 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 1989 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 1990 | } |
David Majnemer | ba3e5ec | 2015-03-13 18:26:17 +0000 | [diff] [blame] | 1991 | |
| 1992 | case Builtin::BI__GetExceptionInfo: { |
| 1993 | if (llvm::GlobalVariable *GV = |
| 1994 | CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType())) |
| 1995 | return RValue::get(llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy)); |
| 1996 | break; |
| 1997 | } |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 1998 | |
| 1999 | // OpenCL v2.0 s6.13.16.2, Built-in pipe read and write functions |
| 2000 | case Builtin::BIread_pipe: |
| 2001 | case Builtin::BIwrite_pipe: { |
| 2002 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2003 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 2004 | |
| 2005 | // Type of the generic packet parameter. |
| 2006 | unsigned GenericAS = |
| 2007 | getContext().getTargetAddressSpace(LangAS::opencl_generic); |
| 2008 | llvm::Type *I8PTy = llvm::PointerType::get( |
| 2009 | llvm::Type::getInt8Ty(getLLVMContext()), GenericAS); |
| 2010 | |
| 2011 | // Testing which overloaded version we should generate the call for. |
| 2012 | if (2U == E->getNumArgs()) { |
| 2013 | const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_2" |
| 2014 | : "__write_pipe_2"; |
| 2015 | // Creating a generic function type to be able to call with any builtin or |
| 2016 | // user defined type. |
| 2017 | llvm::Type *ArgTys[] = {Arg0->getType(), I8PTy}; |
| 2018 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2019 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2020 | Value *BCast = Builder.CreatePointerCast(Arg1, I8PTy); |
| 2021 | return RValue::get(Builder.CreateCall( |
| 2022 | CGM.CreateRuntimeFunction(FTy, Name), {Arg0, BCast})); |
| 2023 | } else { |
| 2024 | assert(4 == E->getNumArgs() && |
| 2025 | "Illegal number of parameters to pipe function"); |
| 2026 | const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_4" |
| 2027 | : "__write_pipe_4"; |
| 2028 | |
| 2029 | llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, I8PTy}; |
| 2030 | Value *Arg2 = EmitScalarExpr(E->getArg(2)), |
| 2031 | *Arg3 = EmitScalarExpr(E->getArg(3)); |
| 2032 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2033 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2034 | Value *BCast = Builder.CreatePointerCast(Arg3, I8PTy); |
| 2035 | // We know the third argument is an integer type, but we may need to cast |
| 2036 | // it to i32. |
| 2037 | if (Arg2->getType() != Int32Ty) |
| 2038 | Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty); |
| 2039 | return RValue::get(Builder.CreateCall( |
| 2040 | CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1, Arg2, BCast})); |
| 2041 | } |
| 2042 | } |
| 2043 | // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write |
| 2044 | // functions |
| 2045 | case Builtin::BIreserve_read_pipe: |
| 2046 | case Builtin::BIreserve_write_pipe: |
| 2047 | case Builtin::BIwork_group_reserve_read_pipe: |
| 2048 | case Builtin::BIwork_group_reserve_write_pipe: |
| 2049 | case Builtin::BIsub_group_reserve_read_pipe: |
| 2050 | case Builtin::BIsub_group_reserve_write_pipe: { |
| 2051 | // Composing the mangled name for the function. |
| 2052 | const char *Name; |
| 2053 | if (BuiltinID == Builtin::BIreserve_read_pipe) |
| 2054 | Name = "__reserve_read_pipe"; |
| 2055 | else if (BuiltinID == Builtin::BIreserve_write_pipe) |
| 2056 | Name = "__reserve_write_pipe"; |
| 2057 | else if (BuiltinID == Builtin::BIwork_group_reserve_read_pipe) |
| 2058 | Name = "__work_group_reserve_read_pipe"; |
| 2059 | else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe) |
| 2060 | Name = "__work_group_reserve_write_pipe"; |
| 2061 | else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe) |
| 2062 | Name = "__sub_group_reserve_read_pipe"; |
| 2063 | else |
| 2064 | Name = "__sub_group_reserve_write_pipe"; |
| 2065 | |
| 2066 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2067 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 2068 | llvm::Type *ReservedIDTy = ConvertType(getContext().OCLReserveIDTy); |
| 2069 | |
| 2070 | // Building the generic function prototype. |
| 2071 | llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty}; |
| 2072 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2073 | ReservedIDTy, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2074 | // We know the second argument is an integer type, but we may need to cast |
| 2075 | // it to i32. |
| 2076 | if (Arg1->getType() != Int32Ty) |
| 2077 | Arg1 = Builder.CreateZExtOrTrunc(Arg1, Int32Ty); |
| 2078 | return RValue::get( |
| 2079 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1})); |
| 2080 | } |
| 2081 | // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe commit read and write |
| 2082 | // functions |
| 2083 | case Builtin::BIcommit_read_pipe: |
| 2084 | case Builtin::BIcommit_write_pipe: |
| 2085 | case Builtin::BIwork_group_commit_read_pipe: |
| 2086 | case Builtin::BIwork_group_commit_write_pipe: |
| 2087 | case Builtin::BIsub_group_commit_read_pipe: |
| 2088 | case Builtin::BIsub_group_commit_write_pipe: { |
| 2089 | const char *Name; |
| 2090 | if (BuiltinID == Builtin::BIcommit_read_pipe) |
| 2091 | Name = "__commit_read_pipe"; |
| 2092 | else if (BuiltinID == Builtin::BIcommit_write_pipe) |
| 2093 | Name = "__commit_write_pipe"; |
| 2094 | else if (BuiltinID == Builtin::BIwork_group_commit_read_pipe) |
| 2095 | Name = "__work_group_commit_read_pipe"; |
| 2096 | else if (BuiltinID == Builtin::BIwork_group_commit_write_pipe) |
| 2097 | Name = "__work_group_commit_write_pipe"; |
| 2098 | else if (BuiltinID == Builtin::BIsub_group_commit_read_pipe) |
| 2099 | Name = "__sub_group_commit_read_pipe"; |
| 2100 | else |
| 2101 | Name = "__sub_group_commit_write_pipe"; |
| 2102 | |
| 2103 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2104 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 2105 | |
| 2106 | // Building the generic function prototype. |
| 2107 | llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType()}; |
| 2108 | llvm::FunctionType *FTy = |
| 2109 | llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()), |
| 2110 | llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2111 | |
| 2112 | return RValue::get( |
| 2113 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1})); |
| 2114 | } |
| 2115 | // OpenCL v2.0 s6.13.16.4 Built-in pipe query functions |
| 2116 | case Builtin::BIget_pipe_num_packets: |
| 2117 | case Builtin::BIget_pipe_max_packets: { |
| 2118 | const char *Name; |
| 2119 | if (BuiltinID == Builtin::BIget_pipe_num_packets) |
| 2120 | Name = "__get_pipe_num_packets"; |
| 2121 | else |
| 2122 | Name = "__get_pipe_max_packets"; |
| 2123 | |
| 2124 | // Building the generic function prototype. |
| 2125 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 2126 | llvm::Type *ArgTys[] = {Arg0->getType()}; |
| 2127 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2128 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2129 | |
| 2130 | return RValue::get( |
| 2131 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0})); |
| 2132 | } |
| 2133 | |
Justin Lebar | 3039a59 | 2016-01-23 21:28:14 +0000 | [diff] [blame] | 2134 | case Builtin::BIprintf: |
| 2135 | if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) |
| 2136 | return EmitCUDADevicePrintfCallExpr(E, ReturnValue); |
Matt Arsenault | 2d93398 | 2016-02-27 09:06:18 +0000 | [diff] [blame] | 2137 | break; |
| 2138 | case Builtin::BI__builtin_canonicalize: |
| 2139 | case Builtin::BI__builtin_canonicalizef: |
| 2140 | case Builtin::BI__builtin_canonicalizel: |
| 2141 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::canonicalize)); |
Nate Begeman | 6c59132 | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 2142 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2143 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 2144 | // If this is an alias for a lib function (e.g. __builtin_sin), emit |
| 2145 | // the call using the normal call path, but using the unmangled |
| 2146 | // version of the function name. |
| 2147 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) |
| 2148 | return emitLibraryCall(*this, FD, E, |
| 2149 | CGM.getBuiltinLibFunction(FD, BuiltinID)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2150 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 2151 | // If this is a predefined lib function (e.g. malloc), emit the call |
| 2152 | // using exactly the normal call path. |
| 2153 | if (getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
| 2154 | return emitLibraryCall(*this, FD, E, EmitScalarExpr(E->getCallee())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2155 | |
Eric Christopher | 1570999 | 2015-10-15 23:47:11 +0000 | [diff] [blame] | 2156 | // Check that a call to a target specific builtin has the correct target |
| 2157 | // features. |
| 2158 | // This is down here to avoid non-target specific builtins, however, if |
| 2159 | // generic builtins start to require generic target features then we |
| 2160 | // can move this up to the beginning of the function. |
Eric Christopher | c7e79db | 2015-11-12 00:44:04 +0000 | [diff] [blame] | 2161 | checkTargetFeatures(E, FD); |
Eric Christopher | 1570999 | 2015-10-15 23:47:11 +0000 | [diff] [blame] | 2162 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2163 | // See if we have a target specific intrinsic. |
Eric Christopher | 02d5d86 | 2015-08-06 01:01:12 +0000 | [diff] [blame] | 2164 | const char *Name = getContext().BuiltinInfo.getName(BuiltinID); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2165 | Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; |
| 2166 | if (const char *Prefix = |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 2167 | llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch())) { |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2168 | IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name); |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 2169 | // NOTE we dont need to perform a compatibility flag check here since the |
| 2170 | // intrinsics are declared in Builtins*.def via LANGBUILTIN which filter the |
| 2171 | // MS builtins via ALL_MS_LANGUAGES and are filtered earlier. |
| 2172 | if (IntrinsicID == Intrinsic::not_intrinsic) |
| 2173 | IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix, Name); |
| 2174 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2175 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2176 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
| 2177 | SmallVector<Value*, 16> Args; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2178 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 2179 | // Find out if any arguments are required to be integer constant |
| 2180 | // expressions. |
| 2181 | unsigned ICEArguments = 0; |
| 2182 | ASTContext::GetBuiltinTypeError Error; |
| 2183 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 2184 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 2185 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2186 | Function *F = CGM.getIntrinsic(IntrinsicID); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2187 | llvm::FunctionType *FTy = F->getFunctionType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2188 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2189 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 2190 | Value *ArgValue; |
| 2191 | // If this is a normal argument, just emit it as a scalar. |
| 2192 | if ((ICEArguments & (1 << i)) == 0) { |
| 2193 | ArgValue = EmitScalarExpr(E->getArg(i)); |
| 2194 | } else { |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2195 | // 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] | 2196 | // know that the generated intrinsic gets a ConstantInt. |
| 2197 | llvm::APSInt Result; |
| 2198 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext()); |
| 2199 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 2200 | (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 2201 | ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 2202 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2203 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2204 | // If the intrinsic arg type is different from the builtin arg type |
| 2205 | // we need to do a bit cast. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2206 | llvm::Type *PTy = FTy->getParamType(i); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2207 | if (PTy != ArgValue->getType()) { |
| 2208 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 2209 | "Must be able to losslessly bit cast to param"); |
| 2210 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 2211 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2212 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2213 | Args.push_back(ArgValue); |
| 2214 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2215 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 2216 | Value *V = Builder.CreateCall(F, Args); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2217 | QualType BuiltinRetType = E->getType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2218 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 2219 | llvm::Type *RetTy = VoidTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2220 | if (!BuiltinRetType->isVoidType()) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 2221 | RetTy = ConvertType(BuiltinRetType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2222 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2223 | if (RetTy != V->getType()) { |
| 2224 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 2225 | "Must be able to losslessly bit cast result type"); |
| 2226 | V = Builder.CreateBitCast(V, RetTy); |
| 2227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2228 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2229 | return RValue::get(V); |
| 2230 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2231 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2232 | // 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] | 2233 | if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2234 | return RValue::get(V); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2235 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 2236 | ErrorUnsupported(E, "builtin function"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2237 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2238 | // Unknown builtin, for now just dump it out and return undef. |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 2239 | return GetUndefRValue(E->getType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2240 | } |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 2241 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2242 | static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF, |
| 2243 | unsigned BuiltinID, const CallExpr *E, |
| 2244 | llvm::Triple::ArchType Arch) { |
| 2245 | switch (Arch) { |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2246 | case llvm::Triple::arm: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 2247 | case llvm::Triple::armeb: |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2248 | case llvm::Triple::thumb: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 2249 | case llvm::Triple::thumbeb: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2250 | return CGF->EmitARMBuiltinExpr(BuiltinID, E); |
Tim Northover | 25e8a67 | 2014-05-24 12:51:25 +0000 | [diff] [blame] | 2251 | case llvm::Triple::aarch64: |
| 2252 | case llvm::Triple::aarch64_be: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2253 | return CGF->EmitAArch64BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2254 | case llvm::Triple::x86: |
| 2255 | case llvm::Triple::x86_64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2256 | return CGF->EmitX86BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2257 | case llvm::Triple::ppc: |
| 2258 | case llvm::Triple::ppc64: |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 2259 | case llvm::Triple::ppc64le: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2260 | return CGF->EmitPPCBuiltinExpr(BuiltinID, E); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 2261 | case llvm::Triple::r600: |
Tom Stellard | d8e38a3 | 2015-01-06 20:34:47 +0000 | [diff] [blame] | 2262 | case llvm::Triple::amdgcn: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2263 | return CGF->EmitAMDGPUBuiltinExpr(BuiltinID, E); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 2264 | case llvm::Triple::systemz: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2265 | return CGF->EmitSystemZBuiltinExpr(BuiltinID, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 2266 | case llvm::Triple::nvptx: |
| 2267 | case llvm::Triple::nvptx64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2268 | return CGF->EmitNVPTXBuiltinExpr(BuiltinID, E); |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 2269 | case llvm::Triple::wasm32: |
| 2270 | case llvm::Triple::wasm64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2271 | return CGF->EmitWebAssemblyBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2272 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2273 | return nullptr; |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2274 | } |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2277 | Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, |
| 2278 | const CallExpr *E) { |
| 2279 | if (getContext().BuiltinInfo.isAuxBuiltinID(BuiltinID)) { |
| 2280 | assert(getContext().getAuxTargetInfo() && "Missing aux target info"); |
| 2281 | return EmitTargetArchBuiltinExpr( |
| 2282 | this, getContext().BuiltinInfo.getAuxBuiltinID(BuiltinID), E, |
| 2283 | getContext().getAuxTargetInfo()->getTriple().getArch()); |
| 2284 | } |
| 2285 | |
| 2286 | return EmitTargetArchBuiltinExpr(this, BuiltinID, E, |
| 2287 | getTarget().getTriple().getArch()); |
| 2288 | } |
| 2289 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 2290 | static llvm::VectorType *GetNeonType(CodeGenFunction *CGF, |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2291 | NeonTypeFlags TypeFlags, |
| 2292 | bool V1Ty=false) { |
NAKAMURA Takumi | dabda6b | 2011-11-08 03:27:04 +0000 | [diff] [blame] | 2293 | int IsQuad = TypeFlags.isQuad(); |
| 2294 | switch (TypeFlags.getEltType()) { |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2295 | case NeonTypeFlags::Int8: |
| 2296 | case NeonTypeFlags::Poly8: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2297 | return llvm::VectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2298 | case NeonTypeFlags::Int16: |
| 2299 | case NeonTypeFlags::Poly16: |
| 2300 | case NeonTypeFlags::Float16: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2301 | return llvm::VectorType::get(CGF->Int16Ty, V1Ty ? 1 : (4 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2302 | case NeonTypeFlags::Int32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2303 | return llvm::VectorType::get(CGF->Int32Ty, V1Ty ? 1 : (2 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2304 | case NeonTypeFlags::Int64: |
Kevin Qin | caac85e | 2013-11-14 03:29:16 +0000 | [diff] [blame] | 2305 | case NeonTypeFlags::Poly64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2306 | return llvm::VectorType::get(CGF->Int64Ty, V1Ty ? 1 : (1 << IsQuad)); |
Kevin Qin | fb79d7f | 2013-12-10 06:49:01 +0000 | [diff] [blame] | 2307 | case NeonTypeFlags::Poly128: |
| 2308 | // FIXME: i128 and f128 doesn't get fully support in Clang and llvm. |
| 2309 | // There is a lot of i128 and f128 API missing. |
| 2310 | // so we use v16i8 to represent poly128 and get pattern matched. |
| 2311 | return llvm::VectorType::get(CGF->Int8Ty, 16); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2312 | case NeonTypeFlags::Float32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2313 | return llvm::VectorType::get(CGF->FloatTy, V1Ty ? 1 : (2 << IsQuad)); |
Tim Northover | 2fe823a | 2013-08-01 09:23:19 +0000 | [diff] [blame] | 2314 | case NeonTypeFlags::Float64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2315 | return llvm::VectorType::get(CGF->DoubleTy, V1Ty ? 1 : (1 << IsQuad)); |
David Blaikie | f47fa30 | 2012-01-17 02:30:50 +0000 | [diff] [blame] | 2316 | } |
Benjamin Kramer | 9b1dfe8 | 2013-09-26 16:36:08 +0000 | [diff] [blame] | 2317 | llvm_unreachable("Unknown vector element type!"); |
Nate Begeman | 5968eb2 | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 2320 | static llvm::VectorType *GetFloatNeonType(CodeGenFunction *CGF, |
| 2321 | NeonTypeFlags IntTypeFlags) { |
| 2322 | int IsQuad = IntTypeFlags.isQuad(); |
| 2323 | switch (IntTypeFlags.getEltType()) { |
| 2324 | case NeonTypeFlags::Int32: |
| 2325 | return llvm::VectorType::get(CGF->FloatTy, (2 << IsQuad)); |
| 2326 | case NeonTypeFlags::Int64: |
| 2327 | return llvm::VectorType::get(CGF->DoubleTy, (1 << IsQuad)); |
| 2328 | default: |
| 2329 | llvm_unreachable("Type can't be converted to floating-point!"); |
| 2330 | } |
| 2331 | } |
| 2332 | |
Bob Wilson | 210f6dd | 2010-12-07 22:40:02 +0000 | [diff] [blame] | 2333 | Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) { |
Nate Begeman | 4a04b46 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 2334 | unsigned nElts = cast<llvm::VectorType>(V->getType())->getNumElements(); |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 2335 | Value* SV = llvm::ConstantVector::getSplat(nElts, C); |
Nate Begeman | 4a04b46 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 2336 | return Builder.CreateShuffleVector(V, V, SV, "lane"); |
| 2337 | } |
| 2338 | |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2339 | Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops, |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 2340 | const char *name, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 2341 | unsigned shift, bool rightshift) { |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2342 | unsigned j = 0; |
| 2343 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 2344 | ai != ae; ++ai, ++j) |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 2345 | if (shift > 0 && shift == j) |
| 2346 | Ops[j] = EmitNeonShiftVector(Ops[j], ai->getType(), rightshift); |
| 2347 | else |
| 2348 | Ops[j] = Builder.CreateBitCast(Ops[j], ai->getType(), name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2349 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 2350 | return Builder.CreateCall(F, Ops, name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2353 | Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty, |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 2354 | bool neg) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 2355 | int SV = cast<ConstantInt>(V)->getSExtValue(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 2356 | return ConstantInt::get(Ty, neg ? -SV : SV); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 2359 | // \brief Right-shift a vector by a constant. |
| 2360 | Value *CodeGenFunction::EmitNeonRShiftImm(Value *Vec, Value *Shift, |
| 2361 | llvm::Type *Ty, bool usgn, |
| 2362 | const char *name) { |
| 2363 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 2364 | |
| 2365 | int ShiftAmt = cast<ConstantInt>(Shift)->getSExtValue(); |
| 2366 | int EltSize = VTy->getScalarSizeInBits(); |
| 2367 | |
| 2368 | Vec = Builder.CreateBitCast(Vec, Ty); |
| 2369 | |
| 2370 | // lshr/ashr are undefined when the shift amount is equal to the vector |
| 2371 | // element size. |
| 2372 | if (ShiftAmt == EltSize) { |
| 2373 | if (usgn) { |
| 2374 | // Right-shifting an unsigned value by its size yields 0. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 2375 | return llvm::ConstantAggregateZero::get(VTy); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 2376 | } else { |
| 2377 | // Right-shifting a signed value by its size is equivalent |
| 2378 | // to a shift of size-1. |
| 2379 | --ShiftAmt; |
| 2380 | Shift = ConstantInt::get(VTy->getElementType(), ShiftAmt); |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | Shift = EmitNeonShiftVector(Shift, Ty, false); |
| 2385 | if (usgn) |
| 2386 | return Builder.CreateLShr(Vec, Shift, name); |
| 2387 | else |
| 2388 | return Builder.CreateAShr(Vec, Shift, name); |
| 2389 | } |
| 2390 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2391 | enum { |
| 2392 | AddRetType = (1 << 0), |
| 2393 | Add1ArgType = (1 << 1), |
| 2394 | Add2ArgTypes = (1 << 2), |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2395 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2396 | VectorizeRetType = (1 << 3), |
| 2397 | VectorizeArgTypes = (1 << 4), |
| 2398 | |
| 2399 | InventFloatType = (1 << 5), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2400 | UnsignedAlts = (1 << 6), |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2401 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2402 | Use64BitVectors = (1 << 7), |
| 2403 | Use128BitVectors = (1 << 8), |
| 2404 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2405 | Vectorize1ArgType = Add1ArgType | VectorizeArgTypes, |
| 2406 | VectorRet = AddRetType | VectorizeRetType, |
| 2407 | VectorRetGetArgs01 = |
| 2408 | AddRetType | Add2ArgTypes | VectorizeRetType | VectorizeArgTypes, |
| 2409 | FpCmpzModifiers = |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 2410 | AddRetType | VectorizeRetType | Add1ArgType | InventFloatType |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2411 | }; |
| 2412 | |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 2413 | namespace { |
| 2414 | struct NeonIntrinsicInfo { |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2415 | const char *NameHint; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2416 | unsigned BuiltinID; |
| 2417 | unsigned LLVMIntrinsic; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2418 | unsigned AltLLVMIntrinsic; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2419 | unsigned TypeModifier; |
| 2420 | |
| 2421 | bool operator<(unsigned RHSBuiltinID) const { |
| 2422 | return BuiltinID < RHSBuiltinID; |
| 2423 | } |
Eric Christopher | ed60b43 | 2015-11-11 02:04:08 +0000 | [diff] [blame] | 2424 | bool operator<(const NeonIntrinsicInfo &TE) const { |
| 2425 | return BuiltinID < TE.BuiltinID; |
| 2426 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2427 | }; |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 2428 | } // end anonymous namespace |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2429 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2430 | #define NEONMAP0(NameBase) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2431 | { #NameBase, NEON::BI__builtin_neon_ ## NameBase, 0, 0, 0 } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2432 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2433 | #define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2434 | { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \ |
| 2435 | Intrinsic::LLVMIntrinsic, 0, TypeModifier } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2436 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2437 | #define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2438 | { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \ |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2439 | Intrinsic::LLVMIntrinsic, Intrinsic::AltLLVMIntrinsic, \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2440 | TypeModifier } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2441 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 2442 | static const NeonIntrinsicInfo ARMSIMDIntrinsicMap [] = { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2443 | NEONMAP2(vabd_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 2444 | NEONMAP2(vabdq_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 2445 | NEONMAP1(vabs_v, arm_neon_vabs, 0), |
| 2446 | NEONMAP1(vabsq_v, arm_neon_vabs, 0), |
| 2447 | NEONMAP0(vaddhn_v), |
| 2448 | NEONMAP1(vaesdq_v, arm_neon_aesd, 0), |
| 2449 | NEONMAP1(vaeseq_v, arm_neon_aese, 0), |
| 2450 | NEONMAP1(vaesimcq_v, arm_neon_aesimc, 0), |
| 2451 | NEONMAP1(vaesmcq_v, arm_neon_aesmc, 0), |
| 2452 | NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType), |
| 2453 | NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType), |
| 2454 | NEONMAP1(vcage_v, arm_neon_vacge, 0), |
| 2455 | NEONMAP1(vcageq_v, arm_neon_vacge, 0), |
| 2456 | NEONMAP1(vcagt_v, arm_neon_vacgt, 0), |
| 2457 | NEONMAP1(vcagtq_v, arm_neon_vacgt, 0), |
| 2458 | NEONMAP1(vcale_v, arm_neon_vacge, 0), |
| 2459 | NEONMAP1(vcaleq_v, arm_neon_vacge, 0), |
| 2460 | NEONMAP1(vcalt_v, arm_neon_vacgt, 0), |
| 2461 | NEONMAP1(vcaltq_v, arm_neon_vacgt, 0), |
| 2462 | NEONMAP1(vcls_v, arm_neon_vcls, Add1ArgType), |
| 2463 | NEONMAP1(vclsq_v, arm_neon_vcls, Add1ArgType), |
| 2464 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 2465 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 2466 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 2467 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Ahmed Bougacha | cd5b8a0 | 2015-08-21 23:34:20 +0000 | [diff] [blame] | 2468 | NEONMAP1(vcvt_f16_f32, arm_neon_vcvtfp2hf, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2469 | NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0), |
| 2470 | NEONMAP0(vcvt_f32_v), |
| 2471 | NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
| 2472 | NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 2473 | NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
| 2474 | NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 2475 | NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
| 2476 | NEONMAP0(vcvt_s32_v), |
| 2477 | NEONMAP0(vcvt_s64_v), |
| 2478 | NEONMAP0(vcvt_u32_v), |
| 2479 | NEONMAP0(vcvt_u64_v), |
| 2480 | NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0), |
| 2481 | NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0), |
| 2482 | NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0), |
| 2483 | NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0), |
| 2484 | NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0), |
| 2485 | NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0), |
| 2486 | NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0), |
| 2487 | NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0), |
| 2488 | NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0), |
| 2489 | NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0), |
| 2490 | NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0), |
| 2491 | NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0), |
| 2492 | NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0), |
| 2493 | NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0), |
| 2494 | NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0), |
| 2495 | NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0), |
| 2496 | NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0), |
| 2497 | NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0), |
| 2498 | NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0), |
| 2499 | NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0), |
| 2500 | NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0), |
| 2501 | NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0), |
| 2502 | NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0), |
| 2503 | NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0), |
| 2504 | NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0), |
| 2505 | NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0), |
| 2506 | NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0), |
| 2507 | NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0), |
| 2508 | NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0), |
| 2509 | NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0), |
| 2510 | NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0), |
| 2511 | NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0), |
| 2512 | NEONMAP0(vcvtq_f32_v), |
| 2513 | NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
| 2514 | NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 2515 | NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
| 2516 | NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 2517 | NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
| 2518 | NEONMAP0(vcvtq_s32_v), |
| 2519 | NEONMAP0(vcvtq_s64_v), |
| 2520 | NEONMAP0(vcvtq_u32_v), |
| 2521 | NEONMAP0(vcvtq_u64_v), |
| 2522 | NEONMAP0(vext_v), |
| 2523 | NEONMAP0(vextq_v), |
| 2524 | NEONMAP0(vfma_v), |
| 2525 | NEONMAP0(vfmaq_v), |
| 2526 | NEONMAP2(vhadd_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 2527 | NEONMAP2(vhaddq_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 2528 | NEONMAP2(vhsub_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 2529 | NEONMAP2(vhsubq_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 2530 | NEONMAP0(vld1_dup_v), |
| 2531 | NEONMAP1(vld1_v, arm_neon_vld1, 0), |
| 2532 | NEONMAP0(vld1q_dup_v), |
| 2533 | NEONMAP1(vld1q_v, arm_neon_vld1, 0), |
| 2534 | NEONMAP1(vld2_lane_v, arm_neon_vld2lane, 0), |
| 2535 | NEONMAP1(vld2_v, arm_neon_vld2, 0), |
| 2536 | NEONMAP1(vld2q_lane_v, arm_neon_vld2lane, 0), |
| 2537 | NEONMAP1(vld2q_v, arm_neon_vld2, 0), |
| 2538 | NEONMAP1(vld3_lane_v, arm_neon_vld3lane, 0), |
| 2539 | NEONMAP1(vld3_v, arm_neon_vld3, 0), |
| 2540 | NEONMAP1(vld3q_lane_v, arm_neon_vld3lane, 0), |
| 2541 | NEONMAP1(vld3q_v, arm_neon_vld3, 0), |
| 2542 | NEONMAP1(vld4_lane_v, arm_neon_vld4lane, 0), |
| 2543 | NEONMAP1(vld4_v, arm_neon_vld4, 0), |
| 2544 | NEONMAP1(vld4q_lane_v, arm_neon_vld4lane, 0), |
| 2545 | NEONMAP1(vld4q_v, arm_neon_vld4, 0), |
| 2546 | NEONMAP2(vmax_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2547 | NEONMAP1(vmaxnm_v, arm_neon_vmaxnm, Add1ArgType), |
| 2548 | NEONMAP1(vmaxnmq_v, arm_neon_vmaxnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2549 | NEONMAP2(vmaxq_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
| 2550 | NEONMAP2(vmin_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2551 | NEONMAP1(vminnm_v, arm_neon_vminnm, Add1ArgType), |
| 2552 | NEONMAP1(vminnmq_v, arm_neon_vminnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2553 | NEONMAP2(vminq_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
| 2554 | NEONMAP0(vmovl_v), |
| 2555 | NEONMAP0(vmovn_v), |
| 2556 | NEONMAP1(vmul_v, arm_neon_vmulp, Add1ArgType), |
| 2557 | NEONMAP0(vmull_v), |
| 2558 | NEONMAP1(vmulq_v, arm_neon_vmulp, Add1ArgType), |
| 2559 | NEONMAP2(vpadal_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 2560 | NEONMAP2(vpadalq_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 2561 | NEONMAP1(vpadd_v, arm_neon_vpadd, Add1ArgType), |
| 2562 | NEONMAP2(vpaddl_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 2563 | NEONMAP2(vpaddlq_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 2564 | NEONMAP1(vpaddq_v, arm_neon_vpadd, Add1ArgType), |
| 2565 | NEONMAP2(vpmax_v, arm_neon_vpmaxu, arm_neon_vpmaxs, Add1ArgType | UnsignedAlts), |
| 2566 | NEONMAP2(vpmin_v, arm_neon_vpminu, arm_neon_vpmins, Add1ArgType | UnsignedAlts), |
| 2567 | NEONMAP1(vqabs_v, arm_neon_vqabs, Add1ArgType), |
| 2568 | NEONMAP1(vqabsq_v, arm_neon_vqabs, Add1ArgType), |
| 2569 | NEONMAP2(vqadd_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 2570 | NEONMAP2(vqaddq_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 2571 | NEONMAP2(vqdmlal_v, arm_neon_vqdmull, arm_neon_vqadds, 0), |
| 2572 | NEONMAP2(vqdmlsl_v, arm_neon_vqdmull, arm_neon_vqsubs, 0), |
| 2573 | NEONMAP1(vqdmulh_v, arm_neon_vqdmulh, Add1ArgType), |
| 2574 | NEONMAP1(vqdmulhq_v, arm_neon_vqdmulh, Add1ArgType), |
| 2575 | NEONMAP1(vqdmull_v, arm_neon_vqdmull, Add1ArgType), |
| 2576 | NEONMAP2(vqmovn_v, arm_neon_vqmovnu, arm_neon_vqmovns, Add1ArgType | UnsignedAlts), |
| 2577 | NEONMAP1(vqmovun_v, arm_neon_vqmovnsu, Add1ArgType), |
| 2578 | NEONMAP1(vqneg_v, arm_neon_vqneg, Add1ArgType), |
| 2579 | NEONMAP1(vqnegq_v, arm_neon_vqneg, Add1ArgType), |
| 2580 | NEONMAP1(vqrdmulh_v, arm_neon_vqrdmulh, Add1ArgType), |
| 2581 | NEONMAP1(vqrdmulhq_v, arm_neon_vqrdmulh, Add1ArgType), |
| 2582 | NEONMAP2(vqrshl_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 2583 | NEONMAP2(vqrshlq_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 2584 | NEONMAP2(vqshl_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 2585 | NEONMAP2(vqshl_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
| 2586 | NEONMAP2(vqshlq_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 2587 | NEONMAP2(vqshlq_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2588 | NEONMAP1(vqshlu_n_v, arm_neon_vqshiftsu, 0), |
| 2589 | NEONMAP1(vqshluq_n_v, arm_neon_vqshiftsu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2590 | NEONMAP2(vqsub_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 2591 | NEONMAP2(vqsubq_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 2592 | NEONMAP1(vraddhn_v, arm_neon_vraddhn, Add1ArgType), |
| 2593 | NEONMAP2(vrecpe_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 2594 | NEONMAP2(vrecpeq_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 2595 | NEONMAP1(vrecps_v, arm_neon_vrecps, Add1ArgType), |
| 2596 | NEONMAP1(vrecpsq_v, arm_neon_vrecps, Add1ArgType), |
| 2597 | NEONMAP2(vrhadd_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
| 2598 | NEONMAP2(vrhaddq_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2599 | NEONMAP1(vrnd_v, arm_neon_vrintz, Add1ArgType), |
| 2600 | NEONMAP1(vrnda_v, arm_neon_vrinta, Add1ArgType), |
| 2601 | NEONMAP1(vrndaq_v, arm_neon_vrinta, Add1ArgType), |
| 2602 | NEONMAP1(vrndm_v, arm_neon_vrintm, Add1ArgType), |
| 2603 | NEONMAP1(vrndmq_v, arm_neon_vrintm, Add1ArgType), |
| 2604 | NEONMAP1(vrndn_v, arm_neon_vrintn, Add1ArgType), |
| 2605 | NEONMAP1(vrndnq_v, arm_neon_vrintn, Add1ArgType), |
| 2606 | NEONMAP1(vrndp_v, arm_neon_vrintp, Add1ArgType), |
| 2607 | NEONMAP1(vrndpq_v, arm_neon_vrintp, Add1ArgType), |
| 2608 | NEONMAP1(vrndq_v, arm_neon_vrintz, Add1ArgType), |
| 2609 | NEONMAP1(vrndx_v, arm_neon_vrintx, Add1ArgType), |
| 2610 | NEONMAP1(vrndxq_v, arm_neon_vrintx, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2611 | NEONMAP2(vrshl_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
| 2612 | NEONMAP2(vrshlq_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2613 | NEONMAP2(vrshr_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
| 2614 | NEONMAP2(vrshrq_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2615 | NEONMAP2(vrsqrte_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 2616 | NEONMAP2(vrsqrteq_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 2617 | NEONMAP1(vrsqrts_v, arm_neon_vrsqrts, Add1ArgType), |
| 2618 | NEONMAP1(vrsqrtsq_v, arm_neon_vrsqrts, Add1ArgType), |
| 2619 | NEONMAP1(vrsubhn_v, arm_neon_vrsubhn, Add1ArgType), |
| 2620 | NEONMAP1(vsha1su0q_v, arm_neon_sha1su0, 0), |
| 2621 | NEONMAP1(vsha1su1q_v, arm_neon_sha1su1, 0), |
| 2622 | NEONMAP1(vsha256h2q_v, arm_neon_sha256h2, 0), |
| 2623 | NEONMAP1(vsha256hq_v, arm_neon_sha256h, 0), |
| 2624 | NEONMAP1(vsha256su0q_v, arm_neon_sha256su0, 0), |
| 2625 | NEONMAP1(vsha256su1q_v, arm_neon_sha256su1, 0), |
| 2626 | NEONMAP0(vshl_n_v), |
| 2627 | NEONMAP2(vshl_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 2628 | NEONMAP0(vshll_n_v), |
| 2629 | NEONMAP0(vshlq_n_v), |
| 2630 | NEONMAP2(vshlq_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 2631 | NEONMAP0(vshr_n_v), |
| 2632 | NEONMAP0(vshrn_n_v), |
| 2633 | NEONMAP0(vshrq_n_v), |
| 2634 | NEONMAP1(vst1_v, arm_neon_vst1, 0), |
| 2635 | NEONMAP1(vst1q_v, arm_neon_vst1, 0), |
| 2636 | NEONMAP1(vst2_lane_v, arm_neon_vst2lane, 0), |
| 2637 | NEONMAP1(vst2_v, arm_neon_vst2, 0), |
| 2638 | NEONMAP1(vst2q_lane_v, arm_neon_vst2lane, 0), |
| 2639 | NEONMAP1(vst2q_v, arm_neon_vst2, 0), |
| 2640 | NEONMAP1(vst3_lane_v, arm_neon_vst3lane, 0), |
| 2641 | NEONMAP1(vst3_v, arm_neon_vst3, 0), |
| 2642 | NEONMAP1(vst3q_lane_v, arm_neon_vst3lane, 0), |
| 2643 | NEONMAP1(vst3q_v, arm_neon_vst3, 0), |
| 2644 | NEONMAP1(vst4_lane_v, arm_neon_vst4lane, 0), |
| 2645 | NEONMAP1(vst4_v, arm_neon_vst4, 0), |
| 2646 | NEONMAP1(vst4q_lane_v, arm_neon_vst4lane, 0), |
| 2647 | NEONMAP1(vst4q_v, arm_neon_vst4, 0), |
| 2648 | NEONMAP0(vsubhn_v), |
| 2649 | NEONMAP0(vtrn_v), |
| 2650 | NEONMAP0(vtrnq_v), |
| 2651 | NEONMAP0(vtst_v), |
| 2652 | NEONMAP0(vtstq_v), |
| 2653 | NEONMAP0(vuzp_v), |
| 2654 | NEONMAP0(vuzpq_v), |
| 2655 | NEONMAP0(vzip_v), |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 2656 | NEONMAP0(vzipq_v) |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2657 | }; |
| 2658 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 2659 | static const NeonIntrinsicInfo AArch64SIMDIntrinsicMap[] = { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2660 | NEONMAP1(vabs_v, aarch64_neon_abs, 0), |
| 2661 | NEONMAP1(vabsq_v, aarch64_neon_abs, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2662 | NEONMAP0(vaddhn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2663 | NEONMAP1(vaesdq_v, aarch64_crypto_aesd, 0), |
| 2664 | NEONMAP1(vaeseq_v, aarch64_crypto_aese, 0), |
| 2665 | NEONMAP1(vaesimcq_v, aarch64_crypto_aesimc, 0), |
| 2666 | NEONMAP1(vaesmcq_v, aarch64_crypto_aesmc, 0), |
| 2667 | NEONMAP1(vcage_v, aarch64_neon_facge, 0), |
| 2668 | NEONMAP1(vcageq_v, aarch64_neon_facge, 0), |
| 2669 | NEONMAP1(vcagt_v, aarch64_neon_facgt, 0), |
| 2670 | NEONMAP1(vcagtq_v, aarch64_neon_facgt, 0), |
| 2671 | NEONMAP1(vcale_v, aarch64_neon_facge, 0), |
| 2672 | NEONMAP1(vcaleq_v, aarch64_neon_facge, 0), |
| 2673 | NEONMAP1(vcalt_v, aarch64_neon_facgt, 0), |
| 2674 | NEONMAP1(vcaltq_v, aarch64_neon_facgt, 0), |
| 2675 | NEONMAP1(vcls_v, aarch64_neon_cls, Add1ArgType), |
| 2676 | NEONMAP1(vclsq_v, aarch64_neon_cls, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2677 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 2678 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 2679 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 2680 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Ahmed Bougacha | cd5b8a0 | 2015-08-21 23:34:20 +0000 | [diff] [blame] | 2681 | NEONMAP1(vcvt_f16_f32, aarch64_neon_vcvtfp2hf, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2682 | NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2683 | NEONMAP0(vcvt_f32_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2684 | NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2685 | NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2686 | NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2687 | NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2688 | NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 2689 | NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2690 | NEONMAP0(vcvtq_f32_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2691 | NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2692 | NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 2693 | NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2694 | NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
| 2695 | NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 2696 | NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
| 2697 | NEONMAP1(vcvtx_f32_v, aarch64_neon_fcvtxn, AddRetType | Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2698 | NEONMAP0(vext_v), |
| 2699 | NEONMAP0(vextq_v), |
| 2700 | NEONMAP0(vfma_v), |
| 2701 | NEONMAP0(vfmaq_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2702 | NEONMAP2(vhadd_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 2703 | NEONMAP2(vhaddq_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 2704 | NEONMAP2(vhsub_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
| 2705 | NEONMAP2(vhsubq_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2706 | NEONMAP0(vmovl_v), |
| 2707 | NEONMAP0(vmovn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2708 | NEONMAP1(vmul_v, aarch64_neon_pmul, Add1ArgType), |
| 2709 | NEONMAP1(vmulq_v, aarch64_neon_pmul, Add1ArgType), |
| 2710 | NEONMAP1(vpadd_v, aarch64_neon_addp, Add1ArgType), |
| 2711 | NEONMAP2(vpaddl_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 2712 | NEONMAP2(vpaddlq_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 2713 | NEONMAP1(vpaddq_v, aarch64_neon_addp, Add1ArgType), |
| 2714 | NEONMAP1(vqabs_v, aarch64_neon_sqabs, Add1ArgType), |
| 2715 | NEONMAP1(vqabsq_v, aarch64_neon_sqabs, Add1ArgType), |
| 2716 | NEONMAP2(vqadd_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 2717 | NEONMAP2(vqaddq_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 2718 | NEONMAP2(vqdmlal_v, aarch64_neon_sqdmull, aarch64_neon_sqadd, 0), |
| 2719 | NEONMAP2(vqdmlsl_v, aarch64_neon_sqdmull, aarch64_neon_sqsub, 0), |
| 2720 | NEONMAP1(vqdmulh_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 2721 | NEONMAP1(vqdmulhq_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 2722 | NEONMAP1(vqdmull_v, aarch64_neon_sqdmull, Add1ArgType), |
| 2723 | NEONMAP2(vqmovn_v, aarch64_neon_uqxtn, aarch64_neon_sqxtn, Add1ArgType | UnsignedAlts), |
| 2724 | NEONMAP1(vqmovun_v, aarch64_neon_sqxtun, Add1ArgType), |
| 2725 | NEONMAP1(vqneg_v, aarch64_neon_sqneg, Add1ArgType), |
| 2726 | NEONMAP1(vqnegq_v, aarch64_neon_sqneg, Add1ArgType), |
| 2727 | NEONMAP1(vqrdmulh_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 2728 | NEONMAP1(vqrdmulhq_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 2729 | NEONMAP2(vqrshl_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 2730 | NEONMAP2(vqrshlq_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 2731 | NEONMAP2(vqshl_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl, UnsignedAlts), |
| 2732 | NEONMAP2(vqshl_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
| 2733 | NEONMAP2(vqshlq_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl,UnsignedAlts), |
| 2734 | NEONMAP2(vqshlq_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2735 | NEONMAP1(vqshlu_n_v, aarch64_neon_sqshlu, 0), |
| 2736 | NEONMAP1(vqshluq_n_v, aarch64_neon_sqshlu, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2737 | NEONMAP2(vqsub_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 2738 | NEONMAP2(vqsubq_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 2739 | NEONMAP1(vraddhn_v, aarch64_neon_raddhn, Add1ArgType), |
| 2740 | NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 2741 | NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 2742 | NEONMAP1(vrecps_v, aarch64_neon_frecps, Add1ArgType), |
| 2743 | NEONMAP1(vrecpsq_v, aarch64_neon_frecps, Add1ArgType), |
| 2744 | NEONMAP2(vrhadd_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 2745 | NEONMAP2(vrhaddq_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 2746 | NEONMAP2(vrshl_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
| 2747 | NEONMAP2(vrshlq_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2748 | NEONMAP2(vrshr_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
| 2749 | NEONMAP2(vrshrq_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2750 | NEONMAP2(vrsqrte_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 2751 | NEONMAP2(vrsqrteq_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 2752 | NEONMAP1(vrsqrts_v, aarch64_neon_frsqrts, Add1ArgType), |
| 2753 | NEONMAP1(vrsqrtsq_v, aarch64_neon_frsqrts, Add1ArgType), |
| 2754 | NEONMAP1(vrsubhn_v, aarch64_neon_rsubhn, Add1ArgType), |
| 2755 | NEONMAP1(vsha1su0q_v, aarch64_crypto_sha1su0, 0), |
| 2756 | NEONMAP1(vsha1su1q_v, aarch64_crypto_sha1su1, 0), |
| 2757 | NEONMAP1(vsha256h2q_v, aarch64_crypto_sha256h2, 0), |
| 2758 | NEONMAP1(vsha256hq_v, aarch64_crypto_sha256h, 0), |
| 2759 | NEONMAP1(vsha256su0q_v, aarch64_crypto_sha256su0, 0), |
| 2760 | NEONMAP1(vsha256su1q_v, aarch64_crypto_sha256su1, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2761 | NEONMAP0(vshl_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2762 | NEONMAP2(vshl_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2763 | NEONMAP0(vshll_n_v), |
| 2764 | NEONMAP0(vshlq_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2765 | NEONMAP2(vshlq_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2766 | NEONMAP0(vshr_n_v), |
| 2767 | NEONMAP0(vshrn_n_v), |
| 2768 | NEONMAP0(vshrq_n_v), |
| 2769 | NEONMAP0(vsubhn_v), |
| 2770 | NEONMAP0(vtst_v), |
| 2771 | NEONMAP0(vtstq_v), |
| 2772 | }; |
| 2773 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 2774 | static const NeonIntrinsicInfo AArch64SISDIntrinsicMap[] = { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2775 | NEONMAP1(vabdd_f64, aarch64_sisd_fabd, Add1ArgType), |
| 2776 | NEONMAP1(vabds_f32, aarch64_sisd_fabd, Add1ArgType), |
| 2777 | NEONMAP1(vabsd_s64, aarch64_neon_abs, Add1ArgType), |
| 2778 | NEONMAP1(vaddlv_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 2779 | NEONMAP1(vaddlv_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 2780 | NEONMAP1(vaddlvq_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 2781 | NEONMAP1(vaddlvq_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 2782 | NEONMAP1(vaddv_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 2783 | NEONMAP1(vaddv_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 2784 | NEONMAP1(vaddv_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2785 | NEONMAP1(vaddvq_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 2786 | NEONMAP1(vaddvq_f64, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 2787 | NEONMAP1(vaddvq_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 2788 | NEONMAP1(vaddvq_s64, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 2789 | NEONMAP1(vaddvq_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2790 | NEONMAP1(vaddvq_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2791 | NEONMAP1(vcaged_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2792 | NEONMAP1(vcages_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2793 | NEONMAP1(vcagtd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2794 | NEONMAP1(vcagts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2795 | NEONMAP1(vcaled_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2796 | NEONMAP1(vcales_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 2797 | NEONMAP1(vcaltd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2798 | NEONMAP1(vcalts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 2799 | NEONMAP1(vcvtad_s64_f64, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 2800 | NEONMAP1(vcvtad_u64_f64, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 2801 | NEONMAP1(vcvtas_s32_f32, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 2802 | NEONMAP1(vcvtas_u32_f32, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 2803 | NEONMAP1(vcvtd_n_f64_s64, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 2804 | NEONMAP1(vcvtd_n_f64_u64, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 2805 | NEONMAP1(vcvtd_n_s64_f64, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 2806 | NEONMAP1(vcvtd_n_u64_f64, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 2807 | NEONMAP1(vcvtmd_s64_f64, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 2808 | NEONMAP1(vcvtmd_u64_f64, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 2809 | NEONMAP1(vcvtms_s32_f32, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 2810 | NEONMAP1(vcvtms_u32_f32, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 2811 | NEONMAP1(vcvtnd_s64_f64, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 2812 | NEONMAP1(vcvtnd_u64_f64, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 2813 | NEONMAP1(vcvtns_s32_f32, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 2814 | NEONMAP1(vcvtns_u32_f32, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 2815 | NEONMAP1(vcvtpd_s64_f64, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 2816 | NEONMAP1(vcvtpd_u64_f64, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 2817 | NEONMAP1(vcvtps_s32_f32, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 2818 | NEONMAP1(vcvtps_u32_f32, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 2819 | NEONMAP1(vcvts_n_f32_s32, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 2820 | NEONMAP1(vcvts_n_f32_u32, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 2821 | NEONMAP1(vcvts_n_s32_f32, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 2822 | NEONMAP1(vcvts_n_u32_f32, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 2823 | NEONMAP1(vcvtxd_f32_f64, aarch64_sisd_fcvtxn, 0), |
| 2824 | NEONMAP1(vmaxnmv_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2825 | NEONMAP1(vmaxnmvq_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2826 | NEONMAP1(vmaxnmvq_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2827 | NEONMAP1(vmaxv_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2828 | NEONMAP1(vmaxv_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 2829 | NEONMAP1(vmaxv_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 2830 | NEONMAP1(vmaxvq_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2831 | NEONMAP1(vmaxvq_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2832 | NEONMAP1(vmaxvq_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 2833 | NEONMAP1(vmaxvq_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 2834 | NEONMAP1(vminnmv_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2835 | NEONMAP1(vminnmvq_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2836 | NEONMAP1(vminnmvq_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2837 | NEONMAP1(vminv_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2838 | NEONMAP1(vminv_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 2839 | NEONMAP1(vminv_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 2840 | NEONMAP1(vminvq_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2841 | NEONMAP1(vminvq_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2842 | NEONMAP1(vminvq_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 2843 | NEONMAP1(vminvq_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 2844 | NEONMAP1(vmull_p64, aarch64_neon_pmull64, 0), |
| 2845 | NEONMAP1(vmulxd_f64, aarch64_neon_fmulx, Add1ArgType), |
| 2846 | NEONMAP1(vmulxs_f32, aarch64_neon_fmulx, Add1ArgType), |
| 2847 | NEONMAP1(vpaddd_s64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2848 | NEONMAP1(vpaddd_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 2849 | NEONMAP1(vpmaxnmqd_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2850 | NEONMAP1(vpmaxnms_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 2851 | NEONMAP1(vpmaxqd_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2852 | NEONMAP1(vpmaxs_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 2853 | NEONMAP1(vpminnmqd_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2854 | NEONMAP1(vpminnms_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 2855 | NEONMAP1(vpminqd_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2856 | NEONMAP1(vpmins_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 2857 | NEONMAP1(vqabsb_s8, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 2858 | NEONMAP1(vqabsd_s64, aarch64_neon_sqabs, Add1ArgType), |
| 2859 | NEONMAP1(vqabsh_s16, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 2860 | NEONMAP1(vqabss_s32, aarch64_neon_sqabs, Add1ArgType), |
| 2861 | NEONMAP1(vqaddb_s8, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 2862 | NEONMAP1(vqaddb_u8, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 2863 | NEONMAP1(vqaddd_s64, aarch64_neon_sqadd, Add1ArgType), |
| 2864 | NEONMAP1(vqaddd_u64, aarch64_neon_uqadd, Add1ArgType), |
| 2865 | NEONMAP1(vqaddh_s16, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 2866 | NEONMAP1(vqaddh_u16, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 2867 | NEONMAP1(vqadds_s32, aarch64_neon_sqadd, Add1ArgType), |
| 2868 | NEONMAP1(vqadds_u32, aarch64_neon_uqadd, Add1ArgType), |
| 2869 | NEONMAP1(vqdmulhh_s16, aarch64_neon_sqdmulh, Vectorize1ArgType | Use64BitVectors), |
| 2870 | NEONMAP1(vqdmulhs_s32, aarch64_neon_sqdmulh, Add1ArgType), |
| 2871 | NEONMAP1(vqdmullh_s16, aarch64_neon_sqdmull, VectorRet | Use128BitVectors), |
| 2872 | NEONMAP1(vqdmulls_s32, aarch64_neon_sqdmulls_scalar, 0), |
| 2873 | NEONMAP1(vqmovnd_s64, aarch64_neon_scalar_sqxtn, AddRetType | Add1ArgType), |
| 2874 | NEONMAP1(vqmovnd_u64, aarch64_neon_scalar_uqxtn, AddRetType | Add1ArgType), |
| 2875 | NEONMAP1(vqmovnh_s16, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 2876 | NEONMAP1(vqmovnh_u16, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 2877 | NEONMAP1(vqmovns_s32, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 2878 | NEONMAP1(vqmovns_u32, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 2879 | NEONMAP1(vqmovund_s64, aarch64_neon_scalar_sqxtun, AddRetType | Add1ArgType), |
| 2880 | NEONMAP1(vqmovunh_s16, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 2881 | NEONMAP1(vqmovuns_s32, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 2882 | NEONMAP1(vqnegb_s8, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 2883 | NEONMAP1(vqnegd_s64, aarch64_neon_sqneg, Add1ArgType), |
| 2884 | NEONMAP1(vqnegh_s16, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 2885 | NEONMAP1(vqnegs_s32, aarch64_neon_sqneg, Add1ArgType), |
| 2886 | NEONMAP1(vqrdmulhh_s16, aarch64_neon_sqrdmulh, Vectorize1ArgType | Use64BitVectors), |
| 2887 | NEONMAP1(vqrdmulhs_s32, aarch64_neon_sqrdmulh, Add1ArgType), |
| 2888 | NEONMAP1(vqrshlb_s8, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2889 | NEONMAP1(vqrshlb_u8, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2890 | NEONMAP1(vqrshld_s64, aarch64_neon_sqrshl, Add1ArgType), |
| 2891 | NEONMAP1(vqrshld_u64, aarch64_neon_uqrshl, Add1ArgType), |
| 2892 | NEONMAP1(vqrshlh_s16, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2893 | NEONMAP1(vqrshlh_u16, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 2894 | NEONMAP1(vqrshls_s32, aarch64_neon_sqrshl, Add1ArgType), |
| 2895 | NEONMAP1(vqrshls_u32, aarch64_neon_uqrshl, Add1ArgType), |
| 2896 | NEONMAP1(vqrshrnd_n_s64, aarch64_neon_sqrshrn, AddRetType), |
| 2897 | NEONMAP1(vqrshrnd_n_u64, aarch64_neon_uqrshrn, AddRetType), |
| 2898 | NEONMAP1(vqrshrnh_n_s16, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 2899 | NEONMAP1(vqrshrnh_n_u16, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 2900 | NEONMAP1(vqrshrns_n_s32, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 2901 | NEONMAP1(vqrshrns_n_u32, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 2902 | NEONMAP1(vqrshrund_n_s64, aarch64_neon_sqrshrun, AddRetType), |
| 2903 | NEONMAP1(vqrshrunh_n_s16, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 2904 | NEONMAP1(vqrshruns_n_s32, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 2905 | NEONMAP1(vqshlb_n_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2906 | NEONMAP1(vqshlb_n_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2907 | NEONMAP1(vqshlb_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2908 | NEONMAP1(vqshlb_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2909 | NEONMAP1(vqshld_s64, aarch64_neon_sqshl, Add1ArgType), |
| 2910 | NEONMAP1(vqshld_u64, aarch64_neon_uqshl, Add1ArgType), |
| 2911 | NEONMAP1(vqshlh_n_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2912 | NEONMAP1(vqshlh_n_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2913 | NEONMAP1(vqshlh_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 2914 | NEONMAP1(vqshlh_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 2915 | NEONMAP1(vqshls_n_s32, aarch64_neon_sqshl, Add1ArgType), |
| 2916 | NEONMAP1(vqshls_n_u32, aarch64_neon_uqshl, Add1ArgType), |
| 2917 | NEONMAP1(vqshls_s32, aarch64_neon_sqshl, Add1ArgType), |
| 2918 | NEONMAP1(vqshls_u32, aarch64_neon_uqshl, Add1ArgType), |
| 2919 | NEONMAP1(vqshlub_n_s8, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 2920 | NEONMAP1(vqshluh_n_s16, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 2921 | NEONMAP1(vqshlus_n_s32, aarch64_neon_sqshlu, Add1ArgType), |
| 2922 | NEONMAP1(vqshrnd_n_s64, aarch64_neon_sqshrn, AddRetType), |
| 2923 | NEONMAP1(vqshrnd_n_u64, aarch64_neon_uqshrn, AddRetType), |
| 2924 | NEONMAP1(vqshrnh_n_s16, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 2925 | NEONMAP1(vqshrnh_n_u16, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 2926 | NEONMAP1(vqshrns_n_s32, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 2927 | NEONMAP1(vqshrns_n_u32, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 2928 | NEONMAP1(vqshrund_n_s64, aarch64_neon_sqshrun, AddRetType), |
| 2929 | NEONMAP1(vqshrunh_n_s16, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 2930 | NEONMAP1(vqshruns_n_s32, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 2931 | NEONMAP1(vqsubb_s8, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 2932 | NEONMAP1(vqsubb_u8, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 2933 | NEONMAP1(vqsubd_s64, aarch64_neon_sqsub, Add1ArgType), |
| 2934 | NEONMAP1(vqsubd_u64, aarch64_neon_uqsub, Add1ArgType), |
| 2935 | NEONMAP1(vqsubh_s16, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 2936 | NEONMAP1(vqsubh_u16, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 2937 | NEONMAP1(vqsubs_s32, aarch64_neon_sqsub, Add1ArgType), |
| 2938 | NEONMAP1(vqsubs_u32, aarch64_neon_uqsub, Add1ArgType), |
| 2939 | NEONMAP1(vrecped_f64, aarch64_neon_frecpe, Add1ArgType), |
| 2940 | NEONMAP1(vrecpes_f32, aarch64_neon_frecpe, Add1ArgType), |
| 2941 | NEONMAP1(vrecpxd_f64, aarch64_neon_frecpx, Add1ArgType), |
| 2942 | NEONMAP1(vrecpxs_f32, aarch64_neon_frecpx, Add1ArgType), |
| 2943 | NEONMAP1(vrshld_s64, aarch64_neon_srshl, Add1ArgType), |
| 2944 | NEONMAP1(vrshld_u64, aarch64_neon_urshl, Add1ArgType), |
| 2945 | NEONMAP1(vrsqrted_f64, aarch64_neon_frsqrte, Add1ArgType), |
| 2946 | NEONMAP1(vrsqrtes_f32, aarch64_neon_frsqrte, Add1ArgType), |
| 2947 | NEONMAP1(vrsqrtsd_f64, aarch64_neon_frsqrts, Add1ArgType), |
| 2948 | NEONMAP1(vrsqrtss_f32, aarch64_neon_frsqrts, Add1ArgType), |
| 2949 | NEONMAP1(vsha1cq_u32, aarch64_crypto_sha1c, 0), |
| 2950 | NEONMAP1(vsha1h_u32, aarch64_crypto_sha1h, 0), |
| 2951 | NEONMAP1(vsha1mq_u32, aarch64_crypto_sha1m, 0), |
| 2952 | NEONMAP1(vsha1pq_u32, aarch64_crypto_sha1p, 0), |
| 2953 | NEONMAP1(vshld_s64, aarch64_neon_sshl, Add1ArgType), |
| 2954 | NEONMAP1(vshld_u64, aarch64_neon_ushl, Add1ArgType), |
| 2955 | NEONMAP1(vslid_n_s64, aarch64_neon_vsli, Vectorize1ArgType), |
| 2956 | NEONMAP1(vslid_n_u64, aarch64_neon_vsli, Vectorize1ArgType), |
| 2957 | NEONMAP1(vsqaddb_u8, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 2958 | NEONMAP1(vsqaddd_u64, aarch64_neon_usqadd, Add1ArgType), |
| 2959 | NEONMAP1(vsqaddh_u16, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 2960 | NEONMAP1(vsqadds_u32, aarch64_neon_usqadd, Add1ArgType), |
| 2961 | NEONMAP1(vsrid_n_s64, aarch64_neon_vsri, Vectorize1ArgType), |
| 2962 | NEONMAP1(vsrid_n_u64, aarch64_neon_vsri, Vectorize1ArgType), |
| 2963 | NEONMAP1(vuqaddb_s8, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 2964 | NEONMAP1(vuqaddd_s64, aarch64_neon_suqadd, Add1ArgType), |
| 2965 | NEONMAP1(vuqaddh_s16, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 2966 | NEONMAP1(vuqadds_s32, aarch64_neon_suqadd, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2967 | }; |
| 2968 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2969 | #undef NEONMAP0 |
| 2970 | #undef NEONMAP1 |
| 2971 | #undef NEONMAP2 |
| 2972 | |
| 2973 | static bool NEONSIMDIntrinsicsProvenSorted = false; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2974 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2975 | static bool AArch64SIMDIntrinsicsProvenSorted = false; |
| 2976 | static bool AArch64SISDIntrinsicsProvenSorted = false; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2977 | |
| 2978 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2979 | static const NeonIntrinsicInfo * |
Craig Topper | 00bbdcf | 2014-06-28 23:22:23 +0000 | [diff] [blame] | 2980 | findNeonIntrinsicInMap(ArrayRef<NeonIntrinsicInfo> IntrinsicMap, |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2981 | unsigned BuiltinID, bool &MapProvenSorted) { |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2982 | |
| 2983 | #ifndef NDEBUG |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2984 | if (!MapProvenSorted) { |
Eric Christopher | ed60b43 | 2015-11-11 02:04:08 +0000 | [diff] [blame] | 2985 | assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap))); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2986 | MapProvenSorted = true; |
| 2987 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2988 | #endif |
| 2989 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2990 | const NeonIntrinsicInfo *Builtin = |
| 2991 | std::lower_bound(IntrinsicMap.begin(), IntrinsicMap.end(), BuiltinID); |
| 2992 | |
| 2993 | if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID) |
| 2994 | return Builtin; |
| 2995 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2996 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | Function *CodeGenFunction::LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
| 3000 | unsigned Modifier, |
| 3001 | llvm::Type *ArgType, |
| 3002 | const CallExpr *E) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3003 | int VectorSize = 0; |
| 3004 | if (Modifier & Use64BitVectors) |
| 3005 | VectorSize = 64; |
| 3006 | else if (Modifier & Use128BitVectors) |
| 3007 | VectorSize = 128; |
| 3008 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3009 | // Return type. |
| 3010 | SmallVector<llvm::Type *, 3> Tys; |
| 3011 | if (Modifier & AddRetType) { |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 3012 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3013 | if (Modifier & VectorizeRetType) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3014 | Ty = llvm::VectorType::get( |
| 3015 | Ty, VectorSize ? VectorSize / Ty->getPrimitiveSizeInBits() : 1); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3016 | |
| 3017 | Tys.push_back(Ty); |
| 3018 | } |
| 3019 | |
| 3020 | // Arguments. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3021 | if (Modifier & VectorizeArgTypes) { |
| 3022 | int Elts = VectorSize ? VectorSize / ArgType->getPrimitiveSizeInBits() : 1; |
| 3023 | ArgType = llvm::VectorType::get(ArgType, Elts); |
| 3024 | } |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3025 | |
| 3026 | if (Modifier & (Add1ArgType | Add2ArgTypes)) |
| 3027 | Tys.push_back(ArgType); |
| 3028 | |
| 3029 | if (Modifier & Add2ArgTypes) |
| 3030 | Tys.push_back(ArgType); |
| 3031 | |
| 3032 | if (Modifier & InventFloatType) |
| 3033 | Tys.push_back(FloatTy); |
| 3034 | |
| 3035 | return CGM.getIntrinsic(IntrinsicID, Tys); |
| 3036 | } |
| 3037 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3038 | static Value *EmitCommonNeonSISDBuiltinExpr(CodeGenFunction &CGF, |
| 3039 | const NeonIntrinsicInfo &SISDInfo, |
| 3040 | SmallVectorImpl<Value *> &Ops, |
| 3041 | const CallExpr *E) { |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 3042 | unsigned BuiltinID = SISDInfo.BuiltinID; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3043 | unsigned int Int = SISDInfo.LLVMIntrinsic; |
| 3044 | unsigned Modifier = SISDInfo.TypeModifier; |
| 3045 | const char *s = SISDInfo.NameHint; |
| 3046 | |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 3047 | switch (BuiltinID) { |
| 3048 | case NEON::BI__builtin_neon_vcled_s64: |
| 3049 | case NEON::BI__builtin_neon_vcled_u64: |
| 3050 | case NEON::BI__builtin_neon_vcles_f32: |
| 3051 | case NEON::BI__builtin_neon_vcled_f64: |
| 3052 | case NEON::BI__builtin_neon_vcltd_s64: |
| 3053 | case NEON::BI__builtin_neon_vcltd_u64: |
| 3054 | case NEON::BI__builtin_neon_vclts_f32: |
| 3055 | case NEON::BI__builtin_neon_vcltd_f64: |
| 3056 | case NEON::BI__builtin_neon_vcales_f32: |
| 3057 | case NEON::BI__builtin_neon_vcaled_f64: |
| 3058 | case NEON::BI__builtin_neon_vcalts_f32: |
| 3059 | case NEON::BI__builtin_neon_vcaltd_f64: |
| 3060 | // Only one direction of comparisons actually exist, cmle is actually a cmge |
| 3061 | // with swapped operands. The table gives us the right intrinsic but we |
| 3062 | // still need to do the swap. |
| 3063 | std::swap(Ops[0], Ops[1]); |
| 3064 | break; |
| 3065 | } |
| 3066 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3067 | assert(Int && "Generic code assumes a valid intrinsic"); |
| 3068 | |
| 3069 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 3070 | const Expr *Arg = E->getArg(0); |
| 3071 | llvm::Type *ArgTy = CGF.ConvertType(Arg->getType()); |
| 3072 | Function *F = CGF.LookupNeonLLVMIntrinsic(Int, Modifier, ArgTy, E); |
| 3073 | |
| 3074 | int j = 0; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 3075 | ConstantInt *C0 = ConstantInt::get(CGF.SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3076 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 3077 | ai != ae; ++ai, ++j) { |
| 3078 | llvm::Type *ArgTy = ai->getType(); |
| 3079 | if (Ops[j]->getType()->getPrimitiveSizeInBits() == |
| 3080 | ArgTy->getPrimitiveSizeInBits()) |
| 3081 | continue; |
| 3082 | |
| 3083 | assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy()); |
| 3084 | // The constant argument to an _n_ intrinsic always has Int32Ty, so truncate |
| 3085 | // it before inserting. |
| 3086 | Ops[j] = |
| 3087 | CGF.Builder.CreateTruncOrBitCast(Ops[j], ArgTy->getVectorElementType()); |
| 3088 | Ops[j] = |
| 3089 | CGF.Builder.CreateInsertElement(UndefValue::get(ArgTy), Ops[j], C0); |
| 3090 | } |
| 3091 | |
| 3092 | Value *Result = CGF.EmitNeonCall(F, Ops, s); |
| 3093 | llvm::Type *ResultType = CGF.ConvertType(E->getType()); |
| 3094 | if (ResultType->getPrimitiveSizeInBits() < |
| 3095 | Result->getType()->getPrimitiveSizeInBits()) |
| 3096 | return CGF.Builder.CreateExtractElement(Result, C0); |
| 3097 | |
| 3098 | return CGF.Builder.CreateBitCast(Result, ResultType, s); |
| 3099 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3100 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3101 | Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( |
| 3102 | unsigned BuiltinID, unsigned LLVMIntrinsic, unsigned AltLLVMIntrinsic, |
| 3103 | const char *NameHint, unsigned Modifier, const CallExpr *E, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3104 | SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1) { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3105 | // Get the last argument, which specifies the vector type. |
| 3106 | llvm::APSInt NeonTypeConst; |
| 3107 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 3108 | if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3109 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3110 | |
| 3111 | // Determine the type of this overloaded NEON intrinsic. |
| 3112 | NeonTypeFlags Type(NeonTypeConst.getZExtValue()); |
| 3113 | bool Usgn = Type.isUnsigned(); |
| 3114 | bool Quad = Type.isQuad(); |
| 3115 | |
| 3116 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 3117 | llvm::Type *Ty = VTy; |
| 3118 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3119 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3120 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3121 | auto getAlignmentValue32 = [&](Address addr) -> Value* { |
| 3122 | return Builder.getInt32(addr.getAlignment().getQuantity()); |
| 3123 | }; |
| 3124 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3125 | unsigned Int = LLVMIntrinsic; |
| 3126 | if ((Modifier & UnsignedAlts) && !Usgn) |
| 3127 | Int = AltLLVMIntrinsic; |
| 3128 | |
| 3129 | switch (BuiltinID) { |
| 3130 | default: break; |
| 3131 | case NEON::BI__builtin_neon_vabs_v: |
| 3132 | case NEON::BI__builtin_neon_vabsq_v: |
| 3133 | if (VTy->getElementType()->isFloatingPointTy()) |
| 3134 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::fabs, Ty), Ops, "vabs"); |
| 3135 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), Ops, "vabs"); |
| 3136 | case NEON::BI__builtin_neon_vaddhn_v: { |
| 3137 | llvm::VectorType *SrcTy = |
| 3138 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3139 | |
| 3140 | // %sum = add <4 x i32> %lhs, %rhs |
| 3141 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3142 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 3143 | Ops[0] = Builder.CreateAdd(Ops[0], Ops[1], "vaddhn"); |
| 3144 | |
| 3145 | // %high = lshr <4 x i32> %sum, <i32 16, i32 16, i32 16, i32 16> |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3146 | Constant *ShiftAmt = |
| 3147 | ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3148 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vaddhn"); |
| 3149 | |
| 3150 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 3151 | return Builder.CreateTrunc(Ops[0], VTy, "vaddhn"); |
| 3152 | } |
| 3153 | case NEON::BI__builtin_neon_vcale_v: |
| 3154 | case NEON::BI__builtin_neon_vcaleq_v: |
| 3155 | case NEON::BI__builtin_neon_vcalt_v: |
| 3156 | case NEON::BI__builtin_neon_vcaltq_v: |
| 3157 | std::swap(Ops[0], Ops[1]); |
| 3158 | case NEON::BI__builtin_neon_vcage_v: |
| 3159 | case NEON::BI__builtin_neon_vcageq_v: |
| 3160 | case NEON::BI__builtin_neon_vcagt_v: |
| 3161 | case NEON::BI__builtin_neon_vcagtq_v: { |
| 3162 | llvm::Type *VecFlt = llvm::VectorType::get( |
| 3163 | VTy->getScalarSizeInBits() == 32 ? FloatTy : DoubleTy, |
| 3164 | VTy->getNumElements()); |
| 3165 | llvm::Type *Tys[] = { VTy, VecFlt }; |
| 3166 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 3167 | return EmitNeonCall(F, Ops, NameHint); |
| 3168 | } |
| 3169 | case NEON::BI__builtin_neon_vclz_v: |
| 3170 | case NEON::BI__builtin_neon_vclzq_v: |
| 3171 | // We generate target-independent intrinsic, which needs a second argument |
| 3172 | // for whether or not clz of zero is undefined; on ARM it isn't. |
| 3173 | Ops.push_back(Builder.getInt1(getTarget().isCLZForZeroUndef())); |
| 3174 | break; |
| 3175 | case NEON::BI__builtin_neon_vcvt_f32_v: |
| 3176 | case NEON::BI__builtin_neon_vcvtq_f32_v: |
| 3177 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3178 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float32, false, Quad)); |
| 3179 | return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 3180 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 3181 | case NEON::BI__builtin_neon_vcvt_n_f32_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3182 | case NEON::BI__builtin_neon_vcvt_n_f64_v: |
| 3183 | case NEON::BI__builtin_neon_vcvtq_n_f32_v: |
| 3184 | case NEON::BI__builtin_neon_vcvtq_n_f64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3185 | llvm::Type *Tys[2] = { GetFloatNeonType(this, Type), Ty }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3186 | Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 3187 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 3188 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 3189 | } |
| 3190 | case NEON::BI__builtin_neon_vcvt_n_s32_v: |
| 3191 | case NEON::BI__builtin_neon_vcvt_n_u32_v: |
| 3192 | case NEON::BI__builtin_neon_vcvt_n_s64_v: |
| 3193 | case NEON::BI__builtin_neon_vcvt_n_u64_v: |
| 3194 | case NEON::BI__builtin_neon_vcvtq_n_s32_v: |
| 3195 | case NEON::BI__builtin_neon_vcvtq_n_u32_v: |
| 3196 | case NEON::BI__builtin_neon_vcvtq_n_s64_v: |
| 3197 | case NEON::BI__builtin_neon_vcvtq_n_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3198 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3199 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 3200 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 3201 | } |
| 3202 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 3203 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 3204 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 3205 | case NEON::BI__builtin_neon_vcvt_u64_v: |
| 3206 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 3207 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 3208 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
| 3209 | case NEON::BI__builtin_neon_vcvtq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3210 | Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3211 | return Usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt") |
| 3212 | : Builder.CreateFPToSI(Ops[0], Ty, "vcvt"); |
| 3213 | } |
| 3214 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 3215 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 3216 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 3217 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 3218 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 3219 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 3220 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 3221 | case NEON::BI__builtin_neon_vcvtaq_u64_v: |
| 3222 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 3223 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 3224 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 3225 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 3226 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 3227 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 3228 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 3229 | case NEON::BI__builtin_neon_vcvtnq_u64_v: |
| 3230 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 3231 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 3232 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 3233 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 3234 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 3235 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 3236 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 3237 | case NEON::BI__builtin_neon_vcvtpq_u64_v: |
| 3238 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 3239 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 3240 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 3241 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 3242 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 3243 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 3244 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 3245 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3246 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3247 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, NameHint); |
| 3248 | } |
| 3249 | case NEON::BI__builtin_neon_vext_v: |
| 3250 | case NEON::BI__builtin_neon_vextq_v: { |
| 3251 | int CV = cast<ConstantInt>(Ops[2])->getSExtValue(); |
| 3252 | SmallVector<Constant*, 16> Indices; |
| 3253 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
| 3254 | Indices.push_back(ConstantInt::get(Int32Ty, i+CV)); |
| 3255 | |
| 3256 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3257 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3258 | Value *SV = llvm::ConstantVector::get(Indices); |
| 3259 | return Builder.CreateShuffleVector(Ops[0], Ops[1], SV, "vext"); |
| 3260 | } |
| 3261 | case NEON::BI__builtin_neon_vfma_v: |
| 3262 | case NEON::BI__builtin_neon_vfmaq_v: { |
| 3263 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 3264 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3265 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3266 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 3267 | |
| 3268 | // NEON intrinsic puts accumulator first, unlike the LLVM fma. |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3269 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3270 | } |
| 3271 | case NEON::BI__builtin_neon_vld1_v: |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3272 | case NEON::BI__builtin_neon_vld1q_v: { |
| 3273 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3274 | Ops.push_back(getAlignmentValue32(PtrOp0)); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3275 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, "vld1"); |
| 3276 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3277 | case NEON::BI__builtin_neon_vld2_v: |
| 3278 | case NEON::BI__builtin_neon_vld2q_v: |
| 3279 | case NEON::BI__builtin_neon_vld3_v: |
| 3280 | case NEON::BI__builtin_neon_vld3q_v: |
| 3281 | case NEON::BI__builtin_neon_vld4_v: |
| 3282 | case NEON::BI__builtin_neon_vld4q_v: { |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3283 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 3284 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3285 | Value *Align = getAlignmentValue32(PtrOp1); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3286 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3287 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 3288 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3289 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3290 | } |
| 3291 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 3292 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 3293 | Value *V = UndefValue::get(Ty); |
| 3294 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3295 | PtrOp0 = Builder.CreateBitCast(PtrOp0, Ty); |
| 3296 | LoadInst *Ld = Builder.CreateLoad(PtrOp0); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 3297 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3298 | Ops[0] = Builder.CreateInsertElement(V, Ld, CI); |
| 3299 | return EmitNeonSplat(Ops[0], CI); |
| 3300 | } |
| 3301 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 3302 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 3303 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 3304 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 3305 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 3306 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3307 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 3308 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3309 | for (unsigned I = 2; I < Ops.size() - 1; ++I) |
| 3310 | Ops[I] = Builder.CreateBitCast(Ops[I], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3311 | Ops.push_back(getAlignmentValue32(PtrOp1)); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3312 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), NameHint); |
| 3313 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 3314 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3315 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3316 | } |
| 3317 | case NEON::BI__builtin_neon_vmovl_v: { |
| 3318 | llvm::Type *DTy =llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 3319 | Ops[0] = Builder.CreateBitCast(Ops[0], DTy); |
| 3320 | if (Usgn) |
| 3321 | return Builder.CreateZExt(Ops[0], Ty, "vmovl"); |
| 3322 | return Builder.CreateSExt(Ops[0], Ty, "vmovl"); |
| 3323 | } |
| 3324 | case NEON::BI__builtin_neon_vmovn_v: { |
| 3325 | llvm::Type *QTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3326 | Ops[0] = Builder.CreateBitCast(Ops[0], QTy); |
| 3327 | return Builder.CreateTrunc(Ops[0], Ty, "vmovn"); |
| 3328 | } |
| 3329 | case NEON::BI__builtin_neon_vmull_v: |
| 3330 | // FIXME: the integer vmull operations could be emitted in terms of pure |
| 3331 | // LLVM IR (2 exts followed by a mul). Unfortunately LLVM has a habit of |
| 3332 | // hoisting the exts outside loops. Until global ISel comes along that can |
| 3333 | // see through such movement this leads to bad CodeGen. So we need an |
| 3334 | // intrinsic for now. |
| 3335 | Int = Usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls; |
| 3336 | Int = Type.isPoly() ? (unsigned)Intrinsic::arm_neon_vmullp : Int; |
| 3337 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 3338 | case NEON::BI__builtin_neon_vpadal_v: |
| 3339 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 3340 | // The source operand type has twice as many elements of half the size. |
| 3341 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 3342 | llvm::Type *EltTy = |
| 3343 | llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 3344 | llvm::Type *NarrowTy = |
| 3345 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 3346 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 3347 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, NameHint); |
| 3348 | } |
| 3349 | case NEON::BI__builtin_neon_vpaddl_v: |
| 3350 | case NEON::BI__builtin_neon_vpaddlq_v: { |
| 3351 | // The source operand type has twice as many elements of half the size. |
| 3352 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 3353 | llvm::Type *EltTy = llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 3354 | llvm::Type *NarrowTy = |
| 3355 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 3356 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 3357 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vpaddl"); |
| 3358 | } |
| 3359 | case NEON::BI__builtin_neon_vqdmlal_v: |
| 3360 | case NEON::BI__builtin_neon_vqdmlsl_v: { |
| 3361 | SmallVector<Value *, 2> MulOps(Ops.begin() + 1, Ops.end()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3362 | Ops[1] = |
| 3363 | EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), MulOps, "vqdmlal"); |
| 3364 | Ops.resize(2); |
| 3365 | return EmitNeonCall(CGM.getIntrinsic(AltLLVMIntrinsic, Ty), Ops, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3366 | } |
| 3367 | case NEON::BI__builtin_neon_vqshl_n_v: |
| 3368 | case NEON::BI__builtin_neon_vqshlq_n_v: |
| 3369 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshl_n", |
| 3370 | 1, false); |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3371 | case NEON::BI__builtin_neon_vqshlu_n_v: |
| 3372 | case NEON::BI__builtin_neon_vqshluq_n_v: |
| 3373 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshlu_n", |
| 3374 | 1, false); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3375 | case NEON::BI__builtin_neon_vrecpe_v: |
| 3376 | case NEON::BI__builtin_neon_vrecpeq_v: |
| 3377 | case NEON::BI__builtin_neon_vrsqrte_v: |
| 3378 | case NEON::BI__builtin_neon_vrsqrteq_v: |
| 3379 | Int = Ty->isFPOrFPVectorTy() ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 3380 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, NameHint); |
| 3381 | |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3382 | case NEON::BI__builtin_neon_vrshr_n_v: |
| 3383 | case NEON::BI__builtin_neon_vrshrq_n_v: |
| 3384 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshr_n", |
| 3385 | 1, true); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3386 | case NEON::BI__builtin_neon_vshl_n_v: |
| 3387 | case NEON::BI__builtin_neon_vshlq_n_v: |
| 3388 | Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false); |
| 3389 | return Builder.CreateShl(Builder.CreateBitCast(Ops[0],Ty), Ops[1], |
| 3390 | "vshl_n"); |
| 3391 | case NEON::BI__builtin_neon_vshll_n_v: { |
| 3392 | llvm::Type *SrcTy = llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 3393 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3394 | if (Usgn) |
| 3395 | Ops[0] = Builder.CreateZExt(Ops[0], VTy); |
| 3396 | else |
| 3397 | Ops[0] = Builder.CreateSExt(Ops[0], VTy); |
| 3398 | Ops[1] = EmitNeonShiftVector(Ops[1], VTy, false); |
| 3399 | return Builder.CreateShl(Ops[0], Ops[1], "vshll_n"); |
| 3400 | } |
| 3401 | case NEON::BI__builtin_neon_vshrn_n_v: { |
| 3402 | llvm::Type *SrcTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3403 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3404 | Ops[1] = EmitNeonShiftVector(Ops[1], SrcTy, false); |
| 3405 | if (Usgn) |
| 3406 | Ops[0] = Builder.CreateLShr(Ops[0], Ops[1]); |
| 3407 | else |
| 3408 | Ops[0] = Builder.CreateAShr(Ops[0], Ops[1]); |
| 3409 | return Builder.CreateTrunc(Ops[0], Ty, "vshrn_n"); |
| 3410 | } |
| 3411 | case NEON::BI__builtin_neon_vshr_n_v: |
| 3412 | case NEON::BI__builtin_neon_vshrq_n_v: |
| 3413 | return EmitNeonRShiftImm(Ops[0], Ops[1], Ty, Usgn, "vshr_n"); |
| 3414 | case NEON::BI__builtin_neon_vst1_v: |
| 3415 | case NEON::BI__builtin_neon_vst1q_v: |
| 3416 | case NEON::BI__builtin_neon_vst2_v: |
| 3417 | case NEON::BI__builtin_neon_vst2q_v: |
| 3418 | case NEON::BI__builtin_neon_vst3_v: |
| 3419 | case NEON::BI__builtin_neon_vst3q_v: |
| 3420 | case NEON::BI__builtin_neon_vst4_v: |
| 3421 | case NEON::BI__builtin_neon_vst4q_v: |
| 3422 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 3423 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 3424 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 3425 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 3426 | case NEON::BI__builtin_neon_vst4_lane_v: |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3427 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 3428 | llvm::Type *Tys[] = {Int8PtrTy, Ty}; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3429 | Ops.push_back(getAlignmentValue32(PtrOp0)); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3430 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, ""); |
| 3431 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3432 | case NEON::BI__builtin_neon_vsubhn_v: { |
| 3433 | llvm::VectorType *SrcTy = |
| 3434 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3435 | |
| 3436 | // %sum = add <4 x i32> %lhs, %rhs |
| 3437 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3438 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 3439 | Ops[0] = Builder.CreateSub(Ops[0], Ops[1], "vsubhn"); |
| 3440 | |
| 3441 | // %high = lshr <4 x i32> %sum, <i32 16, i32 16, i32 16, i32 16> |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3442 | Constant *ShiftAmt = |
| 3443 | ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3444 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vsubhn"); |
| 3445 | |
| 3446 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 3447 | return Builder.CreateTrunc(Ops[0], VTy, "vsubhn"); |
| 3448 | } |
| 3449 | case NEON::BI__builtin_neon_vtrn_v: |
| 3450 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 3451 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3452 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3453 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3454 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3455 | |
| 3456 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 3457 | SmallVector<Constant*, 16> Indices; |
| 3458 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 3459 | Indices.push_back(Builder.getInt32(i+vi)); |
| 3460 | Indices.push_back(Builder.getInt32(i+e+vi)); |
| 3461 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3462 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3463 | SV = llvm::ConstantVector::get(Indices); |
| 3464 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vtrn"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3465 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3466 | } |
| 3467 | return SV; |
| 3468 | } |
| 3469 | case NEON::BI__builtin_neon_vtst_v: |
| 3470 | case NEON::BI__builtin_neon_vtstq_v: { |
| 3471 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3472 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3473 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 3474 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
| 3475 | ConstantAggregateZero::get(Ty)); |
| 3476 | return Builder.CreateSExt(Ops[0], Ty, "vtst"); |
| 3477 | } |
| 3478 | case NEON::BI__builtin_neon_vuzp_v: |
| 3479 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 3480 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3481 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3482 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3483 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3484 | |
| 3485 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 3486 | SmallVector<Constant*, 16> Indices; |
| 3487 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
| 3488 | Indices.push_back(ConstantInt::get(Int32Ty, 2*i+vi)); |
| 3489 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3490 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3491 | SV = llvm::ConstantVector::get(Indices); |
| 3492 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vuzp"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3493 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3494 | } |
| 3495 | return SV; |
| 3496 | } |
| 3497 | case NEON::BI__builtin_neon_vzip_v: |
| 3498 | case NEON::BI__builtin_neon_vzipq_v: { |
| 3499 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3500 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3501 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3502 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3503 | |
| 3504 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 3505 | SmallVector<Constant*, 16> Indices; |
| 3506 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 3507 | Indices.push_back(ConstantInt::get(Int32Ty, (i + vi*e) >> 1)); |
| 3508 | Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e)); |
| 3509 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3510 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3511 | SV = llvm::ConstantVector::get(Indices); |
| 3512 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3513 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3514 | } |
| 3515 | return SV; |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | assert(Int && "Expected valid intrinsic number"); |
| 3520 | |
| 3521 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 3522 | Function *F = LookupNeonLLVMIntrinsic(Int, Modifier, Ty, E); |
| 3523 | |
| 3524 | Value *Result = EmitNeonCall(F, Ops, NameHint); |
| 3525 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 3526 | // AArch64 intrinsic one-element vector type cast to |
| 3527 | // scalar type expected by the builtin |
| 3528 | return Builder.CreateBitCast(Result, ResultType, NameHint); |
| 3529 | } |
| 3530 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3531 | Value *CodeGenFunction::EmitAArch64CompareBuiltinExpr( |
| 3532 | Value *Op, llvm::Type *Ty, const CmpInst::Predicate Fp, |
| 3533 | const CmpInst::Predicate Ip, const Twine &Name) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3534 | llvm::Type *OTy = Op->getType(); |
| 3535 | |
| 3536 | // FIXME: this is utterly horrific. We should not be looking at previous |
| 3537 | // codegen context to find out what needs doing. Unfortunately TableGen |
| 3538 | // currently gives us exactly the same calls for vceqz_f32 and vceqz_s32 |
| 3539 | // (etc). |
| 3540 | if (BitCastInst *BI = dyn_cast<BitCastInst>(Op)) |
| 3541 | OTy = BI->getOperand(0)->getType(); |
| 3542 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3543 | Op = Builder.CreateBitCast(Op, OTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3544 | if (OTy->getScalarType()->isFloatingPointTy()) { |
| 3545 | Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3546 | } else { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3547 | Op = Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3548 | } |
Hao Liu | f96fd37 | 2013-12-23 02:44:00 +0000 | [diff] [blame] | 3549 | return Builder.CreateSExt(Op, Ty, Name); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3550 | } |
| 3551 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3552 | static Value *packTBLDVectorList(CodeGenFunction &CGF, ArrayRef<Value *> Ops, |
| 3553 | Value *ExtOp, Value *IndexOp, |
| 3554 | llvm::Type *ResTy, unsigned IntID, |
| 3555 | const char *Name) { |
| 3556 | SmallVector<Value *, 2> TblOps; |
| 3557 | if (ExtOp) |
| 3558 | TblOps.push_back(ExtOp); |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3559 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3560 | // Build a vector containing sequential number like (0, 1, 2, ..., 15) |
| 3561 | SmallVector<Constant*, 16> Indices; |
| 3562 | llvm::VectorType *TblTy = cast<llvm::VectorType>(Ops[0]->getType()); |
| 3563 | for (unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) { |
| 3564 | Indices.push_back(ConstantInt::get(CGF.Int32Ty, 2*i)); |
| 3565 | Indices.push_back(ConstantInt::get(CGF.Int32Ty, 2*i+1)); |
| 3566 | } |
| 3567 | Value *SV = llvm::ConstantVector::get(Indices); |
| 3568 | |
| 3569 | int PairPos = 0, End = Ops.size() - 1; |
| 3570 | while (PairPos < End) { |
| 3571 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
| 3572 | Ops[PairPos+1], SV, Name)); |
| 3573 | PairPos += 2; |
| 3574 | } |
| 3575 | |
| 3576 | // If there's an odd number of 64-bit lookup table, fill the high 64-bit |
| 3577 | // of the 128-bit lookup table with zero. |
| 3578 | if (PairPos == End) { |
| 3579 | Value *ZeroTbl = ConstantAggregateZero::get(TblTy); |
| 3580 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
| 3581 | ZeroTbl, SV, Name)); |
| 3582 | } |
| 3583 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3584 | Function *TblF; |
| 3585 | TblOps.push_back(IndexOp); |
Tim Northover | b44e080 | 2014-02-26 11:55:15 +0000 | [diff] [blame] | 3586 | TblF = CGF.CGM.getIntrinsic(IntID, ResTy); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3587 | |
| 3588 | return CGF.EmitNeonCall(TblF, TblOps, Name); |
| 3589 | } |
| 3590 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3591 | Value *CodeGenFunction::GetValueForARMHint(unsigned BuiltinID) { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3592 | unsigned Value; |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3593 | switch (BuiltinID) { |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3594 | default: |
| 3595 | return nullptr; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 3596 | case ARM::BI__builtin_arm_nop: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3597 | Value = 0; |
| 3598 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3599 | case ARM::BI__builtin_arm_yield: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3600 | case ARM::BI__yield: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3601 | Value = 1; |
| 3602 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3603 | case ARM::BI__builtin_arm_wfe: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3604 | case ARM::BI__wfe: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3605 | Value = 2; |
| 3606 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3607 | case ARM::BI__builtin_arm_wfi: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3608 | case ARM::BI__wfi: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3609 | Value = 3; |
| 3610 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3611 | case ARM::BI__builtin_arm_sev: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3612 | case ARM::BI__sev: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3613 | Value = 4; |
| 3614 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3615 | case ARM::BI__builtin_arm_sevl: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3616 | case ARM::BI__sevl: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3617 | Value = 5; |
| 3618 | break; |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 3619 | } |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3620 | |
| 3621 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3622 | llvm::ConstantInt::get(Int32Ty, Value)); |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3623 | } |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 3624 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 3625 | // Generates the IR for the read/write special register builtin, |
| 3626 | // ValueType is the type of the value that is to be written or read, |
| 3627 | // RegisterType is the type of the register being written to or read from. |
| 3628 | static Value *EmitSpecialRegisterBuiltin(CodeGenFunction &CGF, |
| 3629 | const CallExpr *E, |
| 3630 | llvm::Type *RegisterType, |
| 3631 | llvm::Type *ValueType, bool IsRead) { |
| 3632 | // write and register intrinsics only support 32 and 64 bit operations. |
| 3633 | assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64)) |
| 3634 | && "Unsupported size for register."); |
| 3635 | |
| 3636 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 3637 | CodeGen::CodeGenModule &CGM = CGF.CGM; |
| 3638 | LLVMContext &Context = CGM.getLLVMContext(); |
| 3639 | |
| 3640 | const Expr *SysRegStrExpr = E->getArg(0)->IgnoreParenCasts(); |
| 3641 | StringRef SysReg = cast<StringLiteral>(SysRegStrExpr)->getString(); |
| 3642 | |
| 3643 | llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) }; |
| 3644 | llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops); |
| 3645 | llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName); |
| 3646 | |
| 3647 | llvm::Type *Types[] = { RegisterType }; |
| 3648 | |
| 3649 | bool MixedTypes = RegisterType->isIntegerTy(64) && ValueType->isIntegerTy(32); |
| 3650 | assert(!(RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64)) |
| 3651 | && "Can't fit 64-bit value in 32-bit register"); |
| 3652 | |
| 3653 | if (IsRead) { |
| 3654 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types); |
| 3655 | llvm::Value *Call = Builder.CreateCall(F, Metadata); |
| 3656 | |
| 3657 | if (MixedTypes) |
| 3658 | // Read into 64 bit register and then truncate result to 32 bit. |
| 3659 | return Builder.CreateTrunc(Call, ValueType); |
| 3660 | |
| 3661 | if (ValueType->isPointerTy()) |
| 3662 | // Have i32/i64 result (Call) but want to return a VoidPtrTy (i8*). |
| 3663 | return Builder.CreateIntToPtr(Call, ValueType); |
| 3664 | |
| 3665 | return Call; |
| 3666 | } |
| 3667 | |
| 3668 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types); |
| 3669 | llvm::Value *ArgValue = CGF.EmitScalarExpr(E->getArg(1)); |
| 3670 | if (MixedTypes) { |
| 3671 | // Extend 32 bit write value to 64 bit to pass to write. |
| 3672 | ArgValue = Builder.CreateZExt(ArgValue, RegisterType); |
| 3673 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 3674 | } |
| 3675 | |
| 3676 | if (ValueType->isPointerTy()) { |
| 3677 | // Have VoidPtrTy ArgValue but want to return an i32/i64. |
| 3678 | ArgValue = Builder.CreatePtrToInt(ArgValue, RegisterType); |
| 3679 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 3680 | } |
| 3681 | |
| 3682 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 3683 | } |
| 3684 | |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3685 | /// Return true if BuiltinID is an overloaded Neon intrinsic with an extra |
| 3686 | /// argument that specifies the vector type. |
| 3687 | static bool HasExtraNeonArgument(unsigned BuiltinID) { |
| 3688 | switch (BuiltinID) { |
| 3689 | default: break; |
| 3690 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 3691 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 3692 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 3693 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 3694 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 3695 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 3696 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 3697 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 3698 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 3699 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 3700 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 3701 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 3702 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 3703 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 3704 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 3705 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 3706 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 3707 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 3708 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 3709 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 3710 | case NEON::BI__builtin_neon_vsha1h_u32: |
| 3711 | case NEON::BI__builtin_neon_vsha1cq_u32: |
| 3712 | case NEON::BI__builtin_neon_vsha1pq_u32: |
| 3713 | case NEON::BI__builtin_neon_vsha1mq_u32: |
| 3714 | case ARM::BI_MoveToCoprocessor: |
| 3715 | case ARM::BI_MoveToCoprocessor2: |
| 3716 | return false; |
| 3717 | } |
| 3718 | return true; |
| 3719 | } |
| 3720 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3721 | Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
| 3722 | const CallExpr *E) { |
| 3723 | if (auto Hint = GetValueForARMHint(BuiltinID)) |
| 3724 | return Hint; |
Saleem Abdulrasool | 38ed6de | 2014-05-02 06:53:57 +0000 | [diff] [blame] | 3725 | |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 3726 | if (BuiltinID == ARM::BI__emit) { |
| 3727 | bool IsThumb = getTarget().getTriple().getArch() == llvm::Triple::thumb; |
| 3728 | llvm::FunctionType *FTy = |
| 3729 | llvm::FunctionType::get(VoidTy, /*Variadic=*/false); |
| 3730 | |
| 3731 | APSInt Value; |
| 3732 | if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext())) |
| 3733 | llvm_unreachable("Sema will ensure that the parameter is constant"); |
| 3734 | |
| 3735 | uint64_t ZExtValue = Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue(); |
| 3736 | |
| 3737 | llvm::InlineAsm *Emit = |
| 3738 | IsThumb ? InlineAsm::get(FTy, ".inst.n 0x" + utohexstr(ZExtValue), "", |
| 3739 | /*SideEffects=*/true) |
| 3740 | : InlineAsm::get(FTy, ".inst 0x" + utohexstr(ZExtValue), "", |
| 3741 | /*SideEffects=*/true); |
| 3742 | |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 3743 | return Builder.CreateCall(Emit); |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Yi Kong | 1d268af | 2014-08-26 12:48:06 +0000 | [diff] [blame] | 3746 | if (BuiltinID == ARM::BI__builtin_arm_dbg) { |
| 3747 | Value *Option = EmitScalarExpr(E->getArg(0)); |
| 3748 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_dbg), Option); |
| 3749 | } |
| 3750 | |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 3751 | if (BuiltinID == ARM::BI__builtin_arm_prefetch) { |
| 3752 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 3753 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 3754 | Value *IsData = EmitScalarExpr(E->getArg(2)); |
| 3755 | |
| 3756 | // Locality is not supported on ARM target |
| 3757 | Value *Locality = llvm::ConstantInt::get(Int32Ty, 3); |
| 3758 | |
| 3759 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3760 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
Jim Grosbach | 171ec34 | 2014-06-16 21:55:58 +0000 | [diff] [blame] | 3763 | if (BuiltinID == ARM::BI__builtin_arm_rbit) { |
| 3764 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_rbit), |
| 3765 | EmitScalarExpr(E->getArg(0)), |
| 3766 | "rbit"); |
| 3767 | } |
| 3768 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3769 | if (BuiltinID == ARM::BI__clear_cache) { |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 3770 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
Rafael Espindola | a54062e | 2010-06-07 17:26:50 +0000 | [diff] [blame] | 3771 | const FunctionDecl *FD = E->getDirectCallee(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3772 | Value *Ops[2]; |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 3773 | for (unsigned i = 0; i < 2; i++) |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3774 | Ops[i] = EmitScalarExpr(E->getArg(i)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 3775 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 3776 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3777 | StringRef Name = FD->getName(); |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 3778 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3779 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 3780 | |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3781 | if (BuiltinID == ARM::BI__builtin_arm_ldrexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3782 | ((BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 3783 | BuiltinID == ARM::BI__builtin_arm_ldaex) && |
Saleem Abdulrasool | e700cab | 2014-07-05 20:10:05 +0000 | [diff] [blame] | 3784 | getContext().getTypeSize(E->getType()) == 64) || |
| 3785 | BuiltinID == ARM::BI__ldrexd) { |
| 3786 | Function *F; |
| 3787 | |
| 3788 | switch (BuiltinID) { |
| 3789 | default: llvm_unreachable("unexpected builtin"); |
| 3790 | case ARM::BI__builtin_arm_ldaex: |
| 3791 | F = CGM.getIntrinsic(Intrinsic::arm_ldaexd); |
| 3792 | break; |
| 3793 | case ARM::BI__builtin_arm_ldrexd: |
| 3794 | case ARM::BI__builtin_arm_ldrex: |
| 3795 | case ARM::BI__ldrexd: |
| 3796 | F = CGM.getIntrinsic(Intrinsic::arm_ldrexd); |
| 3797 | break; |
| 3798 | } |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3799 | |
| 3800 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3801 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 3802 | "ldrexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3803 | |
| 3804 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 3805 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 3806 | Val0 = Builder.CreateZExt(Val0, Int64Ty); |
| 3807 | Val1 = Builder.CreateZExt(Val1, Int64Ty); |
| 3808 | |
| 3809 | Value *ShiftCst = llvm::ConstantInt::get(Int64Ty, 32); |
| 3810 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3811 | Val = Builder.CreateOr(Val, Val1); |
| 3812 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3813 | } |
| 3814 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3815 | if (BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 3816 | BuiltinID == ARM::BI__builtin_arm_ldaex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3817 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 3818 | |
| 3819 | QualType Ty = E->getType(); |
| 3820 | llvm::Type *RealResTy = ConvertType(Ty); |
| 3821 | llvm::Type *IntResTy = llvm::IntegerType::get(getLLVMContext(), |
| 3822 | getContext().getTypeSize(Ty)); |
| 3823 | LoadAddr = Builder.CreateBitCast(LoadAddr, IntResTy->getPointerTo()); |
| 3824 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3825 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_ldaex |
| 3826 | ? Intrinsic::arm_ldaex |
| 3827 | : Intrinsic::arm_ldrex, |
| 3828 | LoadAddr->getType()); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3829 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldrex"); |
| 3830 | |
| 3831 | if (RealResTy->isPointerTy()) |
| 3832 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 3833 | else { |
| 3834 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 3835 | return Builder.CreateBitCast(Val, RealResTy); |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | if (BuiltinID == ARM::BI__builtin_arm_strexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3840 | ((BuiltinID == ARM::BI__builtin_arm_stlex || |
| 3841 | BuiltinID == ARM::BI__builtin_arm_strex) && |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3842 | getContext().getTypeSize(E->getArg(0)->getType()) == 64)) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3843 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 3844 | ? Intrinsic::arm_stlexd |
| 3845 | : Intrinsic::arm_strexd); |
Reid Kleckner | ee7cf84 | 2014-12-01 22:02:27 +0000 | [diff] [blame] | 3846 | llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty, nullptr); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3847 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3848 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3849 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 3850 | Builder.CreateStore(Val, Tmp); |
| 3851 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3852 | Address LdPtr = Builder.CreateBitCast(Tmp,llvm::PointerType::getUnqual(STy)); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3853 | Val = Builder.CreateLoad(LdPtr); |
| 3854 | |
| 3855 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 3856 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3857 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3858 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "strexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 3859 | } |
| 3860 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3861 | if (BuiltinID == ARM::BI__builtin_arm_strex || |
| 3862 | BuiltinID == ARM::BI__builtin_arm_stlex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3863 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 3864 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 3865 | |
| 3866 | QualType Ty = E->getArg(0)->getType(); |
| 3867 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 3868 | getContext().getTypeSize(Ty)); |
| 3869 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 3870 | |
| 3871 | if (StoreVal->getType()->isPointerTy()) |
| 3872 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int32Ty); |
| 3873 | else { |
| 3874 | StoreVal = Builder.CreateBitCast(StoreVal, StoreTy); |
| 3875 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int32Ty); |
| 3876 | } |
| 3877 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 3878 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 3879 | ? Intrinsic::arm_stlex |
| 3880 | : Intrinsic::arm_strex, |
| 3881 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3882 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "strex"); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | if (BuiltinID == ARM::BI__builtin_arm_clrex) { |
| 3886 | Function *F = CGM.getIntrinsic(Intrinsic::arm_clrex); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 3887 | return Builder.CreateCall(F); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 3890 | // CRC32 |
| 3891 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 3892 | switch (BuiltinID) { |
| 3893 | case ARM::BI__builtin_arm_crc32b: |
| 3894 | CRCIntrinsicID = Intrinsic::arm_crc32b; break; |
| 3895 | case ARM::BI__builtin_arm_crc32cb: |
| 3896 | CRCIntrinsicID = Intrinsic::arm_crc32cb; break; |
| 3897 | case ARM::BI__builtin_arm_crc32h: |
| 3898 | CRCIntrinsicID = Intrinsic::arm_crc32h; break; |
| 3899 | case ARM::BI__builtin_arm_crc32ch: |
| 3900 | CRCIntrinsicID = Intrinsic::arm_crc32ch; break; |
| 3901 | case ARM::BI__builtin_arm_crc32w: |
| 3902 | case ARM::BI__builtin_arm_crc32d: |
| 3903 | CRCIntrinsicID = Intrinsic::arm_crc32w; break; |
| 3904 | case ARM::BI__builtin_arm_crc32cw: |
| 3905 | case ARM::BI__builtin_arm_crc32cd: |
| 3906 | CRCIntrinsicID = Intrinsic::arm_crc32cw; break; |
| 3907 | } |
| 3908 | |
| 3909 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 3910 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 3911 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 3912 | |
| 3913 | // crc32{c,}d intrinsics are implemnted as two calls to crc32{c,}w |
| 3914 | // intrinsics, hence we need different codegen for these cases. |
| 3915 | if (BuiltinID == ARM::BI__builtin_arm_crc32d || |
| 3916 | BuiltinID == ARM::BI__builtin_arm_crc32cd) { |
| 3917 | Value *C1 = llvm::ConstantInt::get(Int64Ty, 32); |
| 3918 | Value *Arg1a = Builder.CreateTruncOrBitCast(Arg1, Int32Ty); |
| 3919 | Value *Arg1b = Builder.CreateLShr(Arg1, C1); |
| 3920 | Arg1b = Builder.CreateTruncOrBitCast(Arg1b, Int32Ty); |
| 3921 | |
| 3922 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3923 | Value *Res = Builder.CreateCall(F, {Arg0, Arg1a}); |
| 3924 | return Builder.CreateCall(F, {Res, Arg1b}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 3925 | } else { |
| 3926 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, Int32Ty); |
| 3927 | |
| 3928 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3929 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 3930 | } |
| 3931 | } |
| 3932 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 3933 | if (BuiltinID == ARM::BI__builtin_arm_rsr || |
| 3934 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 3935 | BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 3936 | BuiltinID == ARM::BI__builtin_arm_wsr || |
| 3937 | BuiltinID == ARM::BI__builtin_arm_wsr64 || |
| 3938 | BuiltinID == ARM::BI__builtin_arm_wsrp) { |
| 3939 | |
| 3940 | bool IsRead = BuiltinID == ARM::BI__builtin_arm_rsr || |
| 3941 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 3942 | BuiltinID == ARM::BI__builtin_arm_rsrp; |
| 3943 | |
| 3944 | bool IsPointerBuiltin = BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 3945 | BuiltinID == ARM::BI__builtin_arm_wsrp; |
| 3946 | |
| 3947 | bool Is64Bit = BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 3948 | BuiltinID == ARM::BI__builtin_arm_wsr64; |
| 3949 | |
| 3950 | llvm::Type *ValueType; |
| 3951 | llvm::Type *RegisterType; |
| 3952 | if (IsPointerBuiltin) { |
| 3953 | ValueType = VoidPtrTy; |
| 3954 | RegisterType = Int32Ty; |
| 3955 | } else if (Is64Bit) { |
| 3956 | ValueType = RegisterType = Int64Ty; |
| 3957 | } else { |
| 3958 | ValueType = RegisterType = Int32Ty; |
| 3959 | } |
| 3960 | |
| 3961 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 3962 | } |
| 3963 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 3964 | // Find out if any arguments are required to be integer constant |
| 3965 | // expressions. |
| 3966 | unsigned ICEArguments = 0; |
| 3967 | ASTContext::GetBuiltinTypeError Error; |
| 3968 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 3969 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 3970 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3971 | auto getAlignmentValue32 = [&](Address addr) -> Value* { |
| 3972 | return Builder.getInt32(addr.getAlignment().getQuantity()); |
| 3973 | }; |
| 3974 | |
| 3975 | Address PtrOp0 = Address::invalid(); |
| 3976 | Address PtrOp1 = Address::invalid(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3977 | SmallVector<Value*, 4> Ops; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 3978 | bool HasExtraArg = HasExtraNeonArgument(BuiltinID); |
| 3979 | unsigned NumArgs = E->getNumArgs() - (HasExtraArg ? 1 : 0); |
| 3980 | for (unsigned i = 0, e = NumArgs; i != e; i++) { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 3981 | if (i == 0) { |
| 3982 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 3983 | case NEON::BI__builtin_neon_vld1_v: |
| 3984 | case NEON::BI__builtin_neon_vld1q_v: |
| 3985 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 3986 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 3987 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 3988 | case NEON::BI__builtin_neon_vld1q_dup_v: |
| 3989 | case NEON::BI__builtin_neon_vst1_v: |
| 3990 | case NEON::BI__builtin_neon_vst1q_v: |
| 3991 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 3992 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 3993 | case NEON::BI__builtin_neon_vst2_v: |
| 3994 | case NEON::BI__builtin_neon_vst2q_v: |
| 3995 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 3996 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 3997 | case NEON::BI__builtin_neon_vst3_v: |
| 3998 | case NEON::BI__builtin_neon_vst3q_v: |
| 3999 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 4000 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 4001 | case NEON::BI__builtin_neon_vst4_v: |
| 4002 | case NEON::BI__builtin_neon_vst4q_v: |
| 4003 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 4004 | case NEON::BI__builtin_neon_vst4q_lane_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4005 | // Get the alignment for the argument in addition to the value; |
| 4006 | // we'll use it later. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4007 | PtrOp0 = EmitPointerWithAlignment(E->getArg(0)); |
| 4008 | Ops.push_back(PtrOp0.getPointer()); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4009 | continue; |
| 4010 | } |
| 4011 | } |
| 4012 | if (i == 1) { |
| 4013 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4014 | case NEON::BI__builtin_neon_vld2_v: |
| 4015 | case NEON::BI__builtin_neon_vld2q_v: |
| 4016 | case NEON::BI__builtin_neon_vld3_v: |
| 4017 | case NEON::BI__builtin_neon_vld3q_v: |
| 4018 | case NEON::BI__builtin_neon_vld4_v: |
| 4019 | case NEON::BI__builtin_neon_vld4q_v: |
| 4020 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 4021 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 4022 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 4023 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 4024 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 4025 | case NEON::BI__builtin_neon_vld4q_lane_v: |
| 4026 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 4027 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 4028 | case NEON::BI__builtin_neon_vld4_dup_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4029 | // Get the alignment for the argument in addition to the value; |
| 4030 | // we'll use it later. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4031 | PtrOp1 = EmitPointerWithAlignment(E->getArg(1)); |
| 4032 | Ops.push_back(PtrOp1.getPointer()); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4033 | continue; |
| 4034 | } |
| 4035 | } |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4036 | |
| 4037 | if ((ICEArguments & (1 << i)) == 0) { |
| 4038 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 4039 | } else { |
| 4040 | // If this is required to be a constant, constant fold it so that we know |
| 4041 | // that the generated intrinsic gets a ConstantInt. |
| 4042 | llvm::APSInt Result; |
| 4043 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 4044 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
| 4045 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 4046 | } |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4047 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4048 | |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 4049 | switch (BuiltinID) { |
| 4050 | default: break; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4051 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4052 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 4053 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 4054 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 4055 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 4056 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 4057 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 4058 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 4059 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 4060 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 4061 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4062 | return Builder.CreateExtractElement(Ops[0], Ops[1], "vget_lane"); |
| 4063 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4064 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 4065 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 4066 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 4067 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 4068 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 4069 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 4070 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 4071 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 4072 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 4073 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 4074 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4075 | |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4076 | case NEON::BI__builtin_neon_vsha1h_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4077 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1h), Ops, |
| 4078 | "vsha1h"); |
| 4079 | case NEON::BI__builtin_neon_vsha1cq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4080 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1c), Ops, |
| 4081 | "vsha1h"); |
| 4082 | case NEON::BI__builtin_neon_vsha1pq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4083 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1p), Ops, |
| 4084 | "vsha1h"); |
| 4085 | case NEON::BI__builtin_neon_vsha1mq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4086 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1m), Ops, |
| 4087 | "vsha1h"); |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4088 | |
| 4089 | // The ARM _MoveToCoprocessor builtins put the input register value as |
| 4090 | // the first argument, but the LLVM intrinsic expects it as the third one. |
| 4091 | case ARM::BI_MoveToCoprocessor: |
| 4092 | case ARM::BI_MoveToCoprocessor2: { |
| 4093 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI_MoveToCoprocessor ? |
| 4094 | Intrinsic::arm_mcr : Intrinsic::arm_mcr2); |
| 4095 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0], |
| 4096 | Ops[3], Ops[4], Ops[5]}); |
| 4097 | } |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | // Get the last argument, which specifies the vector type. |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4101 | assert(HasExtraArg); |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4102 | llvm::APSInt Result; |
| 4103 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 4104 | if (!Arg->isIntegerConstantExpr(Result, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4105 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4106 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4107 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f || |
| 4108 | BuiltinID == ARM::BI__builtin_arm_vcvtr_d) { |
| 4109 | // Determine the overloaded type of this builtin. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 4110 | llvm::Type *Ty; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4111 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 4112 | Ty = FloatTy; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4113 | else |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 4114 | Ty = DoubleTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4115 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4116 | // Determine whether this is an unsigned conversion or not. |
| 4117 | bool usgn = Result.getZExtValue() == 1; |
| 4118 | unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr; |
| 4119 | |
| 4120 | // Call the appropriate intrinsic. |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4121 | Function *F = CGM.getIntrinsic(Int, Ty); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 4122 | return Builder.CreateCall(F, Ops, "vcvtr"); |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4123 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4124 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4125 | // Determine the type of this overloaded NEON intrinsic. |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 4126 | NeonTypeFlags Type(Result.getZExtValue()); |
| 4127 | bool usgn = Type.isUnsigned(); |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 4128 | bool rightShift = false; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4129 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 4130 | llvm::VectorType *VTy = GetNeonType(this, Type); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 4131 | llvm::Type *Ty = VTy; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4132 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4133 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4134 | |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 4135 | // Many NEON builtins have identical semantics and uses in ARM and |
| 4136 | // AArch64. Emit these in a single function. |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 4137 | auto IntrinsicMap = makeArrayRef(ARMSIMDIntrinsicMap); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4138 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
| 4139 | IntrinsicMap, BuiltinID, NEONSIMDIntrinsicsProvenSorted); |
| 4140 | if (Builtin) |
| 4141 | return EmitCommonNeonBuiltinExpr( |
| 4142 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4143 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, PtrOp0, PtrOp1); |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 4144 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4145 | unsigned Int; |
| 4146 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4147 | default: return nullptr; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4148 | case NEON::BI__builtin_neon_vld1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4149 | // Handle 64-bit integer elements as a special case. Use shuffles of |
| 4150 | // one-element vectors to avoid poor code for i64 in the backend. |
| 4151 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 4152 | // Extract the other lane. |
| 4153 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4154 | uint32_t Lane = cast<ConstantInt>(Ops[2])->getZExtValue(); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4155 | Value *SV = llvm::ConstantVector::get(ConstantInt::get(Int32Ty, 1-Lane)); |
| 4156 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
| 4157 | // Load the value as a one-element vector. |
| 4158 | Ty = llvm::VectorType::get(VTy->getElementType(), 1); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4159 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4160 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4161 | Value *Align = getAlignmentValue32(PtrOp0); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4162 | Value *Ld = Builder.CreateCall(F, {Ops[0], Align}); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4163 | // Combine them. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4164 | uint32_t Indices[] = {1 - Lane, Lane}; |
| 4165 | SV = llvm::ConstantDataVector::get(getLLVMContext(), Indices); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4166 | return Builder.CreateShuffleVector(Ops[1], Ld, SV, "vld1q_lane"); |
| 4167 | } |
| 4168 | // fall through |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4169 | case NEON::BI__builtin_neon_vld1_lane_v: { |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4170 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Steven Wu | 0d22f2d | 2015-09-09 01:37:18 +0000 | [diff] [blame] | 4171 | PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4172 | Value *Ld = Builder.CreateLoad(PtrOp0); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 4173 | return Builder.CreateInsertElement(Ops[1], Ld, Ops[2], "vld1_lane"); |
| 4174 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4175 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 4176 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 4177 | case NEON::BI__builtin_neon_vld4_dup_v: { |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4178 | // Handle 64-bit elements as a special-case. There is no "dup" needed. |
| 4179 | if (VTy->getElementType()->getPrimitiveSizeInBits() == 64) { |
| 4180 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4181 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4182 | Int = Intrinsic::arm_neon_vld2; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4183 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4184 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4185 | Int = Intrinsic::arm_neon_vld3; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4186 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4187 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4188 | Int = Intrinsic::arm_neon_vld4; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4189 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 4190 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4191 | } |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4192 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4193 | Function *F = CGM.getIntrinsic(Int, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4194 | llvm::Value *Align = getAlignmentValue32(PtrOp1); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4195 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, "vld_dup"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4196 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 4197 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4198 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4199 | } |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4200 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4201 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4202 | Int = Intrinsic::arm_neon_vld2lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4203 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4204 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4205 | Int = Intrinsic::arm_neon_vld3lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4206 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4207 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4208 | Int = Intrinsic::arm_neon_vld4lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4209 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 4210 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4211 | } |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4212 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4213 | Function *F = CGM.getIntrinsic(Int, Tys); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 4214 | llvm::StructType *STy = cast<llvm::StructType>(F->getReturnType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4215 | |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4216 | SmallVector<Value*, 6> Args; |
| 4217 | Args.push_back(Ops[1]); |
| 4218 | Args.append(STy->getNumElements(), UndefValue::get(Ty)); |
| 4219 | |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 4220 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4221 | Args.push_back(CI); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4222 | Args.push_back(getAlignmentValue32(PtrOp1)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4223 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 4224 | Ops[1] = Builder.CreateCall(F, Args, "vld_dup"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4225 | // splat lane 0 to all elts in each vector of the result. |
| 4226 | for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { |
| 4227 | Value *Val = Builder.CreateExtractValue(Ops[1], i); |
| 4228 | Value *Elt = Builder.CreateBitCast(Val, Ty); |
| 4229 | Elt = EmitNeonSplat(Elt, CI); |
| 4230 | Elt = Builder.CreateBitCast(Elt, Val->getType()); |
| 4231 | Ops[1] = Builder.CreateInsertValue(Ops[1], Elt, i); |
| 4232 | } |
| 4233 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 4234 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4235 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4236 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4237 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4238 | Int = |
| 4239 | usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4240 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 4241 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4242 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4243 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 4244 | Ops, "vqrshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4245 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 4246 | Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4247 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 4248 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4249 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4250 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 4251 | Ops, "vqshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4252 | case NEON::BI__builtin_neon_vrecpe_v: |
| 4253 | case NEON::BI__builtin_neon_vrecpeq_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4254 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecpe, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4255 | Ops, "vrecpe"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4256 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4257 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrshiftn, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 4258 | Ops, "vrshrn_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4259 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 4260 | case NEON::BI__builtin_neon_vrsraq_n_v: |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 4261 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4262 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4263 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, true); |
| 4264 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4265 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Ty), {Ops[1], Ops[2]}); |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 4266 | return Builder.CreateAdd(Ops[0], Ops[1], "vrsra_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4267 | case NEON::BI__builtin_neon_vsri_n_v: |
| 4268 | case NEON::BI__builtin_neon_vsriq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 4269 | rightShift = true; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4270 | case NEON::BI__builtin_neon_vsli_n_v: |
| 4271 | case NEON::BI__builtin_neon_vsliq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 4272 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, rightShift); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4273 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftins, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4274 | Ops, "vsli_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4275 | case NEON::BI__builtin_neon_vsra_n_v: |
| 4276 | case NEON::BI__builtin_neon_vsraq_n_v: |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4277 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 4278 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4279 | return Builder.CreateAdd(Ops[0], Ops[1]); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4280 | case NEON::BI__builtin_neon_vst1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4281 | // Handle 64-bit integer elements as a special case. Use a shuffle to get |
| 4282 | // a one-element vector and avoid poor code for i64 in the backend. |
| 4283 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 4284 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4285 | Value *SV = llvm::ConstantVector::get(cast<llvm::Constant>(Ops[2])); |
| 4286 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4287 | Ops[2] = getAlignmentValue32(PtrOp0); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4288 | llvm::Type *Tys[] = {Int8PtrTy, Ops[1]->getType()}; |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4289 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst1, |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4290 | Tys), Ops); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4291 | } |
| 4292 | // fall through |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4293 | case NEON::BI__builtin_neon_vst1_lane_v: { |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4294 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4295 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 4296 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4297 | auto St = Builder.CreateStore(Ops[1], Builder.CreateBitCast(PtrOp0, Ty)); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 4298 | return St; |
| 4299 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4300 | case NEON::BI__builtin_neon_vtbl1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4301 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1), |
| 4302 | Ops, "vtbl1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4303 | case NEON::BI__builtin_neon_vtbl2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4304 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl2), |
| 4305 | Ops, "vtbl2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4306 | case NEON::BI__builtin_neon_vtbl3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4307 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl3), |
| 4308 | Ops, "vtbl3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4309 | case NEON::BI__builtin_neon_vtbl4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4310 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl4), |
| 4311 | Ops, "vtbl4"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4312 | case NEON::BI__builtin_neon_vtbx1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4313 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx1), |
| 4314 | Ops, "vtbx1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4315 | case NEON::BI__builtin_neon_vtbx2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4316 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx2), |
| 4317 | Ops, "vtbx2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4318 | case NEON::BI__builtin_neon_vtbx3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4319 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx3), |
| 4320 | Ops, "vtbx3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4321 | case NEON::BI__builtin_neon_vtbx4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4322 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx4), |
| 4323 | Ops, "vtbx4"); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 4324 | } |
| 4325 | } |
| 4326 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4327 | static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID, |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4328 | const CallExpr *E, |
| 4329 | SmallVectorImpl<Value *> &Ops) { |
| 4330 | unsigned int Int = 0; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4331 | const char *s = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4332 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4333 | switch (BuiltinID) { |
| 4334 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4335 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4336 | case NEON::BI__builtin_neon_vtbl1_v: |
| 4337 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 4338 | case NEON::BI__builtin_neon_vqtbl1q_v: |
| 4339 | case NEON::BI__builtin_neon_vtbl2_v: |
| 4340 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 4341 | case NEON::BI__builtin_neon_vqtbl2q_v: |
| 4342 | case NEON::BI__builtin_neon_vtbl3_v: |
| 4343 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 4344 | case NEON::BI__builtin_neon_vqtbl3q_v: |
| 4345 | case NEON::BI__builtin_neon_vtbl4_v: |
| 4346 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 4347 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4348 | break; |
| 4349 | case NEON::BI__builtin_neon_vtbx1_v: |
| 4350 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 4351 | case NEON::BI__builtin_neon_vqtbx1q_v: |
| 4352 | case NEON::BI__builtin_neon_vtbx2_v: |
| 4353 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 4354 | case NEON::BI__builtin_neon_vqtbx2q_v: |
| 4355 | case NEON::BI__builtin_neon_vtbx3_v: |
| 4356 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 4357 | case NEON::BI__builtin_neon_vqtbx3q_v: |
| 4358 | case NEON::BI__builtin_neon_vtbx4_v: |
| 4359 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 4360 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4361 | break; |
| 4362 | } |
| 4363 | |
| 4364 | assert(E->getNumArgs() >= 3); |
| 4365 | |
| 4366 | // Get the last argument, which specifies the vector type. |
| 4367 | llvm::APSInt Result; |
| 4368 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 4369 | if (!Arg->isIntegerConstantExpr(Result, CGF.getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4370 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4371 | |
| 4372 | // Determine the type of this overloaded NEON intrinsic. |
| 4373 | NeonTypeFlags Type(Result.getZExtValue()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4374 | llvm::VectorType *Ty = GetNeonType(&CGF, Type); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4375 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4376 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4377 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4378 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 4379 | |
| 4380 | // AArch64 scalar builtins are not overloaded, they do not have an extra |
| 4381 | // argument that specifies the vector type, need to handle each case. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4382 | switch (BuiltinID) { |
| 4383 | case NEON::BI__builtin_neon_vtbl1_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4384 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 1), nullptr, |
| 4385 | Ops[1], Ty, Intrinsic::aarch64_neon_tbl1, |
| 4386 | "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4387 | } |
| 4388 | case NEON::BI__builtin_neon_vtbl2_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4389 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 2), nullptr, |
| 4390 | Ops[2], Ty, Intrinsic::aarch64_neon_tbl1, |
| 4391 | "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4392 | } |
| 4393 | case NEON::BI__builtin_neon_vtbl3_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4394 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 3), nullptr, |
| 4395 | Ops[3], Ty, Intrinsic::aarch64_neon_tbl2, |
| 4396 | "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4397 | } |
| 4398 | case NEON::BI__builtin_neon_vtbl4_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4399 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 4), nullptr, |
| 4400 | Ops[4], Ty, Intrinsic::aarch64_neon_tbl2, |
| 4401 | "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4402 | } |
| 4403 | case NEON::BI__builtin_neon_vtbx1_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4404 | Value *TblRes = |
| 4405 | packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 1), nullptr, Ops[2], |
| 4406 | Ty, Intrinsic::aarch64_neon_tbl1, "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4407 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4408 | llvm::Constant *EightV = ConstantInt::get(Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4409 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[2], EightV); |
| 4410 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 4411 | |
| 4412 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 4413 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 4414 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 4415 | } |
| 4416 | case NEON::BI__builtin_neon_vtbx2_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4417 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 2), Ops[0], |
| 4418 | Ops[3], Ty, Intrinsic::aarch64_neon_tbx1, |
| 4419 | "vtbx1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4420 | } |
| 4421 | case NEON::BI__builtin_neon_vtbx3_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4422 | Value *TblRes = |
| 4423 | packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 3), nullptr, Ops[4], |
| 4424 | Ty, Intrinsic::aarch64_neon_tbl2, "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4425 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4426 | llvm::Constant *TwentyFourV = ConstantInt::get(Ty, 24); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4427 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[4], |
| 4428 | TwentyFourV); |
| 4429 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 4430 | |
| 4431 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 4432 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 4433 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 4434 | } |
| 4435 | case NEON::BI__builtin_neon_vtbx4_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4436 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 4), Ops[0], |
| 4437 | Ops[5], Ty, Intrinsic::aarch64_neon_tbx2, |
| 4438 | "vtbx2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4439 | } |
| 4440 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 4441 | case NEON::BI__builtin_neon_vqtbl1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4442 | Int = Intrinsic::aarch64_neon_tbl1; s = "vtbl1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4443 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 4444 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4445 | Int = Intrinsic::aarch64_neon_tbl2; s = "vtbl2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4446 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 4447 | case NEON::BI__builtin_neon_vqtbl3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4448 | Int = Intrinsic::aarch64_neon_tbl3; s = "vtbl3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4449 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 4450 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4451 | Int = Intrinsic::aarch64_neon_tbl4; s = "vtbl4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4452 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 4453 | case NEON::BI__builtin_neon_vqtbx1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4454 | Int = Intrinsic::aarch64_neon_tbx1; s = "vtbx1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4455 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 4456 | case NEON::BI__builtin_neon_vqtbx2q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4457 | Int = Intrinsic::aarch64_neon_tbx2; s = "vtbx2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4458 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 4459 | case NEON::BI__builtin_neon_vqtbx3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4460 | Int = Intrinsic::aarch64_neon_tbx3; s = "vtbx3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4461 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 4462 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4463 | Int = Intrinsic::aarch64_neon_tbx4; s = "vtbx4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | if (!Int) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4468 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4469 | |
| 4470 | Function *F = CGF.CGM.getIntrinsic(Int, Ty); |
| 4471 | return CGF.EmitNeonCall(F, Ops, s); |
| 4472 | } |
| 4473 | |
| 4474 | Value *CodeGenFunction::vectorWrapScalar16(Value *Op) { |
| 4475 | llvm::Type *VTy = llvm::VectorType::get(Int16Ty, 4); |
| 4476 | Op = Builder.CreateBitCast(Op, Int16Ty); |
| 4477 | Value *V = UndefValue::get(VTy); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4478 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4479 | Op = Builder.CreateInsertElement(V, Op, CI); |
| 4480 | return Op; |
| 4481 | } |
| 4482 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4483 | Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, |
| 4484 | const CallExpr *E) { |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 4485 | unsigned HintID = static_cast<unsigned>(-1); |
| 4486 | switch (BuiltinID) { |
| 4487 | default: break; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 4488 | case AArch64::BI__builtin_arm_nop: |
| 4489 | HintID = 0; |
| 4490 | break; |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 4491 | case AArch64::BI__builtin_arm_yield: |
| 4492 | HintID = 1; |
| 4493 | break; |
| 4494 | case AArch64::BI__builtin_arm_wfe: |
| 4495 | HintID = 2; |
| 4496 | break; |
| 4497 | case AArch64::BI__builtin_arm_wfi: |
| 4498 | HintID = 3; |
| 4499 | break; |
| 4500 | case AArch64::BI__builtin_arm_sev: |
| 4501 | HintID = 4; |
| 4502 | break; |
| 4503 | case AArch64::BI__builtin_arm_sevl: |
| 4504 | HintID = 5; |
| 4505 | break; |
| 4506 | } |
| 4507 | |
| 4508 | if (HintID != static_cast<unsigned>(-1)) { |
| 4509 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hint); |
| 4510 | return Builder.CreateCall(F, llvm::ConstantInt::get(Int32Ty, HintID)); |
| 4511 | } |
| 4512 | |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 4513 | if (BuiltinID == AArch64::BI__builtin_arm_prefetch) { |
| 4514 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 4515 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 4516 | Value *CacheLevel = EmitScalarExpr(E->getArg(2)); |
| 4517 | Value *RetentionPolicy = EmitScalarExpr(E->getArg(3)); |
| 4518 | Value *IsData = EmitScalarExpr(E->getArg(4)); |
| 4519 | |
| 4520 | Value *Locality = nullptr; |
| 4521 | if (cast<llvm::ConstantInt>(RetentionPolicy)->isZero()) { |
| 4522 | // Temporal fetch, needs to convert cache level to locality. |
| 4523 | Locality = llvm::ConstantInt::get(Int32Ty, |
| 4524 | -cast<llvm::ConstantInt>(CacheLevel)->getValue() + 3); |
| 4525 | } else { |
| 4526 | // Streaming fetch. |
| 4527 | Locality = llvm::ConstantInt::get(Int32Ty, 0); |
| 4528 | } |
| 4529 | |
| 4530 | // FIXME: We need AArch64 specific LLVM intrinsic if we want to specify |
| 4531 | // PLDL3STRM or PLDL2STRM. |
| 4532 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4533 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
Jim Grosbach | 7914082 | 2014-06-16 21:56:02 +0000 | [diff] [blame] | 4536 | if (BuiltinID == AArch64::BI__builtin_arm_rbit) { |
| 4537 | assert((getContext().getTypeSize(E->getType()) == 32) && |
| 4538 | "rbit of unusual size!"); |
| 4539 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 4540 | return Builder.CreateCall( |
| 4541 | CGM.getIntrinsic(Intrinsic::aarch64_rbit, Arg->getType()), Arg, "rbit"); |
| 4542 | } |
| 4543 | if (BuiltinID == AArch64::BI__builtin_arm_rbit64) { |
| 4544 | assert((getContext().getTypeSize(E->getType()) == 64) && |
| 4545 | "rbit of unusual size!"); |
| 4546 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 4547 | return Builder.CreateCall( |
| 4548 | CGM.getIntrinsic(Intrinsic::aarch64_rbit, Arg->getType()), Arg, "rbit"); |
| 4549 | } |
| 4550 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4551 | if (BuiltinID == AArch64::BI__clear_cache) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4552 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
| 4553 | const FunctionDecl *FD = E->getDirectCallee(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4554 | Value *Ops[2]; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4555 | for (unsigned i = 0; i < 2; i++) |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4556 | Ops[i] = EmitScalarExpr(E->getArg(i)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4557 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 4558 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
| 4559 | StringRef Name = FD->getName(); |
| 4560 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
| 4561 | } |
| 4562 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4563 | if ((BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 4564 | BuiltinID == AArch64::BI__builtin_arm_ldaex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4565 | getContext().getTypeSize(E->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4566 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 4567 | ? Intrinsic::aarch64_ldaxp |
| 4568 | : Intrinsic::aarch64_ldxp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4569 | |
| 4570 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
| 4571 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 4572 | "ldxp"); |
| 4573 | |
| 4574 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 4575 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 4576 | llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128); |
| 4577 | Val0 = Builder.CreateZExt(Val0, Int128Ty); |
| 4578 | Val1 = Builder.CreateZExt(Val1, Int128Ty); |
| 4579 | |
| 4580 | Value *ShiftCst = llvm::ConstantInt::get(Int128Ty, 64); |
| 4581 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
| 4582 | Val = Builder.CreateOr(Val, Val1); |
| 4583 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4584 | } else if (BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 4585 | BuiltinID == AArch64::BI__builtin_arm_ldaex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4586 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 4587 | |
| 4588 | QualType Ty = E->getType(); |
| 4589 | llvm::Type *RealResTy = ConvertType(Ty); |
| 4590 | llvm::Type *IntResTy = llvm::IntegerType::get(getLLVMContext(), |
| 4591 | getContext().getTypeSize(Ty)); |
| 4592 | LoadAddr = Builder.CreateBitCast(LoadAddr, IntResTy->getPointerTo()); |
| 4593 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4594 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 4595 | ? Intrinsic::aarch64_ldaxr |
| 4596 | : Intrinsic::aarch64_ldxr, |
| 4597 | LoadAddr->getType()); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4598 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldxr"); |
| 4599 | |
| 4600 | if (RealResTy->isPointerTy()) |
| 4601 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 4602 | |
| 4603 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 4604 | return Builder.CreateBitCast(Val, RealResTy); |
| 4605 | } |
| 4606 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4607 | if ((BuiltinID == AArch64::BI__builtin_arm_strex || |
| 4608 | BuiltinID == AArch64::BI__builtin_arm_stlex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4609 | getContext().getTypeSize(E->getArg(0)->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4610 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 4611 | ? Intrinsic::aarch64_stlxp |
| 4612 | : Intrinsic::aarch64_stxp); |
Reid Kleckner | ee7cf84 | 2014-12-01 22:02:27 +0000 | [diff] [blame] | 4613 | llvm::Type *STy = llvm::StructType::get(Int64Ty, Int64Ty, nullptr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4614 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4615 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
| 4616 | EmitAnyExprToMem(E->getArg(0), Tmp, Qualifiers(), /*init*/ true); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4617 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4618 | Tmp = Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(STy)); |
| 4619 | llvm::Value *Val = Builder.CreateLoad(Tmp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4620 | |
| 4621 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 4622 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
| 4623 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), |
| 4624 | Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4625 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "stxp"); |
| 4626 | } |
| 4627 | |
| 4628 | if (BuiltinID == AArch64::BI__builtin_arm_strex || |
| 4629 | BuiltinID == AArch64::BI__builtin_arm_stlex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4630 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 4631 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 4632 | |
| 4633 | QualType Ty = E->getArg(0)->getType(); |
| 4634 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 4635 | getContext().getTypeSize(Ty)); |
| 4636 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 4637 | |
| 4638 | if (StoreVal->getType()->isPointerTy()) |
| 4639 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int64Ty); |
| 4640 | else { |
| 4641 | StoreVal = Builder.CreateBitCast(StoreVal, StoreTy); |
| 4642 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int64Ty); |
| 4643 | } |
| 4644 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4645 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 4646 | ? Intrinsic::aarch64_stlxr |
| 4647 | : Intrinsic::aarch64_stxr, |
| 4648 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4649 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4652 | if (BuiltinID == AArch64::BI__builtin_arm_clrex) { |
| 4653 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 4654 | return Builder.CreateCall(F); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Adhemerval Zanella | 3916c91 | 2015-07-28 13:10:10 +0000 | [diff] [blame] | 4657 | if (BuiltinID == AArch64::BI__builtin_thread_pointer) { |
| 4658 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_thread_pointer); |
| 4659 | return Builder.CreateCall(F); |
| 4660 | } |
| 4661 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4662 | // CRC32 |
| 4663 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 4664 | switch (BuiltinID) { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4665 | case AArch64::BI__builtin_arm_crc32b: |
| 4666 | CRCIntrinsicID = Intrinsic::aarch64_crc32b; break; |
| 4667 | case AArch64::BI__builtin_arm_crc32cb: |
| 4668 | CRCIntrinsicID = Intrinsic::aarch64_crc32cb; break; |
| 4669 | case AArch64::BI__builtin_arm_crc32h: |
| 4670 | CRCIntrinsicID = Intrinsic::aarch64_crc32h; break; |
| 4671 | case AArch64::BI__builtin_arm_crc32ch: |
| 4672 | CRCIntrinsicID = Intrinsic::aarch64_crc32ch; break; |
| 4673 | case AArch64::BI__builtin_arm_crc32w: |
| 4674 | CRCIntrinsicID = Intrinsic::aarch64_crc32w; break; |
| 4675 | case AArch64::BI__builtin_arm_crc32cw: |
| 4676 | CRCIntrinsicID = Intrinsic::aarch64_crc32cw; break; |
| 4677 | case AArch64::BI__builtin_arm_crc32d: |
| 4678 | CRCIntrinsicID = Intrinsic::aarch64_crc32x; break; |
| 4679 | case AArch64::BI__builtin_arm_crc32cd: |
| 4680 | CRCIntrinsicID = Intrinsic::aarch64_crc32cx; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 4684 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 4685 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 4686 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
| 4687 | |
| 4688 | llvm::Type *DataTy = F->getFunctionType()->getParamType(1); |
| 4689 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, DataTy); |
| 4690 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4691 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4694 | if (BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 4695 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 4696 | BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 4697 | BuiltinID == AArch64::BI__builtin_arm_wsr || |
| 4698 | BuiltinID == AArch64::BI__builtin_arm_wsr64 || |
| 4699 | BuiltinID == AArch64::BI__builtin_arm_wsrp) { |
| 4700 | |
| 4701 | bool IsRead = BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 4702 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 4703 | BuiltinID == AArch64::BI__builtin_arm_rsrp; |
| 4704 | |
| 4705 | bool IsPointerBuiltin = BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 4706 | BuiltinID == AArch64::BI__builtin_arm_wsrp; |
| 4707 | |
| 4708 | bool Is64Bit = BuiltinID != AArch64::BI__builtin_arm_rsr && |
| 4709 | BuiltinID != AArch64::BI__builtin_arm_wsr; |
| 4710 | |
| 4711 | llvm::Type *ValueType; |
| 4712 | llvm::Type *RegisterType = Int64Ty; |
| 4713 | if (IsPointerBuiltin) { |
| 4714 | ValueType = VoidPtrTy; |
| 4715 | } else if (Is64Bit) { |
| 4716 | ValueType = Int64Ty; |
| 4717 | } else { |
| 4718 | ValueType = Int32Ty; |
| 4719 | } |
| 4720 | |
| 4721 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 4722 | } |
| 4723 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4724 | // Find out if any arguments are required to be integer constant |
| 4725 | // expressions. |
| 4726 | unsigned ICEArguments = 0; |
| 4727 | ASTContext::GetBuiltinTypeError Error; |
| 4728 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 4729 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 4730 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4731 | llvm::SmallVector<Value*, 4> Ops; |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4732 | for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++) { |
| 4733 | if ((ICEArguments & (1 << i)) == 0) { |
| 4734 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 4735 | } else { |
| 4736 | // If this is required to be a constant, constant fold it so that we know |
| 4737 | // that the generated intrinsic gets a ConstantInt. |
| 4738 | llvm::APSInt Result; |
| 4739 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 4740 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 4741 | (void)IsConst; |
| 4742 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 4743 | } |
| 4744 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4745 | |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 4746 | auto SISDMap = makeArrayRef(AArch64SISDIntrinsicMap); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4747 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4748 | SISDMap, BuiltinID, AArch64SISDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4749 | |
| 4750 | if (Builtin) { |
| 4751 | Ops.push_back(EmitScalarExpr(E->getArg(E->getNumArgs() - 1))); |
| 4752 | Value *Result = EmitCommonNeonSISDBuiltinExpr(*this, *Builtin, Ops, E); |
| 4753 | assert(Result && "SISD intrinsic should have been handled"); |
| 4754 | return Result; |
| 4755 | } |
| 4756 | |
| 4757 | llvm::APSInt Result; |
| 4758 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 4759 | NeonTypeFlags Type(0); |
| 4760 | if (Arg->isIntegerConstantExpr(Result, getContext())) |
| 4761 | // Determine the type of this overloaded NEON intrinsic. |
| 4762 | Type = NeonTypeFlags(Result.getZExtValue()); |
| 4763 | |
| 4764 | bool usgn = Type.isUnsigned(); |
| 4765 | bool quad = Type.isQuad(); |
| 4766 | |
| 4767 | // Handle non-overloaded intrinsics first. |
| 4768 | switch (BuiltinID) { |
| 4769 | default: break; |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 4770 | case NEON::BI__builtin_neon_vldrq_p128: { |
| 4771 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 4772 | Value *Ptr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int128PTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4773 | return Builder.CreateDefaultAlignedLoad(Ptr); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 4774 | } |
| 4775 | case NEON::BI__builtin_neon_vstrq_p128: { |
| 4776 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 4777 | Value *Ptr = Builder.CreateBitCast(Ops[0], Int128PTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4778 | return Builder.CreateDefaultAlignedStore(EmitScalarExpr(E->getArg(1)), Ptr); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 4779 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4780 | case NEON::BI__builtin_neon_vcvts_u32_f32: |
| 4781 | case NEON::BI__builtin_neon_vcvtd_u64_f64: |
| 4782 | usgn = true; |
| 4783 | // FALL THROUGH |
| 4784 | case NEON::BI__builtin_neon_vcvts_s32_f32: |
| 4785 | case NEON::BI__builtin_neon_vcvtd_s64_f64: { |
| 4786 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4787 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 4788 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 4789 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 4790 | Ops[0] = Builder.CreateBitCast(Ops[0], FTy); |
| 4791 | if (usgn) |
| 4792 | return Builder.CreateFPToUI(Ops[0], InTy); |
| 4793 | return Builder.CreateFPToSI(Ops[0], InTy); |
| 4794 | } |
| 4795 | case NEON::BI__builtin_neon_vcvts_f32_u32: |
| 4796 | case NEON::BI__builtin_neon_vcvtd_f64_u64: |
| 4797 | usgn = true; |
| 4798 | // FALL THROUGH |
| 4799 | case NEON::BI__builtin_neon_vcvts_f32_s32: |
| 4800 | case NEON::BI__builtin_neon_vcvtd_f64_s64: { |
| 4801 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4802 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 4803 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 4804 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 4805 | Ops[0] = Builder.CreateBitCast(Ops[0], InTy); |
| 4806 | if (usgn) |
| 4807 | return Builder.CreateUIToFP(Ops[0], FTy); |
| 4808 | return Builder.CreateSIToFP(Ops[0], FTy); |
| 4809 | } |
| 4810 | case NEON::BI__builtin_neon_vpaddd_s64: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4811 | llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4812 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 4813 | // The vector is v2f64, so make sure it's bitcast to that. |
| 4814 | Vec = Builder.CreateBitCast(Vec, Ty, "v2i64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4815 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 4816 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4817 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 4818 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 4819 | // Pairwise addition of a v2f64 into a scalar f64. |
| 4820 | return Builder.CreateAdd(Op0, Op1, "vpaddd"); |
| 4821 | } |
| 4822 | case NEON::BI__builtin_neon_vpaddd_f64: { |
| 4823 | llvm::Type *Ty = |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 4824 | llvm::VectorType::get(DoubleTy, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4825 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 4826 | // The vector is v2f64, so make sure it's bitcast to that. |
| 4827 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4828 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 4829 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4830 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 4831 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 4832 | // Pairwise addition of a v2f64 into a scalar f64. |
| 4833 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 4834 | } |
| 4835 | case NEON::BI__builtin_neon_vpadds_f32: { |
| 4836 | llvm::Type *Ty = |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 4837 | llvm::VectorType::get(FloatTy, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4838 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 4839 | // The vector is v2f32, so make sure it's bitcast to that. |
| 4840 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f32"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4841 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 4842 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4843 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 4844 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 4845 | // Pairwise addition of a v2f32 into a scalar f32. |
| 4846 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 4847 | } |
| 4848 | case NEON::BI__builtin_neon_vceqzd_s64: |
| 4849 | case NEON::BI__builtin_neon_vceqzd_f64: |
| 4850 | case NEON::BI__builtin_neon_vceqzs_f32: |
| 4851 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4852 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4853 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4854 | ICmpInst::FCMP_OEQ, ICmpInst::ICMP_EQ, "vceqz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4855 | case NEON::BI__builtin_neon_vcgezd_s64: |
| 4856 | case NEON::BI__builtin_neon_vcgezd_f64: |
| 4857 | case NEON::BI__builtin_neon_vcgezs_f32: |
| 4858 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4859 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4860 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4861 | ICmpInst::FCMP_OGE, ICmpInst::ICMP_SGE, "vcgez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4862 | case NEON::BI__builtin_neon_vclezd_s64: |
| 4863 | case NEON::BI__builtin_neon_vclezd_f64: |
| 4864 | case NEON::BI__builtin_neon_vclezs_f32: |
| 4865 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4866 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4867 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4868 | ICmpInst::FCMP_OLE, ICmpInst::ICMP_SLE, "vclez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4869 | case NEON::BI__builtin_neon_vcgtzd_s64: |
| 4870 | case NEON::BI__builtin_neon_vcgtzd_f64: |
| 4871 | case NEON::BI__builtin_neon_vcgtzs_f32: |
| 4872 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4873 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4874 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4875 | ICmpInst::FCMP_OGT, ICmpInst::ICMP_SGT, "vcgtz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4876 | case NEON::BI__builtin_neon_vcltzd_s64: |
| 4877 | case NEON::BI__builtin_neon_vcltzd_f64: |
| 4878 | case NEON::BI__builtin_neon_vcltzs_f32: |
| 4879 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 4880 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4881 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 4882 | ICmpInst::FCMP_OLT, ICmpInst::ICMP_SLT, "vcltz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4883 | |
| 4884 | case NEON::BI__builtin_neon_vceqzd_u64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4885 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4886 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 4887 | Ops[0] = |
| 4888 | Builder.CreateICmpEQ(Ops[0], llvm::Constant::getNullValue(Int64Ty)); |
| 4889 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqzd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4890 | } |
| 4891 | case NEON::BI__builtin_neon_vceqd_f64: |
| 4892 | case NEON::BI__builtin_neon_vcled_f64: |
| 4893 | case NEON::BI__builtin_neon_vcltd_f64: |
| 4894 | case NEON::BI__builtin_neon_vcged_f64: |
| 4895 | case NEON::BI__builtin_neon_vcgtd_f64: { |
| 4896 | llvm::CmpInst::Predicate P; |
| 4897 | switch (BuiltinID) { |
| 4898 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 4899 | case NEON::BI__builtin_neon_vceqd_f64: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 4900 | case NEON::BI__builtin_neon_vcled_f64: P = llvm::FCmpInst::FCMP_OLE; break; |
| 4901 | case NEON::BI__builtin_neon_vcltd_f64: P = llvm::FCmpInst::FCMP_OLT; break; |
| 4902 | case NEON::BI__builtin_neon_vcged_f64: P = llvm::FCmpInst::FCMP_OGE; break; |
| 4903 | case NEON::BI__builtin_neon_vcgtd_f64: P = llvm::FCmpInst::FCMP_OGT; break; |
| 4904 | } |
| 4905 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4906 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 4907 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 4908 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 4909 | return Builder.CreateSExt(Ops[0], Int64Ty, "vcmpd"); |
| 4910 | } |
| 4911 | case NEON::BI__builtin_neon_vceqs_f32: |
| 4912 | case NEON::BI__builtin_neon_vcles_f32: |
| 4913 | case NEON::BI__builtin_neon_vclts_f32: |
| 4914 | case NEON::BI__builtin_neon_vcges_f32: |
| 4915 | case NEON::BI__builtin_neon_vcgts_f32: { |
| 4916 | llvm::CmpInst::Predicate P; |
| 4917 | switch (BuiltinID) { |
| 4918 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 4919 | case NEON::BI__builtin_neon_vceqs_f32: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 4920 | case NEON::BI__builtin_neon_vcles_f32: P = llvm::FCmpInst::FCMP_OLE; break; |
| 4921 | case NEON::BI__builtin_neon_vclts_f32: P = llvm::FCmpInst::FCMP_OLT; break; |
| 4922 | case NEON::BI__builtin_neon_vcges_f32: P = llvm::FCmpInst::FCMP_OGE; break; |
| 4923 | case NEON::BI__builtin_neon_vcgts_f32: P = llvm::FCmpInst::FCMP_OGT; break; |
| 4924 | } |
| 4925 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 4926 | Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy); |
| 4927 | Ops[1] = Builder.CreateBitCast(Ops[1], FloatTy); |
| 4928 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 4929 | return Builder.CreateSExt(Ops[0], Int32Ty, "vcmpd"); |
| 4930 | } |
| 4931 | case NEON::BI__builtin_neon_vceqd_s64: |
| 4932 | case NEON::BI__builtin_neon_vceqd_u64: |
| 4933 | case NEON::BI__builtin_neon_vcgtd_s64: |
| 4934 | case NEON::BI__builtin_neon_vcgtd_u64: |
| 4935 | case NEON::BI__builtin_neon_vcltd_s64: |
| 4936 | case NEON::BI__builtin_neon_vcltd_u64: |
| 4937 | case NEON::BI__builtin_neon_vcged_u64: |
| 4938 | case NEON::BI__builtin_neon_vcged_s64: |
| 4939 | case NEON::BI__builtin_neon_vcled_u64: |
| 4940 | case NEON::BI__builtin_neon_vcled_s64: { |
| 4941 | llvm::CmpInst::Predicate P; |
| 4942 | switch (BuiltinID) { |
| 4943 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 4944 | case NEON::BI__builtin_neon_vceqd_s64: |
| 4945 | case NEON::BI__builtin_neon_vceqd_u64:P = llvm::ICmpInst::ICMP_EQ;break; |
| 4946 | case NEON::BI__builtin_neon_vcgtd_s64:P = llvm::ICmpInst::ICMP_SGT;break; |
| 4947 | case NEON::BI__builtin_neon_vcgtd_u64:P = llvm::ICmpInst::ICMP_UGT;break; |
| 4948 | case NEON::BI__builtin_neon_vcltd_s64:P = llvm::ICmpInst::ICMP_SLT;break; |
| 4949 | case NEON::BI__builtin_neon_vcltd_u64:P = llvm::ICmpInst::ICMP_ULT;break; |
| 4950 | case NEON::BI__builtin_neon_vcged_u64:P = llvm::ICmpInst::ICMP_UGE;break; |
| 4951 | case NEON::BI__builtin_neon_vcged_s64:P = llvm::ICmpInst::ICMP_SGE;break; |
| 4952 | case NEON::BI__builtin_neon_vcled_u64:P = llvm::ICmpInst::ICMP_ULE;break; |
| 4953 | case NEON::BI__builtin_neon_vcled_s64:P = llvm::ICmpInst::ICMP_SLE;break; |
| 4954 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4955 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4956 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 4957 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4958 | Ops[0] = Builder.CreateICmp(P, Ops[0], Ops[1]); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4959 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4960 | } |
| 4961 | case NEON::BI__builtin_neon_vtstd_s64: |
| 4962 | case NEON::BI__builtin_neon_vtstd_u64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4963 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4964 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 4965 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4966 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 4967 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4968 | llvm::Constant::getNullValue(Int64Ty)); |
| 4969 | return Builder.CreateSExt(Ops[0], Int64Ty, "vtstd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4970 | } |
| 4971 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 4972 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 4973 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 4974 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 4975 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 4976 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 4977 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 4978 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 4979 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 4980 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 4981 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 4982 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 4983 | case NEON::BI__builtin_neon_vset_lane_f64: |
| 4984 | // The vector type needs a cast for the v1f64 variant. |
| 4985 | Ops[1] = Builder.CreateBitCast(Ops[1], |
| 4986 | llvm::VectorType::get(DoubleTy, 1)); |
| 4987 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 4988 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 4989 | case NEON::BI__builtin_neon_vsetq_lane_f64: |
| 4990 | // The vector type needs a cast for the v2f64 variant. |
| 4991 | Ops[1] = Builder.CreateBitCast(Ops[1], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 4992 | llvm::VectorType::get(DoubleTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4993 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 4994 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 4995 | |
| 4996 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 4997 | case NEON::BI__builtin_neon_vdupb_lane_i8: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4998 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int8Ty, 8)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4999 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5000 | "vget_lane"); |
| 5001 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 5002 | case NEON::BI__builtin_neon_vdupb_laneq_i8: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5003 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int8Ty, 16)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5004 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5005 | "vgetq_lane"); |
| 5006 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 5007 | case NEON::BI__builtin_neon_vduph_lane_i16: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5008 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int16Ty, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5009 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5010 | "vget_lane"); |
| 5011 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 5012 | case NEON::BI__builtin_neon_vduph_laneq_i16: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5013 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int16Ty, 8)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5014 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5015 | "vgetq_lane"); |
| 5016 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 5017 | case NEON::BI__builtin_neon_vdups_lane_i32: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5018 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5019 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5020 | "vget_lane"); |
| 5021 | case NEON::BI__builtin_neon_vdups_lane_f32: |
| 5022 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5023 | llvm::VectorType::get(FloatTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5024 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5025 | "vdups_lane"); |
| 5026 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 5027 | case NEON::BI__builtin_neon_vdups_laneq_i32: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5028 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5029 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5030 | "vgetq_lane"); |
| 5031 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 5032 | case NEON::BI__builtin_neon_vdupd_lane_i64: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5033 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5034 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5035 | "vget_lane"); |
| 5036 | case NEON::BI__builtin_neon_vdupd_lane_f64: |
| 5037 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5038 | llvm::VectorType::get(DoubleTy, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5039 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5040 | "vdupd_lane"); |
| 5041 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 5042 | case NEON::BI__builtin_neon_vdupd_laneq_i64: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5043 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5044 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5045 | "vgetq_lane"); |
| 5046 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 5047 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5048 | llvm::VectorType::get(FloatTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5049 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5050 | "vget_lane"); |
| 5051 | case NEON::BI__builtin_neon_vget_lane_f64: |
| 5052 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5053 | llvm::VectorType::get(DoubleTy, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5054 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5055 | "vget_lane"); |
| 5056 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 5057 | case NEON::BI__builtin_neon_vdups_laneq_f32: |
| 5058 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5059 | llvm::VectorType::get(FloatTy, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5060 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5061 | "vgetq_lane"); |
| 5062 | case NEON::BI__builtin_neon_vgetq_lane_f64: |
| 5063 | case NEON::BI__builtin_neon_vdupd_laneq_f64: |
| 5064 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5065 | llvm::VectorType::get(DoubleTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5066 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5067 | "vgetq_lane"); |
| 5068 | case NEON::BI__builtin_neon_vaddd_s64: |
| 5069 | case NEON::BI__builtin_neon_vaddd_u64: |
| 5070 | return Builder.CreateAdd(Ops[0], EmitScalarExpr(E->getArg(1)), "vaddd"); |
| 5071 | case NEON::BI__builtin_neon_vsubd_s64: |
| 5072 | case NEON::BI__builtin_neon_vsubd_u64: |
| 5073 | return Builder.CreateSub(Ops[0], EmitScalarExpr(E->getArg(1)), "vsubd"); |
| 5074 | case NEON::BI__builtin_neon_vqdmlalh_s16: |
| 5075 | case NEON::BI__builtin_neon_vqdmlslh_s16: { |
| 5076 | SmallVector<Value *, 2> ProductOps; |
| 5077 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 5078 | ProductOps.push_back(vectorWrapScalar16(EmitScalarExpr(E->getArg(2)))); |
| 5079 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5080 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5081 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5082 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5083 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 5084 | |
| 5085 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlalh_s16 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5086 | ? Intrinsic::aarch64_neon_sqadd |
| 5087 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5088 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int32Ty), Ops, "vqdmlXl"); |
| 5089 | } |
| 5090 | case NEON::BI__builtin_neon_vqshlud_n_s64: { |
| 5091 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 5092 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5093 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqshlu, Int64Ty), |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 5094 | Ops, "vqshlu_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5095 | } |
| 5096 | case NEON::BI__builtin_neon_vqshld_n_u64: |
| 5097 | case NEON::BI__builtin_neon_vqshld_n_s64: { |
| 5098 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vqshld_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5099 | ? Intrinsic::aarch64_neon_uqshl |
| 5100 | : Intrinsic::aarch64_neon_sqshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5101 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 5102 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 5103 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vqshl_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5104 | } |
| 5105 | case NEON::BI__builtin_neon_vrshrd_n_u64: |
| 5106 | case NEON::BI__builtin_neon_vrshrd_n_s64: { |
| 5107 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5108 | ? Intrinsic::aarch64_neon_urshl |
| 5109 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5110 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 5111 | int SV = cast<ConstantInt>(Ops[1])->getSExtValue(); |
| 5112 | Ops[1] = ConstantInt::get(Int64Ty, -SV); |
| 5113 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vrshr_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5114 | } |
| 5115 | case NEON::BI__builtin_neon_vrsrad_n_u64: |
| 5116 | case NEON::BI__builtin_neon_vrsrad_n_s64: { |
| 5117 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrsrad_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5118 | ? Intrinsic::aarch64_neon_urshl |
| 5119 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5120 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
| 5121 | Ops.push_back(Builder.CreateNeg(EmitScalarExpr(E->getArg(2)))); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5122 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Int64Ty), |
| 5123 | {Ops[1], Builder.CreateSExt(Ops[2], Int64Ty)}); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5124 | return Builder.CreateAdd(Ops[0], Builder.CreateBitCast(Ops[1], Int64Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5125 | } |
| 5126 | case NEON::BI__builtin_neon_vshld_n_s64: |
| 5127 | case NEON::BI__builtin_neon_vshld_n_u64: { |
| 5128 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 5129 | return Builder.CreateShl( |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5130 | Ops[0], ConstantInt::get(Int64Ty, Amt->getZExtValue()), "shld_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5131 | } |
| 5132 | case NEON::BI__builtin_neon_vshrd_n_s64: { |
| 5133 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 5134 | return Builder.CreateAShr( |
| 5135 | Ops[0], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 5136 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5137 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5138 | } |
| 5139 | case NEON::BI__builtin_neon_vshrd_n_u64: { |
| 5140 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5141 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 5142 | // Right-shifting an unsigned value by its size yields 0. |
| 5143 | if (ShiftAmt == 64) |
| 5144 | return ConstantInt::get(Int64Ty, 0); |
| 5145 | return Builder.CreateLShr(Ops[0], ConstantInt::get(Int64Ty, ShiftAmt), |
| 5146 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5147 | } |
| 5148 | case NEON::BI__builtin_neon_vsrad_n_s64: { |
| 5149 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
| 5150 | Ops[1] = Builder.CreateAShr( |
| 5151 | Ops[1], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 5152 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5153 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5154 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 5155 | } |
| 5156 | case NEON::BI__builtin_neon_vsrad_n_u64: { |
| 5157 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5158 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 5159 | // Right-shifting an unsigned value by its size yields 0. |
| 5160 | // As Op + 0 = Op, return Ops[0] directly. |
| 5161 | if (ShiftAmt == 64) |
| 5162 | return Ops[0]; |
| 5163 | Ops[1] = Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, ShiftAmt), |
| 5164 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5165 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 5166 | } |
| 5167 | case NEON::BI__builtin_neon_vqdmlalh_lane_s16: |
| 5168 | case NEON::BI__builtin_neon_vqdmlalh_laneq_s16: |
| 5169 | case NEON::BI__builtin_neon_vqdmlslh_lane_s16: |
| 5170 | case NEON::BI__builtin_neon_vqdmlslh_laneq_s16: { |
| 5171 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 5172 | "lane"); |
| 5173 | SmallVector<Value *, 2> ProductOps; |
| 5174 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 5175 | ProductOps.push_back(vectorWrapScalar16(Ops[2])); |
| 5176 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5177 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5178 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5179 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5180 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 5181 | Ops.pop_back(); |
| 5182 | |
| 5183 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlalh_lane_s16 || |
| 5184 | BuiltinID == NEON::BI__builtin_neon_vqdmlalh_laneq_s16) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5185 | ? Intrinsic::aarch64_neon_sqadd |
| 5186 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5187 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int32Ty), Ops, "vqdmlXl"); |
| 5188 | } |
| 5189 | case NEON::BI__builtin_neon_vqdmlals_s32: |
| 5190 | case NEON::BI__builtin_neon_vqdmlsls_s32: { |
| 5191 | SmallVector<Value *, 2> ProductOps; |
| 5192 | ProductOps.push_back(Ops[1]); |
| 5193 | ProductOps.push_back(EmitScalarExpr(E->getArg(2))); |
| 5194 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5195 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5196 | ProductOps, "vqdmlXl"); |
| 5197 | |
| 5198 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlals_s32 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5199 | ? Intrinsic::aarch64_neon_sqadd |
| 5200 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5201 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int64Ty), Ops, "vqdmlXl"); |
| 5202 | } |
| 5203 | case NEON::BI__builtin_neon_vqdmlals_lane_s32: |
| 5204 | case NEON::BI__builtin_neon_vqdmlals_laneq_s32: |
| 5205 | case NEON::BI__builtin_neon_vqdmlsls_lane_s32: |
| 5206 | case NEON::BI__builtin_neon_vqdmlsls_laneq_s32: { |
| 5207 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 5208 | "lane"); |
| 5209 | SmallVector<Value *, 2> ProductOps; |
| 5210 | ProductOps.push_back(Ops[1]); |
| 5211 | ProductOps.push_back(Ops[2]); |
| 5212 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5213 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5214 | ProductOps, "vqdmlXl"); |
| 5215 | Ops.pop_back(); |
| 5216 | |
| 5217 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlals_lane_s32 || |
| 5218 | BuiltinID == NEON::BI__builtin_neon_vqdmlals_laneq_s32) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5219 | ? Intrinsic::aarch64_neon_sqadd |
| 5220 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5221 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int64Ty), Ops, "vqdmlXl"); |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 5226 | llvm::Type *Ty = VTy; |
| 5227 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5228 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5229 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5230 | // 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] | 5231 | // 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] | 5232 | Builtin = findNeonIntrinsicInMap(AArch64SIMDIntrinsicMap, BuiltinID, |
| 5233 | AArch64SIMDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5234 | |
| 5235 | if (Builtin) |
| 5236 | return EmitCommonNeonBuiltinExpr( |
| 5237 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5238 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, |
| 5239 | /*never use addresses*/ Address::invalid(), Address::invalid()); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5240 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5241 | if (Value *V = EmitAArch64TblBuiltinExpr(*this, BuiltinID, E, Ops)) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5242 | return V; |
| 5243 | |
| 5244 | unsigned Int; |
| 5245 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5246 | default: return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5247 | case NEON::BI__builtin_neon_vbsl_v: |
| 5248 | case NEON::BI__builtin_neon_vbslq_v: { |
| 5249 | llvm::Type *BitTy = llvm::VectorType::getInteger(VTy); |
| 5250 | Ops[0] = Builder.CreateBitCast(Ops[0], BitTy, "vbsl"); |
| 5251 | Ops[1] = Builder.CreateBitCast(Ops[1], BitTy, "vbsl"); |
| 5252 | Ops[2] = Builder.CreateBitCast(Ops[2], BitTy, "vbsl"); |
| 5253 | |
| 5254 | Ops[1] = Builder.CreateAnd(Ops[0], Ops[1], "vbsl"); |
| 5255 | Ops[2] = Builder.CreateAnd(Builder.CreateNot(Ops[0]), Ops[2], "vbsl"); |
| 5256 | Ops[0] = Builder.CreateOr(Ops[1], Ops[2], "vbsl"); |
| 5257 | return Builder.CreateBitCast(Ops[0], Ty); |
| 5258 | } |
| 5259 | case NEON::BI__builtin_neon_vfma_lane_v: |
| 5260 | case NEON::BI__builtin_neon_vfmaq_lane_v: { // Only used for FP types |
| 5261 | // The ARM builtins (and instructions) have the addend as the first |
| 5262 | // operand, but the 'fma' intrinsics have it last. Swap it around here. |
| 5263 | Value *Addend = Ops[0]; |
| 5264 | Value *Multiplicand = Ops[1]; |
| 5265 | Value *LaneSource = Ops[2]; |
| 5266 | Ops[0] = Multiplicand; |
| 5267 | Ops[1] = LaneSource; |
| 5268 | Ops[2] = Addend; |
| 5269 | |
| 5270 | // Now adjust things to handle the lane access. |
| 5271 | llvm::Type *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v ? |
| 5272 | llvm::VectorType::get(VTy->getElementType(), VTy->getNumElements() / 2) : |
| 5273 | VTy; |
| 5274 | llvm::Constant *cst = cast<Constant>(Ops[3]); |
| 5275 | Value *SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), cst); |
| 5276 | Ops[1] = Builder.CreateBitCast(Ops[1], SourceTy); |
| 5277 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV, "lane"); |
| 5278 | |
| 5279 | Ops.pop_back(); |
| 5280 | Int = Intrinsic::fma; |
| 5281 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmla"); |
| 5282 | } |
| 5283 | case NEON::BI__builtin_neon_vfma_laneq_v: { |
| 5284 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 5285 | // v1f64 fma should be mapped to Neon scalar f64 fma |
| 5286 | if (VTy && VTy->getElementType() == DoubleTy) { |
| 5287 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5288 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 5289 | llvm::Type *VTy = GetNeonType(this, |
| 5290 | NeonTypeFlags(NeonTypeFlags::Float64, false, true)); |
| 5291 | Ops[2] = Builder.CreateBitCast(Ops[2], VTy); |
| 5292 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
| 5293 | Value *F = CGM.getIntrinsic(Intrinsic::fma, DoubleTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5294 | Value *Result = Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5295 | return Builder.CreateBitCast(Result, Ty); |
| 5296 | } |
| 5297 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5298 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5299 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5300 | |
| 5301 | llvm::Type *STy = llvm::VectorType::get(VTy->getElementType(), |
| 5302 | VTy->getNumElements() * 2); |
| 5303 | Ops[2] = Builder.CreateBitCast(Ops[2], STy); |
| 5304 | Value* SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), |
| 5305 | cast<ConstantInt>(Ops[3])); |
| 5306 | Ops[2] = Builder.CreateShuffleVector(Ops[2], Ops[2], SV, "lane"); |
| 5307 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5308 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5309 | } |
| 5310 | case NEON::BI__builtin_neon_vfmaq_laneq_v: { |
| 5311 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5312 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5313 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5314 | |
| 5315 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 5316 | Ops[2] = EmitNeonSplat(Ops[2], cast<ConstantInt>(Ops[3])); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5317 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5318 | } |
| 5319 | case NEON::BI__builtin_neon_vfmas_lane_f32: |
| 5320 | case NEON::BI__builtin_neon_vfmas_laneq_f32: |
| 5321 | case NEON::BI__builtin_neon_vfmad_lane_f64: |
| 5322 | case NEON::BI__builtin_neon_vfmad_laneq_f64: { |
| 5323 | Ops.push_back(EmitScalarExpr(E->getArg(3))); |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5324 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5325 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5326 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5327 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5328 | } |
| 5329 | case NEON::BI__builtin_neon_vfms_v: |
| 5330 | case NEON::BI__builtin_neon_vfmsq_v: { // Only used for FP types |
| 5331 | // FIXME: probably remove when we no longer support aarch64_simd.h |
| 5332 | // (arm_neon.h delegates to vfma). |
| 5333 | |
| 5334 | // The ARM builtins (and instructions) have the addend as the first |
| 5335 | // operand, but the 'fma' intrinsics have it last. Swap it around here. |
| 5336 | Value *Subtrahend = Ops[0]; |
| 5337 | Value *Multiplicand = Ops[2]; |
| 5338 | Ops[0] = Multiplicand; |
| 5339 | Ops[2] = Subtrahend; |
| 5340 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 5341 | Ops[1] = Builder.CreateFNeg(Ops[1]); |
| 5342 | Int = Intrinsic::fma; |
| 5343 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmls"); |
| 5344 | } |
| 5345 | case NEON::BI__builtin_neon_vmull_v: |
| 5346 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5347 | Int = usgn ? Intrinsic::aarch64_neon_umull : Intrinsic::aarch64_neon_smull; |
| 5348 | if (Type.isPoly()) Int = Intrinsic::aarch64_neon_pmull; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5349 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 5350 | case NEON::BI__builtin_neon_vmax_v: |
| 5351 | case NEON::BI__builtin_neon_vmaxq_v: |
| 5352 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5353 | Int = usgn ? Intrinsic::aarch64_neon_umax : Intrinsic::aarch64_neon_smax; |
| 5354 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmax; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5355 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmax"); |
| 5356 | case NEON::BI__builtin_neon_vmin_v: |
| 5357 | case NEON::BI__builtin_neon_vminq_v: |
| 5358 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5359 | Int = usgn ? Intrinsic::aarch64_neon_umin : Intrinsic::aarch64_neon_smin; |
| 5360 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmin; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5361 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmin"); |
| 5362 | case NEON::BI__builtin_neon_vabd_v: |
| 5363 | case NEON::BI__builtin_neon_vabdq_v: |
| 5364 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5365 | Int = usgn ? Intrinsic::aarch64_neon_uabd : Intrinsic::aarch64_neon_sabd; |
| 5366 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fabd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5367 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vabd"); |
| 5368 | case NEON::BI__builtin_neon_vpadal_v: |
| 5369 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 5370 | unsigned ArgElts = VTy->getNumElements(); |
| 5371 | llvm::IntegerType *EltTy = cast<IntegerType>(VTy->getElementType()); |
| 5372 | unsigned BitWidth = EltTy->getBitWidth(); |
| 5373 | llvm::Type *ArgTy = llvm::VectorType::get( |
| 5374 | llvm::IntegerType::get(getLLVMContext(), BitWidth/2), 2*ArgElts); |
| 5375 | llvm::Type* Tys[2] = { VTy, ArgTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5376 | Int = usgn ? Intrinsic::aarch64_neon_uaddlp : Intrinsic::aarch64_neon_saddlp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5377 | SmallVector<llvm::Value*, 1> TmpOps; |
| 5378 | TmpOps.push_back(Ops[1]); |
| 5379 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 5380 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vpadal"); |
| 5381 | llvm::Value *addend = Builder.CreateBitCast(Ops[0], tmp->getType()); |
| 5382 | return Builder.CreateAdd(tmp, addend); |
| 5383 | } |
| 5384 | case NEON::BI__builtin_neon_vpmin_v: |
| 5385 | case NEON::BI__builtin_neon_vpminq_v: |
| 5386 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5387 | Int = usgn ? Intrinsic::aarch64_neon_uminp : Intrinsic::aarch64_neon_sminp; |
| 5388 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fminp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5389 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmin"); |
| 5390 | case NEON::BI__builtin_neon_vpmax_v: |
| 5391 | case NEON::BI__builtin_neon_vpmaxq_v: |
| 5392 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5393 | Int = usgn ? Intrinsic::aarch64_neon_umaxp : Intrinsic::aarch64_neon_smaxp; |
| 5394 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmaxp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5395 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmax"); |
| 5396 | case NEON::BI__builtin_neon_vminnm_v: |
| 5397 | case NEON::BI__builtin_neon_vminnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5398 | Int = Intrinsic::aarch64_neon_fminnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5399 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vminnm"); |
| 5400 | case NEON::BI__builtin_neon_vmaxnm_v: |
| 5401 | case NEON::BI__builtin_neon_vmaxnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5402 | Int = Intrinsic::aarch64_neon_fmaxnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5403 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmaxnm"); |
| 5404 | case NEON::BI__builtin_neon_vrecpss_f32: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5405 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5406 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, FloatTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5407 | Ops, "vrecps"); |
| 5408 | } |
| 5409 | case NEON::BI__builtin_neon_vrecpsd_f64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5410 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5411 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, DoubleTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5412 | Ops, "vrecps"); |
| 5413 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5414 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5415 | Int = Intrinsic::aarch64_neon_sqshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5416 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrun_n"); |
| 5417 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5418 | Int = Intrinsic::aarch64_neon_sqrshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5419 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrun_n"); |
| 5420 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5421 | Int = usgn ? Intrinsic::aarch64_neon_uqshrn : Intrinsic::aarch64_neon_sqshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5422 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n"); |
| 5423 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5424 | Int = Intrinsic::aarch64_neon_rshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5425 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshrn_n"); |
| 5426 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5427 | Int = usgn ? Intrinsic::aarch64_neon_uqrshrn : Intrinsic::aarch64_neon_sqrshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5428 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n"); |
| 5429 | case NEON::BI__builtin_neon_vrnda_v: |
| 5430 | case NEON::BI__builtin_neon_vrndaq_v: { |
| 5431 | Int = Intrinsic::round; |
| 5432 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnda"); |
| 5433 | } |
| 5434 | case NEON::BI__builtin_neon_vrndi_v: |
| 5435 | case NEON::BI__builtin_neon_vrndiq_v: { |
| 5436 | Int = Intrinsic::nearbyint; |
| 5437 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndi"); |
| 5438 | } |
| 5439 | case NEON::BI__builtin_neon_vrndm_v: |
| 5440 | case NEON::BI__builtin_neon_vrndmq_v: { |
| 5441 | Int = Intrinsic::floor; |
| 5442 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndm"); |
| 5443 | } |
| 5444 | case NEON::BI__builtin_neon_vrndn_v: |
| 5445 | case NEON::BI__builtin_neon_vrndnq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5446 | Int = Intrinsic::aarch64_neon_frintn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5447 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndn"); |
| 5448 | } |
| 5449 | case NEON::BI__builtin_neon_vrndp_v: |
| 5450 | case NEON::BI__builtin_neon_vrndpq_v: { |
| 5451 | Int = Intrinsic::ceil; |
| 5452 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndp"); |
| 5453 | } |
| 5454 | case NEON::BI__builtin_neon_vrndx_v: |
| 5455 | case NEON::BI__builtin_neon_vrndxq_v: { |
| 5456 | Int = Intrinsic::rint; |
| 5457 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndx"); |
| 5458 | } |
| 5459 | case NEON::BI__builtin_neon_vrnd_v: |
| 5460 | case NEON::BI__builtin_neon_vrndq_v: { |
| 5461 | Int = Intrinsic::trunc; |
| 5462 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndz"); |
| 5463 | } |
| 5464 | case NEON::BI__builtin_neon_vceqz_v: |
| 5465 | case NEON::BI__builtin_neon_vceqzq_v: |
| 5466 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OEQ, |
| 5467 | ICmpInst::ICMP_EQ, "vceqz"); |
| 5468 | case NEON::BI__builtin_neon_vcgez_v: |
| 5469 | case NEON::BI__builtin_neon_vcgezq_v: |
| 5470 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGE, |
| 5471 | ICmpInst::ICMP_SGE, "vcgez"); |
| 5472 | case NEON::BI__builtin_neon_vclez_v: |
| 5473 | case NEON::BI__builtin_neon_vclezq_v: |
| 5474 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLE, |
| 5475 | ICmpInst::ICMP_SLE, "vclez"); |
| 5476 | case NEON::BI__builtin_neon_vcgtz_v: |
| 5477 | case NEON::BI__builtin_neon_vcgtzq_v: |
| 5478 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGT, |
| 5479 | ICmpInst::ICMP_SGT, "vcgtz"); |
| 5480 | case NEON::BI__builtin_neon_vcltz_v: |
| 5481 | case NEON::BI__builtin_neon_vcltzq_v: |
| 5482 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLT, |
| 5483 | ICmpInst::ICMP_SLT, "vcltz"); |
| 5484 | case NEON::BI__builtin_neon_vcvt_f64_v: |
| 5485 | case NEON::BI__builtin_neon_vcvtq_f64_v: |
| 5486 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5487 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float64, false, quad)); |
| 5488 | return usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 5489 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 5490 | case NEON::BI__builtin_neon_vcvt_f64_f32: { |
| 5491 | assert(Type.getEltType() == NeonTypeFlags::Float64 && quad && |
| 5492 | "unexpected vcvt_f64_f32 builtin"); |
| 5493 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float32, false, false); |
| 5494 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 5495 | |
| 5496 | return Builder.CreateFPExt(Ops[0], Ty, "vcvt"); |
| 5497 | } |
| 5498 | case NEON::BI__builtin_neon_vcvt_f32_f64: { |
| 5499 | assert(Type.getEltType() == NeonTypeFlags::Float32 && |
| 5500 | "unexpected vcvt_f32_f64 builtin"); |
| 5501 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float64, false, true); |
| 5502 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 5503 | |
| 5504 | return Builder.CreateFPTrunc(Ops[0], Ty, "vcvt"); |
| 5505 | } |
| 5506 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 5507 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 5508 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 5509 | case NEON::BI__builtin_neon_vcvt_u64_v: |
| 5510 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 5511 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 5512 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
| 5513 | case NEON::BI__builtin_neon_vcvtq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5514 | Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5515 | if (usgn) |
| 5516 | return Builder.CreateFPToUI(Ops[0], Ty); |
| 5517 | return Builder.CreateFPToSI(Ops[0], Ty); |
| 5518 | } |
| 5519 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 5520 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 5521 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 5522 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 5523 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 5524 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 5525 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 5526 | case NEON::BI__builtin_neon_vcvtaq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5527 | Int = usgn ? Intrinsic::aarch64_neon_fcvtau : Intrinsic::aarch64_neon_fcvtas; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5528 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5529 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvta"); |
| 5530 | } |
| 5531 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 5532 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 5533 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 5534 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 5535 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 5536 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 5537 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 5538 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5539 | Int = usgn ? Intrinsic::aarch64_neon_fcvtmu : Intrinsic::aarch64_neon_fcvtms; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5540 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5541 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtm"); |
| 5542 | } |
| 5543 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 5544 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 5545 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 5546 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 5547 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 5548 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 5549 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 5550 | case NEON::BI__builtin_neon_vcvtnq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5551 | Int = usgn ? Intrinsic::aarch64_neon_fcvtnu : Intrinsic::aarch64_neon_fcvtns; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5552 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5553 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtn"); |
| 5554 | } |
| 5555 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 5556 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 5557 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 5558 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 5559 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 5560 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 5561 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 5562 | case NEON::BI__builtin_neon_vcvtpq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5563 | Int = usgn ? Intrinsic::aarch64_neon_fcvtpu : Intrinsic::aarch64_neon_fcvtps; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5564 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5565 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtp"); |
| 5566 | } |
| 5567 | case NEON::BI__builtin_neon_vmulx_v: |
| 5568 | case NEON::BI__builtin_neon_vmulxq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5569 | Int = Intrinsic::aarch64_neon_fmulx; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5570 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmulx"); |
| 5571 | } |
| 5572 | case NEON::BI__builtin_neon_vmul_lane_v: |
| 5573 | case NEON::BI__builtin_neon_vmul_laneq_v: { |
| 5574 | // v1f64 vmul_lane should be mapped to Neon scalar mul lane |
| 5575 | bool Quad = false; |
| 5576 | if (BuiltinID == NEON::BI__builtin_neon_vmul_laneq_v) |
| 5577 | Quad = true; |
| 5578 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5579 | llvm::Type *VTy = GetNeonType(this, |
| 5580 | NeonTypeFlags(NeonTypeFlags::Float64, false, Quad)); |
| 5581 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 5582 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2], "extract"); |
| 5583 | Value *Result = Builder.CreateFMul(Ops[0], Ops[1]); |
| 5584 | return Builder.CreateBitCast(Result, Ty); |
| 5585 | } |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5586 | case NEON::BI__builtin_neon_vnegd_s64: |
| 5587 | return Builder.CreateNeg(EmitScalarExpr(E->getArg(0)), "vnegd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5588 | case NEON::BI__builtin_neon_vpmaxnm_v: |
| 5589 | case NEON::BI__builtin_neon_vpmaxnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5590 | Int = Intrinsic::aarch64_neon_fmaxnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5591 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmaxnm"); |
| 5592 | } |
| 5593 | case NEON::BI__builtin_neon_vpminnm_v: |
| 5594 | case NEON::BI__builtin_neon_vpminnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5595 | Int = Intrinsic::aarch64_neon_fminnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5596 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpminnm"); |
| 5597 | } |
| 5598 | case NEON::BI__builtin_neon_vsqrt_v: |
| 5599 | case NEON::BI__builtin_neon_vsqrtq_v: { |
| 5600 | Int = Intrinsic::sqrt; |
| 5601 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5602 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqrt"); |
| 5603 | } |
| 5604 | case NEON::BI__builtin_neon_vrbit_v: |
| 5605 | case NEON::BI__builtin_neon_vrbitq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5606 | Int = Intrinsic::aarch64_neon_rbit; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5607 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrbit"); |
| 5608 | } |
| 5609 | case NEON::BI__builtin_neon_vaddv_u8: |
| 5610 | // FIXME: These are handled by the AArch64 scalar code. |
| 5611 | usgn = true; |
| 5612 | // FALLTHROUGH |
| 5613 | case NEON::BI__builtin_neon_vaddv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5614 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5615 | Ty = Int32Ty; |
| 5616 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5617 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5618 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5619 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5620 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5621 | } |
| 5622 | case NEON::BI__builtin_neon_vaddv_u16: |
| 5623 | usgn = true; |
| 5624 | // FALLTHROUGH |
| 5625 | case NEON::BI__builtin_neon_vaddv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5626 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5627 | Ty = Int32Ty; |
| 5628 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5629 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5630 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5631 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5632 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5633 | } |
| 5634 | case NEON::BI__builtin_neon_vaddvq_u8: |
| 5635 | usgn = true; |
| 5636 | // FALLTHROUGH |
| 5637 | case NEON::BI__builtin_neon_vaddvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5638 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5639 | Ty = Int32Ty; |
| 5640 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5641 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5642 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5643 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5644 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5645 | } |
| 5646 | case NEON::BI__builtin_neon_vaddvq_u16: |
| 5647 | usgn = true; |
| 5648 | // FALLTHROUGH |
| 5649 | case NEON::BI__builtin_neon_vaddvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5650 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5651 | Ty = Int32Ty; |
| 5652 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5653 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5654 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5655 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5656 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5657 | } |
| 5658 | case NEON::BI__builtin_neon_vmaxv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5659 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5660 | Ty = Int32Ty; |
| 5661 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5662 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5663 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5664 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5665 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5666 | } |
| 5667 | case NEON::BI__builtin_neon_vmaxv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5668 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5669 | Ty = Int32Ty; |
| 5670 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5671 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5672 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5673 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5674 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5675 | } |
| 5676 | case NEON::BI__builtin_neon_vmaxvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5677 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5678 | Ty = Int32Ty; |
| 5679 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5680 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5681 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5682 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5683 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5684 | } |
| 5685 | case NEON::BI__builtin_neon_vmaxvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5686 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5687 | Ty = Int32Ty; |
| 5688 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5689 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5690 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5691 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5692 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5693 | } |
| 5694 | case NEON::BI__builtin_neon_vmaxv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5695 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5696 | Ty = Int32Ty; |
| 5697 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5698 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5699 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5700 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5701 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5702 | } |
| 5703 | case NEON::BI__builtin_neon_vmaxv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5704 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5705 | Ty = Int32Ty; |
| 5706 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5707 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5708 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5709 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5710 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5711 | } |
| 5712 | case NEON::BI__builtin_neon_vmaxvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5713 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5714 | Ty = Int32Ty; |
| 5715 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5716 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5717 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5718 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5719 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5720 | } |
| 5721 | case NEON::BI__builtin_neon_vmaxvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5722 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5723 | Ty = Int32Ty; |
| 5724 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5725 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5726 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5727 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5728 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5729 | } |
| 5730 | case NEON::BI__builtin_neon_vminv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5731 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5732 | Ty = Int32Ty; |
| 5733 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5734 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5735 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5736 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5737 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5738 | } |
| 5739 | case NEON::BI__builtin_neon_vminv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5740 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5741 | Ty = Int32Ty; |
| 5742 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5743 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5744 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5745 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5746 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5747 | } |
| 5748 | case NEON::BI__builtin_neon_vminvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5749 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5750 | Ty = Int32Ty; |
| 5751 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5752 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5753 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5754 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5755 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5756 | } |
| 5757 | case NEON::BI__builtin_neon_vminvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5758 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5759 | Ty = Int32Ty; |
| 5760 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5761 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5762 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5763 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5764 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5765 | } |
| 5766 | case NEON::BI__builtin_neon_vminv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5767 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5768 | Ty = Int32Ty; |
| 5769 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5770 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5771 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5772 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5773 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5774 | } |
| 5775 | case NEON::BI__builtin_neon_vminv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5776 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5777 | Ty = Int32Ty; |
| 5778 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5779 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5780 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5781 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5782 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5783 | } |
| 5784 | case NEON::BI__builtin_neon_vminvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5785 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5786 | Ty = Int32Ty; |
| 5787 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5788 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5789 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5790 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5791 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5792 | } |
| 5793 | case NEON::BI__builtin_neon_vminvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5794 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5795 | Ty = Int32Ty; |
| 5796 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5797 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5798 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5799 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5800 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5801 | } |
| 5802 | case NEON::BI__builtin_neon_vmul_n_f64: { |
| 5803 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5804 | Value *RHS = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), DoubleTy); |
| 5805 | return Builder.CreateFMul(Ops[0], RHS); |
| 5806 | } |
| 5807 | case NEON::BI__builtin_neon_vaddlv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5808 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5809 | Ty = Int32Ty; |
| 5810 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5811 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5812 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5813 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5814 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5815 | } |
| 5816 | case NEON::BI__builtin_neon_vaddlv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5817 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5818 | Ty = Int32Ty; |
| 5819 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5820 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5821 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5822 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5823 | } |
| 5824 | case NEON::BI__builtin_neon_vaddlvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5825 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5826 | Ty = Int32Ty; |
| 5827 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5828 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5829 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5830 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5831 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5832 | } |
| 5833 | case NEON::BI__builtin_neon_vaddlvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5834 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5835 | Ty = Int32Ty; |
| 5836 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5837 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5838 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5839 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5840 | } |
| 5841 | case NEON::BI__builtin_neon_vaddlv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5842 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5843 | Ty = Int32Ty; |
| 5844 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5845 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5846 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5847 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5848 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5849 | } |
| 5850 | case NEON::BI__builtin_neon_vaddlv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5851 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5852 | Ty = Int32Ty; |
| 5853 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5854 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5855 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5856 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5857 | } |
| 5858 | case NEON::BI__builtin_neon_vaddlvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5859 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5860 | Ty = Int32Ty; |
| 5861 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5862 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5863 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5864 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5865 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5866 | } |
| 5867 | case NEON::BI__builtin_neon_vaddlvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5868 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5869 | Ty = Int32Ty; |
| 5870 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5871 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 5872 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5873 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 5874 | } |
| 5875 | case NEON::BI__builtin_neon_vsri_n_v: |
| 5876 | case NEON::BI__builtin_neon_vsriq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5877 | Int = Intrinsic::aarch64_neon_vsri; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5878 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 5879 | return EmitNeonCall(Intrin, Ops, "vsri_n"); |
| 5880 | } |
| 5881 | case NEON::BI__builtin_neon_vsli_n_v: |
| 5882 | case NEON::BI__builtin_neon_vsliq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5883 | Int = Intrinsic::aarch64_neon_vsli; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5884 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 5885 | return EmitNeonCall(Intrin, Ops, "vsli_n"); |
| 5886 | } |
| 5887 | case NEON::BI__builtin_neon_vsra_n_v: |
| 5888 | case NEON::BI__builtin_neon_vsraq_n_v: |
| 5889 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5890 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
| 5891 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 5892 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 5893 | case NEON::BI__builtin_neon_vrsraq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5894 | Int = usgn ? Intrinsic::aarch64_neon_urshl : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5895 | SmallVector<llvm::Value*,2> TmpOps; |
| 5896 | TmpOps.push_back(Ops[1]); |
| 5897 | TmpOps.push_back(Ops[2]); |
| 5898 | Function* F = CGM.getIntrinsic(Int, Ty); |
| 5899 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vrshr_n", 1, true); |
| 5900 | Ops[0] = Builder.CreateBitCast(Ops[0], VTy); |
| 5901 | return Builder.CreateAdd(Ops[0], tmp); |
| 5902 | } |
| 5903 | // FIXME: Sharing loads & stores with 32-bit is complicated by the absence |
| 5904 | // of an Align parameter here. |
| 5905 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 5906 | case NEON::BI__builtin_neon_vld1q_x2_v: |
| 5907 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 5908 | case NEON::BI__builtin_neon_vld1q_x3_v: |
| 5909 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 5910 | case NEON::BI__builtin_neon_vld1q_x4_v: { |
| 5911 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 5912 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5913 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 5914 | unsigned Int; |
| 5915 | switch (BuiltinID) { |
| 5916 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 5917 | case NEON::BI__builtin_neon_vld1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5918 | Int = Intrinsic::aarch64_neon_ld1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5919 | break; |
| 5920 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 5921 | case NEON::BI__builtin_neon_vld1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5922 | Int = Intrinsic::aarch64_neon_ld1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5923 | break; |
| 5924 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 5925 | case NEON::BI__builtin_neon_vld1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5926 | Int = Intrinsic::aarch64_neon_ld1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5927 | break; |
| 5928 | } |
| 5929 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 5930 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld1xN"); |
| 5931 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5932 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5933 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5934 | } |
| 5935 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 5936 | case NEON::BI__builtin_neon_vst1q_x2_v: |
| 5937 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 5938 | case NEON::BI__builtin_neon_vst1q_x3_v: |
| 5939 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 5940 | case NEON::BI__builtin_neon_vst1q_x4_v: { |
| 5941 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 5942 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 5943 | unsigned Int; |
| 5944 | switch (BuiltinID) { |
| 5945 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 5946 | case NEON::BI__builtin_neon_vst1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5947 | Int = Intrinsic::aarch64_neon_st1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5948 | break; |
| 5949 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 5950 | case NEON::BI__builtin_neon_vst1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5951 | Int = Intrinsic::aarch64_neon_st1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5952 | break; |
| 5953 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 5954 | case NEON::BI__builtin_neon_vst1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5955 | Int = Intrinsic::aarch64_neon_st1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5956 | break; |
| 5957 | } |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5958 | std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end()); |
| 5959 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, ""); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5960 | } |
| 5961 | case NEON::BI__builtin_neon_vld1_v: |
| 5962 | case NEON::BI__builtin_neon_vld1q_v: |
| 5963 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5964 | return Builder.CreateDefaultAlignedLoad(Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5965 | case NEON::BI__builtin_neon_vst1_v: |
| 5966 | case NEON::BI__builtin_neon_vst1q_v: |
| 5967 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
| 5968 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5969 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5970 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 5971 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 5972 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5973 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5974 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5975 | Ops[0] = Builder.CreateDefaultAlignedLoad(Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5976 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane"); |
| 5977 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 5978 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 5979 | Value *V = UndefValue::get(Ty); |
| 5980 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 5981 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5982 | Ops[0] = Builder.CreateDefaultAlignedLoad(Ops[0]); |
Michael J. Spencer | 5ce2668 | 2014-06-02 19:48:59 +0000 | [diff] [blame] | 5983 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5984 | Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI); |
| 5985 | return EmitNeonSplat(Ops[0], CI); |
| 5986 | } |
| 5987 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 5988 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 5989 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5990 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 5991 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5992 | return Builder.CreateDefaultAlignedStore(Ops[1], |
| 5993 | Builder.CreateBitCast(Ops[0], Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5994 | case NEON::BI__builtin_neon_vld2_v: |
| 5995 | case NEON::BI__builtin_neon_vld2q_v: { |
| 5996 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 5997 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 5998 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5999 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6000 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 6001 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6002 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6003 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6004 | } |
| 6005 | case NEON::BI__builtin_neon_vld3_v: |
| 6006 | case NEON::BI__builtin_neon_vld3q_v: { |
| 6007 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 6008 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6009 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6010 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6011 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 6012 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6013 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6014 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6015 | } |
| 6016 | case NEON::BI__builtin_neon_vld4_v: |
| 6017 | case NEON::BI__builtin_neon_vld4q_v: { |
| 6018 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 6019 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6020 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6021 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6022 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 6023 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6024 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6025 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6026 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 6027 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 6028 | case NEON::BI__builtin_neon_vld2q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6029 | llvm::Type *PTy = |
| 6030 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6031 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6032 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6033 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6034 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 6035 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6036 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6037 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6038 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 6039 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 6040 | case NEON::BI__builtin_neon_vld3q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6041 | llvm::Type *PTy = |
| 6042 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6043 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6044 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6045 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6046 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 6047 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6048 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6049 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6050 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 6051 | case NEON::BI__builtin_neon_vld4_dup_v: |
| 6052 | case NEON::BI__builtin_neon_vld4q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6053 | llvm::Type *PTy = |
| 6054 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6055 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6056 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6057 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6058 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 6059 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6060 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6061 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6062 | } |
| 6063 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 6064 | case NEON::BI__builtin_neon_vld2q_lane_v: { |
| 6065 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6066 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6067 | Ops.push_back(Ops[1]); |
| 6068 | Ops.erase(Ops.begin()+1); |
| 6069 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6070 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6071 | Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6072 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld2_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6073 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6074 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6075 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6076 | } |
| 6077 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 6078 | case NEON::BI__builtin_neon_vld3q_lane_v: { |
| 6079 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6080 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6081 | Ops.push_back(Ops[1]); |
| 6082 | Ops.erase(Ops.begin()+1); |
| 6083 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6084 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 6085 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6086 | Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6087 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld3_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6088 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6089 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6090 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6091 | } |
| 6092 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 6093 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
| 6094 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6095 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6096 | Ops.push_back(Ops[1]); |
| 6097 | Ops.erase(Ops.begin()+1); |
| 6098 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6099 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 6100 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 6101 | Ops[4] = Builder.CreateBitCast(Ops[4], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6102 | Ops[5] = Builder.CreateZExt(Ops[5], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6103 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld4_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6104 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6105 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6106 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6107 | } |
| 6108 | case NEON::BI__builtin_neon_vst2_v: |
| 6109 | case NEON::BI__builtin_neon_vst2q_v: { |
| 6110 | Ops.push_back(Ops[0]); |
| 6111 | Ops.erase(Ops.begin()); |
| 6112 | llvm::Type *Tys[2] = { VTy, Ops[2]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6113 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6114 | Ops, ""); |
| 6115 | } |
| 6116 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 6117 | case NEON::BI__builtin_neon_vst2q_lane_v: { |
| 6118 | Ops.push_back(Ops[0]); |
| 6119 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6120 | Ops[2] = Builder.CreateZExt(Ops[2], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6121 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6122 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6123 | Ops, ""); |
| 6124 | } |
| 6125 | case NEON::BI__builtin_neon_vst3_v: |
| 6126 | case NEON::BI__builtin_neon_vst3q_v: { |
| 6127 | Ops.push_back(Ops[0]); |
| 6128 | Ops.erase(Ops.begin()); |
| 6129 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6130 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6131 | Ops, ""); |
| 6132 | } |
| 6133 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 6134 | case NEON::BI__builtin_neon_vst3q_lane_v: { |
| 6135 | Ops.push_back(Ops[0]); |
| 6136 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6137 | Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6138 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6139 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6140 | Ops, ""); |
| 6141 | } |
| 6142 | case NEON::BI__builtin_neon_vst4_v: |
| 6143 | case NEON::BI__builtin_neon_vst4q_v: { |
| 6144 | Ops.push_back(Ops[0]); |
| 6145 | Ops.erase(Ops.begin()); |
| 6146 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6147 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6148 | Ops, ""); |
| 6149 | } |
| 6150 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 6151 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 6152 | Ops.push_back(Ops[0]); |
| 6153 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6154 | Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6155 | llvm::Type *Tys[2] = { VTy, Ops[5]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6156 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6157 | Ops, ""); |
| 6158 | } |
| 6159 | case NEON::BI__builtin_neon_vtrn_v: |
| 6160 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 6161 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 6162 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6163 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6164 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6165 | |
| 6166 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 6167 | SmallVector<Constant*, 16> Indices; |
| 6168 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 6169 | Indices.push_back(ConstantInt::get(Int32Ty, i+vi)); |
| 6170 | Indices.push_back(ConstantInt::get(Int32Ty, i+e+vi)); |
| 6171 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 6172 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6173 | SV = llvm::ConstantVector::get(Indices); |
| 6174 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vtrn"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6175 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6176 | } |
| 6177 | return SV; |
| 6178 | } |
| 6179 | case NEON::BI__builtin_neon_vuzp_v: |
| 6180 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 6181 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 6182 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6183 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6184 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6185 | |
| 6186 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 6187 | SmallVector<Constant*, 16> Indices; |
| 6188 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
| 6189 | Indices.push_back(ConstantInt::get(Int32Ty, 2*i+vi)); |
| 6190 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 6191 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6192 | SV = llvm::ConstantVector::get(Indices); |
| 6193 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vuzp"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6194 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6195 | } |
| 6196 | return SV; |
| 6197 | } |
| 6198 | case NEON::BI__builtin_neon_vzip_v: |
| 6199 | case NEON::BI__builtin_neon_vzipq_v: { |
| 6200 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 6201 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6202 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6203 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6204 | |
| 6205 | for (unsigned vi = 0; vi != 2; ++vi) { |
| 6206 | SmallVector<Constant*, 16> Indices; |
| 6207 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
| 6208 | Indices.push_back(ConstantInt::get(Int32Ty, (i + vi*e) >> 1)); |
| 6209 | Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e)); |
| 6210 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 6211 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6212 | SV = llvm::ConstantVector::get(Indices); |
| 6213 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6214 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6215 | } |
| 6216 | return SV; |
| 6217 | } |
| 6218 | case NEON::BI__builtin_neon_vqtbl1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6219 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6220 | Ops, "vtbl1"); |
| 6221 | } |
| 6222 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6223 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6224 | Ops, "vtbl2"); |
| 6225 | } |
| 6226 | case NEON::BI__builtin_neon_vqtbl3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6227 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6228 | Ops, "vtbl3"); |
| 6229 | } |
| 6230 | case NEON::BI__builtin_neon_vqtbl4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6231 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6232 | Ops, "vtbl4"); |
| 6233 | } |
| 6234 | case NEON::BI__builtin_neon_vqtbx1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6235 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6236 | Ops, "vtbx1"); |
| 6237 | } |
| 6238 | case NEON::BI__builtin_neon_vqtbx2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6239 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6240 | Ops, "vtbx2"); |
| 6241 | } |
| 6242 | case NEON::BI__builtin_neon_vqtbx3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6243 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6244 | Ops, "vtbx3"); |
| 6245 | } |
| 6246 | case NEON::BI__builtin_neon_vqtbx4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6247 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6248 | Ops, "vtbx4"); |
| 6249 | } |
| 6250 | case NEON::BI__builtin_neon_vsqadd_v: |
| 6251 | case NEON::BI__builtin_neon_vsqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6252 | Int = Intrinsic::aarch64_neon_usqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6253 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqadd"); |
| 6254 | } |
| 6255 | case NEON::BI__builtin_neon_vuqadd_v: |
| 6256 | case NEON::BI__builtin_neon_vuqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6257 | Int = Intrinsic::aarch64_neon_suqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6258 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vuqadd"); |
| 6259 | } |
| 6260 | } |
| 6261 | } |
| 6262 | |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6263 | llvm::Value *CodeGenFunction:: |
Bill Wendling | f1a3fca | 2012-02-22 09:30:11 +0000 | [diff] [blame] | 6264 | BuildVector(ArrayRef<llvm::Value*> Ops) { |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6265 | assert((Ops.size() & (Ops.size() - 1)) == 0 && |
| 6266 | "Not a power-of-two sized vector!"); |
| 6267 | bool AllConstants = true; |
| 6268 | for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i) |
| 6269 | AllConstants &= isa<Constant>(Ops[i]); |
| 6270 | |
| 6271 | // If this is a constant vector, create a ConstantVector. |
| 6272 | if (AllConstants) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 6273 | SmallVector<llvm::Constant*, 16> CstOps; |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6274 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
| 6275 | CstOps.push_back(cast<Constant>(Ops[i])); |
| 6276 | return llvm::ConstantVector::get(CstOps); |
| 6277 | } |
| 6278 | |
| 6279 | // Otherwise, insertelement the values to build the vector. |
| 6280 | Value *Result = |
| 6281 | llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size())); |
| 6282 | |
| 6283 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 6284 | Result = Builder.CreateInsertElement(Result, Ops[i], Builder.getInt32(i)); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6285 | |
| 6286 | return Result; |
| 6287 | } |
| 6288 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6289 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 6290 | const CallExpr *E) { |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 6291 | if (BuiltinID == X86::BI__builtin_ms_va_start || |
| 6292 | BuiltinID == X86::BI__builtin_ms_va_end) |
| 6293 | return EmitVAStartEnd(EmitMSVAListRef(E->getArg(0)).getPointer(), |
| 6294 | BuiltinID == X86::BI__builtin_ms_va_start); |
| 6295 | if (BuiltinID == X86::BI__builtin_ms_va_copy) { |
| 6296 | // Lower this manually. We can't reliably determine whether or not any |
| 6297 | // given va_copy() is for a Win64 va_list from the calling convention |
| 6298 | // alone, because it's legal to do this from a System V ABI function. |
| 6299 | // With opaque pointer types, we won't have enough information in LLVM |
| 6300 | // IR to determine this from the argument types, either. Best to do it |
| 6301 | // now, while we have enough information. |
| 6302 | Address DestAddr = EmitMSVAListRef(E->getArg(0)); |
| 6303 | Address SrcAddr = EmitMSVAListRef(E->getArg(1)); |
| 6304 | |
| 6305 | llvm::Type *BPP = Int8PtrPtrTy; |
| 6306 | |
| 6307 | DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"), |
| 6308 | DestAddr.getAlignment()); |
| 6309 | SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"), |
| 6310 | SrcAddr.getAlignment()); |
| 6311 | |
| 6312 | Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val"); |
| 6313 | return Builder.CreateStore(ArgPtr, DestAddr); |
| 6314 | } |
| 6315 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6316 | SmallVector<Value*, 4> Ops; |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 6317 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 6318 | // Find out if any arguments are required to be integer constant expressions. |
| 6319 | unsigned ICEArguments = 0; |
| 6320 | ASTContext::GetBuiltinTypeError Error; |
| 6321 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 6322 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 6323 | |
| 6324 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { |
| 6325 | // If this is a normal argument, just emit it as a scalar. |
| 6326 | if ((ICEArguments & (1 << i)) == 0) { |
| 6327 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 6328 | continue; |
| 6329 | } |
| 6330 | |
| 6331 | // If this is required to be a constant, constant fold it so that we know |
| 6332 | // that the generated intrinsic gets a ConstantInt. |
| 6333 | llvm::APSInt Result; |
| 6334 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 6335 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6336 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 6337 | } |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 6338 | |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 6339 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6340 | default: return nullptr; |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 6341 | case X86::BI__builtin_cpu_supports: { |
| 6342 | const Expr *FeatureExpr = E->getArg(0)->IgnoreParenCasts(); |
| 6343 | StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString(); |
| 6344 | |
| 6345 | // TODO: When/if this becomes more than x86 specific then use a TargetInfo |
| 6346 | // based mapping. |
| 6347 | // Processor features and mapping to processor feature value. |
| 6348 | enum X86Features { |
| 6349 | CMOV = 0, |
| 6350 | MMX, |
| 6351 | POPCNT, |
| 6352 | SSE, |
| 6353 | SSE2, |
| 6354 | SSE3, |
| 6355 | SSSE3, |
| 6356 | SSE4_1, |
| 6357 | SSE4_2, |
| 6358 | AVX, |
| 6359 | AVX2, |
| 6360 | SSE4_A, |
| 6361 | FMA4, |
| 6362 | XOP, |
| 6363 | FMA, |
| 6364 | AVX512F, |
| 6365 | BMI, |
| 6366 | BMI2, |
| 6367 | MAX |
| 6368 | }; |
| 6369 | |
| 6370 | X86Features Feature = StringSwitch<X86Features>(FeatureStr) |
| 6371 | .Case("cmov", X86Features::CMOV) |
| 6372 | .Case("mmx", X86Features::MMX) |
| 6373 | .Case("popcnt", X86Features::POPCNT) |
| 6374 | .Case("sse", X86Features::SSE) |
| 6375 | .Case("sse2", X86Features::SSE2) |
| 6376 | .Case("sse3", X86Features::SSE3) |
| 6377 | .Case("sse4.1", X86Features::SSE4_1) |
| 6378 | .Case("sse4.2", X86Features::SSE4_2) |
| 6379 | .Case("avx", X86Features::AVX) |
| 6380 | .Case("avx2", X86Features::AVX2) |
| 6381 | .Case("sse4a", X86Features::SSE4_A) |
| 6382 | .Case("fma4", X86Features::FMA4) |
| 6383 | .Case("xop", X86Features::XOP) |
| 6384 | .Case("fma", X86Features::FMA) |
| 6385 | .Case("avx512f", X86Features::AVX512F) |
| 6386 | .Case("bmi", X86Features::BMI) |
| 6387 | .Case("bmi2", X86Features::BMI2) |
| 6388 | .Default(X86Features::MAX); |
| 6389 | assert(Feature != X86Features::MAX && "Invalid feature!"); |
| 6390 | |
| 6391 | // Matching the struct layout from the compiler-rt/libgcc structure that is |
| 6392 | // filled in: |
| 6393 | // unsigned int __cpu_vendor; |
| 6394 | // unsigned int __cpu_type; |
| 6395 | // unsigned int __cpu_subtype; |
| 6396 | // unsigned int __cpu_features[1]; |
| 6397 | llvm::Type *STy = llvm::StructType::get( |
| 6398 | Int32Ty, Int32Ty, Int32Ty, llvm::ArrayType::get(Int32Ty, 1), nullptr); |
| 6399 | |
| 6400 | // Grab the global __cpu_model. |
| 6401 | llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); |
| 6402 | |
| 6403 | // Grab the first (0th) element from the field __cpu_features off of the |
| 6404 | // global in the struct STy. |
| 6405 | Value *Idxs[] = { |
| 6406 | ConstantInt::get(Int32Ty, 0), |
| 6407 | ConstantInt::get(Int32Ty, 3), |
| 6408 | ConstantInt::get(Int32Ty, 0) |
| 6409 | }; |
| 6410 | Value *CpuFeatures = Builder.CreateGEP(STy, CpuModel, Idxs); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6411 | Value *Features = Builder.CreateAlignedLoad(CpuFeatures, |
| 6412 | CharUnits::fromQuantity(4)); |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 6413 | |
| 6414 | // Check the value of the bit corresponding to the feature requested. |
| 6415 | Value *Bitset = Builder.CreateAnd( |
Aaron Ballman | abd466e | 2016-03-30 21:33:34 +0000 | [diff] [blame] | 6416 | Features, llvm::ConstantInt::get(Int32Ty, 1ULL << Feature)); |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 6417 | return Builder.CreateICmpNE(Bitset, llvm::ConstantInt::get(Int32Ty, 0)); |
| 6418 | } |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 6419 | case X86::BI_mm_prefetch: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6420 | Value *Address = Ops[0]; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 6421 | Value *RW = ConstantInt::get(Int32Ty, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6422 | Value *Locality = Ops[1]; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 6423 | Value *Data = ConstantInt::get(Int32Ty, 1); |
| 6424 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6425 | return Builder.CreateCall(F, {Address, RW, Locality, Data}); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 6426 | } |
Simon Pilgrim | 5aba992 | 2015-08-26 21:17:12 +0000 | [diff] [blame] | 6427 | case X86::BI__builtin_ia32_undef128: |
| 6428 | case X86::BI__builtin_ia32_undef256: |
| 6429 | case X86::BI__builtin_ia32_undef512: |
| 6430 | return UndefValue::get(ConvertType(E->getType())); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6431 | case X86::BI__builtin_ia32_vec_init_v8qi: |
| 6432 | case X86::BI__builtin_ia32_vec_init_v4hi: |
| 6433 | case X86::BI__builtin_ia32_vec_init_v2si: |
| 6434 | return Builder.CreateBitCast(BuildVector(Ops), |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6435 | llvm::Type::getX86_MMXTy(getLLVMContext())); |
Argyrios Kyrtzidis | 073c9cb | 2010-10-10 03:19:11 +0000 | [diff] [blame] | 6436 | case X86::BI__builtin_ia32_vec_ext_v2si: |
| 6437 | return Builder.CreateExtractElement(Ops[0], |
| 6438 | llvm::ConstantInt::get(Ops[1]->getType(), 0)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6439 | case X86::BI__builtin_ia32_ldmxcsr: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6440 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6441 | Builder.CreateStore(Ops[0], Tmp); |
| 6442 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6443 | Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6444 | } |
| 6445 | case X86::BI__builtin_ia32_stmxcsr: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6446 | Address Tmp = CreateMemTemp(E->getType()); |
Ted Kremenek | c14efa7 | 2011-08-17 21:04:19 +0000 | [diff] [blame] | 6447 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6448 | Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6449 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 6450 | } |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 6451 | case X86::BI__builtin_ia32_xsave: |
| 6452 | case X86::BI__builtin_ia32_xsave64: |
| 6453 | case X86::BI__builtin_ia32_xrstor: |
| 6454 | case X86::BI__builtin_ia32_xrstor64: |
| 6455 | case X86::BI__builtin_ia32_xsaveopt: |
| 6456 | case X86::BI__builtin_ia32_xsaveopt64: |
| 6457 | case X86::BI__builtin_ia32_xrstors: |
| 6458 | case X86::BI__builtin_ia32_xrstors64: |
| 6459 | case X86::BI__builtin_ia32_xsavec: |
| 6460 | case X86::BI__builtin_ia32_xsavec64: |
| 6461 | case X86::BI__builtin_ia32_xsaves: |
| 6462 | case X86::BI__builtin_ia32_xsaves64: { |
| 6463 | Intrinsic::ID ID; |
| 6464 | #define INTRINSIC_X86_XSAVE_ID(NAME) \ |
| 6465 | case X86::BI__builtin_ia32_##NAME: \ |
| 6466 | ID = Intrinsic::x86_##NAME; \ |
| 6467 | break |
| 6468 | switch (BuiltinID) { |
| 6469 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6470 | INTRINSIC_X86_XSAVE_ID(xsave); |
| 6471 | INTRINSIC_X86_XSAVE_ID(xsave64); |
| 6472 | INTRINSIC_X86_XSAVE_ID(xrstor); |
| 6473 | INTRINSIC_X86_XSAVE_ID(xrstor64); |
| 6474 | INTRINSIC_X86_XSAVE_ID(xsaveopt); |
| 6475 | INTRINSIC_X86_XSAVE_ID(xsaveopt64); |
| 6476 | INTRINSIC_X86_XSAVE_ID(xrstors); |
| 6477 | INTRINSIC_X86_XSAVE_ID(xrstors64); |
| 6478 | INTRINSIC_X86_XSAVE_ID(xsavec); |
| 6479 | INTRINSIC_X86_XSAVE_ID(xsavec64); |
| 6480 | INTRINSIC_X86_XSAVE_ID(xsaves); |
| 6481 | INTRINSIC_X86_XSAVE_ID(xsaves64); |
| 6482 | } |
| 6483 | #undef INTRINSIC_X86_XSAVE_ID |
| 6484 | Value *Mhi = Builder.CreateTrunc( |
| 6485 | Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, 32)), Int32Ty); |
| 6486 | Value *Mlo = Builder.CreateTrunc(Ops[1], Int32Ty); |
| 6487 | Ops[1] = Mhi; |
| 6488 | Ops.push_back(Mlo); |
| 6489 | return Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 6490 | } |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6491 | case X86::BI__builtin_ia32_storehps: |
| 6492 | case X86::BI__builtin_ia32_storelps: { |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 6493 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(Int64Ty); |
| 6494 | llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6495 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6496 | // cast val v2i64 |
| 6497 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6498 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6499 | // extract (0, 1) |
| 6500 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6501 | llvm::Value *Idx = llvm::ConstantInt::get(SizeTy, Index); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6502 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 6503 | |
| 6504 | // cast pointer to i64 & store |
| 6505 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6506 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 6507 | } |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6508 | case X86::BI__builtin_ia32_palignr128: |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6509 | case X86::BI__builtin_ia32_palignr256: { |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6510 | unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6511 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6512 | unsigned NumElts = |
| 6513 | cast<llvm::VectorType>(Ops[0]->getType())->getNumElements(); |
| 6514 | assert(NumElts % 16 == 0); |
| 6515 | unsigned NumLanes = NumElts / 16; |
| 6516 | unsigned NumLaneElts = NumElts / NumLanes; |
| 6517 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6518 | // If palignr is shifting the pair of vectors more than the size of two |
| 6519 | // lanes, emit zero. |
| 6520 | if (ShiftVal >= (2 * NumLaneElts)) |
| 6521 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6522 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 6523 | // 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] | 6524 | // but less than two lanes, convert to shifting in zeroes. |
| 6525 | if (ShiftVal > NumLaneElts) { |
| 6526 | ShiftVal -= NumLaneElts; |
Benjamin Kramer | b596056 | 2015-07-20 15:31:17 +0000 | [diff] [blame] | 6527 | Ops[1] = Ops[0]; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 6528 | Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType()); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6529 | } |
| 6530 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6531 | uint32_t Indices[32]; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 6532 | // 256-bit palignr operates on 128-bit lanes so we need to handle that |
| 6533 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
| 6534 | for (unsigned i = 0; i != NumLaneElts; ++i) { |
| 6535 | unsigned Idx = ShiftVal + i; |
| 6536 | if (Idx >= NumLaneElts) |
| 6537 | Idx += NumElts - NumLaneElts; // End of lane, switch operand. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6538 | Indices[l + i] = Idx + l; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 6539 | } |
| 6540 | } |
| 6541 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6542 | Value *SV = llvm::ConstantDataVector::get(getLLVMContext(), |
| 6543 | makeArrayRef(Indices, NumElts)); |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 6544 | return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr"); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 6545 | } |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6546 | case X86::BI__builtin_ia32_pslldqi256: { |
| 6547 | // Shift value is in bits so divide by 8. |
| 6548 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() >> 3; |
| 6549 | |
| 6550 | // If pslldq is shifting the vector more than 15 bytes, emit zero. |
| 6551 | if (shiftVal >= 16) |
| 6552 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
| 6553 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6554 | uint32_t Indices[32]; |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6555 | // 256-bit pslldq operates on 128-bit lanes so we need to handle that |
| 6556 | for (unsigned l = 0; l != 32; l += 16) { |
| 6557 | for (unsigned i = 0; i != 16; ++i) { |
| 6558 | unsigned Idx = 32 + i - shiftVal; |
| 6559 | if (Idx < 32) Idx -= 16; // end of lane, switch operand. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6560 | Indices[l + i] = Idx + l; |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | llvm::Type *VecTy = llvm::VectorType::get(Int8Ty, 32); |
| 6565 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 6566 | Value *Zero = llvm::Constant::getNullValue(VecTy); |
| 6567 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6568 | Value *SV = llvm::ConstantDataVector::get(getLLVMContext(), Indices); |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6569 | SV = Builder.CreateShuffleVector(Zero, Ops[0], SV, "pslldq"); |
| 6570 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6571 | return Builder.CreateBitCast(SV, ResultType, "cast"); |
| 6572 | } |
| 6573 | case X86::BI__builtin_ia32_psrldqi256: { |
| 6574 | // Shift value is in bits so divide by 8. |
| 6575 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() >> 3; |
| 6576 | |
| 6577 | // If psrldq is shifting the vector more than 15 bytes, emit zero. |
| 6578 | if (shiftVal >= 16) |
| 6579 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
| 6580 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6581 | uint32_t Indices[32]; |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6582 | // 256-bit psrldq operates on 128-bit lanes so we need to handle that |
| 6583 | for (unsigned l = 0; l != 32; l += 16) { |
| 6584 | for (unsigned i = 0; i != 16; ++i) { |
| 6585 | unsigned Idx = i + shiftVal; |
| 6586 | if (Idx >= 16) Idx += 16; // end of lane, switch operand. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6587 | Indices[l + i] = Idx + l; |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | llvm::Type *VecTy = llvm::VectorType::get(Int8Ty, 32); |
| 6592 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 6593 | Value *Zero = llvm::Constant::getNullValue(VecTy); |
| 6594 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6595 | Value *SV = llvm::ConstantDataVector::get(getLLVMContext(), Indices); |
Craig Topper | 370644f | 2015-02-16 00:42:49 +0000 | [diff] [blame] | 6596 | SV = Builder.CreateShuffleVector(Ops[0], Zero, SV, "psrldq"); |
| 6597 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6598 | return Builder.CreateBitCast(SV, ResultType, "cast"); |
| 6599 | } |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6600 | case X86::BI__builtin_ia32_movntps: |
Craig Topper | c83dff0 | 2012-05-07 06:25:45 +0000 | [diff] [blame] | 6601 | case X86::BI__builtin_ia32_movntps256: |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6602 | case X86::BI__builtin_ia32_movntpd: |
Craig Topper | c83dff0 | 2012-05-07 06:25:45 +0000 | [diff] [blame] | 6603 | case X86::BI__builtin_ia32_movntpd256: |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6604 | case X86::BI__builtin_ia32_movntdq: |
Craig Topper | c83dff0 | 2012-05-07 06:25:45 +0000 | [diff] [blame] | 6605 | case X86::BI__builtin_ia32_movntdq256: |
Eli Friedman | f9d8c6c | 2013-09-23 23:38:39 +0000 | [diff] [blame] | 6606 | case X86::BI__builtin_ia32_movnti: |
| 6607 | case X86::BI__builtin_ia32_movnti64: { |
Duncan P. N. Exon Smith | fb49491 | 2014-12-09 18:39:32 +0000 | [diff] [blame] | 6608 | llvm::MDNode *Node = llvm::MDNode::get( |
| 6609 | getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1))); |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6610 | |
| 6611 | // Convert the type of the pointer to a pointer to the stored type. |
| 6612 | Value *BC = Builder.CreateBitCast(Ops[0], |
| 6613 | llvm::PointerType::getUnqual(Ops[1]->getType()), |
| 6614 | "cast"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6615 | StoreInst *SI = Builder.CreateDefaultAlignedStore(Ops[1], BC); |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6616 | SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); |
Eli Friedman | f9d8c6c | 2013-09-23 23:38:39 +0000 | [diff] [blame] | 6617 | |
| 6618 | // If the operand is an integer, we can't assume alignment. Otherwise, |
| 6619 | // assume natural alignment. |
| 6620 | QualType ArgTy = E->getArg(1)->getType(); |
| 6621 | unsigned Align; |
| 6622 | if (ArgTy->isIntegerType()) |
| 6623 | Align = 1; |
| 6624 | else |
| 6625 | Align = getContext().getTypeSizeInChars(ArgTy).getQuantity(); |
| 6626 | SI->setAlignment(Align); |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 6627 | return SI; |
| 6628 | } |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 6629 | // 3DNow! |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 6630 | case X86::BI__builtin_ia32_pswapdsf: |
| 6631 | case X86::BI__builtin_ia32_pswapdsi: { |
Chandler Carruth | a2a5410 | 2012-02-20 07:35:45 +0000 | [diff] [blame] | 6632 | llvm::Type *MMXTy = llvm::Type::getX86_MMXTy(getLLVMContext()); |
| 6633 | Ops[0] = Builder.CreateBitCast(Ops[0], MMXTy, "cast"); |
Craig Topper | d2f814d | 2015-02-16 21:30:08 +0000 | [diff] [blame] | 6634 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_3dnowa_pswapd); |
| 6635 | return Builder.CreateCall(F, Ops, "pswapd"); |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 6636 | } |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6637 | case X86::BI__builtin_ia32_rdrand16_step: |
| 6638 | case X86::BI__builtin_ia32_rdrand32_step: |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 6639 | case X86::BI__builtin_ia32_rdrand64_step: |
| 6640 | case X86::BI__builtin_ia32_rdseed16_step: |
| 6641 | case X86::BI__builtin_ia32_rdseed32_step: |
| 6642 | case X86::BI__builtin_ia32_rdseed64_step: { |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6643 | Intrinsic::ID ID; |
| 6644 | switch (BuiltinID) { |
| 6645 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6646 | case X86::BI__builtin_ia32_rdrand16_step: |
| 6647 | ID = Intrinsic::x86_rdrand_16; |
| 6648 | break; |
| 6649 | case X86::BI__builtin_ia32_rdrand32_step: |
| 6650 | ID = Intrinsic::x86_rdrand_32; |
| 6651 | break; |
| 6652 | case X86::BI__builtin_ia32_rdrand64_step: |
| 6653 | ID = Intrinsic::x86_rdrand_64; |
| 6654 | break; |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 6655 | case X86::BI__builtin_ia32_rdseed16_step: |
| 6656 | ID = Intrinsic::x86_rdseed_16; |
| 6657 | break; |
| 6658 | case X86::BI__builtin_ia32_rdseed32_step: |
| 6659 | ID = Intrinsic::x86_rdseed_32; |
| 6660 | break; |
| 6661 | case X86::BI__builtin_ia32_rdseed64_step: |
| 6662 | ID = Intrinsic::x86_rdseed_64; |
| 6663 | break; |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6664 | } |
| 6665 | |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 6666 | Value *Call = Builder.CreateCall(CGM.getIntrinsic(ID)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6667 | Builder.CreateDefaultAlignedStore(Builder.CreateExtractValue(Call, 0), |
| 6668 | Ops[0]); |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 6669 | return Builder.CreateExtractValue(Call, 1); |
| 6670 | } |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 6671 | // SSE comparison intrisics |
| 6672 | case X86::BI__builtin_ia32_cmpeqps: |
| 6673 | case X86::BI__builtin_ia32_cmpltps: |
| 6674 | case X86::BI__builtin_ia32_cmpleps: |
| 6675 | case X86::BI__builtin_ia32_cmpunordps: |
| 6676 | case X86::BI__builtin_ia32_cmpneqps: |
| 6677 | case X86::BI__builtin_ia32_cmpnltps: |
| 6678 | case X86::BI__builtin_ia32_cmpnleps: |
| 6679 | case X86::BI__builtin_ia32_cmpordps: |
| 6680 | case X86::BI__builtin_ia32_cmpeqss: |
| 6681 | case X86::BI__builtin_ia32_cmpltss: |
| 6682 | case X86::BI__builtin_ia32_cmpless: |
| 6683 | case X86::BI__builtin_ia32_cmpunordss: |
| 6684 | case X86::BI__builtin_ia32_cmpneqss: |
| 6685 | case X86::BI__builtin_ia32_cmpnltss: |
| 6686 | case X86::BI__builtin_ia32_cmpnless: |
| 6687 | case X86::BI__builtin_ia32_cmpordss: |
| 6688 | case X86::BI__builtin_ia32_cmpeqpd: |
| 6689 | case X86::BI__builtin_ia32_cmpltpd: |
| 6690 | case X86::BI__builtin_ia32_cmplepd: |
| 6691 | case X86::BI__builtin_ia32_cmpunordpd: |
| 6692 | case X86::BI__builtin_ia32_cmpneqpd: |
| 6693 | case X86::BI__builtin_ia32_cmpnltpd: |
| 6694 | case X86::BI__builtin_ia32_cmpnlepd: |
| 6695 | case X86::BI__builtin_ia32_cmpordpd: |
| 6696 | case X86::BI__builtin_ia32_cmpeqsd: |
| 6697 | case X86::BI__builtin_ia32_cmpltsd: |
| 6698 | case X86::BI__builtin_ia32_cmplesd: |
| 6699 | case X86::BI__builtin_ia32_cmpunordsd: |
| 6700 | case X86::BI__builtin_ia32_cmpneqsd: |
| 6701 | case X86::BI__builtin_ia32_cmpnltsd: |
| 6702 | case X86::BI__builtin_ia32_cmpnlesd: |
| 6703 | case X86::BI__builtin_ia32_cmpordsd: |
| 6704 | // These exist so that the builtin that takes an immediate can be bounds |
| 6705 | // checked by clang to avoid passing bad immediates to the backend. Since |
| 6706 | // AVX has a larger immediate than SSE we would need separate builtins to |
| 6707 | // do the different bounds checking. Rather than create a clang specific |
| 6708 | // SSE only builtin, this implements eight separate builtins to match gcc |
| 6709 | // implementation. |
| 6710 | |
| 6711 | // Choose the immediate. |
| 6712 | unsigned Imm; |
| 6713 | switch (BuiltinID) { |
| 6714 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6715 | case X86::BI__builtin_ia32_cmpeqps: |
| 6716 | case X86::BI__builtin_ia32_cmpeqss: |
| 6717 | case X86::BI__builtin_ia32_cmpeqpd: |
| 6718 | case X86::BI__builtin_ia32_cmpeqsd: |
| 6719 | Imm = 0; |
| 6720 | break; |
| 6721 | case X86::BI__builtin_ia32_cmpltps: |
| 6722 | case X86::BI__builtin_ia32_cmpltss: |
| 6723 | case X86::BI__builtin_ia32_cmpltpd: |
| 6724 | case X86::BI__builtin_ia32_cmpltsd: |
| 6725 | Imm = 1; |
| 6726 | break; |
| 6727 | case X86::BI__builtin_ia32_cmpleps: |
| 6728 | case X86::BI__builtin_ia32_cmpless: |
| 6729 | case X86::BI__builtin_ia32_cmplepd: |
| 6730 | case X86::BI__builtin_ia32_cmplesd: |
| 6731 | Imm = 2; |
| 6732 | break; |
| 6733 | case X86::BI__builtin_ia32_cmpunordps: |
| 6734 | case X86::BI__builtin_ia32_cmpunordss: |
| 6735 | case X86::BI__builtin_ia32_cmpunordpd: |
| 6736 | case X86::BI__builtin_ia32_cmpunordsd: |
| 6737 | Imm = 3; |
| 6738 | break; |
| 6739 | case X86::BI__builtin_ia32_cmpneqps: |
| 6740 | case X86::BI__builtin_ia32_cmpneqss: |
| 6741 | case X86::BI__builtin_ia32_cmpneqpd: |
| 6742 | case X86::BI__builtin_ia32_cmpneqsd: |
| 6743 | Imm = 4; |
| 6744 | break; |
| 6745 | case X86::BI__builtin_ia32_cmpnltps: |
| 6746 | case X86::BI__builtin_ia32_cmpnltss: |
| 6747 | case X86::BI__builtin_ia32_cmpnltpd: |
| 6748 | case X86::BI__builtin_ia32_cmpnltsd: |
| 6749 | Imm = 5; |
| 6750 | break; |
| 6751 | case X86::BI__builtin_ia32_cmpnleps: |
| 6752 | case X86::BI__builtin_ia32_cmpnless: |
| 6753 | case X86::BI__builtin_ia32_cmpnlepd: |
| 6754 | case X86::BI__builtin_ia32_cmpnlesd: |
| 6755 | Imm = 6; |
| 6756 | break; |
| 6757 | case X86::BI__builtin_ia32_cmpordps: |
| 6758 | case X86::BI__builtin_ia32_cmpordss: |
| 6759 | case X86::BI__builtin_ia32_cmpordpd: |
| 6760 | case X86::BI__builtin_ia32_cmpordsd: |
| 6761 | Imm = 7; |
| 6762 | break; |
| 6763 | } |
| 6764 | |
| 6765 | // Choose the intrinsic ID. |
| 6766 | const char *name; |
| 6767 | Intrinsic::ID ID; |
| 6768 | switch (BuiltinID) { |
| 6769 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 6770 | case X86::BI__builtin_ia32_cmpeqps: |
| 6771 | case X86::BI__builtin_ia32_cmpltps: |
| 6772 | case X86::BI__builtin_ia32_cmpleps: |
| 6773 | case X86::BI__builtin_ia32_cmpunordps: |
| 6774 | case X86::BI__builtin_ia32_cmpneqps: |
| 6775 | case X86::BI__builtin_ia32_cmpnltps: |
| 6776 | case X86::BI__builtin_ia32_cmpnleps: |
| 6777 | case X86::BI__builtin_ia32_cmpordps: |
| 6778 | name = "cmpps"; |
| 6779 | ID = Intrinsic::x86_sse_cmp_ps; |
| 6780 | break; |
| 6781 | case X86::BI__builtin_ia32_cmpeqss: |
| 6782 | case X86::BI__builtin_ia32_cmpltss: |
| 6783 | case X86::BI__builtin_ia32_cmpless: |
| 6784 | case X86::BI__builtin_ia32_cmpunordss: |
| 6785 | case X86::BI__builtin_ia32_cmpneqss: |
| 6786 | case X86::BI__builtin_ia32_cmpnltss: |
| 6787 | case X86::BI__builtin_ia32_cmpnless: |
| 6788 | case X86::BI__builtin_ia32_cmpordss: |
| 6789 | name = "cmpss"; |
| 6790 | ID = Intrinsic::x86_sse_cmp_ss; |
| 6791 | break; |
| 6792 | case X86::BI__builtin_ia32_cmpeqpd: |
| 6793 | case X86::BI__builtin_ia32_cmpltpd: |
| 6794 | case X86::BI__builtin_ia32_cmplepd: |
| 6795 | case X86::BI__builtin_ia32_cmpunordpd: |
| 6796 | case X86::BI__builtin_ia32_cmpneqpd: |
| 6797 | case X86::BI__builtin_ia32_cmpnltpd: |
| 6798 | case X86::BI__builtin_ia32_cmpnlepd: |
| 6799 | case X86::BI__builtin_ia32_cmpordpd: |
| 6800 | name = "cmppd"; |
| 6801 | ID = Intrinsic::x86_sse2_cmp_pd; |
| 6802 | break; |
| 6803 | case X86::BI__builtin_ia32_cmpeqsd: |
| 6804 | case X86::BI__builtin_ia32_cmpltsd: |
| 6805 | case X86::BI__builtin_ia32_cmplesd: |
| 6806 | case X86::BI__builtin_ia32_cmpunordsd: |
| 6807 | case X86::BI__builtin_ia32_cmpneqsd: |
| 6808 | case X86::BI__builtin_ia32_cmpnltsd: |
| 6809 | case X86::BI__builtin_ia32_cmpnlesd: |
| 6810 | case X86::BI__builtin_ia32_cmpordsd: |
| 6811 | name = "cmpsd"; |
| 6812 | ID = Intrinsic::x86_sse2_cmp_sd; |
| 6813 | break; |
| 6814 | } |
| 6815 | |
| 6816 | Ops.push_back(llvm::ConstantInt::get(Int8Ty, Imm)); |
| 6817 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 6818 | return Builder.CreateCall(F, Ops, name); |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 6819 | } |
| 6820 | } |
| 6821 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 6822 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6823 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 6824 | const CallExpr *E) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6825 | SmallVector<Value*, 4> Ops; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6826 | |
| 6827 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 6828 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 6829 | |
| 6830 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 6831 | |
| 6832 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6833 | default: return nullptr; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6834 | |
Hal Finkel | 65e1e4d | 2015-08-31 23:55:19 +0000 | [diff] [blame] | 6835 | // __builtin_ppc_get_timebase is GCC 4.8+'s PowerPC-specific name for what we |
| 6836 | // call __builtin_readcyclecounter. |
| 6837 | case PPC::BI__builtin_ppc_get_timebase: |
| 6838 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::readcyclecounter)); |
| 6839 | |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6840 | // vec_ld, vec_lvsl, vec_lvsr |
| 6841 | case PPC::BI__builtin_altivec_lvx: |
| 6842 | case PPC::BI__builtin_altivec_lvxl: |
| 6843 | case PPC::BI__builtin_altivec_lvebx: |
| 6844 | case PPC::BI__builtin_altivec_lvehx: |
| 6845 | case PPC::BI__builtin_altivec_lvewx: |
| 6846 | case PPC::BI__builtin_altivec_lvsl: |
| 6847 | case PPC::BI__builtin_altivec_lvsr: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6848 | case PPC::BI__builtin_vsx_lxvd2x: |
| 6849 | case PPC::BI__builtin_vsx_lxvw4x: |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6850 | { |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6851 | Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6852 | |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 6853 | Ops[0] = Builder.CreateGEP(Ops[1], Ops[0]); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6854 | Ops.pop_back(); |
| 6855 | |
| 6856 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6857 | default: llvm_unreachable("Unsupported ld/lvsl/lvsr intrinsic!"); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6858 | case PPC::BI__builtin_altivec_lvx: |
| 6859 | ID = Intrinsic::ppc_altivec_lvx; |
| 6860 | break; |
| 6861 | case PPC::BI__builtin_altivec_lvxl: |
| 6862 | ID = Intrinsic::ppc_altivec_lvxl; |
| 6863 | break; |
| 6864 | case PPC::BI__builtin_altivec_lvebx: |
| 6865 | ID = Intrinsic::ppc_altivec_lvebx; |
| 6866 | break; |
| 6867 | case PPC::BI__builtin_altivec_lvehx: |
| 6868 | ID = Intrinsic::ppc_altivec_lvehx; |
| 6869 | break; |
| 6870 | case PPC::BI__builtin_altivec_lvewx: |
| 6871 | ID = Intrinsic::ppc_altivec_lvewx; |
| 6872 | break; |
| 6873 | case PPC::BI__builtin_altivec_lvsl: |
| 6874 | ID = Intrinsic::ppc_altivec_lvsl; |
| 6875 | break; |
| 6876 | case PPC::BI__builtin_altivec_lvsr: |
| 6877 | ID = Intrinsic::ppc_altivec_lvsr; |
| 6878 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6879 | case PPC::BI__builtin_vsx_lxvd2x: |
| 6880 | ID = Intrinsic::ppc_vsx_lxvd2x; |
| 6881 | break; |
| 6882 | case PPC::BI__builtin_vsx_lxvw4x: |
| 6883 | ID = Intrinsic::ppc_vsx_lxvw4x; |
| 6884 | break; |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6885 | } |
| 6886 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 6887 | return Builder.CreateCall(F, Ops, ""); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 6888 | } |
| 6889 | |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6890 | // vec_st |
| 6891 | case PPC::BI__builtin_altivec_stvx: |
| 6892 | case PPC::BI__builtin_altivec_stvxl: |
| 6893 | case PPC::BI__builtin_altivec_stvebx: |
| 6894 | case PPC::BI__builtin_altivec_stvehx: |
| 6895 | case PPC::BI__builtin_altivec_stvewx: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6896 | case PPC::BI__builtin_vsx_stxvd2x: |
| 6897 | case PPC::BI__builtin_vsx_stxvw4x: |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6898 | { |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6899 | Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 6900 | Ops[1] = Builder.CreateGEP(Ops[2], Ops[1]); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6901 | Ops.pop_back(); |
| 6902 | |
| 6903 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6904 | default: llvm_unreachable("Unsupported st intrinsic!"); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6905 | case PPC::BI__builtin_altivec_stvx: |
| 6906 | ID = Intrinsic::ppc_altivec_stvx; |
| 6907 | break; |
| 6908 | case PPC::BI__builtin_altivec_stvxl: |
| 6909 | ID = Intrinsic::ppc_altivec_stvxl; |
| 6910 | break; |
| 6911 | case PPC::BI__builtin_altivec_stvebx: |
| 6912 | ID = Intrinsic::ppc_altivec_stvebx; |
| 6913 | break; |
| 6914 | case PPC::BI__builtin_altivec_stvehx: |
| 6915 | ID = Intrinsic::ppc_altivec_stvehx; |
| 6916 | break; |
| 6917 | case PPC::BI__builtin_altivec_stvewx: |
| 6918 | ID = Intrinsic::ppc_altivec_stvewx; |
| 6919 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 6920 | case PPC::BI__builtin_vsx_stxvd2x: |
| 6921 | ID = Intrinsic::ppc_vsx_stxvd2x; |
| 6922 | break; |
| 6923 | case PPC::BI__builtin_vsx_stxvw4x: |
| 6924 | ID = Intrinsic::ppc_vsx_stxvw4x; |
| 6925 | break; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6926 | } |
| 6927 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 6928 | return Builder.CreateCall(F, Ops, ""); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6929 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 6930 | // Square root |
| 6931 | case PPC::BI__builtin_vsx_xvsqrtsp: |
| 6932 | case PPC::BI__builtin_vsx_xvsqrtdp: { |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 6933 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6934 | Value *X = EmitScalarExpr(E->getArg(0)); |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 6935 | ID = Intrinsic::sqrt; |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 6936 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 6937 | return Builder.CreateCall(F, X); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 6938 | } |
Nemanja Ivanovic | 6c363ed | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 6939 | // Count leading zeros |
| 6940 | case PPC::BI__builtin_altivec_vclzb: |
| 6941 | case PPC::BI__builtin_altivec_vclzh: |
| 6942 | case PPC::BI__builtin_altivec_vclzw: |
| 6943 | case PPC::BI__builtin_altivec_vclzd: { |
| 6944 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6945 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6946 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 6947 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
| 6948 | return Builder.CreateCall(F, {X, Undef}); |
| 6949 | } |
| 6950 | // Copy sign |
| 6951 | case PPC::BI__builtin_vsx_xvcpsgnsp: |
| 6952 | case PPC::BI__builtin_vsx_xvcpsgndp: { |
| 6953 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6954 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6955 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 6956 | ID = Intrinsic::copysign; |
| 6957 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 6958 | return Builder.CreateCall(F, {X, Y}); |
| 6959 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 6960 | // Rounding/truncation |
| 6961 | case PPC::BI__builtin_vsx_xvrspip: |
| 6962 | case PPC::BI__builtin_vsx_xvrdpip: |
| 6963 | case PPC::BI__builtin_vsx_xvrdpim: |
| 6964 | case PPC::BI__builtin_vsx_xvrspim: |
| 6965 | case PPC::BI__builtin_vsx_xvrdpi: |
| 6966 | case PPC::BI__builtin_vsx_xvrspi: |
| 6967 | case PPC::BI__builtin_vsx_xvrdpic: |
| 6968 | case PPC::BI__builtin_vsx_xvrspic: |
| 6969 | case PPC::BI__builtin_vsx_xvrdpiz: |
| 6970 | case PPC::BI__builtin_vsx_xvrspiz: { |
| 6971 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6972 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6973 | if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim || |
| 6974 | BuiltinID == PPC::BI__builtin_vsx_xvrspim) |
| 6975 | ID = Intrinsic::floor; |
| 6976 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi || |
| 6977 | BuiltinID == PPC::BI__builtin_vsx_xvrspi) |
| 6978 | ID = Intrinsic::round; |
| 6979 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic || |
| 6980 | BuiltinID == PPC::BI__builtin_vsx_xvrspic) |
| 6981 | ID = Intrinsic::nearbyint; |
| 6982 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip || |
| 6983 | BuiltinID == PPC::BI__builtin_vsx_xvrspip) |
| 6984 | ID = Intrinsic::ceil; |
| 6985 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz || |
| 6986 | BuiltinID == PPC::BI__builtin_vsx_xvrspiz) |
| 6987 | ID = Intrinsic::trunc; |
| 6988 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 6989 | return Builder.CreateCall(F, X); |
| 6990 | } |
Kit Barton | fbab158 | 2016-03-09 19:28:31 +0000 | [diff] [blame] | 6991 | |
| 6992 | // Absolute value |
| 6993 | case PPC::BI__builtin_vsx_xvabsdp: |
| 6994 | case PPC::BI__builtin_vsx_xvabssp: { |
| 6995 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 6996 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 6997 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 6998 | return Builder.CreateCall(F, X); |
| 6999 | } |
| 7000 | |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 7001 | // FMA variations |
| 7002 | case PPC::BI__builtin_vsx_xvmaddadp: |
| 7003 | case PPC::BI__builtin_vsx_xvmaddasp: |
| 7004 | case PPC::BI__builtin_vsx_xvnmaddadp: |
| 7005 | case PPC::BI__builtin_vsx_xvnmaddasp: |
| 7006 | case PPC::BI__builtin_vsx_xvmsubadp: |
| 7007 | case PPC::BI__builtin_vsx_xvmsubasp: |
| 7008 | case PPC::BI__builtin_vsx_xvnmsubadp: |
| 7009 | case PPC::BI__builtin_vsx_xvnmsubasp: { |
| 7010 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7011 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7012 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7013 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 7014 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 7015 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
| 7016 | switch (BuiltinID) { |
| 7017 | case PPC::BI__builtin_vsx_xvmaddadp: |
| 7018 | case PPC::BI__builtin_vsx_xvmaddasp: |
| 7019 | return Builder.CreateCall(F, {X, Y, Z}); |
| 7020 | case PPC::BI__builtin_vsx_xvnmaddadp: |
| 7021 | case PPC::BI__builtin_vsx_xvnmaddasp: |
| 7022 | return Builder.CreateFSub(Zero, |
| 7023 | Builder.CreateCall(F, {X, Y, Z}), "sub"); |
| 7024 | case PPC::BI__builtin_vsx_xvmsubadp: |
| 7025 | case PPC::BI__builtin_vsx_xvmsubasp: |
| 7026 | return Builder.CreateCall(F, |
| 7027 | {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
| 7028 | case PPC::BI__builtin_vsx_xvnmsubadp: |
| 7029 | case PPC::BI__builtin_vsx_xvnmsubasp: |
| 7030 | Value *FsubRes = |
| 7031 | Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
| 7032 | return Builder.CreateFSub(Zero, FsubRes, "sub"); |
| 7033 | } |
| 7034 | llvm_unreachable("Unknown FMA operation"); |
| 7035 | return nullptr; // Suppress no-return warning |
| 7036 | } |
| 7037 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7038 | } |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7039 | |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 7040 | Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, |
| 7041 | const CallExpr *E) { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7042 | switch (BuiltinID) { |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7043 | case AMDGPU::BI__builtin_amdgcn_div_scale: |
| 7044 | case AMDGPU::BI__builtin_amdgcn_div_scalef: { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7045 | // Translate from the intrinsics's struct return to the builtin's out |
| 7046 | // argument. |
| 7047 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7048 | Address FlagOutPtr = EmitPointerWithAlignment(E->getArg(3)); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7049 | |
| 7050 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 7051 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7052 | llvm::Value *Z = EmitScalarExpr(E->getArg(2)); |
| 7053 | |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7054 | llvm::Value *Callee = CGM.getIntrinsic(Intrinsic::amdgcn_div_scale, |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7055 | X->getType()); |
| 7056 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7057 | llvm::Value *Tmp = Builder.CreateCall(Callee, {X, Y, Z}); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7058 | |
| 7059 | llvm::Value *Result = Builder.CreateExtractValue(Tmp, 0); |
| 7060 | llvm::Value *Flag = Builder.CreateExtractValue(Tmp, 1); |
| 7061 | |
| 7062 | llvm::Type *RealFlagType |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7063 | = FlagOutPtr.getPointer()->getType()->getPointerElementType(); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7064 | |
| 7065 | llvm::Value *FlagExt = Builder.CreateZExt(Flag, RealFlagType); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7066 | Builder.CreateStore(FlagExt, FlagOutPtr); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7067 | return Result; |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 7068 | } |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7069 | case AMDGPU::BI__builtin_amdgcn_div_fmas: |
| 7070 | case AMDGPU::BI__builtin_amdgcn_div_fmasf: { |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 7071 | llvm::Value *Src0 = EmitScalarExpr(E->getArg(0)); |
| 7072 | llvm::Value *Src1 = EmitScalarExpr(E->getArg(1)); |
| 7073 | llvm::Value *Src2 = EmitScalarExpr(E->getArg(2)); |
| 7074 | llvm::Value *Src3 = EmitScalarExpr(E->getArg(3)); |
| 7075 | |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7076 | llvm::Value *F = CGM.getIntrinsic(Intrinsic::amdgcn_div_fmas, |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 7077 | Src0->getType()); |
| 7078 | llvm::Value *Src3ToBool = Builder.CreateIsNotNull(Src3); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7079 | return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool}); |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 7080 | } |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7081 | case AMDGPU::BI__builtin_amdgcn_div_fixup: |
| 7082 | case AMDGPU::BI__builtin_amdgcn_div_fixupf: |
| 7083 | return emitTernaryFPBuiltin(*this, E, Intrinsic::amdgcn_div_fixup); |
| 7084 | case AMDGPU::BI__builtin_amdgcn_trig_preop: |
| 7085 | case AMDGPU::BI__builtin_amdgcn_trig_preopf: |
| 7086 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_trig_preop); |
| 7087 | case AMDGPU::BI__builtin_amdgcn_rcp: |
| 7088 | case AMDGPU::BI__builtin_amdgcn_rcpf: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 7089 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rcp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7090 | case AMDGPU::BI__builtin_amdgcn_rsq: |
| 7091 | case AMDGPU::BI__builtin_amdgcn_rsqf: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 7092 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq); |
Matt Arsenault | f5c1f47 | 2016-02-13 01:03:09 +0000 | [diff] [blame] | 7093 | case AMDGPU::BI__builtin_amdgcn_rsq_clamp: |
| 7094 | case AMDGPU::BI__builtin_amdgcn_rsq_clampf: |
| 7095 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq_clamp); |
Matt Arsenault | 9b277b4 | 2016-02-13 01:21:09 +0000 | [diff] [blame] | 7096 | case AMDGPU::BI__builtin_amdgcn_sinf: |
| 7097 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_sin); |
| 7098 | case AMDGPU::BI__builtin_amdgcn_cosf: |
| 7099 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_cos); |
| 7100 | case AMDGPU::BI__builtin_amdgcn_log_clampf: |
| 7101 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_log_clamp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7102 | case AMDGPU::BI__builtin_amdgcn_ldexp: |
| 7103 | case AMDGPU::BI__builtin_amdgcn_ldexpf: |
| 7104 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_ldexp); |
Matt Arsenault | 3fb9633 | 2016-03-30 22:57:40 +0000 | [diff] [blame] | 7105 | case AMDGPU::BI__builtin_amdgcn_frexp_mant: |
| 7106 | case AMDGPU::BI__builtin_amdgcn_frexp_mantf: { |
| 7107 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_frexp_mant); |
| 7108 | } |
| 7109 | case AMDGPU::BI__builtin_amdgcn_frexp_exp: |
| 7110 | case AMDGPU::BI__builtin_amdgcn_frexp_expf: { |
| 7111 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_frexp_exp); |
| 7112 | } |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7113 | case AMDGPU::BI__builtin_amdgcn_class: |
| 7114 | case AMDGPU::BI__builtin_amdgcn_classf: |
| 7115 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_class); |
| 7116 | |
| 7117 | // Legacy amdgpu prefix |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 7118 | case AMDGPU::BI__builtin_amdgpu_rsq: |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7119 | case AMDGPU::BI__builtin_amdgpu_rsqf: { |
| 7120 | if (getTarget().getTriple().getArch() == Triple::amdgcn) |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 7121 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq); |
| 7122 | return emitUnaryBuiltin(*this, E, Intrinsic::r600_rsq); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7123 | } |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 7124 | case AMDGPU::BI__builtin_amdgpu_ldexp: |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7125 | case AMDGPU::BI__builtin_amdgpu_ldexpf: { |
| 7126 | if (getTarget().getTriple().getArch() == Triple::amdgcn) |
| 7127 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_ldexp); |
Matt Arsenault | dbb8491 | 2014-08-15 17:44:32 +0000 | [diff] [blame] | 7128 | return emitFPIntBuiltin(*this, E, Intrinsic::AMDGPU_ldexp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7129 | } |
| 7130 | default: |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7131 | return nullptr; |
| 7132 | } |
| 7133 | } |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7134 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7135 | /// Handle a SystemZ function in which the final argument is a pointer |
| 7136 | /// to an int that receives the post-instruction CC value. At the LLVM level |
| 7137 | /// this is represented as a function that returns a {result, cc} pair. |
| 7138 | static Value *EmitSystemZIntrinsicWithCC(CodeGenFunction &CGF, |
| 7139 | unsigned IntrinsicID, |
| 7140 | const CallExpr *E) { |
| 7141 | unsigned NumArgs = E->getNumArgs() - 1; |
| 7142 | SmallVector<Value *, 8> Args(NumArgs); |
| 7143 | for (unsigned I = 0; I < NumArgs; ++I) |
| 7144 | Args[I] = CGF.EmitScalarExpr(E->getArg(I)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7145 | Address CCPtr = CGF.EmitPointerWithAlignment(E->getArg(NumArgs)); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7146 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID); |
| 7147 | Value *Call = CGF.Builder.CreateCall(F, Args); |
| 7148 | Value *CC = CGF.Builder.CreateExtractValue(Call, 1); |
| 7149 | CGF.Builder.CreateStore(CC, CCPtr); |
| 7150 | return CGF.Builder.CreateExtractValue(Call, 0); |
| 7151 | } |
| 7152 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7153 | Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID, |
| 7154 | const CallExpr *E) { |
| 7155 | switch (BuiltinID) { |
| 7156 | case SystemZ::BI__builtin_tbegin: { |
| 7157 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 7158 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 7159 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7160 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7161 | } |
| 7162 | case SystemZ::BI__builtin_tbegin_nofloat: { |
| 7163 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 7164 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 7165 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin_nofloat); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7166 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7167 | } |
| 7168 | case SystemZ::BI__builtin_tbeginc: { |
| 7169 | Value *TDB = llvm::ConstantPointerNull::get(Int8PtrTy); |
| 7170 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff08); |
| 7171 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbeginc); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7172 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7173 | } |
| 7174 | case SystemZ::BI__builtin_tabort: { |
| 7175 | Value *Data = EmitScalarExpr(E->getArg(0)); |
| 7176 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tabort); |
| 7177 | return Builder.CreateCall(F, Builder.CreateSExt(Data, Int64Ty, "tabort")); |
| 7178 | } |
| 7179 | case SystemZ::BI__builtin_non_tx_store: { |
| 7180 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 7181 | Value *Data = EmitScalarExpr(E->getArg(1)); |
| 7182 | Value *F = CGM.getIntrinsic(Intrinsic::s390_ntstg); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7183 | return Builder.CreateCall(F, {Data, Address}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7186 | // Vector builtins. Note that most vector builtins are mapped automatically |
| 7187 | // to target-specific LLVM intrinsics. The ones handled specially here can |
| 7188 | // be represented via standard LLVM IR, which is preferable to enable common |
| 7189 | // LLVM optimizations. |
| 7190 | |
| 7191 | case SystemZ::BI__builtin_s390_vpopctb: |
| 7192 | case SystemZ::BI__builtin_s390_vpopcth: |
| 7193 | case SystemZ::BI__builtin_s390_vpopctf: |
| 7194 | case SystemZ::BI__builtin_s390_vpopctg: { |
| 7195 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7196 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7197 | Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 7198 | return Builder.CreateCall(F, X); |
| 7199 | } |
| 7200 | |
| 7201 | case SystemZ::BI__builtin_s390_vclzb: |
| 7202 | case SystemZ::BI__builtin_s390_vclzh: |
| 7203 | case SystemZ::BI__builtin_s390_vclzf: |
| 7204 | case SystemZ::BI__builtin_s390_vclzg: { |
| 7205 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7206 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7207 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 7208 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7209 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | case SystemZ::BI__builtin_s390_vctzb: |
| 7213 | case SystemZ::BI__builtin_s390_vctzh: |
| 7214 | case SystemZ::BI__builtin_s390_vctzf: |
| 7215 | case SystemZ::BI__builtin_s390_vctzg: { |
| 7216 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7217 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7218 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 7219 | Function *F = CGM.getIntrinsic(Intrinsic::cttz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7220 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | case SystemZ::BI__builtin_s390_vfsqdb: { |
| 7224 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7225 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7226 | Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType); |
| 7227 | return Builder.CreateCall(F, X); |
| 7228 | } |
| 7229 | case SystemZ::BI__builtin_s390_vfmadb: { |
| 7230 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7231 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7232 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7233 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 7234 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7235 | return Builder.CreateCall(F, {X, Y, Z}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7236 | } |
| 7237 | case SystemZ::BI__builtin_s390_vfmsdb: { |
| 7238 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7239 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7240 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7241 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 7242 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 7243 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7244 | return Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7245 | } |
| 7246 | case SystemZ::BI__builtin_s390_vflpdb: { |
| 7247 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7248 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7249 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 7250 | return Builder.CreateCall(F, X); |
| 7251 | } |
| 7252 | case SystemZ::BI__builtin_s390_vflndb: { |
| 7253 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7254 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7255 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 7256 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 7257 | return Builder.CreateFSub(Zero, Builder.CreateCall(F, X), "sub"); |
| 7258 | } |
| 7259 | case SystemZ::BI__builtin_s390_vfidb: { |
| 7260 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7261 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7262 | // Constant-fold the M4 and M5 mask arguments. |
| 7263 | llvm::APSInt M4, M5; |
| 7264 | bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext()); |
| 7265 | bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext()); |
| 7266 | assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?"); |
| 7267 | (void)IsConstM4; (void)IsConstM5; |
| 7268 | // Check whether this instance of vfidb can be represented via a LLVM |
| 7269 | // standard intrinsic. We only support some combinations of M4 and M5. |
| 7270 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 7271 | switch (M4.getZExtValue()) { |
| 7272 | default: break; |
| 7273 | case 0: // IEEE-inexact exception allowed |
| 7274 | switch (M5.getZExtValue()) { |
| 7275 | default: break; |
| 7276 | case 0: ID = Intrinsic::rint; break; |
| 7277 | } |
| 7278 | break; |
| 7279 | case 4: // IEEE-inexact exception suppressed |
| 7280 | switch (M5.getZExtValue()) { |
| 7281 | default: break; |
| 7282 | case 0: ID = Intrinsic::nearbyint; break; |
| 7283 | case 1: ID = Intrinsic::round; break; |
| 7284 | case 5: ID = Intrinsic::trunc; break; |
| 7285 | case 6: ID = Intrinsic::ceil; break; |
| 7286 | case 7: ID = Intrinsic::floor; break; |
| 7287 | } |
| 7288 | break; |
| 7289 | } |
| 7290 | if (ID != Intrinsic::not_intrinsic) { |
| 7291 | Function *F = CGM.getIntrinsic(ID, ResultType); |
| 7292 | return Builder.CreateCall(F, X); |
| 7293 | } |
| 7294 | Function *F = CGM.getIntrinsic(Intrinsic::s390_vfidb); |
| 7295 | Value *M4Value = llvm::ConstantInt::get(getLLVMContext(), M4); |
| 7296 | Value *M5Value = llvm::ConstantInt::get(getLLVMContext(), M5); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7297 | return Builder.CreateCall(F, {X, M4Value, M5Value}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7298 | } |
| 7299 | |
| 7300 | // Vector intrisincs that output the post-instruction CC value. |
| 7301 | |
| 7302 | #define INTRINSIC_WITH_CC(NAME) \ |
| 7303 | case SystemZ::BI__builtin_##NAME: \ |
| 7304 | return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E) |
| 7305 | |
| 7306 | INTRINSIC_WITH_CC(s390_vpkshs); |
| 7307 | INTRINSIC_WITH_CC(s390_vpksfs); |
| 7308 | INTRINSIC_WITH_CC(s390_vpksgs); |
| 7309 | |
| 7310 | INTRINSIC_WITH_CC(s390_vpklshs); |
| 7311 | INTRINSIC_WITH_CC(s390_vpklsfs); |
| 7312 | INTRINSIC_WITH_CC(s390_vpklsgs); |
| 7313 | |
| 7314 | INTRINSIC_WITH_CC(s390_vceqbs); |
| 7315 | INTRINSIC_WITH_CC(s390_vceqhs); |
| 7316 | INTRINSIC_WITH_CC(s390_vceqfs); |
| 7317 | INTRINSIC_WITH_CC(s390_vceqgs); |
| 7318 | |
| 7319 | INTRINSIC_WITH_CC(s390_vchbs); |
| 7320 | INTRINSIC_WITH_CC(s390_vchhs); |
| 7321 | INTRINSIC_WITH_CC(s390_vchfs); |
| 7322 | INTRINSIC_WITH_CC(s390_vchgs); |
| 7323 | |
| 7324 | INTRINSIC_WITH_CC(s390_vchlbs); |
| 7325 | INTRINSIC_WITH_CC(s390_vchlhs); |
| 7326 | INTRINSIC_WITH_CC(s390_vchlfs); |
| 7327 | INTRINSIC_WITH_CC(s390_vchlgs); |
| 7328 | |
| 7329 | INTRINSIC_WITH_CC(s390_vfaebs); |
| 7330 | INTRINSIC_WITH_CC(s390_vfaehs); |
| 7331 | INTRINSIC_WITH_CC(s390_vfaefs); |
| 7332 | |
| 7333 | INTRINSIC_WITH_CC(s390_vfaezbs); |
| 7334 | INTRINSIC_WITH_CC(s390_vfaezhs); |
| 7335 | INTRINSIC_WITH_CC(s390_vfaezfs); |
| 7336 | |
| 7337 | INTRINSIC_WITH_CC(s390_vfeebs); |
| 7338 | INTRINSIC_WITH_CC(s390_vfeehs); |
| 7339 | INTRINSIC_WITH_CC(s390_vfeefs); |
| 7340 | |
| 7341 | INTRINSIC_WITH_CC(s390_vfeezbs); |
| 7342 | INTRINSIC_WITH_CC(s390_vfeezhs); |
| 7343 | INTRINSIC_WITH_CC(s390_vfeezfs); |
| 7344 | |
| 7345 | INTRINSIC_WITH_CC(s390_vfenebs); |
| 7346 | INTRINSIC_WITH_CC(s390_vfenehs); |
| 7347 | INTRINSIC_WITH_CC(s390_vfenefs); |
| 7348 | |
| 7349 | INTRINSIC_WITH_CC(s390_vfenezbs); |
| 7350 | INTRINSIC_WITH_CC(s390_vfenezhs); |
| 7351 | INTRINSIC_WITH_CC(s390_vfenezfs); |
| 7352 | |
| 7353 | INTRINSIC_WITH_CC(s390_vistrbs); |
| 7354 | INTRINSIC_WITH_CC(s390_vistrhs); |
| 7355 | INTRINSIC_WITH_CC(s390_vistrfs); |
| 7356 | |
| 7357 | INTRINSIC_WITH_CC(s390_vstrcbs); |
| 7358 | INTRINSIC_WITH_CC(s390_vstrchs); |
| 7359 | INTRINSIC_WITH_CC(s390_vstrcfs); |
| 7360 | |
| 7361 | INTRINSIC_WITH_CC(s390_vstrczbs); |
| 7362 | INTRINSIC_WITH_CC(s390_vstrczhs); |
| 7363 | INTRINSIC_WITH_CC(s390_vstrczfs); |
| 7364 | |
| 7365 | INTRINSIC_WITH_CC(s390_vfcedbs); |
| 7366 | INTRINSIC_WITH_CC(s390_vfchdbs); |
| 7367 | INTRINSIC_WITH_CC(s390_vfchedbs); |
| 7368 | |
| 7369 | INTRINSIC_WITH_CC(s390_vftcidb); |
| 7370 | |
| 7371 | #undef INTRINSIC_WITH_CC |
| 7372 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7373 | default: |
| 7374 | return nullptr; |
| 7375 | } |
| 7376 | } |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7377 | |
| 7378 | Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, |
| 7379 | const CallExpr *E) { |
| 7380 | switch (BuiltinID) { |
| 7381 | case NVPTX::BI__nvvm_atom_add_gen_i: |
| 7382 | case NVPTX::BI__nvvm_atom_add_gen_l: |
| 7383 | case NVPTX::BI__nvvm_atom_add_gen_ll: |
| 7384 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Add, E); |
| 7385 | |
| 7386 | case NVPTX::BI__nvvm_atom_sub_gen_i: |
| 7387 | case NVPTX::BI__nvvm_atom_sub_gen_l: |
| 7388 | case NVPTX::BI__nvvm_atom_sub_gen_ll: |
| 7389 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Sub, E); |
| 7390 | |
| 7391 | case NVPTX::BI__nvvm_atom_and_gen_i: |
| 7392 | case NVPTX::BI__nvvm_atom_and_gen_l: |
| 7393 | case NVPTX::BI__nvvm_atom_and_gen_ll: |
| 7394 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::And, E); |
| 7395 | |
| 7396 | case NVPTX::BI__nvvm_atom_or_gen_i: |
| 7397 | case NVPTX::BI__nvvm_atom_or_gen_l: |
| 7398 | case NVPTX::BI__nvvm_atom_or_gen_ll: |
| 7399 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Or, E); |
| 7400 | |
| 7401 | case NVPTX::BI__nvvm_atom_xor_gen_i: |
| 7402 | case NVPTX::BI__nvvm_atom_xor_gen_l: |
| 7403 | case NVPTX::BI__nvvm_atom_xor_gen_ll: |
| 7404 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xor, E); |
| 7405 | |
| 7406 | case NVPTX::BI__nvvm_atom_xchg_gen_i: |
| 7407 | case NVPTX::BI__nvvm_atom_xchg_gen_l: |
| 7408 | case NVPTX::BI__nvvm_atom_xchg_gen_ll: |
| 7409 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xchg, E); |
| 7410 | |
| 7411 | case NVPTX::BI__nvvm_atom_max_gen_i: |
| 7412 | case NVPTX::BI__nvvm_atom_max_gen_l: |
| 7413 | case NVPTX::BI__nvvm_atom_max_gen_ll: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 7414 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Max, E); |
| 7415 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7416 | case NVPTX::BI__nvvm_atom_max_gen_ui: |
| 7417 | case NVPTX::BI__nvvm_atom_max_gen_ul: |
| 7418 | case NVPTX::BI__nvvm_atom_max_gen_ull: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 7419 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMax, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7420 | |
| 7421 | case NVPTX::BI__nvvm_atom_min_gen_i: |
| 7422 | case NVPTX::BI__nvvm_atom_min_gen_l: |
| 7423 | case NVPTX::BI__nvvm_atom_min_gen_ll: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 7424 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Min, E); |
| 7425 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7426 | case NVPTX::BI__nvvm_atom_min_gen_ui: |
| 7427 | case NVPTX::BI__nvvm_atom_min_gen_ul: |
| 7428 | case NVPTX::BI__nvvm_atom_min_gen_ull: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 7429 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7430 | |
| 7431 | case NVPTX::BI__nvvm_atom_cas_gen_i: |
| 7432 | case NVPTX::BI__nvvm_atom_cas_gen_l: |
| 7433 | case NVPTX::BI__nvvm_atom_cas_gen_ll: |
Jingyue Wu | f1eca25 | 2015-09-30 21:49:32 +0000 | [diff] [blame] | 7434 | // __nvvm_atom_cas_gen_* should return the old value rather than the |
| 7435 | // success flag. |
| 7436 | return MakeAtomicCmpXchgValue(*this, E, /*ReturnBool=*/false); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7437 | |
| 7438 | case NVPTX::BI__nvvm_atom_add_gen_f: { |
| 7439 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 7440 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 7441 | // atomicrmw only deals with integer arguments so we need to use |
| 7442 | // LLVM's nvvm_atomic_load_add_f32 intrinsic for that. |
| 7443 | Value *FnALAF32 = |
| 7444 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_add_f32, Ptr->getType()); |
| 7445 | return Builder.CreateCall(FnALAF32, {Ptr, Val}); |
| 7446 | } |
| 7447 | |
Justin Lebar | 717d2b0 | 2016-03-22 00:09:28 +0000 | [diff] [blame] | 7448 | case NVPTX::BI__nvvm_atom_inc_gen_ui: { |
| 7449 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 7450 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 7451 | Value *FnALI32 = |
| 7452 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_inc_32, Ptr->getType()); |
| 7453 | return Builder.CreateCall(FnALI32, {Ptr, Val}); |
| 7454 | } |
| 7455 | |
| 7456 | case NVPTX::BI__nvvm_atom_dec_gen_ui: { |
| 7457 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 7458 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 7459 | Value *FnALD32 = |
| 7460 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_dec_32, Ptr->getType()); |
| 7461 | return Builder.CreateCall(FnALD32, {Ptr, Val}); |
| 7462 | } |
| 7463 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 7464 | default: |
| 7465 | return nullptr; |
| 7466 | } |
| 7467 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 7468 | |
| 7469 | Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, |
| 7470 | const CallExpr *E) { |
| 7471 | switch (BuiltinID) { |
Dan Gohman | d4c5fb5 | 2015-10-02 19:38:47 +0000 | [diff] [blame] | 7472 | case WebAssembly::BI__builtin_wasm_memory_size: { |
| 7473 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7474 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_memory_size, ResultType); |
| 7475 | return Builder.CreateCall(Callee); |
| 7476 | } |
Dan Gohman | 24f0a08 | 2015-11-05 20:16:37 +0000 | [diff] [blame] | 7477 | case WebAssembly::BI__builtin_wasm_grow_memory: { |
Dan Gohman | 266b38a | 2015-10-02 20:20:01 +0000 | [diff] [blame] | 7478 | Value *X = EmitScalarExpr(E->getArg(0)); |
Dan Gohman | 24f0a08 | 2015-11-05 20:16:37 +0000 | [diff] [blame] | 7479 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_grow_memory, X->getType()); |
Dan Gohman | 266b38a | 2015-10-02 20:20:01 +0000 | [diff] [blame] | 7480 | return Builder.CreateCall(Callee, X); |
| 7481 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 7482 | |
| 7483 | default: |
| 7484 | return nullptr; |
| 7485 | } |
| 7486 | } |