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" |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 17 | #include "CGOpenCLRuntime.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "CodeGenModule.h" |
| 19 | #include "TargetInfo.h" |
Chris Lattner | 1eec660 | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 21 | #include "clang/AST/Decl.h" |
Chris Lattner | 5abdec7 | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 22 | #include "clang/Basic/TargetBuiltins.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 23 | #include "clang/Basic/TargetInfo.h" |
Mark Lacey | a8e7df3 | 2013-10-30 21:53:58 +0000 | [diff] [blame] | 24 | #include "clang/CodeGen/CGFunctionInfo.h" |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 26 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 27 | #include "llvm/IR/DataLayout.h" |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 28 | #include "llvm/IR/InlineAsm.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Intrinsics.h" |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 30 | #include "llvm/IR/MDBuilder.h" |
Kit Barton | 8246f28 | 2015-03-25 19:41:41 +0000 | [diff] [blame] | 31 | #include <sstream> |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 32 | |
Anders Carlsson | 1d8e521 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 33 | using namespace clang; |
| 34 | using namespace CodeGen; |
Anders Carlsson | a020c43 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 37 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 38 | /// "__builtin_fabsf", return a Function* for "fabsf". |
| 39 | llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, |
| 40 | unsigned BuiltinID) { |
| 41 | assert(Context.BuiltinInfo.isLibFunction(BuiltinID)); |
| 42 | |
| 43 | // Get the name, skip over the __builtin_ prefix (if necessary). |
| 44 | StringRef Name; |
| 45 | GlobalDecl D(FD); |
| 46 | |
| 47 | // If the builtin has been declared explicitly with an assembler label, |
| 48 | // use the mangled name. This differs from the plain label on platforms |
| 49 | // that prefix labels. |
| 50 | if (FD->hasAttr<AsmLabelAttr>()) |
| 51 | Name = getMangledName(D); |
| 52 | else |
Eric Christopher | 02d5d86 | 2015-08-06 01:01:12 +0000 | [diff] [blame] | 53 | Name = Context.BuiltinInfo.getName(BuiltinID) + 10; |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 54 | |
| 55 | llvm::FunctionType *Ty = |
| 56 | cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType())); |
| 57 | |
| 58 | return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable=*/false); |
| 59 | } |
| 60 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 61 | /// Emit the conversions required to turn the given value into an |
| 62 | /// integer of the given size. |
| 63 | static Value *EmitToInt(CodeGenFunction &CGF, llvm::Value *V, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 64 | QualType T, llvm::IntegerType *IntType) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 65 | V = CGF.EmitToMemory(V, T); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 66 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 67 | if (V->getType()->isPointerTy()) |
| 68 | return CGF.Builder.CreatePtrToInt(V, IntType); |
| 69 | |
| 70 | assert(V->getType() == IntType); |
| 71 | return V; |
Chandler Carruth | bc8cab1 | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 72 | } |
| 73 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 74 | static Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 75 | QualType T, llvm::Type *ResultType) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 76 | V = CGF.EmitFromMemory(V, T); |
| 77 | |
| 78 | if (ResultType->isPointerTy()) |
| 79 | return CGF.Builder.CreateIntToPtr(V, ResultType); |
| 80 | |
| 81 | assert(V->getType() == ResultType); |
| 82 | return V; |
Chandler Carruth | bc8cab1 | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 85 | /// Utility to insert an atomic instruction based on Instrinsic::ID |
| 86 | /// and the expression node. |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 87 | static Value *MakeBinaryAtomicValue(CodeGenFunction &CGF, |
| 88 | llvm::AtomicRMWInst::BinOp Kind, |
| 89 | const CallExpr *E) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 90 | QualType T = E->getType(); |
| 91 | assert(E->getArg(0)->getType()->isPointerType()); |
| 92 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 93 | E->getArg(0)->getType()->getPointeeType())); |
| 94 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 95 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 96 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 97 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 98 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 99 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 100 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 101 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 102 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 103 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 104 | llvm::Value *Args[2]; |
| 105 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 106 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 107 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 108 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 109 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 110 | llvm::Value *Result = CGF.Builder.CreateAtomicRMW( |
| 111 | Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 112 | return EmitFromInt(CGF, Result, T, ValueType); |
| 113 | } |
| 114 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 115 | static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) { |
| 116 | Value *Val = CGF.EmitScalarExpr(E->getArg(0)); |
| 117 | Value *Address = CGF.EmitScalarExpr(E->getArg(1)); |
| 118 | |
| 119 | // Convert the type of the pointer to a pointer to the stored type. |
| 120 | Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); |
| 121 | Value *BC = CGF.Builder.CreateBitCast( |
| 122 | Address, llvm::PointerType::getUnqual(Val->getType()), "cast"); |
| 123 | LValue LV = CGF.MakeNaturalAlignAddrLValue(BC, E->getArg(0)->getType()); |
| 124 | LV.setNontemporal(true); |
| 125 | CGF.EmitStoreOfScalar(Val, LV, false); |
| 126 | return nullptr; |
| 127 | } |
| 128 | |
| 129 | static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) { |
| 130 | Value *Address = CGF.EmitScalarExpr(E->getArg(0)); |
| 131 | |
| 132 | LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType()); |
| 133 | LV.setNontemporal(true); |
| 134 | return CGF.EmitLoadOfScalar(LV, E->getExprLoc()); |
| 135 | } |
| 136 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 137 | static RValue EmitBinaryAtomic(CodeGenFunction &CGF, |
| 138 | llvm::AtomicRMWInst::BinOp Kind, |
| 139 | const CallExpr *E) { |
| 140 | return RValue::get(MakeBinaryAtomicValue(CGF, Kind, E)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /// Utility to insert an atomic instruction based Instrinsic::ID and |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 144 | /// the expression node, where the return value is the result of the |
| 145 | /// operation. |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 146 | static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF, |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 147 | llvm::AtomicRMWInst::BinOp Kind, |
| 148 | const CallExpr *E, |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 149 | Instruction::BinaryOps Op, |
| 150 | bool Invert = false) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 151 | QualType T = E->getType(); |
| 152 | assert(E->getArg(0)->getType()->isPointerType()); |
| 153 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 154 | E->getArg(0)->getType()->getPointeeType())); |
| 155 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 156 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 157 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 158 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 159 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 160 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 161 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 162 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 163 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 164 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 165 | llvm::Value *Args[2]; |
| 166 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 167 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 168 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 169 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 170 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 171 | llvm::Value *Result = CGF.Builder.CreateAtomicRMW( |
| 172 | Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 173 | Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 174 | if (Invert) |
| 175 | Result = CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result, |
| 176 | llvm::ConstantInt::get(IntType, -1)); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 177 | Result = EmitFromInt(CGF, Result, T, ValueType); |
| 178 | return RValue::get(Result); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 181 | /// @brief Utility to insert an atomic cmpxchg instruction. |
| 182 | /// |
| 183 | /// @param CGF The current codegen function. |
| 184 | /// @param E Builtin call expression to convert to cmpxchg. |
| 185 | /// arg0 - address to operate on |
| 186 | /// arg1 - value to compare with |
| 187 | /// arg2 - new value |
| 188 | /// @param ReturnBool Specifies whether to return success flag of |
| 189 | /// cmpxchg result or the old value. |
| 190 | /// |
| 191 | /// @returns result of cmpxchg, according to ReturnBool |
| 192 | static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E, |
| 193 | bool ReturnBool) { |
| 194 | QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType(); |
| 195 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
| 196 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
| 197 | |
| 198 | llvm::IntegerType *IntType = llvm::IntegerType::get( |
| 199 | CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); |
| 200 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
| 201 | |
| 202 | Value *Args[3]; |
| 203 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 204 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
| 205 | llvm::Type *ValueType = Args[1]->getType(); |
| 206 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 207 | Args[2] = EmitToInt(CGF, CGF.EmitScalarExpr(E->getArg(2)), T, IntType); |
| 208 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 209 | Value *Pair = CGF.Builder.CreateAtomicCmpXchg( |
| 210 | Args[0], Args[1], Args[2], llvm::AtomicOrdering::SequentiallyConsistent, |
| 211 | llvm::AtomicOrdering::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 212 | if (ReturnBool) |
| 213 | // Extract boolean success flag and zext it to int. |
| 214 | return CGF.Builder.CreateZExt(CGF.Builder.CreateExtractValue(Pair, 1), |
| 215 | CGF.ConvertType(E->getType())); |
| 216 | else |
| 217 | // Extract old value and emit it using the same type as compare value. |
| 218 | return EmitFromInt(CGF, CGF.Builder.CreateExtractValue(Pair, 0), T, |
| 219 | ValueType); |
| 220 | } |
| 221 | |
Matt Arsenault | f652cae | 2016-07-01 17:38:14 +0000 | [diff] [blame] | 222 | // Emit a simple mangled intrinsic that has 1 argument and a return type |
| 223 | // matching the argument type. |
| 224 | static Value *emitUnaryBuiltin(CodeGenFunction &CGF, |
| 225 | const CallExpr *E, |
| 226 | unsigned IntrinsicID) { |
| 227 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 228 | |
| 229 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 230 | return CGF.Builder.CreateCall(F, Src0); |
| 231 | } |
| 232 | |
| 233 | // Emit an intrinsic that has 2 operands of the same type as its result. |
| 234 | static Value *emitBinaryBuiltin(CodeGenFunction &CGF, |
| 235 | const CallExpr *E, |
| 236 | unsigned IntrinsicID) { |
| 237 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 238 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 239 | |
| 240 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 241 | return CGF.Builder.CreateCall(F, { Src0, Src1 }); |
| 242 | } |
| 243 | |
| 244 | // Emit an intrinsic that has 3 operands of the same type as its result. |
| 245 | static Value *emitTernaryBuiltin(CodeGenFunction &CGF, |
| 246 | const CallExpr *E, |
| 247 | unsigned IntrinsicID) { |
| 248 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 249 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 250 | llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); |
| 251 | |
| 252 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 253 | return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 }); |
| 254 | } |
| 255 | |
| 256 | // Emit an intrinsic that has 1 float or double operand, and 1 integer. |
| 257 | static Value *emitFPIntBuiltin(CodeGenFunction &CGF, |
| 258 | const CallExpr *E, |
| 259 | unsigned IntrinsicID) { |
| 260 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 261 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 262 | |
| 263 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 264 | return CGF.Builder.CreateCall(F, {Src0, Src1}); |
| 265 | } |
| 266 | |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 267 | /// EmitFAbs - Emit a call to @llvm.fabs(). |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 268 | static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) { |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 269 | Value *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType()); |
| 270 | llvm::CallInst *Call = CGF.Builder.CreateCall(F, V); |
| 271 | Call->setDoesNotAccessMemory(); |
| 272 | return Call; |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 275 | /// Emit the computation of the sign bit for a floating point value. Returns |
| 276 | /// the i1 sign bit value. |
| 277 | static Value *EmitSignBit(CodeGenFunction &CGF, Value *V) { |
| 278 | LLVMContext &C = CGF.CGM.getLLVMContext(); |
| 279 | |
| 280 | llvm::Type *Ty = V->getType(); |
| 281 | int Width = Ty->getPrimitiveSizeInBits(); |
| 282 | llvm::Type *IntTy = llvm::IntegerType::get(C, Width); |
| 283 | V = CGF.Builder.CreateBitCast(V, IntTy); |
| 284 | if (Ty->isPPC_FP128Ty()) { |
Petar Jovanovic | 73d1044 | 2015-11-06 14:52:46 +0000 | [diff] [blame] | 285 | // We want the sign bit of the higher-order double. The bitcast we just |
| 286 | // did works as if the double-double was stored to memory and then |
| 287 | // read as an i128. The "store" will put the higher-order double in the |
| 288 | // lower address in both little- and big-Endian modes, but the "load" |
| 289 | // will treat those bits as a different part of the i128: the low bits in |
| 290 | // little-Endian, the high bits in big-Endian. Therefore, on big-Endian |
| 291 | // 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] | 292 | Width >>= 1; |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 293 | if (CGF.getTarget().isBigEndian()) { |
| 294 | Value *ShiftCst = llvm::ConstantInt::get(IntTy, Width); |
| 295 | V = CGF.Builder.CreateLShr(V, ShiftCst); |
| 296 | } |
| 297 | // We are truncating value in order to extract the higher-order |
| 298 | // double, which we will be using to extract the sign from. |
| 299 | IntTy = llvm::IntegerType::get(C, Width); |
| 300 | V = CGF.Builder.CreateTrunc(V, IntTy); |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 301 | } |
| 302 | Value *Zero = llvm::Constant::getNullValue(IntTy); |
| 303 | return CGF.Builder.CreateICmpSLT(V, Zero); |
| 304 | } |
| 305 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 306 | static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *Fn, |
| 307 | const CallExpr *E, llvm::Value *calleeValue) { |
Alexey Samsonov | 70b9c01 | 2014-08-21 20:26:47 +0000 | [diff] [blame] | 308 | return CGF.EmitCall(E->getCallee()->getType(), calleeValue, E, |
| 309 | ReturnValueSlot(), Fn); |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 312 | /// \brief Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.* |
| 313 | /// depending on IntrinsicID. |
| 314 | /// |
| 315 | /// \arg CGF The current codegen function. |
| 316 | /// \arg IntrinsicID The ID for the Intrinsic we wish to generate. |
| 317 | /// \arg X The first argument to the llvm.*.with.overflow.*. |
| 318 | /// \arg Y The second argument to the llvm.*.with.overflow.*. |
| 319 | /// \arg Carry The carry returned by the llvm.*.with.overflow.*. |
| 320 | /// \returns The result (i.e. sum/product) returned by the intrinsic. |
| 321 | static llvm::Value *EmitOverflowIntrinsic(CodeGenFunction &CGF, |
| 322 | const llvm::Intrinsic::ID IntrinsicID, |
| 323 | llvm::Value *X, llvm::Value *Y, |
| 324 | llvm::Value *&Carry) { |
| 325 | // Make sure we have integers of the same width. |
| 326 | assert(X->getType() == Y->getType() && |
| 327 | "Arguments must be the same type. (Did you forget to make sure both " |
| 328 | "arguments have the same integer width?)"); |
| 329 | |
NAKAMURA Takumi | 7ab4fbf | 2013-01-13 11:26:44 +0000 | [diff] [blame] | 330 | llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 331 | llvm::Value *Tmp = CGF.Builder.CreateCall(Callee, {X, Y}); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 332 | Carry = CGF.Builder.CreateExtractValue(Tmp, 1); |
| 333 | return CGF.Builder.CreateExtractValue(Tmp, 0); |
| 334 | } |
| 335 | |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 336 | static Value *emitRangedBuiltin(CodeGenFunction &CGF, |
| 337 | unsigned IntrinsicID, |
| 338 | int low, int high) { |
| 339 | llvm::MDBuilder MDHelper(CGF.getLLVMContext()); |
| 340 | llvm::MDNode *RNode = MDHelper.createRange(APInt(32, low), APInt(32, high)); |
| 341 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, {}); |
| 342 | llvm::Instruction *Call = CGF.Builder.CreateCall(F); |
| 343 | Call->setMetadata(llvm::LLVMContext::MD_range, RNode); |
| 344 | return Call; |
| 345 | } |
| 346 | |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 347 | namespace { |
| 348 | struct WidthAndSignedness { |
| 349 | unsigned Width; |
| 350 | bool Signed; |
| 351 | }; |
| 352 | } |
| 353 | |
| 354 | static WidthAndSignedness |
| 355 | getIntegerWidthAndSignedness(const clang::ASTContext &context, |
| 356 | const clang::QualType Type) { |
| 357 | assert(Type->isIntegerType() && "Given type is not an integer."); |
| 358 | unsigned Width = Type->isBooleanType() ? 1 : context.getTypeInfo(Type).Width; |
| 359 | bool Signed = Type->isSignedIntegerType(); |
| 360 | return {Width, Signed}; |
| 361 | } |
| 362 | |
| 363 | // Given one or more integer types, this function produces an integer type that |
| 364 | // encompasses them: any value in one of the given types could be expressed in |
| 365 | // the encompassing type. |
| 366 | static struct WidthAndSignedness |
| 367 | EncompassingIntegerType(ArrayRef<struct WidthAndSignedness> Types) { |
| 368 | assert(Types.size() > 0 && "Empty list of types."); |
| 369 | |
| 370 | // If any of the given types is signed, we must return a signed type. |
| 371 | bool Signed = false; |
| 372 | for (const auto &Type : Types) { |
| 373 | Signed |= Type.Signed; |
| 374 | } |
| 375 | |
| 376 | // The encompassing type must have a width greater than or equal to the width |
| 377 | // of the specified types. Aditionally, if the encompassing type is signed, |
| 378 | // its width must be strictly greater than the width of any unsigned types |
| 379 | // given. |
| 380 | unsigned Width = 0; |
| 381 | for (const auto &Type : Types) { |
| 382 | unsigned MinWidth = Type.Width + (Signed && !Type.Signed); |
| 383 | if (Width < MinWidth) { |
| 384 | Width = MinWidth; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | return {Width, Signed}; |
| 389 | } |
| 390 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 391 | Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) { |
| 392 | llvm::Type *DestType = Int8PtrTy; |
| 393 | if (ArgValue->getType() != DestType) |
| 394 | ArgValue = |
| 395 | Builder.CreateBitCast(ArgValue, DestType, ArgValue->getName().data()); |
| 396 | |
| 397 | Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend; |
| 398 | return Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue); |
| 399 | } |
| 400 | |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 401 | /// Checks if using the result of __builtin_object_size(p, @p From) in place of |
| 402 | /// __builtin_object_size(p, @p To) is correct |
| 403 | static bool areBOSTypesCompatible(int From, int To) { |
| 404 | // Note: Our __builtin_object_size implementation currently treats Type=0 and |
| 405 | // Type=2 identically. Encoding this implementation detail here may make |
| 406 | // improving __builtin_object_size difficult in the future, so it's omitted. |
| 407 | return From == To || (From == 0 && To == 1) || (From == 3 && To == 2); |
| 408 | } |
| 409 | |
| 410 | static llvm::Value * |
| 411 | getDefaultBuiltinObjectSizeResult(unsigned Type, llvm::IntegerType *ResType) { |
| 412 | return ConstantInt::get(ResType, (Type & 2) ? 0 : -1, /*isSigned=*/true); |
| 413 | } |
| 414 | |
| 415 | llvm::Value * |
| 416 | CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, |
| 417 | llvm::IntegerType *ResType) { |
| 418 | uint64_t ObjectSize; |
| 419 | if (!E->tryEvaluateObjectSize(ObjectSize, getContext(), Type)) |
| 420 | return emitBuiltinObjectSize(E, Type, ResType); |
| 421 | return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); |
| 422 | } |
| 423 | |
| 424 | /// Returns a Value corresponding to the size of the given expression. |
| 425 | /// This Value may be either of the following: |
| 426 | /// - A llvm::Argument (if E is a param with the pass_object_size attribute on |
| 427 | /// it) |
| 428 | /// - A call to the @llvm.objectsize intrinsic |
| 429 | llvm::Value * |
| 430 | CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type, |
| 431 | llvm::IntegerType *ResType) { |
| 432 | // We need to reference an argument if the pointer is a parameter with the |
| 433 | // pass_object_size attribute. |
| 434 | if (auto *D = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) { |
| 435 | auto *Param = dyn_cast<ParmVarDecl>(D->getDecl()); |
| 436 | auto *PS = D->getDecl()->getAttr<PassObjectSizeAttr>(); |
| 437 | if (Param != nullptr && PS != nullptr && |
| 438 | areBOSTypesCompatible(PS->getType(), Type)) { |
| 439 | auto Iter = SizeArguments.find(Param); |
| 440 | assert(Iter != SizeArguments.end()); |
| 441 | |
| 442 | const ImplicitParamDecl *D = Iter->second; |
| 443 | auto DIter = LocalDeclMap.find(D); |
| 444 | assert(DIter != LocalDeclMap.end()); |
| 445 | |
| 446 | return EmitLoadOfScalar(DIter->second, /*volatile=*/false, |
| 447 | getContext().getSizeType(), E->getLocStart()); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | // LLVM can't handle Type=3 appropriately, and __builtin_object_size shouldn't |
| 452 | // evaluate E for side-effects. In either case, we shouldn't lower to |
| 453 | // @llvm.objectsize. |
| 454 | if (Type == 3 || E->HasSideEffects(getContext())) |
| 455 | return getDefaultBuiltinObjectSizeResult(Type, ResType); |
| 456 | |
| 457 | // LLVM only supports 0 and 2, make sure that we pass along that |
| 458 | // as a boolean. |
| 459 | auto *CI = ConstantInt::get(Builder.getInt1Ty(), (Type & 2) >> 1); |
| 460 | // FIXME: Get right address space. |
| 461 | llvm::Type *Tys[] = {ResType, Builder.getInt8PtrTy(0)}; |
| 462 | Value *F = CGM.getIntrinsic(Intrinsic::objectsize, Tys); |
| 463 | return Builder.CreateCall(F, {EmitScalarExpr(E), CI}); |
| 464 | } |
| 465 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 467 | unsigned BuiltinID, const CallExpr *E, |
| 468 | ReturnValueSlot ReturnValue) { |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 469 | // 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] | 470 | Expr::EvalResult Result; |
Eli Friedman | df88c54 | 2012-01-06 20:03:09 +0000 | [diff] [blame] | 471 | if (E->EvaluateAsRValue(Result, CGM.getContext()) && |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 472 | !Result.hasSideEffects()) { |
Anders Carlsson | c968790 | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 473 | if (Result.Val.isInt()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 474 | return RValue::get(llvm::ConstantInt::get(getLLVMContext(), |
Owen Anderson | b7a2fe6 | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 475 | Result.Val.getInt())); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 476 | if (Result.Val.isFloat()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 477 | return RValue::get(llvm::ConstantFP::get(getLLVMContext(), |
| 478 | Result.Val.getFloat())); |
Chris Lattner | a1518b1 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 481 | switch (BuiltinID) { |
| 482 | default: break; // Handle intrinsics and libm functions below. |
Chris Lattner | a97132a | 2008-10-06 07:26:43 +0000 | [diff] [blame] | 483 | case Builtin::BI__builtin___CFStringMakeConstantString: |
David Chisnall | 481e3a8 | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 484 | case Builtin::BI__builtin___NSStringMakeConstantString: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 485 | return RValue::get(CGM.EmitConstantExpr(E, E->getType(), nullptr)); |
Chris Lattner | 0bf6791 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 486 | case Builtin::BI__builtin_stdarg_start: |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 487 | case Builtin::BI__builtin_va_start: |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 488 | case Builtin::BI__va_start: |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 489 | case Builtin::BI__builtin_va_end: |
| 490 | return RValue::get( |
| 491 | EmitVAStartEnd(BuiltinID == Builtin::BI__va_start |
| 492 | ? EmitScalarExpr(E->getArg(0)) |
| 493 | : EmitVAListRef(E->getArg(0)).getPointer(), |
| 494 | BuiltinID != Builtin::BI__builtin_va_end)); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 495 | case Builtin::BI__builtin_va_copy: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 496 | Value *DstPtr = EmitVAListRef(E->getArg(0)).getPointer(); |
| 497 | Value *SrcPtr = EmitVAListRef(E->getArg(1)).getPointer(); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 498 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 499 | llvm::Type *Type = Int8PtrTy; |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 500 | |
| 501 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 502 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 503 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), |
| 504 | {DstPtr, SrcPtr})); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 505 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 506 | case Builtin::BI__builtin_abs: |
Eli Friedman | 65499b4 | 2012-01-17 22:11:30 +0000 | [diff] [blame] | 507 | case Builtin::BI__builtin_labs: |
| 508 | case Builtin::BI__builtin_llabs: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 510 | |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 511 | Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | Value *CmpResult = |
| 513 | Builder.CreateICmpSGE(ArgValue, |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 514 | llvm::Constant::getNullValue(ArgValue->getType()), |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 515 | "abscond"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | Value *Result = |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 517 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 518 | |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 519 | return RValue::get(Result); |
| 520 | } |
Reid Kleckner | 06ea7d6 | 2014-11-03 23:52:09 +0000 | [diff] [blame] | 521 | case Builtin::BI__builtin_fabs: |
| 522 | case Builtin::BI__builtin_fabsf: |
| 523 | case Builtin::BI__builtin_fabsl: { |
Matt Arsenault | f652cae | 2016-07-01 17:38:14 +0000 | [diff] [blame] | 524 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::fabs)); |
Reid Kleckner | 06ea7d6 | 2014-11-03 23:52:09 +0000 | [diff] [blame] | 525 | } |
Jan Vesely | b4379f9 | 2014-09-26 01:19:41 +0000 | [diff] [blame] | 526 | case Builtin::BI__builtin_fmod: |
| 527 | case Builtin::BI__builtin_fmodf: |
| 528 | case Builtin::BI__builtin_fmodl: { |
| 529 | Value *Arg1 = EmitScalarExpr(E->getArg(0)); |
| 530 | Value *Arg2 = EmitScalarExpr(E->getArg(1)); |
| 531 | Value *Result = Builder.CreateFRem(Arg1, Arg2, "fmod"); |
| 532 | return RValue::get(Result); |
| 533 | } |
Matt Arsenault | f652cae | 2016-07-01 17:38:14 +0000 | [diff] [blame] | 534 | case Builtin::BI__builtin_copysign: |
| 535 | case Builtin::BI__builtin_copysignf: |
| 536 | case Builtin::BI__builtin_copysignl: { |
| 537 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::copysign)); |
| 538 | } |
| 539 | case Builtin::BI__builtin_ceil: |
| 540 | case Builtin::BI__builtin_ceilf: |
| 541 | case Builtin::BI__builtin_ceill: { |
| 542 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::ceil)); |
| 543 | } |
| 544 | case Builtin::BI__builtin_floor: |
| 545 | case Builtin::BI__builtin_floorf: |
| 546 | case Builtin::BI__builtin_floorl: { |
| 547 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::floor)); |
| 548 | } |
| 549 | case Builtin::BI__builtin_trunc: |
| 550 | case Builtin::BI__builtin_truncf: |
| 551 | case Builtin::BI__builtin_truncl: { |
| 552 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::trunc)); |
| 553 | } |
| 554 | case Builtin::BI__builtin_rint: |
| 555 | case Builtin::BI__builtin_rintf: |
| 556 | case Builtin::BI__builtin_rintl: { |
| 557 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::rint)); |
| 558 | } |
| 559 | case Builtin::BI__builtin_nearbyint: |
| 560 | case Builtin::BI__builtin_nearbyintf: |
| 561 | case Builtin::BI__builtin_nearbyintl: { |
| 562 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::nearbyint)); |
| 563 | } |
| 564 | case Builtin::BI__builtin_round: |
| 565 | case Builtin::BI__builtin_roundf: |
| 566 | case Builtin::BI__builtin_roundl: { |
| 567 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::round)); |
| 568 | } |
| 569 | case Builtin::BI__builtin_fmin: |
| 570 | case Builtin::BI__builtin_fminf: |
| 571 | case Builtin::BI__builtin_fminl: { |
| 572 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::minnum)); |
| 573 | } |
| 574 | case Builtin::BI__builtin_fmax: |
| 575 | case Builtin::BI__builtin_fmaxf: |
| 576 | case Builtin::BI__builtin_fmaxl: { |
| 577 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::maxnum)); |
| 578 | } |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 579 | case Builtin::BI__builtin_conj: |
| 580 | case Builtin::BI__builtin_conjf: |
| 581 | case Builtin::BI__builtin_conjl: { |
| 582 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 583 | Value *Real = ComplexVal.first; |
| 584 | Value *Imag = ComplexVal.second; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 585 | Value *Zero = |
| 586 | Imag->getType()->isFPOrFPVectorTy() |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 587 | ? llvm::ConstantFP::getZeroValueForNegation(Imag->getType()) |
| 588 | : llvm::Constant::getNullValue(Imag->getType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 589 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 590 | Imag = Builder.CreateFSub(Zero, Imag, "sub"); |
| 591 | return RValue::getComplex(std::make_pair(Real, Imag)); |
| 592 | } |
| 593 | case Builtin::BI__builtin_creal: |
| 594 | case Builtin::BI__builtin_crealf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 595 | case Builtin::BI__builtin_creall: |
| 596 | case Builtin::BIcreal: |
| 597 | case Builtin::BIcrealf: |
| 598 | case Builtin::BIcreall: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 599 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 600 | return RValue::get(ComplexVal.first); |
| 601 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 602 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 603 | case Builtin::BI__builtin_cimag: |
| 604 | case Builtin::BI__builtin_cimagf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 605 | case Builtin::BI__builtin_cimagl: |
| 606 | case Builtin::BIcimag: |
| 607 | case Builtin::BIcimagf: |
| 608 | case Builtin::BIcimagl: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 609 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 610 | return RValue::get(ComplexVal.second); |
| 611 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 612 | |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 613 | case Builtin::BI__builtin_ctzs: |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 614 | case Builtin::BI__builtin_ctz: |
| 615 | case Builtin::BI__builtin_ctzl: |
| 616 | case Builtin::BI__builtin_ctzll: { |
| 617 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 619 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 620 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 621 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 622 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 623 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 624 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 625 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 626 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 627 | "cast"); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 628 | return RValue::get(Result); |
| 629 | } |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 630 | case Builtin::BI__builtin_clzs: |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 631 | case Builtin::BI__builtin_clz: |
| 632 | case Builtin::BI__builtin_clzl: |
| 633 | case Builtin::BI__builtin_clzll: { |
| 634 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 636 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 637 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 638 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 639 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 640 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 641 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 642 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 643 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 644 | "cast"); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 645 | return RValue::get(Result); |
| 646 | } |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 647 | case Builtin::BI__builtin_ffs: |
| 648 | case Builtin::BI__builtin_ffsl: |
| 649 | case Builtin::BI__builtin_ffsll: { |
| 650 | // ffs(x) -> x ? cttz(x) + 1 : 0 |
| 651 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 652 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 653 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 654 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 656 | llvm::Type *ResultType = ConvertType(E->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 657 | Value *Tmp = |
| 658 | Builder.CreateAdd(Builder.CreateCall(F, {ArgValue, Builder.getTrue()}), |
| 659 | llvm::ConstantInt::get(ArgType, 1)); |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 660 | Value *Zero = llvm::Constant::getNullValue(ArgType); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 661 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); |
| 662 | Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); |
| 663 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 664 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 665 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 666 | return RValue::get(Result); |
| 667 | } |
| 668 | case Builtin::BI__builtin_parity: |
| 669 | case Builtin::BI__builtin_parityl: |
| 670 | case Builtin::BI__builtin_parityll: { |
| 671 | // parity(x) -> ctpop(x) & 1 |
| 672 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 673 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 674 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 675 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 677 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 678 | Value *Tmp = Builder.CreateCall(F, ArgValue); |
| 679 | Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1)); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 680 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 681 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 682 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 683 | return RValue::get(Result); |
| 684 | } |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 685 | case Builtin::BI__popcnt16: |
| 686 | case Builtin::BI__popcnt: |
| 687 | case Builtin::BI__popcnt64: |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 688 | case Builtin::BI__builtin_popcount: |
| 689 | case Builtin::BI__builtin_popcountl: |
| 690 | case Builtin::BI__builtin_popcountll: { |
| 691 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 693 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 694 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 696 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 697 | Value *Result = Builder.CreateCall(F, ArgValue); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 698 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 699 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 700 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 701 | return RValue::get(Result); |
| 702 | } |
Albert Gutowski | b6a11ac | 2016-09-08 22:32:19 +0000 | [diff] [blame] | 703 | case Builtin::BI_rotr8: |
| 704 | case Builtin::BI_rotr16: |
| 705 | case Builtin::BI_rotr: |
| 706 | case Builtin::BI_lrotr: |
| 707 | case Builtin::BI_rotr64: { |
| 708 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 709 | Value *Shift = EmitScalarExpr(E->getArg(1)); |
| 710 | |
| 711 | llvm::Type *ArgType = Val->getType(); |
| 712 | Shift = Builder.CreateIntCast(Shift, ArgType, false); |
| 713 | unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth(); |
| 714 | Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth); |
| 715 | Value *ArgZero = llvm::Constant::getNullValue(ArgType); |
| 716 | |
| 717 | Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1); |
| 718 | Shift = Builder.CreateAnd(Shift, Mask); |
| 719 | Value *LeftShift = Builder.CreateSub(ArgTypeSize, Shift); |
| 720 | |
| 721 | Value *RightShifted = Builder.CreateLShr(Val, Shift); |
| 722 | Value *LeftShifted = Builder.CreateShl(Val, LeftShift); |
| 723 | Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted); |
| 724 | |
| 725 | Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero); |
| 726 | Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated); |
| 727 | return RValue::get(Result); |
| 728 | } |
| 729 | case Builtin::BI_rotl8: |
| 730 | case Builtin::BI_rotl16: |
| 731 | case Builtin::BI_rotl: |
| 732 | case Builtin::BI_lrotl: |
| 733 | case Builtin::BI_rotl64: { |
| 734 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 735 | Value *Shift = EmitScalarExpr(E->getArg(1)); |
| 736 | |
| 737 | llvm::Type *ArgType = Val->getType(); |
| 738 | Shift = Builder.CreateIntCast(Shift, ArgType, false); |
| 739 | unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth(); |
| 740 | Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth); |
| 741 | Value *ArgZero = llvm::Constant::getNullValue(ArgType); |
| 742 | |
| 743 | Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1); |
| 744 | Shift = Builder.CreateAnd(Shift, Mask); |
| 745 | Value *RightShift = Builder.CreateSub(ArgTypeSize, Shift); |
| 746 | |
| 747 | Value *LeftShifted = Builder.CreateShl(Val, Shift); |
| 748 | Value *RightShifted = Builder.CreateLShr(Val, RightShift); |
| 749 | Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted); |
| 750 | |
| 751 | Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero); |
| 752 | Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated); |
| 753 | return RValue::get(Result); |
| 754 | } |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 755 | case Builtin::BI__builtin_unpredictable: { |
| 756 | // Always return the argument of __builtin_unpredictable. LLVM does not |
| 757 | // handle this builtin. Metadata for this builtin should be added directly |
| 758 | // to instructions such as branches or switches that use it. |
| 759 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
| 760 | } |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 761 | case Builtin::BI__builtin_expect: { |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 762 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 763 | llvm::Type *ArgType = ArgValue->getType(); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 764 | |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 765 | Value *ExpectedValue = EmitScalarExpr(E->getArg(1)); |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 766 | // Don't generate llvm.expect on -O0 as the backend won't use it for |
| 767 | // anything. |
| 768 | // Note, we still IRGen ExpectedValue because it could have side-effects. |
| 769 | if (CGM.getCodeGenOpts().OptimizationLevel == 0) |
| 770 | return RValue::get(ArgValue); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 771 | |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 772 | Value *FnExpect = CGM.getIntrinsic(Intrinsic::expect, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 773 | Value *Result = |
| 774 | Builder.CreateCall(FnExpect, {ArgValue, ExpectedValue}, "expval"); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 775 | return RValue::get(Result); |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 776 | } |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 777 | case Builtin::BI__builtin_assume_aligned: { |
| 778 | Value *PtrValue = EmitScalarExpr(E->getArg(0)); |
| 779 | Value *OffsetValue = |
| 780 | (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr; |
| 781 | |
| 782 | Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); |
| 783 | ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue); |
| 784 | unsigned Alignment = (unsigned) AlignmentCI->getZExtValue(); |
| 785 | |
| 786 | EmitAlignmentAssumption(PtrValue, Alignment, OffsetValue); |
| 787 | return RValue::get(PtrValue); |
| 788 | } |
| 789 | case Builtin::BI__assume: |
| 790 | case Builtin::BI__builtin_assume: { |
| 791 | if (E->getArg(0)->HasSideEffects(getContext())) |
| 792 | return RValue::get(nullptr); |
| 793 | |
| 794 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 795 | Value *FnAssume = CGM.getIntrinsic(Intrinsic::assume); |
| 796 | return RValue::get(Builder.CreateCall(FnAssume, ArgValue)); |
| 797 | } |
Benjamin Kramer | a801f4a | 2012-10-06 14:42:22 +0000 | [diff] [blame] | 798 | case Builtin::BI__builtin_bswap16: |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 799 | case Builtin::BI__builtin_bswap32: |
| 800 | case Builtin::BI__builtin_bswap64: { |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 801 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bswap)); |
| 802 | } |
Matt Arsenault | 08087c5 | 2016-03-23 22:14:43 +0000 | [diff] [blame] | 803 | case Builtin::BI__builtin_bitreverse8: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 804 | case Builtin::BI__builtin_bitreverse16: |
| 805 | case Builtin::BI__builtin_bitreverse32: |
| 806 | case Builtin::BI__builtin_bitreverse64: { |
| 807 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bitreverse)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 808 | } |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 809 | case Builtin::BI__builtin_object_size: { |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 810 | unsigned Type = |
| 811 | E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue(); |
| 812 | auto *ResType = cast<llvm::IntegerType>(ConvertType(E->getType())); |
Richard Smith | 01ade17 | 2012-05-23 04:13:20 +0000 | [diff] [blame] | 813 | |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 814 | // We pass this builtin onto the optimizer so that it can figure out the |
| 815 | // object size in more complex cases. |
| 816 | return RValue::get(emitBuiltinObjectSize(E->getArg(0), Type, ResType)); |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 817 | } |
Daniel Dunbar | b725726 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 818 | case Builtin::BI__builtin_prefetch: { |
| 819 | Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); |
| 820 | // FIXME: Technically these constants should of type 'int', yes? |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 822 | llvm::ConstantInt::get(Int32Ty, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 823 | Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 824 | llvm::ConstantInt::get(Int32Ty, 3); |
Bruno Cardoso Lopes | 3b0297a | 2011-06-14 05:00:30 +0000 | [diff] [blame] | 825 | Value *Data = llvm::ConstantInt::get(Int32Ty, 1); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 826 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 827 | return RValue::get(Builder.CreateCall(F, {Address, RW, Locality, Data})); |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 828 | } |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 829 | case Builtin::BI__builtin_readcyclecounter: { |
| 830 | Value *F = CGM.getIntrinsic(Intrinsic::readcyclecounter); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 831 | return RValue::get(Builder.CreateCall(F)); |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 832 | } |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 833 | case Builtin::BI__builtin___clear_cache: { |
| 834 | Value *Begin = EmitScalarExpr(E->getArg(0)); |
| 835 | Value *End = EmitScalarExpr(E->getArg(1)); |
| 836 | Value *F = CGM.getIntrinsic(Intrinsic::clear_cache); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 837 | return RValue::get(Builder.CreateCall(F, {Begin, End})); |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 838 | } |
Akira Hatanaka | 85365cd | 2015-07-02 22:15:41 +0000 | [diff] [blame] | 839 | case Builtin::BI__builtin_trap: |
| 840 | return RValue::get(EmitTrapCall(Intrinsic::trap)); |
| 841 | case Builtin::BI__debugbreak: |
| 842 | return RValue::get(EmitTrapCall(Intrinsic::debugtrap)); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 843 | case Builtin::BI__builtin_unreachable: { |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 844 | if (SanOpts.has(SanitizerKind::Unreachable)) { |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 845 | SanitizerScope SanScope(this); |
Alexey Samsonov | e396bfc | 2014-11-11 22:03:54 +0000 | [diff] [blame] | 846 | EmitCheck(std::make_pair(static_cast<llvm::Value *>(Builder.getFalse()), |
| 847 | SanitizerKind::Unreachable), |
| 848 | "builtin_unreachable", EmitCheckSourceLocation(E->getExprLoc()), |
| 849 | None); |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 850 | } else |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 851 | Builder.CreateUnreachable(); |
| 852 | |
| 853 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 854 | EmitBlock(createBasicBlock("unreachable.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 855 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 856 | return RValue::get(nullptr); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 857 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 858 | |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 859 | case Builtin::BI__builtin_powi: |
| 860 | case Builtin::BI__builtin_powif: |
Reid Kleckner | 1fcccdd | 2015-02-05 00:24:57 +0000 | [diff] [blame] | 861 | case Builtin::BI__builtin_powil: { |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 862 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 863 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 864 | llvm::Type *ArgType = Base->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 865 | Value *F = CGM.getIntrinsic(Intrinsic::powi, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 866 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 869 | case Builtin::BI__builtin_isgreater: |
| 870 | case Builtin::BI__builtin_isgreaterequal: |
| 871 | case Builtin::BI__builtin_isless: |
| 872 | case Builtin::BI__builtin_islessequal: |
| 873 | case Builtin::BI__builtin_islessgreater: |
| 874 | case Builtin::BI__builtin_isunordered: { |
| 875 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 876 | // floating point values. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 878 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 880 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 881 | default: llvm_unreachable("Unknown ordered comparison"); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 882 | case Builtin::BI__builtin_isgreater: |
| 883 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 884 | break; |
| 885 | case Builtin::BI__builtin_isgreaterequal: |
| 886 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 887 | break; |
| 888 | case Builtin::BI__builtin_isless: |
| 889 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 890 | break; |
| 891 | case Builtin::BI__builtin_islessequal: |
| 892 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 893 | break; |
| 894 | case Builtin::BI__builtin_islessgreater: |
| 895 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 896 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 897 | case Builtin::BI__builtin_isunordered: |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 898 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 899 | break; |
| 900 | } |
| 901 | // ZExt bool to int type. |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 902 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()))); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 903 | } |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 904 | case Builtin::BI__builtin_isnan: { |
| 905 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 906 | V = Builder.CreateFCmpUNO(V, V, "cmp"); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 907 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 908 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 909 | |
Dehao Chen | 5d4f0be | 2016-09-14 17:34:14 +0000 | [diff] [blame] | 910 | case Builtin::BIfinite: |
| 911 | case Builtin::BI__finite: |
| 912 | case Builtin::BIfinitef: |
| 913 | case Builtin::BI__finitef: |
| 914 | case Builtin::BIfinitel: |
| 915 | case Builtin::BI__finitel: |
Sanjay Patel | ae7a9df | 2016-04-07 14:29:05 +0000 | [diff] [blame] | 916 | case Builtin::BI__builtin_isinf: |
| 917 | case Builtin::BI__builtin_isfinite: { |
| 918 | // isinf(x) --> fabs(x) == infinity |
| 919 | // isfinite(x) --> fabs(x) != infinity |
| 920 | // x != NaN via the ordered compare in either case. |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 921 | Value *V = EmitScalarExpr(E->getArg(0)); |
Sanjay Patel | ae7a9df | 2016-04-07 14:29:05 +0000 | [diff] [blame] | 922 | Value *Fabs = EmitFAbs(*this, V); |
| 923 | Constant *Infinity = ConstantFP::getInfinity(V->getType()); |
| 924 | CmpInst::Predicate Pred = (BuiltinID == Builtin::BI__builtin_isinf) |
| 925 | ? CmpInst::FCMP_OEQ |
| 926 | : CmpInst::FCMP_ONE; |
| 927 | Value *FCmp = Builder.CreateFCmp(Pred, Fabs, Infinity, "cmpinf"); |
| 928 | return RValue::get(Builder.CreateZExt(FCmp, ConvertType(E->getType()))); |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 929 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 930 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 931 | case Builtin::BI__builtin_isinf_sign: { |
| 932 | // isinf_sign(x) -> fabs(x) == infinity ? (signbit(x) ? -1 : 1) : 0 |
| 933 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 934 | Value *AbsArg = EmitFAbs(*this, Arg); |
| 935 | Value *IsInf = Builder.CreateFCmpOEQ( |
| 936 | AbsArg, ConstantFP::getInfinity(Arg->getType()), "isinf"); |
| 937 | Value *IsNeg = EmitSignBit(*this, Arg); |
| 938 | |
| 939 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 940 | Value *Zero = Constant::getNullValue(IntTy); |
| 941 | Value *One = ConstantInt::get(IntTy, 1); |
| 942 | Value *NegativeOne = ConstantInt::get(IntTy, -1); |
| 943 | Value *SignResult = Builder.CreateSelect(IsNeg, NegativeOne, One); |
| 944 | Value *Result = Builder.CreateSelect(IsInf, SignResult, Zero); |
| 945 | return RValue::get(Result); |
| 946 | } |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 947 | |
| 948 | case Builtin::BI__builtin_isnormal: { |
| 949 | // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min |
| 950 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 951 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
| 952 | |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 953 | Value *Abs = EmitFAbs(*this, V); |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 954 | Value *IsLessThanInf = |
| 955 | Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 956 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 957 | getContext().getFloatTypeSemantics(E->getArg(0)->getType())); |
| 958 | Value *IsNormal = |
| 959 | Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest), |
| 960 | "isnormal"); |
| 961 | V = Builder.CreateAnd(Eq, IsLessThanInf, "and"); |
| 962 | V = Builder.CreateAnd(V, IsNormal, "and"); |
| 963 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 964 | } |
| 965 | |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 966 | case Builtin::BI__builtin_fpclassify: { |
| 967 | Value *V = EmitScalarExpr(E->getArg(5)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 968 | llvm::Type *Ty = ConvertType(E->getArg(5)->getType()); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 969 | |
| 970 | // Create Result |
| 971 | BasicBlock *Begin = Builder.GetInsertBlock(); |
| 972 | BasicBlock *End = createBasicBlock("fpclassify_end", this->CurFn); |
| 973 | Builder.SetInsertPoint(End); |
| 974 | PHINode *Result = |
Jay Foad | 20c0f02 | 2011-03-30 11:28:58 +0000 | [diff] [blame] | 975 | Builder.CreatePHI(ConvertType(E->getArg(0)->getType()), 4, |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 976 | "fpclassify_result"); |
| 977 | |
| 978 | // if (V==0) return FP_ZERO |
| 979 | Builder.SetInsertPoint(Begin); |
| 980 | Value *IsZero = Builder.CreateFCmpOEQ(V, Constant::getNullValue(Ty), |
| 981 | "iszero"); |
| 982 | Value *ZeroLiteral = EmitScalarExpr(E->getArg(4)); |
| 983 | BasicBlock *NotZero = createBasicBlock("fpclassify_not_zero", this->CurFn); |
| 984 | Builder.CreateCondBr(IsZero, End, NotZero); |
| 985 | Result->addIncoming(ZeroLiteral, Begin); |
| 986 | |
| 987 | // if (V != V) return FP_NAN |
| 988 | Builder.SetInsertPoint(NotZero); |
| 989 | Value *IsNan = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 990 | Value *NanLiteral = EmitScalarExpr(E->getArg(0)); |
| 991 | BasicBlock *NotNan = createBasicBlock("fpclassify_not_nan", this->CurFn); |
| 992 | Builder.CreateCondBr(IsNan, End, NotNan); |
| 993 | Result->addIncoming(NanLiteral, NotZero); |
| 994 | |
| 995 | // if (fabs(V) == infinity) return FP_INFINITY |
| 996 | Builder.SetInsertPoint(NotNan); |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 997 | Value *VAbs = EmitFAbs(*this, V); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 998 | Value *IsInf = |
| 999 | Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(V->getType()), |
| 1000 | "isinf"); |
| 1001 | Value *InfLiteral = EmitScalarExpr(E->getArg(1)); |
| 1002 | BasicBlock *NotInf = createBasicBlock("fpclassify_not_inf", this->CurFn); |
| 1003 | Builder.CreateCondBr(IsInf, End, NotInf); |
| 1004 | Result->addIncoming(InfLiteral, NotNan); |
| 1005 | |
| 1006 | // if (fabs(V) >= MIN_NORMAL) return FP_NORMAL else FP_SUBNORMAL |
| 1007 | Builder.SetInsertPoint(NotInf); |
| 1008 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 1009 | getContext().getFloatTypeSemantics(E->getArg(5)->getType())); |
| 1010 | Value *IsNormal = |
| 1011 | Builder.CreateFCmpUGE(VAbs, ConstantFP::get(V->getContext(), Smallest), |
| 1012 | "isnormal"); |
| 1013 | Value *NormalResult = |
| 1014 | Builder.CreateSelect(IsNormal, EmitScalarExpr(E->getArg(2)), |
| 1015 | EmitScalarExpr(E->getArg(3))); |
| 1016 | Builder.CreateBr(End); |
| 1017 | Result->addIncoming(NormalResult, NotInf); |
| 1018 | |
| 1019 | // return Result |
| 1020 | Builder.SetInsertPoint(End); |
| 1021 | return RValue::get(Result); |
| 1022 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1023 | |
Eli Friedman | f6bd150 | 2009-06-02 07:10:30 +0000 | [diff] [blame] | 1024 | case Builtin::BIalloca: |
Reid Kleckner | 59e4a6f | 2013-11-13 22:58:53 +0000 | [diff] [blame] | 1025 | case Builtin::BI_alloca: |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 1026 | case Builtin::BI__builtin_alloca: { |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 1027 | Value *Size = EmitScalarExpr(E->getArg(0)); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 1028 | return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size)); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1029 | } |
Eli Friedman | d6ef69a | 2010-01-23 19:00:10 +0000 | [diff] [blame] | 1030 | case Builtin::BIbzero: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1031 | case Builtin::BI__builtin_bzero: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1032 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1033 | Value *SizeVal = EmitScalarExpr(E->getArg(1)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1034 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1035 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1036 | Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false); |
| 1037 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 1038 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 1039 | case Builtin::BImemcpy: |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 1040 | case Builtin::BI__builtin_memcpy: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1041 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1042 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1043 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1044 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1045 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1046 | EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1047 | E->getArg(1)->getExprLoc(), FD, 1); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1048 | Builder.CreateMemCpy(Dest, Src, SizeVal, false); |
| 1049 | return RValue::get(Dest.getPointer()); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1050 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1051 | |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1052 | case Builtin::BI__builtin___memcpy_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1053 | // 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] | 1054 | llvm::APSInt Size, DstSize; |
| 1055 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 1056 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1057 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1058 | if (Size.ugt(DstSize)) |
| 1059 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1060 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1061 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1062 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1063 | Builder.CreateMemCpy(Dest, Src, SizeVal, false); |
| 1064 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1065 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1066 | |
Fariborz Jahanian | 4a30307 | 2010-06-16 16:22:04 +0000 | [diff] [blame] | 1067 | case Builtin::BI__builtin_objc_memmove_collectable: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1068 | Address DestAddr = EmitPointerWithAlignment(E->getArg(0)); |
| 1069 | Address SrcAddr = EmitPointerWithAlignment(E->getArg(1)); |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 1070 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1071 | CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1072 | DestAddr, SrcAddr, SizeVal); |
| 1073 | return RValue::get(DestAddr.getPointer()); |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 1074 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1075 | |
| 1076 | case Builtin::BI__builtin___memmove_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1077 | // 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] | 1078 | llvm::APSInt Size, DstSize; |
| 1079 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 1080 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1081 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1082 | if (Size.ugt(DstSize)) |
| 1083 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1084 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1085 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1086 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1087 | Builder.CreateMemMove(Dest, Src, SizeVal, false); |
| 1088 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 1091 | case Builtin::BImemmove: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1092 | case Builtin::BI__builtin_memmove: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1093 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1094 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1095 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1096 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1097 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1098 | EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1099 | E->getArg(1)->getExprLoc(), FD, 1); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1100 | Builder.CreateMemMove(Dest, Src, SizeVal, false); |
| 1101 | return RValue::get(Dest.getPointer()); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1102 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 1103 | case Builtin::BImemset: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1104 | case Builtin::BI__builtin_memset: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1105 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Benjamin Kramer | acc6b4e | 2010-12-30 00:13:21 +0000 | [diff] [blame] | 1106 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 1107 | Builder.getInt8Ty()); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1108 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1109 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1110 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1111 | Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); |
| 1112 | return RValue::get(Dest.getPointer()); |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 1113 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1114 | case Builtin::BI__builtin___memset_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1115 | // 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] | 1116 | llvm::APSInt Size, DstSize; |
| 1117 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 1118 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1119 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1120 | if (Size.ugt(DstSize)) |
| 1121 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1122 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1123 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 1124 | Builder.getInt8Ty()); |
| 1125 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1126 | Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); |
| 1127 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1128 | } |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 1129 | case Builtin::BI__builtin_dwarf_cfa: { |
| 1130 | // The offset in bytes from the first argument to the CFA. |
| 1131 | // |
| 1132 | // Why on earth is this in the frontend? Is there any reason at |
| 1133 | // all that the backend can't reasonably determine this while |
| 1134 | // lowering llvm.eh.dwarf.cfa()? |
| 1135 | // |
| 1136 | // TODO: If there's a satisfactory reason, add a target hook for |
| 1137 | // this instead of hard-coding 0, which is correct for most targets. |
| 1138 | int32_t Offset = 0; |
| 1139 | |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1140 | Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1141 | return RValue::get(Builder.CreateCall(F, |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1142 | llvm::ConstantInt::get(Int32Ty, Offset))); |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 1143 | } |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1144 | case Builtin::BI__builtin_return_address: { |
David Majnemer | 6cd3591 | 2015-07-25 05:57:24 +0000 | [diff] [blame] | 1145 | Value *Depth = |
| 1146 | CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy, this); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1147 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 1148 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1149 | } |
| 1150 | case Builtin::BI__builtin_frame_address: { |
David Majnemer | 6cd3591 | 2015-07-25 05:57:24 +0000 | [diff] [blame] | 1151 | Value *Depth = |
| 1152 | CGM.EmitConstantExpr(E->getArg(0), getContext().UnsignedIntTy, this); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1153 | Value *F = CGM.getIntrinsic(Intrinsic::frameaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 1154 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1155 | } |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 1156 | case Builtin::BI__builtin_extract_return_addr: { |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1157 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1158 | Value *Result = getTargetHooks().decodeReturnAddress(*this, Address); |
| 1159 | return RValue::get(Result); |
| 1160 | } |
| 1161 | case Builtin::BI__builtin_frob_return_addr: { |
| 1162 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1163 | Value *Result = getTargetHooks().encodeReturnAddress(*this, Address); |
| 1164 | return RValue::get(Result); |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 1165 | } |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 1166 | case Builtin::BI__builtin_dwarf_sp_column: { |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1167 | llvm::IntegerType *Ty |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 1168 | = cast<llvm::IntegerType>(ConvertType(E->getType())); |
| 1169 | int Column = getTargetHooks().getDwarfEHStackPointer(CGM); |
| 1170 | if (Column == -1) { |
| 1171 | CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column"); |
| 1172 | return RValue::get(llvm::UndefValue::get(Ty)); |
| 1173 | } |
| 1174 | return RValue::get(llvm::ConstantInt::get(Ty, Column, true)); |
| 1175 | } |
| 1176 | case Builtin::BI__builtin_init_dwarf_reg_size_table: { |
| 1177 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1178 | if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address)) |
| 1179 | CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table"); |
| 1180 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
| 1181 | } |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1182 | case Builtin::BI__builtin_eh_return: { |
| 1183 | Value *Int = EmitScalarExpr(E->getArg(0)); |
| 1184 | Value *Ptr = EmitScalarExpr(E->getArg(1)); |
| 1185 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1186 | llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType()); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1187 | assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && |
| 1188 | "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); |
| 1189 | Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 |
| 1190 | ? Intrinsic::eh_return_i32 |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1191 | : Intrinsic::eh_return_i64); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1192 | Builder.CreateCall(F, {Int, Ptr}); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1193 | Builder.CreateUnreachable(); |
| 1194 | |
| 1195 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1196 | EmitBlock(createBasicBlock("builtin_eh_return.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1197 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1198 | return RValue::get(nullptr); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1199 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1200 | case Builtin::BI__builtin_unwind_init: { |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1201 | Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1202 | return RValue::get(Builder.CreateCall(F)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1203 | } |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1204 | case Builtin::BI__builtin_extend_pointer: { |
| 1205 | // Extends a pointer to the size of an _Unwind_Word, which is |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1206 | // uint64_t on all platforms. Generally this gets poked into a |
| 1207 | // register and eventually used as an address, so if the |
| 1208 | // addressing registers are wider than pointers and the platform |
| 1209 | // doesn't implicitly ignore high-order bits when doing |
| 1210 | // addressing, we need to make sure we zext / sext based on |
| 1211 | // the platform's expectations. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1212 | // |
| 1213 | // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1214 | |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1215 | // Cast the pointer to intptr_t. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1216 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1217 | Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast"); |
| 1218 | |
| 1219 | // If that's 64 bits, we're done. |
| 1220 | if (IntPtrTy->getBitWidth() == 64) |
| 1221 | return RValue::get(Result); |
| 1222 | |
| 1223 | // Otherwise, ask the codegen data what to do. |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1224 | if (getTargetHooks().extendPointerWithSExt()) |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1225 | return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext")); |
| 1226 | else |
| 1227 | return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1228 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1229 | case Builtin::BI__builtin_setjmp: { |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1230 | // Buffer is a void**. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1231 | Address Buf = EmitPointerWithAlignment(E->getArg(0)); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1232 | |
| 1233 | // Store the frame pointer to the setjmp buffer. |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1234 | Value *FrameAddr = |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1235 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1236 | ConstantInt::get(Int32Ty, 0)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1237 | Builder.CreateStore(FrameAddr, Buf); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1238 | |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 1239 | // Store the stack pointer to the setjmp buffer. |
| 1240 | Value *StackAddr = |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1241 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::stacksave)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1242 | Address StackSaveSlot = |
| 1243 | Builder.CreateConstInBoundsGEP(Buf, 2, getPointerSize()); |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 1244 | Builder.CreateStore(StackAddr, StackSaveSlot); |
| 1245 | |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1246 | // Call LLVM's EH setjmp, which is lightweight. |
| 1247 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1248 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1249 | return RValue::get(Builder.CreateCall(F, Buf.getPointer())); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1250 | } |
| 1251 | case Builtin::BI__builtin_longjmp: { |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1252 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1253 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1254 | |
| 1255 | // Call LLVM's EH longjmp, which is lightweight. |
| 1256 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf); |
| 1257 | |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1258 | // longjmp doesn't return; mark this as unreachable. |
| 1259 | Builder.CreateUnreachable(); |
| 1260 | |
| 1261 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1262 | EmitBlock(createBasicBlock("longjmp.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1263 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1264 | return RValue::get(nullptr); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1265 | } |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1266 | case Builtin::BI__sync_fetch_and_add: |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1267 | case Builtin::BI__sync_fetch_and_sub: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1268 | case Builtin::BI__sync_fetch_and_or: |
| 1269 | case Builtin::BI__sync_fetch_and_and: |
| 1270 | case Builtin::BI__sync_fetch_and_xor: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1271 | case Builtin::BI__sync_fetch_and_nand: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1272 | case Builtin::BI__sync_add_and_fetch: |
| 1273 | case Builtin::BI__sync_sub_and_fetch: |
| 1274 | case Builtin::BI__sync_and_and_fetch: |
| 1275 | case Builtin::BI__sync_or_and_fetch: |
| 1276 | case Builtin::BI__sync_xor_and_fetch: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1277 | case Builtin::BI__sync_nand_and_fetch: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1278 | case Builtin::BI__sync_val_compare_and_swap: |
| 1279 | case Builtin::BI__sync_bool_compare_and_swap: |
| 1280 | case Builtin::BI__sync_lock_test_and_set: |
| 1281 | case Builtin::BI__sync_lock_release: |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1282 | case Builtin::BI__sync_swap: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1283 | llvm_unreachable("Shouldn't make it through sema"); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1284 | case Builtin::BI__sync_fetch_and_add_1: |
| 1285 | case Builtin::BI__sync_fetch_and_add_2: |
| 1286 | case Builtin::BI__sync_fetch_and_add_4: |
| 1287 | case Builtin::BI__sync_fetch_and_add_8: |
| 1288 | case Builtin::BI__sync_fetch_and_add_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1289 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Add, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1290 | case Builtin::BI__sync_fetch_and_sub_1: |
| 1291 | case Builtin::BI__sync_fetch_and_sub_2: |
| 1292 | case Builtin::BI__sync_fetch_and_sub_4: |
| 1293 | case Builtin::BI__sync_fetch_and_sub_8: |
| 1294 | case Builtin::BI__sync_fetch_and_sub_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1295 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Sub, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1296 | case Builtin::BI__sync_fetch_and_or_1: |
| 1297 | case Builtin::BI__sync_fetch_and_or_2: |
| 1298 | case Builtin::BI__sync_fetch_and_or_4: |
| 1299 | case Builtin::BI__sync_fetch_and_or_8: |
| 1300 | case Builtin::BI__sync_fetch_and_or_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1301 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Or, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1302 | case Builtin::BI__sync_fetch_and_and_1: |
| 1303 | case Builtin::BI__sync_fetch_and_and_2: |
| 1304 | case Builtin::BI__sync_fetch_and_and_4: |
| 1305 | case Builtin::BI__sync_fetch_and_and_8: |
| 1306 | case Builtin::BI__sync_fetch_and_and_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1307 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::And, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1308 | case Builtin::BI__sync_fetch_and_xor_1: |
| 1309 | case Builtin::BI__sync_fetch_and_xor_2: |
| 1310 | case Builtin::BI__sync_fetch_and_xor_4: |
| 1311 | case Builtin::BI__sync_fetch_and_xor_8: |
| 1312 | case Builtin::BI__sync_fetch_and_xor_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1313 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xor, E); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1314 | case Builtin::BI__sync_fetch_and_nand_1: |
| 1315 | case Builtin::BI__sync_fetch_and_nand_2: |
| 1316 | case Builtin::BI__sync_fetch_and_nand_4: |
| 1317 | case Builtin::BI__sync_fetch_and_nand_8: |
| 1318 | case Builtin::BI__sync_fetch_and_nand_16: |
| 1319 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Nand, E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1321 | // Clang extensions: not overloaded yet. |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1322 | case Builtin::BI__sync_fetch_and_min: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1323 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Min, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1324 | case Builtin::BI__sync_fetch_and_max: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1325 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Max, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1326 | case Builtin::BI__sync_fetch_and_umin: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1327 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMin, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1328 | case Builtin::BI__sync_fetch_and_umax: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1329 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMax, E); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1330 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1331 | case Builtin::BI__sync_add_and_fetch_1: |
| 1332 | case Builtin::BI__sync_add_and_fetch_2: |
| 1333 | case Builtin::BI__sync_add_and_fetch_4: |
| 1334 | case Builtin::BI__sync_add_and_fetch_8: |
| 1335 | case Builtin::BI__sync_add_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1336 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Add, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1337 | llvm::Instruction::Add); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1338 | case Builtin::BI__sync_sub_and_fetch_1: |
| 1339 | case Builtin::BI__sync_sub_and_fetch_2: |
| 1340 | case Builtin::BI__sync_sub_and_fetch_4: |
| 1341 | case Builtin::BI__sync_sub_and_fetch_8: |
| 1342 | case Builtin::BI__sync_sub_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1343 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Sub, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1344 | llvm::Instruction::Sub); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1345 | case Builtin::BI__sync_and_and_fetch_1: |
| 1346 | case Builtin::BI__sync_and_and_fetch_2: |
| 1347 | case Builtin::BI__sync_and_and_fetch_4: |
| 1348 | case Builtin::BI__sync_and_and_fetch_8: |
| 1349 | case Builtin::BI__sync_and_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1350 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::And, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1351 | llvm::Instruction::And); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1352 | case Builtin::BI__sync_or_and_fetch_1: |
| 1353 | case Builtin::BI__sync_or_and_fetch_2: |
| 1354 | case Builtin::BI__sync_or_and_fetch_4: |
| 1355 | case Builtin::BI__sync_or_and_fetch_8: |
| 1356 | case Builtin::BI__sync_or_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1357 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Or, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1358 | llvm::Instruction::Or); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1359 | case Builtin::BI__sync_xor_and_fetch_1: |
| 1360 | case Builtin::BI__sync_xor_and_fetch_2: |
| 1361 | case Builtin::BI__sync_xor_and_fetch_4: |
| 1362 | case Builtin::BI__sync_xor_and_fetch_8: |
| 1363 | case Builtin::BI__sync_xor_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1364 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Xor, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1365 | llvm::Instruction::Xor); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1366 | case Builtin::BI__sync_nand_and_fetch_1: |
| 1367 | case Builtin::BI__sync_nand_and_fetch_2: |
| 1368 | case Builtin::BI__sync_nand_and_fetch_4: |
| 1369 | case Builtin::BI__sync_nand_and_fetch_8: |
| 1370 | case Builtin::BI__sync_nand_and_fetch_16: |
| 1371 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Nand, E, |
| 1372 | llvm::Instruction::And, true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1374 | case Builtin::BI__sync_val_compare_and_swap_1: |
| 1375 | case Builtin::BI__sync_val_compare_and_swap_2: |
| 1376 | case Builtin::BI__sync_val_compare_and_swap_4: |
| 1377 | case Builtin::BI__sync_val_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1378 | case Builtin::BI__sync_val_compare_and_swap_16: |
| 1379 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, false)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1380 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1381 | case Builtin::BI__sync_bool_compare_and_swap_1: |
| 1382 | case Builtin::BI__sync_bool_compare_and_swap_2: |
| 1383 | case Builtin::BI__sync_bool_compare_and_swap_4: |
| 1384 | case Builtin::BI__sync_bool_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1385 | case Builtin::BI__sync_bool_compare_and_swap_16: |
| 1386 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, true)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1387 | |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1388 | case Builtin::BI__sync_swap_1: |
| 1389 | case Builtin::BI__sync_swap_2: |
| 1390 | case Builtin::BI__sync_swap_4: |
| 1391 | case Builtin::BI__sync_swap_8: |
| 1392 | case Builtin::BI__sync_swap_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1393 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1394 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1395 | case Builtin::BI__sync_lock_test_and_set_1: |
| 1396 | case Builtin::BI__sync_lock_test_and_set_2: |
| 1397 | case Builtin::BI__sync_lock_test_and_set_4: |
| 1398 | case Builtin::BI__sync_lock_test_and_set_8: |
| 1399 | case Builtin::BI__sync_lock_test_and_set_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1400 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Daniel Dunbar | 4ff562d | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 1401 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1402 | case Builtin::BI__sync_lock_release_1: |
| 1403 | case Builtin::BI__sync_lock_release_2: |
| 1404 | case Builtin::BI__sync_lock_release_4: |
| 1405 | case Builtin::BI__sync_lock_release_8: |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1406 | case Builtin::BI__sync_lock_release_16: { |
| 1407 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Eli Friedman | 84d2812 | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 1408 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 1409 | CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); |
Eli Friedman | fefe0d0 | 2012-03-16 01:48:04 +0000 | [diff] [blame] | 1410 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 1411 | StoreSize.getQuantity() * 8); |
| 1412 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1413 | llvm::StoreInst *Store = |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1414 | Builder.CreateAlignedStore(llvm::Constant::getNullValue(ITy), Ptr, |
| 1415 | StoreSize); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1416 | Store->setAtomic(llvm::AtomicOrdering::Release); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1417 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1418 | } |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1419 | |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1420 | case Builtin::BI__sync_synchronize: { |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1421 | // We assume this is supposed to correspond to a C++0x-style |
| 1422 | // sequentially-consistent fence (i.e. this is only usable for |
| 1423 | // synchonization, not device I/O or anything like that). This intrinsic |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1424 | // 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] | 1425 | // any way to safely use it... but in practice, it mostly works |
| 1426 | // to use it with non-atomic loads and stores to get acquire/release |
| 1427 | // semantics. |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1428 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1429 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 1430 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1431 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 1432 | case Builtin::BI__builtin_nontemporal_load: |
| 1433 | return RValue::get(EmitNontemporalLoad(*this, E)); |
| 1434 | case Builtin::BI__builtin_nontemporal_store: |
| 1435 | return RValue::get(EmitNontemporalStore(*this, E)); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1436 | case Builtin::BI__c11_atomic_is_lock_free: |
| 1437 | case Builtin::BI__atomic_is_lock_free: { |
| 1438 | // Call "bool __atomic_is_lock_free(size_t size, void *ptr)". For the |
| 1439 | // __c11 builtin, ptr is 0 (indicating a properly-aligned object), since |
| 1440 | // _Atomic(T) is always properly-aligned. |
| 1441 | const char *LibCallName = "__atomic_is_lock_free"; |
| 1442 | CallArgList Args; |
| 1443 | Args.add(RValue::get(EmitScalarExpr(E->getArg(0))), |
| 1444 | getContext().getSizeType()); |
| 1445 | if (BuiltinID == Builtin::BI__atomic_is_lock_free) |
| 1446 | Args.add(RValue::get(EmitScalarExpr(E->getArg(1))), |
| 1447 | getContext().VoidPtrTy); |
| 1448 | else |
| 1449 | Args.add(RValue::get(llvm::Constant::getNullValue(VoidPtrTy)), |
| 1450 | getContext().VoidPtrTy); |
| 1451 | const CGFunctionInfo &FuncInfo = |
John McCall | c56a8b3 | 2016-03-11 04:30:31 +0000 | [diff] [blame] | 1452 | CGM.getTypes().arrangeBuiltinFunctionCall(E->getType(), Args); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1453 | llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FuncInfo); |
| 1454 | llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, LibCallName); |
| 1455 | return EmitCall(FuncInfo, Func, ReturnValueSlot(), Args); |
| 1456 | } |
| 1457 | |
| 1458 | case Builtin::BI__atomic_test_and_set: { |
| 1459 | // Look at the argument type to determine whether this is a volatile |
| 1460 | // operation. The parameter type is always volatile. |
| 1461 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 1462 | bool Volatile = |
| 1463 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 1464 | |
| 1465 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 1466 | unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1467 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 1468 | Value *NewVal = Builder.getInt8(1); |
| 1469 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 1470 | if (isa<llvm::ConstantInt>(Order)) { |
| 1471 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1472 | AtomicRMWInst *Result = nullptr; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1473 | switch (ord) { |
| 1474 | case 0: // memory_order_relaxed |
| 1475 | default: // invalid order |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1476 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1477 | llvm::AtomicOrdering::Monotonic); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1478 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1479 | case 1: // memory_order_consume |
| 1480 | case 2: // memory_order_acquire |
| 1481 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1482 | llvm::AtomicOrdering::Acquire); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1483 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1484 | case 3: // memory_order_release |
| 1485 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1486 | llvm::AtomicOrdering::Release); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1487 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1488 | case 4: // memory_order_acq_rel |
| 1489 | |
| 1490 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1491 | llvm::AtomicOrdering::AcquireRelease); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1492 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1493 | case 5: // memory_order_seq_cst |
| 1494 | Result = Builder.CreateAtomicRMW( |
| 1495 | llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 1496 | llvm::AtomicOrdering::SequentiallyConsistent); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1497 | break; |
| 1498 | } |
| 1499 | Result->setVolatile(Volatile); |
| 1500 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 1501 | } |
| 1502 | |
| 1503 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1504 | |
| 1505 | llvm::BasicBlock *BBs[5] = { |
| 1506 | createBasicBlock("monotonic", CurFn), |
| 1507 | createBasicBlock("acquire", CurFn), |
| 1508 | createBasicBlock("release", CurFn), |
| 1509 | createBasicBlock("acqrel", CurFn), |
| 1510 | createBasicBlock("seqcst", CurFn) |
| 1511 | }; |
| 1512 | llvm::AtomicOrdering Orders[5] = { |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1513 | llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Acquire, |
| 1514 | llvm::AtomicOrdering::Release, llvm::AtomicOrdering::AcquireRelease, |
| 1515 | llvm::AtomicOrdering::SequentiallyConsistent}; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1516 | |
| 1517 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1518 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 1519 | |
| 1520 | Builder.SetInsertPoint(ContBB); |
| 1521 | PHINode *Result = Builder.CreatePHI(Int8Ty, 5, "was_set"); |
| 1522 | |
| 1523 | for (unsigned i = 0; i < 5; ++i) { |
| 1524 | Builder.SetInsertPoint(BBs[i]); |
| 1525 | AtomicRMWInst *RMW = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 1526 | Ptr, NewVal, Orders[i]); |
| 1527 | RMW->setVolatile(Volatile); |
| 1528 | Result->addIncoming(RMW, BBs[i]); |
| 1529 | Builder.CreateBr(ContBB); |
| 1530 | } |
| 1531 | |
| 1532 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 1533 | SI->addCase(Builder.getInt32(1), BBs[1]); |
| 1534 | SI->addCase(Builder.getInt32(2), BBs[1]); |
| 1535 | SI->addCase(Builder.getInt32(3), BBs[2]); |
| 1536 | SI->addCase(Builder.getInt32(4), BBs[3]); |
| 1537 | SI->addCase(Builder.getInt32(5), BBs[4]); |
| 1538 | |
| 1539 | Builder.SetInsertPoint(ContBB); |
| 1540 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 1541 | } |
| 1542 | |
| 1543 | case Builtin::BI__atomic_clear: { |
| 1544 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 1545 | bool Volatile = |
| 1546 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 1547 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1548 | Address Ptr = EmitPointerWithAlignment(E->getArg(0)); |
| 1549 | unsigned AddrSpace = Ptr.getPointer()->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1550 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 1551 | Value *NewVal = Builder.getInt8(0); |
| 1552 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 1553 | if (isa<llvm::ConstantInt>(Order)) { |
| 1554 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 1555 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1556 | switch (ord) { |
| 1557 | case 0: // memory_order_relaxed |
| 1558 | default: // invalid order |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1559 | Store->setOrdering(llvm::AtomicOrdering::Monotonic); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1560 | break; |
| 1561 | case 3: // memory_order_release |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1562 | Store->setOrdering(llvm::AtomicOrdering::Release); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1563 | break; |
| 1564 | case 5: // memory_order_seq_cst |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1565 | Store->setOrdering(llvm::AtomicOrdering::SequentiallyConsistent); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1566 | break; |
| 1567 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1568 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1572 | |
| 1573 | llvm::BasicBlock *BBs[3] = { |
| 1574 | createBasicBlock("monotonic", CurFn), |
| 1575 | createBasicBlock("release", CurFn), |
| 1576 | createBasicBlock("seqcst", CurFn) |
| 1577 | }; |
| 1578 | llvm::AtomicOrdering Orders[3] = { |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1579 | llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Release, |
| 1580 | llvm::AtomicOrdering::SequentiallyConsistent}; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1581 | |
| 1582 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1583 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 1584 | |
| 1585 | for (unsigned i = 0; i < 3; ++i) { |
| 1586 | Builder.SetInsertPoint(BBs[i]); |
| 1587 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1588 | Store->setOrdering(Orders[i]); |
| 1589 | Builder.CreateBr(ContBB); |
| 1590 | } |
| 1591 | |
| 1592 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 1593 | SI->addCase(Builder.getInt32(3), BBs[1]); |
| 1594 | SI->addCase(Builder.getInt32(5), BBs[2]); |
| 1595 | |
| 1596 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1597 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1600 | case Builtin::BI__atomic_thread_fence: |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 1601 | case Builtin::BI__atomic_signal_fence: |
| 1602 | case Builtin::BI__c11_atomic_thread_fence: |
| 1603 | case Builtin::BI__c11_atomic_signal_fence: { |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1604 | llvm::SynchronizationScope Scope; |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 1605 | if (BuiltinID == Builtin::BI__atomic_signal_fence || |
| 1606 | BuiltinID == Builtin::BI__c11_atomic_signal_fence) |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1607 | Scope = llvm::SingleThread; |
| 1608 | else |
| 1609 | Scope = llvm::CrossThread; |
| 1610 | Value *Order = EmitScalarExpr(E->getArg(0)); |
| 1611 | if (isa<llvm::ConstantInt>(Order)) { |
| 1612 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 1613 | switch (ord) { |
| 1614 | case 0: // memory_order_relaxed |
| 1615 | default: // invalid order |
| 1616 | break; |
| 1617 | case 1: // memory_order_consume |
| 1618 | case 2: // memory_order_acquire |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1619 | Builder.CreateFence(llvm::AtomicOrdering::Acquire, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1620 | break; |
| 1621 | case 3: // memory_order_release |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1622 | Builder.CreateFence(llvm::AtomicOrdering::Release, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1623 | break; |
| 1624 | case 4: // memory_order_acq_rel |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1625 | Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1626 | break; |
| 1627 | case 5: // memory_order_seq_cst |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1628 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, |
| 1629 | Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1630 | break; |
| 1631 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1632 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB; |
| 1636 | AcquireBB = createBasicBlock("acquire", CurFn); |
| 1637 | ReleaseBB = createBasicBlock("release", CurFn); |
| 1638 | AcqRelBB = createBasicBlock("acqrel", CurFn); |
| 1639 | SeqCstBB = createBasicBlock("seqcst", CurFn); |
| 1640 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 1641 | |
| 1642 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 1643 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, ContBB); |
| 1644 | |
| 1645 | Builder.SetInsertPoint(AcquireBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1646 | Builder.CreateFence(llvm::AtomicOrdering::Acquire, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1647 | Builder.CreateBr(ContBB); |
| 1648 | SI->addCase(Builder.getInt32(1), AcquireBB); |
| 1649 | SI->addCase(Builder.getInt32(2), AcquireBB); |
| 1650 | |
| 1651 | Builder.SetInsertPoint(ReleaseBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1652 | Builder.CreateFence(llvm::AtomicOrdering::Release, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1653 | Builder.CreateBr(ContBB); |
| 1654 | SI->addCase(Builder.getInt32(3), ReleaseBB); |
| 1655 | |
| 1656 | Builder.SetInsertPoint(AcqRelBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1657 | Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1658 | Builder.CreateBr(ContBB); |
| 1659 | SI->addCase(Builder.getInt32(4), AcqRelBB); |
| 1660 | |
| 1661 | Builder.SetInsertPoint(SeqCstBB); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1662 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, Scope); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1663 | Builder.CreateBr(ContBB); |
| 1664 | SI->addCase(Builder.getInt32(5), SeqCstBB); |
| 1665 | |
| 1666 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1667 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1670 | // Library functions with special handling. |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1671 | case Builtin::BIsqrt: |
| 1672 | case Builtin::BIsqrtf: |
| 1673 | case Builtin::BIsqrtl: { |
Hal Finkel | 28b2ae3 | 2013-09-12 23:57:55 +0000 | [diff] [blame] | 1674 | // Transform a call to sqrt* into a @llvm.sqrt.* intrinsic call, but only |
| 1675 | // in finite- or unsafe-math mode (the intrinsic has different semantics |
| 1676 | // for handling negative numbers compared to the library function, so |
| 1677 | // -fmath-errno=0 is not enough). |
| 1678 | if (!FD->hasAttr<ConstAttr>()) |
| 1679 | break; |
| 1680 | if (!(CGM.getCodeGenOpts().UnsafeFPMath || |
| 1681 | CGM.getCodeGenOpts().NoNaNsFPMath)) |
| 1682 | break; |
| 1683 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 1684 | llvm::Type *ArgType = Arg0->getType(); |
| 1685 | Value *F = CGM.getIntrinsic(Intrinsic::sqrt, ArgType); |
| 1686 | return RValue::get(Builder.CreateCall(F, Arg0)); |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Reid Kleckner | 8a8c129 | 2015-02-05 00:18:01 +0000 | [diff] [blame] | 1689 | case Builtin::BI__builtin_pow: |
| 1690 | case Builtin::BI__builtin_powf: |
| 1691 | case Builtin::BI__builtin_powl: |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1692 | case Builtin::BIpow: |
| 1693 | case Builtin::BIpowf: |
| 1694 | case Builtin::BIpowl: { |
Eli Bendersky | c3496b0 | 2013-07-24 21:22:01 +0000 | [diff] [blame] | 1695 | // Transform a call to pow* into a @llvm.pow.* intrinsic call. |
| 1696 | if (!FD->hasAttr<ConstAttr>()) |
| 1697 | break; |
| 1698 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 1699 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
| 1700 | llvm::Type *ArgType = Base->getType(); |
| 1701 | Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1702 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 1703 | } |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1704 | |
Cameron Zwarich | ae7bc98 | 2011-07-08 21:39:34 +0000 | [diff] [blame] | 1705 | case Builtin::BIfma: |
| 1706 | case Builtin::BIfmaf: |
| 1707 | case Builtin::BIfmal: |
| 1708 | case Builtin::BI__builtin_fma: |
| 1709 | case Builtin::BI__builtin_fmaf: |
| 1710 | case Builtin::BI__builtin_fmal: { |
| 1711 | // Rewrite fma to intrinsic. |
| 1712 | Value *FirstArg = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1713 | llvm::Type *ArgType = FirstArg->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1714 | Value *F = CGM.getIntrinsic(Intrinsic::fma, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1715 | return RValue::get( |
| 1716 | Builder.CreateCall(F, {FirstArg, EmitScalarExpr(E->getArg(1)), |
| 1717 | EmitScalarExpr(E->getArg(2))})); |
Cameron Zwarich | ae7bc98 | 2011-07-08 21:39:34 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1720 | case Builtin::BI__builtin_signbit: |
| 1721 | case Builtin::BI__builtin_signbitf: |
| 1722 | case Builtin::BI__builtin_signbitl: { |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 1723 | return RValue::get( |
| 1724 | Builder.CreateZExt(EmitSignBit(*this, EmitScalarExpr(E->getArg(0))), |
| 1725 | ConvertType(E->getType()))); |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 1726 | } |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1727 | case Builtin::BI__builtin_annotation: { |
| 1728 | llvm::Value *AnnVal = EmitScalarExpr(E->getArg(0)); |
| 1729 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::annotation, |
| 1730 | AnnVal->getType()); |
| 1731 | |
| 1732 | // Get the annotation string, go through casts. Sema requires this to be a |
| 1733 | // non-wide string literal, potentially casted, so the cast<> is safe. |
| 1734 | const Expr *AnnotationStrExpr = E->getArg(1)->IgnoreParenCasts(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1735 | StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString(); |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1736 | return RValue::get(EmitAnnotationCall(F, AnnVal, Str, E->getExprLoc())); |
| 1737 | } |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1738 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1739 | case Builtin::BI__builtin_addcs: |
| 1740 | case Builtin::BI__builtin_addc: |
| 1741 | case Builtin::BI__builtin_addcl: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1742 | case Builtin::BI__builtin_addcll: |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1743 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1744 | case Builtin::BI__builtin_subcs: |
| 1745 | case Builtin::BI__builtin_subc: |
| 1746 | case Builtin::BI__builtin_subcl: |
| 1747 | case Builtin::BI__builtin_subcll: { |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1748 | |
| 1749 | // We translate all of these builtins from expressions of the form: |
| 1750 | // int x = ..., y = ..., carryin = ..., carryout, result; |
| 1751 | // result = __builtin_addc(x, y, carryin, &carryout); |
| 1752 | // |
| 1753 | // to LLVM IR of the form: |
| 1754 | // |
| 1755 | // %tmp1 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y) |
| 1756 | // %tmpsum1 = extractvalue {i32, i1} %tmp1, 0 |
| 1757 | // %carry1 = extractvalue {i32, i1} %tmp1, 1 |
| 1758 | // %tmp2 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %tmpsum1, |
| 1759 | // i32 %carryin) |
| 1760 | // %result = extractvalue {i32, i1} %tmp2, 0 |
| 1761 | // %carry2 = extractvalue {i32, i1} %tmp2, 1 |
| 1762 | // %tmp3 = or i1 %carry1, %carry2 |
| 1763 | // %tmp4 = zext i1 %tmp3 to i32 |
| 1764 | // store i32 %tmp4, i32* %carryout |
| 1765 | |
| 1766 | // Scalarize our inputs. |
| 1767 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 1768 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 1769 | llvm::Value *Carryin = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1770 | Address CarryOutPtr = EmitPointerWithAlignment(E->getArg(3)); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1771 | |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1772 | // Decide if we are lowering to a uadd.with.overflow or usub.with.overflow. |
| 1773 | llvm::Intrinsic::ID IntrinsicId; |
| 1774 | switch (BuiltinID) { |
| 1775 | default: llvm_unreachable("Unknown multiprecision builtin id."); |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1776 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1777 | case Builtin::BI__builtin_addcs: |
| 1778 | case Builtin::BI__builtin_addc: |
| 1779 | case Builtin::BI__builtin_addcl: |
| 1780 | case Builtin::BI__builtin_addcll: |
| 1781 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 1782 | break; |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 1783 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 1784 | case Builtin::BI__builtin_subcs: |
| 1785 | case Builtin::BI__builtin_subc: |
| 1786 | case Builtin::BI__builtin_subcl: |
| 1787 | case Builtin::BI__builtin_subcll: |
| 1788 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 1789 | break; |
| 1790 | } |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1791 | |
| 1792 | // Construct our resulting LLVM IR expression. |
| 1793 | llvm::Value *Carry1; |
| 1794 | llvm::Value *Sum1 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 1795 | X, Y, Carry1); |
| 1796 | llvm::Value *Carry2; |
| 1797 | llvm::Value *Sum2 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 1798 | Sum1, Carryin, Carry2); |
| 1799 | llvm::Value *CarryOut = Builder.CreateZExt(Builder.CreateOr(Carry1, Carry2), |
| 1800 | X->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1801 | Builder.CreateStore(CarryOut, CarryOutPtr); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 1802 | return RValue::get(Sum2); |
| 1803 | } |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 1804 | |
| 1805 | case Builtin::BI__builtin_add_overflow: |
| 1806 | case Builtin::BI__builtin_sub_overflow: |
| 1807 | case Builtin::BI__builtin_mul_overflow: { |
| 1808 | const clang::Expr *LeftArg = E->getArg(0); |
| 1809 | const clang::Expr *RightArg = E->getArg(1); |
| 1810 | const clang::Expr *ResultArg = E->getArg(2); |
| 1811 | |
| 1812 | clang::QualType ResultQTy = |
| 1813 | ResultArg->getType()->castAs<PointerType>()->getPointeeType(); |
| 1814 | |
| 1815 | WidthAndSignedness LeftInfo = |
| 1816 | getIntegerWidthAndSignedness(CGM.getContext(), LeftArg->getType()); |
| 1817 | WidthAndSignedness RightInfo = |
| 1818 | getIntegerWidthAndSignedness(CGM.getContext(), RightArg->getType()); |
| 1819 | WidthAndSignedness ResultInfo = |
| 1820 | getIntegerWidthAndSignedness(CGM.getContext(), ResultQTy); |
| 1821 | WidthAndSignedness EncompassingInfo = |
| 1822 | EncompassingIntegerType({LeftInfo, RightInfo, ResultInfo}); |
| 1823 | |
| 1824 | llvm::Type *EncompassingLLVMTy = |
| 1825 | llvm::IntegerType::get(CGM.getLLVMContext(), EncompassingInfo.Width); |
| 1826 | |
| 1827 | llvm::Type *ResultLLVMTy = CGM.getTypes().ConvertType(ResultQTy); |
| 1828 | |
| 1829 | llvm::Intrinsic::ID IntrinsicId; |
| 1830 | switch (BuiltinID) { |
| 1831 | default: |
| 1832 | llvm_unreachable("Unknown overflow builtin id."); |
| 1833 | case Builtin::BI__builtin_add_overflow: |
| 1834 | IntrinsicId = EncompassingInfo.Signed |
| 1835 | ? llvm::Intrinsic::sadd_with_overflow |
| 1836 | : llvm::Intrinsic::uadd_with_overflow; |
| 1837 | break; |
| 1838 | case Builtin::BI__builtin_sub_overflow: |
| 1839 | IntrinsicId = EncompassingInfo.Signed |
| 1840 | ? llvm::Intrinsic::ssub_with_overflow |
| 1841 | : llvm::Intrinsic::usub_with_overflow; |
| 1842 | break; |
| 1843 | case Builtin::BI__builtin_mul_overflow: |
| 1844 | IntrinsicId = EncompassingInfo.Signed |
| 1845 | ? llvm::Intrinsic::smul_with_overflow |
| 1846 | : llvm::Intrinsic::umul_with_overflow; |
| 1847 | break; |
| 1848 | } |
| 1849 | |
| 1850 | llvm::Value *Left = EmitScalarExpr(LeftArg); |
| 1851 | llvm::Value *Right = EmitScalarExpr(RightArg); |
| 1852 | Address ResultPtr = EmitPointerWithAlignment(ResultArg); |
| 1853 | |
| 1854 | // Extend each operand to the encompassing type. |
| 1855 | Left = Builder.CreateIntCast(Left, EncompassingLLVMTy, LeftInfo.Signed); |
| 1856 | Right = Builder.CreateIntCast(Right, EncompassingLLVMTy, RightInfo.Signed); |
| 1857 | |
| 1858 | // Perform the operation on the extended values. |
| 1859 | llvm::Value *Overflow, *Result; |
| 1860 | Result = EmitOverflowIntrinsic(*this, IntrinsicId, Left, Right, Overflow); |
| 1861 | |
| 1862 | if (EncompassingInfo.Width > ResultInfo.Width) { |
| 1863 | // The encompassing type is wider than the result type, so we need to |
| 1864 | // truncate it. |
| 1865 | llvm::Value *ResultTrunc = Builder.CreateTrunc(Result, ResultLLVMTy); |
| 1866 | |
| 1867 | // To see if the truncation caused an overflow, we will extend |
| 1868 | // the result and then compare it to the original result. |
| 1869 | llvm::Value *ResultTruncExt = Builder.CreateIntCast( |
| 1870 | ResultTrunc, EncompassingLLVMTy, ResultInfo.Signed); |
| 1871 | llvm::Value *TruncationOverflow = |
| 1872 | Builder.CreateICmpNE(Result, ResultTruncExt); |
| 1873 | |
| 1874 | Overflow = Builder.CreateOr(Overflow, TruncationOverflow); |
| 1875 | Result = ResultTrunc; |
| 1876 | } |
| 1877 | |
| 1878 | // Finally, store the result using the pointer. |
| 1879 | bool isVolatile = |
| 1880 | ResultArg->getType()->getPointeeType().isVolatileQualified(); |
| 1881 | Builder.CreateStore(EmitToMemory(Result, ResultQTy), ResultPtr, isVolatile); |
| 1882 | |
| 1883 | return RValue::get(Overflow); |
| 1884 | } |
| 1885 | |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1886 | case Builtin::BI__builtin_uadd_overflow: |
| 1887 | case Builtin::BI__builtin_uaddl_overflow: |
| 1888 | case Builtin::BI__builtin_uaddll_overflow: |
| 1889 | case Builtin::BI__builtin_usub_overflow: |
| 1890 | case Builtin::BI__builtin_usubl_overflow: |
| 1891 | case Builtin::BI__builtin_usubll_overflow: |
| 1892 | case Builtin::BI__builtin_umul_overflow: |
| 1893 | case Builtin::BI__builtin_umull_overflow: |
| 1894 | case Builtin::BI__builtin_umulll_overflow: |
| 1895 | case Builtin::BI__builtin_sadd_overflow: |
| 1896 | case Builtin::BI__builtin_saddl_overflow: |
| 1897 | case Builtin::BI__builtin_saddll_overflow: |
| 1898 | case Builtin::BI__builtin_ssub_overflow: |
| 1899 | case Builtin::BI__builtin_ssubl_overflow: |
| 1900 | case Builtin::BI__builtin_ssubll_overflow: |
| 1901 | case Builtin::BI__builtin_smul_overflow: |
| 1902 | case Builtin::BI__builtin_smull_overflow: |
| 1903 | case Builtin::BI__builtin_smulll_overflow: { |
| 1904 | |
| 1905 | // We translate all of these builtins directly to the relevant llvm IR node. |
| 1906 | |
| 1907 | // Scalarize our inputs. |
| 1908 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 1909 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1910 | Address SumOutPtr = EmitPointerWithAlignment(E->getArg(2)); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1911 | |
| 1912 | // Decide which of the overflow intrinsics we are lowering to: |
| 1913 | llvm::Intrinsic::ID IntrinsicId; |
| 1914 | switch (BuiltinID) { |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 1915 | default: llvm_unreachable("Unknown overflow builtin id."); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1916 | case Builtin::BI__builtin_uadd_overflow: |
| 1917 | case Builtin::BI__builtin_uaddl_overflow: |
| 1918 | case Builtin::BI__builtin_uaddll_overflow: |
| 1919 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 1920 | break; |
| 1921 | case Builtin::BI__builtin_usub_overflow: |
| 1922 | case Builtin::BI__builtin_usubl_overflow: |
| 1923 | case Builtin::BI__builtin_usubll_overflow: |
| 1924 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 1925 | break; |
| 1926 | case Builtin::BI__builtin_umul_overflow: |
| 1927 | case Builtin::BI__builtin_umull_overflow: |
| 1928 | case Builtin::BI__builtin_umulll_overflow: |
| 1929 | IntrinsicId = llvm::Intrinsic::umul_with_overflow; |
| 1930 | break; |
| 1931 | case Builtin::BI__builtin_sadd_overflow: |
| 1932 | case Builtin::BI__builtin_saddl_overflow: |
| 1933 | case Builtin::BI__builtin_saddll_overflow: |
| 1934 | IntrinsicId = llvm::Intrinsic::sadd_with_overflow; |
| 1935 | break; |
| 1936 | case Builtin::BI__builtin_ssub_overflow: |
| 1937 | case Builtin::BI__builtin_ssubl_overflow: |
| 1938 | case Builtin::BI__builtin_ssubll_overflow: |
| 1939 | IntrinsicId = llvm::Intrinsic::ssub_with_overflow; |
| 1940 | break; |
| 1941 | case Builtin::BI__builtin_smul_overflow: |
| 1942 | case Builtin::BI__builtin_smull_overflow: |
| 1943 | case Builtin::BI__builtin_smulll_overflow: |
| 1944 | IntrinsicId = llvm::Intrinsic::smul_with_overflow; |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 1945 | break; |
| 1946 | } |
| 1947 | |
| 1948 | |
| 1949 | llvm::Value *Carry; |
| 1950 | llvm::Value *Sum = EmitOverflowIntrinsic(*this, IntrinsicId, X, Y, Carry); |
| 1951 | Builder.CreateStore(Sum, SumOutPtr); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 1952 | |
| 1953 | return RValue::get(Carry); |
| 1954 | } |
Richard Smith | 6cbd65d | 2013-07-11 02:27:57 +0000 | [diff] [blame] | 1955 | case Builtin::BI__builtin_addressof: |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1956 | return RValue::get(EmitLValue(E->getArg(0)).getPointer()); |
Richard Smith | 760520b | 2014-06-03 23:27:44 +0000 | [diff] [blame] | 1957 | case Builtin::BI__builtin_operator_new: |
| 1958 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 1959 | E->getArg(0), false); |
| 1960 | case Builtin::BI__builtin_operator_delete: |
| 1961 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 1962 | E->getArg(0), true); |
Nico Weber | 636fc09 | 2012-10-13 22:30:41 +0000 | [diff] [blame] | 1963 | case Builtin::BI__noop: |
Reid Kleckner | ed5d4ad | 2014-07-11 20:22:55 +0000 | [diff] [blame] | 1964 | // __noop always evaluates to an integer literal zero. |
| 1965 | return RValue::get(ConstantInt::get(IntTy, 0)); |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 1966 | case Builtin::BI__builtin_call_with_static_chain: { |
| 1967 | const CallExpr *Call = cast<CallExpr>(E->getArg(0)); |
| 1968 | const Expr *Chain = E->getArg(1); |
| 1969 | return EmitCall(Call->getCallee()->getType(), |
| 1970 | EmitScalarExpr(Call->getCallee()), Call, ReturnValue, |
| 1971 | Call->getCalleeDecl(), EmitScalarExpr(Chain)); |
| 1972 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 1973 | case Builtin::BI_InterlockedExchange8: |
| 1974 | case Builtin::BI_InterlockedExchange16: |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 1975 | case Builtin::BI_InterlockedExchange: |
| 1976 | case Builtin::BI_InterlockedExchangePointer: |
| 1977 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
| 1978 | case Builtin::BI_InterlockedCompareExchangePointer: { |
| 1979 | llvm::Type *RTy; |
| 1980 | llvm::IntegerType *IntType = |
| 1981 | IntegerType::get(getLLVMContext(), |
| 1982 | getContext().getTypeSize(E->getType())); |
| 1983 | llvm::Type *IntPtrType = IntType->getPointerTo(); |
| 1984 | |
| 1985 | llvm::Value *Destination = |
| 1986 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), IntPtrType); |
| 1987 | |
| 1988 | llvm::Value *Exchange = EmitScalarExpr(E->getArg(1)); |
| 1989 | RTy = Exchange->getType(); |
| 1990 | Exchange = Builder.CreatePtrToInt(Exchange, IntType); |
| 1991 | |
| 1992 | llvm::Value *Comparand = |
| 1993 | Builder.CreatePtrToInt(EmitScalarExpr(E->getArg(2)), IntType); |
| 1994 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 1995 | auto Result = |
| 1996 | Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange, |
| 1997 | AtomicOrdering::SequentiallyConsistent, |
| 1998 | AtomicOrdering::SequentiallyConsistent); |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 1999 | Result->setVolatile(true); |
| 2000 | |
| 2001 | return RValue::get(Builder.CreateIntToPtr(Builder.CreateExtractValue(Result, |
| 2002 | 0), |
| 2003 | RTy)); |
| 2004 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2005 | case Builtin::BI_InterlockedCompareExchange8: |
| 2006 | case Builtin::BI_InterlockedCompareExchange16: |
| 2007 | case Builtin::BI_InterlockedCompareExchange: |
| 2008 | case Builtin::BI_InterlockedCompareExchange64: { |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2009 | AtomicCmpXchgInst *CXI = Builder.CreateAtomicCmpXchg( |
| 2010 | EmitScalarExpr(E->getArg(0)), |
| 2011 | EmitScalarExpr(E->getArg(2)), |
| 2012 | EmitScalarExpr(E->getArg(1)), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2013 | AtomicOrdering::SequentiallyConsistent, |
| 2014 | AtomicOrdering::SequentiallyConsistent); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2015 | CXI->setVolatile(true); |
Tim Northover | b49b04b | 2014-06-13 14:24:59 +0000 | [diff] [blame] | 2016 | return RValue::get(Builder.CreateExtractValue(CXI, 0)); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2017 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2018 | case Builtin::BI_InterlockedIncrement16: |
Albert Gutowski | fc19fa3 | 2016-09-13 21:51:37 +0000 | [diff] [blame] | 2019 | case Builtin::BI_InterlockedIncrement: { |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2020 | llvm::Type *IntTy = ConvertType(E->getType()); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2021 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 2022 | AtomicRMWInst::Add, |
| 2023 | EmitScalarExpr(E->getArg(0)), |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2024 | ConstantInt::get(IntTy, 1), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2025 | llvm::AtomicOrdering::SequentiallyConsistent); |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2026 | return RValue::get(Builder.CreateAdd(RMWI, ConstantInt::get(IntTy, 1))); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2027 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2028 | case Builtin::BI_InterlockedDecrement16: |
Albert Gutowski | fc19fa3 | 2016-09-13 21:51:37 +0000 | [diff] [blame] | 2029 | case Builtin::BI_InterlockedDecrement: { |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2030 | llvm::Type *IntTy = ConvertType(E->getType()); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2031 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 2032 | AtomicRMWInst::Sub, |
| 2033 | EmitScalarExpr(E->getArg(0)), |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2034 | ConstantInt::get(IntTy, 1), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2035 | llvm::AtomicOrdering::SequentiallyConsistent); |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2036 | return RValue::get(Builder.CreateSub(RMWI, ConstantInt::get(IntTy, 1))); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2037 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2038 | case Builtin::BI_InterlockedAnd8: |
| 2039 | case Builtin::BI_InterlockedAnd16: |
| 2040 | case Builtin::BI_InterlockedAnd: |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2041 | return EmitBinaryAtomic(*this, AtomicRMWInst::And, E); |
| 2042 | case Builtin::BI_InterlockedExchangeAdd8: |
| 2043 | case Builtin::BI_InterlockedExchangeAdd16: |
| 2044 | case Builtin::BI_InterlockedExchangeAdd: |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2045 | return EmitBinaryAtomic(*this, AtomicRMWInst::Add, E); |
| 2046 | case Builtin::BI_InterlockedExchangeSub8: |
| 2047 | case Builtin::BI_InterlockedExchangeSub16: |
| 2048 | case Builtin::BI_InterlockedExchangeSub: |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2049 | return EmitBinaryAtomic(*this, AtomicRMWInst::Sub, E); |
| 2050 | case Builtin::BI_InterlockedOr8: |
| 2051 | case Builtin::BI_InterlockedOr16: |
| 2052 | case Builtin::BI_InterlockedOr: |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2053 | return EmitBinaryAtomic(*this, AtomicRMWInst::Or, E); |
| 2054 | case Builtin::BI_InterlockedXor8: |
| 2055 | case Builtin::BI_InterlockedXor16: |
| 2056 | case Builtin::BI_InterlockedXor: |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2057 | return EmitBinaryAtomic(*this, AtomicRMWInst::Xor, E); |
Saleem Abdulrasool | a25fbef | 2014-10-29 16:35:41 +0000 | [diff] [blame] | 2058 | case Builtin::BI__readfsdword: { |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2059 | llvm::Type *IntTy = ConvertType(E->getType()); |
Saleem Abdulrasool | a25fbef | 2014-10-29 16:35:41 +0000 | [diff] [blame] | 2060 | Value *IntToPtr = |
| 2061 | Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2062 | llvm::PointerType::get(IntTy, 257)); |
Saleem Abdulrasool | a25fbef | 2014-10-29 16:35:41 +0000 | [diff] [blame] | 2063 | LoadInst *Load = |
David Majnemer | e6abf3d | 2016-05-27 02:06:19 +0000 | [diff] [blame] | 2064 | Builder.CreateDefaultAlignedLoad(IntToPtr, /*isVolatile=*/true); |
Saleem Abdulrasool | a25fbef | 2014-10-29 16:35:41 +0000 | [diff] [blame] | 2065 | return RValue::get(Load); |
| 2066 | } |
Reid Kleckner | 1d59f99 | 2015-01-22 01:36:17 +0000 | [diff] [blame] | 2067 | |
| 2068 | case Builtin::BI__exception_code: |
| 2069 | case Builtin::BI_exception_code: |
| 2070 | return RValue::get(EmitSEHExceptionCode()); |
| 2071 | case Builtin::BI__exception_info: |
| 2072 | case Builtin::BI_exception_info: |
| 2073 | return RValue::get(EmitSEHExceptionInfo()); |
Reid Kleckner | aca01db | 2015-02-04 22:37:07 +0000 | [diff] [blame] | 2074 | case Builtin::BI__abnormal_termination: |
| 2075 | case Builtin::BI_abnormal_termination: |
| 2076 | return RValue::get(EmitSEHAbnormalTermination()); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2077 | case Builtin::BI_setjmpex: { |
| 2078 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 2079 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 2080 | llvm::AttributeSet ReturnsTwiceAttr = |
| 2081 | AttributeSet::get(getLLVMContext(), llvm::AttributeSet::FunctionIndex, |
| 2082 | llvm::Attribute::ReturnsTwice); |
| 2083 | llvm::Constant *SetJmpEx = CGM.CreateRuntimeFunction( |
| 2084 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
| 2085 | "_setjmpex", ReturnsTwiceAttr); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2086 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 2087 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2088 | llvm::Value *FrameAddr = |
| 2089 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 2090 | ConstantInt::get(Int32Ty, 0)); |
| 2091 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 2092 | llvm::CallSite CS = EmitRuntimeCallOrInvoke(SetJmpEx, Args); |
| 2093 | CS.setAttributes(ReturnsTwiceAttr); |
| 2094 | return RValue::get(CS.getInstruction()); |
| 2095 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2096 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2097 | } |
| 2098 | case Builtin::BI_setjmp: { |
| 2099 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 2100 | llvm::AttributeSet ReturnsTwiceAttr = |
| 2101 | AttributeSet::get(getLLVMContext(), llvm::AttributeSet::FunctionIndex, |
| 2102 | llvm::Attribute::ReturnsTwice); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2103 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 2104 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2105 | llvm::CallSite CS; |
| 2106 | if (getTarget().getTriple().getArch() == llvm::Triple::x86) { |
| 2107 | llvm::Type *ArgTypes[] = {Int8PtrTy, IntTy}; |
| 2108 | llvm::Constant *SetJmp3 = CGM.CreateRuntimeFunction( |
| 2109 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/true), |
| 2110 | "_setjmp3", ReturnsTwiceAttr); |
| 2111 | llvm::Value *Count = ConstantInt::get(IntTy, 0); |
| 2112 | llvm::Value *Args[] = {Buf, Count}; |
| 2113 | CS = EmitRuntimeCallOrInvoke(SetJmp3, Args); |
| 2114 | } else { |
| 2115 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 2116 | llvm::Constant *SetJmp = CGM.CreateRuntimeFunction( |
| 2117 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
| 2118 | "_setjmp", ReturnsTwiceAttr); |
| 2119 | llvm::Value *FrameAddr = |
| 2120 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 2121 | ConstantInt::get(Int32Ty, 0)); |
| 2122 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 2123 | CS = EmitRuntimeCallOrInvoke(SetJmp, Args); |
| 2124 | } |
| 2125 | CS.setAttributes(ReturnsTwiceAttr); |
| 2126 | return RValue::get(CS.getInstruction()); |
| 2127 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2128 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2129 | } |
David Majnemer | ba3e5ec | 2015-03-13 18:26:17 +0000 | [diff] [blame] | 2130 | |
| 2131 | case Builtin::BI__GetExceptionInfo: { |
| 2132 | if (llvm::GlobalVariable *GV = |
| 2133 | CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType())) |
| 2134 | return RValue::get(llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy)); |
| 2135 | break; |
| 2136 | } |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2137 | |
Gor Nishanov | 97e3b6d | 2016-10-03 22:44:48 +0000 | [diff] [blame^] | 2138 | case Builtin::BI__builtin_coro_size: { |
| 2139 | auto & Context = getContext(); |
| 2140 | auto SizeTy = Context.getSizeType(); |
| 2141 | auto T = Builder.getIntNTy(Context.getTypeSize(SizeTy)); |
| 2142 | Value *F = CGM.getIntrinsic(Intrinsic::coro_size, T); |
| 2143 | return RValue::get(Builder.CreateCall(F)); |
| 2144 | } |
| 2145 | |
| 2146 | case Builtin::BI__builtin_coro_id: |
| 2147 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_id); |
| 2148 | case Builtin::BI__builtin_coro_promise: |
| 2149 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_promise); |
| 2150 | case Builtin::BI__builtin_coro_resume: |
| 2151 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_resume); |
| 2152 | case Builtin::BI__builtin_coro_frame: |
| 2153 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_frame); |
| 2154 | case Builtin::BI__builtin_coro_free: |
| 2155 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_free); |
| 2156 | case Builtin::BI__builtin_coro_destroy: |
| 2157 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_destroy); |
| 2158 | case Builtin::BI__builtin_coro_done: |
| 2159 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_done); |
| 2160 | case Builtin::BI__builtin_coro_alloc: |
| 2161 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_alloc); |
| 2162 | case Builtin::BI__builtin_coro_begin: |
| 2163 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_begin); |
| 2164 | case Builtin::BI__builtin_coro_end: |
| 2165 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_end); |
| 2166 | case Builtin::BI__builtin_coro_suspend: |
| 2167 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_suspend); |
| 2168 | case Builtin::BI__builtin_coro_param: |
| 2169 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_param); |
| 2170 | |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2171 | // OpenCL v2.0 s6.13.16.2, Built-in pipe read and write functions |
| 2172 | case Builtin::BIread_pipe: |
| 2173 | case Builtin::BIwrite_pipe: { |
| 2174 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2175 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2176 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2177 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2178 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2179 | |
| 2180 | // Type of the generic packet parameter. |
| 2181 | unsigned GenericAS = |
| 2182 | getContext().getTargetAddressSpace(LangAS::opencl_generic); |
| 2183 | llvm::Type *I8PTy = llvm::PointerType::get( |
| 2184 | llvm::Type::getInt8Ty(getLLVMContext()), GenericAS); |
| 2185 | |
| 2186 | // Testing which overloaded version we should generate the call for. |
| 2187 | if (2U == E->getNumArgs()) { |
| 2188 | const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_2" |
| 2189 | : "__write_pipe_2"; |
| 2190 | // Creating a generic function type to be able to call with any builtin or |
| 2191 | // user defined type. |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2192 | llvm::Type *ArgTys[] = {Arg0->getType(), I8PTy, Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2193 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2194 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2195 | Value *BCast = Builder.CreatePointerCast(Arg1, I8PTy); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2196 | return RValue::get( |
| 2197 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2198 | {Arg0, BCast, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2199 | } else { |
| 2200 | assert(4 == E->getNumArgs() && |
| 2201 | "Illegal number of parameters to pipe function"); |
| 2202 | const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_4" |
| 2203 | : "__write_pipe_4"; |
| 2204 | |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2205 | llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, I8PTy, |
| 2206 | Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2207 | Value *Arg2 = EmitScalarExpr(E->getArg(2)), |
| 2208 | *Arg3 = EmitScalarExpr(E->getArg(3)); |
| 2209 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2210 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2211 | Value *BCast = Builder.CreatePointerCast(Arg3, I8PTy); |
| 2212 | // We know the third argument is an integer type, but we may need to cast |
| 2213 | // it to i32. |
| 2214 | if (Arg2->getType() != Int32Ty) |
| 2215 | Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty); |
| 2216 | return RValue::get(Builder.CreateCall( |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2217 | CGM.CreateRuntimeFunction(FTy, Name), |
| 2218 | {Arg0, Arg1, Arg2, BCast, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2219 | } |
| 2220 | } |
| 2221 | // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write |
| 2222 | // functions |
| 2223 | case Builtin::BIreserve_read_pipe: |
| 2224 | case Builtin::BIreserve_write_pipe: |
| 2225 | case Builtin::BIwork_group_reserve_read_pipe: |
| 2226 | case Builtin::BIwork_group_reserve_write_pipe: |
| 2227 | case Builtin::BIsub_group_reserve_read_pipe: |
| 2228 | case Builtin::BIsub_group_reserve_write_pipe: { |
| 2229 | // Composing the mangled name for the function. |
| 2230 | const char *Name; |
| 2231 | if (BuiltinID == Builtin::BIreserve_read_pipe) |
| 2232 | Name = "__reserve_read_pipe"; |
| 2233 | else if (BuiltinID == Builtin::BIreserve_write_pipe) |
| 2234 | Name = "__reserve_write_pipe"; |
| 2235 | else if (BuiltinID == Builtin::BIwork_group_reserve_read_pipe) |
| 2236 | Name = "__work_group_reserve_read_pipe"; |
| 2237 | else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe) |
| 2238 | Name = "__work_group_reserve_write_pipe"; |
| 2239 | else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe) |
| 2240 | Name = "__sub_group_reserve_read_pipe"; |
| 2241 | else |
| 2242 | Name = "__sub_group_reserve_write_pipe"; |
| 2243 | |
| 2244 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2245 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 2246 | llvm::Type *ReservedIDTy = ConvertType(getContext().OCLReserveIDTy); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2247 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2248 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2249 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2250 | |
| 2251 | // Building the generic function prototype. |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2252 | llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty, Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2253 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2254 | ReservedIDTy, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2255 | // We know the second argument is an integer type, but we may need to cast |
| 2256 | // it to i32. |
| 2257 | if (Arg1->getType() != Int32Ty) |
| 2258 | Arg1 = Builder.CreateZExtOrTrunc(Arg1, Int32Ty); |
| 2259 | return RValue::get( |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2260 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2261 | {Arg0, Arg1, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2262 | } |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 2263 | // OpenCL v2.0 s6.13.16, s9.17.3.5 - Built-in pipe commit read and write |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2264 | // functions |
| 2265 | case Builtin::BIcommit_read_pipe: |
| 2266 | case Builtin::BIcommit_write_pipe: |
| 2267 | case Builtin::BIwork_group_commit_read_pipe: |
| 2268 | case Builtin::BIwork_group_commit_write_pipe: |
| 2269 | case Builtin::BIsub_group_commit_read_pipe: |
| 2270 | case Builtin::BIsub_group_commit_write_pipe: { |
| 2271 | const char *Name; |
| 2272 | if (BuiltinID == Builtin::BIcommit_read_pipe) |
| 2273 | Name = "__commit_read_pipe"; |
| 2274 | else if (BuiltinID == Builtin::BIcommit_write_pipe) |
| 2275 | Name = "__commit_write_pipe"; |
| 2276 | else if (BuiltinID == Builtin::BIwork_group_commit_read_pipe) |
| 2277 | Name = "__work_group_commit_read_pipe"; |
| 2278 | else if (BuiltinID == Builtin::BIwork_group_commit_write_pipe) |
| 2279 | Name = "__work_group_commit_write_pipe"; |
| 2280 | else if (BuiltinID == Builtin::BIsub_group_commit_read_pipe) |
| 2281 | Name = "__sub_group_commit_read_pipe"; |
| 2282 | else |
| 2283 | Name = "__sub_group_commit_write_pipe"; |
| 2284 | |
| 2285 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2286 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2287 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2288 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2289 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2290 | |
| 2291 | // Building the generic function prototype. |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2292 | llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2293 | llvm::FunctionType *FTy = |
| 2294 | llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()), |
| 2295 | llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2296 | |
| 2297 | return RValue::get( |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2298 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2299 | {Arg0, Arg1, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2300 | } |
| 2301 | // OpenCL v2.0 s6.13.16.4 Built-in pipe query functions |
| 2302 | case Builtin::BIget_pipe_num_packets: |
| 2303 | case Builtin::BIget_pipe_max_packets: { |
| 2304 | const char *Name; |
| 2305 | if (BuiltinID == Builtin::BIget_pipe_num_packets) |
| 2306 | Name = "__get_pipe_num_packets"; |
| 2307 | else |
| 2308 | Name = "__get_pipe_max_packets"; |
| 2309 | |
| 2310 | // Building the generic function prototype. |
| 2311 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2312 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2313 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2314 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
| 2315 | llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2316 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2317 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2318 | |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2319 | return RValue::get(Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2320 | {Arg0, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 2323 | // OpenCL v2.0 s6.13.9 - Address space qualifier functions. |
| 2324 | case Builtin::BIto_global: |
| 2325 | case Builtin::BIto_local: |
| 2326 | case Builtin::BIto_private: { |
| 2327 | auto Arg0 = EmitScalarExpr(E->getArg(0)); |
| 2328 | auto NewArgT = llvm::PointerType::get(Int8Ty, |
| 2329 | CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
| 2330 | auto NewRetT = llvm::PointerType::get(Int8Ty, |
| 2331 | CGM.getContext().getTargetAddressSpace( |
| 2332 | E->getType()->getPointeeType().getAddressSpace())); |
| 2333 | auto FTy = llvm::FunctionType::get(NewRetT, {NewArgT}, false); |
| 2334 | llvm::Value *NewArg; |
| 2335 | if (Arg0->getType()->getPointerAddressSpace() != |
| 2336 | NewArgT->getPointerAddressSpace()) |
| 2337 | NewArg = Builder.CreateAddrSpaceCast(Arg0, NewArgT); |
| 2338 | else |
| 2339 | NewArg = Builder.CreateBitOrPointerCast(Arg0, NewArgT); |
Alexey Bader | d8162326 | 2016-08-04 18:06:27 +0000 | [diff] [blame] | 2340 | auto NewName = std::string("__") + E->getDirectCallee()->getName().str(); |
| 2341 | auto NewCall = |
| 2342 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, NewName), {NewArg}); |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 2343 | return RValue::get(Builder.CreateBitOrPointerCast(NewCall, |
| 2344 | ConvertType(E->getType()))); |
| 2345 | } |
| 2346 | |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2347 | // OpenCL v2.0, s6.13.17 - Enqueue kernel function. |
| 2348 | // It contains four different overload formats specified in Table 6.13.17.1. |
| 2349 | case Builtin::BIenqueue_kernel: { |
| 2350 | StringRef Name; // Generated function call name |
| 2351 | unsigned NumArgs = E->getNumArgs(); |
| 2352 | |
| 2353 | llvm::Type *QueueTy = ConvertType(getContext().OCLQueueTy); |
| 2354 | llvm::Type *RangeTy = ConvertType(getContext().OCLNDRangeTy); |
| 2355 | |
| 2356 | llvm::Value *Queue = EmitScalarExpr(E->getArg(0)); |
| 2357 | llvm::Value *Flags = EmitScalarExpr(E->getArg(1)); |
| 2358 | llvm::Value *Range = EmitScalarExpr(E->getArg(2)); |
| 2359 | |
| 2360 | if (NumArgs == 4) { |
| 2361 | // The most basic form of the call with parameters: |
| 2362 | // queue_t, kernel_enqueue_flags_t, ndrange_t, block(void) |
| 2363 | Name = "__enqueue_kernel_basic"; |
| 2364 | llvm::Type *ArgTys[] = {QueueTy, Int32Ty, RangeTy, Int8PtrTy}; |
| 2365 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2366 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys, 4), false); |
| 2367 | |
| 2368 | llvm::Value *Block = |
| 2369 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(3)), Int8PtrTy); |
| 2370 | |
| 2371 | return RValue::get(Builder.CreateCall( |
| 2372 | CGM.CreateRuntimeFunction(FTy, Name), {Queue, Flags, Range, Block})); |
| 2373 | } |
| 2374 | assert(NumArgs >= 5 && "Invalid enqueue_kernel signature"); |
| 2375 | |
| 2376 | // Could have events and/or vaargs. |
| 2377 | if (E->getArg(3)->getType()->isBlockPointerType()) { |
| 2378 | // No events passed, but has variadic arguments. |
| 2379 | Name = "__enqueue_kernel_vaargs"; |
| 2380 | llvm::Value *Block = |
| 2381 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(3)), Int8PtrTy); |
| 2382 | // Create a vector of the arguments, as well as a constant value to |
| 2383 | // express to the runtime the number of variadic arguments. |
| 2384 | std::vector<llvm::Value *> Args = {Queue, Flags, Range, Block, |
| 2385 | ConstantInt::get(IntTy, NumArgs - 4)}; |
| 2386 | std::vector<llvm::Type *> ArgTys = {QueueTy, IntTy, RangeTy, Int8PtrTy, |
| 2387 | IntTy}; |
| 2388 | |
| 2389 | // Add the variadics. |
| 2390 | for (unsigned I = 4; I < NumArgs; ++I) { |
| 2391 | llvm::Value *ArgSize = EmitScalarExpr(E->getArg(I)); |
| 2392 | unsigned TypeSizeInBytes = |
| 2393 | getContext() |
| 2394 | .getTypeSizeInChars(E->getArg(I)->getType()) |
| 2395 | .getQuantity(); |
| 2396 | Args.push_back(TypeSizeInBytes < 4 |
| 2397 | ? Builder.CreateZExt(ArgSize, Int32Ty) |
| 2398 | : ArgSize); |
| 2399 | } |
| 2400 | |
| 2401 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2402 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), true); |
| 2403 | return RValue::get( |
| 2404 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2405 | llvm::ArrayRef<llvm::Value *>(Args))); |
| 2406 | } |
| 2407 | // Any calls now have event arguments passed. |
| 2408 | if (NumArgs >= 7) { |
| 2409 | llvm::Type *EventTy = ConvertType(getContext().OCLClkEventTy); |
| 2410 | unsigned AS4 = |
| 2411 | E->getArg(4)->getType()->isArrayType() |
| 2412 | ? E->getArg(4)->getType().getAddressSpace() |
| 2413 | : E->getArg(4)->getType()->getPointeeType().getAddressSpace(); |
| 2414 | llvm::Type *EventPtrAS4Ty = |
| 2415 | EventTy->getPointerTo(CGM.getContext().getTargetAddressSpace(AS4)); |
| 2416 | unsigned AS5 = |
| 2417 | E->getArg(5)->getType()->getPointeeType().getAddressSpace(); |
| 2418 | llvm::Type *EventPtrAS5Ty = |
| 2419 | EventTy->getPointerTo(CGM.getContext().getTargetAddressSpace(AS5)); |
| 2420 | |
| 2421 | llvm::Value *NumEvents = EmitScalarExpr(E->getArg(3)); |
| 2422 | llvm::Value *EventList = |
| 2423 | E->getArg(4)->getType()->isArrayType() |
| 2424 | ? EmitArrayToPointerDecay(E->getArg(4)).getPointer() |
| 2425 | : EmitScalarExpr(E->getArg(4)); |
| 2426 | llvm::Value *ClkEvent = EmitScalarExpr(E->getArg(5)); |
| 2427 | llvm::Value *Block = |
| 2428 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(6)), Int8PtrTy); |
| 2429 | |
| 2430 | std::vector<llvm::Type *> ArgTys = { |
| 2431 | QueueTy, Int32Ty, RangeTy, Int32Ty, |
| 2432 | EventPtrAS4Ty, EventPtrAS5Ty, Int8PtrTy}; |
| 2433 | std::vector<llvm::Value *> Args = {Queue, Flags, Range, NumEvents, |
| 2434 | EventList, ClkEvent, Block}; |
| 2435 | |
| 2436 | if (NumArgs == 7) { |
| 2437 | // Has events but no variadics. |
| 2438 | Name = "__enqueue_kernel_basic_events"; |
| 2439 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2440 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2441 | return RValue::get( |
| 2442 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2443 | llvm::ArrayRef<llvm::Value *>(Args))); |
| 2444 | } |
| 2445 | // Has event info and variadics |
| 2446 | // Pass the number of variadics to the runtime function too. |
| 2447 | Args.push_back(ConstantInt::get(Int32Ty, NumArgs - 7)); |
| 2448 | ArgTys.push_back(Int32Ty); |
| 2449 | Name = "__enqueue_kernel_events_vaargs"; |
| 2450 | |
| 2451 | // Add the variadics. |
| 2452 | for (unsigned I = 7; I < NumArgs; ++I) { |
| 2453 | llvm::Value *ArgSize = EmitScalarExpr(E->getArg(I)); |
| 2454 | unsigned TypeSizeInBytes = |
| 2455 | getContext() |
| 2456 | .getTypeSizeInChars(E->getArg(I)->getType()) |
| 2457 | .getQuantity(); |
| 2458 | Args.push_back(TypeSizeInBytes < 4 |
| 2459 | ? Builder.CreateZExt(ArgSize, Int32Ty) |
| 2460 | : ArgSize); |
| 2461 | } |
| 2462 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2463 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), true); |
| 2464 | return RValue::get( |
| 2465 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2466 | llvm::ArrayRef<llvm::Value *>(Args))); |
| 2467 | } |
| 2468 | } |
| 2469 | // OpenCL v2.0 s6.13.17.6 - Kernel query functions need bitcast of block |
| 2470 | // parameter. |
| 2471 | case Builtin::BIget_kernel_work_group_size: { |
| 2472 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 2473 | Arg = Builder.CreateBitCast(Arg, Int8PtrTy); |
| 2474 | return RValue::get( |
| 2475 | Builder.CreateCall(CGM.CreateRuntimeFunction( |
| 2476 | llvm::FunctionType::get(IntTy, Int8PtrTy, false), |
| 2477 | "__get_kernel_work_group_size_impl"), |
| 2478 | Arg)); |
| 2479 | } |
| 2480 | case Builtin::BIget_kernel_preferred_work_group_size_multiple: { |
| 2481 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 2482 | Arg = Builder.CreateBitCast(Arg, Int8PtrTy); |
| 2483 | return RValue::get(Builder.CreateCall( |
| 2484 | CGM.CreateRuntimeFunction( |
| 2485 | llvm::FunctionType::get(IntTy, Int8PtrTy, false), |
| 2486 | "__get_kernel_preferred_work_group_multiple_impl"), |
| 2487 | Arg)); |
| 2488 | } |
Justin Lebar | 3039a59 | 2016-01-23 21:28:14 +0000 | [diff] [blame] | 2489 | case Builtin::BIprintf: |
| 2490 | if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) |
| 2491 | return EmitCUDADevicePrintfCallExpr(E, ReturnValue); |
Matt Arsenault | 2d93398 | 2016-02-27 09:06:18 +0000 | [diff] [blame] | 2492 | break; |
| 2493 | case Builtin::BI__builtin_canonicalize: |
| 2494 | case Builtin::BI__builtin_canonicalizef: |
| 2495 | case Builtin::BI__builtin_canonicalizel: |
| 2496 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::canonicalize)); |
Marcin Koscielnicki | a46fade | 2016-06-16 13:41:54 +0000 | [diff] [blame] | 2497 | |
| 2498 | case Builtin::BI__builtin_thread_pointer: { |
| 2499 | if (!getContext().getTargetInfo().isTLSSupported()) |
| 2500 | CGM.ErrorUnsupported(E, "__builtin_thread_pointer"); |
| 2501 | // Fall through - it's already mapped to the intrinsic by GCCBuiltin. |
| 2502 | break; |
| 2503 | } |
Nate Begeman | 6c59132 | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 2504 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2505 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 2506 | // If this is an alias for a lib function (e.g. __builtin_sin), emit |
| 2507 | // the call using the normal call path, but using the unmangled |
| 2508 | // version of the function name. |
| 2509 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) |
| 2510 | return emitLibraryCall(*this, FD, E, |
| 2511 | CGM.getBuiltinLibFunction(FD, BuiltinID)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2512 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 2513 | // If this is a predefined lib function (e.g. malloc), emit the call |
| 2514 | // using exactly the normal call path. |
| 2515 | if (getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
| 2516 | return emitLibraryCall(*this, FD, E, EmitScalarExpr(E->getCallee())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2517 | |
Eric Christopher | 1570999 | 2015-10-15 23:47:11 +0000 | [diff] [blame] | 2518 | // Check that a call to a target specific builtin has the correct target |
| 2519 | // features. |
| 2520 | // This is down here to avoid non-target specific builtins, however, if |
| 2521 | // generic builtins start to require generic target features then we |
| 2522 | // can move this up to the beginning of the function. |
Eric Christopher | c7e79db | 2015-11-12 00:44:04 +0000 | [diff] [blame] | 2523 | checkTargetFeatures(E, FD); |
Eric Christopher | 1570999 | 2015-10-15 23:47:11 +0000 | [diff] [blame] | 2524 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2525 | // See if we have a target specific intrinsic. |
Eric Christopher | 02d5d86 | 2015-08-06 01:01:12 +0000 | [diff] [blame] | 2526 | const char *Name = getContext().BuiltinInfo.getName(BuiltinID); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2527 | Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; |
Mehdi Amini | b7fb124 | 2016-10-01 01:16:22 +0000 | [diff] [blame] | 2528 | StringRef Prefix = |
| 2529 | llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch()); |
| 2530 | if (!Prefix.empty()) { |
| 2531 | IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix.data(), Name); |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 2532 | // NOTE we dont need to perform a compatibility flag check here since the |
| 2533 | // intrinsics are declared in Builtins*.def via LANGBUILTIN which filter the |
| 2534 | // MS builtins via ALL_MS_LANGUAGES and are filtered earlier. |
| 2535 | if (IntrinsicID == Intrinsic::not_intrinsic) |
Mehdi Amini | b7fb124 | 2016-10-01 01:16:22 +0000 | [diff] [blame] | 2536 | IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix.data(), Name); |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 2537 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2538 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2539 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
| 2540 | SmallVector<Value*, 16> Args; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2541 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 2542 | // Find out if any arguments are required to be integer constant |
| 2543 | // expressions. |
| 2544 | unsigned ICEArguments = 0; |
| 2545 | ASTContext::GetBuiltinTypeError Error; |
| 2546 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 2547 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 2548 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2549 | Function *F = CGM.getIntrinsic(IntrinsicID); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2550 | llvm::FunctionType *FTy = F->getFunctionType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2551 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2552 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 2553 | Value *ArgValue; |
| 2554 | // If this is a normal argument, just emit it as a scalar. |
| 2555 | if ((ICEArguments & (1 << i)) == 0) { |
| 2556 | ArgValue = EmitScalarExpr(E->getArg(i)); |
| 2557 | } else { |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2558 | // 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] | 2559 | // know that the generated intrinsic gets a ConstantInt. |
| 2560 | llvm::APSInt Result; |
| 2561 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext()); |
| 2562 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 2563 | (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 2564 | ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 2565 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2566 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2567 | // If the intrinsic arg type is different from the builtin arg type |
| 2568 | // we need to do a bit cast. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2569 | llvm::Type *PTy = FTy->getParamType(i); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2570 | if (PTy != ArgValue->getType()) { |
| 2571 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 2572 | "Must be able to losslessly bit cast to param"); |
| 2573 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 2574 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2575 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2576 | Args.push_back(ArgValue); |
| 2577 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 2579 | Value *V = Builder.CreateCall(F, Args); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2580 | QualType BuiltinRetType = E->getType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2581 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 2582 | llvm::Type *RetTy = VoidTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2583 | if (!BuiltinRetType->isVoidType()) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 2584 | RetTy = ConvertType(BuiltinRetType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2585 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2586 | if (RetTy != V->getType()) { |
| 2587 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 2588 | "Must be able to losslessly bit cast result type"); |
| 2589 | V = Builder.CreateBitCast(V, RetTy); |
| 2590 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2592 | return RValue::get(V); |
| 2593 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2594 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2595 | // 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] | 2596 | if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2597 | return RValue::get(V); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2598 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 2599 | ErrorUnsupported(E, "builtin function"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2600 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 2601 | // Unknown builtin, for now just dump it out and return undef. |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 2602 | return GetUndefRValue(E->getType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2603 | } |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 2604 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2605 | static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF, |
| 2606 | unsigned BuiltinID, const CallExpr *E, |
| 2607 | llvm::Triple::ArchType Arch) { |
| 2608 | switch (Arch) { |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2609 | case llvm::Triple::arm: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 2610 | case llvm::Triple::armeb: |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2611 | case llvm::Triple::thumb: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 2612 | case llvm::Triple::thumbeb: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2613 | return CGF->EmitARMBuiltinExpr(BuiltinID, E); |
Tim Northover | 25e8a67 | 2014-05-24 12:51:25 +0000 | [diff] [blame] | 2614 | case llvm::Triple::aarch64: |
| 2615 | case llvm::Triple::aarch64_be: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2616 | return CGF->EmitAArch64BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2617 | case llvm::Triple::x86: |
| 2618 | case llvm::Triple::x86_64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2619 | return CGF->EmitX86BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2620 | case llvm::Triple::ppc: |
| 2621 | case llvm::Triple::ppc64: |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 2622 | case llvm::Triple::ppc64le: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2623 | return CGF->EmitPPCBuiltinExpr(BuiltinID, E); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 2624 | case llvm::Triple::r600: |
Tom Stellard | d8e38a3 | 2015-01-06 20:34:47 +0000 | [diff] [blame] | 2625 | case llvm::Triple::amdgcn: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2626 | return CGF->EmitAMDGPUBuiltinExpr(BuiltinID, E); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 2627 | case llvm::Triple::systemz: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2628 | return CGF->EmitSystemZBuiltinExpr(BuiltinID, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 2629 | case llvm::Triple::nvptx: |
| 2630 | case llvm::Triple::nvptx64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2631 | return CGF->EmitNVPTXBuiltinExpr(BuiltinID, E); |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 2632 | case llvm::Triple::wasm32: |
| 2633 | case llvm::Triple::wasm64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2634 | return CGF->EmitWebAssemblyBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2635 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2636 | return nullptr; |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 2637 | } |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 2640 | Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, |
| 2641 | const CallExpr *E) { |
| 2642 | if (getContext().BuiltinInfo.isAuxBuiltinID(BuiltinID)) { |
| 2643 | assert(getContext().getAuxTargetInfo() && "Missing aux target info"); |
| 2644 | return EmitTargetArchBuiltinExpr( |
| 2645 | this, getContext().BuiltinInfo.getAuxBuiltinID(BuiltinID), E, |
| 2646 | getContext().getAuxTargetInfo()->getTriple().getArch()); |
| 2647 | } |
| 2648 | |
| 2649 | return EmitTargetArchBuiltinExpr(this, BuiltinID, E, |
| 2650 | getTarget().getTriple().getArch()); |
| 2651 | } |
| 2652 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 2653 | static llvm::VectorType *GetNeonType(CodeGenFunction *CGF, |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2654 | NeonTypeFlags TypeFlags, |
| 2655 | bool V1Ty=false) { |
NAKAMURA Takumi | dabda6b | 2011-11-08 03:27:04 +0000 | [diff] [blame] | 2656 | int IsQuad = TypeFlags.isQuad(); |
| 2657 | switch (TypeFlags.getEltType()) { |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2658 | case NeonTypeFlags::Int8: |
| 2659 | case NeonTypeFlags::Poly8: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2660 | return llvm::VectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2661 | case NeonTypeFlags::Int16: |
| 2662 | case NeonTypeFlags::Poly16: |
| 2663 | case NeonTypeFlags::Float16: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2664 | return llvm::VectorType::get(CGF->Int16Ty, V1Ty ? 1 : (4 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2665 | case NeonTypeFlags::Int32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2666 | return llvm::VectorType::get(CGF->Int32Ty, V1Ty ? 1 : (2 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2667 | case NeonTypeFlags::Int64: |
Kevin Qin | caac85e | 2013-11-14 03:29:16 +0000 | [diff] [blame] | 2668 | case NeonTypeFlags::Poly64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2669 | return llvm::VectorType::get(CGF->Int64Ty, V1Ty ? 1 : (1 << IsQuad)); |
Kevin Qin | fb79d7f | 2013-12-10 06:49:01 +0000 | [diff] [blame] | 2670 | case NeonTypeFlags::Poly128: |
| 2671 | // FIXME: i128 and f128 doesn't get fully support in Clang and llvm. |
| 2672 | // There is a lot of i128 and f128 API missing. |
| 2673 | // so we use v16i8 to represent poly128 and get pattern matched. |
| 2674 | return llvm::VectorType::get(CGF->Int8Ty, 16); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 2675 | case NeonTypeFlags::Float32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2676 | return llvm::VectorType::get(CGF->FloatTy, V1Ty ? 1 : (2 << IsQuad)); |
Tim Northover | 2fe823a | 2013-08-01 09:23:19 +0000 | [diff] [blame] | 2677 | case NeonTypeFlags::Float64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 2678 | return llvm::VectorType::get(CGF->DoubleTy, V1Ty ? 1 : (1 << IsQuad)); |
David Blaikie | f47fa30 | 2012-01-17 02:30:50 +0000 | [diff] [blame] | 2679 | } |
Benjamin Kramer | 9b1dfe8 | 2013-09-26 16:36:08 +0000 | [diff] [blame] | 2680 | llvm_unreachable("Unknown vector element type!"); |
Nate Begeman | 5968eb2 | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 2683 | static llvm::VectorType *GetFloatNeonType(CodeGenFunction *CGF, |
| 2684 | NeonTypeFlags IntTypeFlags) { |
| 2685 | int IsQuad = IntTypeFlags.isQuad(); |
| 2686 | switch (IntTypeFlags.getEltType()) { |
| 2687 | case NeonTypeFlags::Int32: |
| 2688 | return llvm::VectorType::get(CGF->FloatTy, (2 << IsQuad)); |
| 2689 | case NeonTypeFlags::Int64: |
| 2690 | return llvm::VectorType::get(CGF->DoubleTy, (1 << IsQuad)); |
| 2691 | default: |
| 2692 | llvm_unreachable("Type can't be converted to floating-point!"); |
| 2693 | } |
| 2694 | } |
| 2695 | |
Bob Wilson | 210f6dd | 2010-12-07 22:40:02 +0000 | [diff] [blame] | 2696 | Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) { |
Craig Topper | f2f1a09 | 2016-07-08 02:17:35 +0000 | [diff] [blame] | 2697 | unsigned nElts = V->getType()->getVectorNumElements(); |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 2698 | Value* SV = llvm::ConstantVector::getSplat(nElts, C); |
Nate Begeman | 4a04b46 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 2699 | return Builder.CreateShuffleVector(V, V, SV, "lane"); |
| 2700 | } |
| 2701 | |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2702 | Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops, |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 2703 | const char *name, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 2704 | unsigned shift, bool rightshift) { |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2705 | unsigned j = 0; |
| 2706 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 2707 | ai != ae; ++ai, ++j) |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 2708 | if (shift > 0 && shift == j) |
| 2709 | Ops[j] = EmitNeonShiftVector(Ops[j], ai->getType(), rightshift); |
| 2710 | else |
| 2711 | Ops[j] = Builder.CreateBitCast(Ops[j], ai->getType(), name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2712 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 2713 | return Builder.CreateCall(F, Ops, name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2716 | Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty, |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 2717 | bool neg) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 2718 | int SV = cast<ConstantInt>(V)->getSExtValue(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 2719 | return ConstantInt::get(Ty, neg ? -SV : SV); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 2722 | // \brief Right-shift a vector by a constant. |
| 2723 | Value *CodeGenFunction::EmitNeonRShiftImm(Value *Vec, Value *Shift, |
| 2724 | llvm::Type *Ty, bool usgn, |
| 2725 | const char *name) { |
| 2726 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 2727 | |
| 2728 | int ShiftAmt = cast<ConstantInt>(Shift)->getSExtValue(); |
| 2729 | int EltSize = VTy->getScalarSizeInBits(); |
| 2730 | |
| 2731 | Vec = Builder.CreateBitCast(Vec, Ty); |
| 2732 | |
| 2733 | // lshr/ashr are undefined when the shift amount is equal to the vector |
| 2734 | // element size. |
| 2735 | if (ShiftAmt == EltSize) { |
| 2736 | if (usgn) { |
| 2737 | // Right-shifting an unsigned value by its size yields 0. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 2738 | return llvm::ConstantAggregateZero::get(VTy); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 2739 | } else { |
| 2740 | // Right-shifting a signed value by its size is equivalent |
| 2741 | // to a shift of size-1. |
| 2742 | --ShiftAmt; |
| 2743 | Shift = ConstantInt::get(VTy->getElementType(), ShiftAmt); |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | Shift = EmitNeonShiftVector(Shift, Ty, false); |
| 2748 | if (usgn) |
| 2749 | return Builder.CreateLShr(Vec, Shift, name); |
| 2750 | else |
| 2751 | return Builder.CreateAShr(Vec, Shift, name); |
| 2752 | } |
| 2753 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2754 | enum { |
| 2755 | AddRetType = (1 << 0), |
| 2756 | Add1ArgType = (1 << 1), |
| 2757 | Add2ArgTypes = (1 << 2), |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2758 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2759 | VectorizeRetType = (1 << 3), |
| 2760 | VectorizeArgTypes = (1 << 4), |
| 2761 | |
| 2762 | InventFloatType = (1 << 5), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2763 | UnsignedAlts = (1 << 6), |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2764 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2765 | Use64BitVectors = (1 << 7), |
| 2766 | Use128BitVectors = (1 << 8), |
| 2767 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 2768 | Vectorize1ArgType = Add1ArgType | VectorizeArgTypes, |
| 2769 | VectorRet = AddRetType | VectorizeRetType, |
| 2770 | VectorRetGetArgs01 = |
| 2771 | AddRetType | Add2ArgTypes | VectorizeRetType | VectorizeArgTypes, |
| 2772 | FpCmpzModifiers = |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 2773 | AddRetType | VectorizeRetType | Add1ArgType | InventFloatType |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2774 | }; |
| 2775 | |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 2776 | namespace { |
| 2777 | struct NeonIntrinsicInfo { |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2778 | const char *NameHint; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2779 | unsigned BuiltinID; |
| 2780 | unsigned LLVMIntrinsic; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2781 | unsigned AltLLVMIntrinsic; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2782 | unsigned TypeModifier; |
| 2783 | |
| 2784 | bool operator<(unsigned RHSBuiltinID) const { |
| 2785 | return BuiltinID < RHSBuiltinID; |
| 2786 | } |
Eric Christopher | ed60b43 | 2015-11-11 02:04:08 +0000 | [diff] [blame] | 2787 | bool operator<(const NeonIntrinsicInfo &TE) const { |
| 2788 | return BuiltinID < TE.BuiltinID; |
| 2789 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2790 | }; |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 2791 | } // end anonymous namespace |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2792 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2793 | #define NEONMAP0(NameBase) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2794 | { #NameBase, NEON::BI__builtin_neon_ ## NameBase, 0, 0, 0 } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2795 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2796 | #define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2797 | { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \ |
| 2798 | Intrinsic::LLVMIntrinsic, 0, TypeModifier } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 2799 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2800 | #define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2801 | { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \ |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2802 | Intrinsic::LLVMIntrinsic, Intrinsic::AltLLVMIntrinsic, \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 2803 | TypeModifier } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2804 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 2805 | static const NeonIntrinsicInfo ARMSIMDIntrinsicMap [] = { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2806 | NEONMAP2(vabd_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 2807 | NEONMAP2(vabdq_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 2808 | NEONMAP1(vabs_v, arm_neon_vabs, 0), |
| 2809 | NEONMAP1(vabsq_v, arm_neon_vabs, 0), |
| 2810 | NEONMAP0(vaddhn_v), |
| 2811 | NEONMAP1(vaesdq_v, arm_neon_aesd, 0), |
| 2812 | NEONMAP1(vaeseq_v, arm_neon_aese, 0), |
| 2813 | NEONMAP1(vaesimcq_v, arm_neon_aesimc, 0), |
| 2814 | NEONMAP1(vaesmcq_v, arm_neon_aesmc, 0), |
| 2815 | NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType), |
| 2816 | NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType), |
| 2817 | NEONMAP1(vcage_v, arm_neon_vacge, 0), |
| 2818 | NEONMAP1(vcageq_v, arm_neon_vacge, 0), |
| 2819 | NEONMAP1(vcagt_v, arm_neon_vacgt, 0), |
| 2820 | NEONMAP1(vcagtq_v, arm_neon_vacgt, 0), |
| 2821 | NEONMAP1(vcale_v, arm_neon_vacge, 0), |
| 2822 | NEONMAP1(vcaleq_v, arm_neon_vacge, 0), |
| 2823 | NEONMAP1(vcalt_v, arm_neon_vacgt, 0), |
| 2824 | NEONMAP1(vcaltq_v, arm_neon_vacgt, 0), |
| 2825 | NEONMAP1(vcls_v, arm_neon_vcls, Add1ArgType), |
| 2826 | NEONMAP1(vclsq_v, arm_neon_vcls, Add1ArgType), |
| 2827 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 2828 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 2829 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 2830 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Ahmed Bougacha | cd5b8a0 | 2015-08-21 23:34:20 +0000 | [diff] [blame] | 2831 | NEONMAP1(vcvt_f16_f32, arm_neon_vcvtfp2hf, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2832 | NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0), |
| 2833 | NEONMAP0(vcvt_f32_v), |
| 2834 | NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
| 2835 | NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 2836 | NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
| 2837 | NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 2838 | NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
| 2839 | NEONMAP0(vcvt_s32_v), |
| 2840 | NEONMAP0(vcvt_s64_v), |
| 2841 | NEONMAP0(vcvt_u32_v), |
| 2842 | NEONMAP0(vcvt_u64_v), |
| 2843 | NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0), |
| 2844 | NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0), |
| 2845 | NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0), |
| 2846 | NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0), |
| 2847 | NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0), |
| 2848 | NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0), |
| 2849 | NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0), |
| 2850 | NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0), |
| 2851 | NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0), |
| 2852 | NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0), |
| 2853 | NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0), |
| 2854 | NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0), |
| 2855 | NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0), |
| 2856 | NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0), |
| 2857 | NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0), |
| 2858 | NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0), |
| 2859 | NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0), |
| 2860 | NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0), |
| 2861 | NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0), |
| 2862 | NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0), |
| 2863 | NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0), |
| 2864 | NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0), |
| 2865 | NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0), |
| 2866 | NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0), |
| 2867 | NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0), |
| 2868 | NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0), |
| 2869 | NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0), |
| 2870 | NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0), |
| 2871 | NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0), |
| 2872 | NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0), |
| 2873 | NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0), |
| 2874 | NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0), |
| 2875 | NEONMAP0(vcvtq_f32_v), |
| 2876 | NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
| 2877 | NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 2878 | NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
| 2879 | NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 2880 | NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
| 2881 | NEONMAP0(vcvtq_s32_v), |
| 2882 | NEONMAP0(vcvtq_s64_v), |
| 2883 | NEONMAP0(vcvtq_u32_v), |
| 2884 | NEONMAP0(vcvtq_u64_v), |
| 2885 | NEONMAP0(vext_v), |
| 2886 | NEONMAP0(vextq_v), |
| 2887 | NEONMAP0(vfma_v), |
| 2888 | NEONMAP0(vfmaq_v), |
| 2889 | NEONMAP2(vhadd_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 2890 | NEONMAP2(vhaddq_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 2891 | NEONMAP2(vhsub_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 2892 | NEONMAP2(vhsubq_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 2893 | NEONMAP0(vld1_dup_v), |
| 2894 | NEONMAP1(vld1_v, arm_neon_vld1, 0), |
| 2895 | NEONMAP0(vld1q_dup_v), |
| 2896 | NEONMAP1(vld1q_v, arm_neon_vld1, 0), |
| 2897 | NEONMAP1(vld2_lane_v, arm_neon_vld2lane, 0), |
| 2898 | NEONMAP1(vld2_v, arm_neon_vld2, 0), |
| 2899 | NEONMAP1(vld2q_lane_v, arm_neon_vld2lane, 0), |
| 2900 | NEONMAP1(vld2q_v, arm_neon_vld2, 0), |
| 2901 | NEONMAP1(vld3_lane_v, arm_neon_vld3lane, 0), |
| 2902 | NEONMAP1(vld3_v, arm_neon_vld3, 0), |
| 2903 | NEONMAP1(vld3q_lane_v, arm_neon_vld3lane, 0), |
| 2904 | NEONMAP1(vld3q_v, arm_neon_vld3, 0), |
| 2905 | NEONMAP1(vld4_lane_v, arm_neon_vld4lane, 0), |
| 2906 | NEONMAP1(vld4_v, arm_neon_vld4, 0), |
| 2907 | NEONMAP1(vld4q_lane_v, arm_neon_vld4lane, 0), |
| 2908 | NEONMAP1(vld4q_v, arm_neon_vld4, 0), |
| 2909 | NEONMAP2(vmax_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2910 | NEONMAP1(vmaxnm_v, arm_neon_vmaxnm, Add1ArgType), |
| 2911 | NEONMAP1(vmaxnmq_v, arm_neon_vmaxnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2912 | NEONMAP2(vmaxq_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
| 2913 | NEONMAP2(vmin_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2914 | NEONMAP1(vminnm_v, arm_neon_vminnm, Add1ArgType), |
| 2915 | NEONMAP1(vminnmq_v, arm_neon_vminnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2916 | NEONMAP2(vminq_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
| 2917 | NEONMAP0(vmovl_v), |
| 2918 | NEONMAP0(vmovn_v), |
| 2919 | NEONMAP1(vmul_v, arm_neon_vmulp, Add1ArgType), |
| 2920 | NEONMAP0(vmull_v), |
| 2921 | NEONMAP1(vmulq_v, arm_neon_vmulp, Add1ArgType), |
| 2922 | NEONMAP2(vpadal_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 2923 | NEONMAP2(vpadalq_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 2924 | NEONMAP1(vpadd_v, arm_neon_vpadd, Add1ArgType), |
| 2925 | NEONMAP2(vpaddl_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 2926 | NEONMAP2(vpaddlq_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 2927 | NEONMAP1(vpaddq_v, arm_neon_vpadd, Add1ArgType), |
| 2928 | NEONMAP2(vpmax_v, arm_neon_vpmaxu, arm_neon_vpmaxs, Add1ArgType | UnsignedAlts), |
| 2929 | NEONMAP2(vpmin_v, arm_neon_vpminu, arm_neon_vpmins, Add1ArgType | UnsignedAlts), |
| 2930 | NEONMAP1(vqabs_v, arm_neon_vqabs, Add1ArgType), |
| 2931 | NEONMAP1(vqabsq_v, arm_neon_vqabs, Add1ArgType), |
| 2932 | NEONMAP2(vqadd_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 2933 | NEONMAP2(vqaddq_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 2934 | NEONMAP2(vqdmlal_v, arm_neon_vqdmull, arm_neon_vqadds, 0), |
| 2935 | NEONMAP2(vqdmlsl_v, arm_neon_vqdmull, arm_neon_vqsubs, 0), |
| 2936 | NEONMAP1(vqdmulh_v, arm_neon_vqdmulh, Add1ArgType), |
| 2937 | NEONMAP1(vqdmulhq_v, arm_neon_vqdmulh, Add1ArgType), |
| 2938 | NEONMAP1(vqdmull_v, arm_neon_vqdmull, Add1ArgType), |
| 2939 | NEONMAP2(vqmovn_v, arm_neon_vqmovnu, arm_neon_vqmovns, Add1ArgType | UnsignedAlts), |
| 2940 | NEONMAP1(vqmovun_v, arm_neon_vqmovnsu, Add1ArgType), |
| 2941 | NEONMAP1(vqneg_v, arm_neon_vqneg, Add1ArgType), |
| 2942 | NEONMAP1(vqnegq_v, arm_neon_vqneg, Add1ArgType), |
| 2943 | NEONMAP1(vqrdmulh_v, arm_neon_vqrdmulh, Add1ArgType), |
| 2944 | NEONMAP1(vqrdmulhq_v, arm_neon_vqrdmulh, Add1ArgType), |
| 2945 | NEONMAP2(vqrshl_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 2946 | NEONMAP2(vqrshlq_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 2947 | NEONMAP2(vqshl_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 2948 | NEONMAP2(vqshl_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
| 2949 | NEONMAP2(vqshlq_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 2950 | NEONMAP2(vqshlq_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2951 | NEONMAP1(vqshlu_n_v, arm_neon_vqshiftsu, 0), |
| 2952 | NEONMAP1(vqshluq_n_v, arm_neon_vqshiftsu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2953 | NEONMAP2(vqsub_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 2954 | NEONMAP2(vqsubq_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 2955 | NEONMAP1(vraddhn_v, arm_neon_vraddhn, Add1ArgType), |
| 2956 | NEONMAP2(vrecpe_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 2957 | NEONMAP2(vrecpeq_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 2958 | NEONMAP1(vrecps_v, arm_neon_vrecps, Add1ArgType), |
| 2959 | NEONMAP1(vrecpsq_v, arm_neon_vrecps, Add1ArgType), |
| 2960 | NEONMAP2(vrhadd_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
| 2961 | NEONMAP2(vrhaddq_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 2962 | NEONMAP1(vrnd_v, arm_neon_vrintz, Add1ArgType), |
| 2963 | NEONMAP1(vrnda_v, arm_neon_vrinta, Add1ArgType), |
| 2964 | NEONMAP1(vrndaq_v, arm_neon_vrinta, Add1ArgType), |
| 2965 | NEONMAP1(vrndm_v, arm_neon_vrintm, Add1ArgType), |
| 2966 | NEONMAP1(vrndmq_v, arm_neon_vrintm, Add1ArgType), |
| 2967 | NEONMAP1(vrndn_v, arm_neon_vrintn, Add1ArgType), |
| 2968 | NEONMAP1(vrndnq_v, arm_neon_vrintn, Add1ArgType), |
| 2969 | NEONMAP1(vrndp_v, arm_neon_vrintp, Add1ArgType), |
| 2970 | NEONMAP1(vrndpq_v, arm_neon_vrintp, Add1ArgType), |
| 2971 | NEONMAP1(vrndq_v, arm_neon_vrintz, Add1ArgType), |
| 2972 | NEONMAP1(vrndx_v, arm_neon_vrintx, Add1ArgType), |
| 2973 | NEONMAP1(vrndxq_v, arm_neon_vrintx, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2974 | NEONMAP2(vrshl_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
| 2975 | NEONMAP2(vrshlq_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 2976 | NEONMAP2(vrshr_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
| 2977 | NEONMAP2(vrshrq_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2978 | NEONMAP2(vrsqrte_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 2979 | NEONMAP2(vrsqrteq_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 2980 | NEONMAP1(vrsqrts_v, arm_neon_vrsqrts, Add1ArgType), |
| 2981 | NEONMAP1(vrsqrtsq_v, arm_neon_vrsqrts, Add1ArgType), |
| 2982 | NEONMAP1(vrsubhn_v, arm_neon_vrsubhn, Add1ArgType), |
| 2983 | NEONMAP1(vsha1su0q_v, arm_neon_sha1su0, 0), |
| 2984 | NEONMAP1(vsha1su1q_v, arm_neon_sha1su1, 0), |
| 2985 | NEONMAP1(vsha256h2q_v, arm_neon_sha256h2, 0), |
| 2986 | NEONMAP1(vsha256hq_v, arm_neon_sha256h, 0), |
| 2987 | NEONMAP1(vsha256su0q_v, arm_neon_sha256su0, 0), |
| 2988 | NEONMAP1(vsha256su1q_v, arm_neon_sha256su1, 0), |
| 2989 | NEONMAP0(vshl_n_v), |
| 2990 | NEONMAP2(vshl_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 2991 | NEONMAP0(vshll_n_v), |
| 2992 | NEONMAP0(vshlq_n_v), |
| 2993 | NEONMAP2(vshlq_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 2994 | NEONMAP0(vshr_n_v), |
| 2995 | NEONMAP0(vshrn_n_v), |
| 2996 | NEONMAP0(vshrq_n_v), |
| 2997 | NEONMAP1(vst1_v, arm_neon_vst1, 0), |
| 2998 | NEONMAP1(vst1q_v, arm_neon_vst1, 0), |
| 2999 | NEONMAP1(vst2_lane_v, arm_neon_vst2lane, 0), |
| 3000 | NEONMAP1(vst2_v, arm_neon_vst2, 0), |
| 3001 | NEONMAP1(vst2q_lane_v, arm_neon_vst2lane, 0), |
| 3002 | NEONMAP1(vst2q_v, arm_neon_vst2, 0), |
| 3003 | NEONMAP1(vst3_lane_v, arm_neon_vst3lane, 0), |
| 3004 | NEONMAP1(vst3_v, arm_neon_vst3, 0), |
| 3005 | NEONMAP1(vst3q_lane_v, arm_neon_vst3lane, 0), |
| 3006 | NEONMAP1(vst3q_v, arm_neon_vst3, 0), |
| 3007 | NEONMAP1(vst4_lane_v, arm_neon_vst4lane, 0), |
| 3008 | NEONMAP1(vst4_v, arm_neon_vst4, 0), |
| 3009 | NEONMAP1(vst4q_lane_v, arm_neon_vst4lane, 0), |
| 3010 | NEONMAP1(vst4q_v, arm_neon_vst4, 0), |
| 3011 | NEONMAP0(vsubhn_v), |
| 3012 | NEONMAP0(vtrn_v), |
| 3013 | NEONMAP0(vtrnq_v), |
| 3014 | NEONMAP0(vtst_v), |
| 3015 | NEONMAP0(vtstq_v), |
| 3016 | NEONMAP0(vuzp_v), |
| 3017 | NEONMAP0(vuzpq_v), |
| 3018 | NEONMAP0(vzip_v), |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 3019 | NEONMAP0(vzipq_v) |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3020 | }; |
| 3021 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 3022 | static const NeonIntrinsicInfo AArch64SIMDIntrinsicMap[] = { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3023 | NEONMAP1(vabs_v, aarch64_neon_abs, 0), |
| 3024 | NEONMAP1(vabsq_v, aarch64_neon_abs, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3025 | NEONMAP0(vaddhn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3026 | NEONMAP1(vaesdq_v, aarch64_crypto_aesd, 0), |
| 3027 | NEONMAP1(vaeseq_v, aarch64_crypto_aese, 0), |
| 3028 | NEONMAP1(vaesimcq_v, aarch64_crypto_aesimc, 0), |
| 3029 | NEONMAP1(vaesmcq_v, aarch64_crypto_aesmc, 0), |
| 3030 | NEONMAP1(vcage_v, aarch64_neon_facge, 0), |
| 3031 | NEONMAP1(vcageq_v, aarch64_neon_facge, 0), |
| 3032 | NEONMAP1(vcagt_v, aarch64_neon_facgt, 0), |
| 3033 | NEONMAP1(vcagtq_v, aarch64_neon_facgt, 0), |
| 3034 | NEONMAP1(vcale_v, aarch64_neon_facge, 0), |
| 3035 | NEONMAP1(vcaleq_v, aarch64_neon_facge, 0), |
| 3036 | NEONMAP1(vcalt_v, aarch64_neon_facgt, 0), |
| 3037 | NEONMAP1(vcaltq_v, aarch64_neon_facgt, 0), |
| 3038 | NEONMAP1(vcls_v, aarch64_neon_cls, Add1ArgType), |
| 3039 | NEONMAP1(vclsq_v, aarch64_neon_cls, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3040 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 3041 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 3042 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 3043 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Ahmed Bougacha | cd5b8a0 | 2015-08-21 23:34:20 +0000 | [diff] [blame] | 3044 | NEONMAP1(vcvt_f16_f32, aarch64_neon_vcvtfp2hf, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3045 | NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3046 | NEONMAP0(vcvt_f32_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3047 | NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 3048 | NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 3049 | NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 3050 | NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
| 3051 | NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 3052 | NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3053 | NEONMAP0(vcvtq_f32_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3054 | NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 3055 | NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 3056 | NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 3057 | NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
| 3058 | NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 3059 | NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
| 3060 | NEONMAP1(vcvtx_f32_v, aarch64_neon_fcvtxn, AddRetType | Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3061 | NEONMAP0(vext_v), |
| 3062 | NEONMAP0(vextq_v), |
| 3063 | NEONMAP0(vfma_v), |
| 3064 | NEONMAP0(vfmaq_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3065 | NEONMAP2(vhadd_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 3066 | NEONMAP2(vhaddq_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 3067 | NEONMAP2(vhsub_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
| 3068 | NEONMAP2(vhsubq_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3069 | NEONMAP0(vmovl_v), |
| 3070 | NEONMAP0(vmovn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3071 | NEONMAP1(vmul_v, aarch64_neon_pmul, Add1ArgType), |
| 3072 | NEONMAP1(vmulq_v, aarch64_neon_pmul, Add1ArgType), |
| 3073 | NEONMAP1(vpadd_v, aarch64_neon_addp, Add1ArgType), |
| 3074 | NEONMAP2(vpaddl_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 3075 | NEONMAP2(vpaddlq_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 3076 | NEONMAP1(vpaddq_v, aarch64_neon_addp, Add1ArgType), |
| 3077 | NEONMAP1(vqabs_v, aarch64_neon_sqabs, Add1ArgType), |
| 3078 | NEONMAP1(vqabsq_v, aarch64_neon_sqabs, Add1ArgType), |
| 3079 | NEONMAP2(vqadd_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 3080 | NEONMAP2(vqaddq_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 3081 | NEONMAP2(vqdmlal_v, aarch64_neon_sqdmull, aarch64_neon_sqadd, 0), |
| 3082 | NEONMAP2(vqdmlsl_v, aarch64_neon_sqdmull, aarch64_neon_sqsub, 0), |
| 3083 | NEONMAP1(vqdmulh_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 3084 | NEONMAP1(vqdmulhq_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 3085 | NEONMAP1(vqdmull_v, aarch64_neon_sqdmull, Add1ArgType), |
| 3086 | NEONMAP2(vqmovn_v, aarch64_neon_uqxtn, aarch64_neon_sqxtn, Add1ArgType | UnsignedAlts), |
| 3087 | NEONMAP1(vqmovun_v, aarch64_neon_sqxtun, Add1ArgType), |
| 3088 | NEONMAP1(vqneg_v, aarch64_neon_sqneg, Add1ArgType), |
| 3089 | NEONMAP1(vqnegq_v, aarch64_neon_sqneg, Add1ArgType), |
| 3090 | NEONMAP1(vqrdmulh_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 3091 | NEONMAP1(vqrdmulhq_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 3092 | NEONMAP2(vqrshl_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 3093 | NEONMAP2(vqrshlq_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 3094 | NEONMAP2(vqshl_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl, UnsignedAlts), |
| 3095 | NEONMAP2(vqshl_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
| 3096 | NEONMAP2(vqshlq_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl,UnsignedAlts), |
| 3097 | NEONMAP2(vqshlq_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3098 | NEONMAP1(vqshlu_n_v, aarch64_neon_sqshlu, 0), |
| 3099 | NEONMAP1(vqshluq_n_v, aarch64_neon_sqshlu, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3100 | NEONMAP2(vqsub_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 3101 | NEONMAP2(vqsubq_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 3102 | NEONMAP1(vraddhn_v, aarch64_neon_raddhn, Add1ArgType), |
| 3103 | NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 3104 | NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 3105 | NEONMAP1(vrecps_v, aarch64_neon_frecps, Add1ArgType), |
| 3106 | NEONMAP1(vrecpsq_v, aarch64_neon_frecps, Add1ArgType), |
| 3107 | NEONMAP2(vrhadd_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 3108 | NEONMAP2(vrhaddq_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 3109 | NEONMAP2(vrshl_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
| 3110 | NEONMAP2(vrshlq_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3111 | NEONMAP2(vrshr_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
| 3112 | NEONMAP2(vrshrq_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3113 | NEONMAP2(vrsqrte_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 3114 | NEONMAP2(vrsqrteq_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 3115 | NEONMAP1(vrsqrts_v, aarch64_neon_frsqrts, Add1ArgType), |
| 3116 | NEONMAP1(vrsqrtsq_v, aarch64_neon_frsqrts, Add1ArgType), |
| 3117 | NEONMAP1(vrsubhn_v, aarch64_neon_rsubhn, Add1ArgType), |
| 3118 | NEONMAP1(vsha1su0q_v, aarch64_crypto_sha1su0, 0), |
| 3119 | NEONMAP1(vsha1su1q_v, aarch64_crypto_sha1su1, 0), |
| 3120 | NEONMAP1(vsha256h2q_v, aarch64_crypto_sha256h2, 0), |
| 3121 | NEONMAP1(vsha256hq_v, aarch64_crypto_sha256h, 0), |
| 3122 | NEONMAP1(vsha256su0q_v, aarch64_crypto_sha256su0, 0), |
| 3123 | NEONMAP1(vsha256su1q_v, aarch64_crypto_sha256su1, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3124 | NEONMAP0(vshl_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3125 | NEONMAP2(vshl_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3126 | NEONMAP0(vshll_n_v), |
| 3127 | NEONMAP0(vshlq_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3128 | NEONMAP2(vshlq_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3129 | NEONMAP0(vshr_n_v), |
| 3130 | NEONMAP0(vshrn_n_v), |
| 3131 | NEONMAP0(vshrq_n_v), |
| 3132 | NEONMAP0(vsubhn_v), |
| 3133 | NEONMAP0(vtst_v), |
| 3134 | NEONMAP0(vtstq_v), |
| 3135 | }; |
| 3136 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 3137 | static const NeonIntrinsicInfo AArch64SISDIntrinsicMap[] = { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3138 | NEONMAP1(vabdd_f64, aarch64_sisd_fabd, Add1ArgType), |
| 3139 | NEONMAP1(vabds_f32, aarch64_sisd_fabd, Add1ArgType), |
| 3140 | NEONMAP1(vabsd_s64, aarch64_neon_abs, Add1ArgType), |
| 3141 | NEONMAP1(vaddlv_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 3142 | NEONMAP1(vaddlv_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 3143 | NEONMAP1(vaddlvq_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 3144 | NEONMAP1(vaddlvq_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 3145 | NEONMAP1(vaddv_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 3146 | NEONMAP1(vaddv_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 3147 | NEONMAP1(vaddv_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3148 | NEONMAP1(vaddvq_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 3149 | NEONMAP1(vaddvq_f64, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 3150 | NEONMAP1(vaddvq_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 3151 | NEONMAP1(vaddvq_s64, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 3152 | NEONMAP1(vaddvq_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3153 | NEONMAP1(vaddvq_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3154 | NEONMAP1(vcaged_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3155 | NEONMAP1(vcages_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3156 | NEONMAP1(vcagtd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3157 | NEONMAP1(vcagts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3158 | NEONMAP1(vcaled_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3159 | NEONMAP1(vcales_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3160 | NEONMAP1(vcaltd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3161 | NEONMAP1(vcalts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3162 | NEONMAP1(vcvtad_s64_f64, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 3163 | NEONMAP1(vcvtad_u64_f64, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 3164 | NEONMAP1(vcvtas_s32_f32, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 3165 | NEONMAP1(vcvtas_u32_f32, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 3166 | NEONMAP1(vcvtd_n_f64_s64, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 3167 | NEONMAP1(vcvtd_n_f64_u64, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 3168 | NEONMAP1(vcvtd_n_s64_f64, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 3169 | NEONMAP1(vcvtd_n_u64_f64, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 3170 | NEONMAP1(vcvtmd_s64_f64, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 3171 | NEONMAP1(vcvtmd_u64_f64, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 3172 | NEONMAP1(vcvtms_s32_f32, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 3173 | NEONMAP1(vcvtms_u32_f32, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 3174 | NEONMAP1(vcvtnd_s64_f64, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 3175 | NEONMAP1(vcvtnd_u64_f64, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 3176 | NEONMAP1(vcvtns_s32_f32, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 3177 | NEONMAP1(vcvtns_u32_f32, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 3178 | NEONMAP1(vcvtpd_s64_f64, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 3179 | NEONMAP1(vcvtpd_u64_f64, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 3180 | NEONMAP1(vcvtps_s32_f32, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 3181 | NEONMAP1(vcvtps_u32_f32, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 3182 | NEONMAP1(vcvts_n_f32_s32, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 3183 | NEONMAP1(vcvts_n_f32_u32, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 3184 | NEONMAP1(vcvts_n_s32_f32, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 3185 | NEONMAP1(vcvts_n_u32_f32, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 3186 | NEONMAP1(vcvtxd_f32_f64, aarch64_sisd_fcvtxn, 0), |
| 3187 | NEONMAP1(vmaxnmv_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3188 | NEONMAP1(vmaxnmvq_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3189 | NEONMAP1(vmaxnmvq_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3190 | NEONMAP1(vmaxv_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3191 | NEONMAP1(vmaxv_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 3192 | NEONMAP1(vmaxv_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 3193 | NEONMAP1(vmaxvq_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3194 | NEONMAP1(vmaxvq_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3195 | NEONMAP1(vmaxvq_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 3196 | NEONMAP1(vmaxvq_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 3197 | NEONMAP1(vminnmv_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3198 | NEONMAP1(vminnmvq_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3199 | NEONMAP1(vminnmvq_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3200 | NEONMAP1(vminv_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3201 | NEONMAP1(vminv_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 3202 | NEONMAP1(vminv_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 3203 | NEONMAP1(vminvq_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3204 | NEONMAP1(vminvq_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3205 | NEONMAP1(vminvq_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 3206 | NEONMAP1(vminvq_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 3207 | NEONMAP1(vmull_p64, aarch64_neon_pmull64, 0), |
| 3208 | NEONMAP1(vmulxd_f64, aarch64_neon_fmulx, Add1ArgType), |
| 3209 | NEONMAP1(vmulxs_f32, aarch64_neon_fmulx, Add1ArgType), |
| 3210 | NEONMAP1(vpaddd_s64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3211 | NEONMAP1(vpaddd_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3212 | NEONMAP1(vpmaxnmqd_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3213 | NEONMAP1(vpmaxnms_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3214 | NEONMAP1(vpmaxqd_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3215 | NEONMAP1(vpmaxs_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3216 | NEONMAP1(vpminnmqd_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3217 | NEONMAP1(vpminnms_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3218 | NEONMAP1(vpminqd_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3219 | NEONMAP1(vpmins_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3220 | NEONMAP1(vqabsb_s8, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 3221 | NEONMAP1(vqabsd_s64, aarch64_neon_sqabs, Add1ArgType), |
| 3222 | NEONMAP1(vqabsh_s16, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 3223 | NEONMAP1(vqabss_s32, aarch64_neon_sqabs, Add1ArgType), |
| 3224 | NEONMAP1(vqaddb_s8, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 3225 | NEONMAP1(vqaddb_u8, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 3226 | NEONMAP1(vqaddd_s64, aarch64_neon_sqadd, Add1ArgType), |
| 3227 | NEONMAP1(vqaddd_u64, aarch64_neon_uqadd, Add1ArgType), |
| 3228 | NEONMAP1(vqaddh_s16, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 3229 | NEONMAP1(vqaddh_u16, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 3230 | NEONMAP1(vqadds_s32, aarch64_neon_sqadd, Add1ArgType), |
| 3231 | NEONMAP1(vqadds_u32, aarch64_neon_uqadd, Add1ArgType), |
| 3232 | NEONMAP1(vqdmulhh_s16, aarch64_neon_sqdmulh, Vectorize1ArgType | Use64BitVectors), |
| 3233 | NEONMAP1(vqdmulhs_s32, aarch64_neon_sqdmulh, Add1ArgType), |
| 3234 | NEONMAP1(vqdmullh_s16, aarch64_neon_sqdmull, VectorRet | Use128BitVectors), |
| 3235 | NEONMAP1(vqdmulls_s32, aarch64_neon_sqdmulls_scalar, 0), |
| 3236 | NEONMAP1(vqmovnd_s64, aarch64_neon_scalar_sqxtn, AddRetType | Add1ArgType), |
| 3237 | NEONMAP1(vqmovnd_u64, aarch64_neon_scalar_uqxtn, AddRetType | Add1ArgType), |
| 3238 | NEONMAP1(vqmovnh_s16, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 3239 | NEONMAP1(vqmovnh_u16, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 3240 | NEONMAP1(vqmovns_s32, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 3241 | NEONMAP1(vqmovns_u32, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 3242 | NEONMAP1(vqmovund_s64, aarch64_neon_scalar_sqxtun, AddRetType | Add1ArgType), |
| 3243 | NEONMAP1(vqmovunh_s16, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 3244 | NEONMAP1(vqmovuns_s32, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 3245 | NEONMAP1(vqnegb_s8, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 3246 | NEONMAP1(vqnegd_s64, aarch64_neon_sqneg, Add1ArgType), |
| 3247 | NEONMAP1(vqnegh_s16, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 3248 | NEONMAP1(vqnegs_s32, aarch64_neon_sqneg, Add1ArgType), |
| 3249 | NEONMAP1(vqrdmulhh_s16, aarch64_neon_sqrdmulh, Vectorize1ArgType | Use64BitVectors), |
| 3250 | NEONMAP1(vqrdmulhs_s32, aarch64_neon_sqrdmulh, Add1ArgType), |
| 3251 | NEONMAP1(vqrshlb_s8, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 3252 | NEONMAP1(vqrshlb_u8, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 3253 | NEONMAP1(vqrshld_s64, aarch64_neon_sqrshl, Add1ArgType), |
| 3254 | NEONMAP1(vqrshld_u64, aarch64_neon_uqrshl, Add1ArgType), |
| 3255 | NEONMAP1(vqrshlh_s16, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 3256 | NEONMAP1(vqrshlh_u16, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 3257 | NEONMAP1(vqrshls_s32, aarch64_neon_sqrshl, Add1ArgType), |
| 3258 | NEONMAP1(vqrshls_u32, aarch64_neon_uqrshl, Add1ArgType), |
| 3259 | NEONMAP1(vqrshrnd_n_s64, aarch64_neon_sqrshrn, AddRetType), |
| 3260 | NEONMAP1(vqrshrnd_n_u64, aarch64_neon_uqrshrn, AddRetType), |
| 3261 | NEONMAP1(vqrshrnh_n_s16, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 3262 | NEONMAP1(vqrshrnh_n_u16, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 3263 | NEONMAP1(vqrshrns_n_s32, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 3264 | NEONMAP1(vqrshrns_n_u32, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 3265 | NEONMAP1(vqrshrund_n_s64, aarch64_neon_sqrshrun, AddRetType), |
| 3266 | NEONMAP1(vqrshrunh_n_s16, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 3267 | NEONMAP1(vqrshruns_n_s32, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 3268 | NEONMAP1(vqshlb_n_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 3269 | NEONMAP1(vqshlb_n_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 3270 | NEONMAP1(vqshlb_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 3271 | NEONMAP1(vqshlb_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 3272 | NEONMAP1(vqshld_s64, aarch64_neon_sqshl, Add1ArgType), |
| 3273 | NEONMAP1(vqshld_u64, aarch64_neon_uqshl, Add1ArgType), |
| 3274 | NEONMAP1(vqshlh_n_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 3275 | NEONMAP1(vqshlh_n_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 3276 | NEONMAP1(vqshlh_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 3277 | NEONMAP1(vqshlh_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 3278 | NEONMAP1(vqshls_n_s32, aarch64_neon_sqshl, Add1ArgType), |
| 3279 | NEONMAP1(vqshls_n_u32, aarch64_neon_uqshl, Add1ArgType), |
| 3280 | NEONMAP1(vqshls_s32, aarch64_neon_sqshl, Add1ArgType), |
| 3281 | NEONMAP1(vqshls_u32, aarch64_neon_uqshl, Add1ArgType), |
| 3282 | NEONMAP1(vqshlub_n_s8, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 3283 | NEONMAP1(vqshluh_n_s16, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 3284 | NEONMAP1(vqshlus_n_s32, aarch64_neon_sqshlu, Add1ArgType), |
| 3285 | NEONMAP1(vqshrnd_n_s64, aarch64_neon_sqshrn, AddRetType), |
| 3286 | NEONMAP1(vqshrnd_n_u64, aarch64_neon_uqshrn, AddRetType), |
| 3287 | NEONMAP1(vqshrnh_n_s16, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 3288 | NEONMAP1(vqshrnh_n_u16, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 3289 | NEONMAP1(vqshrns_n_s32, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 3290 | NEONMAP1(vqshrns_n_u32, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 3291 | NEONMAP1(vqshrund_n_s64, aarch64_neon_sqshrun, AddRetType), |
| 3292 | NEONMAP1(vqshrunh_n_s16, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 3293 | NEONMAP1(vqshruns_n_s32, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 3294 | NEONMAP1(vqsubb_s8, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 3295 | NEONMAP1(vqsubb_u8, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 3296 | NEONMAP1(vqsubd_s64, aarch64_neon_sqsub, Add1ArgType), |
| 3297 | NEONMAP1(vqsubd_u64, aarch64_neon_uqsub, Add1ArgType), |
| 3298 | NEONMAP1(vqsubh_s16, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 3299 | NEONMAP1(vqsubh_u16, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 3300 | NEONMAP1(vqsubs_s32, aarch64_neon_sqsub, Add1ArgType), |
| 3301 | NEONMAP1(vqsubs_u32, aarch64_neon_uqsub, Add1ArgType), |
| 3302 | NEONMAP1(vrecped_f64, aarch64_neon_frecpe, Add1ArgType), |
| 3303 | NEONMAP1(vrecpes_f32, aarch64_neon_frecpe, Add1ArgType), |
| 3304 | NEONMAP1(vrecpxd_f64, aarch64_neon_frecpx, Add1ArgType), |
| 3305 | NEONMAP1(vrecpxs_f32, aarch64_neon_frecpx, Add1ArgType), |
| 3306 | NEONMAP1(vrshld_s64, aarch64_neon_srshl, Add1ArgType), |
| 3307 | NEONMAP1(vrshld_u64, aarch64_neon_urshl, Add1ArgType), |
| 3308 | NEONMAP1(vrsqrted_f64, aarch64_neon_frsqrte, Add1ArgType), |
| 3309 | NEONMAP1(vrsqrtes_f32, aarch64_neon_frsqrte, Add1ArgType), |
| 3310 | NEONMAP1(vrsqrtsd_f64, aarch64_neon_frsqrts, Add1ArgType), |
| 3311 | NEONMAP1(vrsqrtss_f32, aarch64_neon_frsqrts, Add1ArgType), |
| 3312 | NEONMAP1(vsha1cq_u32, aarch64_crypto_sha1c, 0), |
| 3313 | NEONMAP1(vsha1h_u32, aarch64_crypto_sha1h, 0), |
| 3314 | NEONMAP1(vsha1mq_u32, aarch64_crypto_sha1m, 0), |
| 3315 | NEONMAP1(vsha1pq_u32, aarch64_crypto_sha1p, 0), |
| 3316 | NEONMAP1(vshld_s64, aarch64_neon_sshl, Add1ArgType), |
| 3317 | NEONMAP1(vshld_u64, aarch64_neon_ushl, Add1ArgType), |
| 3318 | NEONMAP1(vslid_n_s64, aarch64_neon_vsli, Vectorize1ArgType), |
| 3319 | NEONMAP1(vslid_n_u64, aarch64_neon_vsli, Vectorize1ArgType), |
| 3320 | NEONMAP1(vsqaddb_u8, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 3321 | NEONMAP1(vsqaddd_u64, aarch64_neon_usqadd, Add1ArgType), |
| 3322 | NEONMAP1(vsqaddh_u16, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 3323 | NEONMAP1(vsqadds_u32, aarch64_neon_usqadd, Add1ArgType), |
| 3324 | NEONMAP1(vsrid_n_s64, aarch64_neon_vsri, Vectorize1ArgType), |
| 3325 | NEONMAP1(vsrid_n_u64, aarch64_neon_vsri, Vectorize1ArgType), |
| 3326 | NEONMAP1(vuqaddb_s8, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 3327 | NEONMAP1(vuqaddd_s64, aarch64_neon_suqadd, Add1ArgType), |
| 3328 | NEONMAP1(vuqaddh_s16, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 3329 | NEONMAP1(vuqadds_s32, aarch64_neon_suqadd, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3330 | }; |
| 3331 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3332 | #undef NEONMAP0 |
| 3333 | #undef NEONMAP1 |
| 3334 | #undef NEONMAP2 |
| 3335 | |
| 3336 | static bool NEONSIMDIntrinsicsProvenSorted = false; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3337 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3338 | static bool AArch64SIMDIntrinsicsProvenSorted = false; |
| 3339 | static bool AArch64SISDIntrinsicsProvenSorted = false; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3340 | |
| 3341 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3342 | static const NeonIntrinsicInfo * |
Craig Topper | 00bbdcf | 2014-06-28 23:22:23 +0000 | [diff] [blame] | 3343 | findNeonIntrinsicInMap(ArrayRef<NeonIntrinsicInfo> IntrinsicMap, |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3344 | unsigned BuiltinID, bool &MapProvenSorted) { |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3345 | |
| 3346 | #ifndef NDEBUG |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3347 | if (!MapProvenSorted) { |
Eric Christopher | ed60b43 | 2015-11-11 02:04:08 +0000 | [diff] [blame] | 3348 | assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap))); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3349 | MapProvenSorted = true; |
| 3350 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3351 | #endif |
| 3352 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3353 | const NeonIntrinsicInfo *Builtin = |
| 3354 | std::lower_bound(IntrinsicMap.begin(), IntrinsicMap.end(), BuiltinID); |
| 3355 | |
| 3356 | if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID) |
| 3357 | return Builtin; |
| 3358 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3359 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | Function *CodeGenFunction::LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
| 3363 | unsigned Modifier, |
| 3364 | llvm::Type *ArgType, |
| 3365 | const CallExpr *E) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3366 | int VectorSize = 0; |
| 3367 | if (Modifier & Use64BitVectors) |
| 3368 | VectorSize = 64; |
| 3369 | else if (Modifier & Use128BitVectors) |
| 3370 | VectorSize = 128; |
| 3371 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3372 | // Return type. |
| 3373 | SmallVector<llvm::Type *, 3> Tys; |
| 3374 | if (Modifier & AddRetType) { |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 3375 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3376 | if (Modifier & VectorizeRetType) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3377 | Ty = llvm::VectorType::get( |
| 3378 | Ty, VectorSize ? VectorSize / Ty->getPrimitiveSizeInBits() : 1); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3379 | |
| 3380 | Tys.push_back(Ty); |
| 3381 | } |
| 3382 | |
| 3383 | // Arguments. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3384 | if (Modifier & VectorizeArgTypes) { |
| 3385 | int Elts = VectorSize ? VectorSize / ArgType->getPrimitiveSizeInBits() : 1; |
| 3386 | ArgType = llvm::VectorType::get(ArgType, Elts); |
| 3387 | } |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3388 | |
| 3389 | if (Modifier & (Add1ArgType | Add2ArgTypes)) |
| 3390 | Tys.push_back(ArgType); |
| 3391 | |
| 3392 | if (Modifier & Add2ArgTypes) |
| 3393 | Tys.push_back(ArgType); |
| 3394 | |
| 3395 | if (Modifier & InventFloatType) |
| 3396 | Tys.push_back(FloatTy); |
| 3397 | |
| 3398 | return CGM.getIntrinsic(IntrinsicID, Tys); |
| 3399 | } |
| 3400 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3401 | static Value *EmitCommonNeonSISDBuiltinExpr(CodeGenFunction &CGF, |
| 3402 | const NeonIntrinsicInfo &SISDInfo, |
| 3403 | SmallVectorImpl<Value *> &Ops, |
| 3404 | const CallExpr *E) { |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 3405 | unsigned BuiltinID = SISDInfo.BuiltinID; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3406 | unsigned int Int = SISDInfo.LLVMIntrinsic; |
| 3407 | unsigned Modifier = SISDInfo.TypeModifier; |
| 3408 | const char *s = SISDInfo.NameHint; |
| 3409 | |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 3410 | switch (BuiltinID) { |
| 3411 | case NEON::BI__builtin_neon_vcled_s64: |
| 3412 | case NEON::BI__builtin_neon_vcled_u64: |
| 3413 | case NEON::BI__builtin_neon_vcles_f32: |
| 3414 | case NEON::BI__builtin_neon_vcled_f64: |
| 3415 | case NEON::BI__builtin_neon_vcltd_s64: |
| 3416 | case NEON::BI__builtin_neon_vcltd_u64: |
| 3417 | case NEON::BI__builtin_neon_vclts_f32: |
| 3418 | case NEON::BI__builtin_neon_vcltd_f64: |
| 3419 | case NEON::BI__builtin_neon_vcales_f32: |
| 3420 | case NEON::BI__builtin_neon_vcaled_f64: |
| 3421 | case NEON::BI__builtin_neon_vcalts_f32: |
| 3422 | case NEON::BI__builtin_neon_vcaltd_f64: |
| 3423 | // Only one direction of comparisons actually exist, cmle is actually a cmge |
| 3424 | // with swapped operands. The table gives us the right intrinsic but we |
| 3425 | // still need to do the swap. |
| 3426 | std::swap(Ops[0], Ops[1]); |
| 3427 | break; |
| 3428 | } |
| 3429 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3430 | assert(Int && "Generic code assumes a valid intrinsic"); |
| 3431 | |
| 3432 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 3433 | const Expr *Arg = E->getArg(0); |
| 3434 | llvm::Type *ArgTy = CGF.ConvertType(Arg->getType()); |
| 3435 | Function *F = CGF.LookupNeonLLVMIntrinsic(Int, Modifier, ArgTy, E); |
| 3436 | |
| 3437 | int j = 0; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 3438 | ConstantInt *C0 = ConstantInt::get(CGF.SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3439 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 3440 | ai != ae; ++ai, ++j) { |
| 3441 | llvm::Type *ArgTy = ai->getType(); |
| 3442 | if (Ops[j]->getType()->getPrimitiveSizeInBits() == |
| 3443 | ArgTy->getPrimitiveSizeInBits()) |
| 3444 | continue; |
| 3445 | |
| 3446 | assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy()); |
| 3447 | // The constant argument to an _n_ intrinsic always has Int32Ty, so truncate |
| 3448 | // it before inserting. |
| 3449 | Ops[j] = |
| 3450 | CGF.Builder.CreateTruncOrBitCast(Ops[j], ArgTy->getVectorElementType()); |
| 3451 | Ops[j] = |
| 3452 | CGF.Builder.CreateInsertElement(UndefValue::get(ArgTy), Ops[j], C0); |
| 3453 | } |
| 3454 | |
| 3455 | Value *Result = CGF.EmitNeonCall(F, Ops, s); |
| 3456 | llvm::Type *ResultType = CGF.ConvertType(E->getType()); |
| 3457 | if (ResultType->getPrimitiveSizeInBits() < |
| 3458 | Result->getType()->getPrimitiveSizeInBits()) |
| 3459 | return CGF.Builder.CreateExtractElement(Result, C0); |
| 3460 | |
| 3461 | return CGF.Builder.CreateBitCast(Result, ResultType, s); |
| 3462 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3463 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3464 | Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( |
| 3465 | unsigned BuiltinID, unsigned LLVMIntrinsic, unsigned AltLLVMIntrinsic, |
| 3466 | const char *NameHint, unsigned Modifier, const CallExpr *E, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3467 | SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1) { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3468 | // Get the last argument, which specifies the vector type. |
| 3469 | llvm::APSInt NeonTypeConst; |
| 3470 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 3471 | if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3472 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3473 | |
| 3474 | // Determine the type of this overloaded NEON intrinsic. |
| 3475 | NeonTypeFlags Type(NeonTypeConst.getZExtValue()); |
| 3476 | bool Usgn = Type.isUnsigned(); |
| 3477 | bool Quad = Type.isQuad(); |
| 3478 | |
| 3479 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 3480 | llvm::Type *Ty = VTy; |
| 3481 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3482 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3483 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3484 | auto getAlignmentValue32 = [&](Address addr) -> Value* { |
| 3485 | return Builder.getInt32(addr.getAlignment().getQuantity()); |
| 3486 | }; |
| 3487 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3488 | unsigned Int = LLVMIntrinsic; |
| 3489 | if ((Modifier & UnsignedAlts) && !Usgn) |
| 3490 | Int = AltLLVMIntrinsic; |
| 3491 | |
| 3492 | switch (BuiltinID) { |
| 3493 | default: break; |
| 3494 | case NEON::BI__builtin_neon_vabs_v: |
| 3495 | case NEON::BI__builtin_neon_vabsq_v: |
| 3496 | if (VTy->getElementType()->isFloatingPointTy()) |
| 3497 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::fabs, Ty), Ops, "vabs"); |
| 3498 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), Ops, "vabs"); |
| 3499 | case NEON::BI__builtin_neon_vaddhn_v: { |
| 3500 | llvm::VectorType *SrcTy = |
| 3501 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3502 | |
| 3503 | // %sum = add <4 x i32> %lhs, %rhs |
| 3504 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3505 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 3506 | Ops[0] = Builder.CreateAdd(Ops[0], Ops[1], "vaddhn"); |
| 3507 | |
| 3508 | // %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] | 3509 | Constant *ShiftAmt = |
| 3510 | ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3511 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vaddhn"); |
| 3512 | |
| 3513 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 3514 | return Builder.CreateTrunc(Ops[0], VTy, "vaddhn"); |
| 3515 | } |
| 3516 | case NEON::BI__builtin_neon_vcale_v: |
| 3517 | case NEON::BI__builtin_neon_vcaleq_v: |
| 3518 | case NEON::BI__builtin_neon_vcalt_v: |
| 3519 | case NEON::BI__builtin_neon_vcaltq_v: |
| 3520 | std::swap(Ops[0], Ops[1]); |
| 3521 | case NEON::BI__builtin_neon_vcage_v: |
| 3522 | case NEON::BI__builtin_neon_vcageq_v: |
| 3523 | case NEON::BI__builtin_neon_vcagt_v: |
| 3524 | case NEON::BI__builtin_neon_vcagtq_v: { |
| 3525 | llvm::Type *VecFlt = llvm::VectorType::get( |
| 3526 | VTy->getScalarSizeInBits() == 32 ? FloatTy : DoubleTy, |
| 3527 | VTy->getNumElements()); |
| 3528 | llvm::Type *Tys[] = { VTy, VecFlt }; |
| 3529 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 3530 | return EmitNeonCall(F, Ops, NameHint); |
| 3531 | } |
| 3532 | case NEON::BI__builtin_neon_vclz_v: |
| 3533 | case NEON::BI__builtin_neon_vclzq_v: |
| 3534 | // We generate target-independent intrinsic, which needs a second argument |
| 3535 | // for whether or not clz of zero is undefined; on ARM it isn't. |
| 3536 | Ops.push_back(Builder.getInt1(getTarget().isCLZForZeroUndef())); |
| 3537 | break; |
| 3538 | case NEON::BI__builtin_neon_vcvt_f32_v: |
| 3539 | case NEON::BI__builtin_neon_vcvtq_f32_v: |
| 3540 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3541 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float32, false, Quad)); |
| 3542 | return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 3543 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 3544 | case NEON::BI__builtin_neon_vcvt_n_f32_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3545 | case NEON::BI__builtin_neon_vcvt_n_f64_v: |
| 3546 | case NEON::BI__builtin_neon_vcvtq_n_f32_v: |
| 3547 | case NEON::BI__builtin_neon_vcvtq_n_f64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3548 | llvm::Type *Tys[2] = { GetFloatNeonType(this, Type), Ty }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3549 | Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 3550 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 3551 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 3552 | } |
| 3553 | case NEON::BI__builtin_neon_vcvt_n_s32_v: |
| 3554 | case NEON::BI__builtin_neon_vcvt_n_u32_v: |
| 3555 | case NEON::BI__builtin_neon_vcvt_n_s64_v: |
| 3556 | case NEON::BI__builtin_neon_vcvt_n_u64_v: |
| 3557 | case NEON::BI__builtin_neon_vcvtq_n_s32_v: |
| 3558 | case NEON::BI__builtin_neon_vcvtq_n_u32_v: |
| 3559 | case NEON::BI__builtin_neon_vcvtq_n_s64_v: |
| 3560 | case NEON::BI__builtin_neon_vcvtq_n_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3561 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3562 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 3563 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 3564 | } |
| 3565 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 3566 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 3567 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 3568 | case NEON::BI__builtin_neon_vcvt_u64_v: |
| 3569 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 3570 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 3571 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
| 3572 | case NEON::BI__builtin_neon_vcvtq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3573 | Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3574 | return Usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt") |
| 3575 | : Builder.CreateFPToSI(Ops[0], Ty, "vcvt"); |
| 3576 | } |
| 3577 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 3578 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 3579 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 3580 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 3581 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 3582 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 3583 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 3584 | case NEON::BI__builtin_neon_vcvtaq_u64_v: |
| 3585 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 3586 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 3587 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 3588 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 3589 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 3590 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 3591 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 3592 | case NEON::BI__builtin_neon_vcvtnq_u64_v: |
| 3593 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 3594 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 3595 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 3596 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 3597 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 3598 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 3599 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 3600 | case NEON::BI__builtin_neon_vcvtpq_u64_v: |
| 3601 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 3602 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 3603 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 3604 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 3605 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 3606 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 3607 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 3608 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3609 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3610 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, NameHint); |
| 3611 | } |
| 3612 | case NEON::BI__builtin_neon_vext_v: |
| 3613 | case NEON::BI__builtin_neon_vextq_v: { |
| 3614 | int CV = cast<ConstantInt>(Ops[2])->getSExtValue(); |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 3615 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3616 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3617 | Indices.push_back(i+CV); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3618 | |
| 3619 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3620 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3621 | return Builder.CreateShuffleVector(Ops[0], Ops[1], Indices, "vext"); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3622 | } |
| 3623 | case NEON::BI__builtin_neon_vfma_v: |
| 3624 | case NEON::BI__builtin_neon_vfmaq_v: { |
| 3625 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 3626 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3627 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3628 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 3629 | |
| 3630 | // NEON intrinsic puts accumulator first, unlike the LLVM fma. |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3631 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3632 | } |
| 3633 | case NEON::BI__builtin_neon_vld1_v: |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3634 | case NEON::BI__builtin_neon_vld1q_v: { |
| 3635 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3636 | Ops.push_back(getAlignmentValue32(PtrOp0)); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3637 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, "vld1"); |
| 3638 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3639 | case NEON::BI__builtin_neon_vld2_v: |
| 3640 | case NEON::BI__builtin_neon_vld2q_v: |
| 3641 | case NEON::BI__builtin_neon_vld3_v: |
| 3642 | case NEON::BI__builtin_neon_vld3q_v: |
| 3643 | case NEON::BI__builtin_neon_vld4_v: |
| 3644 | case NEON::BI__builtin_neon_vld4q_v: { |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3645 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 3646 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3647 | Value *Align = getAlignmentValue32(PtrOp1); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 3648 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3649 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 3650 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3651 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3652 | } |
| 3653 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 3654 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 3655 | Value *V = UndefValue::get(Ty); |
| 3656 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3657 | PtrOp0 = Builder.CreateBitCast(PtrOp0, Ty); |
| 3658 | LoadInst *Ld = Builder.CreateLoad(PtrOp0); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 3659 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3660 | Ops[0] = Builder.CreateInsertElement(V, Ld, CI); |
| 3661 | return EmitNeonSplat(Ops[0], CI); |
| 3662 | } |
| 3663 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 3664 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 3665 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 3666 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 3667 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 3668 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3669 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 3670 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3671 | for (unsigned I = 2; I < Ops.size() - 1; ++I) |
| 3672 | Ops[I] = Builder.CreateBitCast(Ops[I], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3673 | Ops.push_back(getAlignmentValue32(PtrOp1)); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3674 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), NameHint); |
| 3675 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 3676 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3677 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3678 | } |
| 3679 | case NEON::BI__builtin_neon_vmovl_v: { |
| 3680 | llvm::Type *DTy =llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 3681 | Ops[0] = Builder.CreateBitCast(Ops[0], DTy); |
| 3682 | if (Usgn) |
| 3683 | return Builder.CreateZExt(Ops[0], Ty, "vmovl"); |
| 3684 | return Builder.CreateSExt(Ops[0], Ty, "vmovl"); |
| 3685 | } |
| 3686 | case NEON::BI__builtin_neon_vmovn_v: { |
| 3687 | llvm::Type *QTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3688 | Ops[0] = Builder.CreateBitCast(Ops[0], QTy); |
| 3689 | return Builder.CreateTrunc(Ops[0], Ty, "vmovn"); |
| 3690 | } |
| 3691 | case NEON::BI__builtin_neon_vmull_v: |
| 3692 | // FIXME: the integer vmull operations could be emitted in terms of pure |
| 3693 | // LLVM IR (2 exts followed by a mul). Unfortunately LLVM has a habit of |
| 3694 | // hoisting the exts outside loops. Until global ISel comes along that can |
| 3695 | // see through such movement this leads to bad CodeGen. So we need an |
| 3696 | // intrinsic for now. |
| 3697 | Int = Usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls; |
| 3698 | Int = Type.isPoly() ? (unsigned)Intrinsic::arm_neon_vmullp : Int; |
| 3699 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 3700 | case NEON::BI__builtin_neon_vpadal_v: |
| 3701 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 3702 | // The source operand type has twice as many elements of half the size. |
| 3703 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 3704 | llvm::Type *EltTy = |
| 3705 | llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 3706 | llvm::Type *NarrowTy = |
| 3707 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 3708 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 3709 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, NameHint); |
| 3710 | } |
| 3711 | case NEON::BI__builtin_neon_vpaddl_v: |
| 3712 | case NEON::BI__builtin_neon_vpaddlq_v: { |
| 3713 | // The source operand type has twice as many elements of half the size. |
| 3714 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 3715 | llvm::Type *EltTy = llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 3716 | llvm::Type *NarrowTy = |
| 3717 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 3718 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 3719 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vpaddl"); |
| 3720 | } |
| 3721 | case NEON::BI__builtin_neon_vqdmlal_v: |
| 3722 | case NEON::BI__builtin_neon_vqdmlsl_v: { |
| 3723 | SmallVector<Value *, 2> MulOps(Ops.begin() + 1, Ops.end()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3724 | Ops[1] = |
| 3725 | EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), MulOps, "vqdmlal"); |
| 3726 | Ops.resize(2); |
| 3727 | return EmitNeonCall(CGM.getIntrinsic(AltLLVMIntrinsic, Ty), Ops, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3728 | } |
| 3729 | case NEON::BI__builtin_neon_vqshl_n_v: |
| 3730 | case NEON::BI__builtin_neon_vqshlq_n_v: |
| 3731 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshl_n", |
| 3732 | 1, false); |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3733 | case NEON::BI__builtin_neon_vqshlu_n_v: |
| 3734 | case NEON::BI__builtin_neon_vqshluq_n_v: |
| 3735 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshlu_n", |
| 3736 | 1, false); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3737 | case NEON::BI__builtin_neon_vrecpe_v: |
| 3738 | case NEON::BI__builtin_neon_vrecpeq_v: |
| 3739 | case NEON::BI__builtin_neon_vrsqrte_v: |
| 3740 | case NEON::BI__builtin_neon_vrsqrteq_v: |
| 3741 | Int = Ty->isFPOrFPVectorTy() ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 3742 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, NameHint); |
| 3743 | |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3744 | case NEON::BI__builtin_neon_vrshr_n_v: |
| 3745 | case NEON::BI__builtin_neon_vrshrq_n_v: |
| 3746 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshr_n", |
| 3747 | 1, true); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3748 | case NEON::BI__builtin_neon_vshl_n_v: |
| 3749 | case NEON::BI__builtin_neon_vshlq_n_v: |
| 3750 | Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false); |
| 3751 | return Builder.CreateShl(Builder.CreateBitCast(Ops[0],Ty), Ops[1], |
| 3752 | "vshl_n"); |
| 3753 | case NEON::BI__builtin_neon_vshll_n_v: { |
| 3754 | llvm::Type *SrcTy = llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 3755 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3756 | if (Usgn) |
| 3757 | Ops[0] = Builder.CreateZExt(Ops[0], VTy); |
| 3758 | else |
| 3759 | Ops[0] = Builder.CreateSExt(Ops[0], VTy); |
| 3760 | Ops[1] = EmitNeonShiftVector(Ops[1], VTy, false); |
| 3761 | return Builder.CreateShl(Ops[0], Ops[1], "vshll_n"); |
| 3762 | } |
| 3763 | case NEON::BI__builtin_neon_vshrn_n_v: { |
| 3764 | llvm::Type *SrcTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3765 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3766 | Ops[1] = EmitNeonShiftVector(Ops[1], SrcTy, false); |
| 3767 | if (Usgn) |
| 3768 | Ops[0] = Builder.CreateLShr(Ops[0], Ops[1]); |
| 3769 | else |
| 3770 | Ops[0] = Builder.CreateAShr(Ops[0], Ops[1]); |
| 3771 | return Builder.CreateTrunc(Ops[0], Ty, "vshrn_n"); |
| 3772 | } |
| 3773 | case NEON::BI__builtin_neon_vshr_n_v: |
| 3774 | case NEON::BI__builtin_neon_vshrq_n_v: |
| 3775 | return EmitNeonRShiftImm(Ops[0], Ops[1], Ty, Usgn, "vshr_n"); |
| 3776 | case NEON::BI__builtin_neon_vst1_v: |
| 3777 | case NEON::BI__builtin_neon_vst1q_v: |
| 3778 | case NEON::BI__builtin_neon_vst2_v: |
| 3779 | case NEON::BI__builtin_neon_vst2q_v: |
| 3780 | case NEON::BI__builtin_neon_vst3_v: |
| 3781 | case NEON::BI__builtin_neon_vst3q_v: |
| 3782 | case NEON::BI__builtin_neon_vst4_v: |
| 3783 | case NEON::BI__builtin_neon_vst4q_v: |
| 3784 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 3785 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 3786 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 3787 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 3788 | case NEON::BI__builtin_neon_vst4_lane_v: |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3789 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 3790 | llvm::Type *Tys[] = {Int8PtrTy, Ty}; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3791 | Ops.push_back(getAlignmentValue32(PtrOp0)); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 3792 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, ""); |
| 3793 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3794 | case NEON::BI__builtin_neon_vsubhn_v: { |
| 3795 | llvm::VectorType *SrcTy = |
| 3796 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 3797 | |
| 3798 | // %sum = add <4 x i32> %lhs, %rhs |
| 3799 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 3800 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 3801 | Ops[0] = Builder.CreateSub(Ops[0], Ops[1], "vsubhn"); |
| 3802 | |
| 3803 | // %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] | 3804 | Constant *ShiftAmt = |
| 3805 | ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3806 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vsubhn"); |
| 3807 | |
| 3808 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 3809 | return Builder.CreateTrunc(Ops[0], VTy, "vsubhn"); |
| 3810 | } |
| 3811 | case NEON::BI__builtin_neon_vtrn_v: |
| 3812 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 3813 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3814 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3815 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3816 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3817 | |
| 3818 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 3819 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3820 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3821 | Indices.push_back(i+vi); |
| 3822 | Indices.push_back(i+e+vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3823 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3824 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3825 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vtrn"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3826 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3827 | } |
| 3828 | return SV; |
| 3829 | } |
| 3830 | case NEON::BI__builtin_neon_vtst_v: |
| 3831 | case NEON::BI__builtin_neon_vtstq_v: { |
| 3832 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 3833 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3834 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 3835 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
| 3836 | ConstantAggregateZero::get(Ty)); |
| 3837 | return Builder.CreateSExt(Ops[0], Ty, "vtst"); |
| 3838 | } |
| 3839 | case NEON::BI__builtin_neon_vuzp_v: |
| 3840 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 3841 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3842 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3843 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3844 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3845 | |
| 3846 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 3847 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3848 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3849 | Indices.push_back(2*i+vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3850 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3851 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3852 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vuzp"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3853 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3854 | } |
| 3855 | return SV; |
| 3856 | } |
| 3857 | case NEON::BI__builtin_neon_vzip_v: |
| 3858 | case NEON::BI__builtin_neon_vzipq_v: { |
| 3859 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 3860 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 3861 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3862 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3863 | |
| 3864 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 3865 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3866 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3867 | Indices.push_back((i + vi*e) >> 1); |
| 3868 | Indices.push_back(((i + vi*e) >> 1)+e); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3869 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 3870 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3871 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vzip"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 3872 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3873 | } |
| 3874 | return SV; |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | assert(Int && "Expected valid intrinsic number"); |
| 3879 | |
| 3880 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 3881 | Function *F = LookupNeonLLVMIntrinsic(Int, Modifier, Ty, E); |
| 3882 | |
| 3883 | Value *Result = EmitNeonCall(F, Ops, NameHint); |
| 3884 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 3885 | // AArch64 intrinsic one-element vector type cast to |
| 3886 | // scalar type expected by the builtin |
| 3887 | return Builder.CreateBitCast(Result, ResultType, NameHint); |
| 3888 | } |
| 3889 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3890 | Value *CodeGenFunction::EmitAArch64CompareBuiltinExpr( |
| 3891 | Value *Op, llvm::Type *Ty, const CmpInst::Predicate Fp, |
| 3892 | const CmpInst::Predicate Ip, const Twine &Name) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3893 | llvm::Type *OTy = Op->getType(); |
| 3894 | |
| 3895 | // FIXME: this is utterly horrific. We should not be looking at previous |
| 3896 | // codegen context to find out what needs doing. Unfortunately TableGen |
| 3897 | // currently gives us exactly the same calls for vceqz_f32 and vceqz_s32 |
| 3898 | // (etc). |
| 3899 | if (BitCastInst *BI = dyn_cast<BitCastInst>(Op)) |
| 3900 | OTy = BI->getOperand(0)->getType(); |
| 3901 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3902 | Op = Builder.CreateBitCast(Op, OTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3903 | if (OTy->getScalarType()->isFloatingPointTy()) { |
| 3904 | Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3905 | } else { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3906 | Op = Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3907 | } |
Hao Liu | f96fd37 | 2013-12-23 02:44:00 +0000 | [diff] [blame] | 3908 | return Builder.CreateSExt(Op, Ty, Name); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3911 | static Value *packTBLDVectorList(CodeGenFunction &CGF, ArrayRef<Value *> Ops, |
| 3912 | Value *ExtOp, Value *IndexOp, |
| 3913 | llvm::Type *ResTy, unsigned IntID, |
| 3914 | const char *Name) { |
| 3915 | SmallVector<Value *, 2> TblOps; |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 3916 | if (ExtOp) |
| 3917 | TblOps.push_back(ExtOp); |
| 3918 | |
| 3919 | // Build a vector containing sequential number like (0, 1, 2, ..., 15) |
| 3920 | SmallVector<uint32_t, 16> Indices; |
| 3921 | llvm::VectorType *TblTy = cast<llvm::VectorType>(Ops[0]->getType()); |
| 3922 | for (unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3923 | Indices.push_back(2*i); |
| 3924 | Indices.push_back(2*i+1); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3925 | } |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3926 | |
| 3927 | int PairPos = 0, End = Ops.size() - 1; |
| 3928 | while (PairPos < End) { |
| 3929 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3930 | Ops[PairPos+1], Indices, |
| 3931 | Name)); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3932 | PairPos += 2; |
| 3933 | } |
| 3934 | |
| 3935 | // If there's an odd number of 64-bit lookup table, fill the high 64-bit |
| 3936 | // of the 128-bit lookup table with zero. |
| 3937 | if (PairPos == End) { |
| 3938 | Value *ZeroTbl = ConstantAggregateZero::get(TblTy); |
| 3939 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 3940 | ZeroTbl, Indices, Name)); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 3941 | } |
| 3942 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 3943 | Function *TblF; |
| 3944 | TblOps.push_back(IndexOp); |
| 3945 | TblF = CGF.CGM.getIntrinsic(IntID, ResTy); |
| 3946 | |
| 3947 | return CGF.EmitNeonCall(TblF, TblOps, Name); |
| 3948 | } |
| 3949 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3950 | Value *CodeGenFunction::GetValueForARMHint(unsigned BuiltinID) { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3951 | unsigned Value; |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3952 | switch (BuiltinID) { |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3953 | default: |
| 3954 | return nullptr; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 3955 | case ARM::BI__builtin_arm_nop: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3956 | Value = 0; |
| 3957 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3958 | case ARM::BI__builtin_arm_yield: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3959 | case ARM::BI__yield: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3960 | Value = 1; |
| 3961 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3962 | case ARM::BI__builtin_arm_wfe: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3963 | case ARM::BI__wfe: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3964 | Value = 2; |
| 3965 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3966 | case ARM::BI__builtin_arm_wfi: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3967 | case ARM::BI__wfi: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3968 | Value = 3; |
| 3969 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3970 | case ARM::BI__builtin_arm_sev: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3971 | case ARM::BI__sev: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3972 | Value = 4; |
| 3973 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 3974 | case ARM::BI__builtin_arm_sevl: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 3975 | case ARM::BI__sevl: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3976 | Value = 5; |
| 3977 | break; |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 3978 | } |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3979 | |
| 3980 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 3981 | llvm::ConstantInt::get(Int32Ty, Value)); |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 3982 | } |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 3983 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 3984 | // Generates the IR for the read/write special register builtin, |
| 3985 | // ValueType is the type of the value that is to be written or read, |
| 3986 | // RegisterType is the type of the register being written to or read from. |
| 3987 | static Value *EmitSpecialRegisterBuiltin(CodeGenFunction &CGF, |
| 3988 | const CallExpr *E, |
| 3989 | llvm::Type *RegisterType, |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 3990 | llvm::Type *ValueType, |
| 3991 | bool IsRead, |
| 3992 | StringRef SysReg = "") { |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 3993 | // write and register intrinsics only support 32 and 64 bit operations. |
| 3994 | assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64)) |
| 3995 | && "Unsupported size for register."); |
| 3996 | |
| 3997 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 3998 | CodeGen::CodeGenModule &CGM = CGF.CGM; |
| 3999 | LLVMContext &Context = CGM.getLLVMContext(); |
| 4000 | |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 4001 | if (SysReg.empty()) { |
| 4002 | const Expr *SysRegStrExpr = E->getArg(0)->IgnoreParenCasts(); |
| 4003 | SysReg = cast<StringLiteral>(SysRegStrExpr)->getString(); |
| 4004 | } |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4005 | |
| 4006 | llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) }; |
| 4007 | llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops); |
| 4008 | llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName); |
| 4009 | |
| 4010 | llvm::Type *Types[] = { RegisterType }; |
| 4011 | |
| 4012 | bool MixedTypes = RegisterType->isIntegerTy(64) && ValueType->isIntegerTy(32); |
| 4013 | assert(!(RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64)) |
| 4014 | && "Can't fit 64-bit value in 32-bit register"); |
| 4015 | |
| 4016 | if (IsRead) { |
| 4017 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types); |
| 4018 | llvm::Value *Call = Builder.CreateCall(F, Metadata); |
| 4019 | |
| 4020 | if (MixedTypes) |
| 4021 | // Read into 64 bit register and then truncate result to 32 bit. |
| 4022 | return Builder.CreateTrunc(Call, ValueType); |
| 4023 | |
| 4024 | if (ValueType->isPointerTy()) |
| 4025 | // Have i32/i64 result (Call) but want to return a VoidPtrTy (i8*). |
| 4026 | return Builder.CreateIntToPtr(Call, ValueType); |
| 4027 | |
| 4028 | return Call; |
| 4029 | } |
| 4030 | |
| 4031 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types); |
| 4032 | llvm::Value *ArgValue = CGF.EmitScalarExpr(E->getArg(1)); |
| 4033 | if (MixedTypes) { |
| 4034 | // Extend 32 bit write value to 64 bit to pass to write. |
| 4035 | ArgValue = Builder.CreateZExt(ArgValue, RegisterType); |
| 4036 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 4037 | } |
| 4038 | |
| 4039 | if (ValueType->isPointerTy()) { |
| 4040 | // Have VoidPtrTy ArgValue but want to return an i32/i64. |
| 4041 | ArgValue = Builder.CreatePtrToInt(ArgValue, RegisterType); |
| 4042 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 4043 | } |
| 4044 | |
| 4045 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 4046 | } |
| 4047 | |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4048 | /// Return true if BuiltinID is an overloaded Neon intrinsic with an extra |
| 4049 | /// argument that specifies the vector type. |
| 4050 | static bool HasExtraNeonArgument(unsigned BuiltinID) { |
| 4051 | switch (BuiltinID) { |
| 4052 | default: break; |
| 4053 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 4054 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 4055 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 4056 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 4057 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 4058 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 4059 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 4060 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 4061 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 4062 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 4063 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 4064 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 4065 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 4066 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 4067 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 4068 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 4069 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 4070 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 4071 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 4072 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 4073 | case NEON::BI__builtin_neon_vsha1h_u32: |
| 4074 | case NEON::BI__builtin_neon_vsha1cq_u32: |
| 4075 | case NEON::BI__builtin_neon_vsha1pq_u32: |
| 4076 | case NEON::BI__builtin_neon_vsha1mq_u32: |
| 4077 | case ARM::BI_MoveToCoprocessor: |
| 4078 | case ARM::BI_MoveToCoprocessor2: |
| 4079 | return false; |
| 4080 | } |
| 4081 | return true; |
| 4082 | } |
| 4083 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 4084 | Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
| 4085 | const CallExpr *E) { |
| 4086 | if (auto Hint = GetValueForARMHint(BuiltinID)) |
| 4087 | return Hint; |
Saleem Abdulrasool | 38ed6de | 2014-05-02 06:53:57 +0000 | [diff] [blame] | 4088 | |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 4089 | if (BuiltinID == ARM::BI__emit) { |
| 4090 | bool IsThumb = getTarget().getTriple().getArch() == llvm::Triple::thumb; |
| 4091 | llvm::FunctionType *FTy = |
| 4092 | llvm::FunctionType::get(VoidTy, /*Variadic=*/false); |
| 4093 | |
| 4094 | APSInt Value; |
| 4095 | if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext())) |
| 4096 | llvm_unreachable("Sema will ensure that the parameter is constant"); |
| 4097 | |
| 4098 | uint64_t ZExtValue = Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue(); |
| 4099 | |
| 4100 | llvm::InlineAsm *Emit = |
| 4101 | IsThumb ? InlineAsm::get(FTy, ".inst.n 0x" + utohexstr(ZExtValue), "", |
| 4102 | /*SideEffects=*/true) |
| 4103 | : InlineAsm::get(FTy, ".inst 0x" + utohexstr(ZExtValue), "", |
| 4104 | /*SideEffects=*/true); |
| 4105 | |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 4106 | return Builder.CreateCall(Emit); |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 4107 | } |
| 4108 | |
Yi Kong | 1d268af | 2014-08-26 12:48:06 +0000 | [diff] [blame] | 4109 | if (BuiltinID == ARM::BI__builtin_arm_dbg) { |
| 4110 | Value *Option = EmitScalarExpr(E->getArg(0)); |
| 4111 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_dbg), Option); |
| 4112 | } |
| 4113 | |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 4114 | if (BuiltinID == ARM::BI__builtin_arm_prefetch) { |
| 4115 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 4116 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 4117 | Value *IsData = EmitScalarExpr(E->getArg(2)); |
| 4118 | |
| 4119 | // Locality is not supported on ARM target |
| 4120 | Value *Locality = llvm::ConstantInt::get(Int32Ty, 3); |
| 4121 | |
| 4122 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4123 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
Jim Grosbach | 171ec34 | 2014-06-16 21:55:58 +0000 | [diff] [blame] | 4126 | if (BuiltinID == ARM::BI__builtin_arm_rbit) { |
| 4127 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_rbit), |
| 4128 | EmitScalarExpr(E->getArg(0)), |
| 4129 | "rbit"); |
| 4130 | } |
| 4131 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4132 | if (BuiltinID == ARM::BI__clear_cache) { |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 4133 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
Rafael Espindola | a54062e | 2010-06-07 17:26:50 +0000 | [diff] [blame] | 4134 | const FunctionDecl *FD = E->getDirectCallee(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4135 | Value *Ops[2]; |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 4136 | for (unsigned i = 0; i < 2; i++) |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4137 | Ops[i] = EmitScalarExpr(E->getArg(i)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 4138 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 4139 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4140 | StringRef Name = FD->getName(); |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 4141 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 4142 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4143 | |
Ranjeet Singh | ca2b3e7b | 2016-06-17 00:59:41 +0000 | [diff] [blame] | 4144 | if (BuiltinID == ARM::BI__builtin_arm_mcrr || |
| 4145 | BuiltinID == ARM::BI__builtin_arm_mcrr2) { |
| 4146 | Function *F; |
| 4147 | |
| 4148 | switch (BuiltinID) { |
| 4149 | default: llvm_unreachable("unexpected builtin"); |
| 4150 | case ARM::BI__builtin_arm_mcrr: |
| 4151 | F = CGM.getIntrinsic(Intrinsic::arm_mcrr); |
| 4152 | break; |
| 4153 | case ARM::BI__builtin_arm_mcrr2: |
| 4154 | F = CGM.getIntrinsic(Intrinsic::arm_mcrr2); |
| 4155 | break; |
| 4156 | } |
| 4157 | |
| 4158 | // MCRR{2} instruction has 5 operands but |
| 4159 | // the intrinsic has 4 because Rt and Rt2 |
| 4160 | // are represented as a single unsigned 64 |
| 4161 | // bit integer in the intrinsic definition |
| 4162 | // but internally it's represented as 2 32 |
| 4163 | // bit integers. |
| 4164 | |
| 4165 | Value *Coproc = EmitScalarExpr(E->getArg(0)); |
| 4166 | Value *Opc1 = EmitScalarExpr(E->getArg(1)); |
| 4167 | Value *RtAndRt2 = EmitScalarExpr(E->getArg(2)); |
| 4168 | Value *CRm = EmitScalarExpr(E->getArg(3)); |
| 4169 | |
| 4170 | Value *C1 = llvm::ConstantInt::get(Int64Ty, 32); |
| 4171 | Value *Rt = Builder.CreateTruncOrBitCast(RtAndRt2, Int32Ty); |
| 4172 | Value *Rt2 = Builder.CreateLShr(RtAndRt2, C1); |
| 4173 | Rt2 = Builder.CreateTruncOrBitCast(Rt2, Int32Ty); |
| 4174 | |
| 4175 | return Builder.CreateCall(F, {Coproc, Opc1, Rt, Rt2, CRm}); |
| 4176 | } |
| 4177 | |
| 4178 | if (BuiltinID == ARM::BI__builtin_arm_mrrc || |
| 4179 | BuiltinID == ARM::BI__builtin_arm_mrrc2) { |
| 4180 | Function *F; |
| 4181 | |
| 4182 | switch (BuiltinID) { |
| 4183 | default: llvm_unreachable("unexpected builtin"); |
| 4184 | case ARM::BI__builtin_arm_mrrc: |
| 4185 | F = CGM.getIntrinsic(Intrinsic::arm_mrrc); |
| 4186 | break; |
| 4187 | case ARM::BI__builtin_arm_mrrc2: |
| 4188 | F = CGM.getIntrinsic(Intrinsic::arm_mrrc2); |
| 4189 | break; |
| 4190 | } |
| 4191 | |
| 4192 | Value *Coproc = EmitScalarExpr(E->getArg(0)); |
| 4193 | Value *Opc1 = EmitScalarExpr(E->getArg(1)); |
| 4194 | Value *CRm = EmitScalarExpr(E->getArg(2)); |
| 4195 | Value *RtAndRt2 = Builder.CreateCall(F, {Coproc, Opc1, CRm}); |
| 4196 | |
| 4197 | // Returns an unsigned 64 bit integer, represented |
| 4198 | // as two 32 bit integers. |
| 4199 | |
| 4200 | Value *Rt = Builder.CreateExtractValue(RtAndRt2, 1); |
| 4201 | Value *Rt1 = Builder.CreateExtractValue(RtAndRt2, 0); |
| 4202 | Rt = Builder.CreateZExt(Rt, Int64Ty); |
| 4203 | Rt1 = Builder.CreateZExt(Rt1, Int64Ty); |
| 4204 | |
| 4205 | Value *ShiftCast = llvm::ConstantInt::get(Int64Ty, 32); |
| 4206 | RtAndRt2 = Builder.CreateShl(Rt, ShiftCast, "shl", true); |
| 4207 | RtAndRt2 = Builder.CreateOr(RtAndRt2, Rt1); |
| 4208 | |
| 4209 | return Builder.CreateBitCast(RtAndRt2, ConvertType(E->getType())); |
| 4210 | } |
| 4211 | |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4212 | if (BuiltinID == ARM::BI__builtin_arm_ldrexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4213 | ((BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 4214 | BuiltinID == ARM::BI__builtin_arm_ldaex) && |
Saleem Abdulrasool | e700cab | 2014-07-05 20:10:05 +0000 | [diff] [blame] | 4215 | getContext().getTypeSize(E->getType()) == 64) || |
| 4216 | BuiltinID == ARM::BI__ldrexd) { |
| 4217 | Function *F; |
| 4218 | |
| 4219 | switch (BuiltinID) { |
| 4220 | default: llvm_unreachable("unexpected builtin"); |
| 4221 | case ARM::BI__builtin_arm_ldaex: |
| 4222 | F = CGM.getIntrinsic(Intrinsic::arm_ldaexd); |
| 4223 | break; |
| 4224 | case ARM::BI__builtin_arm_ldrexd: |
| 4225 | case ARM::BI__builtin_arm_ldrex: |
| 4226 | case ARM::BI__ldrexd: |
| 4227 | F = CGM.getIntrinsic(Intrinsic::arm_ldrexd); |
| 4228 | break; |
| 4229 | } |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4230 | |
| 4231 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4232 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 4233 | "ldrexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4234 | |
| 4235 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 4236 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 4237 | Val0 = Builder.CreateZExt(Val0, Int64Ty); |
| 4238 | Val1 = Builder.CreateZExt(Val1, Int64Ty); |
| 4239 | |
| 4240 | Value *ShiftCst = llvm::ConstantInt::get(Int64Ty, 32); |
| 4241 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4242 | Val = Builder.CreateOr(Val, Val1); |
| 4243 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4246 | if (BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 4247 | BuiltinID == ARM::BI__builtin_arm_ldaex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4248 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 4249 | |
| 4250 | QualType Ty = E->getType(); |
| 4251 | llvm::Type *RealResTy = ConvertType(Ty); |
| 4252 | llvm::Type *IntResTy = llvm::IntegerType::get(getLLVMContext(), |
| 4253 | getContext().getTypeSize(Ty)); |
| 4254 | LoadAddr = Builder.CreateBitCast(LoadAddr, IntResTy->getPointerTo()); |
| 4255 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4256 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_ldaex |
| 4257 | ? Intrinsic::arm_ldaex |
| 4258 | : Intrinsic::arm_ldrex, |
| 4259 | LoadAddr->getType()); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4260 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldrex"); |
| 4261 | |
| 4262 | if (RealResTy->isPointerTy()) |
| 4263 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 4264 | else { |
| 4265 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 4266 | return Builder.CreateBitCast(Val, RealResTy); |
| 4267 | } |
| 4268 | } |
| 4269 | |
| 4270 | if (BuiltinID == ARM::BI__builtin_arm_strexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4271 | ((BuiltinID == ARM::BI__builtin_arm_stlex || |
| 4272 | BuiltinID == ARM::BI__builtin_arm_strex) && |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4273 | getContext().getTypeSize(E->getArg(0)->getType()) == 64)) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4274 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 4275 | ? Intrinsic::arm_stlexd |
| 4276 | : Intrinsic::arm_strexd); |
Reid Kleckner | ee7cf84 | 2014-12-01 22:02:27 +0000 | [diff] [blame] | 4277 | llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty, nullptr); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4278 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4279 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4280 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 4281 | Builder.CreateStore(Val, Tmp); |
| 4282 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4283 | Address LdPtr = Builder.CreateBitCast(Tmp,llvm::PointerType::getUnqual(STy)); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4284 | Val = Builder.CreateLoad(LdPtr); |
| 4285 | |
| 4286 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 4287 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4288 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4289 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "strexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4292 | if (BuiltinID == ARM::BI__builtin_arm_strex || |
| 4293 | BuiltinID == ARM::BI__builtin_arm_stlex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4294 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 4295 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 4296 | |
| 4297 | QualType Ty = E->getArg(0)->getType(); |
| 4298 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 4299 | getContext().getTypeSize(Ty)); |
| 4300 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 4301 | |
| 4302 | if (StoreVal->getType()->isPointerTy()) |
| 4303 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int32Ty); |
| 4304 | else { |
| 4305 | StoreVal = Builder.CreateBitCast(StoreVal, StoreTy); |
| 4306 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int32Ty); |
| 4307 | } |
| 4308 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 4309 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 4310 | ? Intrinsic::arm_stlex |
| 4311 | : Intrinsic::arm_strex, |
| 4312 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4313 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "strex"); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4314 | } |
| 4315 | |
Martin Storsjo | ed95a08 | 2016-09-30 19:13:46 +0000 | [diff] [blame] | 4316 | switch (BuiltinID) { |
| 4317 | case ARM::BI__iso_volatile_load8: |
| 4318 | case ARM::BI__iso_volatile_load16: |
| 4319 | case ARM::BI__iso_volatile_load32: |
| 4320 | case ARM::BI__iso_volatile_load64: { |
| 4321 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 4322 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 4323 | CharUnits LoadSize = getContext().getTypeSizeInChars(ElTy); |
| 4324 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 4325 | LoadSize.getQuantity() * 8); |
| 4326 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
| 4327 | llvm::LoadInst *Load = |
| 4328 | Builder.CreateAlignedLoad(Ptr, LoadSize); |
| 4329 | Load->setVolatile(true); |
| 4330 | return Load; |
| 4331 | } |
| 4332 | case ARM::BI__iso_volatile_store8: |
| 4333 | case ARM::BI__iso_volatile_store16: |
| 4334 | case ARM::BI__iso_volatile_store32: |
| 4335 | case ARM::BI__iso_volatile_store64: { |
| 4336 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 4337 | Value *Value = EmitScalarExpr(E->getArg(1)); |
| 4338 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 4339 | CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); |
| 4340 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 4341 | StoreSize.getQuantity() * 8); |
| 4342 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
| 4343 | llvm::StoreInst *Store = |
| 4344 | Builder.CreateAlignedStore(Value, Ptr, |
| 4345 | StoreSize); |
| 4346 | Store->setVolatile(true); |
| 4347 | return Store; |
| 4348 | } |
| 4349 | } |
| 4350 | |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4351 | if (BuiltinID == ARM::BI__builtin_arm_clrex) { |
| 4352 | Function *F = CGM.getIntrinsic(Intrinsic::arm_clrex); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 4353 | return Builder.CreateCall(F); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 4354 | } |
| 4355 | |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 4356 | // CRC32 |
| 4357 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 4358 | switch (BuiltinID) { |
| 4359 | case ARM::BI__builtin_arm_crc32b: |
| 4360 | CRCIntrinsicID = Intrinsic::arm_crc32b; break; |
| 4361 | case ARM::BI__builtin_arm_crc32cb: |
| 4362 | CRCIntrinsicID = Intrinsic::arm_crc32cb; break; |
| 4363 | case ARM::BI__builtin_arm_crc32h: |
| 4364 | CRCIntrinsicID = Intrinsic::arm_crc32h; break; |
| 4365 | case ARM::BI__builtin_arm_crc32ch: |
| 4366 | CRCIntrinsicID = Intrinsic::arm_crc32ch; break; |
| 4367 | case ARM::BI__builtin_arm_crc32w: |
| 4368 | case ARM::BI__builtin_arm_crc32d: |
| 4369 | CRCIntrinsicID = Intrinsic::arm_crc32w; break; |
| 4370 | case ARM::BI__builtin_arm_crc32cw: |
| 4371 | case ARM::BI__builtin_arm_crc32cd: |
| 4372 | CRCIntrinsicID = Intrinsic::arm_crc32cw; break; |
| 4373 | } |
| 4374 | |
| 4375 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 4376 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 4377 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 4378 | |
| 4379 | // crc32{c,}d intrinsics are implemnted as two calls to crc32{c,}w |
| 4380 | // intrinsics, hence we need different codegen for these cases. |
| 4381 | if (BuiltinID == ARM::BI__builtin_arm_crc32d || |
| 4382 | BuiltinID == ARM::BI__builtin_arm_crc32cd) { |
| 4383 | Value *C1 = llvm::ConstantInt::get(Int64Ty, 32); |
| 4384 | Value *Arg1a = Builder.CreateTruncOrBitCast(Arg1, Int32Ty); |
| 4385 | Value *Arg1b = Builder.CreateLShr(Arg1, C1); |
| 4386 | Arg1b = Builder.CreateTruncOrBitCast(Arg1b, Int32Ty); |
| 4387 | |
| 4388 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4389 | Value *Res = Builder.CreateCall(F, {Arg0, Arg1a}); |
| 4390 | return Builder.CreateCall(F, {Res, Arg1b}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 4391 | } else { |
| 4392 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, Int32Ty); |
| 4393 | |
| 4394 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4395 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4399 | if (BuiltinID == ARM::BI__builtin_arm_rsr || |
| 4400 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 4401 | BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 4402 | BuiltinID == ARM::BI__builtin_arm_wsr || |
| 4403 | BuiltinID == ARM::BI__builtin_arm_wsr64 || |
| 4404 | BuiltinID == ARM::BI__builtin_arm_wsrp) { |
| 4405 | |
| 4406 | bool IsRead = BuiltinID == ARM::BI__builtin_arm_rsr || |
| 4407 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 4408 | BuiltinID == ARM::BI__builtin_arm_rsrp; |
| 4409 | |
| 4410 | bool IsPointerBuiltin = BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 4411 | BuiltinID == ARM::BI__builtin_arm_wsrp; |
| 4412 | |
| 4413 | bool Is64Bit = BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 4414 | BuiltinID == ARM::BI__builtin_arm_wsr64; |
| 4415 | |
| 4416 | llvm::Type *ValueType; |
| 4417 | llvm::Type *RegisterType; |
| 4418 | if (IsPointerBuiltin) { |
| 4419 | ValueType = VoidPtrTy; |
| 4420 | RegisterType = Int32Ty; |
| 4421 | } else if (Is64Bit) { |
| 4422 | ValueType = RegisterType = Int64Ty; |
| 4423 | } else { |
| 4424 | ValueType = RegisterType = Int32Ty; |
| 4425 | } |
| 4426 | |
| 4427 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 4428 | } |
| 4429 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4430 | // Find out if any arguments are required to be integer constant |
| 4431 | // expressions. |
| 4432 | unsigned ICEArguments = 0; |
| 4433 | ASTContext::GetBuiltinTypeError Error; |
| 4434 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 4435 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 4436 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4437 | auto getAlignmentValue32 = [&](Address addr) -> Value* { |
| 4438 | return Builder.getInt32(addr.getAlignment().getQuantity()); |
| 4439 | }; |
| 4440 | |
| 4441 | Address PtrOp0 = Address::invalid(); |
| 4442 | Address PtrOp1 = Address::invalid(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4443 | SmallVector<Value*, 4> Ops; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4444 | bool HasExtraArg = HasExtraNeonArgument(BuiltinID); |
| 4445 | unsigned NumArgs = E->getNumArgs() - (HasExtraArg ? 1 : 0); |
| 4446 | for (unsigned i = 0, e = NumArgs; i != e; i++) { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4447 | if (i == 0) { |
| 4448 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4449 | case NEON::BI__builtin_neon_vld1_v: |
| 4450 | case NEON::BI__builtin_neon_vld1q_v: |
| 4451 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 4452 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 4453 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 4454 | case NEON::BI__builtin_neon_vld1q_dup_v: |
| 4455 | case NEON::BI__builtin_neon_vst1_v: |
| 4456 | case NEON::BI__builtin_neon_vst1q_v: |
| 4457 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 4458 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 4459 | case NEON::BI__builtin_neon_vst2_v: |
| 4460 | case NEON::BI__builtin_neon_vst2q_v: |
| 4461 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 4462 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 4463 | case NEON::BI__builtin_neon_vst3_v: |
| 4464 | case NEON::BI__builtin_neon_vst3q_v: |
| 4465 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 4466 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 4467 | case NEON::BI__builtin_neon_vst4_v: |
| 4468 | case NEON::BI__builtin_neon_vst4q_v: |
| 4469 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 4470 | case NEON::BI__builtin_neon_vst4q_lane_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4471 | // Get the alignment for the argument in addition to the value; |
| 4472 | // we'll use it later. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4473 | PtrOp0 = EmitPointerWithAlignment(E->getArg(0)); |
| 4474 | Ops.push_back(PtrOp0.getPointer()); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4475 | continue; |
| 4476 | } |
| 4477 | } |
| 4478 | if (i == 1) { |
| 4479 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4480 | case NEON::BI__builtin_neon_vld2_v: |
| 4481 | case NEON::BI__builtin_neon_vld2q_v: |
| 4482 | case NEON::BI__builtin_neon_vld3_v: |
| 4483 | case NEON::BI__builtin_neon_vld3q_v: |
| 4484 | case NEON::BI__builtin_neon_vld4_v: |
| 4485 | case NEON::BI__builtin_neon_vld4q_v: |
| 4486 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 4487 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 4488 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 4489 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 4490 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 4491 | case NEON::BI__builtin_neon_vld4q_lane_v: |
| 4492 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 4493 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 4494 | case NEON::BI__builtin_neon_vld4_dup_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4495 | // Get the alignment for the argument in addition to the value; |
| 4496 | // we'll use it later. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4497 | PtrOp1 = EmitPointerWithAlignment(E->getArg(1)); |
| 4498 | Ops.push_back(PtrOp1.getPointer()); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4499 | continue; |
| 4500 | } |
| 4501 | } |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 4502 | |
| 4503 | if ((ICEArguments & (1 << i)) == 0) { |
| 4504 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 4505 | } else { |
| 4506 | // If this is required to be a constant, constant fold it so that we know |
| 4507 | // that the generated intrinsic gets a ConstantInt. |
| 4508 | llvm::APSInt Result; |
| 4509 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 4510 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
| 4511 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 4512 | } |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 4513 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4514 | |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 4515 | switch (BuiltinID) { |
| 4516 | default: break; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4517 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4518 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 4519 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 4520 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 4521 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 4522 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 4523 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 4524 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 4525 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 4526 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 4527 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4528 | return Builder.CreateExtractElement(Ops[0], Ops[1], "vget_lane"); |
| 4529 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4530 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 4531 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 4532 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 4533 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 4534 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 4535 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 4536 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 4537 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 4538 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 4539 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 4540 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4541 | |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4542 | case NEON::BI__builtin_neon_vsha1h_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4543 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1h), Ops, |
| 4544 | "vsha1h"); |
| 4545 | case NEON::BI__builtin_neon_vsha1cq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4546 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1c), Ops, |
| 4547 | "vsha1h"); |
| 4548 | case NEON::BI__builtin_neon_vsha1pq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4549 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1p), Ops, |
| 4550 | "vsha1h"); |
| 4551 | case NEON::BI__builtin_neon_vsha1mq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 4552 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1m), Ops, |
| 4553 | "vsha1h"); |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4554 | |
| 4555 | // The ARM _MoveToCoprocessor builtins put the input register value as |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 4556 | // the first argument, but the LLVM intrinsic expects it as the third one. |
| 4557 | case ARM::BI_MoveToCoprocessor: |
| 4558 | case ARM::BI_MoveToCoprocessor2: { |
| 4559 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI_MoveToCoprocessor ? |
| 4560 | Intrinsic::arm_mcr : Intrinsic::arm_mcr2); |
| 4561 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0], |
| 4562 | Ops[3], Ops[4], Ops[5]}); |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4563 | } |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | // Get the last argument, which specifies the vector type. |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4567 | assert(HasExtraArg); |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4568 | llvm::APSInt Result; |
| 4569 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 4570 | if (!Arg->isIntegerConstantExpr(Result, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4571 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4572 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4573 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f || |
| 4574 | BuiltinID == ARM::BI__builtin_arm_vcvtr_d) { |
| 4575 | // Determine the overloaded type of this builtin. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 4576 | llvm::Type *Ty; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4577 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 4578 | Ty = FloatTy; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4579 | else |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 4580 | Ty = DoubleTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4581 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4582 | // Determine whether this is an unsigned conversion or not. |
| 4583 | bool usgn = Result.getZExtValue() == 1; |
| 4584 | unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr; |
| 4585 | |
| 4586 | // Call the appropriate intrinsic. |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4587 | Function *F = CGM.getIntrinsic(Int, Ty); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 4588 | return Builder.CreateCall(F, Ops, "vcvtr"); |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4589 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4590 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 4591 | // Determine the type of this overloaded NEON intrinsic. |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 4592 | NeonTypeFlags Type(Result.getZExtValue()); |
| 4593 | bool usgn = Type.isUnsigned(); |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 4594 | bool rightShift = false; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4595 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 4596 | llvm::VectorType *VTy = GetNeonType(this, Type); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 4597 | llvm::Type *Ty = VTy; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4598 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4599 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4600 | |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 4601 | // Many NEON builtins have identical semantics and uses in ARM and |
| 4602 | // AArch64. Emit these in a single function. |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 4603 | auto IntrinsicMap = makeArrayRef(ARMSIMDIntrinsicMap); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4604 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
| 4605 | IntrinsicMap, BuiltinID, NEONSIMDIntrinsicsProvenSorted); |
| 4606 | if (Builtin) |
| 4607 | return EmitCommonNeonBuiltinExpr( |
| 4608 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4609 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, PtrOp0, PtrOp1); |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 4610 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4611 | unsigned Int; |
| 4612 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4613 | default: return nullptr; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4614 | case NEON::BI__builtin_neon_vld1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4615 | // Handle 64-bit integer elements as a special case. Use shuffles of |
| 4616 | // one-element vectors to avoid poor code for i64 in the backend. |
| 4617 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 4618 | // Extract the other lane. |
| 4619 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4620 | uint32_t Lane = cast<ConstantInt>(Ops[2])->getZExtValue(); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4621 | Value *SV = llvm::ConstantVector::get(ConstantInt::get(Int32Ty, 1-Lane)); |
| 4622 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
| 4623 | // Load the value as a one-element vector. |
| 4624 | Ty = llvm::VectorType::get(VTy->getElementType(), 1); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4625 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4626 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4627 | Value *Align = getAlignmentValue32(PtrOp0); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4628 | Value *Ld = Builder.CreateCall(F, {Ops[0], Align}); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4629 | // Combine them. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4630 | uint32_t Indices[] = {1 - Lane, Lane}; |
| 4631 | SV = llvm::ConstantDataVector::get(getLLVMContext(), Indices); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4632 | return Builder.CreateShuffleVector(Ops[1], Ld, SV, "vld1q_lane"); |
| 4633 | } |
| 4634 | // fall through |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4635 | case NEON::BI__builtin_neon_vld1_lane_v: { |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4636 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Steven Wu | 0d22f2d | 2015-09-09 01:37:18 +0000 | [diff] [blame] | 4637 | PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4638 | Value *Ld = Builder.CreateLoad(PtrOp0); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 4639 | return Builder.CreateInsertElement(Ops[1], Ld, Ops[2], "vld1_lane"); |
| 4640 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4641 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 4642 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 4643 | case NEON::BI__builtin_neon_vld4_dup_v: { |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4644 | // Handle 64-bit elements as a special-case. There is no "dup" needed. |
| 4645 | if (VTy->getElementType()->getPrimitiveSizeInBits() == 64) { |
| 4646 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4647 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4648 | Int = Intrinsic::arm_neon_vld2; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4649 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4650 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4651 | Int = Intrinsic::arm_neon_vld3; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4652 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4653 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4654 | Int = Intrinsic::arm_neon_vld4; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4655 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 4656 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4657 | } |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4658 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4659 | Function *F = CGM.getIntrinsic(Int, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4660 | llvm::Value *Align = getAlignmentValue32(PtrOp1); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4661 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, "vld_dup"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4662 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 4663 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4664 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 4665 | } |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4666 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4667 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4668 | Int = Intrinsic::arm_neon_vld2lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4669 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4670 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4671 | Int = Intrinsic::arm_neon_vld3lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4672 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4673 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4674 | Int = Intrinsic::arm_neon_vld4lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4675 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 4676 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4677 | } |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4678 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4679 | Function *F = CGM.getIntrinsic(Int, Tys); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 4680 | llvm::StructType *STy = cast<llvm::StructType>(F->getReturnType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4681 | |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4682 | SmallVector<Value*, 6> Args; |
| 4683 | Args.push_back(Ops[1]); |
| 4684 | Args.append(STy->getNumElements(), UndefValue::get(Ty)); |
| 4685 | |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 4686 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4687 | Args.push_back(CI); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4688 | Args.push_back(getAlignmentValue32(PtrOp1)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4689 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 4690 | Ops[1] = Builder.CreateCall(F, Args, "vld_dup"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4691 | // splat lane 0 to all elts in each vector of the result. |
| 4692 | for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { |
| 4693 | Value *Val = Builder.CreateExtractValue(Ops[1], i); |
| 4694 | Value *Elt = Builder.CreateBitCast(Val, Ty); |
| 4695 | Elt = EmitNeonSplat(Elt, CI); |
| 4696 | Elt = Builder.CreateBitCast(Elt, Val->getType()); |
| 4697 | Ops[1] = Builder.CreateInsertValue(Ops[1], Elt, i); |
| 4698 | } |
| 4699 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 4700 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4701 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 4702 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4703 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 4704 | Int = |
| 4705 | usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4706 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 4707 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4708 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4709 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 4710 | Ops, "vqrshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4711 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 4712 | Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4713 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 4714 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4715 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4716 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 4717 | Ops, "vqshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4718 | case NEON::BI__builtin_neon_vrecpe_v: |
| 4719 | case NEON::BI__builtin_neon_vrecpeq_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4720 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecpe, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4721 | Ops, "vrecpe"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4722 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4723 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrshiftn, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 4724 | Ops, "vrshrn_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4725 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 4726 | case NEON::BI__builtin_neon_vrsraq_n_v: |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 4727 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4728 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4729 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, true); |
| 4730 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4731 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Ty), {Ops[1], Ops[2]}); |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 4732 | return Builder.CreateAdd(Ops[0], Ops[1], "vrsra_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4733 | case NEON::BI__builtin_neon_vsri_n_v: |
| 4734 | case NEON::BI__builtin_neon_vsriq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 4735 | rightShift = true; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4736 | case NEON::BI__builtin_neon_vsli_n_v: |
| 4737 | case NEON::BI__builtin_neon_vsliq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 4738 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, rightShift); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 4739 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftins, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4740 | Ops, "vsli_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4741 | case NEON::BI__builtin_neon_vsra_n_v: |
| 4742 | case NEON::BI__builtin_neon_vsraq_n_v: |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4743 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 4744 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4745 | return Builder.CreateAdd(Ops[0], Ops[1]); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4746 | case NEON::BI__builtin_neon_vst1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4747 | // Handle 64-bit integer elements as a special case. Use a shuffle to get |
| 4748 | // a one-element vector and avoid poor code for i64 in the backend. |
| 4749 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 4750 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4751 | Value *SV = llvm::ConstantVector::get(cast<llvm::Constant>(Ops[2])); |
| 4752 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4753 | Ops[2] = getAlignmentValue32(PtrOp0); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4754 | llvm::Type *Tys[] = {Int8PtrTy, Ops[1]->getType()}; |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4755 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst1, |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4756 | Tys), Ops); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 4757 | } |
| 4758 | // fall through |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4759 | case NEON::BI__builtin_neon_vst1_lane_v: { |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 4760 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4761 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 4762 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4763 | auto St = Builder.CreateStore(Ops[1], Builder.CreateBitCast(PtrOp0, Ty)); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 4764 | return St; |
| 4765 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4766 | case NEON::BI__builtin_neon_vtbl1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4767 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1), |
| 4768 | Ops, "vtbl1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4769 | case NEON::BI__builtin_neon_vtbl2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4770 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl2), |
| 4771 | Ops, "vtbl2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4772 | case NEON::BI__builtin_neon_vtbl3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4773 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl3), |
| 4774 | Ops, "vtbl3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4775 | case NEON::BI__builtin_neon_vtbl4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4776 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl4), |
| 4777 | Ops, "vtbl4"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4778 | case NEON::BI__builtin_neon_vtbx1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4779 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx1), |
| 4780 | Ops, "vtbx1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4781 | case NEON::BI__builtin_neon_vtbx2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4782 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx2), |
| 4783 | Ops, "vtbx2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4784 | case NEON::BI__builtin_neon_vtbx3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4785 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx3), |
| 4786 | Ops, "vtbx3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 4787 | case NEON::BI__builtin_neon_vtbx4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 4788 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx4), |
| 4789 | Ops, "vtbx4"); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 4790 | } |
| 4791 | } |
| 4792 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4793 | static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID, |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4794 | const CallExpr *E, |
| 4795 | SmallVectorImpl<Value *> &Ops) { |
| 4796 | unsigned int Int = 0; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4797 | const char *s = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4798 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4799 | switch (BuiltinID) { |
| 4800 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4801 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4802 | case NEON::BI__builtin_neon_vtbl1_v: |
| 4803 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 4804 | case NEON::BI__builtin_neon_vqtbl1q_v: |
| 4805 | case NEON::BI__builtin_neon_vtbl2_v: |
| 4806 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 4807 | case NEON::BI__builtin_neon_vqtbl2q_v: |
| 4808 | case NEON::BI__builtin_neon_vtbl3_v: |
| 4809 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 4810 | case NEON::BI__builtin_neon_vqtbl3q_v: |
| 4811 | case NEON::BI__builtin_neon_vtbl4_v: |
| 4812 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 4813 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4814 | break; |
| 4815 | case NEON::BI__builtin_neon_vtbx1_v: |
| 4816 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 4817 | case NEON::BI__builtin_neon_vqtbx1q_v: |
| 4818 | case NEON::BI__builtin_neon_vtbx2_v: |
| 4819 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 4820 | case NEON::BI__builtin_neon_vqtbx2q_v: |
| 4821 | case NEON::BI__builtin_neon_vtbx3_v: |
| 4822 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 4823 | case NEON::BI__builtin_neon_vqtbx3q_v: |
| 4824 | case NEON::BI__builtin_neon_vtbx4_v: |
| 4825 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 4826 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | } |
| 4829 | |
| 4830 | assert(E->getNumArgs() >= 3); |
| 4831 | |
| 4832 | // Get the last argument, which specifies the vector type. |
| 4833 | llvm::APSInt Result; |
| 4834 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 4835 | if (!Arg->isIntegerConstantExpr(Result, CGF.getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4836 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4837 | |
| 4838 | // Determine the type of this overloaded NEON intrinsic. |
| 4839 | NeonTypeFlags Type(Result.getZExtValue()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4840 | llvm::VectorType *Ty = GetNeonType(&CGF, Type); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4841 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4842 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4843 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4844 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 4845 | |
| 4846 | // AArch64 scalar builtins are not overloaded, they do not have an extra |
| 4847 | // argument that specifies the vector type, need to handle each case. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4848 | switch (BuiltinID) { |
| 4849 | case NEON::BI__builtin_neon_vtbl1_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4850 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 1), nullptr, |
| 4851 | Ops[1], Ty, Intrinsic::aarch64_neon_tbl1, |
| 4852 | "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4853 | } |
| 4854 | case NEON::BI__builtin_neon_vtbl2_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4855 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 2), nullptr, |
| 4856 | Ops[2], Ty, Intrinsic::aarch64_neon_tbl1, |
| 4857 | "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4858 | } |
| 4859 | case NEON::BI__builtin_neon_vtbl3_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4860 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 3), nullptr, |
| 4861 | Ops[3], Ty, Intrinsic::aarch64_neon_tbl2, |
| 4862 | "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4863 | } |
| 4864 | case NEON::BI__builtin_neon_vtbl4_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4865 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 4), nullptr, |
| 4866 | Ops[4], Ty, Intrinsic::aarch64_neon_tbl2, |
| 4867 | "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4868 | } |
| 4869 | case NEON::BI__builtin_neon_vtbx1_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4870 | Value *TblRes = |
| 4871 | packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 1), nullptr, Ops[2], |
| 4872 | Ty, Intrinsic::aarch64_neon_tbl1, "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4873 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4874 | llvm::Constant *EightV = ConstantInt::get(Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4875 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[2], EightV); |
| 4876 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 4877 | |
| 4878 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 4879 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 4880 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 4881 | } |
| 4882 | case NEON::BI__builtin_neon_vtbx2_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4883 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 2), Ops[0], |
| 4884 | Ops[3], Ty, Intrinsic::aarch64_neon_tbx1, |
| 4885 | "vtbx1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4886 | } |
| 4887 | case NEON::BI__builtin_neon_vtbx3_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4888 | Value *TblRes = |
| 4889 | packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 3), nullptr, Ops[4], |
| 4890 | Ty, Intrinsic::aarch64_neon_tbl2, "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4891 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4892 | llvm::Constant *TwentyFourV = ConstantInt::get(Ty, 24); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4893 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[4], |
| 4894 | TwentyFourV); |
| 4895 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 4896 | |
| 4897 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 4898 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 4899 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 4900 | } |
| 4901 | case NEON::BI__builtin_neon_vtbx4_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4902 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 4), Ops[0], |
| 4903 | Ops[5], Ty, Intrinsic::aarch64_neon_tbx2, |
| 4904 | "vtbx2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4905 | } |
| 4906 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 4907 | case NEON::BI__builtin_neon_vqtbl1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4908 | Int = Intrinsic::aarch64_neon_tbl1; s = "vtbl1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4909 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 4910 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4911 | Int = Intrinsic::aarch64_neon_tbl2; s = "vtbl2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4912 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 4913 | case NEON::BI__builtin_neon_vqtbl3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4914 | Int = Intrinsic::aarch64_neon_tbl3; s = "vtbl3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4915 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 4916 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4917 | Int = Intrinsic::aarch64_neon_tbl4; s = "vtbl4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4918 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 4919 | case NEON::BI__builtin_neon_vqtbx1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4920 | Int = Intrinsic::aarch64_neon_tbx1; s = "vtbx1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4921 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 4922 | case NEON::BI__builtin_neon_vqtbx2q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4923 | Int = Intrinsic::aarch64_neon_tbx2; s = "vtbx2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4924 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 4925 | case NEON::BI__builtin_neon_vqtbx3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4926 | Int = Intrinsic::aarch64_neon_tbx3; s = "vtbx3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4927 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 4928 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4929 | Int = Intrinsic::aarch64_neon_tbx4; s = "vtbx4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4930 | } |
| 4931 | } |
| 4932 | |
| 4933 | if (!Int) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4934 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4935 | |
| 4936 | Function *F = CGF.CGM.getIntrinsic(Int, Ty); |
| 4937 | return CGF.EmitNeonCall(F, Ops, s); |
| 4938 | } |
| 4939 | |
| 4940 | Value *CodeGenFunction::vectorWrapScalar16(Value *Op) { |
| 4941 | llvm::Type *VTy = llvm::VectorType::get(Int16Ty, 4); |
| 4942 | Op = Builder.CreateBitCast(Op, Int16Ty); |
| 4943 | Value *V = UndefValue::get(VTy); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4944 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4945 | Op = Builder.CreateInsertElement(V, Op, CI); |
| 4946 | return Op; |
| 4947 | } |
| 4948 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4949 | Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, |
| 4950 | const CallExpr *E) { |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 4951 | unsigned HintID = static_cast<unsigned>(-1); |
| 4952 | switch (BuiltinID) { |
| 4953 | default: break; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 4954 | case AArch64::BI__builtin_arm_nop: |
| 4955 | HintID = 0; |
| 4956 | break; |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 4957 | case AArch64::BI__builtin_arm_yield: |
| 4958 | HintID = 1; |
| 4959 | break; |
| 4960 | case AArch64::BI__builtin_arm_wfe: |
| 4961 | HintID = 2; |
| 4962 | break; |
| 4963 | case AArch64::BI__builtin_arm_wfi: |
| 4964 | HintID = 3; |
| 4965 | break; |
| 4966 | case AArch64::BI__builtin_arm_sev: |
| 4967 | HintID = 4; |
| 4968 | break; |
| 4969 | case AArch64::BI__builtin_arm_sevl: |
| 4970 | HintID = 5; |
| 4971 | break; |
| 4972 | } |
| 4973 | |
| 4974 | if (HintID != static_cast<unsigned>(-1)) { |
| 4975 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hint); |
| 4976 | return Builder.CreateCall(F, llvm::ConstantInt::get(Int32Ty, HintID)); |
| 4977 | } |
| 4978 | |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 4979 | if (BuiltinID == AArch64::BI__builtin_arm_prefetch) { |
| 4980 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 4981 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 4982 | Value *CacheLevel = EmitScalarExpr(E->getArg(2)); |
| 4983 | Value *RetentionPolicy = EmitScalarExpr(E->getArg(3)); |
| 4984 | Value *IsData = EmitScalarExpr(E->getArg(4)); |
| 4985 | |
| 4986 | Value *Locality = nullptr; |
| 4987 | if (cast<llvm::ConstantInt>(RetentionPolicy)->isZero()) { |
| 4988 | // Temporal fetch, needs to convert cache level to locality. |
| 4989 | Locality = llvm::ConstantInt::get(Int32Ty, |
| 4990 | -cast<llvm::ConstantInt>(CacheLevel)->getValue() + 3); |
| 4991 | } else { |
| 4992 | // Streaming fetch. |
| 4993 | Locality = llvm::ConstantInt::get(Int32Ty, 0); |
| 4994 | } |
| 4995 | |
| 4996 | // FIXME: We need AArch64 specific LLVM intrinsic if we want to specify |
| 4997 | // PLDL3STRM or PLDL2STRM. |
| 4998 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4999 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
Jim Grosbach | 7914082 | 2014-06-16 21:56:02 +0000 | [diff] [blame] | 5002 | if (BuiltinID == AArch64::BI__builtin_arm_rbit) { |
| 5003 | assert((getContext().getTypeSize(E->getType()) == 32) && |
| 5004 | "rbit of unusual size!"); |
| 5005 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 5006 | return Builder.CreateCall( |
| 5007 | CGM.getIntrinsic(Intrinsic::aarch64_rbit, Arg->getType()), Arg, "rbit"); |
| 5008 | } |
| 5009 | if (BuiltinID == AArch64::BI__builtin_arm_rbit64) { |
| 5010 | assert((getContext().getTypeSize(E->getType()) == 64) && |
| 5011 | "rbit of unusual size!"); |
| 5012 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 5013 | return Builder.CreateCall( |
| 5014 | CGM.getIntrinsic(Intrinsic::aarch64_rbit, Arg->getType()), Arg, "rbit"); |
| 5015 | } |
| 5016 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5017 | if (BuiltinID == AArch64::BI__clear_cache) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5018 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
| 5019 | const FunctionDecl *FD = E->getDirectCallee(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5020 | Value *Ops[2]; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5021 | for (unsigned i = 0; i < 2; i++) |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5022 | Ops[i] = EmitScalarExpr(E->getArg(i)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5023 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 5024 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
| 5025 | StringRef Name = FD->getName(); |
| 5026 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
| 5027 | } |
| 5028 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5029 | if ((BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 5030 | BuiltinID == AArch64::BI__builtin_arm_ldaex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5031 | getContext().getTypeSize(E->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5032 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 5033 | ? Intrinsic::aarch64_ldaxp |
| 5034 | : Intrinsic::aarch64_ldxp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5035 | |
| 5036 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
| 5037 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 5038 | "ldxp"); |
| 5039 | |
| 5040 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 5041 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 5042 | llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128); |
| 5043 | Val0 = Builder.CreateZExt(Val0, Int128Ty); |
| 5044 | Val1 = Builder.CreateZExt(Val1, Int128Ty); |
| 5045 | |
| 5046 | Value *ShiftCst = llvm::ConstantInt::get(Int128Ty, 64); |
| 5047 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
| 5048 | Val = Builder.CreateOr(Val, Val1); |
| 5049 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5050 | } else if (BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 5051 | BuiltinID == AArch64::BI__builtin_arm_ldaex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5052 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 5053 | |
| 5054 | QualType Ty = E->getType(); |
| 5055 | llvm::Type *RealResTy = ConvertType(Ty); |
| 5056 | llvm::Type *IntResTy = llvm::IntegerType::get(getLLVMContext(), |
| 5057 | getContext().getTypeSize(Ty)); |
| 5058 | LoadAddr = Builder.CreateBitCast(LoadAddr, IntResTy->getPointerTo()); |
| 5059 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5060 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 5061 | ? Intrinsic::aarch64_ldaxr |
| 5062 | : Intrinsic::aarch64_ldxr, |
| 5063 | LoadAddr->getType()); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5064 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldxr"); |
| 5065 | |
| 5066 | if (RealResTy->isPointerTy()) |
| 5067 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 5068 | |
| 5069 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 5070 | return Builder.CreateBitCast(Val, RealResTy); |
| 5071 | } |
| 5072 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5073 | if ((BuiltinID == AArch64::BI__builtin_arm_strex || |
| 5074 | BuiltinID == AArch64::BI__builtin_arm_stlex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5075 | getContext().getTypeSize(E->getArg(0)->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5076 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 5077 | ? Intrinsic::aarch64_stlxp |
| 5078 | : Intrinsic::aarch64_stxp); |
Reid Kleckner | ee7cf84 | 2014-12-01 22:02:27 +0000 | [diff] [blame] | 5079 | llvm::Type *STy = llvm::StructType::get(Int64Ty, Int64Ty, nullptr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5080 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5081 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
| 5082 | EmitAnyExprToMem(E->getArg(0), Tmp, Qualifiers(), /*init*/ true); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5083 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5084 | Tmp = Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(STy)); |
| 5085 | llvm::Value *Val = Builder.CreateLoad(Tmp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5086 | |
| 5087 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 5088 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
| 5089 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), |
| 5090 | Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5091 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "stxp"); |
| 5092 | } |
| 5093 | |
| 5094 | if (BuiltinID == AArch64::BI__builtin_arm_strex || |
| 5095 | BuiltinID == AArch64::BI__builtin_arm_stlex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5096 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 5097 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 5098 | |
| 5099 | QualType Ty = E->getArg(0)->getType(); |
| 5100 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 5101 | getContext().getTypeSize(Ty)); |
| 5102 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 5103 | |
| 5104 | if (StoreVal->getType()->isPointerTy()) |
| 5105 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int64Ty); |
| 5106 | else { |
| 5107 | StoreVal = Builder.CreateBitCast(StoreVal, StoreTy); |
| 5108 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int64Ty); |
| 5109 | } |
| 5110 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5111 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 5112 | ? Intrinsic::aarch64_stlxr |
| 5113 | : Intrinsic::aarch64_stxr, |
| 5114 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5115 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5118 | if (BuiltinID == AArch64::BI__builtin_arm_clrex) { |
| 5119 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 5120 | return Builder.CreateCall(F); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | // CRC32 |
| 5124 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 5125 | switch (BuiltinID) { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5126 | case AArch64::BI__builtin_arm_crc32b: |
| 5127 | CRCIntrinsicID = Intrinsic::aarch64_crc32b; break; |
| 5128 | case AArch64::BI__builtin_arm_crc32cb: |
| 5129 | CRCIntrinsicID = Intrinsic::aarch64_crc32cb; break; |
| 5130 | case AArch64::BI__builtin_arm_crc32h: |
| 5131 | CRCIntrinsicID = Intrinsic::aarch64_crc32h; break; |
| 5132 | case AArch64::BI__builtin_arm_crc32ch: |
| 5133 | CRCIntrinsicID = Intrinsic::aarch64_crc32ch; break; |
| 5134 | case AArch64::BI__builtin_arm_crc32w: |
| 5135 | CRCIntrinsicID = Intrinsic::aarch64_crc32w; break; |
| 5136 | case AArch64::BI__builtin_arm_crc32cw: |
| 5137 | CRCIntrinsicID = Intrinsic::aarch64_crc32cw; break; |
| 5138 | case AArch64::BI__builtin_arm_crc32d: |
| 5139 | CRCIntrinsicID = Intrinsic::aarch64_crc32x; break; |
| 5140 | case AArch64::BI__builtin_arm_crc32cd: |
| 5141 | CRCIntrinsicID = Intrinsic::aarch64_crc32cx; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 5145 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 5146 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 5147 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
| 5148 | |
| 5149 | llvm::Type *DataTy = F->getFunctionType()->getParamType(1); |
| 5150 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, DataTy); |
| 5151 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5152 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5153 | } |
| 5154 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 5155 | if (BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 5156 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 5157 | BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 5158 | BuiltinID == AArch64::BI__builtin_arm_wsr || |
| 5159 | BuiltinID == AArch64::BI__builtin_arm_wsr64 || |
| 5160 | BuiltinID == AArch64::BI__builtin_arm_wsrp) { |
| 5161 | |
| 5162 | bool IsRead = BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 5163 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 5164 | BuiltinID == AArch64::BI__builtin_arm_rsrp; |
| 5165 | |
| 5166 | bool IsPointerBuiltin = BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 5167 | BuiltinID == AArch64::BI__builtin_arm_wsrp; |
| 5168 | |
| 5169 | bool Is64Bit = BuiltinID != AArch64::BI__builtin_arm_rsr && |
| 5170 | BuiltinID != AArch64::BI__builtin_arm_wsr; |
| 5171 | |
| 5172 | llvm::Type *ValueType; |
| 5173 | llvm::Type *RegisterType = Int64Ty; |
| 5174 | if (IsPointerBuiltin) { |
| 5175 | ValueType = VoidPtrTy; |
| 5176 | } else if (Is64Bit) { |
| 5177 | ValueType = Int64Ty; |
| 5178 | } else { |
| 5179 | ValueType = Int32Ty; |
| 5180 | } |
| 5181 | |
| 5182 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 5183 | } |
| 5184 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 5185 | // Find out if any arguments are required to be integer constant |
| 5186 | // expressions. |
| 5187 | unsigned ICEArguments = 0; |
| 5188 | ASTContext::GetBuiltinTypeError Error; |
| 5189 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 5190 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 5191 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5192 | llvm::SmallVector<Value*, 4> Ops; |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 5193 | for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++) { |
| 5194 | if ((ICEArguments & (1 << i)) == 0) { |
| 5195 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 5196 | } else { |
| 5197 | // If this is required to be a constant, constant fold it so that we know |
| 5198 | // that the generated intrinsic gets a ConstantInt. |
| 5199 | llvm::APSInt Result; |
| 5200 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 5201 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 5202 | (void)IsConst; |
| 5203 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 5204 | } |
| 5205 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5206 | |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 5207 | auto SISDMap = makeArrayRef(AArch64SISDIntrinsicMap); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5208 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5209 | SISDMap, BuiltinID, AArch64SISDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5210 | |
| 5211 | if (Builtin) { |
| 5212 | Ops.push_back(EmitScalarExpr(E->getArg(E->getNumArgs() - 1))); |
| 5213 | Value *Result = EmitCommonNeonSISDBuiltinExpr(*this, *Builtin, Ops, E); |
| 5214 | assert(Result && "SISD intrinsic should have been handled"); |
| 5215 | return Result; |
| 5216 | } |
| 5217 | |
| 5218 | llvm::APSInt Result; |
| 5219 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 5220 | NeonTypeFlags Type(0); |
| 5221 | if (Arg->isIntegerConstantExpr(Result, getContext())) |
| 5222 | // Determine the type of this overloaded NEON intrinsic. |
| 5223 | Type = NeonTypeFlags(Result.getZExtValue()); |
| 5224 | |
| 5225 | bool usgn = Type.isUnsigned(); |
| 5226 | bool quad = Type.isQuad(); |
| 5227 | |
| 5228 | // Handle non-overloaded intrinsics first. |
| 5229 | switch (BuiltinID) { |
| 5230 | default: break; |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 5231 | case NEON::BI__builtin_neon_vldrq_p128: { |
| 5232 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 5233 | Value *Ptr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int128PTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5234 | return Builder.CreateDefaultAlignedLoad(Ptr); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 5235 | } |
| 5236 | case NEON::BI__builtin_neon_vstrq_p128: { |
| 5237 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 5238 | Value *Ptr = Builder.CreateBitCast(Ops[0], Int128PTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5239 | return Builder.CreateDefaultAlignedStore(EmitScalarExpr(E->getArg(1)), Ptr); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 5240 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5241 | case NEON::BI__builtin_neon_vcvts_u32_f32: |
| 5242 | case NEON::BI__builtin_neon_vcvtd_u64_f64: |
| 5243 | usgn = true; |
| 5244 | // FALL THROUGH |
| 5245 | case NEON::BI__builtin_neon_vcvts_s32_f32: |
| 5246 | case NEON::BI__builtin_neon_vcvtd_s64_f64: { |
| 5247 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5248 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 5249 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 5250 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 5251 | Ops[0] = Builder.CreateBitCast(Ops[0], FTy); |
| 5252 | if (usgn) |
| 5253 | return Builder.CreateFPToUI(Ops[0], InTy); |
| 5254 | return Builder.CreateFPToSI(Ops[0], InTy); |
| 5255 | } |
| 5256 | case NEON::BI__builtin_neon_vcvts_f32_u32: |
| 5257 | case NEON::BI__builtin_neon_vcvtd_f64_u64: |
| 5258 | usgn = true; |
| 5259 | // FALL THROUGH |
| 5260 | case NEON::BI__builtin_neon_vcvts_f32_s32: |
| 5261 | case NEON::BI__builtin_neon_vcvtd_f64_s64: { |
| 5262 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5263 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 5264 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 5265 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 5266 | Ops[0] = Builder.CreateBitCast(Ops[0], InTy); |
| 5267 | if (usgn) |
| 5268 | return Builder.CreateUIToFP(Ops[0], FTy); |
| 5269 | return Builder.CreateSIToFP(Ops[0], FTy); |
| 5270 | } |
| 5271 | case NEON::BI__builtin_neon_vpaddd_s64: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5272 | llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5273 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 5274 | // The vector is v2f64, so make sure it's bitcast to that. |
| 5275 | Vec = Builder.CreateBitCast(Vec, Ty, "v2i64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5276 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 5277 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5278 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 5279 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 5280 | // Pairwise addition of a v2f64 into a scalar f64. |
| 5281 | return Builder.CreateAdd(Op0, Op1, "vpaddd"); |
| 5282 | } |
| 5283 | case NEON::BI__builtin_neon_vpaddd_f64: { |
| 5284 | llvm::Type *Ty = |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5285 | llvm::VectorType::get(DoubleTy, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5286 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 5287 | // The vector is v2f64, so make sure it's bitcast to that. |
| 5288 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5289 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 5290 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5291 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 5292 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 5293 | // Pairwise addition of a v2f64 into a scalar f64. |
| 5294 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 5295 | } |
| 5296 | case NEON::BI__builtin_neon_vpadds_f32: { |
| 5297 | llvm::Type *Ty = |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5298 | llvm::VectorType::get(FloatTy, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5299 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 5300 | // The vector is v2f32, so make sure it's bitcast to that. |
| 5301 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f32"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5302 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 5303 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5304 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 5305 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 5306 | // Pairwise addition of a v2f32 into a scalar f32. |
| 5307 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 5308 | } |
| 5309 | case NEON::BI__builtin_neon_vceqzd_s64: |
| 5310 | case NEON::BI__builtin_neon_vceqzd_f64: |
| 5311 | case NEON::BI__builtin_neon_vceqzs_f32: |
| 5312 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5313 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5314 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 5315 | ICmpInst::FCMP_OEQ, ICmpInst::ICMP_EQ, "vceqz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5316 | case NEON::BI__builtin_neon_vcgezd_s64: |
| 5317 | case NEON::BI__builtin_neon_vcgezd_f64: |
| 5318 | case NEON::BI__builtin_neon_vcgezs_f32: |
| 5319 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5320 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5321 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 5322 | ICmpInst::FCMP_OGE, ICmpInst::ICMP_SGE, "vcgez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5323 | case NEON::BI__builtin_neon_vclezd_s64: |
| 5324 | case NEON::BI__builtin_neon_vclezd_f64: |
| 5325 | case NEON::BI__builtin_neon_vclezs_f32: |
| 5326 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5327 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5328 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 5329 | ICmpInst::FCMP_OLE, ICmpInst::ICMP_SLE, "vclez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5330 | case NEON::BI__builtin_neon_vcgtzd_s64: |
| 5331 | case NEON::BI__builtin_neon_vcgtzd_f64: |
| 5332 | case NEON::BI__builtin_neon_vcgtzs_f32: |
| 5333 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5334 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5335 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 5336 | ICmpInst::FCMP_OGT, ICmpInst::ICMP_SGT, "vcgtz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5337 | case NEON::BI__builtin_neon_vcltzd_s64: |
| 5338 | case NEON::BI__builtin_neon_vcltzd_f64: |
| 5339 | case NEON::BI__builtin_neon_vcltzs_f32: |
| 5340 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 5341 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5342 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 5343 | ICmpInst::FCMP_OLT, ICmpInst::ICMP_SLT, "vcltz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5344 | |
| 5345 | case NEON::BI__builtin_neon_vceqzd_u64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5346 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5347 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 5348 | Ops[0] = |
| 5349 | Builder.CreateICmpEQ(Ops[0], llvm::Constant::getNullValue(Int64Ty)); |
| 5350 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqzd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5351 | } |
| 5352 | case NEON::BI__builtin_neon_vceqd_f64: |
| 5353 | case NEON::BI__builtin_neon_vcled_f64: |
| 5354 | case NEON::BI__builtin_neon_vcltd_f64: |
| 5355 | case NEON::BI__builtin_neon_vcged_f64: |
| 5356 | case NEON::BI__builtin_neon_vcgtd_f64: { |
| 5357 | llvm::CmpInst::Predicate P; |
| 5358 | switch (BuiltinID) { |
| 5359 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 5360 | case NEON::BI__builtin_neon_vceqd_f64: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 5361 | case NEON::BI__builtin_neon_vcled_f64: P = llvm::FCmpInst::FCMP_OLE; break; |
| 5362 | case NEON::BI__builtin_neon_vcltd_f64: P = llvm::FCmpInst::FCMP_OLT; break; |
| 5363 | case NEON::BI__builtin_neon_vcged_f64: P = llvm::FCmpInst::FCMP_OGE; break; |
| 5364 | case NEON::BI__builtin_neon_vcgtd_f64: P = llvm::FCmpInst::FCMP_OGT; break; |
| 5365 | } |
| 5366 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 5367 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5368 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 5369 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 5370 | return Builder.CreateSExt(Ops[0], Int64Ty, "vcmpd"); |
| 5371 | } |
| 5372 | case NEON::BI__builtin_neon_vceqs_f32: |
| 5373 | case NEON::BI__builtin_neon_vcles_f32: |
| 5374 | case NEON::BI__builtin_neon_vclts_f32: |
| 5375 | case NEON::BI__builtin_neon_vcges_f32: |
| 5376 | case NEON::BI__builtin_neon_vcgts_f32: { |
| 5377 | llvm::CmpInst::Predicate P; |
| 5378 | switch (BuiltinID) { |
| 5379 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 5380 | case NEON::BI__builtin_neon_vceqs_f32: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 5381 | case NEON::BI__builtin_neon_vcles_f32: P = llvm::FCmpInst::FCMP_OLE; break; |
| 5382 | case NEON::BI__builtin_neon_vclts_f32: P = llvm::FCmpInst::FCMP_OLT; break; |
| 5383 | case NEON::BI__builtin_neon_vcges_f32: P = llvm::FCmpInst::FCMP_OGE; break; |
| 5384 | case NEON::BI__builtin_neon_vcgts_f32: P = llvm::FCmpInst::FCMP_OGT; break; |
| 5385 | } |
| 5386 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 5387 | Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy); |
| 5388 | Ops[1] = Builder.CreateBitCast(Ops[1], FloatTy); |
| 5389 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 5390 | return Builder.CreateSExt(Ops[0], Int32Ty, "vcmpd"); |
| 5391 | } |
| 5392 | case NEON::BI__builtin_neon_vceqd_s64: |
| 5393 | case NEON::BI__builtin_neon_vceqd_u64: |
| 5394 | case NEON::BI__builtin_neon_vcgtd_s64: |
| 5395 | case NEON::BI__builtin_neon_vcgtd_u64: |
| 5396 | case NEON::BI__builtin_neon_vcltd_s64: |
| 5397 | case NEON::BI__builtin_neon_vcltd_u64: |
| 5398 | case NEON::BI__builtin_neon_vcged_u64: |
| 5399 | case NEON::BI__builtin_neon_vcged_s64: |
| 5400 | case NEON::BI__builtin_neon_vcled_u64: |
| 5401 | case NEON::BI__builtin_neon_vcled_s64: { |
| 5402 | llvm::CmpInst::Predicate P; |
| 5403 | switch (BuiltinID) { |
| 5404 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 5405 | case NEON::BI__builtin_neon_vceqd_s64: |
| 5406 | case NEON::BI__builtin_neon_vceqd_u64:P = llvm::ICmpInst::ICMP_EQ;break; |
| 5407 | case NEON::BI__builtin_neon_vcgtd_s64:P = llvm::ICmpInst::ICMP_SGT;break; |
| 5408 | case NEON::BI__builtin_neon_vcgtd_u64:P = llvm::ICmpInst::ICMP_UGT;break; |
| 5409 | case NEON::BI__builtin_neon_vcltd_s64:P = llvm::ICmpInst::ICMP_SLT;break; |
| 5410 | case NEON::BI__builtin_neon_vcltd_u64:P = llvm::ICmpInst::ICMP_ULT;break; |
| 5411 | case NEON::BI__builtin_neon_vcged_u64:P = llvm::ICmpInst::ICMP_UGE;break; |
| 5412 | case NEON::BI__builtin_neon_vcged_s64:P = llvm::ICmpInst::ICMP_SGE;break; |
| 5413 | case NEON::BI__builtin_neon_vcled_u64:P = llvm::ICmpInst::ICMP_ULE;break; |
| 5414 | case NEON::BI__builtin_neon_vcled_s64:P = llvm::ICmpInst::ICMP_SLE;break; |
| 5415 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5416 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5417 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 5418 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5419 | Ops[0] = Builder.CreateICmp(P, Ops[0], Ops[1]); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5420 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5421 | } |
| 5422 | case NEON::BI__builtin_neon_vtstd_s64: |
| 5423 | case NEON::BI__builtin_neon_vtstd_u64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5424 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5425 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 5426 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5427 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 5428 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5429 | llvm::Constant::getNullValue(Int64Ty)); |
| 5430 | return Builder.CreateSExt(Ops[0], Int64Ty, "vtstd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5431 | } |
| 5432 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 5433 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 5434 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 5435 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 5436 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 5437 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 5438 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 5439 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 5440 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 5441 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 5442 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 5443 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 5444 | case NEON::BI__builtin_neon_vset_lane_f64: |
| 5445 | // The vector type needs a cast for the v1f64 variant. |
| 5446 | Ops[1] = Builder.CreateBitCast(Ops[1], |
| 5447 | llvm::VectorType::get(DoubleTy, 1)); |
| 5448 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 5449 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 5450 | case NEON::BI__builtin_neon_vsetq_lane_f64: |
| 5451 | // The vector type needs a cast for the v2f64 variant. |
| 5452 | Ops[1] = Builder.CreateBitCast(Ops[1], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5453 | llvm::VectorType::get(DoubleTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5454 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 5455 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 5456 | |
| 5457 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 5458 | case NEON::BI__builtin_neon_vdupb_lane_i8: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5459 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int8Ty, 8)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5460 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5461 | "vget_lane"); |
| 5462 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 5463 | case NEON::BI__builtin_neon_vdupb_laneq_i8: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5464 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int8Ty, 16)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5465 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5466 | "vgetq_lane"); |
| 5467 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 5468 | case NEON::BI__builtin_neon_vduph_lane_i16: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5469 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int16Ty, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5470 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5471 | "vget_lane"); |
| 5472 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 5473 | case NEON::BI__builtin_neon_vduph_laneq_i16: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5474 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int16Ty, 8)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5475 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5476 | "vgetq_lane"); |
| 5477 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 5478 | case NEON::BI__builtin_neon_vdups_lane_i32: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5479 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5480 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5481 | "vget_lane"); |
| 5482 | case NEON::BI__builtin_neon_vdups_lane_f32: |
| 5483 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5484 | llvm::VectorType::get(FloatTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5485 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5486 | "vdups_lane"); |
| 5487 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 5488 | case NEON::BI__builtin_neon_vdups_laneq_i32: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5489 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5490 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5491 | "vgetq_lane"); |
| 5492 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 5493 | case NEON::BI__builtin_neon_vdupd_lane_i64: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5494 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5495 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5496 | "vget_lane"); |
| 5497 | case NEON::BI__builtin_neon_vdupd_lane_f64: |
| 5498 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5499 | llvm::VectorType::get(DoubleTy, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5500 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5501 | "vdupd_lane"); |
| 5502 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 5503 | case NEON::BI__builtin_neon_vdupd_laneq_i64: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5504 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5505 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5506 | "vgetq_lane"); |
| 5507 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 5508 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5509 | llvm::VectorType::get(FloatTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5510 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5511 | "vget_lane"); |
| 5512 | case NEON::BI__builtin_neon_vget_lane_f64: |
| 5513 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5514 | llvm::VectorType::get(DoubleTy, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5515 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5516 | "vget_lane"); |
| 5517 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 5518 | case NEON::BI__builtin_neon_vdups_laneq_f32: |
| 5519 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5520 | llvm::VectorType::get(FloatTy, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5521 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5522 | "vgetq_lane"); |
| 5523 | case NEON::BI__builtin_neon_vgetq_lane_f64: |
| 5524 | case NEON::BI__builtin_neon_vdupd_laneq_f64: |
| 5525 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5526 | llvm::VectorType::get(DoubleTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5527 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 5528 | "vgetq_lane"); |
| 5529 | case NEON::BI__builtin_neon_vaddd_s64: |
| 5530 | case NEON::BI__builtin_neon_vaddd_u64: |
| 5531 | return Builder.CreateAdd(Ops[0], EmitScalarExpr(E->getArg(1)), "vaddd"); |
| 5532 | case NEON::BI__builtin_neon_vsubd_s64: |
| 5533 | case NEON::BI__builtin_neon_vsubd_u64: |
| 5534 | return Builder.CreateSub(Ops[0], EmitScalarExpr(E->getArg(1)), "vsubd"); |
| 5535 | case NEON::BI__builtin_neon_vqdmlalh_s16: |
| 5536 | case NEON::BI__builtin_neon_vqdmlslh_s16: { |
| 5537 | SmallVector<Value *, 2> ProductOps; |
| 5538 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 5539 | ProductOps.push_back(vectorWrapScalar16(EmitScalarExpr(E->getArg(2)))); |
| 5540 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5541 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5542 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5543 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5544 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 5545 | |
| 5546 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlalh_s16 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5547 | ? Intrinsic::aarch64_neon_sqadd |
| 5548 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5549 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int32Ty), Ops, "vqdmlXl"); |
| 5550 | } |
| 5551 | case NEON::BI__builtin_neon_vqshlud_n_s64: { |
| 5552 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 5553 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5554 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqshlu, Int64Ty), |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 5555 | Ops, "vqshlu_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5556 | } |
| 5557 | case NEON::BI__builtin_neon_vqshld_n_u64: |
| 5558 | case NEON::BI__builtin_neon_vqshld_n_s64: { |
| 5559 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vqshld_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5560 | ? Intrinsic::aarch64_neon_uqshl |
| 5561 | : Intrinsic::aarch64_neon_sqshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5562 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 5563 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 5564 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vqshl_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5565 | } |
| 5566 | case NEON::BI__builtin_neon_vrshrd_n_u64: |
| 5567 | case NEON::BI__builtin_neon_vrshrd_n_s64: { |
| 5568 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5569 | ? Intrinsic::aarch64_neon_urshl |
| 5570 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5571 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 5572 | int SV = cast<ConstantInt>(Ops[1])->getSExtValue(); |
| 5573 | Ops[1] = ConstantInt::get(Int64Ty, -SV); |
| 5574 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vrshr_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5575 | } |
| 5576 | case NEON::BI__builtin_neon_vrsrad_n_u64: |
| 5577 | case NEON::BI__builtin_neon_vrsrad_n_s64: { |
| 5578 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrsrad_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5579 | ? Intrinsic::aarch64_neon_urshl |
| 5580 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5581 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
| 5582 | Ops.push_back(Builder.CreateNeg(EmitScalarExpr(E->getArg(2)))); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5583 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Int64Ty), |
| 5584 | {Ops[1], Builder.CreateSExt(Ops[2], Int64Ty)}); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 5585 | return Builder.CreateAdd(Ops[0], Builder.CreateBitCast(Ops[1], Int64Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5586 | } |
| 5587 | case NEON::BI__builtin_neon_vshld_n_s64: |
| 5588 | case NEON::BI__builtin_neon_vshld_n_u64: { |
| 5589 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 5590 | return Builder.CreateShl( |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5591 | Ops[0], ConstantInt::get(Int64Ty, Amt->getZExtValue()), "shld_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5592 | } |
| 5593 | case NEON::BI__builtin_neon_vshrd_n_s64: { |
| 5594 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 5595 | return Builder.CreateAShr( |
| 5596 | Ops[0], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 5597 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5598 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5599 | } |
| 5600 | case NEON::BI__builtin_neon_vshrd_n_u64: { |
| 5601 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5602 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 5603 | // Right-shifting an unsigned value by its size yields 0. |
| 5604 | if (ShiftAmt == 64) |
| 5605 | return ConstantInt::get(Int64Ty, 0); |
| 5606 | return Builder.CreateLShr(Ops[0], ConstantInt::get(Int64Ty, ShiftAmt), |
| 5607 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5608 | } |
| 5609 | case NEON::BI__builtin_neon_vsrad_n_s64: { |
| 5610 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
| 5611 | Ops[1] = Builder.CreateAShr( |
| 5612 | Ops[1], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 5613 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5614 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5615 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 5616 | } |
| 5617 | case NEON::BI__builtin_neon_vsrad_n_u64: { |
| 5618 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 5619 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 5620 | // Right-shifting an unsigned value by its size yields 0. |
| 5621 | // As Op + 0 = Op, return Ops[0] directly. |
| 5622 | if (ShiftAmt == 64) |
| 5623 | return Ops[0]; |
| 5624 | Ops[1] = Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, ShiftAmt), |
| 5625 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5626 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 5627 | } |
| 5628 | case NEON::BI__builtin_neon_vqdmlalh_lane_s16: |
| 5629 | case NEON::BI__builtin_neon_vqdmlalh_laneq_s16: |
| 5630 | case NEON::BI__builtin_neon_vqdmlslh_lane_s16: |
| 5631 | case NEON::BI__builtin_neon_vqdmlslh_laneq_s16: { |
| 5632 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 5633 | "lane"); |
| 5634 | SmallVector<Value *, 2> ProductOps; |
| 5635 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 5636 | ProductOps.push_back(vectorWrapScalar16(Ops[2])); |
| 5637 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5638 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5639 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5640 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5641 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 5642 | Ops.pop_back(); |
| 5643 | |
| 5644 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlalh_lane_s16 || |
| 5645 | BuiltinID == NEON::BI__builtin_neon_vqdmlalh_laneq_s16) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5646 | ? Intrinsic::aarch64_neon_sqadd |
| 5647 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5648 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int32Ty), Ops, "vqdmlXl"); |
| 5649 | } |
| 5650 | case NEON::BI__builtin_neon_vqdmlals_s32: |
| 5651 | case NEON::BI__builtin_neon_vqdmlsls_s32: { |
| 5652 | SmallVector<Value *, 2> ProductOps; |
| 5653 | ProductOps.push_back(Ops[1]); |
| 5654 | ProductOps.push_back(EmitScalarExpr(E->getArg(2))); |
| 5655 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5656 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5657 | ProductOps, "vqdmlXl"); |
| 5658 | |
| 5659 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlals_s32 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5660 | ? Intrinsic::aarch64_neon_sqadd |
| 5661 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5662 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int64Ty), Ops, "vqdmlXl"); |
| 5663 | } |
| 5664 | case NEON::BI__builtin_neon_vqdmlals_lane_s32: |
| 5665 | case NEON::BI__builtin_neon_vqdmlals_laneq_s32: |
| 5666 | case NEON::BI__builtin_neon_vqdmlsls_lane_s32: |
| 5667 | case NEON::BI__builtin_neon_vqdmlsls_laneq_s32: { |
| 5668 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 5669 | "lane"); |
| 5670 | SmallVector<Value *, 2> ProductOps; |
| 5671 | ProductOps.push_back(Ops[1]); |
| 5672 | ProductOps.push_back(Ops[2]); |
| 5673 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5674 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5675 | ProductOps, "vqdmlXl"); |
| 5676 | Ops.pop_back(); |
| 5677 | |
| 5678 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlals_lane_s32 || |
| 5679 | BuiltinID == NEON::BI__builtin_neon_vqdmlals_laneq_s32) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5680 | ? Intrinsic::aarch64_neon_sqadd |
| 5681 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5682 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int64Ty), Ops, "vqdmlXl"); |
| 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 5687 | llvm::Type *Ty = VTy; |
| 5688 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5689 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5690 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5691 | // 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] | 5692 | // 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] | 5693 | Builtin = findNeonIntrinsicInMap(AArch64SIMDIntrinsicMap, BuiltinID, |
| 5694 | AArch64SIMDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5695 | |
| 5696 | if (Builtin) |
| 5697 | return EmitCommonNeonBuiltinExpr( |
| 5698 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5699 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, |
| 5700 | /*never use addresses*/ Address::invalid(), Address::invalid()); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5701 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5702 | if (Value *V = EmitAArch64TblBuiltinExpr(*this, BuiltinID, E, Ops)) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5703 | return V; |
| 5704 | |
| 5705 | unsigned Int; |
| 5706 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5707 | default: return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5708 | case NEON::BI__builtin_neon_vbsl_v: |
| 5709 | case NEON::BI__builtin_neon_vbslq_v: { |
| 5710 | llvm::Type *BitTy = llvm::VectorType::getInteger(VTy); |
| 5711 | Ops[0] = Builder.CreateBitCast(Ops[0], BitTy, "vbsl"); |
| 5712 | Ops[1] = Builder.CreateBitCast(Ops[1], BitTy, "vbsl"); |
| 5713 | Ops[2] = Builder.CreateBitCast(Ops[2], BitTy, "vbsl"); |
| 5714 | |
| 5715 | Ops[1] = Builder.CreateAnd(Ops[0], Ops[1], "vbsl"); |
| 5716 | Ops[2] = Builder.CreateAnd(Builder.CreateNot(Ops[0]), Ops[2], "vbsl"); |
| 5717 | Ops[0] = Builder.CreateOr(Ops[1], Ops[2], "vbsl"); |
| 5718 | return Builder.CreateBitCast(Ops[0], Ty); |
| 5719 | } |
| 5720 | case NEON::BI__builtin_neon_vfma_lane_v: |
| 5721 | case NEON::BI__builtin_neon_vfmaq_lane_v: { // Only used for FP types |
| 5722 | // The ARM builtins (and instructions) have the addend as the first |
| 5723 | // operand, but the 'fma' intrinsics have it last. Swap it around here. |
| 5724 | Value *Addend = Ops[0]; |
| 5725 | Value *Multiplicand = Ops[1]; |
| 5726 | Value *LaneSource = Ops[2]; |
| 5727 | Ops[0] = Multiplicand; |
| 5728 | Ops[1] = LaneSource; |
| 5729 | Ops[2] = Addend; |
| 5730 | |
| 5731 | // Now adjust things to handle the lane access. |
| 5732 | llvm::Type *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v ? |
| 5733 | llvm::VectorType::get(VTy->getElementType(), VTy->getNumElements() / 2) : |
| 5734 | VTy; |
| 5735 | llvm::Constant *cst = cast<Constant>(Ops[3]); |
| 5736 | Value *SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), cst); |
| 5737 | Ops[1] = Builder.CreateBitCast(Ops[1], SourceTy); |
| 5738 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV, "lane"); |
| 5739 | |
| 5740 | Ops.pop_back(); |
| 5741 | Int = Intrinsic::fma; |
| 5742 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmla"); |
| 5743 | } |
| 5744 | case NEON::BI__builtin_neon_vfma_laneq_v: { |
| 5745 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 5746 | // v1f64 fma should be mapped to Neon scalar f64 fma |
| 5747 | if (VTy && VTy->getElementType() == DoubleTy) { |
| 5748 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 5749 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 5750 | llvm::Type *VTy = GetNeonType(this, |
| 5751 | NeonTypeFlags(NeonTypeFlags::Float64, false, true)); |
| 5752 | Ops[2] = Builder.CreateBitCast(Ops[2], VTy); |
| 5753 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
| 5754 | Value *F = CGM.getIntrinsic(Intrinsic::fma, DoubleTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5755 | Value *Result = Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5756 | return Builder.CreateBitCast(Result, Ty); |
| 5757 | } |
| 5758 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5759 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5760 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5761 | |
| 5762 | llvm::Type *STy = llvm::VectorType::get(VTy->getElementType(), |
| 5763 | VTy->getNumElements() * 2); |
| 5764 | Ops[2] = Builder.CreateBitCast(Ops[2], STy); |
| 5765 | Value* SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), |
| 5766 | cast<ConstantInt>(Ops[3])); |
| 5767 | Ops[2] = Builder.CreateShuffleVector(Ops[2], Ops[2], SV, "lane"); |
| 5768 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5769 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5770 | } |
| 5771 | case NEON::BI__builtin_neon_vfmaq_laneq_v: { |
| 5772 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5773 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5774 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5775 | |
| 5776 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 5777 | Ops[2] = EmitNeonSplat(Ops[2], cast<ConstantInt>(Ops[3])); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5778 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5779 | } |
| 5780 | case NEON::BI__builtin_neon_vfmas_lane_f32: |
| 5781 | case NEON::BI__builtin_neon_vfmas_laneq_f32: |
| 5782 | case NEON::BI__builtin_neon_vfmad_lane_f64: |
| 5783 | case NEON::BI__builtin_neon_vfmad_laneq_f64: { |
| 5784 | Ops.push_back(EmitScalarExpr(E->getArg(3))); |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 5785 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5786 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 5787 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5788 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5789 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5790 | case NEON::BI__builtin_neon_vmull_v: |
| 5791 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5792 | Int = usgn ? Intrinsic::aarch64_neon_umull : Intrinsic::aarch64_neon_smull; |
| 5793 | if (Type.isPoly()) Int = Intrinsic::aarch64_neon_pmull; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5794 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 5795 | case NEON::BI__builtin_neon_vmax_v: |
| 5796 | case NEON::BI__builtin_neon_vmaxq_v: |
| 5797 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5798 | Int = usgn ? Intrinsic::aarch64_neon_umax : Intrinsic::aarch64_neon_smax; |
| 5799 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmax; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5800 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmax"); |
| 5801 | case NEON::BI__builtin_neon_vmin_v: |
| 5802 | case NEON::BI__builtin_neon_vminq_v: |
| 5803 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5804 | Int = usgn ? Intrinsic::aarch64_neon_umin : Intrinsic::aarch64_neon_smin; |
| 5805 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmin; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5806 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmin"); |
| 5807 | case NEON::BI__builtin_neon_vabd_v: |
| 5808 | case NEON::BI__builtin_neon_vabdq_v: |
| 5809 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5810 | Int = usgn ? Intrinsic::aarch64_neon_uabd : Intrinsic::aarch64_neon_sabd; |
| 5811 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fabd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5812 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vabd"); |
| 5813 | case NEON::BI__builtin_neon_vpadal_v: |
| 5814 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 5815 | unsigned ArgElts = VTy->getNumElements(); |
| 5816 | llvm::IntegerType *EltTy = cast<IntegerType>(VTy->getElementType()); |
| 5817 | unsigned BitWidth = EltTy->getBitWidth(); |
| 5818 | llvm::Type *ArgTy = llvm::VectorType::get( |
| 5819 | llvm::IntegerType::get(getLLVMContext(), BitWidth/2), 2*ArgElts); |
| 5820 | llvm::Type* Tys[2] = { VTy, ArgTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5821 | Int = usgn ? Intrinsic::aarch64_neon_uaddlp : Intrinsic::aarch64_neon_saddlp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5822 | SmallVector<llvm::Value*, 1> TmpOps; |
| 5823 | TmpOps.push_back(Ops[1]); |
| 5824 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 5825 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vpadal"); |
| 5826 | llvm::Value *addend = Builder.CreateBitCast(Ops[0], tmp->getType()); |
| 5827 | return Builder.CreateAdd(tmp, addend); |
| 5828 | } |
| 5829 | case NEON::BI__builtin_neon_vpmin_v: |
| 5830 | case NEON::BI__builtin_neon_vpminq_v: |
| 5831 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5832 | Int = usgn ? Intrinsic::aarch64_neon_uminp : Intrinsic::aarch64_neon_sminp; |
| 5833 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fminp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5834 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmin"); |
| 5835 | case NEON::BI__builtin_neon_vpmax_v: |
| 5836 | case NEON::BI__builtin_neon_vpmaxq_v: |
| 5837 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5838 | Int = usgn ? Intrinsic::aarch64_neon_umaxp : Intrinsic::aarch64_neon_smaxp; |
| 5839 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmaxp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5840 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmax"); |
| 5841 | case NEON::BI__builtin_neon_vminnm_v: |
| 5842 | case NEON::BI__builtin_neon_vminnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5843 | Int = Intrinsic::aarch64_neon_fminnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5844 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vminnm"); |
| 5845 | case NEON::BI__builtin_neon_vmaxnm_v: |
| 5846 | case NEON::BI__builtin_neon_vmaxnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5847 | Int = Intrinsic::aarch64_neon_fmaxnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5848 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmaxnm"); |
| 5849 | case NEON::BI__builtin_neon_vrecpss_f32: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5850 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5851 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, FloatTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5852 | Ops, "vrecps"); |
| 5853 | } |
| 5854 | case NEON::BI__builtin_neon_vrecpsd_f64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5855 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 5856 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, DoubleTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5857 | Ops, "vrecps"); |
| 5858 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5859 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5860 | Int = Intrinsic::aarch64_neon_sqshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5861 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrun_n"); |
| 5862 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5863 | Int = Intrinsic::aarch64_neon_sqrshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5864 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrun_n"); |
| 5865 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5866 | Int = usgn ? Intrinsic::aarch64_neon_uqshrn : Intrinsic::aarch64_neon_sqshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5867 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n"); |
| 5868 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5869 | Int = Intrinsic::aarch64_neon_rshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5870 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshrn_n"); |
| 5871 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5872 | Int = usgn ? Intrinsic::aarch64_neon_uqrshrn : Intrinsic::aarch64_neon_sqrshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5873 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n"); |
| 5874 | case NEON::BI__builtin_neon_vrnda_v: |
| 5875 | case NEON::BI__builtin_neon_vrndaq_v: { |
| 5876 | Int = Intrinsic::round; |
| 5877 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnda"); |
| 5878 | } |
| 5879 | case NEON::BI__builtin_neon_vrndi_v: |
| 5880 | case NEON::BI__builtin_neon_vrndiq_v: { |
| 5881 | Int = Intrinsic::nearbyint; |
| 5882 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndi"); |
| 5883 | } |
| 5884 | case NEON::BI__builtin_neon_vrndm_v: |
| 5885 | case NEON::BI__builtin_neon_vrndmq_v: { |
| 5886 | Int = Intrinsic::floor; |
| 5887 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndm"); |
| 5888 | } |
| 5889 | case NEON::BI__builtin_neon_vrndn_v: |
| 5890 | case NEON::BI__builtin_neon_vrndnq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5891 | Int = Intrinsic::aarch64_neon_frintn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5892 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndn"); |
| 5893 | } |
| 5894 | case NEON::BI__builtin_neon_vrndp_v: |
| 5895 | case NEON::BI__builtin_neon_vrndpq_v: { |
| 5896 | Int = Intrinsic::ceil; |
| 5897 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndp"); |
| 5898 | } |
| 5899 | case NEON::BI__builtin_neon_vrndx_v: |
| 5900 | case NEON::BI__builtin_neon_vrndxq_v: { |
| 5901 | Int = Intrinsic::rint; |
| 5902 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndx"); |
| 5903 | } |
| 5904 | case NEON::BI__builtin_neon_vrnd_v: |
| 5905 | case NEON::BI__builtin_neon_vrndq_v: { |
| 5906 | Int = Intrinsic::trunc; |
| 5907 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndz"); |
| 5908 | } |
| 5909 | case NEON::BI__builtin_neon_vceqz_v: |
| 5910 | case NEON::BI__builtin_neon_vceqzq_v: |
| 5911 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OEQ, |
| 5912 | ICmpInst::ICMP_EQ, "vceqz"); |
| 5913 | case NEON::BI__builtin_neon_vcgez_v: |
| 5914 | case NEON::BI__builtin_neon_vcgezq_v: |
| 5915 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGE, |
| 5916 | ICmpInst::ICMP_SGE, "vcgez"); |
| 5917 | case NEON::BI__builtin_neon_vclez_v: |
| 5918 | case NEON::BI__builtin_neon_vclezq_v: |
| 5919 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLE, |
| 5920 | ICmpInst::ICMP_SLE, "vclez"); |
| 5921 | case NEON::BI__builtin_neon_vcgtz_v: |
| 5922 | case NEON::BI__builtin_neon_vcgtzq_v: |
| 5923 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGT, |
| 5924 | ICmpInst::ICMP_SGT, "vcgtz"); |
| 5925 | case NEON::BI__builtin_neon_vcltz_v: |
| 5926 | case NEON::BI__builtin_neon_vcltzq_v: |
| 5927 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLT, |
| 5928 | ICmpInst::ICMP_SLT, "vcltz"); |
| 5929 | case NEON::BI__builtin_neon_vcvt_f64_v: |
| 5930 | case NEON::BI__builtin_neon_vcvtq_f64_v: |
| 5931 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5932 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float64, false, quad)); |
| 5933 | return usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 5934 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 5935 | case NEON::BI__builtin_neon_vcvt_f64_f32: { |
| 5936 | assert(Type.getEltType() == NeonTypeFlags::Float64 && quad && |
| 5937 | "unexpected vcvt_f64_f32 builtin"); |
| 5938 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float32, false, false); |
| 5939 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 5940 | |
| 5941 | return Builder.CreateFPExt(Ops[0], Ty, "vcvt"); |
| 5942 | } |
| 5943 | case NEON::BI__builtin_neon_vcvt_f32_f64: { |
| 5944 | assert(Type.getEltType() == NeonTypeFlags::Float32 && |
| 5945 | "unexpected vcvt_f32_f64 builtin"); |
| 5946 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float64, false, true); |
| 5947 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 5948 | |
| 5949 | return Builder.CreateFPTrunc(Ops[0], Ty, "vcvt"); |
| 5950 | } |
| 5951 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 5952 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 5953 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 5954 | case NEON::BI__builtin_neon_vcvt_u64_v: |
| 5955 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 5956 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 5957 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
| 5958 | case NEON::BI__builtin_neon_vcvtq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5959 | Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5960 | if (usgn) |
| 5961 | return Builder.CreateFPToUI(Ops[0], Ty); |
| 5962 | return Builder.CreateFPToSI(Ops[0], Ty); |
| 5963 | } |
| 5964 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 5965 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 5966 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 5967 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 5968 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 5969 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 5970 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 5971 | case NEON::BI__builtin_neon_vcvtaq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5972 | Int = usgn ? Intrinsic::aarch64_neon_fcvtau : Intrinsic::aarch64_neon_fcvtas; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5973 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5974 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvta"); |
| 5975 | } |
| 5976 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 5977 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 5978 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 5979 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 5980 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 5981 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 5982 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 5983 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5984 | Int = usgn ? Intrinsic::aarch64_neon_fcvtmu : Intrinsic::aarch64_neon_fcvtms; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5985 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5986 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtm"); |
| 5987 | } |
| 5988 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 5989 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 5990 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 5991 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 5992 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 5993 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 5994 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 5995 | case NEON::BI__builtin_neon_vcvtnq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5996 | Int = usgn ? Intrinsic::aarch64_neon_fcvtnu : Intrinsic::aarch64_neon_fcvtns; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 5997 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5998 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtn"); |
| 5999 | } |
| 6000 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 6001 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 6002 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 6003 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 6004 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 6005 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 6006 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 6007 | case NEON::BI__builtin_neon_vcvtpq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6008 | Int = usgn ? Intrinsic::aarch64_neon_fcvtpu : Intrinsic::aarch64_neon_fcvtps; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 6009 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6010 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtp"); |
| 6011 | } |
| 6012 | case NEON::BI__builtin_neon_vmulx_v: |
| 6013 | case NEON::BI__builtin_neon_vmulxq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6014 | Int = Intrinsic::aarch64_neon_fmulx; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6015 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmulx"); |
| 6016 | } |
| 6017 | case NEON::BI__builtin_neon_vmul_lane_v: |
| 6018 | case NEON::BI__builtin_neon_vmul_laneq_v: { |
| 6019 | // v1f64 vmul_lane should be mapped to Neon scalar mul lane |
| 6020 | bool Quad = false; |
| 6021 | if (BuiltinID == NEON::BI__builtin_neon_vmul_laneq_v) |
| 6022 | Quad = true; |
| 6023 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 6024 | llvm::Type *VTy = GetNeonType(this, |
| 6025 | NeonTypeFlags(NeonTypeFlags::Float64, false, Quad)); |
| 6026 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 6027 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2], "extract"); |
| 6028 | Value *Result = Builder.CreateFMul(Ops[0], Ops[1]); |
| 6029 | return Builder.CreateBitCast(Result, Ty); |
| 6030 | } |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 6031 | case NEON::BI__builtin_neon_vnegd_s64: |
| 6032 | return Builder.CreateNeg(EmitScalarExpr(E->getArg(0)), "vnegd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6033 | case NEON::BI__builtin_neon_vpmaxnm_v: |
| 6034 | case NEON::BI__builtin_neon_vpmaxnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6035 | Int = Intrinsic::aarch64_neon_fmaxnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6036 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmaxnm"); |
| 6037 | } |
| 6038 | case NEON::BI__builtin_neon_vpminnm_v: |
| 6039 | case NEON::BI__builtin_neon_vpminnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6040 | Int = Intrinsic::aarch64_neon_fminnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6041 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpminnm"); |
| 6042 | } |
| 6043 | case NEON::BI__builtin_neon_vsqrt_v: |
| 6044 | case NEON::BI__builtin_neon_vsqrtq_v: { |
| 6045 | Int = Intrinsic::sqrt; |
| 6046 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 6047 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqrt"); |
| 6048 | } |
| 6049 | case NEON::BI__builtin_neon_vrbit_v: |
| 6050 | case NEON::BI__builtin_neon_vrbitq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6051 | Int = Intrinsic::aarch64_neon_rbit; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6052 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrbit"); |
| 6053 | } |
| 6054 | case NEON::BI__builtin_neon_vaddv_u8: |
| 6055 | // FIXME: These are handled by the AArch64 scalar code. |
| 6056 | usgn = true; |
| 6057 | // FALLTHROUGH |
| 6058 | case NEON::BI__builtin_neon_vaddv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6059 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6060 | Ty = Int32Ty; |
| 6061 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6062 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6063 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6064 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6065 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6066 | } |
| 6067 | case NEON::BI__builtin_neon_vaddv_u16: |
| 6068 | usgn = true; |
| 6069 | // FALLTHROUGH |
| 6070 | case NEON::BI__builtin_neon_vaddv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6071 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6072 | Ty = Int32Ty; |
| 6073 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6074 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6075 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6076 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6077 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6078 | } |
| 6079 | case NEON::BI__builtin_neon_vaddvq_u8: |
| 6080 | usgn = true; |
| 6081 | // FALLTHROUGH |
| 6082 | case NEON::BI__builtin_neon_vaddvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6083 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6084 | Ty = Int32Ty; |
| 6085 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6086 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6087 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6088 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6089 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6090 | } |
| 6091 | case NEON::BI__builtin_neon_vaddvq_u16: |
| 6092 | usgn = true; |
| 6093 | // FALLTHROUGH |
| 6094 | case NEON::BI__builtin_neon_vaddvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6095 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6096 | Ty = Int32Ty; |
| 6097 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6098 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6099 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6100 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6101 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6102 | } |
| 6103 | case NEON::BI__builtin_neon_vmaxv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6104 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6105 | Ty = Int32Ty; |
| 6106 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6107 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6108 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6109 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6110 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6111 | } |
| 6112 | case NEON::BI__builtin_neon_vmaxv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6113 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6114 | Ty = Int32Ty; |
| 6115 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6116 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6117 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6118 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6119 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6120 | } |
| 6121 | case NEON::BI__builtin_neon_vmaxvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6122 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6123 | Ty = Int32Ty; |
| 6124 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6125 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6126 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6127 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6128 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6129 | } |
| 6130 | case NEON::BI__builtin_neon_vmaxvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6131 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6132 | Ty = Int32Ty; |
| 6133 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6134 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6135 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6136 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6137 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6138 | } |
| 6139 | case NEON::BI__builtin_neon_vmaxv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6140 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6141 | Ty = Int32Ty; |
| 6142 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6143 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6144 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6145 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6146 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6147 | } |
| 6148 | case NEON::BI__builtin_neon_vmaxv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6149 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6150 | Ty = Int32Ty; |
| 6151 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6152 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6153 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6154 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6155 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6156 | } |
| 6157 | case NEON::BI__builtin_neon_vmaxvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6158 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6159 | Ty = Int32Ty; |
| 6160 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6161 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6162 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6163 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6164 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6165 | } |
| 6166 | case NEON::BI__builtin_neon_vmaxvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6167 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6168 | Ty = Int32Ty; |
| 6169 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6170 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6171 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6172 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6173 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6174 | } |
| 6175 | case NEON::BI__builtin_neon_vminv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6176 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6177 | Ty = Int32Ty; |
| 6178 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6179 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6180 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6181 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6182 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6183 | } |
| 6184 | case NEON::BI__builtin_neon_vminv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6185 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6186 | Ty = Int32Ty; |
| 6187 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6188 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6189 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6190 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6191 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6192 | } |
| 6193 | case NEON::BI__builtin_neon_vminvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6194 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6195 | Ty = Int32Ty; |
| 6196 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6197 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6198 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6199 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6200 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6201 | } |
| 6202 | case NEON::BI__builtin_neon_vminvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6203 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6204 | Ty = Int32Ty; |
| 6205 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6206 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6207 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6208 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6209 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6210 | } |
| 6211 | case NEON::BI__builtin_neon_vminv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6212 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6213 | Ty = Int32Ty; |
| 6214 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6215 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6216 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6217 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6218 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6219 | } |
| 6220 | case NEON::BI__builtin_neon_vminv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6221 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6222 | Ty = Int32Ty; |
| 6223 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6224 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6225 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6226 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6227 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6228 | } |
| 6229 | case NEON::BI__builtin_neon_vminvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6230 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6231 | Ty = Int32Ty; |
| 6232 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6233 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6234 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6235 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6236 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6237 | } |
| 6238 | case NEON::BI__builtin_neon_vminvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6239 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6240 | Ty = Int32Ty; |
| 6241 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6242 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6243 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6244 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6245 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6246 | } |
| 6247 | case NEON::BI__builtin_neon_vmul_n_f64: { |
| 6248 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 6249 | Value *RHS = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), DoubleTy); |
| 6250 | return Builder.CreateFMul(Ops[0], RHS); |
| 6251 | } |
| 6252 | case NEON::BI__builtin_neon_vaddlv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6253 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6254 | Ty = Int32Ty; |
| 6255 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6256 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6257 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6258 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6259 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6260 | } |
| 6261 | case NEON::BI__builtin_neon_vaddlv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6262 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6263 | Ty = Int32Ty; |
| 6264 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6265 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6266 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6267 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 6268 | } |
| 6269 | case NEON::BI__builtin_neon_vaddlvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6270 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6271 | Ty = Int32Ty; |
| 6272 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6273 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6274 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6275 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6276 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6277 | } |
| 6278 | case NEON::BI__builtin_neon_vaddlvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6279 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6280 | Ty = Int32Ty; |
| 6281 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6282 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6283 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6284 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 6285 | } |
| 6286 | case NEON::BI__builtin_neon_vaddlv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6287 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6288 | Ty = Int32Ty; |
| 6289 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6290 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6291 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6292 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6293 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6294 | } |
| 6295 | case NEON::BI__builtin_neon_vaddlv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6296 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6297 | Ty = Int32Ty; |
| 6298 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6299 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6300 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6301 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 6302 | } |
| 6303 | case NEON::BI__builtin_neon_vaddlvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6304 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6305 | Ty = Int32Ty; |
| 6306 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6307 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6308 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6309 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6310 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6311 | } |
| 6312 | case NEON::BI__builtin_neon_vaddlvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6313 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6314 | Ty = Int32Ty; |
| 6315 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6316 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6317 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6318 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 6319 | } |
| 6320 | case NEON::BI__builtin_neon_vsri_n_v: |
| 6321 | case NEON::BI__builtin_neon_vsriq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6322 | Int = Intrinsic::aarch64_neon_vsri; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6323 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 6324 | return EmitNeonCall(Intrin, Ops, "vsri_n"); |
| 6325 | } |
| 6326 | case NEON::BI__builtin_neon_vsli_n_v: |
| 6327 | case NEON::BI__builtin_neon_vsliq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6328 | Int = Intrinsic::aarch64_neon_vsli; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6329 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 6330 | return EmitNeonCall(Intrin, Ops, "vsli_n"); |
| 6331 | } |
| 6332 | case NEON::BI__builtin_neon_vsra_n_v: |
| 6333 | case NEON::BI__builtin_neon_vsraq_n_v: |
| 6334 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 6335 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
| 6336 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 6337 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 6338 | case NEON::BI__builtin_neon_vrsraq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6339 | Int = usgn ? Intrinsic::aarch64_neon_urshl : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6340 | SmallVector<llvm::Value*,2> TmpOps; |
| 6341 | TmpOps.push_back(Ops[1]); |
| 6342 | TmpOps.push_back(Ops[2]); |
| 6343 | Function* F = CGM.getIntrinsic(Int, Ty); |
| 6344 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vrshr_n", 1, true); |
| 6345 | Ops[0] = Builder.CreateBitCast(Ops[0], VTy); |
| 6346 | return Builder.CreateAdd(Ops[0], tmp); |
| 6347 | } |
| 6348 | // FIXME: Sharing loads & stores with 32-bit is complicated by the absence |
| 6349 | // of an Align parameter here. |
| 6350 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 6351 | case NEON::BI__builtin_neon_vld1q_x2_v: |
| 6352 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 6353 | case NEON::BI__builtin_neon_vld1q_x3_v: |
| 6354 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 6355 | case NEON::BI__builtin_neon_vld1q_x4_v: { |
| 6356 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 6357 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6358 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 6359 | unsigned Int; |
| 6360 | switch (BuiltinID) { |
| 6361 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 6362 | case NEON::BI__builtin_neon_vld1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6363 | Int = Intrinsic::aarch64_neon_ld1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6364 | break; |
| 6365 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 6366 | case NEON::BI__builtin_neon_vld1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6367 | Int = Intrinsic::aarch64_neon_ld1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6368 | break; |
| 6369 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 6370 | case NEON::BI__builtin_neon_vld1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6371 | Int = Intrinsic::aarch64_neon_ld1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6372 | break; |
| 6373 | } |
| 6374 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 6375 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld1xN"); |
| 6376 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6377 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6378 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6379 | } |
| 6380 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 6381 | case NEON::BI__builtin_neon_vst1q_x2_v: |
| 6382 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 6383 | case NEON::BI__builtin_neon_vst1q_x3_v: |
| 6384 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 6385 | case NEON::BI__builtin_neon_vst1q_x4_v: { |
| 6386 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 6387 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 6388 | unsigned Int; |
| 6389 | switch (BuiltinID) { |
| 6390 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 6391 | case NEON::BI__builtin_neon_vst1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6392 | Int = Intrinsic::aarch64_neon_st1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6393 | break; |
| 6394 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 6395 | case NEON::BI__builtin_neon_vst1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6396 | Int = Intrinsic::aarch64_neon_st1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6397 | break; |
| 6398 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 6399 | case NEON::BI__builtin_neon_vst1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6400 | Int = Intrinsic::aarch64_neon_st1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6401 | break; |
| 6402 | } |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6403 | std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end()); |
| 6404 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, ""); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6405 | } |
| 6406 | case NEON::BI__builtin_neon_vld1_v: |
| 6407 | case NEON::BI__builtin_neon_vld1q_v: |
| 6408 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6409 | return Builder.CreateDefaultAlignedLoad(Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6410 | case NEON::BI__builtin_neon_vst1_v: |
| 6411 | case NEON::BI__builtin_neon_vst1q_v: |
| 6412 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
| 6413 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6414 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6415 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 6416 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 6417 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6418 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6419 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6420 | Ops[0] = Builder.CreateDefaultAlignedLoad(Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6421 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane"); |
| 6422 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 6423 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 6424 | Value *V = UndefValue::get(Ty); |
| 6425 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6426 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6427 | Ops[0] = Builder.CreateDefaultAlignedLoad(Ops[0]); |
Michael J. Spencer | 5ce2668 | 2014-06-02 19:48:59 +0000 | [diff] [blame] | 6428 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6429 | Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI); |
| 6430 | return EmitNeonSplat(Ops[0], CI); |
| 6431 | } |
| 6432 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 6433 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 6434 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6435 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 6436 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6437 | return Builder.CreateDefaultAlignedStore(Ops[1], |
| 6438 | Builder.CreateBitCast(Ops[0], Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6439 | case NEON::BI__builtin_neon_vld2_v: |
| 6440 | case NEON::BI__builtin_neon_vld2q_v: { |
| 6441 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 6442 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6443 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6444 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6445 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 6446 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6447 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6448 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6449 | } |
| 6450 | case NEON::BI__builtin_neon_vld3_v: |
| 6451 | case NEON::BI__builtin_neon_vld3q_v: { |
| 6452 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 6453 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6454 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6455 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6456 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 6457 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6458 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6459 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6460 | } |
| 6461 | case NEON::BI__builtin_neon_vld4_v: |
| 6462 | case NEON::BI__builtin_neon_vld4q_v: { |
| 6463 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 6464 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6465 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6466 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6467 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 6468 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6469 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6470 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6471 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 6472 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 6473 | case NEON::BI__builtin_neon_vld2q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6474 | llvm::Type *PTy = |
| 6475 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6476 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6477 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6478 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6479 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 6480 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6481 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6482 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6483 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 6484 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 6485 | case NEON::BI__builtin_neon_vld3q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6486 | llvm::Type *PTy = |
| 6487 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6488 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6489 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6490 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6491 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 6492 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6493 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6494 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6495 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 6496 | case NEON::BI__builtin_neon_vld4_dup_v: |
| 6497 | case NEON::BI__builtin_neon_vld4q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6498 | llvm::Type *PTy = |
| 6499 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 6500 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 6501 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6502 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6503 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 6504 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 6505 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6506 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6507 | } |
| 6508 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 6509 | case NEON::BI__builtin_neon_vld2q_lane_v: { |
| 6510 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6511 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6512 | Ops.push_back(Ops[1]); |
| 6513 | Ops.erase(Ops.begin()+1); |
| 6514 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6515 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6516 | Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6517 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld2_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6518 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6519 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6520 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6521 | } |
| 6522 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 6523 | case NEON::BI__builtin_neon_vld3q_lane_v: { |
| 6524 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6525 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6526 | Ops.push_back(Ops[1]); |
| 6527 | Ops.erase(Ops.begin()+1); |
| 6528 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6529 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 6530 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6531 | Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6532 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld3_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6533 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6534 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6535 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6536 | } |
| 6537 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 6538 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
| 6539 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6540 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6541 | Ops.push_back(Ops[1]); |
| 6542 | Ops.erase(Ops.begin()+1); |
| 6543 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6544 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 6545 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 6546 | Ops[4] = Builder.CreateBitCast(Ops[4], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6547 | Ops[5] = Builder.CreateZExt(Ops[5], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6548 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld4_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6549 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 6550 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6551 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6552 | } |
| 6553 | case NEON::BI__builtin_neon_vst2_v: |
| 6554 | case NEON::BI__builtin_neon_vst2q_v: { |
| 6555 | Ops.push_back(Ops[0]); |
| 6556 | Ops.erase(Ops.begin()); |
| 6557 | llvm::Type *Tys[2] = { VTy, Ops[2]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6558 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6559 | Ops, ""); |
| 6560 | } |
| 6561 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 6562 | case NEON::BI__builtin_neon_vst2q_lane_v: { |
| 6563 | Ops.push_back(Ops[0]); |
| 6564 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6565 | Ops[2] = Builder.CreateZExt(Ops[2], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6566 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6567 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6568 | Ops, ""); |
| 6569 | } |
| 6570 | case NEON::BI__builtin_neon_vst3_v: |
| 6571 | case NEON::BI__builtin_neon_vst3q_v: { |
| 6572 | Ops.push_back(Ops[0]); |
| 6573 | Ops.erase(Ops.begin()); |
| 6574 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6575 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6576 | Ops, ""); |
| 6577 | } |
| 6578 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 6579 | case NEON::BI__builtin_neon_vst3q_lane_v: { |
| 6580 | Ops.push_back(Ops[0]); |
| 6581 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6582 | Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6583 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6584 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6585 | Ops, ""); |
| 6586 | } |
| 6587 | case NEON::BI__builtin_neon_vst4_v: |
| 6588 | case NEON::BI__builtin_neon_vst4q_v: { |
| 6589 | Ops.push_back(Ops[0]); |
| 6590 | Ops.erase(Ops.begin()); |
| 6591 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6592 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6593 | Ops, ""); |
| 6594 | } |
| 6595 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 6596 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 6597 | Ops.push_back(Ops[0]); |
| 6598 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6599 | Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6600 | llvm::Type *Tys[2] = { VTy, Ops[5]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6601 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6602 | Ops, ""); |
| 6603 | } |
| 6604 | case NEON::BI__builtin_neon_vtrn_v: |
| 6605 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 6606 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 6607 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6608 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6609 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6610 | |
| 6611 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 6612 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6613 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 6614 | Indices.push_back(i+vi); |
| 6615 | Indices.push_back(i+e+vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6616 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 6617 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 6618 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vtrn"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6619 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6620 | } |
| 6621 | return SV; |
| 6622 | } |
| 6623 | case NEON::BI__builtin_neon_vuzp_v: |
| 6624 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 6625 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 6626 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6627 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6628 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6629 | |
| 6630 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 6631 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6632 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 6633 | Indices.push_back(2*i+vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6634 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 6635 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 6636 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vuzp"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6637 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6638 | } |
| 6639 | return SV; |
| 6640 | } |
| 6641 | case NEON::BI__builtin_neon_vzip_v: |
| 6642 | case NEON::BI__builtin_neon_vzipq_v: { |
| 6643 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 6644 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6645 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6646 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6647 | |
| 6648 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 6649 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6650 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 6651 | Indices.push_back((i + vi*e) >> 1); |
| 6652 | Indices.push_back(((i + vi*e) >> 1)+e); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6653 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 6654 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 6655 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vzip"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6656 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6657 | } |
| 6658 | return SV; |
| 6659 | } |
| 6660 | case NEON::BI__builtin_neon_vqtbl1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6661 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6662 | Ops, "vtbl1"); |
| 6663 | } |
| 6664 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6665 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6666 | Ops, "vtbl2"); |
| 6667 | } |
| 6668 | case NEON::BI__builtin_neon_vqtbl3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6669 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6670 | Ops, "vtbl3"); |
| 6671 | } |
| 6672 | case NEON::BI__builtin_neon_vqtbl4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6673 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6674 | Ops, "vtbl4"); |
| 6675 | } |
| 6676 | case NEON::BI__builtin_neon_vqtbx1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6677 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6678 | Ops, "vtbx1"); |
| 6679 | } |
| 6680 | case NEON::BI__builtin_neon_vqtbx2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6681 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6682 | Ops, "vtbx2"); |
| 6683 | } |
| 6684 | case NEON::BI__builtin_neon_vqtbx3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6685 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6686 | Ops, "vtbx3"); |
| 6687 | } |
| 6688 | case NEON::BI__builtin_neon_vqtbx4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6689 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6690 | Ops, "vtbx4"); |
| 6691 | } |
| 6692 | case NEON::BI__builtin_neon_vsqadd_v: |
| 6693 | case NEON::BI__builtin_neon_vsqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6694 | Int = Intrinsic::aarch64_neon_usqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6695 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqadd"); |
| 6696 | } |
| 6697 | case NEON::BI__builtin_neon_vuqadd_v: |
| 6698 | case NEON::BI__builtin_neon_vuqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6699 | Int = Intrinsic::aarch64_neon_suqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6700 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vuqadd"); |
| 6701 | } |
| 6702 | } |
| 6703 | } |
| 6704 | |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6705 | llvm::Value *CodeGenFunction:: |
Bill Wendling | f1a3fca | 2012-02-22 09:30:11 +0000 | [diff] [blame] | 6706 | BuildVector(ArrayRef<llvm::Value*> Ops) { |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6707 | assert((Ops.size() & (Ops.size() - 1)) == 0 && |
| 6708 | "Not a power-of-two sized vector!"); |
| 6709 | bool AllConstants = true; |
| 6710 | for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i) |
| 6711 | AllConstants &= isa<Constant>(Ops[i]); |
| 6712 | |
| 6713 | // If this is a constant vector, create a ConstantVector. |
| 6714 | if (AllConstants) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 6715 | SmallVector<llvm::Constant*, 16> CstOps; |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6716 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
| 6717 | CstOps.push_back(cast<Constant>(Ops[i])); |
| 6718 | return llvm::ConstantVector::get(CstOps); |
| 6719 | } |
| 6720 | |
| 6721 | // Otherwise, insertelement the values to build the vector. |
| 6722 | Value *Result = |
| 6723 | llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size())); |
| 6724 | |
| 6725 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 6726 | Result = Builder.CreateInsertElement(Result, Ops[i], Builder.getInt32(i)); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 6727 | |
| 6728 | return Result; |
| 6729 | } |
| 6730 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6731 | // Convert the mask from an integer type to a vector of i1. |
| 6732 | static Value *getMaskVecValue(CodeGenFunction &CGF, Value *Mask, |
| 6733 | unsigned NumElts) { |
| 6734 | |
| 6735 | llvm::VectorType *MaskTy = llvm::VectorType::get(CGF.Builder.getInt1Ty(), |
| 6736 | cast<IntegerType>(Mask->getType())->getBitWidth()); |
| 6737 | Value *MaskVec = CGF.Builder.CreateBitCast(Mask, MaskTy); |
| 6738 | |
| 6739 | // If we have less than 8 elements, then the starting mask was an i8 and |
| 6740 | // we need to extract down to the right number of elements. |
| 6741 | if (NumElts < 8) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 6742 | uint32_t Indices[4]; |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6743 | for (unsigned i = 0; i != NumElts; ++i) |
| 6744 | Indices[i] = i; |
| 6745 | MaskVec = CGF.Builder.CreateShuffleVector(MaskVec, MaskVec, |
| 6746 | makeArrayRef(Indices, NumElts), |
| 6747 | "extract"); |
| 6748 | } |
| 6749 | return MaskVec; |
| 6750 | } |
| 6751 | |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 6752 | static Value *EmitX86MaskedStore(CodeGenFunction &CGF, |
| 6753 | SmallVectorImpl<Value *> &Ops, |
| 6754 | unsigned Align) { |
| 6755 | // Cast the pointer to right type. |
| 6756 | Ops[0] = CGF.Builder.CreateBitCast(Ops[0], |
| 6757 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 6758 | |
| 6759 | // If the mask is all ones just emit a regular store. |
| 6760 | if (const auto *C = dyn_cast<Constant>(Ops[2])) |
| 6761 | if (C->isAllOnesValue()) |
| 6762 | return CGF.Builder.CreateAlignedStore(Ops[1], Ops[0], Align); |
| 6763 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6764 | Value *MaskVec = getMaskVecValue(CGF, Ops[2], |
| 6765 | Ops[1]->getType()->getVectorNumElements()); |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 6766 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6767 | return CGF.Builder.CreateMaskedStore(Ops[1], Ops[0], Align, MaskVec); |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 6768 | } |
| 6769 | |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 6770 | static Value *EmitX86MaskedLoad(CodeGenFunction &CGF, |
| 6771 | SmallVectorImpl<Value *> &Ops, unsigned Align) { |
| 6772 | // Cast the pointer to right type. |
| 6773 | Ops[0] = CGF.Builder.CreateBitCast(Ops[0], |
| 6774 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 6775 | |
| 6776 | // If the mask is all ones just emit a regular store. |
| 6777 | if (const auto *C = dyn_cast<Constant>(Ops[2])) |
| 6778 | if (C->isAllOnesValue()) |
| 6779 | return CGF.Builder.CreateAlignedLoad(Ops[0], Align); |
| 6780 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6781 | Value *MaskVec = getMaskVecValue(CGF, Ops[2], |
| 6782 | Ops[1]->getType()->getVectorNumElements()); |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 6783 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6784 | return CGF.Builder.CreateMaskedLoad(Ops[0], Align, MaskVec, Ops[1]); |
| 6785 | } |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 6786 | |
Simon Pilgrim | 2d85173 | 2016-07-22 13:58:56 +0000 | [diff] [blame] | 6787 | static Value *EmitX86SubVectorBroadcast(CodeGenFunction &CGF, |
| 6788 | SmallVectorImpl<Value *> &Ops, |
| 6789 | llvm::Type *DstTy, |
| 6790 | unsigned SrcSizeInBits, |
| 6791 | unsigned Align) { |
| 6792 | // Load the subvector. |
| 6793 | Ops[0] = CGF.Builder.CreateAlignedLoad(Ops[0], Align); |
| 6794 | |
| 6795 | // Create broadcast mask. |
| 6796 | unsigned NumDstElts = DstTy->getVectorNumElements(); |
| 6797 | unsigned NumSrcElts = SrcSizeInBits / DstTy->getScalarSizeInBits(); |
| 6798 | |
| 6799 | SmallVector<uint32_t, 8> Mask; |
| 6800 | for (unsigned i = 0; i != NumDstElts; i += NumSrcElts) |
| 6801 | for (unsigned j = 0; j != NumSrcElts; ++j) |
| 6802 | Mask.push_back(j); |
| 6803 | |
| 6804 | return CGF.Builder.CreateShuffleVector(Ops[0], Ops[0], Mask, "subvecbcst"); |
| 6805 | } |
| 6806 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6807 | static Value *EmitX86Select(CodeGenFunction &CGF, |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 6808 | Value *Mask, Value *Op0, Value *Op1) { |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6809 | |
| 6810 | // If the mask is all ones just return first argument. |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 6811 | if (const auto *C = dyn_cast<Constant>(Mask)) |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6812 | if (C->isAllOnesValue()) |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 6813 | return Op0; |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6814 | |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 6815 | Mask = getMaskVecValue(CGF, Mask, Op0->getType()->getVectorNumElements()); |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 6816 | |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 6817 | return CGF.Builder.CreateSelect(Mask, Op0, Op1); |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 6818 | } |
| 6819 | |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 6820 | static Value *EmitX86MaskedCompare(CodeGenFunction &CGF, unsigned CC, |
| 6821 | bool Signed, SmallVectorImpl<Value *> &Ops) { |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 6822 | unsigned NumElts = Ops[0]->getType()->getVectorNumElements(); |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 6823 | Value *Cmp; |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 6824 | |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 6825 | if (CC == 3) { |
| 6826 | Cmp = Constant::getNullValue( |
| 6827 | llvm::VectorType::get(CGF.Builder.getInt1Ty(), NumElts)); |
| 6828 | } else if (CC == 7) { |
| 6829 | Cmp = Constant::getAllOnesValue( |
| 6830 | llvm::VectorType::get(CGF.Builder.getInt1Ty(), NumElts)); |
| 6831 | } else { |
| 6832 | ICmpInst::Predicate Pred; |
| 6833 | switch (CC) { |
| 6834 | default: llvm_unreachable("Unknown condition code"); |
| 6835 | case 0: Pred = ICmpInst::ICMP_EQ; break; |
| 6836 | case 1: Pred = Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; |
| 6837 | case 2: Pred = Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; |
| 6838 | case 4: Pred = ICmpInst::ICMP_NE; break; |
| 6839 | case 5: Pred = Signed ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; |
| 6840 | case 6: Pred = Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; |
| 6841 | } |
| 6842 | Cmp = CGF.Builder.CreateICmp(Pred, Ops[0], Ops[1]); |
| 6843 | } |
| 6844 | |
| 6845 | const auto *C = dyn_cast<Constant>(Ops.back()); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 6846 | if (!C || !C->isAllOnesValue()) |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 6847 | Cmp = CGF.Builder.CreateAnd(Cmp, getMaskVecValue(CGF, Ops.back(), NumElts)); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 6848 | |
| 6849 | if (NumElts < 8) { |
| 6850 | uint32_t Indices[8]; |
| 6851 | for (unsigned i = 0; i != NumElts; ++i) |
| 6852 | Indices[i] = i; |
| 6853 | for (unsigned i = NumElts; i != 8; ++i) |
Craig Topper | ac1823f | 2016-07-04 07:09:46 +0000 | [diff] [blame] | 6854 | Indices[i] = i % NumElts + NumElts; |
Igor Breger | 2c880cf | 2016-06-29 08:14:17 +0000 | [diff] [blame] | 6855 | Cmp = CGF.Builder.CreateShuffleVector( |
| 6856 | Cmp, llvm::Constant::getNullValue(Cmp->getType()), Indices); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 6857 | } |
| 6858 | return CGF.Builder.CreateBitCast(Cmp, |
| 6859 | IntegerType::get(CGF.getLLVMContext(), |
| 6860 | std::max(NumElts, 8U))); |
| 6861 | } |
| 6862 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 6863 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 6864 | const CallExpr *E) { |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 6865 | if (BuiltinID == X86::BI__builtin_ms_va_start || |
| 6866 | BuiltinID == X86::BI__builtin_ms_va_end) |
| 6867 | return EmitVAStartEnd(EmitMSVAListRef(E->getArg(0)).getPointer(), |
| 6868 | BuiltinID == X86::BI__builtin_ms_va_start); |
| 6869 | if (BuiltinID == X86::BI__builtin_ms_va_copy) { |
| 6870 | // Lower this manually. We can't reliably determine whether or not any |
| 6871 | // given va_copy() is for a Win64 va_list from the calling convention |
| 6872 | // alone, because it's legal to do this from a System V ABI function. |
| 6873 | // With opaque pointer types, we won't have enough information in LLVM |
| 6874 | // IR to determine this from the argument types, either. Best to do it |
| 6875 | // now, while we have enough information. |
| 6876 | Address DestAddr = EmitMSVAListRef(E->getArg(0)); |
| 6877 | Address SrcAddr = EmitMSVAListRef(E->getArg(1)); |
| 6878 | |
| 6879 | llvm::Type *BPP = Int8PtrPtrTy; |
| 6880 | |
| 6881 | DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"), |
| 6882 | DestAddr.getAlignment()); |
| 6883 | SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"), |
| 6884 | SrcAddr.getAlignment()); |
| 6885 | |
| 6886 | Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val"); |
| 6887 | return Builder.CreateStore(ArgPtr, DestAddr); |
| 6888 | } |
| 6889 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6890 | SmallVector<Value*, 4> Ops; |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 6891 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 6892 | // Find out if any arguments are required to be integer constant expressions. |
| 6893 | unsigned ICEArguments = 0; |
| 6894 | ASTContext::GetBuiltinTypeError Error; |
| 6895 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 6896 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 6897 | |
| 6898 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { |
| 6899 | // If this is a normal argument, just emit it as a scalar. |
| 6900 | if ((ICEArguments & (1 << i)) == 0) { |
| 6901 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 6902 | continue; |
| 6903 | } |
| 6904 | |
| 6905 | // If this is required to be a constant, constant fold it so that we know |
| 6906 | // that the generated intrinsic gets a ConstantInt. |
| 6907 | llvm::APSInt Result; |
| 6908 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 6909 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 6910 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 6911 | } |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 6912 | |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 6913 | // These exist so that the builtin that takes an immediate can be bounds |
| 6914 | // checked by clang to avoid passing bad immediates to the backend. Since |
| 6915 | // AVX has a larger immediate than SSE we would need separate builtins to |
| 6916 | // do the different bounds checking. Rather than create a clang specific |
| 6917 | // SSE only builtin, this implements eight separate builtins to match gcc |
| 6918 | // implementation. |
| 6919 | auto getCmpIntrinsicCall = [this, &Ops](Intrinsic::ID ID, unsigned Imm) { |
| 6920 | Ops.push_back(llvm::ConstantInt::get(Int8Ty, Imm)); |
| 6921 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 6922 | return Builder.CreateCall(F, Ops); |
| 6923 | }; |
| 6924 | |
| 6925 | // For the vector forms of FP comparisons, translate the builtins directly to |
| 6926 | // IR. |
| 6927 | // TODO: The builtins could be removed if the SSE header files used vector |
| 6928 | // extension comparisons directly (vector ordered/unordered may need |
| 6929 | // additional support via __builtin_isnan()). |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 6930 | auto getVectorFCmpIR = [this, &Ops](CmpInst::Predicate Pred) { |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 6931 | Value *Cmp = Builder.CreateFCmp(Pred, Ops[0], Ops[1]); |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 6932 | llvm::VectorType *FPVecTy = cast<llvm::VectorType>(Ops[0]->getType()); |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 6933 | llvm::VectorType *IntVecTy = llvm::VectorType::getInteger(FPVecTy); |
| 6934 | Value *Sext = Builder.CreateSExt(Cmp, IntVecTy); |
| 6935 | return Builder.CreateBitCast(Sext, FPVecTy); |
| 6936 | }; |
| 6937 | |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 6938 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6939 | default: return nullptr; |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 6940 | case X86::BI__builtin_cpu_supports: { |
| 6941 | const Expr *FeatureExpr = E->getArg(0)->IgnoreParenCasts(); |
| 6942 | StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString(); |
| 6943 | |
| 6944 | // TODO: When/if this becomes more than x86 specific then use a TargetInfo |
| 6945 | // based mapping. |
| 6946 | // Processor features and mapping to processor feature value. |
| 6947 | enum X86Features { |
| 6948 | CMOV = 0, |
| 6949 | MMX, |
| 6950 | POPCNT, |
| 6951 | SSE, |
| 6952 | SSE2, |
| 6953 | SSE3, |
| 6954 | SSSE3, |
| 6955 | SSE4_1, |
| 6956 | SSE4_2, |
| 6957 | AVX, |
| 6958 | AVX2, |
| 6959 | SSE4_A, |
| 6960 | FMA4, |
| 6961 | XOP, |
| 6962 | FMA, |
| 6963 | AVX512F, |
| 6964 | BMI, |
| 6965 | BMI2, |
Benjamin Kramer | f4c520d | 2016-05-20 15:21:08 +0000 | [diff] [blame] | 6966 | AES, |
| 6967 | PCLMUL, |
| 6968 | AVX512VL, |
| 6969 | AVX512BW, |
| 6970 | AVX512DQ, |
| 6971 | AVX512CD, |
| 6972 | AVX512ER, |
| 6973 | AVX512PF, |
| 6974 | AVX512VBMI, |
| 6975 | AVX512IFMA, |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 6976 | MAX |
| 6977 | }; |
| 6978 | |
| 6979 | X86Features Feature = StringSwitch<X86Features>(FeatureStr) |
| 6980 | .Case("cmov", X86Features::CMOV) |
| 6981 | .Case("mmx", X86Features::MMX) |
| 6982 | .Case("popcnt", X86Features::POPCNT) |
| 6983 | .Case("sse", X86Features::SSE) |
| 6984 | .Case("sse2", X86Features::SSE2) |
| 6985 | .Case("sse3", X86Features::SSE3) |
Benjamin Kramer | f4c520d | 2016-05-20 15:21:08 +0000 | [diff] [blame] | 6986 | .Case("ssse3", X86Features::SSSE3) |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 6987 | .Case("sse4.1", X86Features::SSE4_1) |
| 6988 | .Case("sse4.2", X86Features::SSE4_2) |
| 6989 | .Case("avx", X86Features::AVX) |
| 6990 | .Case("avx2", X86Features::AVX2) |
| 6991 | .Case("sse4a", X86Features::SSE4_A) |
| 6992 | .Case("fma4", X86Features::FMA4) |
| 6993 | .Case("xop", X86Features::XOP) |
| 6994 | .Case("fma", X86Features::FMA) |
| 6995 | .Case("avx512f", X86Features::AVX512F) |
| 6996 | .Case("bmi", X86Features::BMI) |
| 6997 | .Case("bmi2", X86Features::BMI2) |
Benjamin Kramer | f4c520d | 2016-05-20 15:21:08 +0000 | [diff] [blame] | 6998 | .Case("aes", X86Features::AES) |
| 6999 | .Case("pclmul", X86Features::PCLMUL) |
| 7000 | .Case("avx512vl", X86Features::AVX512VL) |
| 7001 | .Case("avx512bw", X86Features::AVX512BW) |
| 7002 | .Case("avx512dq", X86Features::AVX512DQ) |
| 7003 | .Case("avx512cd", X86Features::AVX512CD) |
| 7004 | .Case("avx512er", X86Features::AVX512ER) |
| 7005 | .Case("avx512pf", X86Features::AVX512PF) |
| 7006 | .Case("avx512vbmi", X86Features::AVX512VBMI) |
| 7007 | .Case("avx512ifma", X86Features::AVX512IFMA) |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 7008 | .Default(X86Features::MAX); |
| 7009 | assert(Feature != X86Features::MAX && "Invalid feature!"); |
| 7010 | |
| 7011 | // Matching the struct layout from the compiler-rt/libgcc structure that is |
| 7012 | // filled in: |
| 7013 | // unsigned int __cpu_vendor; |
| 7014 | // unsigned int __cpu_type; |
| 7015 | // unsigned int __cpu_subtype; |
| 7016 | // unsigned int __cpu_features[1]; |
| 7017 | llvm::Type *STy = llvm::StructType::get( |
| 7018 | Int32Ty, Int32Ty, Int32Ty, llvm::ArrayType::get(Int32Ty, 1), nullptr); |
| 7019 | |
| 7020 | // Grab the global __cpu_model. |
| 7021 | llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); |
| 7022 | |
| 7023 | // Grab the first (0th) element from the field __cpu_features off of the |
| 7024 | // global in the struct STy. |
| 7025 | Value *Idxs[] = { |
| 7026 | ConstantInt::get(Int32Ty, 0), |
| 7027 | ConstantInt::get(Int32Ty, 3), |
| 7028 | ConstantInt::get(Int32Ty, 0) |
| 7029 | }; |
| 7030 | Value *CpuFeatures = Builder.CreateGEP(STy, CpuModel, Idxs); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7031 | Value *Features = Builder.CreateAlignedLoad(CpuFeatures, |
| 7032 | CharUnits::fromQuantity(4)); |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 7033 | |
| 7034 | // Check the value of the bit corresponding to the feature requested. |
| 7035 | Value *Bitset = Builder.CreateAnd( |
Aaron Ballman | abd466e | 2016-03-30 21:33:34 +0000 | [diff] [blame] | 7036 | Features, llvm::ConstantInt::get(Int32Ty, 1ULL << Feature)); |
Eric Christopher | d983270 | 2015-06-29 21:00:05 +0000 | [diff] [blame] | 7037 | return Builder.CreateICmpNE(Bitset, llvm::ConstantInt::get(Int32Ty, 0)); |
| 7038 | } |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 7039 | case X86::BI_mm_prefetch: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7040 | Value *Address = Ops[0]; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 7041 | Value *RW = ConstantInt::get(Int32Ty, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7042 | Value *Locality = Ops[1]; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 7043 | Value *Data = ConstantInt::get(Int32Ty, 1); |
| 7044 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7045 | return Builder.CreateCall(F, {Address, RW, Locality, Data}); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 7046 | } |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 7047 | case X86::BI_mm_clflush: { |
| 7048 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush), |
| 7049 | Ops[0]); |
| 7050 | } |
| 7051 | case X86::BI_mm_lfence: { |
| 7052 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_lfence)); |
| 7053 | } |
| 7054 | case X86::BI_mm_mfence: { |
| 7055 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_mfence)); |
| 7056 | } |
| 7057 | case X86::BI_mm_sfence: { |
| 7058 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_sfence)); |
| 7059 | } |
| 7060 | case X86::BI_mm_pause: { |
| 7061 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_pause)); |
| 7062 | } |
| 7063 | case X86::BI__rdtsc: { |
| 7064 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_rdtsc)); |
| 7065 | } |
Simon Pilgrim | 5aba992 | 2015-08-26 21:17:12 +0000 | [diff] [blame] | 7066 | case X86::BI__builtin_ia32_undef128: |
| 7067 | case X86::BI__builtin_ia32_undef256: |
| 7068 | case X86::BI__builtin_ia32_undef512: |
| 7069 | return UndefValue::get(ConvertType(E->getType())); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 7070 | case X86::BI__builtin_ia32_vec_init_v8qi: |
| 7071 | case X86::BI__builtin_ia32_vec_init_v4hi: |
| 7072 | case X86::BI__builtin_ia32_vec_init_v2si: |
| 7073 | return Builder.CreateBitCast(BuildVector(Ops), |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 7074 | llvm::Type::getX86_MMXTy(getLLVMContext())); |
Argyrios Kyrtzidis | 073c9cb | 2010-10-10 03:19:11 +0000 | [diff] [blame] | 7075 | case X86::BI__builtin_ia32_vec_ext_v2si: |
| 7076 | return Builder.CreateExtractElement(Ops[0], |
| 7077 | llvm::ConstantInt::get(Ops[1]->getType(), 0)); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 7078 | case X86::BI_mm_setcsr: |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7079 | case X86::BI__builtin_ia32_ldmxcsr: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7080 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7081 | Builder.CreateStore(Ops[0], Tmp); |
| 7082 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7083 | Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7084 | } |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 7085 | case X86::BI_mm_getcsr: |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7086 | case X86::BI__builtin_ia32_stmxcsr: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7087 | Address Tmp = CreateMemTemp(E->getType()); |
Ted Kremenek | c14efa7 | 2011-08-17 21:04:19 +0000 | [diff] [blame] | 7088 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7089 | Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7090 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 7091 | } |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 7092 | case X86::BI__builtin_ia32_xsave: |
| 7093 | case X86::BI__builtin_ia32_xsave64: |
| 7094 | case X86::BI__builtin_ia32_xrstor: |
| 7095 | case X86::BI__builtin_ia32_xrstor64: |
| 7096 | case X86::BI__builtin_ia32_xsaveopt: |
| 7097 | case X86::BI__builtin_ia32_xsaveopt64: |
| 7098 | case X86::BI__builtin_ia32_xrstors: |
| 7099 | case X86::BI__builtin_ia32_xrstors64: |
| 7100 | case X86::BI__builtin_ia32_xsavec: |
| 7101 | case X86::BI__builtin_ia32_xsavec64: |
| 7102 | case X86::BI__builtin_ia32_xsaves: |
Reid Kleckner | 66e7717 | 2016-08-16 16:04:14 +0000 | [diff] [blame] | 7103 | case X86::BI__builtin_ia32_xsaves64: { |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 7104 | Intrinsic::ID ID; |
| 7105 | #define INTRINSIC_X86_XSAVE_ID(NAME) \ |
| 7106 | case X86::BI__builtin_ia32_##NAME: \ |
| 7107 | ID = Intrinsic::x86_##NAME; \ |
| 7108 | break |
| 7109 | switch (BuiltinID) { |
| 7110 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 7111 | INTRINSIC_X86_XSAVE_ID(xsave); |
| 7112 | INTRINSIC_X86_XSAVE_ID(xsave64); |
| 7113 | INTRINSIC_X86_XSAVE_ID(xrstor); |
| 7114 | INTRINSIC_X86_XSAVE_ID(xrstor64); |
| 7115 | INTRINSIC_X86_XSAVE_ID(xsaveopt); |
| 7116 | INTRINSIC_X86_XSAVE_ID(xsaveopt64); |
| 7117 | INTRINSIC_X86_XSAVE_ID(xrstors); |
| 7118 | INTRINSIC_X86_XSAVE_ID(xrstors64); |
| 7119 | INTRINSIC_X86_XSAVE_ID(xsavec); |
| 7120 | INTRINSIC_X86_XSAVE_ID(xsavec64); |
| 7121 | INTRINSIC_X86_XSAVE_ID(xsaves); |
| 7122 | INTRINSIC_X86_XSAVE_ID(xsaves64); |
| 7123 | } |
| 7124 | #undef INTRINSIC_X86_XSAVE_ID |
| 7125 | Value *Mhi = Builder.CreateTrunc( |
| 7126 | Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, 32)), Int32Ty); |
| 7127 | Value *Mlo = Builder.CreateTrunc(Ops[1], Int32Ty); |
| 7128 | Ops[1] = Mhi; |
| 7129 | Ops.push_back(Mlo); |
| 7130 | return Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 7131 | } |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 7132 | case X86::BI__builtin_ia32_storedqudi128_mask: |
| 7133 | case X86::BI__builtin_ia32_storedqusi128_mask: |
| 7134 | case X86::BI__builtin_ia32_storedquhi128_mask: |
| 7135 | case X86::BI__builtin_ia32_storedquqi128_mask: |
| 7136 | case X86::BI__builtin_ia32_storeupd128_mask: |
| 7137 | case X86::BI__builtin_ia32_storeups128_mask: |
| 7138 | case X86::BI__builtin_ia32_storedqudi256_mask: |
| 7139 | case X86::BI__builtin_ia32_storedqusi256_mask: |
| 7140 | case X86::BI__builtin_ia32_storedquhi256_mask: |
| 7141 | case X86::BI__builtin_ia32_storedquqi256_mask: |
| 7142 | case X86::BI__builtin_ia32_storeupd256_mask: |
| 7143 | case X86::BI__builtin_ia32_storeups256_mask: |
| 7144 | case X86::BI__builtin_ia32_storedqudi512_mask: |
| 7145 | case X86::BI__builtin_ia32_storedqusi512_mask: |
| 7146 | case X86::BI__builtin_ia32_storedquhi512_mask: |
| 7147 | case X86::BI__builtin_ia32_storedquqi512_mask: |
| 7148 | case X86::BI__builtin_ia32_storeupd512_mask: |
| 7149 | case X86::BI__builtin_ia32_storeups512_mask: |
| 7150 | return EmitX86MaskedStore(*this, Ops, 1); |
| 7151 | |
| 7152 | case X86::BI__builtin_ia32_movdqa32store128_mask: |
| 7153 | case X86::BI__builtin_ia32_movdqa64store128_mask: |
| 7154 | case X86::BI__builtin_ia32_storeaps128_mask: |
| 7155 | case X86::BI__builtin_ia32_storeapd128_mask: |
| 7156 | case X86::BI__builtin_ia32_movdqa32store256_mask: |
| 7157 | case X86::BI__builtin_ia32_movdqa64store256_mask: |
| 7158 | case X86::BI__builtin_ia32_storeaps256_mask: |
| 7159 | case X86::BI__builtin_ia32_storeapd256_mask: |
| 7160 | case X86::BI__builtin_ia32_movdqa32store512_mask: |
| 7161 | case X86::BI__builtin_ia32_movdqa64store512_mask: |
| 7162 | case X86::BI__builtin_ia32_storeaps512_mask: |
| 7163 | case X86::BI__builtin_ia32_storeapd512_mask: { |
| 7164 | unsigned Align = |
| 7165 | getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity(); |
| 7166 | return EmitX86MaskedStore(*this, Ops, Align); |
| 7167 | } |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 7168 | case X86::BI__builtin_ia32_loadups128_mask: |
| 7169 | case X86::BI__builtin_ia32_loadups256_mask: |
| 7170 | case X86::BI__builtin_ia32_loadups512_mask: |
| 7171 | case X86::BI__builtin_ia32_loadupd128_mask: |
| 7172 | case X86::BI__builtin_ia32_loadupd256_mask: |
| 7173 | case X86::BI__builtin_ia32_loadupd512_mask: |
| 7174 | case X86::BI__builtin_ia32_loaddquqi128_mask: |
| 7175 | case X86::BI__builtin_ia32_loaddquqi256_mask: |
| 7176 | case X86::BI__builtin_ia32_loaddquqi512_mask: |
| 7177 | case X86::BI__builtin_ia32_loaddquhi128_mask: |
| 7178 | case X86::BI__builtin_ia32_loaddquhi256_mask: |
| 7179 | case X86::BI__builtin_ia32_loaddquhi512_mask: |
| 7180 | case X86::BI__builtin_ia32_loaddqusi128_mask: |
| 7181 | case X86::BI__builtin_ia32_loaddqusi256_mask: |
| 7182 | case X86::BI__builtin_ia32_loaddqusi512_mask: |
| 7183 | case X86::BI__builtin_ia32_loaddqudi128_mask: |
| 7184 | case X86::BI__builtin_ia32_loaddqudi256_mask: |
| 7185 | case X86::BI__builtin_ia32_loaddqudi512_mask: |
| 7186 | return EmitX86MaskedLoad(*this, Ops, 1); |
| 7187 | |
| 7188 | case X86::BI__builtin_ia32_loadaps128_mask: |
| 7189 | case X86::BI__builtin_ia32_loadaps256_mask: |
| 7190 | case X86::BI__builtin_ia32_loadaps512_mask: |
| 7191 | case X86::BI__builtin_ia32_loadapd128_mask: |
| 7192 | case X86::BI__builtin_ia32_loadapd256_mask: |
| 7193 | case X86::BI__builtin_ia32_loadapd512_mask: |
| 7194 | case X86::BI__builtin_ia32_movdqa32load128_mask: |
| 7195 | case X86::BI__builtin_ia32_movdqa32load256_mask: |
| 7196 | case X86::BI__builtin_ia32_movdqa32load512_mask: |
| 7197 | case X86::BI__builtin_ia32_movdqa64load128_mask: |
| 7198 | case X86::BI__builtin_ia32_movdqa64load256_mask: |
| 7199 | case X86::BI__builtin_ia32_movdqa64load512_mask: { |
| 7200 | unsigned Align = |
| 7201 | getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity(); |
| 7202 | return EmitX86MaskedLoad(*this, Ops, Align); |
| 7203 | } |
Simon Pilgrim | 2d85173 | 2016-07-22 13:58:56 +0000 | [diff] [blame] | 7204 | |
| 7205 | case X86::BI__builtin_ia32_vbroadcastf128_pd256: |
| 7206 | case X86::BI__builtin_ia32_vbroadcastf128_ps256: { |
| 7207 | llvm::Type *DstTy = ConvertType(E->getType()); |
Chandler Carruth | 4c5e8cc | 2016-08-10 07:32:47 +0000 | [diff] [blame] | 7208 | return EmitX86SubVectorBroadcast(*this, Ops, DstTy, 128, 1); |
Simon Pilgrim | 2d85173 | 2016-07-22 13:58:56 +0000 | [diff] [blame] | 7209 | } |
| 7210 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7211 | case X86::BI__builtin_ia32_storehps: |
| 7212 | case X86::BI__builtin_ia32_storelps: { |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 7213 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(Int64Ty); |
| 7214 | llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7215 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7216 | // cast val v2i64 |
| 7217 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7218 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7219 | // extract (0, 1) |
| 7220 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 7221 | llvm::Value *Idx = llvm::ConstantInt::get(SizeTy, Index); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7222 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 7223 | |
| 7224 | // cast pointer to i64 & store |
| 7225 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7226 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 7227 | } |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7228 | case X86::BI__builtin_ia32_palignr128: |
Craig Topper | f51cc07 | 2016-06-06 06:13:01 +0000 | [diff] [blame] | 7229 | case X86::BI__builtin_ia32_palignr256: |
| 7230 | case X86::BI__builtin_ia32_palignr128_mask: |
| 7231 | case X86::BI__builtin_ia32_palignr256_mask: |
| 7232 | case X86::BI__builtin_ia32_palignr512_mask: { |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7233 | unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 7234 | |
Craig Topper | f2f1a09 | 2016-07-08 02:17:35 +0000 | [diff] [blame] | 7235 | unsigned NumElts = Ops[0]->getType()->getVectorNumElements(); |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7236 | assert(NumElts % 16 == 0); |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7237 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7238 | // If palignr is shifting the pair of vectors more than the size of two |
| 7239 | // lanes, emit zero. |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 7240 | if (ShiftVal >= 32) |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7241 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 7242 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 7243 | // 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] | 7244 | // but less than two lanes, convert to shifting in zeroes. |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 7245 | if (ShiftVal > 16) { |
| 7246 | ShiftVal -= 16; |
Benjamin Kramer | b596056 | 2015-07-20 15:31:17 +0000 | [diff] [blame] | 7247 | Ops[1] = Ops[0]; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 7248 | Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType()); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 7249 | } |
| 7250 | |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 7251 | uint32_t Indices[64]; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 7252 | // 256-bit palignr operates on 128-bit lanes so we need to handle that |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 7253 | for (unsigned l = 0; l != NumElts; l += 16) { |
| 7254 | for (unsigned i = 0; i != 16; ++i) { |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 7255 | unsigned Idx = ShiftVal + i; |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 7256 | if (Idx >= 16) |
| 7257 | Idx += NumElts - 16; // End of lane, switch operand. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7258 | Indices[l + i] = Idx + l; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 7259 | } |
| 7260 | } |
| 7261 | |
Craig Topper | f51cc07 | 2016-06-06 06:13:01 +0000 | [diff] [blame] | 7262 | Value *Align = Builder.CreateShuffleVector(Ops[1], Ops[0], |
| 7263 | makeArrayRef(Indices, NumElts), |
| 7264 | "palignr"); |
| 7265 | |
| 7266 | // If this isn't a masked builtin, just return the align operation. |
| 7267 | if (Ops.size() == 3) |
| 7268 | return Align; |
| 7269 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 7270 | return EmitX86Select(*this, Ops[4], Align, Ops[3]); |
| 7271 | } |
| 7272 | |
| 7273 | case X86::BI__builtin_ia32_movnti: |
| 7274 | case X86::BI__builtin_ia32_movnti64: { |
| 7275 | llvm::MDNode *Node = llvm::MDNode::get( |
Duncan P. N. Exon Smith | fb49491 | 2014-12-09 18:39:32 +0000 | [diff] [blame] | 7276 | getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1))); |
Bill Wendling | 5f9150b | 2011-05-04 02:40:38 +0000 | [diff] [blame] | 7277 | |
| 7278 | // Convert the type of the pointer to a pointer to the stored type. |
| 7279 | Value *BC = Builder.CreateBitCast(Ops[0], |
| 7280 | llvm::PointerType::getUnqual(Ops[1]->getType()), |
| 7281 | "cast"); |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 7282 | StoreInst *SI = Builder.CreateDefaultAlignedStore(Ops[1], BC); |
| 7283 | SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); |
| 7284 | |
| 7285 | // No alignment for scalar intrinsic store. |
| 7286 | SI->setAlignment(1); |
| 7287 | return SI; |
| 7288 | } |
Simon Pilgrim | d39d026 | 2016-06-17 14:28:16 +0000 | [diff] [blame] | 7289 | case X86::BI__builtin_ia32_movntsd: |
| 7290 | case X86::BI__builtin_ia32_movntss: { |
| 7291 | llvm::MDNode *Node = llvm::MDNode::get( |
| 7292 | getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1))); |
| 7293 | |
| 7294 | // Extract the 0'th element of the source vector. |
| 7295 | Value *Scl = Builder.CreateExtractElement(Ops[1], (uint64_t)0, "extract"); |
| 7296 | |
| 7297 | // Convert the type of the pointer to a pointer to the stored type. |
| 7298 | Value *BC = Builder.CreateBitCast(Ops[0], |
| 7299 | llvm::PointerType::getUnqual(Scl->getType()), |
| 7300 | "cast"); |
| 7301 | |
| 7302 | // Unaligned nontemporal store of the scalar value. |
| 7303 | StoreInst *SI = Builder.CreateDefaultAlignedStore(Scl, BC); |
| 7304 | SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); |
| 7305 | SI->setAlignment(1); |
| 7306 | return SI; |
| 7307 | } |
| 7308 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 7309 | case X86::BI__builtin_ia32_selectb_128: |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7310 | case X86::BI__builtin_ia32_selectb_256: |
| 7311 | case X86::BI__builtin_ia32_selectb_512: |
| 7312 | case X86::BI__builtin_ia32_selectw_128: |
| 7313 | case X86::BI__builtin_ia32_selectw_256: |
| 7314 | case X86::BI__builtin_ia32_selectw_512: |
| 7315 | case X86::BI__builtin_ia32_selectd_128: |
| 7316 | case X86::BI__builtin_ia32_selectd_256: |
| 7317 | case X86::BI__builtin_ia32_selectd_512: |
| 7318 | case X86::BI__builtin_ia32_selectq_128: |
| 7319 | case X86::BI__builtin_ia32_selectq_256: |
| 7320 | case X86::BI__builtin_ia32_selectq_512: |
| 7321 | case X86::BI__builtin_ia32_selectps_128: |
| 7322 | case X86::BI__builtin_ia32_selectps_256: |
| 7323 | case X86::BI__builtin_ia32_selectps_512: |
| 7324 | case X86::BI__builtin_ia32_selectpd_128: |
| 7325 | case X86::BI__builtin_ia32_selectpd_256: |
| 7326 | case X86::BI__builtin_ia32_selectpd_512: |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 7327 | return EmitX86Select(*this, Ops[0], Ops[1], Ops[2]); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7328 | case X86::BI__builtin_ia32_pcmpeqb128_mask: |
| 7329 | case X86::BI__builtin_ia32_pcmpeqb256_mask: |
| 7330 | case X86::BI__builtin_ia32_pcmpeqb512_mask: |
| 7331 | case X86::BI__builtin_ia32_pcmpeqw128_mask: |
| 7332 | case X86::BI__builtin_ia32_pcmpeqw256_mask: |
| 7333 | case X86::BI__builtin_ia32_pcmpeqw512_mask: |
| 7334 | case X86::BI__builtin_ia32_pcmpeqd128_mask: |
| 7335 | case X86::BI__builtin_ia32_pcmpeqd256_mask: |
| 7336 | case X86::BI__builtin_ia32_pcmpeqd512_mask: |
| 7337 | case X86::BI__builtin_ia32_pcmpeqq128_mask: |
| 7338 | case X86::BI__builtin_ia32_pcmpeqq256_mask: |
| 7339 | case X86::BI__builtin_ia32_pcmpeqq512_mask: |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 7340 | return EmitX86MaskedCompare(*this, 0, false, Ops); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7341 | case X86::BI__builtin_ia32_pcmpgtb128_mask: |
| 7342 | case X86::BI__builtin_ia32_pcmpgtb256_mask: |
| 7343 | case X86::BI__builtin_ia32_pcmpgtb512_mask: |
| 7344 | case X86::BI__builtin_ia32_pcmpgtw128_mask: |
| 7345 | case X86::BI__builtin_ia32_pcmpgtw256_mask: |
| 7346 | case X86::BI__builtin_ia32_pcmpgtw512_mask: |
| 7347 | case X86::BI__builtin_ia32_pcmpgtd128_mask: |
| 7348 | case X86::BI__builtin_ia32_pcmpgtd256_mask: |
| 7349 | case X86::BI__builtin_ia32_pcmpgtd512_mask: |
| 7350 | case X86::BI__builtin_ia32_pcmpgtq128_mask: |
| 7351 | case X86::BI__builtin_ia32_pcmpgtq256_mask: |
| 7352 | case X86::BI__builtin_ia32_pcmpgtq512_mask: |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 7353 | return EmitX86MaskedCompare(*this, 6, true, Ops); |
| 7354 | case X86::BI__builtin_ia32_cmpb128_mask: |
| 7355 | case X86::BI__builtin_ia32_cmpb256_mask: |
| 7356 | case X86::BI__builtin_ia32_cmpb512_mask: |
| 7357 | case X86::BI__builtin_ia32_cmpw128_mask: |
| 7358 | case X86::BI__builtin_ia32_cmpw256_mask: |
| 7359 | case X86::BI__builtin_ia32_cmpw512_mask: |
| 7360 | case X86::BI__builtin_ia32_cmpd128_mask: |
| 7361 | case X86::BI__builtin_ia32_cmpd256_mask: |
| 7362 | case X86::BI__builtin_ia32_cmpd512_mask: |
| 7363 | case X86::BI__builtin_ia32_cmpq128_mask: |
| 7364 | case X86::BI__builtin_ia32_cmpq256_mask: |
| 7365 | case X86::BI__builtin_ia32_cmpq512_mask: { |
| 7366 | unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7; |
| 7367 | return EmitX86MaskedCompare(*this, CC, true, Ops); |
| 7368 | } |
| 7369 | case X86::BI__builtin_ia32_ucmpb128_mask: |
| 7370 | case X86::BI__builtin_ia32_ucmpb256_mask: |
| 7371 | case X86::BI__builtin_ia32_ucmpb512_mask: |
| 7372 | case X86::BI__builtin_ia32_ucmpw128_mask: |
| 7373 | case X86::BI__builtin_ia32_ucmpw256_mask: |
| 7374 | case X86::BI__builtin_ia32_ucmpw512_mask: |
| 7375 | case X86::BI__builtin_ia32_ucmpd128_mask: |
| 7376 | case X86::BI__builtin_ia32_ucmpd256_mask: |
| 7377 | case X86::BI__builtin_ia32_ucmpd512_mask: |
| 7378 | case X86::BI__builtin_ia32_ucmpq128_mask: |
| 7379 | case X86::BI__builtin_ia32_ucmpq256_mask: |
| 7380 | case X86::BI__builtin_ia32_ucmpq512_mask: { |
| 7381 | unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7; |
| 7382 | return EmitX86MaskedCompare(*this, CC, false, Ops); |
| 7383 | } |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 7384 | |
Craig Topper | 46e7555 | 2016-07-06 04:24:29 +0000 | [diff] [blame] | 7385 | case X86::BI__builtin_ia32_vplzcntd_128_mask: |
| 7386 | case X86::BI__builtin_ia32_vplzcntd_256_mask: |
| 7387 | case X86::BI__builtin_ia32_vplzcntd_512_mask: |
| 7388 | case X86::BI__builtin_ia32_vplzcntq_128_mask: |
| 7389 | case X86::BI__builtin_ia32_vplzcntq_256_mask: |
| 7390 | case X86::BI__builtin_ia32_vplzcntq_512_mask: { |
| 7391 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, Ops[0]->getType()); |
| 7392 | return EmitX86Select(*this, Ops[2], |
| 7393 | Builder.CreateCall(F, {Ops[0],Builder.getInt1(false)}), |
| 7394 | Ops[1]); |
| 7395 | } |
| 7396 | |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 7397 | // TODO: Handle 64/512-bit vector widths of min/max. |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 7398 | case X86::BI__builtin_ia32_pmaxsb128: |
| 7399 | case X86::BI__builtin_ia32_pmaxsw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 7400 | case X86::BI__builtin_ia32_pmaxsd128: |
| 7401 | case X86::BI__builtin_ia32_pmaxsb256: |
| 7402 | case X86::BI__builtin_ia32_pmaxsw256: |
| 7403 | case X86::BI__builtin_ia32_pmaxsd256: { |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 7404 | Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_SGT, Ops[0], Ops[1]); |
| 7405 | return Builder.CreateSelect(Cmp, Ops[0], Ops[1]); |
| 7406 | } |
| 7407 | case X86::BI__builtin_ia32_pmaxub128: |
| 7408 | case X86::BI__builtin_ia32_pmaxuw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 7409 | case X86::BI__builtin_ia32_pmaxud128: |
| 7410 | case X86::BI__builtin_ia32_pmaxub256: |
| 7411 | case X86::BI__builtin_ia32_pmaxuw256: |
| 7412 | case X86::BI__builtin_ia32_pmaxud256: { |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 7413 | Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_UGT, Ops[0], Ops[1]); |
| 7414 | return Builder.CreateSelect(Cmp, Ops[0], Ops[1]); |
| 7415 | } |
| 7416 | case X86::BI__builtin_ia32_pminsb128: |
| 7417 | case X86::BI__builtin_ia32_pminsw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 7418 | case X86::BI__builtin_ia32_pminsd128: |
| 7419 | case X86::BI__builtin_ia32_pminsb256: |
| 7420 | case X86::BI__builtin_ia32_pminsw256: |
| 7421 | case X86::BI__builtin_ia32_pminsd256: { |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 7422 | Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_SLT, Ops[0], Ops[1]); |
| 7423 | return Builder.CreateSelect(Cmp, Ops[0], Ops[1]); |
| 7424 | } |
| 7425 | case X86::BI__builtin_ia32_pminub128: |
| 7426 | case X86::BI__builtin_ia32_pminuw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 7427 | case X86::BI__builtin_ia32_pminud128: |
| 7428 | case X86::BI__builtin_ia32_pminub256: |
| 7429 | case X86::BI__builtin_ia32_pminuw256: |
| 7430 | case X86::BI__builtin_ia32_pminud256: { |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 7431 | Value *Cmp = Builder.CreateICmp(ICmpInst::ICMP_ULT, Ops[0], Ops[1]); |
| 7432 | return Builder.CreateSelect(Cmp, Ops[0], Ops[1]); |
| 7433 | } |
| 7434 | |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 7435 | // 3DNow! |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 7436 | case X86::BI__builtin_ia32_pswapdsf: |
| 7437 | case X86::BI__builtin_ia32_pswapdsi: { |
Chandler Carruth | a2a5410 | 2012-02-20 07:35:45 +0000 | [diff] [blame] | 7438 | llvm::Type *MMXTy = llvm::Type::getX86_MMXTy(getLLVMContext()); |
| 7439 | Ops[0] = Builder.CreateBitCast(Ops[0], MMXTy, "cast"); |
Craig Topper | d2f814d | 2015-02-16 21:30:08 +0000 | [diff] [blame] | 7440 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_3dnowa_pswapd); |
| 7441 | return Builder.CreateCall(F, Ops, "pswapd"); |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 7442 | } |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 7443 | case X86::BI__builtin_ia32_rdrand16_step: |
| 7444 | case X86::BI__builtin_ia32_rdrand32_step: |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 7445 | case X86::BI__builtin_ia32_rdrand64_step: |
| 7446 | case X86::BI__builtin_ia32_rdseed16_step: |
| 7447 | case X86::BI__builtin_ia32_rdseed32_step: |
| 7448 | case X86::BI__builtin_ia32_rdseed64_step: { |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 7449 | Intrinsic::ID ID; |
| 7450 | switch (BuiltinID) { |
| 7451 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 7452 | case X86::BI__builtin_ia32_rdrand16_step: |
| 7453 | ID = Intrinsic::x86_rdrand_16; |
| 7454 | break; |
| 7455 | case X86::BI__builtin_ia32_rdrand32_step: |
| 7456 | ID = Intrinsic::x86_rdrand_32; |
| 7457 | break; |
| 7458 | case X86::BI__builtin_ia32_rdrand64_step: |
| 7459 | ID = Intrinsic::x86_rdrand_64; |
| 7460 | break; |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 7461 | case X86::BI__builtin_ia32_rdseed16_step: |
| 7462 | ID = Intrinsic::x86_rdseed_16; |
| 7463 | break; |
| 7464 | case X86::BI__builtin_ia32_rdseed32_step: |
| 7465 | ID = Intrinsic::x86_rdseed_32; |
| 7466 | break; |
| 7467 | case X86::BI__builtin_ia32_rdseed64_step: |
| 7468 | ID = Intrinsic::x86_rdseed_64; |
| 7469 | break; |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 7470 | } |
| 7471 | |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 7472 | Value *Call = Builder.CreateCall(CGM.getIntrinsic(ID)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7473 | Builder.CreateDefaultAlignedStore(Builder.CreateExtractValue(Call, 0), |
| 7474 | Ops[0]); |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 7475 | return Builder.CreateExtractValue(Call, 1); |
| 7476 | } |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7477 | |
| 7478 | // SSE packed comparison intrinsics |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7479 | case X86::BI__builtin_ia32_cmpeqps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7480 | case X86::BI__builtin_ia32_cmpeqpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7481 | return getVectorFCmpIR(CmpInst::FCMP_OEQ); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7482 | case X86::BI__builtin_ia32_cmpltps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7483 | case X86::BI__builtin_ia32_cmpltpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7484 | return getVectorFCmpIR(CmpInst::FCMP_OLT); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7485 | case X86::BI__builtin_ia32_cmpleps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7486 | case X86::BI__builtin_ia32_cmplepd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7487 | return getVectorFCmpIR(CmpInst::FCMP_OLE); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7488 | case X86::BI__builtin_ia32_cmpunordps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7489 | case X86::BI__builtin_ia32_cmpunordpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7490 | return getVectorFCmpIR(CmpInst::FCMP_UNO); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7491 | case X86::BI__builtin_ia32_cmpneqps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7492 | case X86::BI__builtin_ia32_cmpneqpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7493 | return getVectorFCmpIR(CmpInst::FCMP_UNE); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7494 | case X86::BI__builtin_ia32_cmpnltps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7495 | case X86::BI__builtin_ia32_cmpnltpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7496 | return getVectorFCmpIR(CmpInst::FCMP_UGE); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7497 | case X86::BI__builtin_ia32_cmpnleps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7498 | case X86::BI__builtin_ia32_cmpnlepd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7499 | return getVectorFCmpIR(CmpInst::FCMP_UGT); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 7500 | case X86::BI__builtin_ia32_cmpordps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7501 | case X86::BI__builtin_ia32_cmpordpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7502 | return getVectorFCmpIR(CmpInst::FCMP_ORD); |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 7503 | case X86::BI__builtin_ia32_cmpps: |
| 7504 | case X86::BI__builtin_ia32_cmpps256: |
| 7505 | case X86::BI__builtin_ia32_cmppd: |
| 7506 | case X86::BI__builtin_ia32_cmppd256: { |
| 7507 | unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
| 7508 | // If this one of the SSE immediates, we can use native IR. |
| 7509 | if (CC < 8) { |
| 7510 | FCmpInst::Predicate Pred; |
| 7511 | switch (CC) { |
| 7512 | case 0: Pred = FCmpInst::FCMP_OEQ; break; |
| 7513 | case 1: Pred = FCmpInst::FCMP_OLT; break; |
| 7514 | case 2: Pred = FCmpInst::FCMP_OLE; break; |
| 7515 | case 3: Pred = FCmpInst::FCMP_UNO; break; |
| 7516 | case 4: Pred = FCmpInst::FCMP_UNE; break; |
| 7517 | case 5: Pred = FCmpInst::FCMP_UGE; break; |
| 7518 | case 6: Pred = FCmpInst::FCMP_UGT; break; |
| 7519 | case 7: Pred = FCmpInst::FCMP_ORD; break; |
| 7520 | } |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 7521 | return getVectorFCmpIR(Pred); |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | // We can't handle 8-31 immediates with native IR, use the intrinsic. |
| 7525 | Intrinsic::ID ID; |
| 7526 | switch (BuiltinID) { |
| 7527 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 7528 | case X86::BI__builtin_ia32_cmpps: |
| 7529 | ID = Intrinsic::x86_sse_cmp_ps; |
| 7530 | break; |
| 7531 | case X86::BI__builtin_ia32_cmpps256: |
| 7532 | ID = Intrinsic::x86_avx_cmp_ps_256; |
| 7533 | break; |
| 7534 | case X86::BI__builtin_ia32_cmppd: |
| 7535 | ID = Intrinsic::x86_sse2_cmp_pd; |
| 7536 | break; |
| 7537 | case X86::BI__builtin_ia32_cmppd256: |
| 7538 | ID = Intrinsic::x86_avx_cmp_pd_256; |
| 7539 | break; |
| 7540 | } |
| 7541 | |
| 7542 | return Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 7543 | } |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7544 | |
| 7545 | // SSE scalar comparison intrinsics |
| 7546 | case X86::BI__builtin_ia32_cmpeqss: |
| 7547 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 0); |
| 7548 | case X86::BI__builtin_ia32_cmpltss: |
| 7549 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 1); |
| 7550 | case X86::BI__builtin_ia32_cmpless: |
| 7551 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 2); |
| 7552 | case X86::BI__builtin_ia32_cmpunordss: |
| 7553 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 3); |
| 7554 | case X86::BI__builtin_ia32_cmpneqss: |
| 7555 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 4); |
| 7556 | case X86::BI__builtin_ia32_cmpnltss: |
| 7557 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 5); |
| 7558 | case X86::BI__builtin_ia32_cmpnless: |
| 7559 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 6); |
| 7560 | case X86::BI__builtin_ia32_cmpordss: |
| 7561 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 7); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7562 | case X86::BI__builtin_ia32_cmpeqsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7563 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 0); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7564 | case X86::BI__builtin_ia32_cmpltsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7565 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 1); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7566 | case X86::BI__builtin_ia32_cmplesd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7567 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 2); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7568 | case X86::BI__builtin_ia32_cmpunordsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7569 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 3); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7570 | case X86::BI__builtin_ia32_cmpneqsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7571 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 4); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7572 | case X86::BI__builtin_ia32_cmpnltsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7573 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 5); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7574 | case X86::BI__builtin_ia32_cmpnlesd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7575 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 6); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 7576 | case X86::BI__builtin_ia32_cmpordsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7577 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 7); |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 7578 | } |
| 7579 | } |
| 7580 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 7581 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7582 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 7583 | const CallExpr *E) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7584 | SmallVector<Value*, 4> Ops; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7585 | |
| 7586 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 7587 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 7588 | |
| 7589 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 7590 | |
| 7591 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 7592 | default: return nullptr; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7593 | |
Hal Finkel | 65e1e4d | 2015-08-31 23:55:19 +0000 | [diff] [blame] | 7594 | // __builtin_ppc_get_timebase is GCC 4.8+'s PowerPC-specific name for what we |
| 7595 | // call __builtin_readcyclecounter. |
| 7596 | case PPC::BI__builtin_ppc_get_timebase: |
| 7597 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::readcyclecounter)); |
| 7598 | |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7599 | // vec_ld, vec_lvsl, vec_lvsr |
| 7600 | case PPC::BI__builtin_altivec_lvx: |
| 7601 | case PPC::BI__builtin_altivec_lvxl: |
| 7602 | case PPC::BI__builtin_altivec_lvebx: |
| 7603 | case PPC::BI__builtin_altivec_lvehx: |
| 7604 | case PPC::BI__builtin_altivec_lvewx: |
| 7605 | case PPC::BI__builtin_altivec_lvsl: |
| 7606 | case PPC::BI__builtin_altivec_lvsr: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 7607 | case PPC::BI__builtin_vsx_lxvd2x: |
| 7608 | case PPC::BI__builtin_vsx_lxvw4x: |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7609 | { |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 7610 | Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7611 | |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 7612 | Ops[0] = Builder.CreateGEP(Ops[1], Ops[0]); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7613 | Ops.pop_back(); |
| 7614 | |
| 7615 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 7616 | default: llvm_unreachable("Unsupported ld/lvsl/lvsr intrinsic!"); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7617 | case PPC::BI__builtin_altivec_lvx: |
| 7618 | ID = Intrinsic::ppc_altivec_lvx; |
| 7619 | break; |
| 7620 | case PPC::BI__builtin_altivec_lvxl: |
| 7621 | ID = Intrinsic::ppc_altivec_lvxl; |
| 7622 | break; |
| 7623 | case PPC::BI__builtin_altivec_lvebx: |
| 7624 | ID = Intrinsic::ppc_altivec_lvebx; |
| 7625 | break; |
| 7626 | case PPC::BI__builtin_altivec_lvehx: |
| 7627 | ID = Intrinsic::ppc_altivec_lvehx; |
| 7628 | break; |
| 7629 | case PPC::BI__builtin_altivec_lvewx: |
| 7630 | ID = Intrinsic::ppc_altivec_lvewx; |
| 7631 | break; |
| 7632 | case PPC::BI__builtin_altivec_lvsl: |
| 7633 | ID = Intrinsic::ppc_altivec_lvsl; |
| 7634 | break; |
| 7635 | case PPC::BI__builtin_altivec_lvsr: |
| 7636 | ID = Intrinsic::ppc_altivec_lvsr; |
| 7637 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 7638 | case PPC::BI__builtin_vsx_lxvd2x: |
| 7639 | ID = Intrinsic::ppc_vsx_lxvd2x; |
| 7640 | break; |
| 7641 | case PPC::BI__builtin_vsx_lxvw4x: |
| 7642 | ID = Intrinsic::ppc_vsx_lxvw4x; |
| 7643 | break; |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7644 | } |
| 7645 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 7646 | return Builder.CreateCall(F, Ops, ""); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 7647 | } |
| 7648 | |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7649 | // vec_st |
| 7650 | case PPC::BI__builtin_altivec_stvx: |
| 7651 | case PPC::BI__builtin_altivec_stvxl: |
| 7652 | case PPC::BI__builtin_altivec_stvebx: |
| 7653 | case PPC::BI__builtin_altivec_stvehx: |
| 7654 | case PPC::BI__builtin_altivec_stvewx: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 7655 | case PPC::BI__builtin_vsx_stxvd2x: |
| 7656 | case PPC::BI__builtin_vsx_stxvw4x: |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7657 | { |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 7658 | Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 7659 | Ops[1] = Builder.CreateGEP(Ops[2], Ops[1]); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7660 | Ops.pop_back(); |
| 7661 | |
| 7662 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 7663 | default: llvm_unreachable("Unsupported st intrinsic!"); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7664 | case PPC::BI__builtin_altivec_stvx: |
| 7665 | ID = Intrinsic::ppc_altivec_stvx; |
| 7666 | break; |
| 7667 | case PPC::BI__builtin_altivec_stvxl: |
| 7668 | ID = Intrinsic::ppc_altivec_stvxl; |
| 7669 | break; |
| 7670 | case PPC::BI__builtin_altivec_stvebx: |
| 7671 | ID = Intrinsic::ppc_altivec_stvebx; |
| 7672 | break; |
| 7673 | case PPC::BI__builtin_altivec_stvehx: |
| 7674 | ID = Intrinsic::ppc_altivec_stvehx; |
| 7675 | break; |
| 7676 | case PPC::BI__builtin_altivec_stvewx: |
| 7677 | ID = Intrinsic::ppc_altivec_stvewx; |
| 7678 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 7679 | case PPC::BI__builtin_vsx_stxvd2x: |
| 7680 | ID = Intrinsic::ppc_vsx_stxvd2x; |
| 7681 | break; |
| 7682 | case PPC::BI__builtin_vsx_stxvw4x: |
| 7683 | ID = Intrinsic::ppc_vsx_stxvw4x; |
| 7684 | break; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7685 | } |
| 7686 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 7687 | return Builder.CreateCall(F, Ops, ""); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7688 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 7689 | // Square root |
| 7690 | case PPC::BI__builtin_vsx_xvsqrtsp: |
| 7691 | case PPC::BI__builtin_vsx_xvsqrtdp: { |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 7692 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7693 | Value *X = EmitScalarExpr(E->getArg(0)); |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 7694 | ID = Intrinsic::sqrt; |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 7695 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 7696 | return Builder.CreateCall(F, X); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 7697 | } |
Nemanja Ivanovic | 6c363ed | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 7698 | // Count leading zeros |
| 7699 | case PPC::BI__builtin_altivec_vclzb: |
| 7700 | case PPC::BI__builtin_altivec_vclzh: |
| 7701 | case PPC::BI__builtin_altivec_vclzw: |
| 7702 | case PPC::BI__builtin_altivec_vclzd: { |
| 7703 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7704 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7705 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 7706 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
| 7707 | return Builder.CreateCall(F, {X, Undef}); |
| 7708 | } |
Nemanja Ivanovic | 10e2b5d | 2016-09-27 10:45:22 +0000 | [diff] [blame] | 7709 | case PPC::BI__builtin_altivec_vctzb: |
| 7710 | case PPC::BI__builtin_altivec_vctzh: |
| 7711 | case PPC::BI__builtin_altivec_vctzw: |
| 7712 | case PPC::BI__builtin_altivec_vctzd: { |
| 7713 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7714 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7715 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 7716 | Function *F = CGM.getIntrinsic(Intrinsic::cttz, ResultType); |
| 7717 | return Builder.CreateCall(F, {X, Undef}); |
| 7718 | } |
| 7719 | case PPC::BI__builtin_altivec_vpopcntb: |
| 7720 | case PPC::BI__builtin_altivec_vpopcnth: |
| 7721 | case PPC::BI__builtin_altivec_vpopcntw: |
| 7722 | case PPC::BI__builtin_altivec_vpopcntd: { |
| 7723 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7724 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7725 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 7726 | return Builder.CreateCall(F, X); |
| 7727 | } |
Nemanja Ivanovic | 6c363ed | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 7728 | // Copy sign |
| 7729 | case PPC::BI__builtin_vsx_xvcpsgnsp: |
| 7730 | case PPC::BI__builtin_vsx_xvcpsgndp: { |
| 7731 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7732 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7733 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7734 | ID = Intrinsic::copysign; |
| 7735 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 7736 | return Builder.CreateCall(F, {X, Y}); |
| 7737 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 7738 | // Rounding/truncation |
| 7739 | case PPC::BI__builtin_vsx_xvrspip: |
| 7740 | case PPC::BI__builtin_vsx_xvrdpip: |
| 7741 | case PPC::BI__builtin_vsx_xvrdpim: |
| 7742 | case PPC::BI__builtin_vsx_xvrspim: |
| 7743 | case PPC::BI__builtin_vsx_xvrdpi: |
| 7744 | case PPC::BI__builtin_vsx_xvrspi: |
| 7745 | case PPC::BI__builtin_vsx_xvrdpic: |
| 7746 | case PPC::BI__builtin_vsx_xvrspic: |
| 7747 | case PPC::BI__builtin_vsx_xvrdpiz: |
| 7748 | case PPC::BI__builtin_vsx_xvrspiz: { |
| 7749 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7750 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7751 | if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim || |
| 7752 | BuiltinID == PPC::BI__builtin_vsx_xvrspim) |
| 7753 | ID = Intrinsic::floor; |
| 7754 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi || |
| 7755 | BuiltinID == PPC::BI__builtin_vsx_xvrspi) |
| 7756 | ID = Intrinsic::round; |
| 7757 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic || |
| 7758 | BuiltinID == PPC::BI__builtin_vsx_xvrspic) |
| 7759 | ID = Intrinsic::nearbyint; |
| 7760 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip || |
| 7761 | BuiltinID == PPC::BI__builtin_vsx_xvrspip) |
| 7762 | ID = Intrinsic::ceil; |
| 7763 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz || |
| 7764 | BuiltinID == PPC::BI__builtin_vsx_xvrspiz) |
| 7765 | ID = Intrinsic::trunc; |
| 7766 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 7767 | return Builder.CreateCall(F, X); |
| 7768 | } |
Kit Barton | fbab158 | 2016-03-09 19:28:31 +0000 | [diff] [blame] | 7769 | |
| 7770 | // Absolute value |
| 7771 | case PPC::BI__builtin_vsx_xvabsdp: |
| 7772 | case PPC::BI__builtin_vsx_xvabssp: { |
| 7773 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7774 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7775 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 7776 | return Builder.CreateCall(F, X); |
| 7777 | } |
| 7778 | |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 7779 | // FMA variations |
| 7780 | case PPC::BI__builtin_vsx_xvmaddadp: |
| 7781 | case PPC::BI__builtin_vsx_xvmaddasp: |
| 7782 | case PPC::BI__builtin_vsx_xvnmaddadp: |
| 7783 | case PPC::BI__builtin_vsx_xvnmaddasp: |
| 7784 | case PPC::BI__builtin_vsx_xvmsubadp: |
| 7785 | case PPC::BI__builtin_vsx_xvmsubasp: |
| 7786 | case PPC::BI__builtin_vsx_xvnmsubadp: |
| 7787 | case PPC::BI__builtin_vsx_xvnmsubasp: { |
| 7788 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 7789 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 7790 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7791 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 7792 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 7793 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
| 7794 | switch (BuiltinID) { |
| 7795 | case PPC::BI__builtin_vsx_xvmaddadp: |
| 7796 | case PPC::BI__builtin_vsx_xvmaddasp: |
| 7797 | return Builder.CreateCall(F, {X, Y, Z}); |
| 7798 | case PPC::BI__builtin_vsx_xvnmaddadp: |
| 7799 | case PPC::BI__builtin_vsx_xvnmaddasp: |
| 7800 | return Builder.CreateFSub(Zero, |
| 7801 | Builder.CreateCall(F, {X, Y, Z}), "sub"); |
| 7802 | case PPC::BI__builtin_vsx_xvmsubadp: |
| 7803 | case PPC::BI__builtin_vsx_xvmsubasp: |
| 7804 | return Builder.CreateCall(F, |
| 7805 | {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
| 7806 | case PPC::BI__builtin_vsx_xvnmsubadp: |
| 7807 | case PPC::BI__builtin_vsx_xvnmsubasp: |
| 7808 | Value *FsubRes = |
| 7809 | Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
| 7810 | return Builder.CreateFSub(Zero, FsubRes, "sub"); |
| 7811 | } |
| 7812 | llvm_unreachable("Unknown FMA operation"); |
| 7813 | return nullptr; // Suppress no-return warning |
| 7814 | } |
| 7815 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7816 | } |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7817 | |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 7818 | Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, |
| 7819 | const CallExpr *E) { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7820 | switch (BuiltinID) { |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7821 | case AMDGPU::BI__builtin_amdgcn_div_scale: |
| 7822 | case AMDGPU::BI__builtin_amdgcn_div_scalef: { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7823 | // Translate from the intrinsics's struct return to the builtin's out |
| 7824 | // argument. |
| 7825 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7826 | Address FlagOutPtr = EmitPointerWithAlignment(E->getArg(3)); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7827 | |
| 7828 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 7829 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 7830 | llvm::Value *Z = EmitScalarExpr(E->getArg(2)); |
| 7831 | |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7832 | llvm::Value *Callee = CGM.getIntrinsic(Intrinsic::amdgcn_div_scale, |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7833 | X->getType()); |
| 7834 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7835 | llvm::Value *Tmp = Builder.CreateCall(Callee, {X, Y, Z}); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7836 | |
| 7837 | llvm::Value *Result = Builder.CreateExtractValue(Tmp, 0); |
| 7838 | llvm::Value *Flag = Builder.CreateExtractValue(Tmp, 1); |
| 7839 | |
| 7840 | llvm::Type *RealFlagType |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7841 | = FlagOutPtr.getPointer()->getType()->getPointerElementType(); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7842 | |
| 7843 | llvm::Value *FlagExt = Builder.CreateZExt(Flag, RealFlagType); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7844 | Builder.CreateStore(FlagExt, FlagOutPtr); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7845 | return Result; |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 7846 | } |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7847 | case AMDGPU::BI__builtin_amdgcn_div_fmas: |
| 7848 | case AMDGPU::BI__builtin_amdgcn_div_fmasf: { |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 7849 | llvm::Value *Src0 = EmitScalarExpr(E->getArg(0)); |
| 7850 | llvm::Value *Src1 = EmitScalarExpr(E->getArg(1)); |
| 7851 | llvm::Value *Src2 = EmitScalarExpr(E->getArg(2)); |
| 7852 | llvm::Value *Src3 = EmitScalarExpr(E->getArg(3)); |
| 7853 | |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7854 | llvm::Value *F = CGM.getIntrinsic(Intrinsic::amdgcn_div_fmas, |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 7855 | Src0->getType()); |
| 7856 | llvm::Value *Src3ToBool = Builder.CreateIsNotNull(Src3); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7857 | return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool}); |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 7858 | } |
Changpeng Fang | 03bdd8f | 2016-08-18 22:04:54 +0000 | [diff] [blame] | 7859 | |
| 7860 | case AMDGPU::BI__builtin_amdgcn_ds_swizzle: |
| 7861 | return emitBinaryBuiltin(*this, E, Intrinsic::amdgcn_ds_swizzle); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7862 | case AMDGPU::BI__builtin_amdgcn_div_fixup: |
| 7863 | case AMDGPU::BI__builtin_amdgcn_div_fixupf: |
Matt Arsenault | f652cae | 2016-07-01 17:38:14 +0000 | [diff] [blame] | 7864 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_div_fixup); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7865 | case AMDGPU::BI__builtin_amdgcn_trig_preop: |
| 7866 | case AMDGPU::BI__builtin_amdgcn_trig_preopf: |
| 7867 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_trig_preop); |
| 7868 | case AMDGPU::BI__builtin_amdgcn_rcp: |
| 7869 | case AMDGPU::BI__builtin_amdgcn_rcpf: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 7870 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rcp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7871 | case AMDGPU::BI__builtin_amdgcn_rsq: |
| 7872 | case AMDGPU::BI__builtin_amdgcn_rsqf: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 7873 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq); |
Matt Arsenault | f5c1f47 | 2016-02-13 01:03:09 +0000 | [diff] [blame] | 7874 | case AMDGPU::BI__builtin_amdgcn_rsq_clamp: |
| 7875 | case AMDGPU::BI__builtin_amdgcn_rsq_clampf: |
| 7876 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq_clamp); |
Matt Arsenault | 9b277b4 | 2016-02-13 01:21:09 +0000 | [diff] [blame] | 7877 | case AMDGPU::BI__builtin_amdgcn_sinf: |
| 7878 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_sin); |
| 7879 | case AMDGPU::BI__builtin_amdgcn_cosf: |
| 7880 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_cos); |
| 7881 | case AMDGPU::BI__builtin_amdgcn_log_clampf: |
| 7882 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_log_clamp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7883 | case AMDGPU::BI__builtin_amdgcn_ldexp: |
| 7884 | case AMDGPU::BI__builtin_amdgcn_ldexpf: |
| 7885 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_ldexp); |
Matt Arsenault | 3fb9633 | 2016-03-30 22:57:40 +0000 | [diff] [blame] | 7886 | case AMDGPU::BI__builtin_amdgcn_frexp_mant: |
| 7887 | case AMDGPU::BI__builtin_amdgcn_frexp_mantf: { |
| 7888 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_frexp_mant); |
| 7889 | } |
| 7890 | case AMDGPU::BI__builtin_amdgcn_frexp_exp: |
| 7891 | case AMDGPU::BI__builtin_amdgcn_frexp_expf: { |
| 7892 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_frexp_exp); |
| 7893 | } |
Matt Arsenault | 2d51059 | 2016-05-28 00:43:27 +0000 | [diff] [blame] | 7894 | case AMDGPU::BI__builtin_amdgcn_fract: |
| 7895 | case AMDGPU::BI__builtin_amdgcn_fractf: |
| 7896 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_fract); |
Wei Ding | ea41f35 | 2016-07-15 16:43:03 +0000 | [diff] [blame] | 7897 | case AMDGPU::BI__builtin_amdgcn_lerp: |
| 7898 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_lerp); |
Wei Ding | 91c8450 | 2016-08-05 15:38:46 +0000 | [diff] [blame] | 7899 | case AMDGPU::BI__builtin_amdgcn_uicmp: |
| 7900 | case AMDGPU::BI__builtin_amdgcn_uicmpl: |
| 7901 | case AMDGPU::BI__builtin_amdgcn_sicmp: |
| 7902 | case AMDGPU::BI__builtin_amdgcn_sicmpl: |
| 7903 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_icmp); |
| 7904 | case AMDGPU::BI__builtin_amdgcn_fcmp: |
| 7905 | case AMDGPU::BI__builtin_amdgcn_fcmpf: |
| 7906 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_fcmp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7907 | case AMDGPU::BI__builtin_amdgcn_class: |
| 7908 | case AMDGPU::BI__builtin_amdgcn_classf: |
| 7909 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_class); |
| 7910 | |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 7911 | case AMDGPU::BI__builtin_amdgcn_read_exec: { |
| 7912 | CallInst *CI = cast<CallInst>( |
| 7913 | EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, true, "exec")); |
| 7914 | CI->setConvergent(); |
| 7915 | return CI; |
| 7916 | } |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 7917 | |
| 7918 | // amdgcn workitem |
| 7919 | case AMDGPU::BI__builtin_amdgcn_workitem_id_x: |
| 7920 | return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_x, 0, 1024); |
| 7921 | case AMDGPU::BI__builtin_amdgcn_workitem_id_y: |
| 7922 | return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_y, 0, 1024); |
| 7923 | case AMDGPU::BI__builtin_amdgcn_workitem_id_z: |
| 7924 | return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_z, 0, 1024); |
| 7925 | |
Matt Arsenault | c86671d | 2016-07-15 21:33:02 +0000 | [diff] [blame] | 7926 | // r600 intrinsics |
| 7927 | case AMDGPU::BI__builtin_r600_recipsqrt_ieee: |
| 7928 | case AMDGPU::BI__builtin_r600_recipsqrt_ieeef: |
| 7929 | return emitUnaryBuiltin(*this, E, Intrinsic::r600_recipsqrt_ieee); |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 7930 | case AMDGPU::BI__builtin_r600_read_tidig_x: |
| 7931 | return emitRangedBuiltin(*this, Intrinsic::r600_read_tidig_x, 0, 1024); |
| 7932 | case AMDGPU::BI__builtin_r600_read_tidig_y: |
| 7933 | return emitRangedBuiltin(*this, Intrinsic::r600_read_tidig_y, 0, 1024); |
| 7934 | case AMDGPU::BI__builtin_r600_read_tidig_z: |
| 7935 | return emitRangedBuiltin(*this, Intrinsic::r600_read_tidig_z, 0, 1024); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 7936 | default: |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 7937 | return nullptr; |
| 7938 | } |
| 7939 | } |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7940 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7941 | /// Handle a SystemZ function in which the final argument is a pointer |
| 7942 | /// to an int that receives the post-instruction CC value. At the LLVM level |
| 7943 | /// this is represented as a function that returns a {result, cc} pair. |
| 7944 | static Value *EmitSystemZIntrinsicWithCC(CodeGenFunction &CGF, |
| 7945 | unsigned IntrinsicID, |
| 7946 | const CallExpr *E) { |
| 7947 | unsigned NumArgs = E->getNumArgs() - 1; |
| 7948 | SmallVector<Value *, 8> Args(NumArgs); |
| 7949 | for (unsigned I = 0; I < NumArgs; ++I) |
| 7950 | Args[I] = CGF.EmitScalarExpr(E->getArg(I)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7951 | Address CCPtr = CGF.EmitPointerWithAlignment(E->getArg(NumArgs)); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7952 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID); |
| 7953 | Value *Call = CGF.Builder.CreateCall(F, Args); |
| 7954 | Value *CC = CGF.Builder.CreateExtractValue(Call, 1); |
| 7955 | CGF.Builder.CreateStore(CC, CCPtr); |
| 7956 | return CGF.Builder.CreateExtractValue(Call, 0); |
| 7957 | } |
| 7958 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7959 | Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID, |
| 7960 | const CallExpr *E) { |
| 7961 | switch (BuiltinID) { |
| 7962 | case SystemZ::BI__builtin_tbegin: { |
| 7963 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 7964 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 7965 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7966 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7967 | } |
| 7968 | case SystemZ::BI__builtin_tbegin_nofloat: { |
| 7969 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 7970 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 7971 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin_nofloat); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7972 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7973 | } |
| 7974 | case SystemZ::BI__builtin_tbeginc: { |
| 7975 | Value *TDB = llvm::ConstantPointerNull::get(Int8PtrTy); |
| 7976 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff08); |
| 7977 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbeginc); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7978 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7979 | } |
| 7980 | case SystemZ::BI__builtin_tabort: { |
| 7981 | Value *Data = EmitScalarExpr(E->getArg(0)); |
| 7982 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tabort); |
| 7983 | return Builder.CreateCall(F, Builder.CreateSExt(Data, Int64Ty, "tabort")); |
| 7984 | } |
| 7985 | case SystemZ::BI__builtin_non_tx_store: { |
| 7986 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 7987 | Value *Data = EmitScalarExpr(E->getArg(1)); |
| 7988 | Value *F = CGM.getIntrinsic(Intrinsic::s390_ntstg); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 7989 | return Builder.CreateCall(F, {Data, Address}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 7990 | } |
| 7991 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 7992 | // Vector builtins. Note that most vector builtins are mapped automatically |
| 7993 | // to target-specific LLVM intrinsics. The ones handled specially here can |
| 7994 | // be represented via standard LLVM IR, which is preferable to enable common |
| 7995 | // LLVM optimizations. |
| 7996 | |
| 7997 | case SystemZ::BI__builtin_s390_vpopctb: |
| 7998 | case SystemZ::BI__builtin_s390_vpopcth: |
| 7999 | case SystemZ::BI__builtin_s390_vpopctf: |
| 8000 | case SystemZ::BI__builtin_s390_vpopctg: { |
| 8001 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8002 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8003 | Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 8004 | return Builder.CreateCall(F, X); |
| 8005 | } |
| 8006 | |
| 8007 | case SystemZ::BI__builtin_s390_vclzb: |
| 8008 | case SystemZ::BI__builtin_s390_vclzh: |
| 8009 | case SystemZ::BI__builtin_s390_vclzf: |
| 8010 | case SystemZ::BI__builtin_s390_vclzg: { |
| 8011 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8012 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8013 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 8014 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 8015 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 8016 | } |
| 8017 | |
| 8018 | case SystemZ::BI__builtin_s390_vctzb: |
| 8019 | case SystemZ::BI__builtin_s390_vctzh: |
| 8020 | case SystemZ::BI__builtin_s390_vctzf: |
| 8021 | case SystemZ::BI__builtin_s390_vctzg: { |
| 8022 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8023 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8024 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 8025 | Function *F = CGM.getIntrinsic(Intrinsic::cttz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 8026 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 8027 | } |
| 8028 | |
| 8029 | case SystemZ::BI__builtin_s390_vfsqdb: { |
| 8030 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8031 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8032 | Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType); |
| 8033 | return Builder.CreateCall(F, X); |
| 8034 | } |
| 8035 | case SystemZ::BI__builtin_s390_vfmadb: { |
| 8036 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8037 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8038 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 8039 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 8040 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 8041 | return Builder.CreateCall(F, {X, Y, Z}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 8042 | } |
| 8043 | case SystemZ::BI__builtin_s390_vfmsdb: { |
| 8044 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8045 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8046 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 8047 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 8048 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 8049 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 8050 | return Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 8051 | } |
| 8052 | case SystemZ::BI__builtin_s390_vflpdb: { |
| 8053 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8054 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8055 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 8056 | return Builder.CreateCall(F, X); |
| 8057 | } |
| 8058 | case SystemZ::BI__builtin_s390_vflndb: { |
| 8059 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8060 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8061 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 8062 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 8063 | return Builder.CreateFSub(Zero, Builder.CreateCall(F, X), "sub"); |
| 8064 | } |
| 8065 | case SystemZ::BI__builtin_s390_vfidb: { |
| 8066 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8067 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8068 | // Constant-fold the M4 and M5 mask arguments. |
| 8069 | llvm::APSInt M4, M5; |
| 8070 | bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext()); |
| 8071 | bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext()); |
| 8072 | assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?"); |
| 8073 | (void)IsConstM4; (void)IsConstM5; |
| 8074 | // Check whether this instance of vfidb can be represented via a LLVM |
| 8075 | // standard intrinsic. We only support some combinations of M4 and M5. |
| 8076 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 8077 | switch (M4.getZExtValue()) { |
| 8078 | default: break; |
| 8079 | case 0: // IEEE-inexact exception allowed |
| 8080 | switch (M5.getZExtValue()) { |
| 8081 | default: break; |
| 8082 | case 0: ID = Intrinsic::rint; break; |
| 8083 | } |
| 8084 | break; |
| 8085 | case 4: // IEEE-inexact exception suppressed |
| 8086 | switch (M5.getZExtValue()) { |
| 8087 | default: break; |
| 8088 | case 0: ID = Intrinsic::nearbyint; break; |
| 8089 | case 1: ID = Intrinsic::round; break; |
| 8090 | case 5: ID = Intrinsic::trunc; break; |
| 8091 | case 6: ID = Intrinsic::ceil; break; |
| 8092 | case 7: ID = Intrinsic::floor; break; |
| 8093 | } |
| 8094 | break; |
| 8095 | } |
| 8096 | if (ID != Intrinsic::not_intrinsic) { |
| 8097 | Function *F = CGM.getIntrinsic(ID, ResultType); |
| 8098 | return Builder.CreateCall(F, X); |
| 8099 | } |
| 8100 | Function *F = CGM.getIntrinsic(Intrinsic::s390_vfidb); |
| 8101 | Value *M4Value = llvm::ConstantInt::get(getLLVMContext(), M4); |
| 8102 | Value *M5Value = llvm::ConstantInt::get(getLLVMContext(), M5); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 8103 | return Builder.CreateCall(F, {X, M4Value, M5Value}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 8104 | } |
| 8105 | |
| 8106 | // Vector intrisincs that output the post-instruction CC value. |
| 8107 | |
| 8108 | #define INTRINSIC_WITH_CC(NAME) \ |
| 8109 | case SystemZ::BI__builtin_##NAME: \ |
| 8110 | return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E) |
| 8111 | |
| 8112 | INTRINSIC_WITH_CC(s390_vpkshs); |
| 8113 | INTRINSIC_WITH_CC(s390_vpksfs); |
| 8114 | INTRINSIC_WITH_CC(s390_vpksgs); |
| 8115 | |
| 8116 | INTRINSIC_WITH_CC(s390_vpklshs); |
| 8117 | INTRINSIC_WITH_CC(s390_vpklsfs); |
| 8118 | INTRINSIC_WITH_CC(s390_vpklsgs); |
| 8119 | |
| 8120 | INTRINSIC_WITH_CC(s390_vceqbs); |
| 8121 | INTRINSIC_WITH_CC(s390_vceqhs); |
| 8122 | INTRINSIC_WITH_CC(s390_vceqfs); |
| 8123 | INTRINSIC_WITH_CC(s390_vceqgs); |
| 8124 | |
| 8125 | INTRINSIC_WITH_CC(s390_vchbs); |
| 8126 | INTRINSIC_WITH_CC(s390_vchhs); |
| 8127 | INTRINSIC_WITH_CC(s390_vchfs); |
| 8128 | INTRINSIC_WITH_CC(s390_vchgs); |
| 8129 | |
| 8130 | INTRINSIC_WITH_CC(s390_vchlbs); |
| 8131 | INTRINSIC_WITH_CC(s390_vchlhs); |
| 8132 | INTRINSIC_WITH_CC(s390_vchlfs); |
| 8133 | INTRINSIC_WITH_CC(s390_vchlgs); |
| 8134 | |
| 8135 | INTRINSIC_WITH_CC(s390_vfaebs); |
| 8136 | INTRINSIC_WITH_CC(s390_vfaehs); |
| 8137 | INTRINSIC_WITH_CC(s390_vfaefs); |
| 8138 | |
| 8139 | INTRINSIC_WITH_CC(s390_vfaezbs); |
| 8140 | INTRINSIC_WITH_CC(s390_vfaezhs); |
| 8141 | INTRINSIC_WITH_CC(s390_vfaezfs); |
| 8142 | |
| 8143 | INTRINSIC_WITH_CC(s390_vfeebs); |
| 8144 | INTRINSIC_WITH_CC(s390_vfeehs); |
| 8145 | INTRINSIC_WITH_CC(s390_vfeefs); |
| 8146 | |
| 8147 | INTRINSIC_WITH_CC(s390_vfeezbs); |
| 8148 | INTRINSIC_WITH_CC(s390_vfeezhs); |
| 8149 | INTRINSIC_WITH_CC(s390_vfeezfs); |
| 8150 | |
| 8151 | INTRINSIC_WITH_CC(s390_vfenebs); |
| 8152 | INTRINSIC_WITH_CC(s390_vfenehs); |
| 8153 | INTRINSIC_WITH_CC(s390_vfenefs); |
| 8154 | |
| 8155 | INTRINSIC_WITH_CC(s390_vfenezbs); |
| 8156 | INTRINSIC_WITH_CC(s390_vfenezhs); |
| 8157 | INTRINSIC_WITH_CC(s390_vfenezfs); |
| 8158 | |
| 8159 | INTRINSIC_WITH_CC(s390_vistrbs); |
| 8160 | INTRINSIC_WITH_CC(s390_vistrhs); |
| 8161 | INTRINSIC_WITH_CC(s390_vistrfs); |
| 8162 | |
| 8163 | INTRINSIC_WITH_CC(s390_vstrcbs); |
| 8164 | INTRINSIC_WITH_CC(s390_vstrchs); |
| 8165 | INTRINSIC_WITH_CC(s390_vstrcfs); |
| 8166 | |
| 8167 | INTRINSIC_WITH_CC(s390_vstrczbs); |
| 8168 | INTRINSIC_WITH_CC(s390_vstrczhs); |
| 8169 | INTRINSIC_WITH_CC(s390_vstrczfs); |
| 8170 | |
| 8171 | INTRINSIC_WITH_CC(s390_vfcedbs); |
| 8172 | INTRINSIC_WITH_CC(s390_vfchdbs); |
| 8173 | INTRINSIC_WITH_CC(s390_vfchedbs); |
| 8174 | |
| 8175 | INTRINSIC_WITH_CC(s390_vftcidb); |
| 8176 | |
| 8177 | #undef INTRINSIC_WITH_CC |
| 8178 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 8179 | default: |
| 8180 | return nullptr; |
| 8181 | } |
| 8182 | } |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8183 | |
| 8184 | Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, |
| 8185 | const CallExpr *E) { |
Justin Lebar | 2e4ecfd | 2016-05-19 22:49:13 +0000 | [diff] [blame] | 8186 | auto MakeLdg = [&](unsigned IntrinsicID) { |
| 8187 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8188 | AlignmentSource AlignSource; |
| 8189 | clang::CharUnits Align = |
| 8190 | getNaturalPointeeTypeAlignment(E->getArg(0)->getType(), &AlignSource); |
| 8191 | return Builder.CreateCall( |
| 8192 | CGM.getIntrinsic(IntrinsicID, {Ptr->getType()->getPointerElementType(), |
| 8193 | Ptr->getType()}), |
| 8194 | {Ptr, ConstantInt::get(Builder.getInt32Ty(), Align.getQuantity())}); |
| 8195 | }; |
Artem Belevich | fda9905 | 2016-09-28 17:47:35 +0000 | [diff] [blame] | 8196 | auto MakeScopedAtomic = [&](unsigned IntrinsicID) { |
| 8197 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8198 | return Builder.CreateCall( |
| 8199 | CGM.getIntrinsic(IntrinsicID, {Ptr->getType()->getPointerElementType(), |
| 8200 | Ptr->getType()}), |
| 8201 | {Ptr, EmitScalarExpr(E->getArg(1))}); |
| 8202 | }; |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8203 | switch (BuiltinID) { |
| 8204 | case NVPTX::BI__nvvm_atom_add_gen_i: |
| 8205 | case NVPTX::BI__nvvm_atom_add_gen_l: |
| 8206 | case NVPTX::BI__nvvm_atom_add_gen_ll: |
| 8207 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Add, E); |
| 8208 | |
| 8209 | case NVPTX::BI__nvvm_atom_sub_gen_i: |
| 8210 | case NVPTX::BI__nvvm_atom_sub_gen_l: |
| 8211 | case NVPTX::BI__nvvm_atom_sub_gen_ll: |
| 8212 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Sub, E); |
| 8213 | |
| 8214 | case NVPTX::BI__nvvm_atom_and_gen_i: |
| 8215 | case NVPTX::BI__nvvm_atom_and_gen_l: |
| 8216 | case NVPTX::BI__nvvm_atom_and_gen_ll: |
| 8217 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::And, E); |
| 8218 | |
| 8219 | case NVPTX::BI__nvvm_atom_or_gen_i: |
| 8220 | case NVPTX::BI__nvvm_atom_or_gen_l: |
| 8221 | case NVPTX::BI__nvvm_atom_or_gen_ll: |
| 8222 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Or, E); |
| 8223 | |
| 8224 | case NVPTX::BI__nvvm_atom_xor_gen_i: |
| 8225 | case NVPTX::BI__nvvm_atom_xor_gen_l: |
| 8226 | case NVPTX::BI__nvvm_atom_xor_gen_ll: |
| 8227 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xor, E); |
| 8228 | |
| 8229 | case NVPTX::BI__nvvm_atom_xchg_gen_i: |
| 8230 | case NVPTX::BI__nvvm_atom_xchg_gen_l: |
| 8231 | case NVPTX::BI__nvvm_atom_xchg_gen_ll: |
| 8232 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xchg, E); |
| 8233 | |
| 8234 | case NVPTX::BI__nvvm_atom_max_gen_i: |
| 8235 | case NVPTX::BI__nvvm_atom_max_gen_l: |
| 8236 | case NVPTX::BI__nvvm_atom_max_gen_ll: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 8237 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Max, E); |
| 8238 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8239 | case NVPTX::BI__nvvm_atom_max_gen_ui: |
| 8240 | case NVPTX::BI__nvvm_atom_max_gen_ul: |
| 8241 | case NVPTX::BI__nvvm_atom_max_gen_ull: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 8242 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMax, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8243 | |
| 8244 | case NVPTX::BI__nvvm_atom_min_gen_i: |
| 8245 | case NVPTX::BI__nvvm_atom_min_gen_l: |
| 8246 | case NVPTX::BI__nvvm_atom_min_gen_ll: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 8247 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Min, E); |
| 8248 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8249 | case NVPTX::BI__nvvm_atom_min_gen_ui: |
| 8250 | case NVPTX::BI__nvvm_atom_min_gen_ul: |
| 8251 | case NVPTX::BI__nvvm_atom_min_gen_ull: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 8252 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8253 | |
| 8254 | case NVPTX::BI__nvvm_atom_cas_gen_i: |
| 8255 | case NVPTX::BI__nvvm_atom_cas_gen_l: |
| 8256 | case NVPTX::BI__nvvm_atom_cas_gen_ll: |
Jingyue Wu | f1eca25 | 2015-09-30 21:49:32 +0000 | [diff] [blame] | 8257 | // __nvvm_atom_cas_gen_* should return the old value rather than the |
| 8258 | // success flag. |
| 8259 | return MakeAtomicCmpXchgValue(*this, E, /*ReturnBool=*/false); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8260 | |
| 8261 | case NVPTX::BI__nvvm_atom_add_gen_f: { |
| 8262 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8263 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 8264 | // atomicrmw only deals with integer arguments so we need to use |
| 8265 | // LLVM's nvvm_atomic_load_add_f32 intrinsic for that. |
| 8266 | Value *FnALAF32 = |
| 8267 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_add_f32, Ptr->getType()); |
| 8268 | return Builder.CreateCall(FnALAF32, {Ptr, Val}); |
| 8269 | } |
| 8270 | |
Justin Lebar | 717d2b0 | 2016-03-22 00:09:28 +0000 | [diff] [blame] | 8271 | case NVPTX::BI__nvvm_atom_inc_gen_ui: { |
| 8272 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8273 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 8274 | Value *FnALI32 = |
| 8275 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_inc_32, Ptr->getType()); |
| 8276 | return Builder.CreateCall(FnALI32, {Ptr, Val}); |
| 8277 | } |
| 8278 | |
| 8279 | case NVPTX::BI__nvvm_atom_dec_gen_ui: { |
| 8280 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8281 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 8282 | Value *FnALD32 = |
| 8283 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_dec_32, Ptr->getType()); |
| 8284 | return Builder.CreateCall(FnALD32, {Ptr, Val}); |
| 8285 | } |
| 8286 | |
Justin Lebar | 2e4ecfd | 2016-05-19 22:49:13 +0000 | [diff] [blame] | 8287 | case NVPTX::BI__nvvm_ldg_c: |
| 8288 | case NVPTX::BI__nvvm_ldg_c2: |
| 8289 | case NVPTX::BI__nvvm_ldg_c4: |
| 8290 | case NVPTX::BI__nvvm_ldg_s: |
| 8291 | case NVPTX::BI__nvvm_ldg_s2: |
| 8292 | case NVPTX::BI__nvvm_ldg_s4: |
| 8293 | case NVPTX::BI__nvvm_ldg_i: |
| 8294 | case NVPTX::BI__nvvm_ldg_i2: |
| 8295 | case NVPTX::BI__nvvm_ldg_i4: |
| 8296 | case NVPTX::BI__nvvm_ldg_l: |
| 8297 | case NVPTX::BI__nvvm_ldg_ll: |
| 8298 | case NVPTX::BI__nvvm_ldg_ll2: |
| 8299 | case NVPTX::BI__nvvm_ldg_uc: |
| 8300 | case NVPTX::BI__nvvm_ldg_uc2: |
| 8301 | case NVPTX::BI__nvvm_ldg_uc4: |
| 8302 | case NVPTX::BI__nvvm_ldg_us: |
| 8303 | case NVPTX::BI__nvvm_ldg_us2: |
| 8304 | case NVPTX::BI__nvvm_ldg_us4: |
| 8305 | case NVPTX::BI__nvvm_ldg_ui: |
| 8306 | case NVPTX::BI__nvvm_ldg_ui2: |
| 8307 | case NVPTX::BI__nvvm_ldg_ui4: |
| 8308 | case NVPTX::BI__nvvm_ldg_ul: |
| 8309 | case NVPTX::BI__nvvm_ldg_ull: |
| 8310 | case NVPTX::BI__nvvm_ldg_ull2: |
| 8311 | // PTX Interoperability section 2.2: "For a vector with an even number of |
| 8312 | // elements, its alignment is set to number of elements times the alignment |
| 8313 | // of its member: n*alignof(t)." |
| 8314 | return MakeLdg(Intrinsic::nvvm_ldg_global_i); |
| 8315 | case NVPTX::BI__nvvm_ldg_f: |
| 8316 | case NVPTX::BI__nvvm_ldg_f2: |
| 8317 | case NVPTX::BI__nvvm_ldg_f4: |
| 8318 | case NVPTX::BI__nvvm_ldg_d: |
| 8319 | case NVPTX::BI__nvvm_ldg_d2: |
| 8320 | return MakeLdg(Intrinsic::nvvm_ldg_global_f); |
Artem Belevich | fda9905 | 2016-09-28 17:47:35 +0000 | [diff] [blame] | 8321 | |
| 8322 | case NVPTX::BI__nvvm_atom_cta_add_gen_i: |
| 8323 | case NVPTX::BI__nvvm_atom_cta_add_gen_l: |
| 8324 | case NVPTX::BI__nvvm_atom_cta_add_gen_ll: |
| 8325 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_cta); |
| 8326 | case NVPTX::BI__nvvm_atom_sys_add_gen_i: |
| 8327 | case NVPTX::BI__nvvm_atom_sys_add_gen_l: |
| 8328 | case NVPTX::BI__nvvm_atom_sys_add_gen_ll: |
| 8329 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_sys); |
| 8330 | case NVPTX::BI__nvvm_atom_cta_add_gen_f: |
| 8331 | case NVPTX::BI__nvvm_atom_cta_add_gen_d: |
| 8332 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_cta); |
| 8333 | case NVPTX::BI__nvvm_atom_sys_add_gen_f: |
| 8334 | case NVPTX::BI__nvvm_atom_sys_add_gen_d: |
| 8335 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_sys); |
| 8336 | case NVPTX::BI__nvvm_atom_cta_xchg_gen_i: |
| 8337 | case NVPTX::BI__nvvm_atom_cta_xchg_gen_l: |
| 8338 | case NVPTX::BI__nvvm_atom_cta_xchg_gen_ll: |
| 8339 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_cta); |
| 8340 | case NVPTX::BI__nvvm_atom_sys_xchg_gen_i: |
| 8341 | case NVPTX::BI__nvvm_atom_sys_xchg_gen_l: |
| 8342 | case NVPTX::BI__nvvm_atom_sys_xchg_gen_ll: |
| 8343 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_sys); |
| 8344 | case NVPTX::BI__nvvm_atom_cta_max_gen_i: |
| 8345 | case NVPTX::BI__nvvm_atom_cta_max_gen_ui: |
| 8346 | case NVPTX::BI__nvvm_atom_cta_max_gen_l: |
| 8347 | case NVPTX::BI__nvvm_atom_cta_max_gen_ul: |
| 8348 | case NVPTX::BI__nvvm_atom_cta_max_gen_ll: |
| 8349 | case NVPTX::BI__nvvm_atom_cta_max_gen_ull: |
| 8350 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_cta); |
| 8351 | case NVPTX::BI__nvvm_atom_sys_max_gen_i: |
| 8352 | case NVPTX::BI__nvvm_atom_sys_max_gen_ui: |
| 8353 | case NVPTX::BI__nvvm_atom_sys_max_gen_l: |
| 8354 | case NVPTX::BI__nvvm_atom_sys_max_gen_ul: |
| 8355 | case NVPTX::BI__nvvm_atom_sys_max_gen_ll: |
| 8356 | case NVPTX::BI__nvvm_atom_sys_max_gen_ull: |
| 8357 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_sys); |
| 8358 | case NVPTX::BI__nvvm_atom_cta_min_gen_i: |
| 8359 | case NVPTX::BI__nvvm_atom_cta_min_gen_ui: |
| 8360 | case NVPTX::BI__nvvm_atom_cta_min_gen_l: |
| 8361 | case NVPTX::BI__nvvm_atom_cta_min_gen_ul: |
| 8362 | case NVPTX::BI__nvvm_atom_cta_min_gen_ll: |
| 8363 | case NVPTX::BI__nvvm_atom_cta_min_gen_ull: |
| 8364 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_cta); |
| 8365 | case NVPTX::BI__nvvm_atom_sys_min_gen_i: |
| 8366 | case NVPTX::BI__nvvm_atom_sys_min_gen_ui: |
| 8367 | case NVPTX::BI__nvvm_atom_sys_min_gen_l: |
| 8368 | case NVPTX::BI__nvvm_atom_sys_min_gen_ul: |
| 8369 | case NVPTX::BI__nvvm_atom_sys_min_gen_ll: |
| 8370 | case NVPTX::BI__nvvm_atom_sys_min_gen_ull: |
| 8371 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_sys); |
| 8372 | case NVPTX::BI__nvvm_atom_cta_inc_gen_ui: |
| 8373 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_cta); |
| 8374 | case NVPTX::BI__nvvm_atom_cta_dec_gen_ui: |
| 8375 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_cta); |
| 8376 | case NVPTX::BI__nvvm_atom_sys_inc_gen_ui: |
| 8377 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_sys); |
| 8378 | case NVPTX::BI__nvvm_atom_sys_dec_gen_ui: |
| 8379 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_sys); |
| 8380 | case NVPTX::BI__nvvm_atom_cta_and_gen_i: |
| 8381 | case NVPTX::BI__nvvm_atom_cta_and_gen_l: |
| 8382 | case NVPTX::BI__nvvm_atom_cta_and_gen_ll: |
| 8383 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_cta); |
| 8384 | case NVPTX::BI__nvvm_atom_sys_and_gen_i: |
| 8385 | case NVPTX::BI__nvvm_atom_sys_and_gen_l: |
| 8386 | case NVPTX::BI__nvvm_atom_sys_and_gen_ll: |
| 8387 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_sys); |
| 8388 | case NVPTX::BI__nvvm_atom_cta_or_gen_i: |
| 8389 | case NVPTX::BI__nvvm_atom_cta_or_gen_l: |
| 8390 | case NVPTX::BI__nvvm_atom_cta_or_gen_ll: |
| 8391 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_cta); |
| 8392 | case NVPTX::BI__nvvm_atom_sys_or_gen_i: |
| 8393 | case NVPTX::BI__nvvm_atom_sys_or_gen_l: |
| 8394 | case NVPTX::BI__nvvm_atom_sys_or_gen_ll: |
| 8395 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_sys); |
| 8396 | case NVPTX::BI__nvvm_atom_cta_xor_gen_i: |
| 8397 | case NVPTX::BI__nvvm_atom_cta_xor_gen_l: |
| 8398 | case NVPTX::BI__nvvm_atom_cta_xor_gen_ll: |
| 8399 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_cta); |
| 8400 | case NVPTX::BI__nvvm_atom_sys_xor_gen_i: |
| 8401 | case NVPTX::BI__nvvm_atom_sys_xor_gen_l: |
| 8402 | case NVPTX::BI__nvvm_atom_sys_xor_gen_ll: |
| 8403 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys); |
| 8404 | case NVPTX::BI__nvvm_atom_cta_cas_gen_i: |
| 8405 | case NVPTX::BI__nvvm_atom_cta_cas_gen_l: |
| 8406 | case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: { |
| 8407 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8408 | return Builder.CreateCall( |
| 8409 | CGM.getIntrinsic( |
| 8410 | Intrinsic::nvvm_atomic_cas_gen_i_cta, |
| 8411 | {Ptr->getType()->getPointerElementType(), Ptr->getType()}), |
| 8412 | {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))}); |
| 8413 | } |
| 8414 | case NVPTX::BI__nvvm_atom_sys_cas_gen_i: |
| 8415 | case NVPTX::BI__nvvm_atom_sys_cas_gen_l: |
| 8416 | case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: { |
| 8417 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 8418 | return Builder.CreateCall( |
| 8419 | CGM.getIntrinsic( |
| 8420 | Intrinsic::nvvm_atomic_cas_gen_i_sys, |
| 8421 | {Ptr->getType()->getPointerElementType(), Ptr->getType()}), |
| 8422 | {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))}); |
| 8423 | } |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 8424 | default: |
| 8425 | return nullptr; |
| 8426 | } |
| 8427 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 8428 | |
| 8429 | Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, |
| 8430 | const CallExpr *E) { |
| 8431 | switch (BuiltinID) { |
Derek Schuff | dbd24b4 | 2016-05-02 17:26:19 +0000 | [diff] [blame] | 8432 | case WebAssembly::BI__builtin_wasm_current_memory: { |
Dan Gohman | d4c5fb5 | 2015-10-02 19:38:47 +0000 | [diff] [blame] | 8433 | llvm::Type *ResultType = ConvertType(E->getType()); |
Derek Schuff | dbd24b4 | 2016-05-02 17:26:19 +0000 | [diff] [blame] | 8434 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_current_memory, ResultType); |
Dan Gohman | d4c5fb5 | 2015-10-02 19:38:47 +0000 | [diff] [blame] | 8435 | return Builder.CreateCall(Callee); |
| 8436 | } |
Dan Gohman | 24f0a08 | 2015-11-05 20:16:37 +0000 | [diff] [blame] | 8437 | case WebAssembly::BI__builtin_wasm_grow_memory: { |
Dan Gohman | 266b38a | 2015-10-02 20:20:01 +0000 | [diff] [blame] | 8438 | Value *X = EmitScalarExpr(E->getArg(0)); |
Dan Gohman | 24f0a08 | 2015-11-05 20:16:37 +0000 | [diff] [blame] | 8439 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_grow_memory, X->getType()); |
Dan Gohman | 266b38a | 2015-10-02 20:20:01 +0000 | [diff] [blame] | 8440 | return Builder.CreateCall(Callee, X); |
| 8441 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 8442 | |
| 8443 | default: |
| 8444 | return nullptr; |
| 8445 | } |
| 8446 | } |