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 | |
David Majnemer | ba3e5ec | 2015-03-13 18:26:17 +0000 | [diff] [blame] | 14 | #include "CGCXXABI.h" |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 15 | #include "CGObjCRuntime.h" |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 16 | #include "CGOpenCLRuntime.h" |
Mehdi Amini | 06d367c | 2016-10-24 20:39:34 +0000 | [diff] [blame] | 17 | #include "CodeGenFunction.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "CodeGenModule.h" |
John McCall | de0fe07 | 2017-08-15 21:42:52 +0000 | [diff] [blame] | 19 | #include "ConstantEmitter.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "TargetInfo.h" |
Chris Lattner | 1eec660 | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 6e8aa53 | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
Mehdi Amini | 06d367c | 2016-10-24 20:39:34 +0000 | [diff] [blame] | 23 | #include "clang/Analysis/Analyses/OSLog.h" |
Chris Lattner | 5abdec7 | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 24 | #include "clang/Basic/TargetBuiltins.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Mark Lacey | a8e7df3 | 2013-10-30 21:53:58 +0000 | [diff] [blame] | 26 | #include "clang/CodeGen/CGFunctionInfo.h" |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 28 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 29 | #include "llvm/IR/DataLayout.h" |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 30 | #include "llvm/IR/InlineAsm.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 31 | #include "llvm/IR/Intrinsics.h" |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 32 | #include "llvm/IR/MDBuilder.h" |
Reid Kleckner | 30701ed | 2017-09-05 20:27:35 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ConvertUTF.h" |
Erich Keane | 8202521 | 2017-11-15 00:11:24 +0000 | [diff] [blame] | 34 | #include "llvm/Support/ScopedPrinter.h" |
| 35 | #include "llvm/Support/TargetParser.h" |
Kit Barton | 8246f28 | 2015-03-25 19:41:41 +0000 | [diff] [blame] | 36 | #include <sstream> |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 37 | |
Anders Carlsson | 1d8e521 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 38 | using namespace clang; |
| 39 | using namespace CodeGen; |
Anders Carlsson | a020c43 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 40 | using namespace llvm; |
| 41 | |
Sean Fertile | 96d9e0e | 2017-01-05 21:43:30 +0000 | [diff] [blame] | 42 | static |
| 43 | int64_t clamp(int64_t Value, int64_t Low, int64_t High) { |
| 44 | return std::min(High, std::max(Low, Value)); |
| 45 | } |
| 46 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 47 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 48 | /// "__builtin_fabsf", return a Function* for "fabsf". |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 49 | llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, |
| 50 | unsigned BuiltinID) { |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 51 | assert(Context.BuiltinInfo.isLibFunction(BuiltinID)); |
| 52 | |
| 53 | // Get the name, skip over the __builtin_ prefix (if necessary). |
| 54 | StringRef Name; |
| 55 | GlobalDecl D(FD); |
| 56 | |
| 57 | // If the builtin has been declared explicitly with an assembler label, |
| 58 | // use the mangled name. This differs from the plain label on platforms |
| 59 | // that prefix labels. |
| 60 | if (FD->hasAttr<AsmLabelAttr>()) |
| 61 | Name = getMangledName(D); |
| 62 | else |
Mehdi Amini | 7186a43 | 2016-10-11 19:04:24 +0000 | [diff] [blame] | 63 | Name = Context.BuiltinInfo.getName(BuiltinID) + 10; |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 64 | |
| 65 | llvm::FunctionType *Ty = |
| 66 | cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType())); |
| 67 | |
| 68 | return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable=*/false); |
| 69 | } |
| 70 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 71 | /// Emit the conversions required to turn the given value into an |
| 72 | /// integer of the given size. |
| 73 | static Value *EmitToInt(CodeGenFunction &CGF, llvm::Value *V, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 74 | QualType T, llvm::IntegerType *IntType) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 75 | V = CGF.EmitToMemory(V, T); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 76 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 77 | if (V->getType()->isPointerTy()) |
| 78 | return CGF.Builder.CreatePtrToInt(V, IntType); |
| 79 | |
| 80 | assert(V->getType() == IntType); |
| 81 | return V; |
Chandler Carruth | bc8cab1 | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 82 | } |
| 83 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 84 | static Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 85 | QualType T, llvm::Type *ResultType) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 86 | V = CGF.EmitFromMemory(V, T); |
| 87 | |
| 88 | if (ResultType->isPointerTy()) |
| 89 | return CGF.Builder.CreateIntToPtr(V, ResultType); |
| 90 | |
| 91 | assert(V->getType() == ResultType); |
| 92 | return V; |
Chandler Carruth | bc8cab1 | 2010-07-18 07:23:17 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 95 | /// Utility to insert an atomic instruction based on Instrinsic::ID |
| 96 | /// and the expression node. |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 97 | static Value *MakeBinaryAtomicValue(CodeGenFunction &CGF, |
| 98 | llvm::AtomicRMWInst::BinOp Kind, |
| 99 | const CallExpr *E) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 100 | QualType T = E->getType(); |
| 101 | assert(E->getArg(0)->getType()->isPointerType()); |
| 102 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 103 | E->getArg(0)->getType()->getPointeeType())); |
| 104 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 105 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 106 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 107 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 108 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 109 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 110 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 111 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 112 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 113 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 114 | llvm::Value *Args[2]; |
| 115 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 116 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 117 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 118 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 119 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 120 | llvm::Value *Result = CGF.Builder.CreateAtomicRMW( |
| 121 | Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 122 | return EmitFromInt(CGF, Result, T, ValueType); |
| 123 | } |
| 124 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 125 | static Value *EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E) { |
| 126 | Value *Val = CGF.EmitScalarExpr(E->getArg(0)); |
| 127 | Value *Address = CGF.EmitScalarExpr(E->getArg(1)); |
| 128 | |
| 129 | // Convert the type of the pointer to a pointer to the stored type. |
| 130 | Val = CGF.EmitToMemory(Val, E->getArg(0)->getType()); |
| 131 | Value *BC = CGF.Builder.CreateBitCast( |
| 132 | Address, llvm::PointerType::getUnqual(Val->getType()), "cast"); |
| 133 | LValue LV = CGF.MakeNaturalAlignAddrLValue(BC, E->getArg(0)->getType()); |
| 134 | LV.setNontemporal(true); |
| 135 | CGF.EmitStoreOfScalar(Val, LV, false); |
| 136 | return nullptr; |
| 137 | } |
| 138 | |
| 139 | static Value *EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E) { |
| 140 | Value *Address = CGF.EmitScalarExpr(E->getArg(0)); |
| 141 | |
| 142 | LValue LV = CGF.MakeNaturalAlignAddrLValue(Address, E->getType()); |
| 143 | LV.setNontemporal(true); |
| 144 | return CGF.EmitLoadOfScalar(LV, E->getExprLoc()); |
| 145 | } |
| 146 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 147 | static RValue EmitBinaryAtomic(CodeGenFunction &CGF, |
| 148 | llvm::AtomicRMWInst::BinOp Kind, |
| 149 | const CallExpr *E) { |
| 150 | return RValue::get(MakeBinaryAtomicValue(CGF, Kind, E)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /// Utility to insert an atomic instruction based Instrinsic::ID and |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 154 | /// the expression node, where the return value is the result of the |
| 155 | /// operation. |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 156 | static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF, |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 157 | llvm::AtomicRMWInst::BinOp Kind, |
| 158 | const CallExpr *E, |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 159 | Instruction::BinaryOps Op, |
| 160 | bool Invert = false) { |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 161 | QualType T = E->getType(); |
| 162 | assert(E->getArg(0)->getType()->isPointerType()); |
| 163 | assert(CGF.getContext().hasSameUnqualifiedType(T, |
| 164 | E->getArg(0)->getType()->getPointeeType())); |
| 165 | assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); |
| 166 | |
Chris Lattner | b2f659b | 2010-09-21 23:40:48 +0000 | [diff] [blame] | 167 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 168 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
John McCall | 6bde954 | 2010-10-26 22:09:15 +0000 | [diff] [blame] | 169 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 170 | llvm::IntegerType *IntType = |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 171 | llvm::IntegerType::get(CGF.getLLVMContext(), |
| 172 | CGF.getContext().getTypeSize(T)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 173 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 174 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 175 | llvm::Value *Args[2]; |
| 176 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 177 | llvm::Type *ValueType = Args[1]->getType(); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 178 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 179 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 180 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 181 | llvm::Value *Result = CGF.Builder.CreateAtomicRMW( |
| 182 | Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 183 | Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 184 | if (Invert) |
| 185 | Result = CGF.Builder.CreateBinOp(llvm::Instruction::Xor, Result, |
| 186 | llvm::ConstantInt::get(IntType, -1)); |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 187 | Result = EmitFromInt(CGF, Result, T, ValueType); |
| 188 | return RValue::get(Result); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 191 | /// @brief Utility to insert an atomic cmpxchg instruction. |
| 192 | /// |
| 193 | /// @param CGF The current codegen function. |
| 194 | /// @param E Builtin call expression to convert to cmpxchg. |
| 195 | /// arg0 - address to operate on |
| 196 | /// arg1 - value to compare with |
| 197 | /// arg2 - new value |
| 198 | /// @param ReturnBool Specifies whether to return success flag of |
| 199 | /// cmpxchg result or the old value. |
| 200 | /// |
| 201 | /// @returns result of cmpxchg, according to ReturnBool |
| 202 | static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E, |
| 203 | bool ReturnBool) { |
| 204 | QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType(); |
| 205 | llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0)); |
| 206 | unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); |
| 207 | |
| 208 | llvm::IntegerType *IntType = llvm::IntegerType::get( |
| 209 | CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); |
| 210 | llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); |
| 211 | |
| 212 | Value *Args[3]; |
| 213 | Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); |
| 214 | Args[1] = CGF.EmitScalarExpr(E->getArg(1)); |
| 215 | llvm::Type *ValueType = Args[1]->getType(); |
| 216 | Args[1] = EmitToInt(CGF, Args[1], T, IntType); |
| 217 | Args[2] = EmitToInt(CGF, CGF.EmitScalarExpr(E->getArg(2)), T, IntType); |
| 218 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 219 | Value *Pair = CGF.Builder.CreateAtomicCmpXchg( |
| 220 | Args[0], Args[1], Args[2], llvm::AtomicOrdering::SequentiallyConsistent, |
| 221 | llvm::AtomicOrdering::SequentiallyConsistent); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 222 | if (ReturnBool) |
| 223 | // Extract boolean success flag and zext it to int. |
| 224 | return CGF.Builder.CreateZExt(CGF.Builder.CreateExtractValue(Pair, 1), |
| 225 | CGF.ConvertType(E->getType())); |
| 226 | else |
| 227 | // Extract old value and emit it using the same type as compare value. |
| 228 | return EmitFromInt(CGF, CGF.Builder.CreateExtractValue(Pair, 0), T, |
| 229 | ValueType); |
| 230 | } |
| 231 | |
Matt Arsenault | f652cae | 2016-07-01 17:38:14 +0000 | [diff] [blame] | 232 | // Emit a simple mangled intrinsic that has 1 argument and a return type |
| 233 | // matching the argument type. |
| 234 | static Value *emitUnaryBuiltin(CodeGenFunction &CGF, |
| 235 | const CallExpr *E, |
| 236 | unsigned IntrinsicID) { |
| 237 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 238 | |
| 239 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 240 | return CGF.Builder.CreateCall(F, Src0); |
| 241 | } |
| 242 | |
| 243 | // Emit an intrinsic that has 2 operands of the same type as its result. |
| 244 | static Value *emitBinaryBuiltin(CodeGenFunction &CGF, |
| 245 | const CallExpr *E, |
| 246 | unsigned IntrinsicID) { |
| 247 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 248 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 249 | |
| 250 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 251 | return CGF.Builder.CreateCall(F, { Src0, Src1 }); |
| 252 | } |
| 253 | |
| 254 | // Emit an intrinsic that has 3 operands of the same type as its result. |
| 255 | static Value *emitTernaryBuiltin(CodeGenFunction &CGF, |
| 256 | const CallExpr *E, |
| 257 | unsigned IntrinsicID) { |
| 258 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 259 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 260 | llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2)); |
| 261 | |
| 262 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 263 | return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 }); |
| 264 | } |
| 265 | |
| 266 | // Emit an intrinsic that has 1 float or double operand, and 1 integer. |
| 267 | static Value *emitFPIntBuiltin(CodeGenFunction &CGF, |
| 268 | const CallExpr *E, |
| 269 | unsigned IntrinsicID) { |
| 270 | llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0)); |
| 271 | llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1)); |
| 272 | |
| 273 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType()); |
| 274 | return CGF.Builder.CreateCall(F, {Src0, Src1}); |
| 275 | } |
| 276 | |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 277 | /// EmitFAbs - Emit a call to @llvm.fabs(). |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 278 | static Value *EmitFAbs(CodeGenFunction &CGF, Value *V) { |
Tom Stellard | c4e0c10 | 2014-09-03 15:24:29 +0000 | [diff] [blame] | 279 | Value *F = CGF.CGM.getIntrinsic(Intrinsic::fabs, V->getType()); |
| 280 | llvm::CallInst *Call = CGF.Builder.CreateCall(F, V); |
| 281 | Call->setDoesNotAccessMemory(); |
| 282 | return Call; |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 285 | /// Emit the computation of the sign bit for a floating point value. Returns |
| 286 | /// the i1 sign bit value. |
| 287 | static Value *EmitSignBit(CodeGenFunction &CGF, Value *V) { |
| 288 | LLVMContext &C = CGF.CGM.getLLVMContext(); |
| 289 | |
| 290 | llvm::Type *Ty = V->getType(); |
| 291 | int Width = Ty->getPrimitiveSizeInBits(); |
| 292 | llvm::Type *IntTy = llvm::IntegerType::get(C, Width); |
| 293 | V = CGF.Builder.CreateBitCast(V, IntTy); |
| 294 | if (Ty->isPPC_FP128Ty()) { |
Petar Jovanovic | 73d1044 | 2015-11-06 14:52:46 +0000 | [diff] [blame] | 295 | // We want the sign bit of the higher-order double. The bitcast we just |
| 296 | // did works as if the double-double was stored to memory and then |
| 297 | // read as an i128. The "store" will put the higher-order double in the |
| 298 | // lower address in both little- and big-Endian modes, but the "load" |
| 299 | // will treat those bits as a different part of the i128: the low bits in |
| 300 | // little-Endian, the high bits in big-Endian. Therefore, on big-Endian |
| 301 | // 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] | 302 | Width >>= 1; |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 303 | if (CGF.getTarget().isBigEndian()) { |
| 304 | Value *ShiftCst = llvm::ConstantInt::get(IntTy, Width); |
| 305 | V = CGF.Builder.CreateLShr(V, ShiftCst); |
| 306 | } |
| 307 | // We are truncating value in order to extract the higher-order |
| 308 | // double, which we will be using to extract the sign from. |
| 309 | IntTy = llvm::IntegerType::get(C, Width); |
| 310 | V = CGF.Builder.CreateTrunc(V, IntTy); |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 311 | } |
| 312 | Value *Zero = llvm::Constant::getNullValue(IntTy); |
| 313 | return CGF.Builder.CreateICmpSLT(V, Zero); |
| 314 | } |
| 315 | |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 316 | static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, |
| 317 | const CallExpr *E, llvm::Constant *calleeValue) { |
| 318 | CGCallee callee = CGCallee::forDirect(calleeValue, FD); |
| 319 | return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot()); |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 322 | /// \brief Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.* |
| 323 | /// depending on IntrinsicID. |
| 324 | /// |
| 325 | /// \arg CGF The current codegen function. |
| 326 | /// \arg IntrinsicID The ID for the Intrinsic we wish to generate. |
| 327 | /// \arg X The first argument to the llvm.*.with.overflow.*. |
| 328 | /// \arg Y The second argument to the llvm.*.with.overflow.*. |
| 329 | /// \arg Carry The carry returned by the llvm.*.with.overflow.*. |
| 330 | /// \returns The result (i.e. sum/product) returned by the intrinsic. |
| 331 | static llvm::Value *EmitOverflowIntrinsic(CodeGenFunction &CGF, |
| 332 | const llvm::Intrinsic::ID IntrinsicID, |
| 333 | llvm::Value *X, llvm::Value *Y, |
| 334 | llvm::Value *&Carry) { |
| 335 | // Make sure we have integers of the same width. |
| 336 | assert(X->getType() == Y->getType() && |
| 337 | "Arguments must be the same type. (Did you forget to make sure both " |
| 338 | "arguments have the same integer width?)"); |
| 339 | |
NAKAMURA Takumi | 7ab4fbf | 2013-01-13 11:26:44 +0000 | [diff] [blame] | 340 | llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 341 | llvm::Value *Tmp = CGF.Builder.CreateCall(Callee, {X, Y}); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 342 | Carry = CGF.Builder.CreateExtractValue(Tmp, 1); |
| 343 | return CGF.Builder.CreateExtractValue(Tmp, 0); |
| 344 | } |
| 345 | |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 346 | static Value *emitRangedBuiltin(CodeGenFunction &CGF, |
| 347 | unsigned IntrinsicID, |
| 348 | int low, int high) { |
| 349 | llvm::MDBuilder MDHelper(CGF.getLLVMContext()); |
| 350 | llvm::MDNode *RNode = MDHelper.createRange(APInt(32, low), APInt(32, high)); |
| 351 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID, {}); |
| 352 | llvm::Instruction *Call = CGF.Builder.CreateCall(F); |
| 353 | Call->setMetadata(llvm::LLVMContext::MD_range, RNode); |
| 354 | return Call; |
| 355 | } |
| 356 | |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 357 | namespace { |
| 358 | struct WidthAndSignedness { |
| 359 | unsigned Width; |
| 360 | bool Signed; |
| 361 | }; |
| 362 | } |
| 363 | |
| 364 | static WidthAndSignedness |
| 365 | getIntegerWidthAndSignedness(const clang::ASTContext &context, |
| 366 | const clang::QualType Type) { |
| 367 | assert(Type->isIntegerType() && "Given type is not an integer."); |
| 368 | unsigned Width = Type->isBooleanType() ? 1 : context.getTypeInfo(Type).Width; |
| 369 | bool Signed = Type->isSignedIntegerType(); |
| 370 | return {Width, Signed}; |
| 371 | } |
| 372 | |
| 373 | // Given one or more integer types, this function produces an integer type that |
| 374 | // encompasses them: any value in one of the given types could be expressed in |
| 375 | // the encompassing type. |
| 376 | static struct WidthAndSignedness |
| 377 | EncompassingIntegerType(ArrayRef<struct WidthAndSignedness> Types) { |
| 378 | assert(Types.size() > 0 && "Empty list of types."); |
| 379 | |
| 380 | // If any of the given types is signed, we must return a signed type. |
| 381 | bool Signed = false; |
| 382 | for (const auto &Type : Types) { |
| 383 | Signed |= Type.Signed; |
| 384 | } |
| 385 | |
| 386 | // The encompassing type must have a width greater than or equal to the width |
| 387 | // of the specified types. Aditionally, if the encompassing type is signed, |
| 388 | // its width must be strictly greater than the width of any unsigned types |
| 389 | // given. |
| 390 | unsigned Width = 0; |
| 391 | for (const auto &Type : Types) { |
| 392 | unsigned MinWidth = Type.Width + (Signed && !Type.Signed); |
| 393 | if (Width < MinWidth) { |
| 394 | Width = MinWidth; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | return {Width, Signed}; |
| 399 | } |
| 400 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 401 | Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) { |
| 402 | llvm::Type *DestType = Int8PtrTy; |
| 403 | if (ArgValue->getType() != DestType) |
| 404 | ArgValue = |
| 405 | Builder.CreateBitCast(ArgValue, DestType, ArgValue->getName().data()); |
| 406 | |
| 407 | Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend; |
| 408 | return Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue); |
| 409 | } |
| 410 | |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 411 | /// Checks if using the result of __builtin_object_size(p, @p From) in place of |
| 412 | /// __builtin_object_size(p, @p To) is correct |
| 413 | static bool areBOSTypesCompatible(int From, int To) { |
| 414 | // Note: Our __builtin_object_size implementation currently treats Type=0 and |
| 415 | // Type=2 identically. Encoding this implementation detail here may make |
| 416 | // improving __builtin_object_size difficult in the future, so it's omitted. |
| 417 | return From == To || (From == 0 && To == 1) || (From == 3 && To == 2); |
| 418 | } |
| 419 | |
| 420 | static llvm::Value * |
| 421 | getDefaultBuiltinObjectSizeResult(unsigned Type, llvm::IntegerType *ResType) { |
| 422 | return ConstantInt::get(ResType, (Type & 2) ? 0 : -1, /*isSigned=*/true); |
| 423 | } |
| 424 | |
| 425 | llvm::Value * |
| 426 | CodeGenFunction::evaluateOrEmitBuiltinObjectSize(const Expr *E, unsigned Type, |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 427 | llvm::IntegerType *ResType, |
| 428 | llvm::Value *EmittedE) { |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 429 | uint64_t ObjectSize; |
| 430 | if (!E->tryEvaluateObjectSize(ObjectSize, getContext(), Type)) |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 431 | return emitBuiltinObjectSize(E, Type, ResType, EmittedE); |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 432 | return ConstantInt::get(ResType, ObjectSize, /*isSigned=*/true); |
| 433 | } |
| 434 | |
| 435 | /// Returns a Value corresponding to the size of the given expression. |
| 436 | /// This Value may be either of the following: |
| 437 | /// - A llvm::Argument (if E is a param with the pass_object_size attribute on |
| 438 | /// it) |
| 439 | /// - A call to the @llvm.objectsize intrinsic |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 440 | /// |
| 441 | /// EmittedE is the result of emitting `E` as a scalar expr. If it's non-null |
| 442 | /// and we wouldn't otherwise try to reference a pass_object_size parameter, |
| 443 | /// we'll call @llvm.objectsize on EmittedE, rather than emitting E. |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 444 | llvm::Value * |
| 445 | CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type, |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 446 | llvm::IntegerType *ResType, |
| 447 | llvm::Value *EmittedE) { |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 448 | // We need to reference an argument if the pointer is a parameter with the |
| 449 | // pass_object_size attribute. |
| 450 | if (auto *D = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) { |
| 451 | auto *Param = dyn_cast<ParmVarDecl>(D->getDecl()); |
| 452 | auto *PS = D->getDecl()->getAttr<PassObjectSizeAttr>(); |
| 453 | if (Param != nullptr && PS != nullptr && |
| 454 | areBOSTypesCompatible(PS->getType(), Type)) { |
| 455 | auto Iter = SizeArguments.find(Param); |
| 456 | assert(Iter != SizeArguments.end()); |
| 457 | |
| 458 | const ImplicitParamDecl *D = Iter->second; |
| 459 | auto DIter = LocalDeclMap.find(D); |
| 460 | assert(DIter != LocalDeclMap.end()); |
| 461 | |
| 462 | return EmitLoadOfScalar(DIter->second, /*volatile=*/false, |
| 463 | getContext().getSizeType(), E->getLocStart()); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // LLVM can't handle Type=3 appropriately, and __builtin_object_size shouldn't |
| 468 | // evaluate E for side-effects. In either case, we shouldn't lower to |
| 469 | // @llvm.objectsize. |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 470 | if (Type == 3 || (!EmittedE && E->HasSideEffects(getContext()))) |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 471 | return getDefaultBuiltinObjectSizeResult(Type, ResType); |
| 472 | |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 473 | Value *Ptr = EmittedE ? EmittedE : EmitScalarExpr(E); |
George Burgess IV | 8856aa9 | 2017-02-22 02:35:51 +0000 | [diff] [blame] | 474 | assert(Ptr->getType()->isPointerTy() && |
| 475 | "Non-pointer passed to __builtin_object_size?"); |
| 476 | |
George Burgess IV | 8856aa9 | 2017-02-22 02:35:51 +0000 | [diff] [blame] | 477 | Value *F = CGM.getIntrinsic(Intrinsic::objectsize, {ResType, Ptr->getType()}); |
George Burgess IV | a63f915 | 2017-03-21 20:09:35 +0000 | [diff] [blame] | 478 | |
| 479 | // LLVM only supports 0 and 2, make sure that we pass along that as a boolean. |
| 480 | Value *Min = Builder.getInt1((Type & 2) != 0); |
| 481 | // For GCC compatability, __builtin_object_size treat NULL as unknown size. |
| 482 | Value *NullIsUnknown = Builder.getTrue(); |
| 483 | return Builder.CreateCall(F, {Ptr, Min, NullIsUnknown}); |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 486 | // Many of MSVC builtins are on both x64 and ARM; to avoid repeating code, we |
| 487 | // handle them here. |
| 488 | enum class CodeGenFunction::MSVCIntrin { |
| 489 | _BitScanForward, |
| 490 | _BitScanReverse, |
| 491 | _InterlockedAnd, |
| 492 | _InterlockedDecrement, |
| 493 | _InterlockedExchange, |
| 494 | _InterlockedExchangeAdd, |
| 495 | _InterlockedExchangeSub, |
| 496 | _InterlockedIncrement, |
| 497 | _InterlockedOr, |
| 498 | _InterlockedXor, |
Hans Wennborg | 5c3c51f | 2017-04-07 16:41:47 +0000 | [diff] [blame] | 499 | _interlockedbittestandset, |
Reid Kleckner | 04f9f91 | 2017-02-09 18:31:06 +0000 | [diff] [blame] | 500 | __fastfail, |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | Value *CodeGenFunction::EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, |
Reid Kleckner | 04f9f91 | 2017-02-09 18:31:06 +0000 | [diff] [blame] | 504 | const CallExpr *E) { |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 505 | switch (BuiltinID) { |
| 506 | case MSVCIntrin::_BitScanForward: |
| 507 | case MSVCIntrin::_BitScanReverse: { |
| 508 | Value *ArgValue = EmitScalarExpr(E->getArg(1)); |
| 509 | |
| 510 | llvm::Type *ArgType = ArgValue->getType(); |
| 511 | llvm::Type *IndexType = |
| 512 | EmitScalarExpr(E->getArg(0))->getType()->getPointerElementType(); |
| 513 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 514 | |
| 515 | Value *ArgZero = llvm::Constant::getNullValue(ArgType); |
| 516 | Value *ResZero = llvm::Constant::getNullValue(ResultType); |
| 517 | Value *ResOne = llvm::ConstantInt::get(ResultType, 1); |
| 518 | |
| 519 | BasicBlock *Begin = Builder.GetInsertBlock(); |
| 520 | BasicBlock *End = createBasicBlock("bitscan_end", this->CurFn); |
| 521 | Builder.SetInsertPoint(End); |
| 522 | PHINode *Result = Builder.CreatePHI(ResultType, 2, "bitscan_result"); |
| 523 | |
| 524 | Builder.SetInsertPoint(Begin); |
| 525 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, ArgZero); |
| 526 | BasicBlock *NotZero = createBasicBlock("bitscan_not_zero", this->CurFn); |
| 527 | Builder.CreateCondBr(IsZero, End, NotZero); |
| 528 | Result->addIncoming(ResZero, Begin); |
| 529 | |
| 530 | Builder.SetInsertPoint(NotZero); |
| 531 | Address IndexAddress = EmitPointerWithAlignment(E->getArg(0)); |
| 532 | |
| 533 | if (BuiltinID == MSVCIntrin::_BitScanForward) { |
| 534 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
| 535 | Value *ZeroCount = Builder.CreateCall(F, {ArgValue, Builder.getTrue()}); |
| 536 | ZeroCount = Builder.CreateIntCast(ZeroCount, IndexType, false); |
| 537 | Builder.CreateStore(ZeroCount, IndexAddress, false); |
| 538 | } else { |
| 539 | unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth(); |
| 540 | Value *ArgTypeLastIndex = llvm::ConstantInt::get(IndexType, ArgWidth - 1); |
| 541 | |
| 542 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType); |
| 543 | Value *ZeroCount = Builder.CreateCall(F, {ArgValue, Builder.getTrue()}); |
| 544 | ZeroCount = Builder.CreateIntCast(ZeroCount, IndexType, false); |
| 545 | Value *Index = Builder.CreateNSWSub(ArgTypeLastIndex, ZeroCount); |
| 546 | Builder.CreateStore(Index, IndexAddress, false); |
| 547 | } |
| 548 | Builder.CreateBr(End); |
| 549 | Result->addIncoming(ResOne, NotZero); |
| 550 | |
| 551 | Builder.SetInsertPoint(End); |
| 552 | return Result; |
| 553 | } |
| 554 | case MSVCIntrin::_InterlockedAnd: |
| 555 | return MakeBinaryAtomicValue(*this, AtomicRMWInst::And, E); |
| 556 | case MSVCIntrin::_InterlockedExchange: |
| 557 | return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xchg, E); |
| 558 | case MSVCIntrin::_InterlockedExchangeAdd: |
| 559 | return MakeBinaryAtomicValue(*this, AtomicRMWInst::Add, E); |
| 560 | case MSVCIntrin::_InterlockedExchangeSub: |
| 561 | return MakeBinaryAtomicValue(*this, AtomicRMWInst::Sub, E); |
| 562 | case MSVCIntrin::_InterlockedOr: |
| 563 | return MakeBinaryAtomicValue(*this, AtomicRMWInst::Or, E); |
| 564 | case MSVCIntrin::_InterlockedXor: |
| 565 | return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xor, E); |
| 566 | |
Hans Wennborg | 5c3c51f | 2017-04-07 16:41:47 +0000 | [diff] [blame] | 567 | case MSVCIntrin::_interlockedbittestandset: { |
| 568 | llvm::Value *Addr = EmitScalarExpr(E->getArg(0)); |
| 569 | llvm::Value *Bit = EmitScalarExpr(E->getArg(1)); |
| 570 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 571 | AtomicRMWInst::Or, Addr, |
| 572 | Builder.CreateShl(ConstantInt::get(Bit->getType(), 1), Bit), |
| 573 | llvm::AtomicOrdering::SequentiallyConsistent); |
| 574 | // Shift the relevant bit to the least significant position, truncate to |
| 575 | // the result type, and test the low bit. |
| 576 | llvm::Value *Shifted = Builder.CreateLShr(RMWI, Bit); |
| 577 | llvm::Value *Truncated = |
| 578 | Builder.CreateTrunc(Shifted, ConvertType(E->getType())); |
| 579 | return Builder.CreateAnd(Truncated, |
| 580 | ConstantInt::get(Truncated->getType(), 1)); |
| 581 | } |
| 582 | |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 583 | case MSVCIntrin::_InterlockedDecrement: { |
| 584 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 585 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 586 | AtomicRMWInst::Sub, |
| 587 | EmitScalarExpr(E->getArg(0)), |
| 588 | ConstantInt::get(IntTy, 1), |
| 589 | llvm::AtomicOrdering::SequentiallyConsistent); |
| 590 | return Builder.CreateSub(RMWI, ConstantInt::get(IntTy, 1)); |
| 591 | } |
| 592 | case MSVCIntrin::_InterlockedIncrement: { |
| 593 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 594 | AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( |
| 595 | AtomicRMWInst::Add, |
| 596 | EmitScalarExpr(E->getArg(0)), |
| 597 | ConstantInt::get(IntTy, 1), |
| 598 | llvm::AtomicOrdering::SequentiallyConsistent); |
| 599 | return Builder.CreateAdd(RMWI, ConstantInt::get(IntTy, 1)); |
| 600 | } |
Reid Kleckner | 04f9f91 | 2017-02-09 18:31:06 +0000 | [diff] [blame] | 601 | |
| 602 | case MSVCIntrin::__fastfail: { |
| 603 | // Request immediate process termination from the kernel. The instruction |
| 604 | // sequences to do this are documented on MSDN: |
| 605 | // https://msdn.microsoft.com/en-us/library/dn774154.aspx |
| 606 | llvm::Triple::ArchType ISA = getTarget().getTriple().getArch(); |
| 607 | StringRef Asm, Constraints; |
| 608 | switch (ISA) { |
| 609 | default: |
| 610 | ErrorUnsupported(E, "__fastfail call for this architecture"); |
| 611 | break; |
| 612 | case llvm::Triple::x86: |
| 613 | case llvm::Triple::x86_64: |
| 614 | Asm = "int $$0x29"; |
| 615 | Constraints = "{cx}"; |
| 616 | break; |
| 617 | case llvm::Triple::thumb: |
| 618 | Asm = "udf #251"; |
| 619 | Constraints = "{r0}"; |
| 620 | break; |
| 621 | } |
| 622 | llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, {Int32Ty}, false); |
| 623 | llvm::InlineAsm *IA = |
| 624 | llvm::InlineAsm::get(FTy, Asm, Constraints, /*SideEffects=*/true); |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 625 | llvm::AttributeList NoReturnAttr = llvm::AttributeList::get( |
| 626 | getLLVMContext(), llvm::AttributeList::FunctionIndex, |
| 627 | llvm::Attribute::NoReturn); |
Reid Kleckner | 04f9f91 | 2017-02-09 18:31:06 +0000 | [diff] [blame] | 628 | CallSite CS = Builder.CreateCall(IA, EmitScalarExpr(E->getArg(0))); |
| 629 | CS.setAttributes(NoReturnAttr); |
| 630 | return CS.getInstruction(); |
| 631 | } |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 632 | } |
| 633 | llvm_unreachable("Incorrect MSVC intrinsic!"); |
| 634 | } |
| 635 | |
Mehdi Amini | 06d367c | 2016-10-24 20:39:34 +0000 | [diff] [blame] | 636 | namespace { |
| 637 | // ARC cleanup for __builtin_os_log_format |
| 638 | struct CallObjCArcUse final : EHScopeStack::Cleanup { |
| 639 | CallObjCArcUse(llvm::Value *object) : object(object) {} |
| 640 | llvm::Value *object; |
| 641 | |
| 642 | void Emit(CodeGenFunction &CGF, Flags flags) override { |
| 643 | CGF.EmitARCIntrinsicUse(object); |
| 644 | } |
| 645 | }; |
| 646 | } |
| 647 | |
Vedant Kumar | 10c3102 | 2017-07-29 00:19:51 +0000 | [diff] [blame] | 648 | Value *CodeGenFunction::EmitCheckedArgForBuiltin(const Expr *E, |
| 649 | BuiltinCheckKind Kind) { |
Victor Leschuk | 198357b | 2017-07-29 08:18:38 +0000 | [diff] [blame] | 650 | assert((Kind == BCK_CLZPassedZero || Kind == BCK_CTZPassedZero) |
| 651 | && "Unsupported builtin check kind"); |
Vedant Kumar | 10c3102 | 2017-07-29 00:19:51 +0000 | [diff] [blame] | 652 | |
| 653 | Value *ArgValue = EmitScalarExpr(E); |
| 654 | if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef()) |
| 655 | return ArgValue; |
| 656 | |
| 657 | SanitizerScope SanScope(this); |
| 658 | Value *Cond = Builder.CreateICmpNE( |
| 659 | ArgValue, llvm::Constant::getNullValue(ArgValue->getType())); |
| 660 | EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin), |
| 661 | SanitizerHandler::InvalidBuiltin, |
| 662 | {EmitCheckSourceLocation(E->getExprLoc()), |
| 663 | llvm::ConstantInt::get(Builder.getInt8Ty(), Kind)}, |
| 664 | None); |
| 665 | return ArgValue; |
| 666 | } |
| 667 | |
Akira Hatanaka | 6b103bc | 2017-10-06 07:12:46 +0000 | [diff] [blame] | 668 | /// Get the argument type for arguments to os_log_helper. |
| 669 | static CanQualType getOSLogArgType(ASTContext &C, int Size) { |
| 670 | QualType UnsignedTy = C.getIntTypeForBitwidth(Size * 8, /*Signed=*/false); |
| 671 | return C.getCanonicalType(UnsignedTy); |
| 672 | } |
| 673 | |
| 674 | llvm::Function *CodeGenFunction::generateBuiltinOSLogHelperFunction( |
| 675 | const analyze_os_log::OSLogBufferLayout &Layout, |
| 676 | CharUnits BufferAlignment) { |
| 677 | ASTContext &Ctx = getContext(); |
| 678 | |
| 679 | llvm::SmallString<64> Name; |
| 680 | { |
| 681 | raw_svector_ostream OS(Name); |
| 682 | OS << "__os_log_helper"; |
| 683 | OS << "_" << BufferAlignment.getQuantity(); |
| 684 | OS << "_" << int(Layout.getSummaryByte()); |
| 685 | OS << "_" << int(Layout.getNumArgsByte()); |
| 686 | for (const auto &Item : Layout.Items) |
| 687 | OS << "_" << int(Item.getSizeByte()) << "_" |
| 688 | << int(Item.getDescriptorByte()); |
| 689 | } |
| 690 | |
| 691 | if (llvm::Function *F = CGM.getModule().getFunction(Name)) |
| 692 | return F; |
| 693 | |
| 694 | llvm::SmallVector<ImplicitParamDecl, 4> Params; |
| 695 | Params.emplace_back(Ctx, nullptr, SourceLocation(), &Ctx.Idents.get("buffer"), |
| 696 | Ctx.VoidPtrTy, ImplicitParamDecl::Other); |
| 697 | |
| 698 | for (unsigned int I = 0, E = Layout.Items.size(); I < E; ++I) { |
| 699 | char Size = Layout.Items[I].getSizeByte(); |
| 700 | if (!Size) |
| 701 | continue; |
| 702 | |
Akira Hatanaka | a463812 | 2017-10-06 07:47:47 +0000 | [diff] [blame] | 703 | Params.emplace_back( |
| 704 | Ctx, nullptr, SourceLocation(), |
| 705 | &Ctx.Idents.get(std::string("arg") + llvm::to_string(I)), |
| 706 | getOSLogArgType(Ctx, Size), ImplicitParamDecl::Other); |
Akira Hatanaka | 6b103bc | 2017-10-06 07:12:46 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | FunctionArgList Args; |
| 710 | for (auto &P : Params) |
| 711 | Args.push_back(&P); |
| 712 | |
| 713 | // The helper function has linkonce_odr linkage to enable the linker to merge |
| 714 | // identical functions. To ensure the merging always happens, 'noinline' is |
| 715 | // attached to the function when compiling with -Oz. |
| 716 | const CGFunctionInfo &FI = |
| 717 | CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args); |
| 718 | llvm::FunctionType *FuncTy = CGM.getTypes().GetFunctionType(FI); |
| 719 | llvm::Function *Fn = llvm::Function::Create( |
| 720 | FuncTy, llvm::GlobalValue::LinkOnceODRLinkage, Name, &CGM.getModule()); |
| 721 | Fn->setVisibility(llvm::GlobalValue::HiddenVisibility); |
| 722 | CGM.SetLLVMFunctionAttributes(nullptr, FI, Fn); |
| 723 | CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn); |
| 724 | |
| 725 | // Attach 'noinline' at -Oz. |
| 726 | if (CGM.getCodeGenOpts().OptimizeSize == 2) |
| 727 | Fn->addFnAttr(llvm::Attribute::NoInline); |
| 728 | |
| 729 | auto NL = ApplyDebugLocation::CreateEmpty(*this); |
| 730 | IdentifierInfo *II = &Ctx.Idents.get(Name); |
| 731 | FunctionDecl *FD = FunctionDecl::Create( |
| 732 | Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II, |
| 733 | Ctx.VoidTy, nullptr, SC_PrivateExtern, false, false); |
| 734 | |
| 735 | StartFunction(FD, Ctx.VoidTy, Fn, FI, Args); |
| 736 | |
| 737 | // Create a scope with an artificial location for the body of this function. |
| 738 | auto AL = ApplyDebugLocation::CreateArtificial(*this); |
| 739 | |
| 740 | CharUnits Offset; |
| 741 | Address BufAddr(Builder.CreateLoad(GetAddrOfLocalVar(&Params[0]), "buf"), |
| 742 | BufferAlignment); |
| 743 | Builder.CreateStore(Builder.getInt8(Layout.getSummaryByte()), |
| 744 | Builder.CreateConstByteGEP(BufAddr, Offset++, "summary")); |
| 745 | Builder.CreateStore(Builder.getInt8(Layout.getNumArgsByte()), |
| 746 | Builder.CreateConstByteGEP(BufAddr, Offset++, "numArgs")); |
| 747 | |
| 748 | unsigned I = 1; |
| 749 | for (const auto &Item : Layout.Items) { |
| 750 | Builder.CreateStore( |
| 751 | Builder.getInt8(Item.getDescriptorByte()), |
| 752 | Builder.CreateConstByteGEP(BufAddr, Offset++, "argDescriptor")); |
| 753 | Builder.CreateStore( |
| 754 | Builder.getInt8(Item.getSizeByte()), |
| 755 | Builder.CreateConstByteGEP(BufAddr, Offset++, "argSize")); |
| 756 | |
| 757 | CharUnits Size = Item.size(); |
| 758 | if (!Size.getQuantity()) |
| 759 | continue; |
| 760 | |
| 761 | Address Arg = GetAddrOfLocalVar(&Params[I]); |
| 762 | Address Addr = Builder.CreateConstByteGEP(BufAddr, Offset, "argData"); |
| 763 | Addr = Builder.CreateBitCast(Addr, Arg.getPointer()->getType(), |
| 764 | "argDataCast"); |
| 765 | Builder.CreateStore(Builder.CreateLoad(Arg), Addr); |
| 766 | Offset += Size; |
| 767 | ++I; |
| 768 | } |
| 769 | |
| 770 | FinishFunction(); |
| 771 | |
| 772 | return Fn; |
| 773 | } |
| 774 | |
| 775 | RValue CodeGenFunction::emitBuiltinOSLogFormat(const CallExpr &E) { |
| 776 | assert(E.getNumArgs() >= 2 && |
| 777 | "__builtin_os_log_format takes at least 2 arguments"); |
| 778 | ASTContext &Ctx = getContext(); |
| 779 | analyze_os_log::OSLogBufferLayout Layout; |
| 780 | analyze_os_log::computeOSLogBufferLayout(Ctx, &E, Layout); |
| 781 | Address BufAddr = EmitPointerWithAlignment(E.getArg(0)); |
| 782 | llvm::SmallVector<llvm::Value *, 4> RetainableOperands; |
| 783 | |
| 784 | // Ignore argument 1, the format string. It is not currently used. |
| 785 | CallArgList Args; |
| 786 | Args.add(RValue::get(BufAddr.getPointer()), Ctx.VoidPtrTy); |
| 787 | |
| 788 | for (const auto &Item : Layout.Items) { |
| 789 | int Size = Item.getSizeByte(); |
| 790 | if (!Size) |
| 791 | continue; |
| 792 | |
| 793 | llvm::Value *ArgVal; |
| 794 | |
| 795 | if (const Expr *TheExpr = Item.getExpr()) { |
| 796 | ArgVal = EmitScalarExpr(TheExpr, /*Ignore*/ false); |
| 797 | |
| 798 | // Check if this is a retainable type. |
| 799 | if (TheExpr->getType()->isObjCRetainableType()) { |
| 800 | assert(getEvaluationKind(TheExpr->getType()) == TEK_Scalar && |
| 801 | "Only scalar can be a ObjC retainable type"); |
| 802 | // Check if the object is constant, if not, save it in |
| 803 | // RetainableOperands. |
| 804 | if (!isa<Constant>(ArgVal)) |
| 805 | RetainableOperands.push_back(ArgVal); |
| 806 | } |
| 807 | } else { |
| 808 | ArgVal = Builder.getInt32(Item.getConstValue().getQuantity()); |
| 809 | } |
| 810 | |
| 811 | unsigned ArgValSize = |
| 812 | CGM.getDataLayout().getTypeSizeInBits(ArgVal->getType()); |
| 813 | llvm::IntegerType *IntTy = llvm::Type::getIntNTy(getLLVMContext(), |
| 814 | ArgValSize); |
| 815 | ArgVal = Builder.CreateBitOrPointerCast(ArgVal, IntTy); |
| 816 | CanQualType ArgTy = getOSLogArgType(Ctx, Size); |
| 817 | // If ArgVal has type x86_fp80, zero-extend ArgVal. |
| 818 | ArgVal = Builder.CreateZExtOrBitCast(ArgVal, ConvertType(ArgTy)); |
| 819 | Args.add(RValue::get(ArgVal), ArgTy); |
| 820 | } |
| 821 | |
| 822 | const CGFunctionInfo &FI = |
| 823 | CGM.getTypes().arrangeBuiltinFunctionCall(Ctx.VoidTy, Args); |
| 824 | llvm::Function *F = CodeGenFunction(CGM).generateBuiltinOSLogHelperFunction( |
| 825 | Layout, BufAddr.getAlignment()); |
| 826 | EmitCall(FI, CGCallee::forDirect(F), ReturnValueSlot(), Args); |
| 827 | |
| 828 | // Push a clang.arc.use cleanup for each object in RetainableOperands. The |
| 829 | // cleanup will cause the use to appear after the final log call, keeping |
| 830 | // the object valid while it’s held in the log buffer. Note that if there’s |
| 831 | // a release cleanup on the object, it will already be active; since |
| 832 | // cleanups are emitted in reverse order, the use will occur before the |
| 833 | // object is released. |
| 834 | if (!RetainableOperands.empty() && getLangOpts().ObjCAutoRefCount && |
| 835 | CGM.getCodeGenOpts().OptimizationLevel != 0) |
| 836 | for (llvm::Value *Object : RetainableOperands) |
| 837 | pushFullExprCleanup<CallObjCArcUse>(getARCCleanupKind(), Object); |
| 838 | |
| 839 | return RValue::get(BufAddr.getPointer()); |
| 840 | } |
| 841 | |
Vedant Kumar | fa5a0e5 | 2017-12-16 01:28:25 +0000 | [diff] [blame] | 842 | /// Determine if a binop is a checked mixed-sign multiply we can specialize. |
| 843 | static bool isSpecialMixedSignMultiply(unsigned BuiltinID, |
| 844 | WidthAndSignedness Op1Info, |
| 845 | WidthAndSignedness Op2Info, |
| 846 | WidthAndSignedness ResultInfo) { |
| 847 | return BuiltinID == Builtin::BI__builtin_mul_overflow && |
| 848 | Op1Info.Width == Op2Info.Width && Op1Info.Width >= ResultInfo.Width && |
| 849 | Op1Info.Signed != Op2Info.Signed; |
| 850 | } |
| 851 | |
| 852 | /// Emit a checked mixed-sign multiply. This is a cheaper specialization of |
| 853 | /// the generic checked-binop irgen. |
| 854 | static RValue |
| 855 | EmitCheckedMixedSignMultiply(CodeGenFunction &CGF, const clang::Expr *Op1, |
| 856 | WidthAndSignedness Op1Info, const clang::Expr *Op2, |
| 857 | WidthAndSignedness Op2Info, |
| 858 | const clang::Expr *ResultArg, QualType ResultQTy, |
| 859 | WidthAndSignedness ResultInfo) { |
| 860 | assert(isSpecialMixedSignMultiply(Builtin::BI__builtin_mul_overflow, Op1Info, |
| 861 | Op2Info, ResultInfo) && |
| 862 | "Not a mixed-sign multipliction we can specialize"); |
| 863 | |
| 864 | // Emit the signed and unsigned operands. |
| 865 | const clang::Expr *SignedOp = Op1Info.Signed ? Op1 : Op2; |
| 866 | const clang::Expr *UnsignedOp = Op1Info.Signed ? Op2 : Op1; |
| 867 | llvm::Value *Signed = CGF.EmitScalarExpr(SignedOp); |
| 868 | llvm::Value *Unsigned = CGF.EmitScalarExpr(UnsignedOp); |
| 869 | |
| 870 | llvm::Type *OpTy = Signed->getType(); |
| 871 | llvm::Value *Zero = llvm::Constant::getNullValue(OpTy); |
| 872 | Address ResultPtr = CGF.EmitPointerWithAlignment(ResultArg); |
| 873 | llvm::Type *ResTy = ResultPtr.getElementType(); |
| 874 | |
| 875 | // Take the absolute value of the signed operand. |
| 876 | llvm::Value *IsNegative = CGF.Builder.CreateICmpSLT(Signed, Zero); |
| 877 | llvm::Value *AbsOfNegative = CGF.Builder.CreateSub(Zero, Signed); |
| 878 | llvm::Value *AbsSigned = |
| 879 | CGF.Builder.CreateSelect(IsNegative, AbsOfNegative, Signed); |
| 880 | |
| 881 | // Perform a checked unsigned multiplication. |
| 882 | llvm::Value *UnsignedOverflow; |
| 883 | llvm::Value *UnsignedResult = |
| 884 | EmitOverflowIntrinsic(CGF, llvm::Intrinsic::umul_with_overflow, AbsSigned, |
| 885 | Unsigned, UnsignedOverflow); |
| 886 | |
| 887 | llvm::Value *Overflow, *Result; |
| 888 | if (ResultInfo.Signed) { |
| 889 | // Signed overflow occurs if the result is greater than INT_MAX or lesser |
| 890 | // than INT_MIN, i.e when |Result| > (INT_MAX + IsNegative). |
| 891 | auto IntMax = llvm::APInt::getSignedMaxValue(ResultInfo.Width) |
| 892 | .zextOrSelf(Op1Info.Width); |
| 893 | llvm::Value *MaxResult = |
| 894 | CGF.Builder.CreateAdd(llvm::ConstantInt::get(OpTy, IntMax), |
| 895 | CGF.Builder.CreateZExt(IsNegative, OpTy)); |
| 896 | llvm::Value *SignedOverflow = |
| 897 | CGF.Builder.CreateICmpUGT(UnsignedResult, MaxResult); |
| 898 | Overflow = CGF.Builder.CreateOr(UnsignedOverflow, SignedOverflow); |
| 899 | |
| 900 | // Prepare the signed result (possibly by negating it). |
| 901 | llvm::Value *NegativeResult = CGF.Builder.CreateNeg(UnsignedResult); |
| 902 | llvm::Value *SignedResult = |
| 903 | CGF.Builder.CreateSelect(IsNegative, NegativeResult, UnsignedResult); |
| 904 | Result = CGF.Builder.CreateTrunc(SignedResult, ResTy); |
| 905 | } else { |
| 906 | // Unsigned overflow occurs if the result is < 0 or greater than UINT_MAX. |
| 907 | llvm::Value *Underflow = CGF.Builder.CreateAnd( |
| 908 | IsNegative, CGF.Builder.CreateIsNotNull(UnsignedResult)); |
| 909 | Overflow = CGF.Builder.CreateOr(UnsignedOverflow, Underflow); |
| 910 | if (ResultInfo.Width < Op1Info.Width) { |
| 911 | auto IntMax = |
| 912 | llvm::APInt::getMaxValue(ResultInfo.Width).zext(Op1Info.Width); |
| 913 | llvm::Value *TruncOverflow = CGF.Builder.CreateICmpUGT( |
| 914 | UnsignedResult, llvm::ConstantInt::get(OpTy, IntMax)); |
| 915 | Overflow = CGF.Builder.CreateOr(Overflow, TruncOverflow); |
| 916 | } |
| 917 | |
| 918 | Result = CGF.Builder.CreateTrunc(UnsignedResult, ResTy); |
| 919 | } |
| 920 | assert(Overflow && Result && "Missing overflow or result"); |
| 921 | |
| 922 | bool isVolatile = |
| 923 | ResultArg->getType()->getPointeeType().isVolatileQualified(); |
| 924 | CGF.Builder.CreateStore(CGF.EmitToMemory(Result, ResultQTy), ResultPtr, |
| 925 | isVolatile); |
| 926 | return RValue::get(Overflow); |
| 927 | } |
| 928 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 930 | unsigned BuiltinID, const CallExpr *E, |
| 931 | ReturnValueSlot ReturnValue) { |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 932 | // 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] | 933 | Expr::EvalResult Result; |
Eli Friedman | df88c54 | 2012-01-06 20:03:09 +0000 | [diff] [blame] | 934 | if (E->EvaluateAsRValue(Result, CGM.getContext()) && |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 935 | !Result.hasSideEffects()) { |
Anders Carlsson | c968790 | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 936 | if (Result.Val.isInt()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 937 | return RValue::get(llvm::ConstantInt::get(getLLVMContext(), |
Owen Anderson | b7a2fe6 | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 938 | Result.Val.getInt())); |
Chris Lattner | 07e9686 | 2010-10-01 23:43:16 +0000 | [diff] [blame] | 939 | if (Result.Val.isFloat()) |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 940 | return RValue::get(llvm::ConstantFP::get(getLLVMContext(), |
| 941 | Result.Val.getFloat())); |
Chris Lattner | a1518b1 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 942 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 943 | |
Sanjay Patel | 08fba37 | 2017-12-02 17:52:00 +0000 | [diff] [blame] | 944 | // There are LLVM math intrinsics/instructions corresponding to math library |
| 945 | // functions except the LLVM op will never set errno while the math library |
| 946 | // might. Also, math builtins have the same semantics as their math library |
| 947 | // twins. Thus, we can transform math library and builtin calls to their |
| 948 | // LLVM counterparts if the call is marked 'const' (known to never set errno). |
Sanjay Patel | 3e287b4 | 2017-12-01 23:15:52 +0000 | [diff] [blame] | 949 | if (FD->hasAttr<ConstAttr>()) { |
| 950 | switch (BuiltinID) { |
| 951 | case Builtin::BIceil: |
| 952 | case Builtin::BIceilf: |
| 953 | case Builtin::BIceill: |
| 954 | case Builtin::BI__builtin_ceil: |
| 955 | case Builtin::BI__builtin_ceilf: |
| 956 | case Builtin::BI__builtin_ceill: |
| 957 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::ceil)); |
| 958 | |
| 959 | case Builtin::BIcopysign: |
| 960 | case Builtin::BIcopysignf: |
| 961 | case Builtin::BIcopysignl: |
| 962 | case Builtin::BI__builtin_copysign: |
| 963 | case Builtin::BI__builtin_copysignf: |
| 964 | case Builtin::BI__builtin_copysignl: |
| 965 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::copysign)); |
| 966 | |
| 967 | case Builtin::BIcos: |
| 968 | case Builtin::BIcosf: |
| 969 | case Builtin::BIcosl: |
| 970 | case Builtin::BI__builtin_cos: |
| 971 | case Builtin::BI__builtin_cosf: |
| 972 | case Builtin::BI__builtin_cosl: |
| 973 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::cos)); |
| 974 | |
| 975 | case Builtin::BIexp: |
| 976 | case Builtin::BIexpf: |
| 977 | case Builtin::BIexpl: |
| 978 | case Builtin::BI__builtin_exp: |
| 979 | case Builtin::BI__builtin_expf: |
| 980 | case Builtin::BI__builtin_expl: |
| 981 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::exp)); |
| 982 | |
| 983 | case Builtin::BIexp2: |
| 984 | case Builtin::BIexp2f: |
| 985 | case Builtin::BIexp2l: |
| 986 | case Builtin::BI__builtin_exp2: |
| 987 | case Builtin::BI__builtin_exp2f: |
| 988 | case Builtin::BI__builtin_exp2l: |
| 989 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::exp2)); |
| 990 | |
| 991 | case Builtin::BIfabs: |
| 992 | case Builtin::BIfabsf: |
| 993 | case Builtin::BIfabsl: |
| 994 | case Builtin::BI__builtin_fabs: |
| 995 | case Builtin::BI__builtin_fabsf: |
| 996 | case Builtin::BI__builtin_fabsl: |
| 997 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::fabs)); |
| 998 | |
| 999 | case Builtin::BIfloor: |
| 1000 | case Builtin::BIfloorf: |
| 1001 | case Builtin::BIfloorl: |
| 1002 | case Builtin::BI__builtin_floor: |
| 1003 | case Builtin::BI__builtin_floorf: |
| 1004 | case Builtin::BI__builtin_floorl: |
| 1005 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::floor)); |
| 1006 | |
| 1007 | case Builtin::BIfma: |
| 1008 | case Builtin::BIfmaf: |
| 1009 | case Builtin::BIfmal: |
| 1010 | case Builtin::BI__builtin_fma: |
| 1011 | case Builtin::BI__builtin_fmaf: |
| 1012 | case Builtin::BI__builtin_fmal: |
| 1013 | return RValue::get(emitTernaryBuiltin(*this, E, Intrinsic::fma)); |
| 1014 | |
| 1015 | case Builtin::BIfmax: |
| 1016 | case Builtin::BIfmaxf: |
| 1017 | case Builtin::BIfmaxl: |
| 1018 | case Builtin::BI__builtin_fmax: |
| 1019 | case Builtin::BI__builtin_fmaxf: |
| 1020 | case Builtin::BI__builtin_fmaxl: |
| 1021 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::maxnum)); |
| 1022 | |
| 1023 | case Builtin::BIfmin: |
| 1024 | case Builtin::BIfminf: |
| 1025 | case Builtin::BIfminl: |
| 1026 | case Builtin::BI__builtin_fmin: |
| 1027 | case Builtin::BI__builtin_fminf: |
| 1028 | case Builtin::BI__builtin_fminl: |
| 1029 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::minnum)); |
| 1030 | |
Sanjay Patel | 08fba37 | 2017-12-02 17:52:00 +0000 | [diff] [blame] | 1031 | // fmod() is a special-case. It maps to the frem instruction rather than an |
| 1032 | // LLVM intrinsic. |
| 1033 | case Builtin::BIfmod: |
| 1034 | case Builtin::BIfmodf: |
| 1035 | case Builtin::BIfmodl: |
| 1036 | case Builtin::BI__builtin_fmod: |
| 1037 | case Builtin::BI__builtin_fmodf: |
| 1038 | case Builtin::BI__builtin_fmodl: { |
| 1039 | Value *Arg1 = EmitScalarExpr(E->getArg(0)); |
| 1040 | Value *Arg2 = EmitScalarExpr(E->getArg(1)); |
| 1041 | return RValue::get(Builder.CreateFRem(Arg1, Arg2, "fmod")); |
| 1042 | } |
| 1043 | |
Sanjay Patel | 3e287b4 | 2017-12-01 23:15:52 +0000 | [diff] [blame] | 1044 | case Builtin::BIlog: |
| 1045 | case Builtin::BIlogf: |
| 1046 | case Builtin::BIlogl: |
| 1047 | case Builtin::BI__builtin_log: |
| 1048 | case Builtin::BI__builtin_logf: |
| 1049 | case Builtin::BI__builtin_logl: |
| 1050 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::log)); |
| 1051 | |
| 1052 | case Builtin::BIlog10: |
| 1053 | case Builtin::BIlog10f: |
| 1054 | case Builtin::BIlog10l: |
| 1055 | case Builtin::BI__builtin_log10: |
| 1056 | case Builtin::BI__builtin_log10f: |
| 1057 | case Builtin::BI__builtin_log10l: |
| 1058 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::log10)); |
| 1059 | |
| 1060 | case Builtin::BIlog2: |
| 1061 | case Builtin::BIlog2f: |
| 1062 | case Builtin::BIlog2l: |
| 1063 | case Builtin::BI__builtin_log2: |
| 1064 | case Builtin::BI__builtin_log2f: |
| 1065 | case Builtin::BI__builtin_log2l: |
| 1066 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::log2)); |
| 1067 | |
| 1068 | case Builtin::BInearbyint: |
| 1069 | case Builtin::BInearbyintf: |
| 1070 | case Builtin::BInearbyintl: |
| 1071 | case Builtin::BI__builtin_nearbyint: |
| 1072 | case Builtin::BI__builtin_nearbyintf: |
| 1073 | case Builtin::BI__builtin_nearbyintl: |
| 1074 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::nearbyint)); |
| 1075 | |
| 1076 | case Builtin::BIpow: |
| 1077 | case Builtin::BIpowf: |
| 1078 | case Builtin::BIpowl: |
| 1079 | case Builtin::BI__builtin_pow: |
| 1080 | case Builtin::BI__builtin_powf: |
| 1081 | case Builtin::BI__builtin_powl: |
| 1082 | return RValue::get(emitBinaryBuiltin(*this, E, Intrinsic::pow)); |
| 1083 | |
| 1084 | case Builtin::BIrint: |
| 1085 | case Builtin::BIrintf: |
| 1086 | case Builtin::BIrintl: |
| 1087 | case Builtin::BI__builtin_rint: |
| 1088 | case Builtin::BI__builtin_rintf: |
| 1089 | case Builtin::BI__builtin_rintl: |
| 1090 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::rint)); |
| 1091 | |
| 1092 | case Builtin::BIround: |
| 1093 | case Builtin::BIroundf: |
| 1094 | case Builtin::BIroundl: |
| 1095 | case Builtin::BI__builtin_round: |
| 1096 | case Builtin::BI__builtin_roundf: |
| 1097 | case Builtin::BI__builtin_roundl: |
| 1098 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::round)); |
| 1099 | |
| 1100 | case Builtin::BIsin: |
| 1101 | case Builtin::BIsinf: |
| 1102 | case Builtin::BIsinl: |
| 1103 | case Builtin::BI__builtin_sin: |
| 1104 | case Builtin::BI__builtin_sinf: |
| 1105 | case Builtin::BI__builtin_sinl: |
| 1106 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::sin)); |
| 1107 | |
| 1108 | case Builtin::BIsqrt: |
| 1109 | case Builtin::BIsqrtf: |
| 1110 | case Builtin::BIsqrtl: |
| 1111 | case Builtin::BI__builtin_sqrt: |
| 1112 | case Builtin::BI__builtin_sqrtf: |
| 1113 | case Builtin::BI__builtin_sqrtl: |
| 1114 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::sqrt)); |
| 1115 | |
| 1116 | case Builtin::BItrunc: |
| 1117 | case Builtin::BItruncf: |
| 1118 | case Builtin::BItruncl: |
| 1119 | case Builtin::BI__builtin_trunc: |
| 1120 | case Builtin::BI__builtin_truncf: |
| 1121 | case Builtin::BI__builtin_truncl: |
| 1122 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::trunc)); |
| 1123 | |
| 1124 | default: |
| 1125 | break; |
| 1126 | } |
| 1127 | } |
| 1128 | |
Chris Lattner | 24355b5 | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 1129 | switch (BuiltinID) { |
Sanjay Patel | 0c0f77d | 2017-12-02 16:29:34 +0000 | [diff] [blame] | 1130 | default: break; |
Chris Lattner | a97132a | 2008-10-06 07:26:43 +0000 | [diff] [blame] | 1131 | case Builtin::BI__builtin___CFStringMakeConstantString: |
David Chisnall | 481e3a8 | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 1132 | case Builtin::BI__builtin___NSStringMakeConstantString: |
John McCall | de0fe07 | 2017-08-15 21:42:52 +0000 | [diff] [blame] | 1133 | return RValue::get(ConstantEmitter(*this).emitAbstract(E, E->getType())); |
Chris Lattner | 0bf6791 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 1134 | case Builtin::BI__builtin_stdarg_start: |
Anders Carlsson | 24ebce6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 1135 | case Builtin::BI__builtin_va_start: |
Reid Kleckner | 597e81d | 2014-03-26 15:38:33 +0000 | [diff] [blame] | 1136 | case Builtin::BI__va_start: |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 1137 | case Builtin::BI__builtin_va_end: |
| 1138 | return RValue::get( |
| 1139 | EmitVAStartEnd(BuiltinID == Builtin::BI__va_start |
| 1140 | ? EmitScalarExpr(E->getArg(0)) |
| 1141 | : EmitVAListRef(E->getArg(0)).getPointer(), |
| 1142 | BuiltinID != Builtin::BI__builtin_va_end)); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 1143 | case Builtin::BI__builtin_va_copy: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1144 | Value *DstPtr = EmitVAListRef(E->getArg(0)).getPointer(); |
| 1145 | Value *SrcPtr = EmitVAListRef(E->getArg(1)).getPointer(); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 1146 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1147 | llvm::Type *Type = Int8PtrTy; |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 1148 | |
| 1149 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 1150 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1151 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(Intrinsic::vacopy), |
| 1152 | {DstPtr, SrcPtr})); |
Anders Carlsson | c0b0e59 | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 1153 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1154 | case Builtin::BI__builtin_abs: |
Eli Friedman | 65499b4 | 2012-01-17 22:11:30 +0000 | [diff] [blame] | 1155 | case Builtin::BI__builtin_labs: |
| 1156 | case Builtin::BI__builtin_llabs: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 1158 | |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 1159 | Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1160 | Value *CmpResult = |
| 1161 | Builder.CreateICmpSGE(ArgValue, |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 1162 | llvm::Constant::getNullValue(ArgValue->getType()), |
Chris Lattner | 28ee5b3 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 1163 | "abscond"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | Value *Result = |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 1165 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | |
Anders Carlsson | 4f8eb12 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 1167 | return RValue::get(Result); |
| 1168 | } |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 1169 | case Builtin::BI__builtin_conj: |
| 1170 | case Builtin::BI__builtin_conjf: |
| 1171 | case Builtin::BI__builtin_conjl: { |
| 1172 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 1173 | Value *Real = ComplexVal.first; |
| 1174 | Value *Imag = ComplexVal.second; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1175 | Value *Zero = |
| 1176 | Imag->getType()->isFPOrFPVectorTy() |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 1177 | ? llvm::ConstantFP::getZeroValueForNegation(Imag->getType()) |
| 1178 | : llvm::Constant::getNullValue(Imag->getType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1179 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 1180 | Imag = Builder.CreateFSub(Zero, Imag, "sub"); |
| 1181 | return RValue::getComplex(std::make_pair(Real, Imag)); |
| 1182 | } |
| 1183 | case Builtin::BI__builtin_creal: |
| 1184 | case Builtin::BI__builtin_crealf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 1185 | case Builtin::BI__builtin_creall: |
| 1186 | case Builtin::BIcreal: |
| 1187 | case Builtin::BIcrealf: |
| 1188 | case Builtin::BIcreall: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 1189 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 1190 | return RValue::get(ComplexVal.first); |
| 1191 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1192 | |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 1193 | case Builtin::BI__builtin_cimag: |
| 1194 | case Builtin::BI__builtin_cimagf: |
Meador Inge | b97878a | 2012-12-18 20:58:04 +0000 | [diff] [blame] | 1195 | case Builtin::BI__builtin_cimagl: |
| 1196 | case Builtin::BIcimag: |
| 1197 | case Builtin::BIcimagf: |
| 1198 | case Builtin::BIcimagl: { |
Fariborz Jahanian | 1ac1119 | 2012-08-14 20:09:28 +0000 | [diff] [blame] | 1199 | ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0)); |
| 1200 | return RValue::get(ComplexVal.second); |
| 1201 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1202 | |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 1203 | case Builtin::BI__builtin_ctzs: |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 1204 | case Builtin::BI__builtin_ctz: |
| 1205 | case Builtin::BI__builtin_ctzl: |
| 1206 | case Builtin::BI__builtin_ctzll: { |
Vedant Kumar | 10c3102 | 2017-07-29 00:19:51 +0000 | [diff] [blame] | 1207 | Value *ArgValue = EmitCheckedArgForBuiltin(E->getArg(0), BCK_CTZPassedZero); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1208 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1209 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1210 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 1211 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1212 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 1213 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1214 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 1215 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 1216 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 1217 | "cast"); |
Anders Carlsson | 093f1a0 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 1218 | return RValue::get(Result); |
| 1219 | } |
Benjamin Kramer | 1412816 | 2012-01-28 18:42:57 +0000 | [diff] [blame] | 1220 | case Builtin::BI__builtin_clzs: |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 1221 | case Builtin::BI__builtin_clz: |
| 1222 | case Builtin::BI__builtin_clzl: |
| 1223 | case Builtin::BI__builtin_clzll: { |
Vedant Kumar | 10c3102 | 2017-07-29 00:19:51 +0000 | [diff] [blame] | 1224 | Value *ArgValue = EmitCheckedArgForBuiltin(E->getArg(0), BCK_CLZPassedZero); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1226 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1227 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 1228 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1229 | llvm::Type *ResultType = ConvertType(E->getType()); |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 1230 | Value *ZeroUndef = Builder.getInt1(getTarget().isCLZForZeroUndef()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1231 | Value *Result = Builder.CreateCall(F, {ArgValue, ZeroUndef}); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 1232 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 1233 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 1234 | "cast"); |
Eli Friedman | 5e2281e | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 1235 | return RValue::get(Result); |
| 1236 | } |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1237 | case Builtin::BI__builtin_ffs: |
| 1238 | case Builtin::BI__builtin_ffsl: |
| 1239 | case Builtin::BI__builtin_ffsll: { |
| 1240 | // ffs(x) -> x ? cttz(x) + 1 : 0 |
| 1241 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1243 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1244 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1246 | llvm::Type *ResultType = ConvertType(E->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1247 | Value *Tmp = |
| 1248 | Builder.CreateAdd(Builder.CreateCall(F, {ArgValue, Builder.getTrue()}), |
| 1249 | llvm::ConstantInt::get(ArgType, 1)); |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 1250 | Value *Zero = llvm::Constant::getNullValue(ArgType); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1251 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); |
| 1252 | Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); |
| 1253 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 1254 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 1255 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1256 | return RValue::get(Result); |
| 1257 | } |
| 1258 | case Builtin::BI__builtin_parity: |
| 1259 | case Builtin::BI__builtin_parityl: |
| 1260 | case Builtin::BI__builtin_parityll: { |
| 1261 | // parity(x) -> ctpop(x) & 1 |
| 1262 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1264 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1265 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1266 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1267 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 1268 | Value *Tmp = Builder.CreateCall(F, ArgValue); |
| 1269 | Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1)); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1270 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 1271 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 1272 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1273 | return RValue::get(Result); |
| 1274 | } |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 1275 | case Builtin::BI__popcnt16: |
| 1276 | case Builtin::BI__popcnt: |
| 1277 | case Builtin::BI__popcnt64: |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1278 | case Builtin::BI__builtin_popcount: |
| 1279 | case Builtin::BI__builtin_popcountl: |
| 1280 | case Builtin::BI__builtin_popcountll: { |
| 1281 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1282 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1283 | llvm::Type *ArgType = ArgValue->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1284 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1286 | llvm::Type *ResultType = ConvertType(E->getType()); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 1287 | Value *Result = Builder.CreateCall(F, ArgValue); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1288 | if (Result->getType() != ResultType) |
Duncan Sands | 7876dad | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 1289 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 1290 | "cast"); |
Daniel Dunbar | d93abc3 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 1291 | return RValue::get(Result); |
| 1292 | } |
Albert Gutowski | b6a11ac | 2016-09-08 22:32:19 +0000 | [diff] [blame] | 1293 | case Builtin::BI_rotr8: |
| 1294 | case Builtin::BI_rotr16: |
| 1295 | case Builtin::BI_rotr: |
| 1296 | case Builtin::BI_lrotr: |
| 1297 | case Builtin::BI_rotr64: { |
| 1298 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 1299 | Value *Shift = EmitScalarExpr(E->getArg(1)); |
| 1300 | |
| 1301 | llvm::Type *ArgType = Val->getType(); |
| 1302 | Shift = Builder.CreateIntCast(Shift, ArgType, false); |
| 1303 | unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth(); |
| 1304 | Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth); |
| 1305 | Value *ArgZero = llvm::Constant::getNullValue(ArgType); |
| 1306 | |
| 1307 | Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1); |
| 1308 | Shift = Builder.CreateAnd(Shift, Mask); |
| 1309 | Value *LeftShift = Builder.CreateSub(ArgTypeSize, Shift); |
| 1310 | |
| 1311 | Value *RightShifted = Builder.CreateLShr(Val, Shift); |
| 1312 | Value *LeftShifted = Builder.CreateShl(Val, LeftShift); |
| 1313 | Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted); |
| 1314 | |
| 1315 | Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero); |
| 1316 | Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated); |
| 1317 | return RValue::get(Result); |
| 1318 | } |
| 1319 | case Builtin::BI_rotl8: |
| 1320 | case Builtin::BI_rotl16: |
| 1321 | case Builtin::BI_rotl: |
| 1322 | case Builtin::BI_lrotl: |
| 1323 | case Builtin::BI_rotl64: { |
| 1324 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 1325 | Value *Shift = EmitScalarExpr(E->getArg(1)); |
| 1326 | |
| 1327 | llvm::Type *ArgType = Val->getType(); |
| 1328 | Shift = Builder.CreateIntCast(Shift, ArgType, false); |
| 1329 | unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth(); |
| 1330 | Value *ArgTypeSize = llvm::ConstantInt::get(ArgType, ArgWidth); |
| 1331 | Value *ArgZero = llvm::Constant::getNullValue(ArgType); |
| 1332 | |
| 1333 | Value *Mask = llvm::ConstantInt::get(ArgType, ArgWidth - 1); |
| 1334 | Shift = Builder.CreateAnd(Shift, Mask); |
| 1335 | Value *RightShift = Builder.CreateSub(ArgTypeSize, Shift); |
| 1336 | |
| 1337 | Value *LeftShifted = Builder.CreateShl(Val, Shift); |
| 1338 | Value *RightShifted = Builder.CreateLShr(Val, RightShift); |
| 1339 | Value *Rotated = Builder.CreateOr(LeftShifted, RightShifted); |
| 1340 | |
| 1341 | Value *ShiftIsZero = Builder.CreateICmpEQ(Shift, ArgZero); |
| 1342 | Value *Result = Builder.CreateSelect(ShiftIsZero, Val, Rotated); |
| 1343 | return RValue::get(Result); |
| 1344 | } |
Sanjay Patel | a24296b | 2015-09-02 20:01:30 +0000 | [diff] [blame] | 1345 | case Builtin::BI__builtin_unpredictable: { |
| 1346 | // Always return the argument of __builtin_unpredictable. LLVM does not |
| 1347 | // handle this builtin. Metadata for this builtin should be added directly |
| 1348 | // to instructions such as branches or switches that use it. |
| 1349 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
| 1350 | } |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 1351 | case Builtin::BI__builtin_expect: { |
Fariborz Jahanian | 24ac159 | 2011-04-25 23:10:07 +0000 | [diff] [blame] | 1352 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1353 | llvm::Type *ArgType = ArgValue->getType(); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 1354 | |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 1355 | Value *ExpectedValue = EmitScalarExpr(E->getArg(1)); |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 1356 | // Don't generate llvm.expect on -O0 as the backend won't use it for |
| 1357 | // anything. |
| 1358 | // Note, we still IRGen ExpectedValue because it could have side-effects. |
| 1359 | if (CGM.getCodeGenOpts().OptimizationLevel == 0) |
| 1360 | return RValue::get(ArgValue); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 1361 | |
Pete Cooper | f051cbf | 2015-01-26 20:51:58 +0000 | [diff] [blame] | 1362 | Value *FnExpect = CGM.getIntrinsic(Intrinsic::expect, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1363 | Value *Result = |
| 1364 | Builder.CreateCall(FnExpect, {ArgValue, ExpectedValue}, "expval"); |
Jakub Staszak | d2cf2cb | 2011-07-08 22:45:14 +0000 | [diff] [blame] | 1365 | return RValue::get(Result); |
Fariborz Jahanian | 0ebca28 | 2010-07-26 23:11:03 +0000 | [diff] [blame] | 1366 | } |
Hal Finkel | bcc0608 | 2014-09-07 22:58:14 +0000 | [diff] [blame] | 1367 | case Builtin::BI__builtin_assume_aligned: { |
| 1368 | Value *PtrValue = EmitScalarExpr(E->getArg(0)); |
| 1369 | Value *OffsetValue = |
| 1370 | (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr; |
| 1371 | |
| 1372 | Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); |
| 1373 | ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue); |
| 1374 | unsigned Alignment = (unsigned) AlignmentCI->getZExtValue(); |
| 1375 | |
| 1376 | EmitAlignmentAssumption(PtrValue, Alignment, OffsetValue); |
| 1377 | return RValue::get(PtrValue); |
| 1378 | } |
| 1379 | case Builtin::BI__assume: |
| 1380 | case Builtin::BI__builtin_assume: { |
| 1381 | if (E->getArg(0)->HasSideEffects(getContext())) |
| 1382 | return RValue::get(nullptr); |
| 1383 | |
| 1384 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 1385 | Value *FnAssume = CGM.getIntrinsic(Intrinsic::assume); |
| 1386 | return RValue::get(Builder.CreateCall(FnAssume, ArgValue)); |
| 1387 | } |
Benjamin Kramer | a801f4a | 2012-10-06 14:42:22 +0000 | [diff] [blame] | 1388 | case Builtin::BI__builtin_bswap16: |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 1389 | case Builtin::BI__builtin_bswap32: |
| 1390 | case Builtin::BI__builtin_bswap64: { |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 1391 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bswap)); |
| 1392 | } |
Matt Arsenault | 08087c5 | 2016-03-23 22:14:43 +0000 | [diff] [blame] | 1393 | case Builtin::BI__builtin_bitreverse8: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 1394 | case Builtin::BI__builtin_bitreverse16: |
| 1395 | case Builtin::BI__builtin_bitreverse32: |
| 1396 | case Builtin::BI__builtin_bitreverse64: { |
| 1397 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::bitreverse)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | } |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 1399 | case Builtin::BI__builtin_object_size: { |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 1400 | unsigned Type = |
| 1401 | E->getArg(1)->EvaluateKnownConstInt(getContext()).getZExtValue(); |
| 1402 | auto *ResType = cast<llvm::IntegerType>(ConvertType(E->getType())); |
Richard Smith | 01ade17 | 2012-05-23 04:13:20 +0000 | [diff] [blame] | 1403 | |
George Burgess IV | 3e3bb95b | 2015-12-02 21:58:08 +0000 | [diff] [blame] | 1404 | // We pass this builtin onto the optimizer so that it can figure out the |
| 1405 | // object size in more complex cases. |
George Burgess IV | 0d6592a | 2017-02-23 05:59:56 +0000 | [diff] [blame] | 1406 | return RValue::get(emitBuiltinObjectSize(E->getArg(0), Type, ResType, |
| 1407 | /*EmittedE=*/nullptr)); |
Daniel Dunbar | b0d34c8 | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 1408 | } |
Daniel Dunbar | b725726 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 1409 | case Builtin::BI__builtin_prefetch: { |
| 1410 | Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); |
| 1411 | // FIXME: Technically these constants should of type 'int', yes? |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1413 | llvm::ConstantInt::get(Int32Ty, 0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1415 | llvm::ConstantInt::get(Int32Ty, 3); |
Bruno Cardoso Lopes | 3b0297a | 2011-06-14 05:00:30 +0000 | [diff] [blame] | 1416 | Value *Data = llvm::ConstantInt::get(Int32Ty, 1); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1417 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1418 | return RValue::get(Builder.CreateCall(F, {Address, RW, Locality, Data})); |
Anders Carlsson | ef93b9d | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 1419 | } |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 1420 | case Builtin::BI__builtin_readcyclecounter: { |
| 1421 | Value *F = CGM.getIntrinsic(Intrinsic::readcyclecounter); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1422 | return RValue::get(Builder.CreateCall(F)); |
Hal Finkel | 3fadbb5 | 2012-08-05 22:03:08 +0000 | [diff] [blame] | 1423 | } |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 1424 | case Builtin::BI__builtin___clear_cache: { |
| 1425 | Value *Begin = EmitScalarExpr(E->getArg(0)); |
| 1426 | Value *End = EmitScalarExpr(E->getArg(1)); |
| 1427 | Value *F = CGM.getIntrinsic(Intrinsic::clear_cache); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1428 | return RValue::get(Builder.CreateCall(F, {Begin, End})); |
Renato Golin | c491a8d | 2014-03-26 15:36:05 +0000 | [diff] [blame] | 1429 | } |
Akira Hatanaka | 85365cd | 2015-07-02 22:15:41 +0000 | [diff] [blame] | 1430 | case Builtin::BI__builtin_trap: |
| 1431 | return RValue::get(EmitTrapCall(Intrinsic::trap)); |
| 1432 | case Builtin::BI__debugbreak: |
| 1433 | return RValue::get(EmitTrapCall(Intrinsic::debugtrap)); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 1434 | case Builtin::BI__builtin_unreachable: { |
Vedant Kumar | 09b5bfd | 2017-12-21 00:10:25 +0000 | [diff] [blame] | 1435 | EmitUnreachable(E->getExprLoc()); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1436 | |
| 1437 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1438 | EmitBlock(createBasicBlock("unreachable.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1439 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1440 | return RValue::get(nullptr); |
Chris Lattner | bf20638 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 1441 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1442 | |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 1443 | case Builtin::BI__builtin_powi: |
| 1444 | case Builtin::BI__builtin_powif: |
Reid Kleckner | 1fcccdd | 2015-02-05 00:24:57 +0000 | [diff] [blame] | 1445 | case Builtin::BI__builtin_powil: { |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 1446 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 1447 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1448 | llvm::Type *ArgType = Base->getType(); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1449 | Value *F = CGM.getIntrinsic(Intrinsic::powi, ArgType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1450 | return RValue::get(Builder.CreateCall(F, {Base, Exponent})); |
Daniel Dunbar | c2f6796 | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 1453 | case Builtin::BI__builtin_isgreater: |
| 1454 | case Builtin::BI__builtin_isgreaterequal: |
| 1455 | case Builtin::BI__builtin_isless: |
| 1456 | case Builtin::BI__builtin_islessequal: |
| 1457 | case Builtin::BI__builtin_islessgreater: |
| 1458 | case Builtin::BI__builtin_isunordered: { |
| 1459 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 1460 | // floating point values. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1461 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 1462 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1463 | |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 1464 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1465 | default: llvm_unreachable("Unknown ordered comparison"); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 1466 | case Builtin::BI__builtin_isgreater: |
| 1467 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 1468 | break; |
| 1469 | case Builtin::BI__builtin_isgreaterequal: |
| 1470 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 1471 | break; |
| 1472 | case Builtin::BI__builtin_isless: |
| 1473 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 1474 | break; |
| 1475 | case Builtin::BI__builtin_islessequal: |
| 1476 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 1477 | break; |
| 1478 | case Builtin::BI__builtin_islessgreater: |
| 1479 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 1480 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1481 | case Builtin::BI__builtin_isunordered: |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 1482 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 1483 | break; |
| 1484 | } |
| 1485 | // ZExt bool to int type. |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 1486 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()))); |
Chris Lattner | 6c9ffe9 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 1487 | } |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 1488 | case Builtin::BI__builtin_isnan: { |
| 1489 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 1490 | V = Builder.CreateFCmpUNO(V, V, "cmp"); |
Benjamin Kramer | 76399eb | 2011-09-27 21:06:10 +0000 | [diff] [blame] | 1491 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
Eli Friedman | 1c277d0 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 1492 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1493 | |
Dehao Chen | 5d4f0be | 2016-09-14 17:34:14 +0000 | [diff] [blame] | 1494 | case Builtin::BIfinite: |
| 1495 | case Builtin::BI__finite: |
| 1496 | case Builtin::BIfinitef: |
| 1497 | case Builtin::BI__finitef: |
| 1498 | case Builtin::BIfinitel: |
| 1499 | case Builtin::BI__finitel: |
Sanjay Patel | ae7a9df | 2016-04-07 14:29:05 +0000 | [diff] [blame] | 1500 | case Builtin::BI__builtin_isinf: |
| 1501 | case Builtin::BI__builtin_isfinite: { |
| 1502 | // isinf(x) --> fabs(x) == infinity |
| 1503 | // isfinite(x) --> fabs(x) != infinity |
| 1504 | // x != NaN via the ordered compare in either case. |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 1505 | Value *V = EmitScalarExpr(E->getArg(0)); |
Sanjay Patel | ae7a9df | 2016-04-07 14:29:05 +0000 | [diff] [blame] | 1506 | Value *Fabs = EmitFAbs(*this, V); |
| 1507 | Constant *Infinity = ConstantFP::getInfinity(V->getType()); |
| 1508 | CmpInst::Predicate Pred = (BuiltinID == Builtin::BI__builtin_isinf) |
| 1509 | ? CmpInst::FCMP_OEQ |
| 1510 | : CmpInst::FCMP_ONE; |
| 1511 | Value *FCmp = Builder.CreateFCmp(Pred, Fabs, Infinity, "cmpinf"); |
| 1512 | return RValue::get(Builder.CreateZExt(FCmp, ConvertType(E->getType()))); |
Chris Lattner | 43660c5 | 2010-05-06 05:35:16 +0000 | [diff] [blame] | 1513 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1514 | |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 1515 | case Builtin::BI__builtin_isinf_sign: { |
| 1516 | // isinf_sign(x) -> fabs(x) == infinity ? (signbit(x) ? -1 : 1) : 0 |
| 1517 | Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 1518 | Value *AbsArg = EmitFAbs(*this, Arg); |
| 1519 | Value *IsInf = Builder.CreateFCmpOEQ( |
| 1520 | AbsArg, ConstantFP::getInfinity(Arg->getType()), "isinf"); |
| 1521 | Value *IsNeg = EmitSignBit(*this, Arg); |
| 1522 | |
| 1523 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 1524 | Value *Zero = Constant::getNullValue(IntTy); |
| 1525 | Value *One = ConstantInt::get(IntTy, 1); |
| 1526 | Value *NegativeOne = ConstantInt::get(IntTy, -1); |
| 1527 | Value *SignResult = Builder.CreateSelect(IsNeg, NegativeOne, One); |
| 1528 | Value *Result = Builder.CreateSelect(IsInf, SignResult, Zero); |
| 1529 | return RValue::get(Result); |
| 1530 | } |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 1531 | |
| 1532 | case Builtin::BI__builtin_isnormal: { |
| 1533 | // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min |
| 1534 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 1535 | Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq"); |
| 1536 | |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 1537 | Value *Abs = EmitFAbs(*this, V); |
Benjamin Kramer | fdb61d7 | 2010-05-19 11:24:26 +0000 | [diff] [blame] | 1538 | Value *IsLessThanInf = |
| 1539 | Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf"); |
| 1540 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 1541 | getContext().getFloatTypeSemantics(E->getArg(0)->getType())); |
| 1542 | Value *IsNormal = |
| 1543 | Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest), |
| 1544 | "isnormal"); |
| 1545 | V = Builder.CreateAnd(Eq, IsLessThanInf, "and"); |
| 1546 | V = Builder.CreateAnd(V, IsNormal, "and"); |
| 1547 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()))); |
| 1548 | } |
| 1549 | |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 1550 | case Builtin::BI__builtin_fpclassify: { |
| 1551 | Value *V = EmitScalarExpr(E->getArg(5)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1552 | llvm::Type *Ty = ConvertType(E->getArg(5)->getType()); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 1553 | |
| 1554 | // Create Result |
| 1555 | BasicBlock *Begin = Builder.GetInsertBlock(); |
| 1556 | BasicBlock *End = createBasicBlock("fpclassify_end", this->CurFn); |
| 1557 | Builder.SetInsertPoint(End); |
| 1558 | PHINode *Result = |
Jay Foad | 20c0f02 | 2011-03-30 11:28:58 +0000 | [diff] [blame] | 1559 | Builder.CreatePHI(ConvertType(E->getArg(0)->getType()), 4, |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 1560 | "fpclassify_result"); |
| 1561 | |
| 1562 | // if (V==0) return FP_ZERO |
| 1563 | Builder.SetInsertPoint(Begin); |
| 1564 | Value *IsZero = Builder.CreateFCmpOEQ(V, Constant::getNullValue(Ty), |
| 1565 | "iszero"); |
| 1566 | Value *ZeroLiteral = EmitScalarExpr(E->getArg(4)); |
| 1567 | BasicBlock *NotZero = createBasicBlock("fpclassify_not_zero", this->CurFn); |
| 1568 | Builder.CreateCondBr(IsZero, End, NotZero); |
| 1569 | Result->addIncoming(ZeroLiteral, Begin); |
| 1570 | |
| 1571 | // if (V != V) return FP_NAN |
| 1572 | Builder.SetInsertPoint(NotZero); |
| 1573 | Value *IsNan = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 1574 | Value *NanLiteral = EmitScalarExpr(E->getArg(0)); |
| 1575 | BasicBlock *NotNan = createBasicBlock("fpclassify_not_nan", this->CurFn); |
| 1576 | Builder.CreateCondBr(IsNan, End, NotNan); |
| 1577 | Result->addIncoming(NanLiteral, NotZero); |
| 1578 | |
| 1579 | // if (fabs(V) == infinity) return FP_INFINITY |
| 1580 | Builder.SetInsertPoint(NotNan); |
Reid Kleckner | 4cad00a | 2014-11-03 23:51:40 +0000 | [diff] [blame] | 1581 | Value *VAbs = EmitFAbs(*this, V); |
Benjamin Kramer | 7039fcb | 2010-06-14 10:30:41 +0000 | [diff] [blame] | 1582 | Value *IsInf = |
| 1583 | Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(V->getType()), |
| 1584 | "isinf"); |
| 1585 | Value *InfLiteral = EmitScalarExpr(E->getArg(1)); |
| 1586 | BasicBlock *NotInf = createBasicBlock("fpclassify_not_inf", this->CurFn); |
| 1587 | Builder.CreateCondBr(IsInf, End, NotInf); |
| 1588 | Result->addIncoming(InfLiteral, NotNan); |
| 1589 | |
| 1590 | // if (fabs(V) >= MIN_NORMAL) return FP_NORMAL else FP_SUBNORMAL |
| 1591 | Builder.SetInsertPoint(NotInf); |
| 1592 | APFloat Smallest = APFloat::getSmallestNormalized( |
| 1593 | getContext().getFloatTypeSemantics(E->getArg(5)->getType())); |
| 1594 | Value *IsNormal = |
| 1595 | Builder.CreateFCmpUGE(VAbs, ConstantFP::get(V->getContext(), Smallest), |
| 1596 | "isnormal"); |
| 1597 | Value *NormalResult = |
| 1598 | Builder.CreateSelect(IsNormal, EmitScalarExpr(E->getArg(2)), |
| 1599 | EmitScalarExpr(E->getArg(3))); |
| 1600 | Builder.CreateBr(End); |
| 1601 | Result->addIncoming(NormalResult, NotInf); |
| 1602 | |
| 1603 | // return Result |
| 1604 | Builder.SetInsertPoint(End); |
| 1605 | return RValue::get(Result); |
| 1606 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1607 | |
Eli Friedman | f6bd150 | 2009-06-02 07:10:30 +0000 | [diff] [blame] | 1608 | case Builtin::BIalloca: |
Reid Kleckner | 59e4a6f | 2013-11-13 22:58:53 +0000 | [diff] [blame] | 1609 | case Builtin::BI_alloca: |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 1610 | case Builtin::BI__builtin_alloca: { |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 1611 | Value *Size = EmitScalarExpr(E->getArg(0)); |
David Majnemer | 1878da4 | 2016-10-27 17:18:24 +0000 | [diff] [blame] | 1612 | const TargetInfo &TI = getContext().getTargetInfo(); |
| 1613 | // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__. |
| 1614 | unsigned SuitableAlignmentInBytes = |
David Majnemer | bb103d9 | 2016-10-31 16:48:30 +0000 | [diff] [blame] | 1615 | CGM.getContext() |
| 1616 | .toCharUnitsFromBits(TI.getSuitableAlign()) |
| 1617 | .getQuantity(); |
David Majnemer | 1878da4 | 2016-10-27 17:18:24 +0000 | [diff] [blame] | 1618 | AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); |
| 1619 | AI->setAlignment(SuitableAlignmentInBytes); |
| 1620 | return RValue::get(AI); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1621 | } |
David Majnemer | 5116993 | 2016-10-31 05:37:48 +0000 | [diff] [blame] | 1622 | |
| 1623 | case Builtin::BI__builtin_alloca_with_align: { |
| 1624 | Value *Size = EmitScalarExpr(E->getArg(0)); |
David Majnemer | bb103d9 | 2016-10-31 16:48:30 +0000 | [diff] [blame] | 1625 | Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1)); |
| 1626 | auto *AlignmentInBitsCI = cast<ConstantInt>(AlignmentInBitsValue); |
| 1627 | unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue(); |
| 1628 | unsigned AlignmentInBytes = |
| 1629 | CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity(); |
David Majnemer | 5116993 | 2016-10-31 05:37:48 +0000 | [diff] [blame] | 1630 | AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); |
| 1631 | AI->setAlignment(AlignmentInBytes); |
| 1632 | return RValue::get(AI); |
| 1633 | } |
| 1634 | |
Eli Friedman | d6ef69a | 2010-01-23 19:00:10 +0000 | [diff] [blame] | 1635 | case Builtin::BIbzero: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1636 | case Builtin::BI__builtin_bzero: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1637 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1638 | Value *SizeVal = EmitScalarExpr(E->getArg(1)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1639 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1640 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1641 | Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false); |
John McCall | 26d55e0 | 2017-11-09 09:32:32 +0000 | [diff] [blame] | 1642 | return RValue::get(nullptr); |
Chris Lattner | 22b9ff4 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 1643 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 1644 | case Builtin::BImemcpy: |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 1645 | case Builtin::BI__builtin_memcpy: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1646 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1647 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1648 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1649 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1650 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1651 | EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1652 | E->getArg(1)->getExprLoc(), FD, 1); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1653 | Builder.CreateMemCpy(Dest, Src, SizeVal, false); |
| 1654 | return RValue::get(Dest.getPointer()); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1655 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1656 | |
Richard Smith | 5e29dd3 | 2017-01-20 00:45:35 +0000 | [diff] [blame] | 1657 | case Builtin::BI__builtin_char_memchr: |
| 1658 | BuiltinID = Builtin::BI__builtin_memchr; |
| 1659 | break; |
| 1660 | |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1661 | case Builtin::BI__builtin___memcpy_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1662 | // 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] | 1663 | llvm::APSInt Size, DstSize; |
| 1664 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 1665 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1666 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1667 | if (Size.ugt(DstSize)) |
| 1668 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1669 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1670 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1671 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1672 | Builder.CreateMemCpy(Dest, Src, SizeVal, false); |
| 1673 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1674 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1675 | |
Fariborz Jahanian | 4a30307 | 2010-06-16 16:22:04 +0000 | [diff] [blame] | 1676 | case Builtin::BI__builtin_objc_memmove_collectable: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1677 | Address DestAddr = EmitPointerWithAlignment(E->getArg(0)); |
| 1678 | Address SrcAddr = EmitPointerWithAlignment(E->getArg(1)); |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 1679 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1680 | CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1681 | DestAddr, SrcAddr, SizeVal); |
| 1682 | return RValue::get(DestAddr.getPointer()); |
Fariborz Jahanian | 021510e | 2010-06-15 22:44:06 +0000 | [diff] [blame] | 1683 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1684 | |
| 1685 | case Builtin::BI__builtin___memmove_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1686 | // 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] | 1687 | llvm::APSInt Size, DstSize; |
| 1688 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 1689 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1690 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1691 | if (Size.ugt(DstSize)) |
| 1692 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1693 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1694 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1695 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1696 | Builder.CreateMemMove(Dest, Src, SizeVal, false); |
| 1697 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 1700 | case Builtin::BImemmove: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1701 | case Builtin::BI__builtin_memmove: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1702 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
| 1703 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1704 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1705 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1706 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1707 | EmitNonNullArgCheck(RValue::get(Src.getPointer()), E->getArg(1)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1708 | E->getArg(1)->getExprLoc(), FD, 1); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1709 | Builder.CreateMemMove(Dest, Src, SizeVal, false); |
| 1710 | return RValue::get(Dest.getPointer()); |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1711 | } |
Eli Friedman | 7f4933f | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 1712 | case Builtin::BImemset: |
Daniel Dunbar | 327acd7 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 1713 | case Builtin::BI__builtin_memset: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1714 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Benjamin Kramer | acc6b4e | 2010-12-30 00:13:21 +0000 | [diff] [blame] | 1715 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 1716 | Builder.getInt8Ty()); |
Mon P Wang | cc2ab0c | 2010-04-04 03:10:52 +0000 | [diff] [blame] | 1717 | Value *SizeVal = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1718 | EmitNonNullArgCheck(RValue::get(Dest.getPointer()), E->getArg(0)->getType(), |
Nuno Lopes | 1ba2d78 | 2015-05-30 16:11:40 +0000 | [diff] [blame] | 1719 | E->getArg(0)->getExprLoc(), FD, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1720 | Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); |
| 1721 | return RValue::get(Dest.getPointer()); |
Eli Friedman | a3a4068 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 1722 | } |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1723 | case Builtin::BI__builtin___memset_chk: { |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1724 | // 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] | 1725 | llvm::APSInt Size, DstSize; |
| 1726 | if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) || |
| 1727 | !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext())) |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1728 | break; |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1729 | if (Size.ugt(DstSize)) |
| 1730 | break; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1731 | Address Dest = EmitPointerWithAlignment(E->getArg(0)); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1732 | Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
| 1733 | Builder.getInt8Ty()); |
| 1734 | Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1735 | Builder.CreateMemSet(Dest, ByteVal, SizeVal, false); |
| 1736 | return RValue::get(Dest.getPointer()); |
Chris Lattner | 30107ed | 2011-04-17 00:40:24 +0000 | [diff] [blame] | 1737 | } |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 1738 | case Builtin::BI__builtin_dwarf_cfa: { |
| 1739 | // The offset in bytes from the first argument to the CFA. |
| 1740 | // |
| 1741 | // Why on earth is this in the frontend? Is there any reason at |
| 1742 | // all that the backend can't reasonably determine this while |
| 1743 | // lowering llvm.eh.dwarf.cfa()? |
| 1744 | // |
| 1745 | // TODO: If there's a satisfactory reason, add a target hook for |
| 1746 | // this instead of hard-coding 0, which is correct for most targets. |
| 1747 | int32_t Offset = 0; |
| 1748 | |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1749 | Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 1750 | return RValue::get(Builder.CreateCall(F, |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1751 | llvm::ConstantInt::get(Int32Ty, Offset))); |
John McCall | 515c3c5 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 1752 | } |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1753 | case Builtin::BI__builtin_return_address: { |
John McCall | de0fe07 | 2017-08-15 21:42:52 +0000 | [diff] [blame] | 1754 | Value *Depth = ConstantEmitter(*this).emitAbstract(E->getArg(0), |
| 1755 | getContext().UnsignedIntTy); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1756 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 1757 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1758 | } |
Albert Gutowski | 397d81b | 2016-10-13 16:03:42 +0000 | [diff] [blame] | 1759 | case Builtin::BI_ReturnAddress: { |
| 1760 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress); |
| 1761 | return RValue::get(Builder.CreateCall(F, Builder.getInt32(0))); |
| 1762 | } |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1763 | case Builtin::BI__builtin_frame_address: { |
John McCall | de0fe07 | 2017-08-15 21:42:52 +0000 | [diff] [blame] | 1764 | Value *Depth = ConstantEmitter(*this).emitAbstract(E->getArg(0), |
| 1765 | getContext().UnsignedIntTy); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1766 | Value *F = CGM.getIntrinsic(Intrinsic::frameaddress); |
Anton Korobeynikov | 73d50b9 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 1767 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 53e38bd | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 1768 | } |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 1769 | case Builtin::BI__builtin_extract_return_addr: { |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1770 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1771 | Value *Result = getTargetHooks().decodeReturnAddress(*this, Address); |
| 1772 | return RValue::get(Result); |
| 1773 | } |
| 1774 | case Builtin::BI__builtin_frob_return_addr: { |
| 1775 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1776 | Value *Result = getTargetHooks().encodeReturnAddress(*this, Address); |
| 1777 | return RValue::get(Result); |
Eli Friedman | 5b73b5e | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 1778 | } |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 1779 | case Builtin::BI__builtin_dwarf_sp_column: { |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1780 | llvm::IntegerType *Ty |
John McCall | beec5a0 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 1781 | = cast<llvm::IntegerType>(ConvertType(E->getType())); |
| 1782 | int Column = getTargetHooks().getDwarfEHStackPointer(CGM); |
| 1783 | if (Column == -1) { |
| 1784 | CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column"); |
| 1785 | return RValue::get(llvm::UndefValue::get(Ty)); |
| 1786 | } |
| 1787 | return RValue::get(llvm::ConstantInt::get(Ty, Column, true)); |
| 1788 | } |
| 1789 | case Builtin::BI__builtin_init_dwarf_reg_size_table: { |
| 1790 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 1791 | if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address)) |
| 1792 | CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table"); |
| 1793 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
| 1794 | } |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1795 | case Builtin::BI__builtin_eh_return: { |
| 1796 | Value *Int = EmitScalarExpr(E->getArg(0)); |
| 1797 | Value *Ptr = EmitScalarExpr(E->getArg(1)); |
| 1798 | |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1799 | llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType()); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1800 | assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && |
| 1801 | "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); |
| 1802 | Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 |
| 1803 | ? Intrinsic::eh_return_i32 |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1804 | : Intrinsic::eh_return_i64); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 1805 | Builder.CreateCall(F, {Int, Ptr}); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1806 | Builder.CreateUnreachable(); |
| 1807 | |
| 1808 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1809 | EmitBlock(createBasicBlock("builtin_eh_return.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1810 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1811 | return RValue::get(nullptr); |
John McCall | 66769f8 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 1812 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1813 | case Builtin::BI__builtin_unwind_init: { |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 1814 | Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1815 | return RValue::get(Builder.CreateCall(F)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1816 | } |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1817 | case Builtin::BI__builtin_extend_pointer: { |
| 1818 | // Extends a pointer to the size of an _Unwind_Word, which is |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1819 | // uint64_t on all platforms. Generally this gets poked into a |
| 1820 | // register and eventually used as an address, so if the |
| 1821 | // addressing registers are wider than pointers and the platform |
| 1822 | // doesn't implicitly ignore high-order bits when doing |
| 1823 | // addressing, we need to make sure we zext / sext based on |
| 1824 | // the platform's expectations. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1825 | // |
| 1826 | // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1827 | |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1828 | // Cast the pointer to intptr_t. |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1829 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1830 | Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast"); |
| 1831 | |
| 1832 | // If that's 64 bits, we're done. |
| 1833 | if (IntPtrTy->getBitWidth() == 64) |
| 1834 | return RValue::get(Result); |
| 1835 | |
| 1836 | // Otherwise, ask the codegen data what to do. |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 1837 | if (getTargetHooks().extendPointerWithSExt()) |
John McCall | b6cc2c04 | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 1838 | return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext")); |
| 1839 | else |
| 1840 | return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); |
John McCall | 4b613fa | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 1841 | } |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1842 | case Builtin::BI__builtin_setjmp: { |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1843 | // Buffer is a void**. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1844 | Address Buf = EmitPointerWithAlignment(E->getArg(0)); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1845 | |
| 1846 | // Store the frame pointer to the setjmp buffer. |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1847 | Value *FrameAddr = |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1848 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1849 | ConstantInt::get(Int32Ty, 0)); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1850 | Builder.CreateStore(FrameAddr, Buf); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1851 | |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 1852 | // Store the stack pointer to the setjmp buffer. |
| 1853 | Value *StackAddr = |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 1854 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::stacksave)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1855 | Address StackSaveSlot = |
| 1856 | Builder.CreateConstInBoundsGEP(Buf, 2, getPointerSize()); |
Jim Grosbach | 4cf59b9 | 2010-05-27 23:54:20 +0000 | [diff] [blame] | 1857 | Builder.CreateStore(StackAddr, StackSaveSlot); |
| 1858 | |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1859 | // Call LLVM's EH setjmp, which is lightweight. |
| 1860 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1861 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 1862 | return RValue::get(Builder.CreateCall(F, Buf.getPointer())); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1863 | } |
| 1864 | case Builtin::BI__builtin_longjmp: { |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1865 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1866 | Buf = Builder.CreateBitCast(Buf, Int8PtrTy); |
John McCall | 02269a6 | 2010-05-27 18:47:06 +0000 | [diff] [blame] | 1867 | |
| 1868 | // Call LLVM's EH longjmp, which is lightweight. |
| 1869 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf); |
| 1870 | |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1871 | // longjmp doesn't return; mark this as unreachable. |
| 1872 | Builder.CreateUnreachable(); |
| 1873 | |
| 1874 | // We do need to preserve an insertion point. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1875 | EmitBlock(createBasicBlock("longjmp.cont")); |
John McCall | 20f6ab8 | 2011-01-12 03:41:02 +0000 | [diff] [blame] | 1876 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1877 | return RValue::get(nullptr); |
Eli Friedman | cb9d07c | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 1878 | } |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1879 | case Builtin::BI__sync_fetch_and_add: |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1880 | case Builtin::BI__sync_fetch_and_sub: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1881 | case Builtin::BI__sync_fetch_and_or: |
| 1882 | case Builtin::BI__sync_fetch_and_and: |
| 1883 | case Builtin::BI__sync_fetch_and_xor: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1884 | case Builtin::BI__sync_fetch_and_nand: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1885 | case Builtin::BI__sync_add_and_fetch: |
| 1886 | case Builtin::BI__sync_sub_and_fetch: |
| 1887 | case Builtin::BI__sync_and_and_fetch: |
| 1888 | case Builtin::BI__sync_or_and_fetch: |
| 1889 | case Builtin::BI__sync_xor_and_fetch: |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1890 | case Builtin::BI__sync_nand_and_fetch: |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1891 | case Builtin::BI__sync_val_compare_and_swap: |
| 1892 | case Builtin::BI__sync_bool_compare_and_swap: |
| 1893 | case Builtin::BI__sync_lock_test_and_set: |
| 1894 | case Builtin::BI__sync_lock_release: |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 1895 | case Builtin::BI__sync_swap: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1896 | llvm_unreachable("Shouldn't make it through sema"); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1897 | case Builtin::BI__sync_fetch_and_add_1: |
| 1898 | case Builtin::BI__sync_fetch_and_add_2: |
| 1899 | case Builtin::BI__sync_fetch_and_add_4: |
| 1900 | case Builtin::BI__sync_fetch_and_add_8: |
| 1901 | case Builtin::BI__sync_fetch_and_add_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1902 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Add, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1903 | case Builtin::BI__sync_fetch_and_sub_1: |
| 1904 | case Builtin::BI__sync_fetch_and_sub_2: |
| 1905 | case Builtin::BI__sync_fetch_and_sub_4: |
| 1906 | case Builtin::BI__sync_fetch_and_sub_8: |
| 1907 | case Builtin::BI__sync_fetch_and_sub_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1908 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Sub, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1909 | case Builtin::BI__sync_fetch_and_or_1: |
| 1910 | case Builtin::BI__sync_fetch_and_or_2: |
| 1911 | case Builtin::BI__sync_fetch_and_or_4: |
| 1912 | case Builtin::BI__sync_fetch_and_or_8: |
| 1913 | case Builtin::BI__sync_fetch_and_or_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1914 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Or, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1915 | case Builtin::BI__sync_fetch_and_and_1: |
| 1916 | case Builtin::BI__sync_fetch_and_and_2: |
| 1917 | case Builtin::BI__sync_fetch_and_and_4: |
| 1918 | case Builtin::BI__sync_fetch_and_and_8: |
| 1919 | case Builtin::BI__sync_fetch_and_and_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1920 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::And, E); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1921 | case Builtin::BI__sync_fetch_and_xor_1: |
| 1922 | case Builtin::BI__sync_fetch_and_xor_2: |
| 1923 | case Builtin::BI__sync_fetch_and_xor_4: |
| 1924 | case Builtin::BI__sync_fetch_and_xor_8: |
| 1925 | case Builtin::BI__sync_fetch_and_xor_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1926 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xor, E); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1927 | case Builtin::BI__sync_fetch_and_nand_1: |
| 1928 | case Builtin::BI__sync_fetch_and_nand_2: |
| 1929 | case Builtin::BI__sync_fetch_and_nand_4: |
| 1930 | case Builtin::BI__sync_fetch_and_nand_8: |
| 1931 | case Builtin::BI__sync_fetch_and_nand_16: |
| 1932 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Nand, E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1933 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1934 | // Clang extensions: not overloaded yet. |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1935 | case Builtin::BI__sync_fetch_and_min: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1936 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Min, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1937 | case Builtin::BI__sync_fetch_and_max: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1938 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Max, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1939 | case Builtin::BI__sync_fetch_and_umin: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1940 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMin, E); |
Mon P Wang | b84407d | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 1941 | case Builtin::BI__sync_fetch_and_umax: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1942 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMax, E); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1943 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1944 | case Builtin::BI__sync_add_and_fetch_1: |
| 1945 | case Builtin::BI__sync_add_and_fetch_2: |
| 1946 | case Builtin::BI__sync_add_and_fetch_4: |
| 1947 | case Builtin::BI__sync_add_and_fetch_8: |
| 1948 | case Builtin::BI__sync_add_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1949 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Add, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1950 | llvm::Instruction::Add); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1951 | case Builtin::BI__sync_sub_and_fetch_1: |
| 1952 | case Builtin::BI__sync_sub_and_fetch_2: |
| 1953 | case Builtin::BI__sync_sub_and_fetch_4: |
| 1954 | case Builtin::BI__sync_sub_and_fetch_8: |
| 1955 | case Builtin::BI__sync_sub_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1956 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Sub, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1957 | llvm::Instruction::Sub); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1958 | case Builtin::BI__sync_and_and_fetch_1: |
| 1959 | case Builtin::BI__sync_and_and_fetch_2: |
| 1960 | case Builtin::BI__sync_and_and_fetch_4: |
| 1961 | case Builtin::BI__sync_and_and_fetch_8: |
| 1962 | case Builtin::BI__sync_and_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1963 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::And, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1964 | llvm::Instruction::And); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1965 | case Builtin::BI__sync_or_and_fetch_1: |
| 1966 | case Builtin::BI__sync_or_and_fetch_2: |
| 1967 | case Builtin::BI__sync_or_and_fetch_4: |
| 1968 | case Builtin::BI__sync_or_and_fetch_8: |
| 1969 | case Builtin::BI__sync_or_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1970 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Or, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1971 | llvm::Instruction::Or); |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1972 | case Builtin::BI__sync_xor_and_fetch_1: |
| 1973 | case Builtin::BI__sync_xor_and_fetch_2: |
| 1974 | case Builtin::BI__sync_xor_and_fetch_4: |
| 1975 | case Builtin::BI__sync_xor_and_fetch_8: |
| 1976 | case Builtin::BI__sync_xor_and_fetch_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 1977 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Xor, E, |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1978 | llvm::Instruction::Xor); |
Hal Finkel | d2208b5 | 2014-10-02 20:53:50 +0000 | [diff] [blame] | 1979 | case Builtin::BI__sync_nand_and_fetch_1: |
| 1980 | case Builtin::BI__sync_nand_and_fetch_2: |
| 1981 | case Builtin::BI__sync_nand_and_fetch_4: |
| 1982 | case Builtin::BI__sync_nand_and_fetch_8: |
| 1983 | case Builtin::BI__sync_nand_and_fetch_16: |
| 1984 | return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Nand, E, |
| 1985 | llvm::Instruction::And, true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1986 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1987 | case Builtin::BI__sync_val_compare_and_swap_1: |
| 1988 | case Builtin::BI__sync_val_compare_and_swap_2: |
| 1989 | case Builtin::BI__sync_val_compare_and_swap_4: |
| 1990 | case Builtin::BI__sync_val_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1991 | case Builtin::BI__sync_val_compare_and_swap_16: |
| 1992 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, false)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 1993 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 1994 | case Builtin::BI__sync_bool_compare_and_swap_1: |
| 1995 | case Builtin::BI__sync_bool_compare_and_swap_2: |
| 1996 | case Builtin::BI__sync_bool_compare_and_swap_4: |
| 1997 | case Builtin::BI__sync_bool_compare_and_swap_8: |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 1998 | case Builtin::BI__sync_bool_compare_and_swap_16: |
| 1999 | return RValue::get(MakeAtomicCmpXchgValue(*this, E, true)); |
Daniel Dunbar | 4fab57d | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 2000 | |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 2001 | case Builtin::BI__sync_swap_1: |
| 2002 | case Builtin::BI__sync_swap_2: |
| 2003 | case Builtin::BI__sync_swap_4: |
| 2004 | case Builtin::BI__sync_swap_8: |
| 2005 | case Builtin::BI__sync_swap_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 2006 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Chris Lattner | 9cb59fa | 2011-04-09 03:57:26 +0000 | [diff] [blame] | 2007 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 2008 | case Builtin::BI__sync_lock_test_and_set_1: |
| 2009 | case Builtin::BI__sync_lock_test_and_set_2: |
| 2010 | case Builtin::BI__sync_lock_test_and_set_4: |
| 2011 | case Builtin::BI__sync_lock_test_and_set_8: |
| 2012 | case Builtin::BI__sync_lock_test_and_set_16: |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 2013 | return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E); |
Daniel Dunbar | 4ff562d | 2010-03-20 07:04:11 +0000 | [diff] [blame] | 2014 | |
Chris Lattner | dc04654 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 2015 | case Builtin::BI__sync_lock_release_1: |
| 2016 | case Builtin::BI__sync_lock_release_2: |
| 2017 | case Builtin::BI__sync_lock_release_4: |
| 2018 | case Builtin::BI__sync_lock_release_8: |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 2019 | case Builtin::BI__sync_lock_release_16: { |
| 2020 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Eli Friedman | 84d2812 | 2011-09-13 22:21:56 +0000 | [diff] [blame] | 2021 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 2022 | CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); |
Eli Friedman | fefe0d0 | 2012-03-16 01:48:04 +0000 | [diff] [blame] | 2023 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 2024 | StoreSize.getQuantity() * 8); |
| 2025 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2026 | llvm::StoreInst *Store = |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 2027 | Builder.CreateAlignedStore(llvm::Constant::getNullValue(ITy), Ptr, |
| 2028 | StoreSize); |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2029 | Store->setAtomic(llvm::AtomicOrdering::Release); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2030 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 2031 | } |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 2032 | |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 2033 | case Builtin::BI__sync_synchronize: { |
Eli Friedman | e9f8113 | 2011-09-07 01:41:24 +0000 | [diff] [blame] | 2034 | // We assume this is supposed to correspond to a C++0x-style |
| 2035 | // sequentially-consistent fence (i.e. this is only usable for |
| 2036 | // synchonization, not device I/O or anything like that). This intrinsic |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 2037 | // 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] | 2038 | // any way to safely use it... but in practice, it mostly works |
| 2039 | // to use it with non-atomic loads and stores to get acquire/release |
| 2040 | // semantics. |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2041 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2042 | return RValue::get(nullptr); |
Chris Lattner | afde259 | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 2043 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2044 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 2045 | case Builtin::BI__builtin_nontemporal_load: |
| 2046 | return RValue::get(EmitNontemporalLoad(*this, E)); |
| 2047 | case Builtin::BI__builtin_nontemporal_store: |
| 2048 | return RValue::get(EmitNontemporalStore(*this, E)); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2049 | case Builtin::BI__c11_atomic_is_lock_free: |
| 2050 | case Builtin::BI__atomic_is_lock_free: { |
| 2051 | // Call "bool __atomic_is_lock_free(size_t size, void *ptr)". For the |
| 2052 | // __c11 builtin, ptr is 0 (indicating a properly-aligned object), since |
| 2053 | // _Atomic(T) is always properly-aligned. |
| 2054 | const char *LibCallName = "__atomic_is_lock_free"; |
| 2055 | CallArgList Args; |
| 2056 | Args.add(RValue::get(EmitScalarExpr(E->getArg(0))), |
| 2057 | getContext().getSizeType()); |
| 2058 | if (BuiltinID == Builtin::BI__atomic_is_lock_free) |
| 2059 | Args.add(RValue::get(EmitScalarExpr(E->getArg(1))), |
| 2060 | getContext().VoidPtrTy); |
| 2061 | else |
| 2062 | Args.add(RValue::get(llvm::Constant::getNullValue(VoidPtrTy)), |
| 2063 | getContext().VoidPtrTy); |
| 2064 | const CGFunctionInfo &FuncInfo = |
John McCall | c56a8b3 | 2016-03-11 04:30:31 +0000 | [diff] [blame] | 2065 | CGM.getTypes().arrangeBuiltinFunctionCall(E->getType(), Args); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2066 | llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FuncInfo); |
| 2067 | llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, LibCallName); |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 2068 | return EmitCall(FuncInfo, CGCallee::forDirect(Func), |
| 2069 | ReturnValueSlot(), Args); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | case Builtin::BI__atomic_test_and_set: { |
| 2073 | // Look at the argument type to determine whether this is a volatile |
| 2074 | // operation. The parameter type is always volatile. |
| 2075 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 2076 | bool Volatile = |
| 2077 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 2078 | |
| 2079 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Micah Villmow | ea2fea2 | 2012-10-25 15:39:14 +0000 | [diff] [blame] | 2080 | unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2081 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 2082 | Value *NewVal = Builder.getInt8(1); |
| 2083 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 2084 | if (isa<llvm::ConstantInt>(Order)) { |
| 2085 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2086 | AtomicRMWInst *Result = nullptr; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2087 | switch (ord) { |
| 2088 | case 0: // memory_order_relaxed |
| 2089 | default: // invalid order |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2090 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 2091 | llvm::AtomicOrdering::Monotonic); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2092 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2093 | case 1: // memory_order_consume |
| 2094 | case 2: // memory_order_acquire |
| 2095 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 2096 | llvm::AtomicOrdering::Acquire); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2097 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2098 | case 3: // memory_order_release |
| 2099 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 2100 | llvm::AtomicOrdering::Release); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2101 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2102 | case 4: // memory_order_acq_rel |
| 2103 | |
| 2104 | Result = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 2105 | llvm::AtomicOrdering::AcquireRelease); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2106 | break; |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2107 | case 5: // memory_order_seq_cst |
| 2108 | Result = Builder.CreateAtomicRMW( |
| 2109 | llvm::AtomicRMWInst::Xchg, Ptr, NewVal, |
| 2110 | llvm::AtomicOrdering::SequentiallyConsistent); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2111 | break; |
| 2112 | } |
| 2113 | Result->setVolatile(Volatile); |
| 2114 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 2115 | } |
| 2116 | |
| 2117 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 2118 | |
| 2119 | llvm::BasicBlock *BBs[5] = { |
| 2120 | createBasicBlock("monotonic", CurFn), |
| 2121 | createBasicBlock("acquire", CurFn), |
| 2122 | createBasicBlock("release", CurFn), |
| 2123 | createBasicBlock("acqrel", CurFn), |
| 2124 | createBasicBlock("seqcst", CurFn) |
| 2125 | }; |
| 2126 | llvm::AtomicOrdering Orders[5] = { |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2127 | llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Acquire, |
| 2128 | llvm::AtomicOrdering::Release, llvm::AtomicOrdering::AcquireRelease, |
| 2129 | llvm::AtomicOrdering::SequentiallyConsistent}; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2130 | |
| 2131 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 2132 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 2133 | |
| 2134 | Builder.SetInsertPoint(ContBB); |
| 2135 | PHINode *Result = Builder.CreatePHI(Int8Ty, 5, "was_set"); |
| 2136 | |
| 2137 | for (unsigned i = 0; i < 5; ++i) { |
| 2138 | Builder.SetInsertPoint(BBs[i]); |
| 2139 | AtomicRMWInst *RMW = Builder.CreateAtomicRMW(llvm::AtomicRMWInst::Xchg, |
| 2140 | Ptr, NewVal, Orders[i]); |
| 2141 | RMW->setVolatile(Volatile); |
| 2142 | Result->addIncoming(RMW, BBs[i]); |
| 2143 | Builder.CreateBr(ContBB); |
| 2144 | } |
| 2145 | |
| 2146 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 2147 | SI->addCase(Builder.getInt32(1), BBs[1]); |
| 2148 | SI->addCase(Builder.getInt32(2), BBs[1]); |
| 2149 | SI->addCase(Builder.getInt32(3), BBs[2]); |
| 2150 | SI->addCase(Builder.getInt32(4), BBs[3]); |
| 2151 | SI->addCase(Builder.getInt32(5), BBs[4]); |
| 2152 | |
| 2153 | Builder.SetInsertPoint(ContBB); |
| 2154 | return RValue::get(Builder.CreateIsNotNull(Result, "tobool")); |
| 2155 | } |
| 2156 | |
| 2157 | case Builtin::BI__atomic_clear: { |
| 2158 | QualType PtrTy = E->getArg(0)->IgnoreImpCasts()->getType(); |
| 2159 | bool Volatile = |
| 2160 | PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); |
| 2161 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 2162 | Address Ptr = EmitPointerWithAlignment(E->getArg(0)); |
| 2163 | unsigned AddrSpace = Ptr.getPointer()->getType()->getPointerAddressSpace(); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2164 | Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); |
| 2165 | Value *NewVal = Builder.getInt8(0); |
| 2166 | Value *Order = EmitScalarExpr(E->getArg(1)); |
| 2167 | if (isa<llvm::ConstantInt>(Order)) { |
| 2168 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 2169 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2170 | switch (ord) { |
| 2171 | case 0: // memory_order_relaxed |
| 2172 | default: // invalid order |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2173 | Store->setOrdering(llvm::AtomicOrdering::Monotonic); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2174 | break; |
| 2175 | case 3: // memory_order_release |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2176 | Store->setOrdering(llvm::AtomicOrdering::Release); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2177 | break; |
| 2178 | case 5: // memory_order_seq_cst |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2179 | Store->setOrdering(llvm::AtomicOrdering::SequentiallyConsistent); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2180 | break; |
| 2181 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2182 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 2186 | |
| 2187 | llvm::BasicBlock *BBs[3] = { |
| 2188 | createBasicBlock("monotonic", CurFn), |
| 2189 | createBasicBlock("release", CurFn), |
| 2190 | createBasicBlock("seqcst", CurFn) |
| 2191 | }; |
| 2192 | llvm::AtomicOrdering Orders[3] = { |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2193 | llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Release, |
| 2194 | llvm::AtomicOrdering::SequentiallyConsistent}; |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2195 | |
| 2196 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 2197 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, BBs[0]); |
| 2198 | |
| 2199 | for (unsigned i = 0; i < 3; ++i) { |
| 2200 | Builder.SetInsertPoint(BBs[i]); |
| 2201 | StoreInst *Store = Builder.CreateStore(NewVal, Ptr, Volatile); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2202 | Store->setOrdering(Orders[i]); |
| 2203 | Builder.CreateBr(ContBB); |
| 2204 | } |
| 2205 | |
| 2206 | SI->addCase(Builder.getInt32(0), BBs[0]); |
| 2207 | SI->addCase(Builder.getInt32(3), BBs[1]); |
| 2208 | SI->addCase(Builder.getInt32(5), BBs[2]); |
| 2209 | |
| 2210 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2211 | return RValue::get(nullptr); |
Richard Smith | 01ba47d | 2012-04-13 00:45:38 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2214 | case Builtin::BI__atomic_thread_fence: |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 2215 | case Builtin::BI__atomic_signal_fence: |
| 2216 | case Builtin::BI__c11_atomic_thread_fence: |
| 2217 | case Builtin::BI__c11_atomic_signal_fence: { |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2218 | llvm::SyncScope::ID SSID; |
Richard Smith | b1e36c6 | 2012-04-11 17:55:32 +0000 | [diff] [blame] | 2219 | if (BuiltinID == Builtin::BI__atomic_signal_fence || |
| 2220 | BuiltinID == Builtin::BI__c11_atomic_signal_fence) |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2221 | SSID = llvm::SyncScope::SingleThread; |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2222 | else |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2223 | SSID = llvm::SyncScope::System; |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2224 | Value *Order = EmitScalarExpr(E->getArg(0)); |
| 2225 | if (isa<llvm::ConstantInt>(Order)) { |
| 2226 | int ord = cast<llvm::ConstantInt>(Order)->getZExtValue(); |
| 2227 | switch (ord) { |
| 2228 | case 0: // memory_order_relaxed |
| 2229 | default: // invalid order |
| 2230 | break; |
| 2231 | case 1: // memory_order_consume |
| 2232 | case 2: // memory_order_acquire |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2233 | Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2234 | break; |
| 2235 | case 3: // memory_order_release |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2236 | Builder.CreateFence(llvm::AtomicOrdering::Release, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2237 | break; |
| 2238 | case 4: // memory_order_acq_rel |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2239 | Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2240 | break; |
| 2241 | case 5: // memory_order_seq_cst |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2242 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2243 | break; |
| 2244 | } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2245 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB; |
| 2249 | AcquireBB = createBasicBlock("acquire", CurFn); |
| 2250 | ReleaseBB = createBasicBlock("release", CurFn); |
| 2251 | AcqRelBB = createBasicBlock("acqrel", CurFn); |
| 2252 | SeqCstBB = createBasicBlock("seqcst", CurFn); |
| 2253 | llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn); |
| 2254 | |
| 2255 | Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false); |
| 2256 | llvm::SwitchInst *SI = Builder.CreateSwitch(Order, ContBB); |
| 2257 | |
| 2258 | Builder.SetInsertPoint(AcquireBB); |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2259 | Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2260 | Builder.CreateBr(ContBB); |
| 2261 | SI->addCase(Builder.getInt32(1), AcquireBB); |
| 2262 | SI->addCase(Builder.getInt32(2), AcquireBB); |
| 2263 | |
| 2264 | Builder.SetInsertPoint(ReleaseBB); |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2265 | Builder.CreateFence(llvm::AtomicOrdering::Release, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2266 | Builder.CreateBr(ContBB); |
| 2267 | SI->addCase(Builder.getInt32(3), ReleaseBB); |
| 2268 | |
| 2269 | Builder.SetInsertPoint(AcqRelBB); |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2270 | Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2271 | Builder.CreateBr(ContBB); |
| 2272 | SI->addCase(Builder.getInt32(4), AcqRelBB); |
| 2273 | |
| 2274 | Builder.SetInsertPoint(SeqCstBB); |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 2275 | Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2276 | Builder.CreateBr(ContBB); |
| 2277 | SI->addCase(Builder.getInt32(5), SeqCstBB); |
| 2278 | |
| 2279 | Builder.SetInsertPoint(ContBB); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2280 | return RValue::get(nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 2283 | case Builtin::BI__builtin_signbit: |
| 2284 | case Builtin::BI__builtin_signbitf: |
| 2285 | case Builtin::BI__builtin_signbitl: { |
Chandler Carruth | c66deaf | 2015-03-19 22:39:51 +0000 | [diff] [blame] | 2286 | return RValue::get( |
| 2287 | Builder.CreateZExt(EmitSignBit(*this, EmitScalarExpr(E->getArg(0))), |
| 2288 | ConvertType(E->getType()))); |
Eli Friedman | 99d20f8 | 2010-03-06 02:17:52 +0000 | [diff] [blame] | 2289 | } |
Reid Kleckner | 30701ed | 2017-09-05 20:27:35 +0000 | [diff] [blame] | 2290 | case Builtin::BI__annotation: { |
| 2291 | // Re-encode each wide string to UTF8 and make an MDString. |
| 2292 | SmallVector<Metadata *, 1> Strings; |
| 2293 | for (const Expr *Arg : E->arguments()) { |
| 2294 | const auto *Str = cast<StringLiteral>(Arg->IgnoreParenCasts()); |
| 2295 | assert(Str->getCharByteWidth() == 2); |
| 2296 | StringRef WideBytes = Str->getBytes(); |
| 2297 | std::string StrUtf8; |
| 2298 | if (!convertUTF16ToUTF8String( |
| 2299 | makeArrayRef(WideBytes.data(), WideBytes.size()), StrUtf8)) { |
| 2300 | CGM.ErrorUnsupported(E, "non-UTF16 __annotation argument"); |
| 2301 | continue; |
| 2302 | } |
| 2303 | Strings.push_back(llvm::MDString::get(getLLVMContext(), StrUtf8)); |
| 2304 | } |
| 2305 | |
| 2306 | // Build and MDTuple of MDStrings and emit the intrinsic call. |
Reid Kleckner | d53c39b | 2017-09-05 20:38:29 +0000 | [diff] [blame] | 2307 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::codeview_annotation, {}); |
Reid Kleckner | 30701ed | 2017-09-05 20:27:35 +0000 | [diff] [blame] | 2308 | MDTuple *StrTuple = MDTuple::get(getLLVMContext(), Strings); |
| 2309 | Builder.CreateCall(F, MetadataAsValue::get(getLLVMContext(), StrTuple)); |
| 2310 | return RValue::getIgnored(); |
| 2311 | } |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 2312 | case Builtin::BI__builtin_annotation: { |
| 2313 | llvm::Value *AnnVal = EmitScalarExpr(E->getArg(0)); |
| 2314 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::annotation, |
| 2315 | AnnVal->getType()); |
| 2316 | |
| 2317 | // Get the annotation string, go through casts. Sema requires this to be a |
| 2318 | // non-wide string literal, potentially casted, so the cast<> is safe. |
| 2319 | const Expr *AnnotationStrExpr = E->getArg(1)->IgnoreParenCasts(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2320 | StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString(); |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 2321 | return RValue::get(EmitAnnotationCall(F, AnnVal, Str, E->getExprLoc())); |
| 2322 | } |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 2323 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 2324 | case Builtin::BI__builtin_addcs: |
| 2325 | case Builtin::BI__builtin_addc: |
| 2326 | case Builtin::BI__builtin_addcl: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 2327 | case Builtin::BI__builtin_addcll: |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 2328 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 2329 | case Builtin::BI__builtin_subcs: |
| 2330 | case Builtin::BI__builtin_subc: |
| 2331 | case Builtin::BI__builtin_subcl: |
| 2332 | case Builtin::BI__builtin_subcll: { |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 2333 | |
| 2334 | // We translate all of these builtins from expressions of the form: |
| 2335 | // int x = ..., y = ..., carryin = ..., carryout, result; |
| 2336 | // result = __builtin_addc(x, y, carryin, &carryout); |
| 2337 | // |
| 2338 | // to LLVM IR of the form: |
| 2339 | // |
| 2340 | // %tmp1 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y) |
| 2341 | // %tmpsum1 = extractvalue {i32, i1} %tmp1, 0 |
| 2342 | // %carry1 = extractvalue {i32, i1} %tmp1, 1 |
| 2343 | // %tmp2 = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %tmpsum1, |
| 2344 | // i32 %carryin) |
| 2345 | // %result = extractvalue {i32, i1} %tmp2, 0 |
| 2346 | // %carry2 = extractvalue {i32, i1} %tmp2, 1 |
| 2347 | // %tmp3 = or i1 %carry1, %carry2 |
| 2348 | // %tmp4 = zext i1 %tmp3 to i32 |
| 2349 | // store i32 %tmp4, i32* %carryout |
| 2350 | |
| 2351 | // Scalarize our inputs. |
| 2352 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 2353 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 2354 | llvm::Value *Carryin = EmitScalarExpr(E->getArg(2)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 2355 | Address CarryOutPtr = EmitPointerWithAlignment(E->getArg(3)); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 2356 | |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 2357 | // Decide if we are lowering to a uadd.with.overflow or usub.with.overflow. |
| 2358 | llvm::Intrinsic::ID IntrinsicId; |
| 2359 | switch (BuiltinID) { |
| 2360 | default: llvm_unreachable("Unknown multiprecision builtin id."); |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 2361 | case Builtin::BI__builtin_addcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 2362 | case Builtin::BI__builtin_addcs: |
| 2363 | case Builtin::BI__builtin_addc: |
| 2364 | case Builtin::BI__builtin_addcl: |
| 2365 | case Builtin::BI__builtin_addcll: |
| 2366 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 2367 | break; |
Michael Gottesman | 1534399 | 2013-06-18 20:40:40 +0000 | [diff] [blame] | 2368 | case Builtin::BI__builtin_subcb: |
Michael Gottesman | a2b5c4b | 2013-01-14 21:44:30 +0000 | [diff] [blame] | 2369 | case Builtin::BI__builtin_subcs: |
| 2370 | case Builtin::BI__builtin_subc: |
| 2371 | case Builtin::BI__builtin_subcl: |
| 2372 | case Builtin::BI__builtin_subcll: |
| 2373 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 2374 | break; |
| 2375 | } |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 2376 | |
| 2377 | // Construct our resulting LLVM IR expression. |
| 2378 | llvm::Value *Carry1; |
| 2379 | llvm::Value *Sum1 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 2380 | X, Y, Carry1); |
| 2381 | llvm::Value *Carry2; |
| 2382 | llvm::Value *Sum2 = EmitOverflowIntrinsic(*this, IntrinsicId, |
| 2383 | Sum1, Carryin, Carry2); |
| 2384 | llvm::Value *CarryOut = Builder.CreateZExt(Builder.CreateOr(Carry1, Carry2), |
| 2385 | X->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 2386 | Builder.CreateStore(CarryOut, CarryOutPtr); |
Michael Gottesman | 5439801 | 2013-01-13 02:22:39 +0000 | [diff] [blame] | 2387 | return RValue::get(Sum2); |
| 2388 | } |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 2389 | |
| 2390 | case Builtin::BI__builtin_add_overflow: |
| 2391 | case Builtin::BI__builtin_sub_overflow: |
| 2392 | case Builtin::BI__builtin_mul_overflow: { |
| 2393 | const clang::Expr *LeftArg = E->getArg(0); |
| 2394 | const clang::Expr *RightArg = E->getArg(1); |
| 2395 | const clang::Expr *ResultArg = E->getArg(2); |
| 2396 | |
| 2397 | clang::QualType ResultQTy = |
| 2398 | ResultArg->getType()->castAs<PointerType>()->getPointeeType(); |
| 2399 | |
| 2400 | WidthAndSignedness LeftInfo = |
| 2401 | getIntegerWidthAndSignedness(CGM.getContext(), LeftArg->getType()); |
| 2402 | WidthAndSignedness RightInfo = |
| 2403 | getIntegerWidthAndSignedness(CGM.getContext(), RightArg->getType()); |
| 2404 | WidthAndSignedness ResultInfo = |
| 2405 | getIntegerWidthAndSignedness(CGM.getContext(), ResultQTy); |
Vedant Kumar | fa5a0e5 | 2017-12-16 01:28:25 +0000 | [diff] [blame] | 2406 | |
| 2407 | // Handle mixed-sign multiplication as a special case, because adding |
| 2408 | // runtime or backend support for our generic irgen would be too expensive. |
| 2409 | if (isSpecialMixedSignMultiply(BuiltinID, LeftInfo, RightInfo, ResultInfo)) |
| 2410 | return EmitCheckedMixedSignMultiply(*this, LeftArg, LeftInfo, RightArg, |
| 2411 | RightInfo, ResultArg, ResultQTy, |
| 2412 | ResultInfo); |
| 2413 | |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 2414 | WidthAndSignedness EncompassingInfo = |
| 2415 | EncompassingIntegerType({LeftInfo, RightInfo, ResultInfo}); |
| 2416 | |
| 2417 | llvm::Type *EncompassingLLVMTy = |
| 2418 | llvm::IntegerType::get(CGM.getLLVMContext(), EncompassingInfo.Width); |
| 2419 | |
| 2420 | llvm::Type *ResultLLVMTy = CGM.getTypes().ConvertType(ResultQTy); |
| 2421 | |
| 2422 | llvm::Intrinsic::ID IntrinsicId; |
| 2423 | switch (BuiltinID) { |
| 2424 | default: |
| 2425 | llvm_unreachable("Unknown overflow builtin id."); |
| 2426 | case Builtin::BI__builtin_add_overflow: |
| 2427 | IntrinsicId = EncompassingInfo.Signed |
| 2428 | ? llvm::Intrinsic::sadd_with_overflow |
| 2429 | : llvm::Intrinsic::uadd_with_overflow; |
| 2430 | break; |
| 2431 | case Builtin::BI__builtin_sub_overflow: |
| 2432 | IntrinsicId = EncompassingInfo.Signed |
| 2433 | ? llvm::Intrinsic::ssub_with_overflow |
| 2434 | : llvm::Intrinsic::usub_with_overflow; |
| 2435 | break; |
| 2436 | case Builtin::BI__builtin_mul_overflow: |
| 2437 | IntrinsicId = EncompassingInfo.Signed |
| 2438 | ? llvm::Intrinsic::smul_with_overflow |
| 2439 | : llvm::Intrinsic::umul_with_overflow; |
| 2440 | break; |
| 2441 | } |
| 2442 | |
| 2443 | llvm::Value *Left = EmitScalarExpr(LeftArg); |
| 2444 | llvm::Value *Right = EmitScalarExpr(RightArg); |
| 2445 | Address ResultPtr = EmitPointerWithAlignment(ResultArg); |
| 2446 | |
| 2447 | // Extend each operand to the encompassing type. |
| 2448 | Left = Builder.CreateIntCast(Left, EncompassingLLVMTy, LeftInfo.Signed); |
| 2449 | Right = Builder.CreateIntCast(Right, EncompassingLLVMTy, RightInfo.Signed); |
| 2450 | |
| 2451 | // Perform the operation on the extended values. |
| 2452 | llvm::Value *Overflow, *Result; |
| 2453 | Result = EmitOverflowIntrinsic(*this, IntrinsicId, Left, Right, Overflow); |
| 2454 | |
| 2455 | if (EncompassingInfo.Width > ResultInfo.Width) { |
| 2456 | // The encompassing type is wider than the result type, so we need to |
| 2457 | // truncate it. |
| 2458 | llvm::Value *ResultTrunc = Builder.CreateTrunc(Result, ResultLLVMTy); |
| 2459 | |
| 2460 | // To see if the truncation caused an overflow, we will extend |
| 2461 | // the result and then compare it to the original result. |
| 2462 | llvm::Value *ResultTruncExt = Builder.CreateIntCast( |
| 2463 | ResultTrunc, EncompassingLLVMTy, ResultInfo.Signed); |
| 2464 | llvm::Value *TruncationOverflow = |
| 2465 | Builder.CreateICmpNE(Result, ResultTruncExt); |
| 2466 | |
| 2467 | Overflow = Builder.CreateOr(Overflow, TruncationOverflow); |
| 2468 | Result = ResultTrunc; |
| 2469 | } |
| 2470 | |
| 2471 | // Finally, store the result using the pointer. |
| 2472 | bool isVolatile = |
| 2473 | ResultArg->getType()->getPointeeType().isVolatileQualified(); |
| 2474 | Builder.CreateStore(EmitToMemory(Result, ResultQTy), ResultPtr, isVolatile); |
| 2475 | |
| 2476 | return RValue::get(Overflow); |
| 2477 | } |
| 2478 | |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 2479 | case Builtin::BI__builtin_uadd_overflow: |
| 2480 | case Builtin::BI__builtin_uaddl_overflow: |
| 2481 | case Builtin::BI__builtin_uaddll_overflow: |
| 2482 | case Builtin::BI__builtin_usub_overflow: |
| 2483 | case Builtin::BI__builtin_usubl_overflow: |
| 2484 | case Builtin::BI__builtin_usubll_overflow: |
| 2485 | case Builtin::BI__builtin_umul_overflow: |
| 2486 | case Builtin::BI__builtin_umull_overflow: |
| 2487 | case Builtin::BI__builtin_umulll_overflow: |
| 2488 | case Builtin::BI__builtin_sadd_overflow: |
| 2489 | case Builtin::BI__builtin_saddl_overflow: |
| 2490 | case Builtin::BI__builtin_saddll_overflow: |
| 2491 | case Builtin::BI__builtin_ssub_overflow: |
| 2492 | case Builtin::BI__builtin_ssubl_overflow: |
| 2493 | case Builtin::BI__builtin_ssubll_overflow: |
| 2494 | case Builtin::BI__builtin_smul_overflow: |
| 2495 | case Builtin::BI__builtin_smull_overflow: |
| 2496 | case Builtin::BI__builtin_smulll_overflow: { |
| 2497 | |
| 2498 | // We translate all of these builtins directly to the relevant llvm IR node. |
| 2499 | |
| 2500 | // Scalarize our inputs. |
| 2501 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 2502 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 2503 | Address SumOutPtr = EmitPointerWithAlignment(E->getArg(2)); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 2504 | |
| 2505 | // Decide which of the overflow intrinsics we are lowering to: |
| 2506 | llvm::Intrinsic::ID IntrinsicId; |
| 2507 | switch (BuiltinID) { |
John McCall | 03107a4 | 2015-10-29 20:48:01 +0000 | [diff] [blame] | 2508 | default: llvm_unreachable("Unknown overflow builtin id."); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 2509 | case Builtin::BI__builtin_uadd_overflow: |
| 2510 | case Builtin::BI__builtin_uaddl_overflow: |
| 2511 | case Builtin::BI__builtin_uaddll_overflow: |
| 2512 | IntrinsicId = llvm::Intrinsic::uadd_with_overflow; |
| 2513 | break; |
| 2514 | case Builtin::BI__builtin_usub_overflow: |
| 2515 | case Builtin::BI__builtin_usubl_overflow: |
| 2516 | case Builtin::BI__builtin_usubll_overflow: |
| 2517 | IntrinsicId = llvm::Intrinsic::usub_with_overflow; |
| 2518 | break; |
| 2519 | case Builtin::BI__builtin_umul_overflow: |
| 2520 | case Builtin::BI__builtin_umull_overflow: |
| 2521 | case Builtin::BI__builtin_umulll_overflow: |
| 2522 | IntrinsicId = llvm::Intrinsic::umul_with_overflow; |
| 2523 | break; |
| 2524 | case Builtin::BI__builtin_sadd_overflow: |
| 2525 | case Builtin::BI__builtin_saddl_overflow: |
| 2526 | case Builtin::BI__builtin_saddll_overflow: |
| 2527 | IntrinsicId = llvm::Intrinsic::sadd_with_overflow; |
| 2528 | break; |
| 2529 | case Builtin::BI__builtin_ssub_overflow: |
| 2530 | case Builtin::BI__builtin_ssubl_overflow: |
| 2531 | case Builtin::BI__builtin_ssubll_overflow: |
| 2532 | IntrinsicId = llvm::Intrinsic::ssub_with_overflow; |
| 2533 | break; |
| 2534 | case Builtin::BI__builtin_smul_overflow: |
| 2535 | case Builtin::BI__builtin_smull_overflow: |
| 2536 | case Builtin::BI__builtin_smulll_overflow: |
| 2537 | IntrinsicId = llvm::Intrinsic::smul_with_overflow; |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 2538 | break; |
| 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | llvm::Value *Carry; |
| 2543 | llvm::Value *Sum = EmitOverflowIntrinsic(*this, IntrinsicId, X, Y, Carry); |
| 2544 | Builder.CreateStore(Sum, SumOutPtr); |
Michael Gottesman | 930ecdb | 2013-06-20 23:28:10 +0000 | [diff] [blame] | 2545 | |
| 2546 | return RValue::get(Carry); |
| 2547 | } |
Richard Smith | 6cbd65d | 2013-07-11 02:27:57 +0000 | [diff] [blame] | 2548 | case Builtin::BI__builtin_addressof: |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 2549 | return RValue::get(EmitLValue(E->getArg(0)).getPointer()); |
Richard Smith | 760520b | 2014-06-03 23:27:44 +0000 | [diff] [blame] | 2550 | case Builtin::BI__builtin_operator_new: |
| 2551 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 2552 | E->getArg(0), false); |
| 2553 | case Builtin::BI__builtin_operator_delete: |
| 2554 | return EmitBuiltinNewDeleteCall(FD->getType()->castAs<FunctionProtoType>(), |
| 2555 | E->getArg(0), true); |
Nico Weber | 636fc09 | 2012-10-13 22:30:41 +0000 | [diff] [blame] | 2556 | case Builtin::BI__noop: |
Reid Kleckner | ed5d4ad | 2014-07-11 20:22:55 +0000 | [diff] [blame] | 2557 | // __noop always evaluates to an integer literal zero. |
| 2558 | return RValue::get(ConstantInt::get(IntTy, 0)); |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 2559 | case Builtin::BI__builtin_call_with_static_chain: { |
| 2560 | const CallExpr *Call = cast<CallExpr>(E->getArg(0)); |
| 2561 | const Expr *Chain = E->getArg(1); |
| 2562 | return EmitCall(Call->getCallee()->getType(), |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 2563 | EmitCallee(Call->getCallee()), Call, ReturnValue, |
| 2564 | EmitScalarExpr(Chain)); |
Peter Collingbourne | f770683 | 2014-12-12 23:41:25 +0000 | [diff] [blame] | 2565 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2566 | case Builtin::BI_InterlockedExchange8: |
| 2567 | case Builtin::BI_InterlockedExchange16: |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 2568 | case Builtin::BI_InterlockedExchange: |
| 2569 | case Builtin::BI_InterlockedExchangePointer: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2570 | return RValue::get( |
| 2571 | EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange, E)); |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 2572 | case Builtin::BI_InterlockedCompareExchangePointer: { |
| 2573 | llvm::Type *RTy; |
| 2574 | llvm::IntegerType *IntType = |
| 2575 | IntegerType::get(getLLVMContext(), |
| 2576 | getContext().getTypeSize(E->getType())); |
| 2577 | llvm::Type *IntPtrType = IntType->getPointerTo(); |
| 2578 | |
| 2579 | llvm::Value *Destination = |
| 2580 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), IntPtrType); |
| 2581 | |
| 2582 | llvm::Value *Exchange = EmitScalarExpr(E->getArg(1)); |
| 2583 | RTy = Exchange->getType(); |
| 2584 | Exchange = Builder.CreatePtrToInt(Exchange, IntType); |
| 2585 | |
| 2586 | llvm::Value *Comparand = |
| 2587 | Builder.CreatePtrToInt(EmitScalarExpr(E->getArg(2)), IntType); |
| 2588 | |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2589 | auto Result = |
| 2590 | Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange, |
| 2591 | AtomicOrdering::SequentiallyConsistent, |
| 2592 | AtomicOrdering::SequentiallyConsistent); |
Saleem Abdulrasool | 114efe0 | 2014-06-18 20:51:10 +0000 | [diff] [blame] | 2593 | Result->setVolatile(true); |
| 2594 | |
| 2595 | return RValue::get(Builder.CreateIntToPtr(Builder.CreateExtractValue(Result, |
| 2596 | 0), |
| 2597 | RTy)); |
| 2598 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2599 | case Builtin::BI_InterlockedCompareExchange8: |
| 2600 | case Builtin::BI_InterlockedCompareExchange16: |
| 2601 | case Builtin::BI_InterlockedCompareExchange: |
| 2602 | case Builtin::BI_InterlockedCompareExchange64: { |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2603 | AtomicCmpXchgInst *CXI = Builder.CreateAtomicCmpXchg( |
| 2604 | EmitScalarExpr(E->getArg(0)), |
| 2605 | EmitScalarExpr(E->getArg(2)), |
| 2606 | EmitScalarExpr(E->getArg(1)), |
JF Bastien | 92f4ef1 | 2016-04-06 17:26:42 +0000 | [diff] [blame] | 2607 | AtomicOrdering::SequentiallyConsistent, |
| 2608 | AtomicOrdering::SequentiallyConsistent); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2609 | CXI->setVolatile(true); |
Tim Northover | b49b04b | 2014-06-13 14:24:59 +0000 | [diff] [blame] | 2610 | return RValue::get(Builder.CreateExtractValue(CXI, 0)); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 2611 | } |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2612 | case Builtin::BI_InterlockedIncrement16: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2613 | case Builtin::BI_InterlockedIncrement: |
| 2614 | return RValue::get( |
| 2615 | EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedIncrement, E)); |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2616 | case Builtin::BI_InterlockedDecrement16: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2617 | case Builtin::BI_InterlockedDecrement: |
| 2618 | return RValue::get( |
| 2619 | EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedDecrement, E)); |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2620 | case Builtin::BI_InterlockedAnd8: |
| 2621 | case Builtin::BI_InterlockedAnd16: |
| 2622 | case Builtin::BI_InterlockedAnd: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2623 | return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedAnd, E)); |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2624 | case Builtin::BI_InterlockedExchangeAdd8: |
| 2625 | case Builtin::BI_InterlockedExchangeAdd16: |
| 2626 | case Builtin::BI_InterlockedExchangeAdd: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2627 | return RValue::get( |
| 2628 | EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchangeAdd, E)); |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2629 | case Builtin::BI_InterlockedExchangeSub8: |
| 2630 | case Builtin::BI_InterlockedExchangeSub16: |
| 2631 | case Builtin::BI_InterlockedExchangeSub: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2632 | return RValue::get( |
| 2633 | EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchangeSub, E)); |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2634 | case Builtin::BI_InterlockedOr8: |
| 2635 | case Builtin::BI_InterlockedOr16: |
| 2636 | case Builtin::BI_InterlockedOr: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2637 | return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedOr, E)); |
Albert Gutowski | ce7a9a4 | 2016-09-13 19:43:33 +0000 | [diff] [blame] | 2638 | case Builtin::BI_InterlockedXor8: |
| 2639 | case Builtin::BI_InterlockedXor16: |
| 2640 | case Builtin::BI_InterlockedXor: |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 2641 | return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedXor, E)); |
Hans Wennborg | 5c3c51f | 2017-04-07 16:41:47 +0000 | [diff] [blame] | 2642 | case Builtin::BI_interlockedbittestandset: |
| 2643 | return RValue::get( |
| 2644 | EmitMSVCBuiltinExpr(MSVCIntrin::_interlockedbittestandset, E)); |
Reid Kleckner | 1d59f99 | 2015-01-22 01:36:17 +0000 | [diff] [blame] | 2645 | |
| 2646 | case Builtin::BI__exception_code: |
| 2647 | case Builtin::BI_exception_code: |
| 2648 | return RValue::get(EmitSEHExceptionCode()); |
| 2649 | case Builtin::BI__exception_info: |
| 2650 | case Builtin::BI_exception_info: |
| 2651 | return RValue::get(EmitSEHExceptionInfo()); |
Reid Kleckner | aca01db | 2015-02-04 22:37:07 +0000 | [diff] [blame] | 2652 | case Builtin::BI__abnormal_termination: |
| 2653 | case Builtin::BI_abnormal_termination: |
| 2654 | return RValue::get(EmitSEHAbnormalTermination()); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2655 | case Builtin::BI_setjmpex: { |
| 2656 | if (getTarget().getTriple().isOSMSVCRT()) { |
| 2657 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 2658 | llvm::AttributeList ReturnsTwiceAttr = llvm::AttributeList::get( |
| 2659 | getLLVMContext(), llvm::AttributeList::FunctionIndex, |
| 2660 | llvm::Attribute::ReturnsTwice); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2661 | llvm::Constant *SetJmpEx = CGM.CreateRuntimeFunction( |
| 2662 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
Saleem Abdulrasool | 342beeb | 2016-12-15 07:29:04 +0000 | [diff] [blame] | 2663 | "_setjmpex", ReturnsTwiceAttr, /*Local=*/true); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2664 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 2665 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2666 | llvm::Value *FrameAddr = |
| 2667 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 2668 | ConstantInt::get(Int32Ty, 0)); |
| 2669 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 2670 | llvm::CallSite CS = EmitRuntimeCallOrInvoke(SetJmpEx, Args); |
| 2671 | CS.setAttributes(ReturnsTwiceAttr); |
| 2672 | return RValue::get(CS.getInstruction()); |
| 2673 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2674 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2675 | } |
| 2676 | case Builtin::BI_setjmp: { |
| 2677 | if (getTarget().getTriple().isOSMSVCRT()) { |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 2678 | llvm::AttributeList ReturnsTwiceAttr = llvm::AttributeList::get( |
| 2679 | getLLVMContext(), llvm::AttributeList::FunctionIndex, |
| 2680 | llvm::Attribute::ReturnsTwice); |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2681 | llvm::Value *Buf = Builder.CreateBitOrPointerCast( |
| 2682 | EmitScalarExpr(E->getArg(0)), Int8PtrTy); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2683 | llvm::CallSite CS; |
| 2684 | if (getTarget().getTriple().getArch() == llvm::Triple::x86) { |
| 2685 | llvm::Type *ArgTypes[] = {Int8PtrTy, IntTy}; |
| 2686 | llvm::Constant *SetJmp3 = CGM.CreateRuntimeFunction( |
| 2687 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/true), |
Saleem Abdulrasool | 342beeb | 2016-12-15 07:29:04 +0000 | [diff] [blame] | 2688 | "_setjmp3", ReturnsTwiceAttr, /*Local=*/true); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2689 | llvm::Value *Count = ConstantInt::get(IntTy, 0); |
| 2690 | llvm::Value *Args[] = {Buf, Count}; |
| 2691 | CS = EmitRuntimeCallOrInvoke(SetJmp3, Args); |
| 2692 | } else { |
| 2693 | llvm::Type *ArgTypes[] = {Int8PtrTy, Int8PtrTy}; |
| 2694 | llvm::Constant *SetJmp = CGM.CreateRuntimeFunction( |
| 2695 | llvm::FunctionType::get(IntTy, ArgTypes, /*isVarArg=*/false), |
Saleem Abdulrasool | 342beeb | 2016-12-15 07:29:04 +0000 | [diff] [blame] | 2696 | "_setjmp", ReturnsTwiceAttr, /*Local=*/true); |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2697 | llvm::Value *FrameAddr = |
| 2698 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress), |
| 2699 | ConstantInt::get(Int32Ty, 0)); |
| 2700 | llvm::Value *Args[] = {Buf, FrameAddr}; |
| 2701 | CS = EmitRuntimeCallOrInvoke(SetJmp, Args); |
| 2702 | } |
| 2703 | CS.setAttributes(ReturnsTwiceAttr); |
| 2704 | return RValue::get(CS.getInstruction()); |
| 2705 | } |
David Majnemer | c403a1c | 2015-03-20 17:03:35 +0000 | [diff] [blame] | 2706 | break; |
David Majnemer | 310e3a8 | 2015-01-29 09:29:21 +0000 | [diff] [blame] | 2707 | } |
David Majnemer | ba3e5ec | 2015-03-13 18:26:17 +0000 | [diff] [blame] | 2708 | |
| 2709 | case Builtin::BI__GetExceptionInfo: { |
| 2710 | if (llvm::GlobalVariable *GV = |
| 2711 | CGM.getCXXABI().getThrowInfo(FD->getParamDecl(0)->getType())) |
| 2712 | return RValue::get(llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy)); |
| 2713 | break; |
| 2714 | } |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2715 | |
Hans Wennborg | 5c3c51f | 2017-04-07 16:41:47 +0000 | [diff] [blame] | 2716 | case Builtin::BI__fastfail: |
Reid Kleckner | 04f9f91 | 2017-02-09 18:31:06 +0000 | [diff] [blame] | 2717 | return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::__fastfail, E)); |
Reid Kleckner | 04f9f91 | 2017-02-09 18:31:06 +0000 | [diff] [blame] | 2718 | |
Gor Nishanov | 97e3b6d | 2016-10-03 22:44:48 +0000 | [diff] [blame] | 2719 | case Builtin::BI__builtin_coro_size: { |
| 2720 | auto & Context = getContext(); |
| 2721 | auto SizeTy = Context.getSizeType(); |
| 2722 | auto T = Builder.getIntNTy(Context.getTypeSize(SizeTy)); |
| 2723 | Value *F = CGM.getIntrinsic(Intrinsic::coro_size, T); |
| 2724 | return RValue::get(Builder.CreateCall(F)); |
| 2725 | } |
| 2726 | |
| 2727 | case Builtin::BI__builtin_coro_id: |
| 2728 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_id); |
| 2729 | case Builtin::BI__builtin_coro_promise: |
| 2730 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_promise); |
| 2731 | case Builtin::BI__builtin_coro_resume: |
| 2732 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_resume); |
| 2733 | case Builtin::BI__builtin_coro_frame: |
| 2734 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_frame); |
| 2735 | case Builtin::BI__builtin_coro_free: |
| 2736 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_free); |
| 2737 | case Builtin::BI__builtin_coro_destroy: |
| 2738 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_destroy); |
| 2739 | case Builtin::BI__builtin_coro_done: |
| 2740 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_done); |
| 2741 | case Builtin::BI__builtin_coro_alloc: |
| 2742 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_alloc); |
| 2743 | case Builtin::BI__builtin_coro_begin: |
| 2744 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_begin); |
| 2745 | case Builtin::BI__builtin_coro_end: |
| 2746 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_end); |
| 2747 | case Builtin::BI__builtin_coro_suspend: |
| 2748 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_suspend); |
| 2749 | case Builtin::BI__builtin_coro_param: |
| 2750 | return EmitCoroutineIntrinsic(E, Intrinsic::coro_param); |
| 2751 | |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2752 | // OpenCL v2.0 s6.13.16.2, Built-in pipe read and write functions |
| 2753 | case Builtin::BIread_pipe: |
| 2754 | case Builtin::BIwrite_pipe: { |
| 2755 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2756 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2757 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2758 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2759 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2760 | |
| 2761 | // Type of the generic packet parameter. |
| 2762 | unsigned GenericAS = |
| 2763 | getContext().getTargetAddressSpace(LangAS::opencl_generic); |
| 2764 | llvm::Type *I8PTy = llvm::PointerType::get( |
| 2765 | llvm::Type::getInt8Ty(getLLVMContext()), GenericAS); |
| 2766 | |
| 2767 | // Testing which overloaded version we should generate the call for. |
| 2768 | if (2U == E->getNumArgs()) { |
| 2769 | const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_2" |
| 2770 | : "__write_pipe_2"; |
| 2771 | // Creating a generic function type to be able to call with any builtin or |
| 2772 | // user defined type. |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2773 | llvm::Type *ArgTys[] = {Arg0->getType(), I8PTy, Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2774 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2775 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2776 | Value *BCast = Builder.CreatePointerCast(Arg1, I8PTy); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2777 | return RValue::get( |
| 2778 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2779 | {Arg0, BCast, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2780 | } else { |
| 2781 | assert(4 == E->getNumArgs() && |
| 2782 | "Illegal number of parameters to pipe function"); |
| 2783 | const char *Name = (BuiltinID == Builtin::BIread_pipe) ? "__read_pipe_4" |
| 2784 | : "__write_pipe_4"; |
| 2785 | |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2786 | llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, I8PTy, |
| 2787 | Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2788 | Value *Arg2 = EmitScalarExpr(E->getArg(2)), |
| 2789 | *Arg3 = EmitScalarExpr(E->getArg(3)); |
| 2790 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2791 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2792 | Value *BCast = Builder.CreatePointerCast(Arg3, I8PTy); |
| 2793 | // We know the third argument is an integer type, but we may need to cast |
| 2794 | // it to i32. |
| 2795 | if (Arg2->getType() != Int32Ty) |
| 2796 | Arg2 = Builder.CreateZExtOrTrunc(Arg2, Int32Ty); |
| 2797 | return RValue::get(Builder.CreateCall( |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2798 | CGM.CreateRuntimeFunction(FTy, Name), |
| 2799 | {Arg0, Arg1, Arg2, BCast, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2800 | } |
| 2801 | } |
| 2802 | // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe reserve read and write |
| 2803 | // functions |
| 2804 | case Builtin::BIreserve_read_pipe: |
| 2805 | case Builtin::BIreserve_write_pipe: |
| 2806 | case Builtin::BIwork_group_reserve_read_pipe: |
| 2807 | case Builtin::BIwork_group_reserve_write_pipe: |
| 2808 | case Builtin::BIsub_group_reserve_read_pipe: |
| 2809 | case Builtin::BIsub_group_reserve_write_pipe: { |
| 2810 | // Composing the mangled name for the function. |
| 2811 | const char *Name; |
| 2812 | if (BuiltinID == Builtin::BIreserve_read_pipe) |
| 2813 | Name = "__reserve_read_pipe"; |
| 2814 | else if (BuiltinID == Builtin::BIreserve_write_pipe) |
| 2815 | Name = "__reserve_write_pipe"; |
| 2816 | else if (BuiltinID == Builtin::BIwork_group_reserve_read_pipe) |
| 2817 | Name = "__work_group_reserve_read_pipe"; |
| 2818 | else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe) |
| 2819 | Name = "__work_group_reserve_write_pipe"; |
| 2820 | else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe) |
| 2821 | Name = "__sub_group_reserve_read_pipe"; |
| 2822 | else |
| 2823 | Name = "__sub_group_reserve_write_pipe"; |
| 2824 | |
| 2825 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2826 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 2827 | llvm::Type *ReservedIDTy = ConvertType(getContext().OCLReserveIDTy); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2828 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2829 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2830 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2831 | |
| 2832 | // Building the generic function prototype. |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2833 | llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty, Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2834 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2835 | ReservedIDTy, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2836 | // We know the second argument is an integer type, but we may need to cast |
| 2837 | // it to i32. |
| 2838 | if (Arg1->getType() != Int32Ty) |
| 2839 | Arg1 = Builder.CreateZExtOrTrunc(Arg1, Int32Ty); |
| 2840 | return RValue::get( |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2841 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2842 | {Arg0, Arg1, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2843 | } |
Anastasia Stulova | 7f8d6dc | 2016-07-04 16:07:18 +0000 | [diff] [blame] | 2844 | // 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] | 2845 | // functions |
| 2846 | case Builtin::BIcommit_read_pipe: |
| 2847 | case Builtin::BIcommit_write_pipe: |
| 2848 | case Builtin::BIwork_group_commit_read_pipe: |
| 2849 | case Builtin::BIwork_group_commit_write_pipe: |
| 2850 | case Builtin::BIsub_group_commit_read_pipe: |
| 2851 | case Builtin::BIsub_group_commit_write_pipe: { |
| 2852 | const char *Name; |
| 2853 | if (BuiltinID == Builtin::BIcommit_read_pipe) |
| 2854 | Name = "__commit_read_pipe"; |
| 2855 | else if (BuiltinID == Builtin::BIcommit_write_pipe) |
| 2856 | Name = "__commit_write_pipe"; |
| 2857 | else if (BuiltinID == Builtin::BIwork_group_commit_read_pipe) |
| 2858 | Name = "__work_group_commit_read_pipe"; |
| 2859 | else if (BuiltinID == Builtin::BIwork_group_commit_write_pipe) |
| 2860 | Name = "__work_group_commit_write_pipe"; |
| 2861 | else if (BuiltinID == Builtin::BIsub_group_commit_read_pipe) |
| 2862 | Name = "__sub_group_commit_read_pipe"; |
| 2863 | else |
| 2864 | Name = "__sub_group_commit_write_pipe"; |
| 2865 | |
| 2866 | Value *Arg0 = EmitScalarExpr(E->getArg(0)), |
| 2867 | *Arg1 = EmitScalarExpr(E->getArg(1)); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2868 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2869 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2870 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2871 | |
| 2872 | // Building the generic function prototype. |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2873 | llvm::Type *ArgTys[] = {Arg0->getType(), Arg1->getType(), Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2874 | llvm::FunctionType *FTy = |
| 2875 | llvm::FunctionType::get(llvm::Type::getVoidTy(getLLVMContext()), |
| 2876 | llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2877 | |
| 2878 | return RValue::get( |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2879 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2880 | {Arg0, Arg1, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2881 | } |
| 2882 | // OpenCL v2.0 s6.13.16.4 Built-in pipe query functions |
| 2883 | case Builtin::BIget_pipe_num_packets: |
| 2884 | case Builtin::BIget_pipe_max_packets: { |
| 2885 | const char *Name; |
| 2886 | if (BuiltinID == Builtin::BIget_pipe_num_packets) |
| 2887 | Name = "__get_pipe_num_packets"; |
| 2888 | else |
| 2889 | Name = "__get_pipe_max_packets"; |
| 2890 | |
| 2891 | // Building the generic function prototype. |
| 2892 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2893 | CGOpenCLRuntime OpenCLRT(CGM); |
| 2894 | Value *PacketSize = OpenCLRT.getPipeElemSize(E->getArg(0)); |
| 2895 | Value *PacketAlign = OpenCLRT.getPipeElemAlign(E->getArg(0)); |
| 2896 | llvm::Type *ArgTys[] = {Arg0->getType(), Int32Ty, Int32Ty}; |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2897 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 2898 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 2899 | |
Alexey Bader | 465c189 | 2016-09-23 14:20:00 +0000 | [diff] [blame] | 2900 | return RValue::get(Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 2901 | {Arg0, PacketSize, PacketAlign})); |
Xiuli Pan | bb4d8d3 | 2016-01-26 04:03:48 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 2904 | // OpenCL v2.0 s6.13.9 - Address space qualifier functions. |
| 2905 | case Builtin::BIto_global: |
| 2906 | case Builtin::BIto_local: |
| 2907 | case Builtin::BIto_private: { |
| 2908 | auto Arg0 = EmitScalarExpr(E->getArg(0)); |
| 2909 | auto NewArgT = llvm::PointerType::get(Int8Ty, |
| 2910 | CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
| 2911 | auto NewRetT = llvm::PointerType::get(Int8Ty, |
| 2912 | CGM.getContext().getTargetAddressSpace( |
| 2913 | E->getType()->getPointeeType().getAddressSpace())); |
| 2914 | auto FTy = llvm::FunctionType::get(NewRetT, {NewArgT}, false); |
| 2915 | llvm::Value *NewArg; |
| 2916 | if (Arg0->getType()->getPointerAddressSpace() != |
| 2917 | NewArgT->getPointerAddressSpace()) |
| 2918 | NewArg = Builder.CreateAddrSpaceCast(Arg0, NewArgT); |
| 2919 | else |
| 2920 | NewArg = Builder.CreateBitOrPointerCast(Arg0, NewArgT); |
Alexey Bader | d8162326 | 2016-08-04 18:06:27 +0000 | [diff] [blame] | 2921 | auto NewName = std::string("__") + E->getDirectCallee()->getName().str(); |
| 2922 | auto NewCall = |
| 2923 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, NewName), {NewArg}); |
Yaxun Liu | f7449a1 | 2016-05-20 19:54:38 +0000 | [diff] [blame] | 2924 | return RValue::get(Builder.CreateBitOrPointerCast(NewCall, |
| 2925 | ConvertType(E->getType()))); |
| 2926 | } |
| 2927 | |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2928 | // OpenCL v2.0, s6.13.17 - Enqueue kernel function. |
| 2929 | // It contains four different overload formats specified in Table 6.13.17.1. |
| 2930 | case Builtin::BIenqueue_kernel: { |
| 2931 | StringRef Name; // Generated function call name |
| 2932 | unsigned NumArgs = E->getNumArgs(); |
| 2933 | |
| 2934 | llvm::Type *QueueTy = ConvertType(getContext().OCLQueueTy); |
Anastasia Stulova | af0a7bb | 2017-01-27 15:11:34 +0000 | [diff] [blame] | 2935 | llvm::Type *GenericVoidPtrTy = Builder.getInt8PtrTy( |
| 2936 | getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2937 | |
| 2938 | llvm::Value *Queue = EmitScalarExpr(E->getArg(0)); |
| 2939 | llvm::Value *Flags = EmitScalarExpr(E->getArg(1)); |
Anastasia Stulova | 58984e7 | 2017-02-16 12:27:47 +0000 | [diff] [blame] | 2940 | LValue NDRangeL = EmitAggExprToLValue(E->getArg(2)); |
| 2941 | llvm::Value *Range = NDRangeL.getAddress().getPointer(); |
| 2942 | llvm::Type *RangeTy = NDRangeL.getAddress().getType(); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2943 | |
| 2944 | if (NumArgs == 4) { |
| 2945 | // The most basic form of the call with parameters: |
| 2946 | // queue_t, kernel_enqueue_flags_t, ndrange_t, block(void) |
| 2947 | Name = "__enqueue_kernel_basic"; |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 2948 | llvm::Type *ArgTys[] = {QueueTy, Int32Ty, RangeTy, GenericVoidPtrTy, |
| 2949 | GenericVoidPtrTy}; |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2950 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 2951 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2952 | |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 2953 | auto Info = |
| 2954 | CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(3)); |
| 2955 | llvm::Value *Kernel = |
| 2956 | Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); |
| 2957 | llvm::Value *Block = |
| 2958 | Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2959 | |
Anastasia Stulova | 58984e7 | 2017-02-16 12:27:47 +0000 | [diff] [blame] | 2960 | AttrBuilder B; |
| 2961 | B.addAttribute(Attribute::ByVal); |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 2962 | llvm::AttributeList ByValAttrSet = |
| 2963 | llvm::AttributeList::get(CGM.getModule().getContext(), 3U, B); |
Anastasia Stulova | 58984e7 | 2017-02-16 12:27:47 +0000 | [diff] [blame] | 2964 | |
| 2965 | auto RTCall = |
| 2966 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name, ByValAttrSet), |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 2967 | {Queue, Flags, Range, Kernel, Block}); |
Anastasia Stulova | 58984e7 | 2017-02-16 12:27:47 +0000 | [diff] [blame] | 2968 | RTCall->setAttributes(ByValAttrSet); |
| 2969 | return RValue::get(RTCall); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2970 | } |
| 2971 | assert(NumArgs >= 5 && "Invalid enqueue_kernel signature"); |
| 2972 | |
Yaxun Liu | 29a5ee3 | 2017-09-03 13:52:24 +0000 | [diff] [blame] | 2973 | // Create a temporary array to hold the sizes of local pointer arguments |
| 2974 | // for the block. \p First is the position of the first size argument. |
| 2975 | auto CreateArrayForSizeVar = [=](unsigned First) { |
| 2976 | auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First); |
| 2977 | auto *Arr = Builder.CreateAlloca(AT); |
| 2978 | llvm::Value *Ptr; |
| 2979 | // Each of the following arguments specifies the size of the corresponding |
| 2980 | // argument passed to the enqueued block. |
| 2981 | auto *Zero = llvm::ConstantInt::get(IntTy, 0); |
| 2982 | for (unsigned I = First; I < NumArgs; ++I) { |
| 2983 | auto *Index = llvm::ConstantInt::get(IntTy, I - First); |
| 2984 | auto *GEP = Builder.CreateGEP(Arr, {Zero, Index}); |
| 2985 | if (I == First) |
| 2986 | Ptr = GEP; |
| 2987 | auto *V = |
| 2988 | Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)), SizeTy); |
| 2989 | Builder.CreateAlignedStore( |
| 2990 | V, GEP, CGM.getDataLayout().getPrefTypeAlignment(SizeTy)); |
| 2991 | } |
| 2992 | return Ptr; |
| 2993 | }; |
| 2994 | |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 2995 | // Could have events and/or vaargs. |
| 2996 | if (E->getArg(3)->getType()->isBlockPointerType()) { |
| 2997 | // No events passed, but has variadic arguments. |
| 2998 | Name = "__enqueue_kernel_vaargs"; |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 2999 | auto Info = |
| 3000 | CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(3)); |
| 3001 | llvm::Value *Kernel = |
| 3002 | Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); |
| 3003 | auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); |
Yaxun Liu | 29a5ee3 | 2017-09-03 13:52:24 +0000 | [diff] [blame] | 3004 | auto *PtrToSizeArray = CreateArrayForSizeVar(4); |
| 3005 | |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3006 | // Create a vector of the arguments, as well as a constant value to |
| 3007 | // express to the runtime the number of variadic arguments. |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3008 | std::vector<llvm::Value *> Args = { |
| 3009 | Queue, Flags, Range, |
| 3010 | Kernel, Block, ConstantInt::get(IntTy, NumArgs - 4), |
| 3011 | PtrToSizeArray}; |
| 3012 | std::vector<llvm::Type *> ArgTys = { |
| 3013 | QueueTy, IntTy, RangeTy, |
| 3014 | GenericVoidPtrTy, GenericVoidPtrTy, IntTy, |
| 3015 | PtrToSizeArray->getType()}; |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3016 | |
| 3017 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
Yaxun Liu | 29a5ee3 | 2017-09-03 13:52:24 +0000 | [diff] [blame] | 3018 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3019 | return RValue::get( |
| 3020 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 3021 | llvm::ArrayRef<llvm::Value *>(Args))); |
| 3022 | } |
| 3023 | // Any calls now have event arguments passed. |
| 3024 | if (NumArgs >= 7) { |
| 3025 | llvm::Type *EventTy = ConvertType(getContext().OCLClkEventTy); |
Anastasia Stulova | 2b46120 | 2016-11-14 15:34:01 +0000 | [diff] [blame] | 3026 | llvm::Type *EventPtrTy = EventTy->getPointerTo( |
| 3027 | CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3028 | |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 3029 | llvm::Value *NumEvents = |
| 3030 | Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(3)), Int32Ty); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3031 | llvm::Value *EventList = |
| 3032 | E->getArg(4)->getType()->isArrayType() |
| 3033 | ? EmitArrayToPointerDecay(E->getArg(4)).getPointer() |
| 3034 | : EmitScalarExpr(E->getArg(4)); |
| 3035 | llvm::Value *ClkEvent = EmitScalarExpr(E->getArg(5)); |
Anastasia Stulova | 2b46120 | 2016-11-14 15:34:01 +0000 | [diff] [blame] | 3036 | // Convert to generic address space. |
| 3037 | EventList = Builder.CreatePointerCast(EventList, EventPtrTy); |
| 3038 | ClkEvent = Builder.CreatePointerCast(ClkEvent, EventPtrTy); |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3039 | auto Info = |
| 3040 | CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(6)); |
| 3041 | llvm::Value *Kernel = |
| 3042 | Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); |
| 3043 | llvm::Value *Block = |
| 3044 | Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3045 | |
Anastasia Stulova | af0a7bb | 2017-01-27 15:11:34 +0000 | [diff] [blame] | 3046 | std::vector<llvm::Type *> ArgTys = { |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3047 | QueueTy, Int32Ty, RangeTy, Int32Ty, |
| 3048 | EventPtrTy, EventPtrTy, GenericVoidPtrTy, GenericVoidPtrTy}; |
Anastasia Stulova | 2b46120 | 2016-11-14 15:34:01 +0000 | [diff] [blame] | 3049 | |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3050 | std::vector<llvm::Value *> Args = {Queue, Flags, Range, NumEvents, |
| 3051 | EventList, ClkEvent, Kernel, Block}; |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3052 | |
| 3053 | if (NumArgs == 7) { |
| 3054 | // Has events but no variadics. |
| 3055 | Name = "__enqueue_kernel_basic_events"; |
| 3056 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
| 3057 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
| 3058 | return RValue::get( |
| 3059 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 3060 | llvm::ArrayRef<llvm::Value *>(Args))); |
| 3061 | } |
| 3062 | // Has event info and variadics |
| 3063 | // Pass the number of variadics to the runtime function too. |
| 3064 | Args.push_back(ConstantInt::get(Int32Ty, NumArgs - 7)); |
| 3065 | ArgTys.push_back(Int32Ty); |
| 3066 | Name = "__enqueue_kernel_events_vaargs"; |
| 3067 | |
Yaxun Liu | 29a5ee3 | 2017-09-03 13:52:24 +0000 | [diff] [blame] | 3068 | auto *PtrToSizeArray = CreateArrayForSizeVar(7); |
| 3069 | Args.push_back(PtrToSizeArray); |
| 3070 | ArgTys.push_back(PtrToSizeArray->getType()); |
Anastasia Stulova | 0df4ac3 | 2016-11-14 17:39:58 +0000 | [diff] [blame] | 3071 | |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3072 | llvm::FunctionType *FTy = llvm::FunctionType::get( |
Yaxun Liu | 29a5ee3 | 2017-09-03 13:52:24 +0000 | [diff] [blame] | 3073 | Int32Ty, llvm::ArrayRef<llvm::Type *>(ArgTys), false); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3074 | return RValue::get( |
| 3075 | Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), |
| 3076 | llvm::ArrayRef<llvm::Value *>(Args))); |
| 3077 | } |
Galina Kistanova | 0872d6c | 2017-06-03 06:30:46 +0000 | [diff] [blame] | 3078 | LLVM_FALLTHROUGH; |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3079 | } |
| 3080 | // OpenCL v2.0 s6.13.17.6 - Kernel query functions need bitcast of block |
| 3081 | // parameter. |
| 3082 | case Builtin::BIget_kernel_work_group_size: { |
Anastasia Stulova | af0a7bb | 2017-01-27 15:11:34 +0000 | [diff] [blame] | 3083 | llvm::Type *GenericVoidPtrTy = Builder.getInt8PtrTy( |
| 3084 | getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3085 | auto Info = |
| 3086 | CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(0)); |
| 3087 | Value *Kernel = Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); |
| 3088 | Value *Arg = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3089 | return RValue::get(Builder.CreateCall( |
| 3090 | CGM.CreateRuntimeFunction( |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3091 | llvm::FunctionType::get(IntTy, {GenericVoidPtrTy, GenericVoidPtrTy}, |
| 3092 | false), |
Anastasia Stulova | af0a7bb | 2017-01-27 15:11:34 +0000 | [diff] [blame] | 3093 | "__get_kernel_work_group_size_impl"), |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3094 | {Kernel, Arg})); |
Anastasia Stulova | af0a7bb | 2017-01-27 15:11:34 +0000 | [diff] [blame] | 3095 | } |
| 3096 | case Builtin::BIget_kernel_preferred_work_group_size_multiple: { |
| 3097 | llvm::Type *GenericVoidPtrTy = Builder.getInt8PtrTy( |
| 3098 | getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3099 | auto Info = |
| 3100 | CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(0)); |
| 3101 | Value *Kernel = Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); |
| 3102 | Value *Arg = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); |
Anastasia Stulova | af0a7bb | 2017-01-27 15:11:34 +0000 | [diff] [blame] | 3103 | return RValue::get(Builder.CreateCall( |
| 3104 | CGM.CreateRuntimeFunction( |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3105 | llvm::FunctionType::get(IntTy, {GenericVoidPtrTy, GenericVoidPtrTy}, |
| 3106 | false), |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3107 | "__get_kernel_preferred_work_group_multiple_impl"), |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3108 | {Kernel, Arg})); |
Anastasia Stulova | db7a31c | 2016-07-05 11:31:24 +0000 | [diff] [blame] | 3109 | } |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 3110 | case Builtin::BIget_kernel_max_sub_group_size_for_ndrange: |
| 3111 | case Builtin::BIget_kernel_sub_group_count_for_ndrange: { |
| 3112 | llvm::Type *GenericVoidPtrTy = Builder.getInt8PtrTy( |
| 3113 | getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
| 3114 | LValue NDRangeL = EmitAggExprToLValue(E->getArg(0)); |
| 3115 | llvm::Value *NDRange = NDRangeL.getAddress().getPointer(); |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3116 | auto Info = |
| 3117 | CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(1)); |
| 3118 | Value *Kernel = Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); |
| 3119 | Value *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 3120 | const char *Name = |
| 3121 | BuiltinID == Builtin::BIget_kernel_max_sub_group_size_for_ndrange |
| 3122 | ? "__get_kernel_max_sub_group_size_for_ndrange_impl" |
| 3123 | : "__get_kernel_sub_group_count_for_ndrange_impl"; |
| 3124 | return RValue::get(Builder.CreateCall( |
| 3125 | CGM.CreateRuntimeFunction( |
| 3126 | llvm::FunctionType::get( |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3127 | IntTy, {NDRange->getType(), GenericVoidPtrTy, GenericVoidPtrTy}, |
| 3128 | false), |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 3129 | Name), |
Yaxun Liu | c2a87a0 | 2017-10-14 12:23:50 +0000 | [diff] [blame] | 3130 | {NDRange, Kernel, Block})); |
Joey Gouly | fa76b49 | 2017-08-01 13:27:09 +0000 | [diff] [blame] | 3131 | } |
Jan Vesely | 31ecb4b | 2017-09-07 19:39:10 +0000 | [diff] [blame] | 3132 | |
| 3133 | case Builtin::BI__builtin_store_half: |
| 3134 | case Builtin::BI__builtin_store_halff: { |
| 3135 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 3136 | Address Address = EmitPointerWithAlignment(E->getArg(1)); |
| 3137 | Value *HalfVal = Builder.CreateFPTrunc(Val, Builder.getHalfTy()); |
| 3138 | return RValue::get(Builder.CreateStore(HalfVal, Address)); |
| 3139 | } |
| 3140 | case Builtin::BI__builtin_load_half: { |
| 3141 | Address Address = EmitPointerWithAlignment(E->getArg(0)); |
| 3142 | Value *HalfVal = Builder.CreateLoad(Address); |
| 3143 | return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getDoubleTy())); |
| 3144 | } |
| 3145 | case Builtin::BI__builtin_load_halff: { |
| 3146 | Address Address = EmitPointerWithAlignment(E->getArg(0)); |
| 3147 | Value *HalfVal = Builder.CreateLoad(Address); |
| 3148 | return RValue::get(Builder.CreateFPExt(HalfVal, Builder.getFloatTy())); |
| 3149 | } |
Justin Lebar | 3039a59 | 2016-01-23 21:28:14 +0000 | [diff] [blame] | 3150 | case Builtin::BIprintf: |
Arpith Chacko Jacob | cdda3daa | 2017-01-29 20:49:31 +0000 | [diff] [blame] | 3151 | if (getTarget().getTriple().isNVPTX()) |
| 3152 | return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue); |
Matt Arsenault | 2d93398 | 2016-02-27 09:06:18 +0000 | [diff] [blame] | 3153 | break; |
| 3154 | case Builtin::BI__builtin_canonicalize: |
| 3155 | case Builtin::BI__builtin_canonicalizef: |
| 3156 | case Builtin::BI__builtin_canonicalizel: |
| 3157 | return RValue::get(emitUnaryBuiltin(*this, E, Intrinsic::canonicalize)); |
Marcin Koscielnicki | a46fade | 2016-06-16 13:41:54 +0000 | [diff] [blame] | 3158 | |
| 3159 | case Builtin::BI__builtin_thread_pointer: { |
| 3160 | if (!getContext().getTargetInfo().isTLSSupported()) |
| 3161 | CGM.ErrorUnsupported(E, "__builtin_thread_pointer"); |
| 3162 | // Fall through - it's already mapped to the intrinsic by GCCBuiltin. |
| 3163 | break; |
| 3164 | } |
Akira Hatanaka | 6b103bc | 2017-10-06 07:12:46 +0000 | [diff] [blame] | 3165 | case Builtin::BI__builtin_os_log_format: |
| 3166 | return emitBuiltinOSLogFormat(*E); |
Mehdi Amini | 06d367c | 2016-10-24 20:39:34 +0000 | [diff] [blame] | 3167 | |
| 3168 | case Builtin::BI__builtin_os_log_format_buffer_size: { |
| 3169 | analyze_os_log::OSLogBufferLayout Layout; |
| 3170 | analyze_os_log::computeOSLogBufferLayout(CGM.getContext(), E, Layout); |
| 3171 | return RValue::get(ConstantInt::get(ConvertType(E->getType()), |
| 3172 | Layout.size().getQuantity())); |
| 3173 | } |
Dean Michael Berris | 42af651 | 2017-05-09 00:45:40 +0000 | [diff] [blame] | 3174 | |
| 3175 | case Builtin::BI__xray_customevent: { |
| 3176 | if (!ShouldXRayInstrumentFunction()) |
| 3177 | return RValue::getIgnored(); |
Dean Michael Berris | 1a5b10d | 2017-11-30 00:04:54 +0000 | [diff] [blame] | 3178 | if (const auto *XRayAttr = CurFuncDecl->getAttr<XRayInstrumentAttr>()) |
| 3179 | if (XRayAttr->neverXRayInstrument() && !AlwaysEmitXRayCustomEvents()) |
Dean Michael Berris | 42af651 | 2017-05-09 00:45:40 +0000 | [diff] [blame] | 3180 | return RValue::getIgnored(); |
Dean Michael Berris | 1a5b10d | 2017-11-30 00:04:54 +0000 | [diff] [blame] | 3181 | |
Dean Michael Berris | 42af651 | 2017-05-09 00:45:40 +0000 | [diff] [blame] | 3182 | Function *F = CGM.getIntrinsic(Intrinsic::xray_customevent); |
| 3183 | auto FTy = F->getFunctionType(); |
| 3184 | auto Arg0 = E->getArg(0); |
| 3185 | auto Arg0Val = EmitScalarExpr(Arg0); |
| 3186 | auto Arg0Ty = Arg0->getType(); |
| 3187 | auto PTy0 = FTy->getParamType(0); |
| 3188 | if (PTy0 != Arg0Val->getType()) { |
| 3189 | if (Arg0Ty->isArrayType()) |
| 3190 | Arg0Val = EmitArrayToPointerDecay(Arg0).getPointer(); |
| 3191 | else |
| 3192 | Arg0Val = Builder.CreatePointerCast(Arg0Val, PTy0); |
| 3193 | } |
| 3194 | auto Arg1 = EmitScalarExpr(E->getArg(1)); |
| 3195 | auto PTy1 = FTy->getParamType(1); |
| 3196 | if (PTy1 != Arg1->getType()) |
| 3197 | Arg1 = Builder.CreateTruncOrBitCast(Arg1, PTy1); |
| 3198 | return RValue::get(Builder.CreateCall(F, {Arg0Val, Arg1})); |
| 3199 | } |
Martin Storsjo | 022e782 | 2017-07-17 20:49:45 +0000 | [diff] [blame] | 3200 | |
| 3201 | case Builtin::BI__builtin_ms_va_start: |
| 3202 | case Builtin::BI__builtin_ms_va_end: |
| 3203 | return RValue::get( |
| 3204 | EmitVAStartEnd(EmitMSVAListRef(E->getArg(0)).getPointer(), |
| 3205 | BuiltinID == Builtin::BI__builtin_ms_va_start)); |
| 3206 | |
| 3207 | case Builtin::BI__builtin_ms_va_copy: { |
| 3208 | // Lower this manually. We can't reliably determine whether or not any |
| 3209 | // given va_copy() is for a Win64 va_list from the calling convention |
| 3210 | // alone, because it's legal to do this from a System V ABI function. |
| 3211 | // With opaque pointer types, we won't have enough information in LLVM |
| 3212 | // IR to determine this from the argument types, either. Best to do it |
| 3213 | // now, while we have enough information. |
| 3214 | Address DestAddr = EmitMSVAListRef(E->getArg(0)); |
| 3215 | Address SrcAddr = EmitMSVAListRef(E->getArg(1)); |
| 3216 | |
| 3217 | llvm::Type *BPP = Int8PtrPtrTy; |
| 3218 | |
| 3219 | DestAddr = Address(Builder.CreateBitCast(DestAddr.getPointer(), BPP, "cp"), |
| 3220 | DestAddr.getAlignment()); |
| 3221 | SrcAddr = Address(Builder.CreateBitCast(SrcAddr.getPointer(), BPP, "ap"), |
| 3222 | SrcAddr.getAlignment()); |
| 3223 | |
| 3224 | Value *ArgPtr = Builder.CreateLoad(SrcAddr, "ap.val"); |
| 3225 | return RValue::get(Builder.CreateStore(ArgPtr, DestAddr)); |
| 3226 | } |
Nate Begeman | 6c59132 | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 3227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3228 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 3229 | // If this is an alias for a lib function (e.g. __builtin_sin), emit |
| 3230 | // the call using the normal call path, but using the unmangled |
| 3231 | // version of the function name. |
| 3232 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) |
| 3233 | return emitLibraryCall(*this, FD, E, |
| 3234 | CGM.getBuiltinLibFunction(FD, BuiltinID)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3235 | |
John McCall | 30e4efd | 2011-09-13 23:05:03 +0000 | [diff] [blame] | 3236 | // If this is a predefined lib function (e.g. malloc), emit the call |
| 3237 | // using exactly the normal call path. |
| 3238 | if (getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 3239 | return emitLibraryCall(*this, FD, E, |
| 3240 | cast<llvm::Constant>(EmitScalarExpr(E->getCallee()))); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3241 | |
Eric Christopher | 1570999 | 2015-10-15 23:47:11 +0000 | [diff] [blame] | 3242 | // Check that a call to a target specific builtin has the correct target |
| 3243 | // features. |
| 3244 | // This is down here to avoid non-target specific builtins, however, if |
| 3245 | // generic builtins start to require generic target features then we |
| 3246 | // can move this up to the beginning of the function. |
Eric Christopher | c7e79db | 2015-11-12 00:44:04 +0000 | [diff] [blame] | 3247 | checkTargetFeatures(E, FD); |
Eric Christopher | 1570999 | 2015-10-15 23:47:11 +0000 | [diff] [blame] | 3248 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3249 | // See if we have a target specific intrinsic. |
Mehdi Amini | 7186a43 | 2016-10-11 19:04:24 +0000 | [diff] [blame] | 3250 | const char *Name = getContext().BuiltinInfo.getName(BuiltinID); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 3251 | Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; |
Mehdi Amini | b7fb124 | 2016-10-01 01:16:22 +0000 | [diff] [blame] | 3252 | StringRef Prefix = |
| 3253 | llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch()); |
| 3254 | if (!Prefix.empty()) { |
| 3255 | IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix.data(), Name); |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 3256 | // NOTE we dont need to perform a compatibility flag check here since the |
| 3257 | // intrinsics are declared in Builtins*.def via LANGBUILTIN which filter the |
| 3258 | // MS builtins via ALL_MS_LANGUAGES and are filtered earlier. |
| 3259 | if (IntrinsicID == Intrinsic::not_intrinsic) |
Mehdi Amini | b7fb124 | 2016-10-01 01:16:22 +0000 | [diff] [blame] | 3260 | IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix.data(), Name); |
Saleem Abdulrasool | 96bfda8 | 2014-07-04 21:49:39 +0000 | [diff] [blame] | 3261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3262 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3263 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
| 3264 | SmallVector<Value*, 16> Args; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3265 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 3266 | // Find out if any arguments are required to be integer constant |
| 3267 | // expressions. |
| 3268 | unsigned ICEArguments = 0; |
| 3269 | ASTContext::GetBuiltinTypeError Error; |
| 3270 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 3271 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 3272 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3273 | Function *F = CGM.getIntrinsic(IntrinsicID); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 3274 | llvm::FunctionType *FTy = F->getFunctionType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3275 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3276 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 3277 | Value *ArgValue; |
| 3278 | // If this is a normal argument, just emit it as a scalar. |
| 3279 | if ((ICEArguments & (1 << i)) == 0) { |
| 3280 | ArgValue = EmitScalarExpr(E->getArg(i)); |
| 3281 | } else { |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3282 | // 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] | 3283 | // know that the generated intrinsic gets a ConstantInt. |
| 3284 | llvm::APSInt Result; |
| 3285 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext()); |
| 3286 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 3287 | (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 3288 | ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 3289 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3290 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3291 | // If the intrinsic arg type is different from the builtin arg type |
| 3292 | // we need to do a bit cast. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 3293 | llvm::Type *PTy = FTy->getParamType(i); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3294 | if (PTy != ArgValue->getType()) { |
| 3295 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 3296 | "Must be able to losslessly bit cast to param"); |
| 3297 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 3298 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3299 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3300 | Args.push_back(ArgValue); |
| 3301 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3302 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 3303 | Value *V = Builder.CreateCall(F, Args); |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3304 | QualType BuiltinRetType = E->getType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3305 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 3306 | llvm::Type *RetTy = VoidTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3307 | if (!BuiltinRetType->isVoidType()) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 3308 | RetTy = ConvertType(BuiltinRetType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3309 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3310 | if (RetTy != V->getType()) { |
| 3311 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 3312 | "Must be able to losslessly bit cast result type"); |
| 3313 | V = Builder.CreateBitCast(V, RetTy); |
| 3314 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3315 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3316 | return RValue::get(V); |
| 3317 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3318 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3319 | // 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] | 3320 | if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3321 | return RValue::get(V); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3322 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 3323 | ErrorUnsupported(E, "builtin function"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3324 | |
Chris Lattner | 9a8d1d9 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 3325 | // Unknown builtin, for now just dump it out and return undef. |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 3326 | return GetUndefRValue(E->getType()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3327 | } |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 3328 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3329 | static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF, |
| 3330 | unsigned BuiltinID, const CallExpr *E, |
| 3331 | llvm::Triple::ArchType Arch) { |
| 3332 | switch (Arch) { |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3333 | case llvm::Triple::arm: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3334 | case llvm::Triple::armeb: |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 3335 | case llvm::Triple::thumb: |
Christian Pirker | f01cd6f | 2014-03-28 14:40:46 +0000 | [diff] [blame] | 3336 | case llvm::Triple::thumbeb: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3337 | return CGF->EmitARMBuiltinExpr(BuiltinID, E); |
Tim Northover | 25e8a67 | 2014-05-24 12:51:25 +0000 | [diff] [blame] | 3338 | case llvm::Triple::aarch64: |
| 3339 | case llvm::Triple::aarch64_be: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3340 | return CGF->EmitAArch64BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 3341 | case llvm::Triple::x86: |
| 3342 | case llvm::Triple::x86_64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3343 | return CGF->EmitX86BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 3344 | case llvm::Triple::ppc: |
| 3345 | case llvm::Triple::ppc64: |
Bill Schmidt | 778d387 | 2013-07-26 01:36:11 +0000 | [diff] [blame] | 3346 | case llvm::Triple::ppc64le: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3347 | return CGF->EmitPPCBuiltinExpr(BuiltinID, E); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 3348 | case llvm::Triple::r600: |
Tom Stellard | d8e38a3 | 2015-01-06 20:34:47 +0000 | [diff] [blame] | 3349 | case llvm::Triple::amdgcn: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3350 | return CGF->EmitAMDGPUBuiltinExpr(BuiltinID, E); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 3351 | case llvm::Triple::systemz: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3352 | return CGF->EmitSystemZBuiltinExpr(BuiltinID, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 3353 | case llvm::Triple::nvptx: |
| 3354 | case llvm::Triple::nvptx64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3355 | return CGF->EmitNVPTXBuiltinExpr(BuiltinID, E); |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 3356 | case llvm::Triple::wasm32: |
| 3357 | case llvm::Triple::wasm64: |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3358 | return CGF->EmitWebAssemblyBuiltinExpr(BuiltinID, E); |
Krzysztof Parzyszek | 5a65583 | 2017-12-13 19:56:03 +0000 | [diff] [blame] | 3359 | case llvm::Triple::hexagon: |
| 3360 | return CGF->EmitHexagonBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 3361 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 3362 | return nullptr; |
Daniel Dunbar | 576d90d | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 3363 | } |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 3366 | Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, |
| 3367 | const CallExpr *E) { |
| 3368 | if (getContext().BuiltinInfo.isAuxBuiltinID(BuiltinID)) { |
| 3369 | assert(getContext().getAuxTargetInfo() && "Missing aux target info"); |
| 3370 | return EmitTargetArchBuiltinExpr( |
| 3371 | this, getContext().BuiltinInfo.getAuxBuiltinID(BuiltinID), E, |
| 3372 | getContext().getAuxTargetInfo()->getTriple().getArch()); |
| 3373 | } |
| 3374 | |
| 3375 | return EmitTargetArchBuiltinExpr(this, BuiltinID, E, |
| 3376 | getTarget().getTriple().getArch()); |
| 3377 | } |
| 3378 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 3379 | static llvm::VectorType *GetNeonType(CodeGenFunction *CGF, |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3380 | NeonTypeFlags TypeFlags, |
| 3381 | bool V1Ty=false) { |
NAKAMURA Takumi | dabda6b | 2011-11-08 03:27:04 +0000 | [diff] [blame] | 3382 | int IsQuad = TypeFlags.isQuad(); |
| 3383 | switch (TypeFlags.getEltType()) { |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 3384 | case NeonTypeFlags::Int8: |
| 3385 | case NeonTypeFlags::Poly8: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3386 | return llvm::VectorType::get(CGF->Int8Ty, V1Ty ? 1 : (8 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 3387 | case NeonTypeFlags::Int16: |
| 3388 | case NeonTypeFlags::Poly16: |
Sjoerd Meijer | 98ee785 | 2017-07-06 16:37:31 +0000 | [diff] [blame] | 3389 | return llvm::VectorType::get(CGF->Int16Ty, V1Ty ? 1 : (4 << IsQuad)); |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3390 | case NeonTypeFlags::Float16: |
| 3391 | return llvm::VectorType::get(CGF->HalfTy, V1Ty ? 1 : (4 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 3392 | case NeonTypeFlags::Int32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3393 | return llvm::VectorType::get(CGF->Int32Ty, V1Ty ? 1 : (2 << IsQuad)); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 3394 | case NeonTypeFlags::Int64: |
Kevin Qin | caac85e | 2013-11-14 03:29:16 +0000 | [diff] [blame] | 3395 | case NeonTypeFlags::Poly64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3396 | return llvm::VectorType::get(CGF->Int64Ty, V1Ty ? 1 : (1 << IsQuad)); |
Kevin Qin | fb79d7f | 2013-12-10 06:49:01 +0000 | [diff] [blame] | 3397 | case NeonTypeFlags::Poly128: |
| 3398 | // FIXME: i128 and f128 doesn't get fully support in Clang and llvm. |
| 3399 | // There is a lot of i128 and f128 API missing. |
| 3400 | // so we use v16i8 to represent poly128 and get pattern matched. |
| 3401 | return llvm::VectorType::get(CGF->Int8Ty, 16); |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 3402 | case NeonTypeFlags::Float32: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3403 | return llvm::VectorType::get(CGF->FloatTy, V1Ty ? 1 : (2 << IsQuad)); |
Tim Northover | 2fe823a | 2013-08-01 09:23:19 +0000 | [diff] [blame] | 3404 | case NeonTypeFlags::Float64: |
Jiangning Liu | 036f16d | 2013-09-24 02:48:06 +0000 | [diff] [blame] | 3405 | return llvm::VectorType::get(CGF->DoubleTy, V1Ty ? 1 : (1 << IsQuad)); |
David Blaikie | f47fa30 | 2012-01-17 02:30:50 +0000 | [diff] [blame] | 3406 | } |
Benjamin Kramer | 9b1dfe8 | 2013-09-26 16:36:08 +0000 | [diff] [blame] | 3407 | llvm_unreachable("Unknown vector element type!"); |
Nate Begeman | 5968eb2 | 2010-06-07 16:01:56 +0000 | [diff] [blame] | 3408 | } |
| 3409 | |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3410 | static llvm::VectorType *GetFloatNeonType(CodeGenFunction *CGF, |
| 3411 | NeonTypeFlags IntTypeFlags) { |
| 3412 | int IsQuad = IntTypeFlags.isQuad(); |
| 3413 | switch (IntTypeFlags.getEltType()) { |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3414 | case NeonTypeFlags::Int16: |
| 3415 | return llvm::VectorType::get(CGF->HalfTy, (4 << IsQuad)); |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 3416 | case NeonTypeFlags::Int32: |
| 3417 | return llvm::VectorType::get(CGF->FloatTy, (2 << IsQuad)); |
| 3418 | case NeonTypeFlags::Int64: |
| 3419 | return llvm::VectorType::get(CGF->DoubleTy, (1 << IsQuad)); |
| 3420 | default: |
| 3421 | llvm_unreachable("Type can't be converted to floating-point!"); |
| 3422 | } |
| 3423 | } |
| 3424 | |
Bob Wilson | 210f6dd | 2010-12-07 22:40:02 +0000 | [diff] [blame] | 3425 | Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) { |
Craig Topper | f2f1a09 | 2016-07-08 02:17:35 +0000 | [diff] [blame] | 3426 | unsigned nElts = V->getType()->getVectorNumElements(); |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 3427 | Value* SV = llvm::ConstantVector::getSplat(nElts, C); |
Nate Begeman | 4a04b46 | 2010-06-10 00:17:56 +0000 | [diff] [blame] | 3428 | return Builder.CreateShuffleVector(V, V, SV, "lane"); |
| 3429 | } |
| 3430 | |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 3431 | Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops, |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 3432 | const char *name, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 3433 | unsigned shift, bool rightshift) { |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 3434 | unsigned j = 0; |
| 3435 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 3436 | ai != ae; ++ai, ++j) |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 3437 | if (shift > 0 && shift == j) |
| 3438 | Ops[j] = EmitNeonShiftVector(Ops[j], ai->getType(), rightshift); |
| 3439 | else |
| 3440 | Ops[j] = Builder.CreateBitCast(Ops[j], ai->getType(), name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 3441 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 3442 | return Builder.CreateCall(F, Ops, name); |
Nate Begeman | ae6b1d8 | 2010-06-08 06:03:01 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 3445 | Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty, |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3446 | bool neg) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 3447 | int SV = cast<ConstantInt>(V)->getSExtValue(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3448 | return ConstantInt::get(Ty, neg ? -SV : SV); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 3451 | // \brief Right-shift a vector by a constant. |
| 3452 | Value *CodeGenFunction::EmitNeonRShiftImm(Value *Vec, Value *Shift, |
| 3453 | llvm::Type *Ty, bool usgn, |
| 3454 | const char *name) { |
| 3455 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 3456 | |
| 3457 | int ShiftAmt = cast<ConstantInt>(Shift)->getSExtValue(); |
| 3458 | int EltSize = VTy->getScalarSizeInBits(); |
| 3459 | |
| 3460 | Vec = Builder.CreateBitCast(Vec, Ty); |
| 3461 | |
| 3462 | // lshr/ashr are undefined when the shift amount is equal to the vector |
| 3463 | // element size. |
| 3464 | if (ShiftAmt == EltSize) { |
| 3465 | if (usgn) { |
| 3466 | // Right-shifting an unsigned value by its size yields 0. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 3467 | return llvm::ConstantAggregateZero::get(VTy); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 3468 | } else { |
| 3469 | // Right-shifting a signed value by its size is equivalent |
| 3470 | // to a shift of size-1. |
| 3471 | --ShiftAmt; |
| 3472 | Shift = ConstantInt::get(VTy->getElementType(), ShiftAmt); |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | Shift = EmitNeonShiftVector(Shift, Ty, false); |
| 3477 | if (usgn) |
| 3478 | return Builder.CreateLShr(Vec, Shift, name); |
| 3479 | else |
| 3480 | return Builder.CreateAShr(Vec, Shift, name); |
| 3481 | } |
| 3482 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3483 | enum { |
| 3484 | AddRetType = (1 << 0), |
| 3485 | Add1ArgType = (1 << 1), |
| 3486 | Add2ArgTypes = (1 << 2), |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3487 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3488 | VectorizeRetType = (1 << 3), |
| 3489 | VectorizeArgTypes = (1 << 4), |
| 3490 | |
| 3491 | InventFloatType = (1 << 5), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3492 | UnsignedAlts = (1 << 6), |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3493 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3494 | Use64BitVectors = (1 << 7), |
| 3495 | Use128BitVectors = (1 << 8), |
| 3496 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 3497 | Vectorize1ArgType = Add1ArgType | VectorizeArgTypes, |
| 3498 | VectorRet = AddRetType | VectorizeRetType, |
| 3499 | VectorRetGetArgs01 = |
| 3500 | AddRetType | Add2ArgTypes | VectorizeRetType | VectorizeArgTypes, |
| 3501 | FpCmpzModifiers = |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 3502 | AddRetType | VectorizeRetType | Add1ArgType | InventFloatType |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3503 | }; |
| 3504 | |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 3505 | namespace { |
| 3506 | struct NeonIntrinsicInfo { |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 3507 | const char *NameHint; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3508 | unsigned BuiltinID; |
| 3509 | unsigned LLVMIntrinsic; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3510 | unsigned AltLLVMIntrinsic; |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3511 | unsigned TypeModifier; |
| 3512 | |
| 3513 | bool operator<(unsigned RHSBuiltinID) const { |
| 3514 | return BuiltinID < RHSBuiltinID; |
| 3515 | } |
Eric Christopher | ed60b43 | 2015-11-11 02:04:08 +0000 | [diff] [blame] | 3516 | bool operator<(const NeonIntrinsicInfo &TE) const { |
| 3517 | return BuiltinID < TE.BuiltinID; |
| 3518 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3519 | }; |
Benjamin Kramer | e003ca2 | 2015-10-28 13:54:16 +0000 | [diff] [blame] | 3520 | } // end anonymous namespace |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3521 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3522 | #define NEONMAP0(NameBase) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 3523 | { #NameBase, NEON::BI__builtin_neon_ ## NameBase, 0, 0, 0 } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3524 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3525 | #define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 3526 | { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \ |
| 3527 | Intrinsic::LLVMIntrinsic, 0, TypeModifier } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 3528 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3529 | #define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier) \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 3530 | { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \ |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3531 | Intrinsic::LLVMIntrinsic, Intrinsic::AltLLVMIntrinsic, \ |
Ben Craig | cd7e9f1 | 2015-12-14 21:54:11 +0000 | [diff] [blame] | 3532 | TypeModifier } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3533 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 3534 | static const NeonIntrinsicInfo ARMSIMDIntrinsicMap [] = { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3535 | NEONMAP2(vabd_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 3536 | NEONMAP2(vabdq_v, arm_neon_vabdu, arm_neon_vabds, Add1ArgType | UnsignedAlts), |
| 3537 | NEONMAP1(vabs_v, arm_neon_vabs, 0), |
| 3538 | NEONMAP1(vabsq_v, arm_neon_vabs, 0), |
| 3539 | NEONMAP0(vaddhn_v), |
| 3540 | NEONMAP1(vaesdq_v, arm_neon_aesd, 0), |
| 3541 | NEONMAP1(vaeseq_v, arm_neon_aese, 0), |
| 3542 | NEONMAP1(vaesimcq_v, arm_neon_aesimc, 0), |
| 3543 | NEONMAP1(vaesmcq_v, arm_neon_aesmc, 0), |
| 3544 | NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType), |
| 3545 | NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType), |
| 3546 | NEONMAP1(vcage_v, arm_neon_vacge, 0), |
| 3547 | NEONMAP1(vcageq_v, arm_neon_vacge, 0), |
| 3548 | NEONMAP1(vcagt_v, arm_neon_vacgt, 0), |
| 3549 | NEONMAP1(vcagtq_v, arm_neon_vacgt, 0), |
| 3550 | NEONMAP1(vcale_v, arm_neon_vacge, 0), |
| 3551 | NEONMAP1(vcaleq_v, arm_neon_vacge, 0), |
| 3552 | NEONMAP1(vcalt_v, arm_neon_vacgt, 0), |
| 3553 | NEONMAP1(vcaltq_v, arm_neon_vacgt, 0), |
| 3554 | NEONMAP1(vcls_v, arm_neon_vcls, Add1ArgType), |
| 3555 | NEONMAP1(vclsq_v, arm_neon_vcls, Add1ArgType), |
| 3556 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 3557 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 3558 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 3559 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Ahmed Bougacha | cd5b8a0 | 2015-08-21 23:34:20 +0000 | [diff] [blame] | 3560 | NEONMAP1(vcvt_f16_f32, arm_neon_vcvtfp2hf, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3561 | NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0), |
| 3562 | NEONMAP0(vcvt_f32_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3563 | NEONMAP2(vcvt_n_f16_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3564 | NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3565 | NEONMAP1(vcvt_n_s16_v, arm_neon_vcvtfp2fxs, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3566 | NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 3567 | NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3568 | NEONMAP1(vcvt_n_u16_v, arm_neon_vcvtfp2fxu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3569 | NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 3570 | NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3571 | NEONMAP0(vcvt_s16_v), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3572 | NEONMAP0(vcvt_s32_v), |
| 3573 | NEONMAP0(vcvt_s64_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3574 | NEONMAP0(vcvt_u16_v), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3575 | NEONMAP0(vcvt_u32_v), |
| 3576 | NEONMAP0(vcvt_u64_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3577 | NEONMAP1(vcvta_s16_v, arm_neon_vcvtas, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3578 | NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0), |
| 3579 | NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0), |
| 3580 | NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0), |
| 3581 | NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3582 | NEONMAP1(vcvtaq_s16_v, arm_neon_vcvtas, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3583 | NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0), |
| 3584 | NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3585 | NEONMAP1(vcvtaq_u16_v, arm_neon_vcvtau, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3586 | NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0), |
| 3587 | NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3588 | NEONMAP1(vcvtm_s16_v, arm_neon_vcvtms, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3589 | NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0), |
| 3590 | NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3591 | NEONMAP1(vcvtm_u16_v, arm_neon_vcvtmu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3592 | NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0), |
| 3593 | NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3594 | NEONMAP1(vcvtmq_s16_v, arm_neon_vcvtms, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3595 | NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0), |
| 3596 | NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3597 | NEONMAP1(vcvtmq_u16_v, arm_neon_vcvtmu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3598 | NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0), |
| 3599 | NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3600 | NEONMAP1(vcvtn_s16_v, arm_neon_vcvtns, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3601 | NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0), |
| 3602 | NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3603 | NEONMAP1(vcvtn_u16_v, arm_neon_vcvtnu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3604 | NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0), |
| 3605 | NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3606 | NEONMAP1(vcvtnq_s16_v, arm_neon_vcvtns, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3607 | NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0), |
| 3608 | NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3609 | NEONMAP1(vcvtnq_u16_v, arm_neon_vcvtnu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3610 | NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0), |
| 3611 | NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3612 | NEONMAP1(vcvtp_s16_v, arm_neon_vcvtps, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3613 | NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0), |
| 3614 | NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3615 | NEONMAP1(vcvtp_u16_v, arm_neon_vcvtpu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3616 | NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0), |
| 3617 | NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3618 | NEONMAP1(vcvtpq_s16_v, arm_neon_vcvtps, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3619 | NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0), |
| 3620 | NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3621 | NEONMAP1(vcvtpq_u16_v, arm_neon_vcvtpu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3622 | NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0), |
| 3623 | NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0), |
| 3624 | NEONMAP0(vcvtq_f32_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3625 | NEONMAP2(vcvtq_n_f16_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3626 | NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3627 | NEONMAP1(vcvtq_n_s16_v, arm_neon_vcvtfp2fxs, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3628 | NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0), |
| 3629 | NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3630 | NEONMAP1(vcvtq_n_u16_v, arm_neon_vcvtfp2fxu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3631 | NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0), |
| 3632 | NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3633 | NEONMAP0(vcvtq_s16_v), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3634 | NEONMAP0(vcvtq_s32_v), |
| 3635 | NEONMAP0(vcvtq_s64_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3636 | NEONMAP0(vcvtq_u16_v), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3637 | NEONMAP0(vcvtq_u32_v), |
| 3638 | NEONMAP0(vcvtq_u64_v), |
| 3639 | NEONMAP0(vext_v), |
| 3640 | NEONMAP0(vextq_v), |
| 3641 | NEONMAP0(vfma_v), |
| 3642 | NEONMAP0(vfmaq_v), |
| 3643 | NEONMAP2(vhadd_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 3644 | NEONMAP2(vhaddq_v, arm_neon_vhaddu, arm_neon_vhadds, Add1ArgType | UnsignedAlts), |
| 3645 | NEONMAP2(vhsub_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 3646 | NEONMAP2(vhsubq_v, arm_neon_vhsubu, arm_neon_vhsubs, Add1ArgType | UnsignedAlts), |
| 3647 | NEONMAP0(vld1_dup_v), |
| 3648 | NEONMAP1(vld1_v, arm_neon_vld1, 0), |
| 3649 | NEONMAP0(vld1q_dup_v), |
| 3650 | NEONMAP1(vld1q_v, arm_neon_vld1, 0), |
| 3651 | NEONMAP1(vld2_lane_v, arm_neon_vld2lane, 0), |
| 3652 | NEONMAP1(vld2_v, arm_neon_vld2, 0), |
| 3653 | NEONMAP1(vld2q_lane_v, arm_neon_vld2lane, 0), |
| 3654 | NEONMAP1(vld2q_v, arm_neon_vld2, 0), |
| 3655 | NEONMAP1(vld3_lane_v, arm_neon_vld3lane, 0), |
| 3656 | NEONMAP1(vld3_v, arm_neon_vld3, 0), |
| 3657 | NEONMAP1(vld3q_lane_v, arm_neon_vld3lane, 0), |
| 3658 | NEONMAP1(vld3q_v, arm_neon_vld3, 0), |
| 3659 | NEONMAP1(vld4_lane_v, arm_neon_vld4lane, 0), |
| 3660 | NEONMAP1(vld4_v, arm_neon_vld4, 0), |
| 3661 | NEONMAP1(vld4q_lane_v, arm_neon_vld4lane, 0), |
| 3662 | NEONMAP1(vld4q_v, arm_neon_vld4, 0), |
| 3663 | NEONMAP2(vmax_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 3664 | NEONMAP1(vmaxnm_v, arm_neon_vmaxnm, Add1ArgType), |
| 3665 | NEONMAP1(vmaxnmq_v, arm_neon_vmaxnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3666 | NEONMAP2(vmaxq_v, arm_neon_vmaxu, arm_neon_vmaxs, Add1ArgType | UnsignedAlts), |
| 3667 | NEONMAP2(vmin_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 3668 | NEONMAP1(vminnm_v, arm_neon_vminnm, Add1ArgType), |
| 3669 | NEONMAP1(vminnmq_v, arm_neon_vminnm, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3670 | NEONMAP2(vminq_v, arm_neon_vminu, arm_neon_vmins, Add1ArgType | UnsignedAlts), |
| 3671 | NEONMAP0(vmovl_v), |
| 3672 | NEONMAP0(vmovn_v), |
| 3673 | NEONMAP1(vmul_v, arm_neon_vmulp, Add1ArgType), |
| 3674 | NEONMAP0(vmull_v), |
| 3675 | NEONMAP1(vmulq_v, arm_neon_vmulp, Add1ArgType), |
| 3676 | NEONMAP2(vpadal_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 3677 | NEONMAP2(vpadalq_v, arm_neon_vpadalu, arm_neon_vpadals, UnsignedAlts), |
| 3678 | NEONMAP1(vpadd_v, arm_neon_vpadd, Add1ArgType), |
| 3679 | NEONMAP2(vpaddl_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 3680 | NEONMAP2(vpaddlq_v, arm_neon_vpaddlu, arm_neon_vpaddls, UnsignedAlts), |
| 3681 | NEONMAP1(vpaddq_v, arm_neon_vpadd, Add1ArgType), |
| 3682 | NEONMAP2(vpmax_v, arm_neon_vpmaxu, arm_neon_vpmaxs, Add1ArgType | UnsignedAlts), |
| 3683 | NEONMAP2(vpmin_v, arm_neon_vpminu, arm_neon_vpmins, Add1ArgType | UnsignedAlts), |
| 3684 | NEONMAP1(vqabs_v, arm_neon_vqabs, Add1ArgType), |
| 3685 | NEONMAP1(vqabsq_v, arm_neon_vqabs, Add1ArgType), |
| 3686 | NEONMAP2(vqadd_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 3687 | NEONMAP2(vqaddq_v, arm_neon_vqaddu, arm_neon_vqadds, Add1ArgType | UnsignedAlts), |
| 3688 | NEONMAP2(vqdmlal_v, arm_neon_vqdmull, arm_neon_vqadds, 0), |
| 3689 | NEONMAP2(vqdmlsl_v, arm_neon_vqdmull, arm_neon_vqsubs, 0), |
| 3690 | NEONMAP1(vqdmulh_v, arm_neon_vqdmulh, Add1ArgType), |
| 3691 | NEONMAP1(vqdmulhq_v, arm_neon_vqdmulh, Add1ArgType), |
| 3692 | NEONMAP1(vqdmull_v, arm_neon_vqdmull, Add1ArgType), |
| 3693 | NEONMAP2(vqmovn_v, arm_neon_vqmovnu, arm_neon_vqmovns, Add1ArgType | UnsignedAlts), |
| 3694 | NEONMAP1(vqmovun_v, arm_neon_vqmovnsu, Add1ArgType), |
| 3695 | NEONMAP1(vqneg_v, arm_neon_vqneg, Add1ArgType), |
| 3696 | NEONMAP1(vqnegq_v, arm_neon_vqneg, Add1ArgType), |
| 3697 | NEONMAP1(vqrdmulh_v, arm_neon_vqrdmulh, Add1ArgType), |
| 3698 | NEONMAP1(vqrdmulhq_v, arm_neon_vqrdmulh, Add1ArgType), |
| 3699 | NEONMAP2(vqrshl_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 3700 | NEONMAP2(vqrshlq_v, arm_neon_vqrshiftu, arm_neon_vqrshifts, Add1ArgType | UnsignedAlts), |
| 3701 | NEONMAP2(vqshl_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 3702 | NEONMAP2(vqshl_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
| 3703 | NEONMAP2(vqshlq_n_v, arm_neon_vqshiftu, arm_neon_vqshifts, UnsignedAlts), |
| 3704 | NEONMAP2(vqshlq_v, arm_neon_vqshiftu, arm_neon_vqshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3705 | NEONMAP1(vqshlu_n_v, arm_neon_vqshiftsu, 0), |
| 3706 | NEONMAP1(vqshluq_n_v, arm_neon_vqshiftsu, 0), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3707 | NEONMAP2(vqsub_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 3708 | NEONMAP2(vqsubq_v, arm_neon_vqsubu, arm_neon_vqsubs, Add1ArgType | UnsignedAlts), |
| 3709 | NEONMAP1(vraddhn_v, arm_neon_vraddhn, Add1ArgType), |
| 3710 | NEONMAP2(vrecpe_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 3711 | NEONMAP2(vrecpeq_v, arm_neon_vrecpe, arm_neon_vrecpe, 0), |
| 3712 | NEONMAP1(vrecps_v, arm_neon_vrecps, Add1ArgType), |
| 3713 | NEONMAP1(vrecpsq_v, arm_neon_vrecps, Add1ArgType), |
| 3714 | NEONMAP2(vrhadd_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
| 3715 | NEONMAP2(vrhaddq_v, arm_neon_vrhaddu, arm_neon_vrhadds, Add1ArgType | UnsignedAlts), |
James Molloy | 163b1ba | 2014-09-05 13:50:34 +0000 | [diff] [blame] | 3716 | NEONMAP1(vrnd_v, arm_neon_vrintz, Add1ArgType), |
| 3717 | NEONMAP1(vrnda_v, arm_neon_vrinta, Add1ArgType), |
| 3718 | NEONMAP1(vrndaq_v, arm_neon_vrinta, Add1ArgType), |
| 3719 | NEONMAP1(vrndm_v, arm_neon_vrintm, Add1ArgType), |
| 3720 | NEONMAP1(vrndmq_v, arm_neon_vrintm, Add1ArgType), |
| 3721 | NEONMAP1(vrndn_v, arm_neon_vrintn, Add1ArgType), |
| 3722 | NEONMAP1(vrndnq_v, arm_neon_vrintn, Add1ArgType), |
| 3723 | NEONMAP1(vrndp_v, arm_neon_vrintp, Add1ArgType), |
| 3724 | NEONMAP1(vrndpq_v, arm_neon_vrintp, Add1ArgType), |
| 3725 | NEONMAP1(vrndq_v, arm_neon_vrintz, Add1ArgType), |
| 3726 | NEONMAP1(vrndx_v, arm_neon_vrintx, Add1ArgType), |
| 3727 | NEONMAP1(vrndxq_v, arm_neon_vrintx, Add1ArgType), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3728 | NEONMAP2(vrshl_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
| 3729 | NEONMAP2(vrshlq_v, arm_neon_vrshiftu, arm_neon_vrshifts, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3730 | NEONMAP2(vrshr_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
| 3731 | NEONMAP2(vrshrq_n_v, arm_neon_vrshiftu, arm_neon_vrshifts, UnsignedAlts), |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3732 | NEONMAP2(vrsqrte_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 3733 | NEONMAP2(vrsqrteq_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0), |
| 3734 | NEONMAP1(vrsqrts_v, arm_neon_vrsqrts, Add1ArgType), |
| 3735 | NEONMAP1(vrsqrtsq_v, arm_neon_vrsqrts, Add1ArgType), |
| 3736 | NEONMAP1(vrsubhn_v, arm_neon_vrsubhn, Add1ArgType), |
| 3737 | NEONMAP1(vsha1su0q_v, arm_neon_sha1su0, 0), |
| 3738 | NEONMAP1(vsha1su1q_v, arm_neon_sha1su1, 0), |
| 3739 | NEONMAP1(vsha256h2q_v, arm_neon_sha256h2, 0), |
| 3740 | NEONMAP1(vsha256hq_v, arm_neon_sha256h, 0), |
| 3741 | NEONMAP1(vsha256su0q_v, arm_neon_sha256su0, 0), |
| 3742 | NEONMAP1(vsha256su1q_v, arm_neon_sha256su1, 0), |
| 3743 | NEONMAP0(vshl_n_v), |
| 3744 | NEONMAP2(vshl_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 3745 | NEONMAP0(vshll_n_v), |
| 3746 | NEONMAP0(vshlq_n_v), |
| 3747 | NEONMAP2(vshlq_v, arm_neon_vshiftu, arm_neon_vshifts, Add1ArgType | UnsignedAlts), |
| 3748 | NEONMAP0(vshr_n_v), |
| 3749 | NEONMAP0(vshrn_n_v), |
| 3750 | NEONMAP0(vshrq_n_v), |
| 3751 | NEONMAP1(vst1_v, arm_neon_vst1, 0), |
| 3752 | NEONMAP1(vst1q_v, arm_neon_vst1, 0), |
| 3753 | NEONMAP1(vst2_lane_v, arm_neon_vst2lane, 0), |
| 3754 | NEONMAP1(vst2_v, arm_neon_vst2, 0), |
| 3755 | NEONMAP1(vst2q_lane_v, arm_neon_vst2lane, 0), |
| 3756 | NEONMAP1(vst2q_v, arm_neon_vst2, 0), |
| 3757 | NEONMAP1(vst3_lane_v, arm_neon_vst3lane, 0), |
| 3758 | NEONMAP1(vst3_v, arm_neon_vst3, 0), |
| 3759 | NEONMAP1(vst3q_lane_v, arm_neon_vst3lane, 0), |
| 3760 | NEONMAP1(vst3q_v, arm_neon_vst3, 0), |
| 3761 | NEONMAP1(vst4_lane_v, arm_neon_vst4lane, 0), |
| 3762 | NEONMAP1(vst4_v, arm_neon_vst4, 0), |
| 3763 | NEONMAP1(vst4q_lane_v, arm_neon_vst4lane, 0), |
| 3764 | NEONMAP1(vst4q_v, arm_neon_vst4, 0), |
| 3765 | NEONMAP0(vsubhn_v), |
| 3766 | NEONMAP0(vtrn_v), |
| 3767 | NEONMAP0(vtrnq_v), |
| 3768 | NEONMAP0(vtst_v), |
| 3769 | NEONMAP0(vtstq_v), |
| 3770 | NEONMAP0(vuzp_v), |
| 3771 | NEONMAP0(vuzpq_v), |
| 3772 | NEONMAP0(vzip_v), |
Tim Northover | a0c95eb | 2014-02-21 12:16:59 +0000 | [diff] [blame] | 3773 | NEONMAP0(vzipq_v) |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 3774 | }; |
| 3775 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 3776 | static const NeonIntrinsicInfo AArch64SIMDIntrinsicMap[] = { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3777 | NEONMAP1(vabs_v, aarch64_neon_abs, 0), |
| 3778 | NEONMAP1(vabsq_v, aarch64_neon_abs, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3779 | NEONMAP0(vaddhn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3780 | NEONMAP1(vaesdq_v, aarch64_crypto_aesd, 0), |
| 3781 | NEONMAP1(vaeseq_v, aarch64_crypto_aese, 0), |
| 3782 | NEONMAP1(vaesimcq_v, aarch64_crypto_aesimc, 0), |
| 3783 | NEONMAP1(vaesmcq_v, aarch64_crypto_aesmc, 0), |
| 3784 | NEONMAP1(vcage_v, aarch64_neon_facge, 0), |
| 3785 | NEONMAP1(vcageq_v, aarch64_neon_facge, 0), |
| 3786 | NEONMAP1(vcagt_v, aarch64_neon_facgt, 0), |
| 3787 | NEONMAP1(vcagtq_v, aarch64_neon_facgt, 0), |
| 3788 | NEONMAP1(vcale_v, aarch64_neon_facge, 0), |
| 3789 | NEONMAP1(vcaleq_v, aarch64_neon_facge, 0), |
| 3790 | NEONMAP1(vcalt_v, aarch64_neon_facgt, 0), |
| 3791 | NEONMAP1(vcaltq_v, aarch64_neon_facgt, 0), |
| 3792 | NEONMAP1(vcls_v, aarch64_neon_cls, Add1ArgType), |
| 3793 | NEONMAP1(vclsq_v, aarch64_neon_cls, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3794 | NEONMAP1(vclz_v, ctlz, Add1ArgType), |
| 3795 | NEONMAP1(vclzq_v, ctlz, Add1ArgType), |
| 3796 | NEONMAP1(vcnt_v, ctpop, Add1ArgType), |
| 3797 | NEONMAP1(vcntq_v, ctpop, Add1ArgType), |
Ahmed Bougacha | cd5b8a0 | 2015-08-21 23:34:20 +0000 | [diff] [blame] | 3798 | NEONMAP1(vcvt_f16_f32, aarch64_neon_vcvtfp2hf, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3799 | NEONMAP0(vcvt_f16_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3800 | NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3801 | NEONMAP0(vcvt_f32_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3802 | NEONMAP2(vcvt_n_f16_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3803 | NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 3804 | NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3805 | NEONMAP1(vcvt_n_s16_v, aarch64_neon_vcvtfp2fxs, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3806 | NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 3807 | NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3808 | NEONMAP1(vcvt_n_u16_v, aarch64_neon_vcvtfp2fxu, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3809 | NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 3810 | NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3811 | NEONMAP0(vcvtq_f16_v), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3812 | NEONMAP0(vcvtq_f32_v), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3813 | NEONMAP2(vcvtq_n_f16_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3814 | NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
| 3815 | NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3816 | NEONMAP1(vcvtq_n_s16_v, aarch64_neon_vcvtfp2fxs, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3817 | NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0), |
| 3818 | NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0), |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 3819 | NEONMAP1(vcvtq_n_u16_v, aarch64_neon_vcvtfp2fxu, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3820 | NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0), |
| 3821 | NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0), |
| 3822 | NEONMAP1(vcvtx_f32_v, aarch64_neon_fcvtxn, AddRetType | Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3823 | NEONMAP0(vext_v), |
| 3824 | NEONMAP0(vextq_v), |
| 3825 | NEONMAP0(vfma_v), |
| 3826 | NEONMAP0(vfmaq_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3827 | NEONMAP2(vhadd_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 3828 | NEONMAP2(vhaddq_v, aarch64_neon_uhadd, aarch64_neon_shadd, Add1ArgType | UnsignedAlts), |
| 3829 | NEONMAP2(vhsub_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
| 3830 | NEONMAP2(vhsubq_v, aarch64_neon_uhsub, aarch64_neon_shsub, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3831 | NEONMAP0(vmovl_v), |
| 3832 | NEONMAP0(vmovn_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3833 | NEONMAP1(vmul_v, aarch64_neon_pmul, Add1ArgType), |
| 3834 | NEONMAP1(vmulq_v, aarch64_neon_pmul, Add1ArgType), |
| 3835 | NEONMAP1(vpadd_v, aarch64_neon_addp, Add1ArgType), |
| 3836 | NEONMAP2(vpaddl_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 3837 | NEONMAP2(vpaddlq_v, aarch64_neon_uaddlp, aarch64_neon_saddlp, UnsignedAlts), |
| 3838 | NEONMAP1(vpaddq_v, aarch64_neon_addp, Add1ArgType), |
| 3839 | NEONMAP1(vqabs_v, aarch64_neon_sqabs, Add1ArgType), |
| 3840 | NEONMAP1(vqabsq_v, aarch64_neon_sqabs, Add1ArgType), |
| 3841 | NEONMAP2(vqadd_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 3842 | NEONMAP2(vqaddq_v, aarch64_neon_uqadd, aarch64_neon_sqadd, Add1ArgType | UnsignedAlts), |
| 3843 | NEONMAP2(vqdmlal_v, aarch64_neon_sqdmull, aarch64_neon_sqadd, 0), |
| 3844 | NEONMAP2(vqdmlsl_v, aarch64_neon_sqdmull, aarch64_neon_sqsub, 0), |
| 3845 | NEONMAP1(vqdmulh_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 3846 | NEONMAP1(vqdmulhq_v, aarch64_neon_sqdmulh, Add1ArgType), |
| 3847 | NEONMAP1(vqdmull_v, aarch64_neon_sqdmull, Add1ArgType), |
| 3848 | NEONMAP2(vqmovn_v, aarch64_neon_uqxtn, aarch64_neon_sqxtn, Add1ArgType | UnsignedAlts), |
| 3849 | NEONMAP1(vqmovun_v, aarch64_neon_sqxtun, Add1ArgType), |
| 3850 | NEONMAP1(vqneg_v, aarch64_neon_sqneg, Add1ArgType), |
| 3851 | NEONMAP1(vqnegq_v, aarch64_neon_sqneg, Add1ArgType), |
| 3852 | NEONMAP1(vqrdmulh_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 3853 | NEONMAP1(vqrdmulhq_v, aarch64_neon_sqrdmulh, Add1ArgType), |
| 3854 | NEONMAP2(vqrshl_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 3855 | NEONMAP2(vqrshlq_v, aarch64_neon_uqrshl, aarch64_neon_sqrshl, Add1ArgType | UnsignedAlts), |
| 3856 | NEONMAP2(vqshl_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl, UnsignedAlts), |
| 3857 | NEONMAP2(vqshl_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
| 3858 | NEONMAP2(vqshlq_n_v, aarch64_neon_uqshl, aarch64_neon_sqshl,UnsignedAlts), |
| 3859 | NEONMAP2(vqshlq_v, aarch64_neon_uqshl, aarch64_neon_sqshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3860 | NEONMAP1(vqshlu_n_v, aarch64_neon_sqshlu, 0), |
| 3861 | NEONMAP1(vqshluq_n_v, aarch64_neon_sqshlu, 0), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3862 | NEONMAP2(vqsub_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 3863 | NEONMAP2(vqsubq_v, aarch64_neon_uqsub, aarch64_neon_sqsub, Add1ArgType | UnsignedAlts), |
| 3864 | NEONMAP1(vraddhn_v, aarch64_neon_raddhn, Add1ArgType), |
| 3865 | NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 3866 | NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0), |
| 3867 | NEONMAP1(vrecps_v, aarch64_neon_frecps, Add1ArgType), |
| 3868 | NEONMAP1(vrecpsq_v, aarch64_neon_frecps, Add1ArgType), |
| 3869 | NEONMAP2(vrhadd_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 3870 | NEONMAP2(vrhaddq_v, aarch64_neon_urhadd, aarch64_neon_srhadd, Add1ArgType | UnsignedAlts), |
| 3871 | NEONMAP2(vrshl_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
| 3872 | NEONMAP2(vrshlq_v, aarch64_neon_urshl, aarch64_neon_srshl, Add1ArgType | UnsignedAlts), |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 3873 | NEONMAP2(vrshr_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
| 3874 | NEONMAP2(vrshrq_n_v, aarch64_neon_urshl, aarch64_neon_srshl, UnsignedAlts), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3875 | NEONMAP2(vrsqrte_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 3876 | NEONMAP2(vrsqrteq_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0), |
| 3877 | NEONMAP1(vrsqrts_v, aarch64_neon_frsqrts, Add1ArgType), |
| 3878 | NEONMAP1(vrsqrtsq_v, aarch64_neon_frsqrts, Add1ArgType), |
| 3879 | NEONMAP1(vrsubhn_v, aarch64_neon_rsubhn, Add1ArgType), |
| 3880 | NEONMAP1(vsha1su0q_v, aarch64_crypto_sha1su0, 0), |
| 3881 | NEONMAP1(vsha1su1q_v, aarch64_crypto_sha1su1, 0), |
| 3882 | NEONMAP1(vsha256h2q_v, aarch64_crypto_sha256h2, 0), |
| 3883 | NEONMAP1(vsha256hq_v, aarch64_crypto_sha256h, 0), |
| 3884 | NEONMAP1(vsha256su0q_v, aarch64_crypto_sha256su0, 0), |
| 3885 | NEONMAP1(vsha256su1q_v, aarch64_crypto_sha256su1, 0), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3886 | NEONMAP0(vshl_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3887 | NEONMAP2(vshl_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3888 | NEONMAP0(vshll_n_v), |
| 3889 | NEONMAP0(vshlq_n_v), |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3890 | NEONMAP2(vshlq_v, aarch64_neon_ushl, aarch64_neon_sshl, Add1ArgType | UnsignedAlts), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 3891 | NEONMAP0(vshr_n_v), |
| 3892 | NEONMAP0(vshrn_n_v), |
| 3893 | NEONMAP0(vshrq_n_v), |
| 3894 | NEONMAP0(vsubhn_v), |
| 3895 | NEONMAP0(vtst_v), |
| 3896 | NEONMAP0(vtstq_v), |
| 3897 | }; |
| 3898 | |
Craig Topper | 273dbc6 | 2015-10-18 05:29:26 +0000 | [diff] [blame] | 3899 | static const NeonIntrinsicInfo AArch64SISDIntrinsicMap[] = { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 3900 | NEONMAP1(vabdd_f64, aarch64_sisd_fabd, Add1ArgType), |
| 3901 | NEONMAP1(vabds_f32, aarch64_sisd_fabd, Add1ArgType), |
| 3902 | NEONMAP1(vabsd_s64, aarch64_neon_abs, Add1ArgType), |
| 3903 | NEONMAP1(vaddlv_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 3904 | NEONMAP1(vaddlv_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 3905 | NEONMAP1(vaddlvq_s32, aarch64_neon_saddlv, AddRetType | Add1ArgType), |
| 3906 | NEONMAP1(vaddlvq_u32, aarch64_neon_uaddlv, AddRetType | Add1ArgType), |
| 3907 | NEONMAP1(vaddv_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 3908 | NEONMAP1(vaddv_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 3909 | NEONMAP1(vaddv_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3910 | NEONMAP1(vaddvq_f32, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 3911 | NEONMAP1(vaddvq_f64, aarch64_neon_faddv, AddRetType | Add1ArgType), |
| 3912 | NEONMAP1(vaddvq_s32, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 3913 | NEONMAP1(vaddvq_s64, aarch64_neon_saddv, AddRetType | Add1ArgType), |
| 3914 | NEONMAP1(vaddvq_u32, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3915 | NEONMAP1(vaddvq_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3916 | NEONMAP1(vcaged_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3917 | NEONMAP1(vcages_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3918 | NEONMAP1(vcagtd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3919 | NEONMAP1(vcagts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3920 | NEONMAP1(vcaled_f64, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3921 | NEONMAP1(vcales_f32, aarch64_neon_facge, AddRetType | Add1ArgType), |
| 3922 | NEONMAP1(vcaltd_f64, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3923 | NEONMAP1(vcalts_f32, aarch64_neon_facgt, AddRetType | Add1ArgType), |
| 3924 | NEONMAP1(vcvtad_s64_f64, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 3925 | NEONMAP1(vcvtad_u64_f64, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 3926 | NEONMAP1(vcvtas_s32_f32, aarch64_neon_fcvtas, AddRetType | Add1ArgType), |
| 3927 | NEONMAP1(vcvtas_u32_f32, aarch64_neon_fcvtau, AddRetType | Add1ArgType), |
| 3928 | NEONMAP1(vcvtd_n_f64_s64, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 3929 | NEONMAP1(vcvtd_n_f64_u64, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 3930 | NEONMAP1(vcvtd_n_s64_f64, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 3931 | NEONMAP1(vcvtd_n_u64_f64, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 3932 | NEONMAP1(vcvtmd_s64_f64, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 3933 | NEONMAP1(vcvtmd_u64_f64, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 3934 | NEONMAP1(vcvtms_s32_f32, aarch64_neon_fcvtms, AddRetType | Add1ArgType), |
| 3935 | NEONMAP1(vcvtms_u32_f32, aarch64_neon_fcvtmu, AddRetType | Add1ArgType), |
| 3936 | NEONMAP1(vcvtnd_s64_f64, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 3937 | NEONMAP1(vcvtnd_u64_f64, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 3938 | NEONMAP1(vcvtns_s32_f32, aarch64_neon_fcvtns, AddRetType | Add1ArgType), |
| 3939 | NEONMAP1(vcvtns_u32_f32, aarch64_neon_fcvtnu, AddRetType | Add1ArgType), |
| 3940 | NEONMAP1(vcvtpd_s64_f64, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 3941 | NEONMAP1(vcvtpd_u64_f64, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 3942 | NEONMAP1(vcvtps_s32_f32, aarch64_neon_fcvtps, AddRetType | Add1ArgType), |
| 3943 | NEONMAP1(vcvtps_u32_f32, aarch64_neon_fcvtpu, AddRetType | Add1ArgType), |
| 3944 | NEONMAP1(vcvts_n_f32_s32, aarch64_neon_vcvtfxs2fp, AddRetType | Add1ArgType), |
| 3945 | NEONMAP1(vcvts_n_f32_u32, aarch64_neon_vcvtfxu2fp, AddRetType | Add1ArgType), |
| 3946 | NEONMAP1(vcvts_n_s32_f32, aarch64_neon_vcvtfp2fxs, AddRetType | Add1ArgType), |
| 3947 | NEONMAP1(vcvts_n_u32_f32, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType), |
| 3948 | NEONMAP1(vcvtxd_f32_f64, aarch64_sisd_fcvtxn, 0), |
| 3949 | NEONMAP1(vmaxnmv_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3950 | NEONMAP1(vmaxnmvq_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3951 | NEONMAP1(vmaxnmvq_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3952 | NEONMAP1(vmaxv_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3953 | NEONMAP1(vmaxv_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 3954 | NEONMAP1(vmaxv_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 3955 | NEONMAP1(vmaxvq_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3956 | NEONMAP1(vmaxvq_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3957 | NEONMAP1(vmaxvq_s32, aarch64_neon_smaxv, AddRetType | Add1ArgType), |
| 3958 | NEONMAP1(vmaxvq_u32, aarch64_neon_umaxv, AddRetType | Add1ArgType), |
| 3959 | NEONMAP1(vminnmv_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3960 | NEONMAP1(vminnmvq_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3961 | NEONMAP1(vminnmvq_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3962 | NEONMAP1(vminv_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3963 | NEONMAP1(vminv_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 3964 | NEONMAP1(vminv_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 3965 | NEONMAP1(vminvq_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3966 | NEONMAP1(vminvq_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3967 | NEONMAP1(vminvq_s32, aarch64_neon_sminv, AddRetType | Add1ArgType), |
| 3968 | NEONMAP1(vminvq_u32, aarch64_neon_uminv, AddRetType | Add1ArgType), |
| 3969 | NEONMAP1(vmull_p64, aarch64_neon_pmull64, 0), |
| 3970 | NEONMAP1(vmulxd_f64, aarch64_neon_fmulx, Add1ArgType), |
| 3971 | NEONMAP1(vmulxs_f32, aarch64_neon_fmulx, Add1ArgType), |
| 3972 | NEONMAP1(vpaddd_s64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3973 | NEONMAP1(vpaddd_u64, aarch64_neon_uaddv, AddRetType | Add1ArgType), |
| 3974 | NEONMAP1(vpmaxnmqd_f64, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3975 | NEONMAP1(vpmaxnms_f32, aarch64_neon_fmaxnmv, AddRetType | Add1ArgType), |
| 3976 | NEONMAP1(vpmaxqd_f64, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3977 | NEONMAP1(vpmaxs_f32, aarch64_neon_fmaxv, AddRetType | Add1ArgType), |
| 3978 | NEONMAP1(vpminnmqd_f64, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3979 | NEONMAP1(vpminnms_f32, aarch64_neon_fminnmv, AddRetType | Add1ArgType), |
| 3980 | NEONMAP1(vpminqd_f64, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3981 | NEONMAP1(vpmins_f32, aarch64_neon_fminv, AddRetType | Add1ArgType), |
| 3982 | NEONMAP1(vqabsb_s8, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 3983 | NEONMAP1(vqabsd_s64, aarch64_neon_sqabs, Add1ArgType), |
| 3984 | NEONMAP1(vqabsh_s16, aarch64_neon_sqabs, Vectorize1ArgType | Use64BitVectors), |
| 3985 | NEONMAP1(vqabss_s32, aarch64_neon_sqabs, Add1ArgType), |
| 3986 | NEONMAP1(vqaddb_s8, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 3987 | NEONMAP1(vqaddb_u8, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 3988 | NEONMAP1(vqaddd_s64, aarch64_neon_sqadd, Add1ArgType), |
| 3989 | NEONMAP1(vqaddd_u64, aarch64_neon_uqadd, Add1ArgType), |
| 3990 | NEONMAP1(vqaddh_s16, aarch64_neon_sqadd, Vectorize1ArgType | Use64BitVectors), |
| 3991 | NEONMAP1(vqaddh_u16, aarch64_neon_uqadd, Vectorize1ArgType | Use64BitVectors), |
| 3992 | NEONMAP1(vqadds_s32, aarch64_neon_sqadd, Add1ArgType), |
| 3993 | NEONMAP1(vqadds_u32, aarch64_neon_uqadd, Add1ArgType), |
| 3994 | NEONMAP1(vqdmulhh_s16, aarch64_neon_sqdmulh, Vectorize1ArgType | Use64BitVectors), |
| 3995 | NEONMAP1(vqdmulhs_s32, aarch64_neon_sqdmulh, Add1ArgType), |
| 3996 | NEONMAP1(vqdmullh_s16, aarch64_neon_sqdmull, VectorRet | Use128BitVectors), |
| 3997 | NEONMAP1(vqdmulls_s32, aarch64_neon_sqdmulls_scalar, 0), |
| 3998 | NEONMAP1(vqmovnd_s64, aarch64_neon_scalar_sqxtn, AddRetType | Add1ArgType), |
| 3999 | NEONMAP1(vqmovnd_u64, aarch64_neon_scalar_uqxtn, AddRetType | Add1ArgType), |
| 4000 | NEONMAP1(vqmovnh_s16, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 4001 | NEONMAP1(vqmovnh_u16, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 4002 | NEONMAP1(vqmovns_s32, aarch64_neon_sqxtn, VectorRet | Use64BitVectors), |
| 4003 | NEONMAP1(vqmovns_u32, aarch64_neon_uqxtn, VectorRet | Use64BitVectors), |
| 4004 | NEONMAP1(vqmovund_s64, aarch64_neon_scalar_sqxtun, AddRetType | Add1ArgType), |
| 4005 | NEONMAP1(vqmovunh_s16, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 4006 | NEONMAP1(vqmovuns_s32, aarch64_neon_sqxtun, VectorRet | Use64BitVectors), |
| 4007 | NEONMAP1(vqnegb_s8, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 4008 | NEONMAP1(vqnegd_s64, aarch64_neon_sqneg, Add1ArgType), |
| 4009 | NEONMAP1(vqnegh_s16, aarch64_neon_sqneg, Vectorize1ArgType | Use64BitVectors), |
| 4010 | NEONMAP1(vqnegs_s32, aarch64_neon_sqneg, Add1ArgType), |
| 4011 | NEONMAP1(vqrdmulhh_s16, aarch64_neon_sqrdmulh, Vectorize1ArgType | Use64BitVectors), |
| 4012 | NEONMAP1(vqrdmulhs_s32, aarch64_neon_sqrdmulh, Add1ArgType), |
| 4013 | NEONMAP1(vqrshlb_s8, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 4014 | NEONMAP1(vqrshlb_u8, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 4015 | NEONMAP1(vqrshld_s64, aarch64_neon_sqrshl, Add1ArgType), |
| 4016 | NEONMAP1(vqrshld_u64, aarch64_neon_uqrshl, Add1ArgType), |
| 4017 | NEONMAP1(vqrshlh_s16, aarch64_neon_sqrshl, Vectorize1ArgType | Use64BitVectors), |
| 4018 | NEONMAP1(vqrshlh_u16, aarch64_neon_uqrshl, Vectorize1ArgType | Use64BitVectors), |
| 4019 | NEONMAP1(vqrshls_s32, aarch64_neon_sqrshl, Add1ArgType), |
| 4020 | NEONMAP1(vqrshls_u32, aarch64_neon_uqrshl, Add1ArgType), |
| 4021 | NEONMAP1(vqrshrnd_n_s64, aarch64_neon_sqrshrn, AddRetType), |
| 4022 | NEONMAP1(vqrshrnd_n_u64, aarch64_neon_uqrshrn, AddRetType), |
| 4023 | NEONMAP1(vqrshrnh_n_s16, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 4024 | NEONMAP1(vqrshrnh_n_u16, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 4025 | NEONMAP1(vqrshrns_n_s32, aarch64_neon_sqrshrn, VectorRet | Use64BitVectors), |
| 4026 | NEONMAP1(vqrshrns_n_u32, aarch64_neon_uqrshrn, VectorRet | Use64BitVectors), |
| 4027 | NEONMAP1(vqrshrund_n_s64, aarch64_neon_sqrshrun, AddRetType), |
| 4028 | NEONMAP1(vqrshrunh_n_s16, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 4029 | NEONMAP1(vqrshruns_n_s32, aarch64_neon_sqrshrun, VectorRet | Use64BitVectors), |
| 4030 | NEONMAP1(vqshlb_n_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 4031 | NEONMAP1(vqshlb_n_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 4032 | NEONMAP1(vqshlb_s8, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 4033 | NEONMAP1(vqshlb_u8, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 4034 | NEONMAP1(vqshld_s64, aarch64_neon_sqshl, Add1ArgType), |
| 4035 | NEONMAP1(vqshld_u64, aarch64_neon_uqshl, Add1ArgType), |
| 4036 | NEONMAP1(vqshlh_n_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 4037 | NEONMAP1(vqshlh_n_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 4038 | NEONMAP1(vqshlh_s16, aarch64_neon_sqshl, Vectorize1ArgType | Use64BitVectors), |
| 4039 | NEONMAP1(vqshlh_u16, aarch64_neon_uqshl, Vectorize1ArgType | Use64BitVectors), |
| 4040 | NEONMAP1(vqshls_n_s32, aarch64_neon_sqshl, Add1ArgType), |
| 4041 | NEONMAP1(vqshls_n_u32, aarch64_neon_uqshl, Add1ArgType), |
| 4042 | NEONMAP1(vqshls_s32, aarch64_neon_sqshl, Add1ArgType), |
| 4043 | NEONMAP1(vqshls_u32, aarch64_neon_uqshl, Add1ArgType), |
| 4044 | NEONMAP1(vqshlub_n_s8, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 4045 | NEONMAP1(vqshluh_n_s16, aarch64_neon_sqshlu, Vectorize1ArgType | Use64BitVectors), |
| 4046 | NEONMAP1(vqshlus_n_s32, aarch64_neon_sqshlu, Add1ArgType), |
| 4047 | NEONMAP1(vqshrnd_n_s64, aarch64_neon_sqshrn, AddRetType), |
| 4048 | NEONMAP1(vqshrnd_n_u64, aarch64_neon_uqshrn, AddRetType), |
| 4049 | NEONMAP1(vqshrnh_n_s16, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 4050 | NEONMAP1(vqshrnh_n_u16, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 4051 | NEONMAP1(vqshrns_n_s32, aarch64_neon_sqshrn, VectorRet | Use64BitVectors), |
| 4052 | NEONMAP1(vqshrns_n_u32, aarch64_neon_uqshrn, VectorRet | Use64BitVectors), |
| 4053 | NEONMAP1(vqshrund_n_s64, aarch64_neon_sqshrun, AddRetType), |
| 4054 | NEONMAP1(vqshrunh_n_s16, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 4055 | NEONMAP1(vqshruns_n_s32, aarch64_neon_sqshrun, VectorRet | Use64BitVectors), |
| 4056 | NEONMAP1(vqsubb_s8, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 4057 | NEONMAP1(vqsubb_u8, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 4058 | NEONMAP1(vqsubd_s64, aarch64_neon_sqsub, Add1ArgType), |
| 4059 | NEONMAP1(vqsubd_u64, aarch64_neon_uqsub, Add1ArgType), |
| 4060 | NEONMAP1(vqsubh_s16, aarch64_neon_sqsub, Vectorize1ArgType | Use64BitVectors), |
| 4061 | NEONMAP1(vqsubh_u16, aarch64_neon_uqsub, Vectorize1ArgType | Use64BitVectors), |
| 4062 | NEONMAP1(vqsubs_s32, aarch64_neon_sqsub, Add1ArgType), |
| 4063 | NEONMAP1(vqsubs_u32, aarch64_neon_uqsub, Add1ArgType), |
| 4064 | NEONMAP1(vrecped_f64, aarch64_neon_frecpe, Add1ArgType), |
| 4065 | NEONMAP1(vrecpes_f32, aarch64_neon_frecpe, Add1ArgType), |
| 4066 | NEONMAP1(vrecpxd_f64, aarch64_neon_frecpx, Add1ArgType), |
| 4067 | NEONMAP1(vrecpxs_f32, aarch64_neon_frecpx, Add1ArgType), |
| 4068 | NEONMAP1(vrshld_s64, aarch64_neon_srshl, Add1ArgType), |
| 4069 | NEONMAP1(vrshld_u64, aarch64_neon_urshl, Add1ArgType), |
| 4070 | NEONMAP1(vrsqrted_f64, aarch64_neon_frsqrte, Add1ArgType), |
| 4071 | NEONMAP1(vrsqrtes_f32, aarch64_neon_frsqrte, Add1ArgType), |
| 4072 | NEONMAP1(vrsqrtsd_f64, aarch64_neon_frsqrts, Add1ArgType), |
| 4073 | NEONMAP1(vrsqrtss_f32, aarch64_neon_frsqrts, Add1ArgType), |
| 4074 | NEONMAP1(vsha1cq_u32, aarch64_crypto_sha1c, 0), |
| 4075 | NEONMAP1(vsha1h_u32, aarch64_crypto_sha1h, 0), |
| 4076 | NEONMAP1(vsha1mq_u32, aarch64_crypto_sha1m, 0), |
| 4077 | NEONMAP1(vsha1pq_u32, aarch64_crypto_sha1p, 0), |
| 4078 | NEONMAP1(vshld_s64, aarch64_neon_sshl, Add1ArgType), |
| 4079 | NEONMAP1(vshld_u64, aarch64_neon_ushl, Add1ArgType), |
| 4080 | NEONMAP1(vslid_n_s64, aarch64_neon_vsli, Vectorize1ArgType), |
| 4081 | NEONMAP1(vslid_n_u64, aarch64_neon_vsli, Vectorize1ArgType), |
| 4082 | NEONMAP1(vsqaddb_u8, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 4083 | NEONMAP1(vsqaddd_u64, aarch64_neon_usqadd, Add1ArgType), |
| 4084 | NEONMAP1(vsqaddh_u16, aarch64_neon_usqadd, Vectorize1ArgType | Use64BitVectors), |
| 4085 | NEONMAP1(vsqadds_u32, aarch64_neon_usqadd, Add1ArgType), |
| 4086 | NEONMAP1(vsrid_n_s64, aarch64_neon_vsri, Vectorize1ArgType), |
| 4087 | NEONMAP1(vsrid_n_u64, aarch64_neon_vsri, Vectorize1ArgType), |
| 4088 | NEONMAP1(vuqaddb_s8, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 4089 | NEONMAP1(vuqaddd_s64, aarch64_neon_suqadd, Add1ArgType), |
| 4090 | NEONMAP1(vuqaddh_s16, aarch64_neon_suqadd, Vectorize1ArgType | Use64BitVectors), |
| 4091 | NEONMAP1(vuqadds_s32, aarch64_neon_suqadd, Add1ArgType), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4092 | }; |
| 4093 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4094 | #undef NEONMAP0 |
| 4095 | #undef NEONMAP1 |
| 4096 | #undef NEONMAP2 |
| 4097 | |
| 4098 | static bool NEONSIMDIntrinsicsProvenSorted = false; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4099 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 4100 | static bool AArch64SIMDIntrinsicsProvenSorted = false; |
| 4101 | static bool AArch64SISDIntrinsicsProvenSorted = false; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4102 | |
| 4103 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4104 | static const NeonIntrinsicInfo * |
Craig Topper | 00bbdcf | 2014-06-28 23:22:23 +0000 | [diff] [blame] | 4105 | findNeonIntrinsicInMap(ArrayRef<NeonIntrinsicInfo> IntrinsicMap, |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4106 | unsigned BuiltinID, bool &MapProvenSorted) { |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 4107 | |
| 4108 | #ifndef NDEBUG |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4109 | if (!MapProvenSorted) { |
Eric Christopher | ed60b43 | 2015-11-11 02:04:08 +0000 | [diff] [blame] | 4110 | assert(std::is_sorted(std::begin(IntrinsicMap), std::end(IntrinsicMap))); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4111 | MapProvenSorted = true; |
| 4112 | } |
Tim Northover | db3e5e2 | 2014-02-19 11:55:06 +0000 | [diff] [blame] | 4113 | #endif |
| 4114 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4115 | const NeonIntrinsicInfo *Builtin = |
| 4116 | std::lower_bound(IntrinsicMap.begin(), IntrinsicMap.end(), BuiltinID); |
| 4117 | |
| 4118 | if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID) |
| 4119 | return Builtin; |
| 4120 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4121 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4122 | } |
| 4123 | |
| 4124 | Function *CodeGenFunction::LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
| 4125 | unsigned Modifier, |
| 4126 | llvm::Type *ArgType, |
| 4127 | const CallExpr *E) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4128 | int VectorSize = 0; |
| 4129 | if (Modifier & Use64BitVectors) |
| 4130 | VectorSize = 64; |
| 4131 | else if (Modifier & Use128BitVectors) |
| 4132 | VectorSize = 128; |
| 4133 | |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 4134 | // Return type. |
| 4135 | SmallVector<llvm::Type *, 3> Tys; |
| 4136 | if (Modifier & AddRetType) { |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 4137 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 4138 | if (Modifier & VectorizeRetType) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4139 | Ty = llvm::VectorType::get( |
| 4140 | Ty, VectorSize ? VectorSize / Ty->getPrimitiveSizeInBits() : 1); |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 4141 | |
| 4142 | Tys.push_back(Ty); |
| 4143 | } |
| 4144 | |
| 4145 | // Arguments. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4146 | if (Modifier & VectorizeArgTypes) { |
| 4147 | int Elts = VectorSize ? VectorSize / ArgType->getPrimitiveSizeInBits() : 1; |
| 4148 | ArgType = llvm::VectorType::get(ArgType, Elts); |
| 4149 | } |
Tim Northover | 2d83796 | 2014-02-21 11:57:20 +0000 | [diff] [blame] | 4150 | |
| 4151 | if (Modifier & (Add1ArgType | Add2ArgTypes)) |
| 4152 | Tys.push_back(ArgType); |
| 4153 | |
| 4154 | if (Modifier & Add2ArgTypes) |
| 4155 | Tys.push_back(ArgType); |
| 4156 | |
| 4157 | if (Modifier & InventFloatType) |
| 4158 | Tys.push_back(FloatTy); |
| 4159 | |
| 4160 | return CGM.getIntrinsic(IntrinsicID, Tys); |
| 4161 | } |
| 4162 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4163 | static Value *EmitCommonNeonSISDBuiltinExpr(CodeGenFunction &CGF, |
| 4164 | const NeonIntrinsicInfo &SISDInfo, |
| 4165 | SmallVectorImpl<Value *> &Ops, |
| 4166 | const CallExpr *E) { |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4167 | unsigned BuiltinID = SISDInfo.BuiltinID; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4168 | unsigned int Int = SISDInfo.LLVMIntrinsic; |
| 4169 | unsigned Modifier = SISDInfo.TypeModifier; |
| 4170 | const char *s = SISDInfo.NameHint; |
| 4171 | |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 4172 | switch (BuiltinID) { |
| 4173 | case NEON::BI__builtin_neon_vcled_s64: |
| 4174 | case NEON::BI__builtin_neon_vcled_u64: |
| 4175 | case NEON::BI__builtin_neon_vcles_f32: |
| 4176 | case NEON::BI__builtin_neon_vcled_f64: |
| 4177 | case NEON::BI__builtin_neon_vcltd_s64: |
| 4178 | case NEON::BI__builtin_neon_vcltd_u64: |
| 4179 | case NEON::BI__builtin_neon_vclts_f32: |
| 4180 | case NEON::BI__builtin_neon_vcltd_f64: |
| 4181 | case NEON::BI__builtin_neon_vcales_f32: |
| 4182 | case NEON::BI__builtin_neon_vcaled_f64: |
| 4183 | case NEON::BI__builtin_neon_vcalts_f32: |
| 4184 | case NEON::BI__builtin_neon_vcaltd_f64: |
| 4185 | // Only one direction of comparisons actually exist, cmle is actually a cmge |
| 4186 | // with swapped operands. The table gives us the right intrinsic but we |
| 4187 | // still need to do the swap. |
| 4188 | std::swap(Ops[0], Ops[1]); |
| 4189 | break; |
| 4190 | } |
| 4191 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4192 | assert(Int && "Generic code assumes a valid intrinsic"); |
| 4193 | |
| 4194 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 4195 | const Expr *Arg = E->getArg(0); |
| 4196 | llvm::Type *ArgTy = CGF.ConvertType(Arg->getType()); |
| 4197 | Function *F = CGF.LookupNeonLLVMIntrinsic(Int, Modifier, ArgTy, E); |
| 4198 | |
| 4199 | int j = 0; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4200 | ConstantInt *C0 = ConstantInt::get(CGF.SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4201 | for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end(); |
| 4202 | ai != ae; ++ai, ++j) { |
| 4203 | llvm::Type *ArgTy = ai->getType(); |
| 4204 | if (Ops[j]->getType()->getPrimitiveSizeInBits() == |
| 4205 | ArgTy->getPrimitiveSizeInBits()) |
| 4206 | continue; |
| 4207 | |
| 4208 | assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy()); |
| 4209 | // The constant argument to an _n_ intrinsic always has Int32Ty, so truncate |
| 4210 | // it before inserting. |
| 4211 | Ops[j] = |
| 4212 | CGF.Builder.CreateTruncOrBitCast(Ops[j], ArgTy->getVectorElementType()); |
| 4213 | Ops[j] = |
| 4214 | CGF.Builder.CreateInsertElement(UndefValue::get(ArgTy), Ops[j], C0); |
| 4215 | } |
| 4216 | |
| 4217 | Value *Result = CGF.EmitNeonCall(F, Ops, s); |
| 4218 | llvm::Type *ResultType = CGF.ConvertType(E->getType()); |
| 4219 | if (ResultType->getPrimitiveSizeInBits() < |
| 4220 | Result->getType()->getPrimitiveSizeInBits()) |
| 4221 | return CGF.Builder.CreateExtractElement(Result, C0); |
| 4222 | |
| 4223 | return CGF.Builder.CreateBitCast(Result, ResultType, s); |
| 4224 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4225 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4226 | Value *CodeGenFunction::EmitCommonNeonBuiltinExpr( |
| 4227 | unsigned BuiltinID, unsigned LLVMIntrinsic, unsigned AltLLVMIntrinsic, |
| 4228 | const char *NameHint, unsigned Modifier, const CallExpr *E, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4229 | SmallVectorImpl<llvm::Value *> &Ops, Address PtrOp0, Address PtrOp1) { |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4230 | // Get the last argument, which specifies the vector type. |
| 4231 | llvm::APSInt NeonTypeConst; |
| 4232 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 4233 | if (!Arg->isIntegerConstantExpr(NeonTypeConst, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4234 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4235 | |
| 4236 | // Determine the type of this overloaded NEON intrinsic. |
| 4237 | NeonTypeFlags Type(NeonTypeConst.getZExtValue()); |
| 4238 | bool Usgn = Type.isUnsigned(); |
| 4239 | bool Quad = Type.isQuad(); |
| 4240 | |
| 4241 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 4242 | llvm::Type *Ty = VTy; |
| 4243 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4244 | return nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4245 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4246 | auto getAlignmentValue32 = [&](Address addr) -> Value* { |
| 4247 | return Builder.getInt32(addr.getAlignment().getQuantity()); |
| 4248 | }; |
| 4249 | |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4250 | unsigned Int = LLVMIntrinsic; |
| 4251 | if ((Modifier & UnsignedAlts) && !Usgn) |
| 4252 | Int = AltLLVMIntrinsic; |
| 4253 | |
| 4254 | switch (BuiltinID) { |
| 4255 | default: break; |
| 4256 | case NEON::BI__builtin_neon_vabs_v: |
| 4257 | case NEON::BI__builtin_neon_vabsq_v: |
| 4258 | if (VTy->getElementType()->isFloatingPointTy()) |
| 4259 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::fabs, Ty), Ops, "vabs"); |
| 4260 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), Ops, "vabs"); |
| 4261 | case NEON::BI__builtin_neon_vaddhn_v: { |
| 4262 | llvm::VectorType *SrcTy = |
| 4263 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 4264 | |
| 4265 | // %sum = add <4 x i32> %lhs, %rhs |
| 4266 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 4267 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 4268 | Ops[0] = Builder.CreateAdd(Ops[0], Ops[1], "vaddhn"); |
| 4269 | |
| 4270 | // %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] | 4271 | Constant *ShiftAmt = |
| 4272 | ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4273 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vaddhn"); |
| 4274 | |
| 4275 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 4276 | return Builder.CreateTrunc(Ops[0], VTy, "vaddhn"); |
| 4277 | } |
| 4278 | case NEON::BI__builtin_neon_vcale_v: |
| 4279 | case NEON::BI__builtin_neon_vcaleq_v: |
| 4280 | case NEON::BI__builtin_neon_vcalt_v: |
| 4281 | case NEON::BI__builtin_neon_vcaltq_v: |
| 4282 | std::swap(Ops[0], Ops[1]); |
Galina Kistanova | 0872d6c | 2017-06-03 06:30:46 +0000 | [diff] [blame] | 4283 | LLVM_FALLTHROUGH; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4284 | case NEON::BI__builtin_neon_vcage_v: |
| 4285 | case NEON::BI__builtin_neon_vcageq_v: |
| 4286 | case NEON::BI__builtin_neon_vcagt_v: |
| 4287 | case NEON::BI__builtin_neon_vcagtq_v: { |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4288 | llvm::Type *Ty; |
| 4289 | switch (VTy->getScalarSizeInBits()) { |
| 4290 | default: llvm_unreachable("unexpected type"); |
| 4291 | case 32: |
| 4292 | Ty = FloatTy; |
| 4293 | break; |
| 4294 | case 64: |
| 4295 | Ty = DoubleTy; |
| 4296 | break; |
| 4297 | case 16: |
| 4298 | Ty = HalfTy; |
| 4299 | break; |
| 4300 | } |
| 4301 | llvm::Type *VecFlt = llvm::VectorType::get(Ty, VTy->getNumElements()); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4302 | llvm::Type *Tys[] = { VTy, VecFlt }; |
| 4303 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 4304 | return EmitNeonCall(F, Ops, NameHint); |
| 4305 | } |
| 4306 | case NEON::BI__builtin_neon_vclz_v: |
| 4307 | case NEON::BI__builtin_neon_vclzq_v: |
| 4308 | // We generate target-independent intrinsic, which needs a second argument |
| 4309 | // for whether or not clz of zero is undefined; on ARM it isn't. |
| 4310 | Ops.push_back(Builder.getInt1(getTarget().isCLZForZeroUndef())); |
| 4311 | break; |
| 4312 | case NEON::BI__builtin_neon_vcvt_f32_v: |
| 4313 | case NEON::BI__builtin_neon_vcvtq_f32_v: |
| 4314 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4315 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float32, false, Quad)); |
| 4316 | return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 4317 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4318 | case NEON::BI__builtin_neon_vcvt_f16_v: |
| 4319 | case NEON::BI__builtin_neon_vcvtq_f16_v: |
| 4320 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4321 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float16, false, Quad)); |
| 4322 | return Usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 4323 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 4324 | case NEON::BI__builtin_neon_vcvt_n_f16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4325 | case NEON::BI__builtin_neon_vcvt_n_f32_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4326 | case NEON::BI__builtin_neon_vcvt_n_f64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4327 | case NEON::BI__builtin_neon_vcvtq_n_f16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4328 | case NEON::BI__builtin_neon_vcvtq_n_f32_v: |
| 4329 | case NEON::BI__builtin_neon_vcvtq_n_f64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 4330 | llvm::Type *Tys[2] = { GetFloatNeonType(this, Type), Ty }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4331 | Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 4332 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 4333 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 4334 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4335 | case NEON::BI__builtin_neon_vcvt_n_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4336 | case NEON::BI__builtin_neon_vcvt_n_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4337 | case NEON::BI__builtin_neon_vcvt_n_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4338 | case NEON::BI__builtin_neon_vcvt_n_u32_v: |
| 4339 | case NEON::BI__builtin_neon_vcvt_n_s64_v: |
| 4340 | case NEON::BI__builtin_neon_vcvt_n_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4341 | case NEON::BI__builtin_neon_vcvtq_n_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4342 | case NEON::BI__builtin_neon_vcvtq_n_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4343 | case NEON::BI__builtin_neon_vcvtq_n_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4344 | case NEON::BI__builtin_neon_vcvtq_n_u32_v: |
| 4345 | case NEON::BI__builtin_neon_vcvtq_n_s64_v: |
| 4346 | case NEON::BI__builtin_neon_vcvtq_n_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 4347 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4348 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
| 4349 | return EmitNeonCall(F, Ops, "vcvt_n"); |
| 4350 | } |
| 4351 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 4352 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 4353 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 4354 | case NEON::BI__builtin_neon_vcvt_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4355 | case NEON::BI__builtin_neon_vcvt_s16_v: |
| 4356 | case NEON::BI__builtin_neon_vcvt_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4357 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 4358 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 4359 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4360 | case NEON::BI__builtin_neon_vcvtq_u64_v: |
| 4361 | case NEON::BI__builtin_neon_vcvtq_s16_v: |
| 4362 | case NEON::BI__builtin_neon_vcvtq_u16_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 4363 | Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4364 | return Usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt") |
| 4365 | : Builder.CreateFPToSI(Ops[0], Ty, "vcvt"); |
| 4366 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4367 | case NEON::BI__builtin_neon_vcvta_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4368 | case NEON::BI__builtin_neon_vcvta_s32_v: |
| 4369 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 4370 | case NEON::BI__builtin_neon_vcvta_u32_v: |
| 4371 | case NEON::BI__builtin_neon_vcvta_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4372 | case NEON::BI__builtin_neon_vcvtaq_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4373 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 4374 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4375 | case NEON::BI__builtin_neon_vcvtaq_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4376 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 4377 | case NEON::BI__builtin_neon_vcvtaq_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4378 | case NEON::BI__builtin_neon_vcvtn_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4379 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
| 4380 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4381 | case NEON::BI__builtin_neon_vcvtn_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4382 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
| 4383 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4384 | case NEON::BI__builtin_neon_vcvtnq_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4385 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
| 4386 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4387 | case NEON::BI__builtin_neon_vcvtnq_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4388 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 4389 | case NEON::BI__builtin_neon_vcvtnq_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4390 | case NEON::BI__builtin_neon_vcvtp_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4391 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
| 4392 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4393 | case NEON::BI__builtin_neon_vcvtp_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4394 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
| 4395 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4396 | case NEON::BI__builtin_neon_vcvtpq_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4397 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
| 4398 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4399 | case NEON::BI__builtin_neon_vcvtpq_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4400 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 4401 | case NEON::BI__builtin_neon_vcvtpq_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4402 | case NEON::BI__builtin_neon_vcvtm_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4403 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
| 4404 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4405 | case NEON::BI__builtin_neon_vcvtm_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4406 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
| 4407 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4408 | case NEON::BI__builtin_neon_vcvtmq_s16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4409 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
| 4410 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 4411 | case NEON::BI__builtin_neon_vcvtmq_u16_v: |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4412 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 4413 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 4414 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4415 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, NameHint); |
| 4416 | } |
| 4417 | case NEON::BI__builtin_neon_vext_v: |
| 4418 | case NEON::BI__builtin_neon_vextq_v: { |
| 4419 | int CV = cast<ConstantInt>(Ops[2])->getSExtValue(); |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 4420 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4421 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4422 | Indices.push_back(i+CV); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4423 | |
| 4424 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4425 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4426 | return Builder.CreateShuffleVector(Ops[0], Ops[1], Indices, "vext"); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4427 | } |
| 4428 | case NEON::BI__builtin_neon_vfma_v: |
| 4429 | case NEON::BI__builtin_neon_vfmaq_v: { |
| 4430 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 4431 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4432 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4433 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 4434 | |
| 4435 | // NEON intrinsic puts accumulator first, unlike the LLVM fma. |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4436 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4437 | } |
| 4438 | case NEON::BI__builtin_neon_vld1_v: |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4439 | case NEON::BI__builtin_neon_vld1q_v: { |
| 4440 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4441 | Ops.push_back(getAlignmentValue32(PtrOp0)); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4442 | return EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Tys), Ops, "vld1"); |
| 4443 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4444 | case NEON::BI__builtin_neon_vld2_v: |
| 4445 | case NEON::BI__builtin_neon_vld2q_v: |
| 4446 | case NEON::BI__builtin_neon_vld3_v: |
| 4447 | case NEON::BI__builtin_neon_vld3q_v: |
| 4448 | case NEON::BI__builtin_neon_vld4_v: |
| 4449 | case NEON::BI__builtin_neon_vld4q_v: { |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4450 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4451 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4452 | Value *Align = getAlignmentValue32(PtrOp1); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4453 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4454 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 4455 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4456 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4457 | } |
| 4458 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 4459 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 4460 | Value *V = UndefValue::get(Ty); |
| 4461 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4462 | PtrOp0 = Builder.CreateBitCast(PtrOp0, Ty); |
| 4463 | LoadInst *Ld = Builder.CreateLoad(PtrOp0); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 4464 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4465 | Ops[0] = Builder.CreateInsertElement(V, Ld, CI); |
| 4466 | return EmitNeonSplat(Ops[0], CI); |
| 4467 | } |
| 4468 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 4469 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 4470 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 4471 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 4472 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 4473 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4474 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 4475 | Function *F = CGM.getIntrinsic(LLVMIntrinsic, Tys); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4476 | for (unsigned I = 2; I < Ops.size() - 1; ++I) |
| 4477 | Ops[I] = Builder.CreateBitCast(Ops[I], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4478 | Ops.push_back(getAlignmentValue32(PtrOp1)); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4479 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), NameHint); |
| 4480 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 4481 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4482 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4483 | } |
| 4484 | case NEON::BI__builtin_neon_vmovl_v: { |
| 4485 | llvm::Type *DTy =llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 4486 | Ops[0] = Builder.CreateBitCast(Ops[0], DTy); |
| 4487 | if (Usgn) |
| 4488 | return Builder.CreateZExt(Ops[0], Ty, "vmovl"); |
| 4489 | return Builder.CreateSExt(Ops[0], Ty, "vmovl"); |
| 4490 | } |
| 4491 | case NEON::BI__builtin_neon_vmovn_v: { |
| 4492 | llvm::Type *QTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 4493 | Ops[0] = Builder.CreateBitCast(Ops[0], QTy); |
| 4494 | return Builder.CreateTrunc(Ops[0], Ty, "vmovn"); |
| 4495 | } |
| 4496 | case NEON::BI__builtin_neon_vmull_v: |
| 4497 | // FIXME: the integer vmull operations could be emitted in terms of pure |
| 4498 | // LLVM IR (2 exts followed by a mul). Unfortunately LLVM has a habit of |
| 4499 | // hoisting the exts outside loops. Until global ISel comes along that can |
| 4500 | // see through such movement this leads to bad CodeGen. So we need an |
| 4501 | // intrinsic for now. |
| 4502 | Int = Usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls; |
| 4503 | Int = Type.isPoly() ? (unsigned)Intrinsic::arm_neon_vmullp : Int; |
| 4504 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 4505 | case NEON::BI__builtin_neon_vpadal_v: |
| 4506 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 4507 | // The source operand type has twice as many elements of half the size. |
| 4508 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 4509 | llvm::Type *EltTy = |
| 4510 | llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 4511 | llvm::Type *NarrowTy = |
| 4512 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 4513 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 4514 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, NameHint); |
| 4515 | } |
| 4516 | case NEON::BI__builtin_neon_vpaddl_v: |
| 4517 | case NEON::BI__builtin_neon_vpaddlq_v: { |
| 4518 | // The source operand type has twice as many elements of half the size. |
| 4519 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); |
| 4520 | llvm::Type *EltTy = llvm::IntegerType::get(getLLVMContext(), EltBits / 2); |
| 4521 | llvm::Type *NarrowTy = |
| 4522 | llvm::VectorType::get(EltTy, VTy->getNumElements() * 2); |
| 4523 | llvm::Type *Tys[2] = { Ty, NarrowTy }; |
| 4524 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vpaddl"); |
| 4525 | } |
| 4526 | case NEON::BI__builtin_neon_vqdmlal_v: |
| 4527 | case NEON::BI__builtin_neon_vqdmlsl_v: { |
| 4528 | SmallVector<Value *, 2> MulOps(Ops.begin() + 1, Ops.end()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4529 | Ops[1] = |
| 4530 | EmitNeonCall(CGM.getIntrinsic(LLVMIntrinsic, Ty), MulOps, "vqdmlal"); |
| 4531 | Ops.resize(2); |
| 4532 | return EmitNeonCall(CGM.getIntrinsic(AltLLVMIntrinsic, Ty), Ops, NameHint); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4533 | } |
| 4534 | case NEON::BI__builtin_neon_vqshl_n_v: |
| 4535 | case NEON::BI__builtin_neon_vqshlq_n_v: |
| 4536 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshl_n", |
| 4537 | 1, false); |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 4538 | case NEON::BI__builtin_neon_vqshlu_n_v: |
| 4539 | case NEON::BI__builtin_neon_vqshluq_n_v: |
| 4540 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshlu_n", |
| 4541 | 1, false); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4542 | case NEON::BI__builtin_neon_vrecpe_v: |
| 4543 | case NEON::BI__builtin_neon_vrecpeq_v: |
| 4544 | case NEON::BI__builtin_neon_vrsqrte_v: |
| 4545 | case NEON::BI__builtin_neon_vrsqrteq_v: |
| 4546 | Int = Ty->isFPOrFPVectorTy() ? LLVMIntrinsic : AltLLVMIntrinsic; |
| 4547 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, NameHint); |
| 4548 | |
Yi Kong | 1083eb5 | 2014-07-29 09:25:17 +0000 | [diff] [blame] | 4549 | case NEON::BI__builtin_neon_vrshr_n_v: |
| 4550 | case NEON::BI__builtin_neon_vrshrq_n_v: |
| 4551 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshr_n", |
| 4552 | 1, true); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4553 | case NEON::BI__builtin_neon_vshl_n_v: |
| 4554 | case NEON::BI__builtin_neon_vshlq_n_v: |
| 4555 | Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false); |
| 4556 | return Builder.CreateShl(Builder.CreateBitCast(Ops[0],Ty), Ops[1], |
| 4557 | "vshl_n"); |
| 4558 | case NEON::BI__builtin_neon_vshll_n_v: { |
| 4559 | llvm::Type *SrcTy = llvm::VectorType::getTruncatedElementVectorType(VTy); |
| 4560 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 4561 | if (Usgn) |
| 4562 | Ops[0] = Builder.CreateZExt(Ops[0], VTy); |
| 4563 | else |
| 4564 | Ops[0] = Builder.CreateSExt(Ops[0], VTy); |
| 4565 | Ops[1] = EmitNeonShiftVector(Ops[1], VTy, false); |
| 4566 | return Builder.CreateShl(Ops[0], Ops[1], "vshll_n"); |
| 4567 | } |
| 4568 | case NEON::BI__builtin_neon_vshrn_n_v: { |
| 4569 | llvm::Type *SrcTy = llvm::VectorType::getExtendedElementVectorType(VTy); |
| 4570 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 4571 | Ops[1] = EmitNeonShiftVector(Ops[1], SrcTy, false); |
| 4572 | if (Usgn) |
| 4573 | Ops[0] = Builder.CreateLShr(Ops[0], Ops[1]); |
| 4574 | else |
| 4575 | Ops[0] = Builder.CreateAShr(Ops[0], Ops[1]); |
| 4576 | return Builder.CreateTrunc(Ops[0], Ty, "vshrn_n"); |
| 4577 | } |
| 4578 | case NEON::BI__builtin_neon_vshr_n_v: |
| 4579 | case NEON::BI__builtin_neon_vshrq_n_v: |
| 4580 | return EmitNeonRShiftImm(Ops[0], Ops[1], Ty, Usgn, "vshr_n"); |
| 4581 | case NEON::BI__builtin_neon_vst1_v: |
| 4582 | case NEON::BI__builtin_neon_vst1q_v: |
| 4583 | case NEON::BI__builtin_neon_vst2_v: |
| 4584 | case NEON::BI__builtin_neon_vst2q_v: |
| 4585 | case NEON::BI__builtin_neon_vst3_v: |
| 4586 | case NEON::BI__builtin_neon_vst3q_v: |
| 4587 | case NEON::BI__builtin_neon_vst4_v: |
| 4588 | case NEON::BI__builtin_neon_vst4q_v: |
| 4589 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 4590 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 4591 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 4592 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 4593 | case NEON::BI__builtin_neon_vst4_lane_v: |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4594 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 4595 | llvm::Type *Tys[] = {Int8PtrTy, Ty}; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4596 | Ops.push_back(getAlignmentValue32(PtrOp0)); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 4597 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, ""); |
| 4598 | } |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4599 | case NEON::BI__builtin_neon_vsubhn_v: { |
| 4600 | llvm::VectorType *SrcTy = |
| 4601 | llvm::VectorType::getExtendedElementVectorType(VTy); |
| 4602 | |
| 4603 | // %sum = add <4 x i32> %lhs, %rhs |
| 4604 | Ops[0] = Builder.CreateBitCast(Ops[0], SrcTy); |
| 4605 | Ops[1] = Builder.CreateBitCast(Ops[1], SrcTy); |
| 4606 | Ops[0] = Builder.CreateSub(Ops[0], Ops[1], "vsubhn"); |
| 4607 | |
| 4608 | // %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] | 4609 | Constant *ShiftAmt = |
| 4610 | ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4611 | Ops[0] = Builder.CreateLShr(Ops[0], ShiftAmt, "vsubhn"); |
| 4612 | |
| 4613 | // %res = trunc <4 x i32> %high to <4 x i16> |
| 4614 | return Builder.CreateTrunc(Ops[0], VTy, "vsubhn"); |
| 4615 | } |
| 4616 | case NEON::BI__builtin_neon_vtrn_v: |
| 4617 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 4618 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 4619 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4620 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4621 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4622 | |
| 4623 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 4624 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4625 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4626 | Indices.push_back(i+vi); |
| 4627 | Indices.push_back(i+e+vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4628 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 4629 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4630 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vtrn"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4631 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4632 | } |
| 4633 | return SV; |
| 4634 | } |
| 4635 | case NEON::BI__builtin_neon_vtst_v: |
| 4636 | case NEON::BI__builtin_neon_vtstq_v: { |
| 4637 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 4638 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4639 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 4640 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
| 4641 | ConstantAggregateZero::get(Ty)); |
| 4642 | return Builder.CreateSExt(Ops[0], Ty, "vtst"); |
| 4643 | } |
| 4644 | case NEON::BI__builtin_neon_vuzp_v: |
| 4645 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 4646 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 4647 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4648 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4649 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4650 | |
| 4651 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 4652 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4653 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4654 | Indices.push_back(2*i+vi); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4655 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 4656 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4657 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vuzp"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4658 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4659 | } |
| 4660 | return SV; |
| 4661 | } |
| 4662 | case NEON::BI__builtin_neon_vzip_v: |
| 4663 | case NEON::BI__builtin_neon_vzipq_v: { |
| 4664 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 4665 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 4666 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 4667 | Value *SV = nullptr; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4668 | |
| 4669 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 4670 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4671 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4672 | Indices.push_back((i + vi*e) >> 1); |
| 4673 | Indices.push_back(((i + vi*e) >> 1)+e); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4674 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 4675 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4676 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vzip"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 4677 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 4678 | } |
| 4679 | return SV; |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | assert(Int && "Expected valid intrinsic number"); |
| 4684 | |
| 4685 | // Determine the type(s) of this overloaded AArch64 intrinsic. |
| 4686 | Function *F = LookupNeonLLVMIntrinsic(Int, Modifier, Ty, E); |
| 4687 | |
| 4688 | Value *Result = EmitNeonCall(F, Ops, NameHint); |
| 4689 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 4690 | // AArch64 intrinsic one-element vector type cast to |
| 4691 | // scalar type expected by the builtin |
| 4692 | return Builder.CreateBitCast(Result, ResultType, NameHint); |
| 4693 | } |
| 4694 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 4695 | Value *CodeGenFunction::EmitAArch64CompareBuiltinExpr( |
| 4696 | Value *Op, llvm::Type *Ty, const CmpInst::Predicate Fp, |
| 4697 | const CmpInst::Predicate Ip, const Twine &Name) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4698 | llvm::Type *OTy = Op->getType(); |
| 4699 | |
| 4700 | // FIXME: this is utterly horrific. We should not be looking at previous |
| 4701 | // codegen context to find out what needs doing. Unfortunately TableGen |
| 4702 | // currently gives us exactly the same calls for vceqz_f32 and vceqz_s32 |
| 4703 | // (etc). |
| 4704 | if (BitCastInst *BI = dyn_cast<BitCastInst>(Op)) |
| 4705 | OTy = BI->getOperand(0)->getType(); |
| 4706 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 4707 | Op = Builder.CreateBitCast(Op, OTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4708 | if (OTy->getScalarType()->isFloatingPointTy()) { |
| 4709 | Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 4710 | } else { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 4711 | Op = Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy)); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 4712 | } |
Hao Liu | f96fd37 | 2013-12-23 02:44:00 +0000 | [diff] [blame] | 4713 | return Builder.CreateSExt(Op, Ty, Name); |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 4714 | } |
| 4715 | |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 4716 | static Value *packTBLDVectorList(CodeGenFunction &CGF, ArrayRef<Value *> Ops, |
| 4717 | Value *ExtOp, Value *IndexOp, |
| 4718 | llvm::Type *ResTy, unsigned IntID, |
| 4719 | const char *Name) { |
| 4720 | SmallVector<Value *, 2> TblOps; |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 4721 | if (ExtOp) |
| 4722 | TblOps.push_back(ExtOp); |
| 4723 | |
| 4724 | // Build a vector containing sequential number like (0, 1, 2, ..., 15) |
| 4725 | SmallVector<uint32_t, 16> Indices; |
| 4726 | llvm::VectorType *TblTy = cast<llvm::VectorType>(Ops[0]->getType()); |
| 4727 | for (unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4728 | Indices.push_back(2*i); |
| 4729 | Indices.push_back(2*i+1); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 4730 | } |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 4731 | |
| 4732 | int PairPos = 0, End = Ops.size() - 1; |
| 4733 | while (PairPos < End) { |
| 4734 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4735 | Ops[PairPos+1], Indices, |
| 4736 | Name)); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 4737 | PairPos += 2; |
| 4738 | } |
| 4739 | |
| 4740 | // If there's an odd number of 64-bit lookup table, fill the high 64-bit |
| 4741 | // of the 128-bit lookup table with zero. |
| 4742 | if (PairPos == End) { |
| 4743 | Value *ZeroTbl = ConstantAggregateZero::get(TblTy); |
| 4744 | TblOps.push_back(CGF.Builder.CreateShuffleVector(Ops[PairPos], |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 4745 | ZeroTbl, Indices, Name)); |
Jiangning Liu | 18b707c | 2013-11-14 01:57:55 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 4748 | Function *TblF; |
| 4749 | TblOps.push_back(IndexOp); |
| 4750 | TblF = CGF.CGM.getIntrinsic(IntID, ResTy); |
| 4751 | |
| 4752 | return CGF.EmitNeonCall(TblF, TblOps, Name); |
| 4753 | } |
| 4754 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 4755 | Value *CodeGenFunction::GetValueForARMHint(unsigned BuiltinID) { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4756 | unsigned Value; |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 4757 | switch (BuiltinID) { |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 4758 | default: |
| 4759 | return nullptr; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 4760 | case ARM::BI__builtin_arm_nop: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4761 | Value = 0; |
| 4762 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 4763 | case ARM::BI__builtin_arm_yield: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 4764 | case ARM::BI__yield: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4765 | Value = 1; |
| 4766 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 4767 | case ARM::BI__builtin_arm_wfe: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 4768 | case ARM::BI__wfe: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4769 | Value = 2; |
| 4770 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 4771 | case ARM::BI__builtin_arm_wfi: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 4772 | case ARM::BI__wfi: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4773 | Value = 3; |
| 4774 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 4775 | case ARM::BI__builtin_arm_sev: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 4776 | case ARM::BI__sev: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4777 | Value = 4; |
| 4778 | break; |
Saleem Abdulrasool | ece7217 | 2014-07-03 02:43:20 +0000 | [diff] [blame] | 4779 | case ARM::BI__builtin_arm_sevl: |
Saleem Abdulrasool | 956c2ec | 2014-05-04 02:52:25 +0000 | [diff] [blame] | 4780 | case ARM::BI__sevl: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4781 | Value = 5; |
| 4782 | break; |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 4783 | } |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4784 | |
| 4785 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_hint), |
| 4786 | llvm::ConstantInt::get(Int32Ty, Value)); |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 4787 | } |
Saleem Abdulrasool | b9f07e3 | 2014-04-25 21:13:29 +0000 | [diff] [blame] | 4788 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4789 | // Generates the IR for the read/write special register builtin, |
| 4790 | // ValueType is the type of the value that is to be written or read, |
| 4791 | // RegisterType is the type of the register being written to or read from. |
| 4792 | static Value *EmitSpecialRegisterBuiltin(CodeGenFunction &CGF, |
| 4793 | const CallExpr *E, |
| 4794 | llvm::Type *RegisterType, |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 4795 | llvm::Type *ValueType, |
| 4796 | bool IsRead, |
| 4797 | StringRef SysReg = "") { |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4798 | // write and register intrinsics only support 32 and 64 bit operations. |
| 4799 | assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64)) |
| 4800 | && "Unsupported size for register."); |
| 4801 | |
| 4802 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 4803 | CodeGen::CodeGenModule &CGM = CGF.CGM; |
| 4804 | LLVMContext &Context = CGM.getLLVMContext(); |
| 4805 | |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 4806 | if (SysReg.empty()) { |
| 4807 | const Expr *SysRegStrExpr = E->getArg(0)->IgnoreParenCasts(); |
Zachary Turner | 26dab12 | 2016-12-13 17:10:16 +0000 | [diff] [blame] | 4808 | SysReg = cast<clang::StringLiteral>(SysRegStrExpr)->getString(); |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 4809 | } |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 4810 | |
| 4811 | llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) }; |
| 4812 | llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops); |
| 4813 | llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName); |
| 4814 | |
| 4815 | llvm::Type *Types[] = { RegisterType }; |
| 4816 | |
| 4817 | bool MixedTypes = RegisterType->isIntegerTy(64) && ValueType->isIntegerTy(32); |
| 4818 | assert(!(RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64)) |
| 4819 | && "Can't fit 64-bit value in 32-bit register"); |
| 4820 | |
| 4821 | if (IsRead) { |
| 4822 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types); |
| 4823 | llvm::Value *Call = Builder.CreateCall(F, Metadata); |
| 4824 | |
| 4825 | if (MixedTypes) |
| 4826 | // Read into 64 bit register and then truncate result to 32 bit. |
| 4827 | return Builder.CreateTrunc(Call, ValueType); |
| 4828 | |
| 4829 | if (ValueType->isPointerTy()) |
| 4830 | // Have i32/i64 result (Call) but want to return a VoidPtrTy (i8*). |
| 4831 | return Builder.CreateIntToPtr(Call, ValueType); |
| 4832 | |
| 4833 | return Call; |
| 4834 | } |
| 4835 | |
| 4836 | llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types); |
| 4837 | llvm::Value *ArgValue = CGF.EmitScalarExpr(E->getArg(1)); |
| 4838 | if (MixedTypes) { |
| 4839 | // Extend 32 bit write value to 64 bit to pass to write. |
| 4840 | ArgValue = Builder.CreateZExt(ArgValue, RegisterType); |
| 4841 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 4842 | } |
| 4843 | |
| 4844 | if (ValueType->isPointerTy()) { |
| 4845 | // Have VoidPtrTy ArgValue but want to return an i32/i64. |
| 4846 | ArgValue = Builder.CreatePtrToInt(ArgValue, RegisterType); |
| 4847 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 4848 | } |
| 4849 | |
| 4850 | return Builder.CreateCall(F, { Metadata, ArgValue }); |
| 4851 | } |
| 4852 | |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4853 | /// Return true if BuiltinID is an overloaded Neon intrinsic with an extra |
| 4854 | /// argument that specifies the vector type. |
| 4855 | static bool HasExtraNeonArgument(unsigned BuiltinID) { |
| 4856 | switch (BuiltinID) { |
| 4857 | default: break; |
| 4858 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 4859 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 4860 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 4861 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 4862 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 4863 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 4864 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 4865 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 4866 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 4867 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 4868 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 4869 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 4870 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 4871 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 4872 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 4873 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 4874 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 4875 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 4876 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 4877 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 4878 | case NEON::BI__builtin_neon_vsha1h_u32: |
| 4879 | case NEON::BI__builtin_neon_vsha1cq_u32: |
| 4880 | case NEON::BI__builtin_neon_vsha1pq_u32: |
| 4881 | case NEON::BI__builtin_neon_vsha1mq_u32: |
Erich Keane | 8202521 | 2017-11-15 00:11:24 +0000 | [diff] [blame] | 4882 | case clang::ARM::BI_MoveToCoprocessor: |
| 4883 | case clang::ARM::BI_MoveToCoprocessor2: |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 4884 | return false; |
| 4885 | } |
| 4886 | return true; |
| 4887 | } |
| 4888 | |
Saleem Abdulrasool | a14ac3f4 | 2014-12-04 04:52:37 +0000 | [diff] [blame] | 4889 | Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
| 4890 | const CallExpr *E) { |
| 4891 | if (auto Hint = GetValueForARMHint(BuiltinID)) |
| 4892 | return Hint; |
Saleem Abdulrasool | 38ed6de | 2014-05-02 06:53:57 +0000 | [diff] [blame] | 4893 | |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 4894 | if (BuiltinID == ARM::BI__emit) { |
| 4895 | bool IsThumb = getTarget().getTriple().getArch() == llvm::Triple::thumb; |
| 4896 | llvm::FunctionType *FTy = |
| 4897 | llvm::FunctionType::get(VoidTy, /*Variadic=*/false); |
| 4898 | |
| 4899 | APSInt Value; |
| 4900 | if (!E->getArg(0)->EvaluateAsInt(Value, CGM.getContext())) |
| 4901 | llvm_unreachable("Sema will ensure that the parameter is constant"); |
| 4902 | |
| 4903 | uint64_t ZExtValue = Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue(); |
| 4904 | |
| 4905 | llvm::InlineAsm *Emit = |
| 4906 | IsThumb ? InlineAsm::get(FTy, ".inst.n 0x" + utohexstr(ZExtValue), "", |
| 4907 | /*SideEffects=*/true) |
| 4908 | : InlineAsm::get(FTy, ".inst 0x" + utohexstr(ZExtValue), "", |
| 4909 | /*SideEffects=*/true); |
| 4910 | |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 4911 | return Builder.CreateCall(Emit); |
Saleem Abdulrasool | 86b881c | 2014-12-17 17:52:30 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
Yi Kong | 1d268af | 2014-08-26 12:48:06 +0000 | [diff] [blame] | 4914 | if (BuiltinID == ARM::BI__builtin_arm_dbg) { |
| 4915 | Value *Option = EmitScalarExpr(E->getArg(0)); |
| 4916 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_dbg), Option); |
| 4917 | } |
| 4918 | |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 4919 | if (BuiltinID == ARM::BI__builtin_arm_prefetch) { |
| 4920 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 4921 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 4922 | Value *IsData = EmitScalarExpr(E->getArg(2)); |
| 4923 | |
| 4924 | // Locality is not supported on ARM target |
| 4925 | Value *Locality = llvm::ConstantInt::get(Int32Ty, 3); |
| 4926 | |
| 4927 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 4928 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | 26d104a | 2014-08-13 19:18:14 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
Jim Grosbach | 171ec34 | 2014-06-16 21:55:58 +0000 | [diff] [blame] | 4931 | if (BuiltinID == ARM::BI__builtin_arm_rbit) { |
Chad Rosier | c22abb3 | 2017-01-10 18:55:11 +0000 | [diff] [blame] | 4932 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 4933 | return Builder.CreateCall( |
| 4934 | CGM.getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg, "rbit"); |
Jim Grosbach | 171ec34 | 2014-06-16 21:55:58 +0000 | [diff] [blame] | 4935 | } |
| 4936 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4937 | if (BuiltinID == ARM::BI__clear_cache) { |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 4938 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
Rafael Espindola | a54062e | 2010-06-07 17:26:50 +0000 | [diff] [blame] | 4939 | const FunctionDecl *FD = E->getDirectCallee(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4940 | Value *Ops[2]; |
Rafael Espindola | 2219fc5 | 2013-05-14 12:45:47 +0000 | [diff] [blame] | 4941 | for (unsigned i = 0; i < 2; i++) |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 4942 | Ops[i] = EmitScalarExpr(E->getArg(i)); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 4943 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 4944 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4945 | StringRef Name = FD->getName(); |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 4946 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 4947 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 4948 | |
Ranjeet Singh | ca2b3e7b | 2016-06-17 00:59:41 +0000 | [diff] [blame] | 4949 | if (BuiltinID == ARM::BI__builtin_arm_mcrr || |
| 4950 | BuiltinID == ARM::BI__builtin_arm_mcrr2) { |
| 4951 | Function *F; |
| 4952 | |
| 4953 | switch (BuiltinID) { |
| 4954 | default: llvm_unreachable("unexpected builtin"); |
| 4955 | case ARM::BI__builtin_arm_mcrr: |
| 4956 | F = CGM.getIntrinsic(Intrinsic::arm_mcrr); |
| 4957 | break; |
| 4958 | case ARM::BI__builtin_arm_mcrr2: |
| 4959 | F = CGM.getIntrinsic(Intrinsic::arm_mcrr2); |
| 4960 | break; |
| 4961 | } |
| 4962 | |
| 4963 | // MCRR{2} instruction has 5 operands but |
| 4964 | // the intrinsic has 4 because Rt and Rt2 |
| 4965 | // are represented as a single unsigned 64 |
| 4966 | // bit integer in the intrinsic definition |
| 4967 | // but internally it's represented as 2 32 |
| 4968 | // bit integers. |
| 4969 | |
| 4970 | Value *Coproc = EmitScalarExpr(E->getArg(0)); |
| 4971 | Value *Opc1 = EmitScalarExpr(E->getArg(1)); |
| 4972 | Value *RtAndRt2 = EmitScalarExpr(E->getArg(2)); |
| 4973 | Value *CRm = EmitScalarExpr(E->getArg(3)); |
| 4974 | |
| 4975 | Value *C1 = llvm::ConstantInt::get(Int64Ty, 32); |
| 4976 | Value *Rt = Builder.CreateTruncOrBitCast(RtAndRt2, Int32Ty); |
| 4977 | Value *Rt2 = Builder.CreateLShr(RtAndRt2, C1); |
| 4978 | Rt2 = Builder.CreateTruncOrBitCast(Rt2, Int32Ty); |
| 4979 | |
| 4980 | return Builder.CreateCall(F, {Coproc, Opc1, Rt, Rt2, CRm}); |
| 4981 | } |
| 4982 | |
| 4983 | if (BuiltinID == ARM::BI__builtin_arm_mrrc || |
| 4984 | BuiltinID == ARM::BI__builtin_arm_mrrc2) { |
| 4985 | Function *F; |
| 4986 | |
| 4987 | switch (BuiltinID) { |
| 4988 | default: llvm_unreachable("unexpected builtin"); |
| 4989 | case ARM::BI__builtin_arm_mrrc: |
| 4990 | F = CGM.getIntrinsic(Intrinsic::arm_mrrc); |
| 4991 | break; |
| 4992 | case ARM::BI__builtin_arm_mrrc2: |
| 4993 | F = CGM.getIntrinsic(Intrinsic::arm_mrrc2); |
| 4994 | break; |
| 4995 | } |
| 4996 | |
| 4997 | Value *Coproc = EmitScalarExpr(E->getArg(0)); |
| 4998 | Value *Opc1 = EmitScalarExpr(E->getArg(1)); |
| 4999 | Value *CRm = EmitScalarExpr(E->getArg(2)); |
| 5000 | Value *RtAndRt2 = Builder.CreateCall(F, {Coproc, Opc1, CRm}); |
| 5001 | |
| 5002 | // Returns an unsigned 64 bit integer, represented |
| 5003 | // as two 32 bit integers. |
| 5004 | |
| 5005 | Value *Rt = Builder.CreateExtractValue(RtAndRt2, 1); |
| 5006 | Value *Rt1 = Builder.CreateExtractValue(RtAndRt2, 0); |
| 5007 | Rt = Builder.CreateZExt(Rt, Int64Ty); |
| 5008 | Rt1 = Builder.CreateZExt(Rt1, Int64Ty); |
| 5009 | |
| 5010 | Value *ShiftCast = llvm::ConstantInt::get(Int64Ty, 32); |
| 5011 | RtAndRt2 = Builder.CreateShl(Rt, ShiftCast, "shl", true); |
| 5012 | RtAndRt2 = Builder.CreateOr(RtAndRt2, Rt1); |
| 5013 | |
| 5014 | return Builder.CreateBitCast(RtAndRt2, ConvertType(E->getType())); |
| 5015 | } |
| 5016 | |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5017 | if (BuiltinID == ARM::BI__builtin_arm_ldrexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5018 | ((BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 5019 | BuiltinID == ARM::BI__builtin_arm_ldaex) && |
Saleem Abdulrasool | e700cab | 2014-07-05 20:10:05 +0000 | [diff] [blame] | 5020 | getContext().getTypeSize(E->getType()) == 64) || |
| 5021 | BuiltinID == ARM::BI__ldrexd) { |
| 5022 | Function *F; |
| 5023 | |
| 5024 | switch (BuiltinID) { |
| 5025 | default: llvm_unreachable("unexpected builtin"); |
| 5026 | case ARM::BI__builtin_arm_ldaex: |
| 5027 | F = CGM.getIntrinsic(Intrinsic::arm_ldaexd); |
| 5028 | break; |
| 5029 | case ARM::BI__builtin_arm_ldrexd: |
| 5030 | case ARM::BI__builtin_arm_ldrex: |
| 5031 | case ARM::BI__ldrexd: |
| 5032 | F = CGM.getIntrinsic(Intrinsic::arm_ldrexd); |
| 5033 | break; |
| 5034 | } |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5035 | |
| 5036 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5037 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 5038 | "ldrexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5039 | |
| 5040 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 5041 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 5042 | Val0 = Builder.CreateZExt(Val0, Int64Ty); |
| 5043 | Val1 = Builder.CreateZExt(Val1, Int64Ty); |
| 5044 | |
| 5045 | Value *ShiftCst = llvm::ConstantInt::get(Int64Ty, 32); |
| 5046 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5047 | Val = Builder.CreateOr(Val, Val1); |
| 5048 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5049 | } |
| 5050 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5051 | if (BuiltinID == ARM::BI__builtin_arm_ldrex || |
| 5052 | BuiltinID == ARM::BI__builtin_arm_ldaex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5053 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 5054 | |
| 5055 | QualType Ty = E->getType(); |
| 5056 | llvm::Type *RealResTy = ConvertType(Ty); |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5057 | llvm::Type *PtrTy = llvm::IntegerType::get( |
| 5058 | getLLVMContext(), getContext().getTypeSize(Ty))->getPointerTo(); |
| 5059 | LoadAddr = Builder.CreateBitCast(LoadAddr, PtrTy); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5060 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5061 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_ldaex |
| 5062 | ? Intrinsic::arm_ldaex |
| 5063 | : Intrinsic::arm_ldrex, |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5064 | PtrTy); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5065 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldrex"); |
| 5066 | |
| 5067 | if (RealResTy->isPointerTy()) |
| 5068 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 5069 | else { |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5070 | llvm::Type *IntResTy = llvm::IntegerType::get( |
| 5071 | getLLVMContext(), CGM.getDataLayout().getTypeSizeInBits(RealResTy)); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5072 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 5073 | return Builder.CreateBitCast(Val, RealResTy); |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | if (BuiltinID == ARM::BI__builtin_arm_strexd || |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5078 | ((BuiltinID == ARM::BI__builtin_arm_stlex || |
| 5079 | BuiltinID == ARM::BI__builtin_arm_strex) && |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5080 | getContext().getTypeSize(E->getArg(0)->getType()) == 64)) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5081 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 5082 | ? Intrinsic::arm_stlexd |
| 5083 | : Intrinsic::arm_strexd); |
Serge Guelton | 1d99327 | 2017-05-09 19:31:30 +0000 | [diff] [blame] | 5084 | llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5085 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5086 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5087 | Value *Val = EmitScalarExpr(E->getArg(0)); |
| 5088 | Builder.CreateStore(Val, Tmp); |
| 5089 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5090 | Address LdPtr = Builder.CreateBitCast(Tmp,llvm::PointerType::getUnqual(STy)); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5091 | Val = Builder.CreateLoad(LdPtr); |
| 5092 | |
| 5093 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 5094 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5095 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5096 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "strexd"); |
Bruno Cardoso Lopes | fe73374 | 2011-05-28 04:11:33 +0000 | [diff] [blame] | 5097 | } |
| 5098 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5099 | if (BuiltinID == ARM::BI__builtin_arm_strex || |
| 5100 | BuiltinID == ARM::BI__builtin_arm_stlex) { |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5101 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 5102 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 5103 | |
| 5104 | QualType Ty = E->getArg(0)->getType(); |
| 5105 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 5106 | getContext().getTypeSize(Ty)); |
| 5107 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 5108 | |
| 5109 | if (StoreVal->getType()->isPointerTy()) |
| 5110 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int32Ty); |
| 5111 | else { |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5112 | llvm::Type *IntTy = llvm::IntegerType::get( |
| 5113 | getLLVMContext(), |
| 5114 | CGM.getDataLayout().getTypeSizeInBits(StoreVal->getType())); |
| 5115 | StoreVal = Builder.CreateBitCast(StoreVal, IntTy); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5116 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int32Ty); |
| 5117 | } |
| 5118 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5119 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI__builtin_arm_stlex |
| 5120 | ? Intrinsic::arm_stlex |
| 5121 | : Intrinsic::arm_strex, |
| 5122 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5123 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "strex"); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5124 | } |
| 5125 | |
Martin Storsjo | ed95a08 | 2016-09-30 19:13:46 +0000 | [diff] [blame] | 5126 | switch (BuiltinID) { |
| 5127 | case ARM::BI__iso_volatile_load8: |
| 5128 | case ARM::BI__iso_volatile_load16: |
| 5129 | case ARM::BI__iso_volatile_load32: |
| 5130 | case ARM::BI__iso_volatile_load64: { |
| 5131 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 5132 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 5133 | CharUnits LoadSize = getContext().getTypeSizeInChars(ElTy); |
| 5134 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 5135 | LoadSize.getQuantity() * 8); |
| 5136 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
| 5137 | llvm::LoadInst *Load = |
| 5138 | Builder.CreateAlignedLoad(Ptr, LoadSize); |
| 5139 | Load->setVolatile(true); |
| 5140 | return Load; |
| 5141 | } |
| 5142 | case ARM::BI__iso_volatile_store8: |
| 5143 | case ARM::BI__iso_volatile_store16: |
| 5144 | case ARM::BI__iso_volatile_store32: |
| 5145 | case ARM::BI__iso_volatile_store64: { |
| 5146 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 5147 | Value *Value = EmitScalarExpr(E->getArg(1)); |
| 5148 | QualType ElTy = E->getArg(0)->getType()->getPointeeType(); |
| 5149 | CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); |
| 5150 | llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), |
| 5151 | StoreSize.getQuantity() * 8); |
| 5152 | Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); |
| 5153 | llvm::StoreInst *Store = |
| 5154 | Builder.CreateAlignedStore(Value, Ptr, |
| 5155 | StoreSize); |
| 5156 | Store->setVolatile(true); |
| 5157 | return Store; |
| 5158 | } |
| 5159 | } |
| 5160 | |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5161 | if (BuiltinID == ARM::BI__builtin_arm_clrex) { |
| 5162 | Function *F = CGM.getIntrinsic(Intrinsic::arm_clrex); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 5163 | return Builder.CreateCall(F); |
Tim Northover | 6aacd49 | 2013-07-16 09:47:53 +0000 | [diff] [blame] | 5164 | } |
| 5165 | |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 5166 | // CRC32 |
| 5167 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 5168 | switch (BuiltinID) { |
| 5169 | case ARM::BI__builtin_arm_crc32b: |
| 5170 | CRCIntrinsicID = Intrinsic::arm_crc32b; break; |
| 5171 | case ARM::BI__builtin_arm_crc32cb: |
| 5172 | CRCIntrinsicID = Intrinsic::arm_crc32cb; break; |
| 5173 | case ARM::BI__builtin_arm_crc32h: |
| 5174 | CRCIntrinsicID = Intrinsic::arm_crc32h; break; |
| 5175 | case ARM::BI__builtin_arm_crc32ch: |
| 5176 | CRCIntrinsicID = Intrinsic::arm_crc32ch; break; |
| 5177 | case ARM::BI__builtin_arm_crc32w: |
| 5178 | case ARM::BI__builtin_arm_crc32d: |
| 5179 | CRCIntrinsicID = Intrinsic::arm_crc32w; break; |
| 5180 | case ARM::BI__builtin_arm_crc32cw: |
| 5181 | case ARM::BI__builtin_arm_crc32cd: |
| 5182 | CRCIntrinsicID = Intrinsic::arm_crc32cw; break; |
| 5183 | } |
| 5184 | |
| 5185 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 5186 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 5187 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 5188 | |
| 5189 | // crc32{c,}d intrinsics are implemnted as two calls to crc32{c,}w |
| 5190 | // intrinsics, hence we need different codegen for these cases. |
| 5191 | if (BuiltinID == ARM::BI__builtin_arm_crc32d || |
| 5192 | BuiltinID == ARM::BI__builtin_arm_crc32cd) { |
| 5193 | Value *C1 = llvm::ConstantInt::get(Int64Ty, 32); |
| 5194 | Value *Arg1a = Builder.CreateTruncOrBitCast(Arg1, Int32Ty); |
| 5195 | Value *Arg1b = Builder.CreateLShr(Arg1, C1); |
| 5196 | Arg1b = Builder.CreateTruncOrBitCast(Arg1b, Int32Ty); |
| 5197 | |
| 5198 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5199 | Value *Res = Builder.CreateCall(F, {Arg0, Arg1a}); |
| 5200 | return Builder.CreateCall(F, {Res, Arg1b}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 5201 | } else { |
| 5202 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, Int32Ty); |
| 5203 | |
| 5204 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5205 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Joey Gouly | 1e8637b | 2013-09-18 10:07:09 +0000 | [diff] [blame] | 5206 | } |
| 5207 | } |
| 5208 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 5209 | if (BuiltinID == ARM::BI__builtin_arm_rsr || |
| 5210 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 5211 | BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 5212 | BuiltinID == ARM::BI__builtin_arm_wsr || |
| 5213 | BuiltinID == ARM::BI__builtin_arm_wsr64 || |
| 5214 | BuiltinID == ARM::BI__builtin_arm_wsrp) { |
| 5215 | |
| 5216 | bool IsRead = BuiltinID == ARM::BI__builtin_arm_rsr || |
| 5217 | BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 5218 | BuiltinID == ARM::BI__builtin_arm_rsrp; |
| 5219 | |
| 5220 | bool IsPointerBuiltin = BuiltinID == ARM::BI__builtin_arm_rsrp || |
| 5221 | BuiltinID == ARM::BI__builtin_arm_wsrp; |
| 5222 | |
| 5223 | bool Is64Bit = BuiltinID == ARM::BI__builtin_arm_rsr64 || |
| 5224 | BuiltinID == ARM::BI__builtin_arm_wsr64; |
| 5225 | |
| 5226 | llvm::Type *ValueType; |
| 5227 | llvm::Type *RegisterType; |
| 5228 | if (IsPointerBuiltin) { |
| 5229 | ValueType = VoidPtrTy; |
| 5230 | RegisterType = Int32Ty; |
| 5231 | } else if (Is64Bit) { |
| 5232 | ValueType = RegisterType = Int64Ty; |
| 5233 | } else { |
| 5234 | ValueType = RegisterType = Int32Ty; |
| 5235 | } |
| 5236 | |
| 5237 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 5238 | } |
| 5239 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 5240 | // Find out if any arguments are required to be integer constant |
| 5241 | // expressions. |
| 5242 | unsigned ICEArguments = 0; |
| 5243 | ASTContext::GetBuiltinTypeError Error; |
| 5244 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 5245 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 5246 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5247 | auto getAlignmentValue32 = [&](Address addr) -> Value* { |
| 5248 | return Builder.getInt32(addr.getAlignment().getQuantity()); |
| 5249 | }; |
| 5250 | |
| 5251 | Address PtrOp0 = Address::invalid(); |
| 5252 | Address PtrOp1 = Address::invalid(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5253 | SmallVector<Value*, 4> Ops; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 5254 | bool HasExtraArg = HasExtraNeonArgument(BuiltinID); |
| 5255 | unsigned NumArgs = E->getNumArgs() - (HasExtraArg ? 1 : 0); |
| 5256 | for (unsigned i = 0, e = NumArgs; i != e; i++) { |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 5257 | if (i == 0) { |
| 5258 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5259 | case NEON::BI__builtin_neon_vld1_v: |
| 5260 | case NEON::BI__builtin_neon_vld1q_v: |
| 5261 | case NEON::BI__builtin_neon_vld1q_lane_v: |
| 5262 | case NEON::BI__builtin_neon_vld1_lane_v: |
| 5263 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 5264 | case NEON::BI__builtin_neon_vld1q_dup_v: |
| 5265 | case NEON::BI__builtin_neon_vst1_v: |
| 5266 | case NEON::BI__builtin_neon_vst1q_v: |
| 5267 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 5268 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 5269 | case NEON::BI__builtin_neon_vst2_v: |
| 5270 | case NEON::BI__builtin_neon_vst2q_v: |
| 5271 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 5272 | case NEON::BI__builtin_neon_vst2q_lane_v: |
| 5273 | case NEON::BI__builtin_neon_vst3_v: |
| 5274 | case NEON::BI__builtin_neon_vst3q_v: |
| 5275 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 5276 | case NEON::BI__builtin_neon_vst3q_lane_v: |
| 5277 | case NEON::BI__builtin_neon_vst4_v: |
| 5278 | case NEON::BI__builtin_neon_vst4q_v: |
| 5279 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 5280 | case NEON::BI__builtin_neon_vst4q_lane_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 5281 | // Get the alignment for the argument in addition to the value; |
| 5282 | // we'll use it later. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5283 | PtrOp0 = EmitPointerWithAlignment(E->getArg(0)); |
| 5284 | Ops.push_back(PtrOp0.getPointer()); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 5285 | continue; |
| 5286 | } |
| 5287 | } |
| 5288 | if (i == 1) { |
| 5289 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5290 | case NEON::BI__builtin_neon_vld2_v: |
| 5291 | case NEON::BI__builtin_neon_vld2q_v: |
| 5292 | case NEON::BI__builtin_neon_vld3_v: |
| 5293 | case NEON::BI__builtin_neon_vld3q_v: |
| 5294 | case NEON::BI__builtin_neon_vld4_v: |
| 5295 | case NEON::BI__builtin_neon_vld4q_v: |
| 5296 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 5297 | case NEON::BI__builtin_neon_vld2q_lane_v: |
| 5298 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 5299 | case NEON::BI__builtin_neon_vld3q_lane_v: |
| 5300 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 5301 | case NEON::BI__builtin_neon_vld4q_lane_v: |
| 5302 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 5303 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 5304 | case NEON::BI__builtin_neon_vld4_dup_v: |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 5305 | // Get the alignment for the argument in addition to the value; |
| 5306 | // we'll use it later. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5307 | PtrOp1 = EmitPointerWithAlignment(E->getArg(1)); |
| 5308 | Ops.push_back(PtrOp1.getPointer()); |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 5309 | continue; |
| 5310 | } |
| 5311 | } |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 5312 | |
| 5313 | if ((ICEArguments & (1 << i)) == 0) { |
| 5314 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 5315 | } else { |
| 5316 | // If this is required to be a constant, constant fold it so that we know |
| 5317 | // that the generated intrinsic gets a ConstantInt. |
| 5318 | llvm::APSInt Result; |
| 5319 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 5320 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
| 5321 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 5322 | } |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 5323 | } |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5324 | |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 5325 | switch (BuiltinID) { |
| 5326 | default: break; |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 5327 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5328 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 5329 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 5330 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 5331 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 5332 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 5333 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 5334 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 5335 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 5336 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 5337 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 5338 | return Builder.CreateExtractElement(Ops[0], Ops[1], "vget_lane"); |
| 5339 | |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5340 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 5341 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 5342 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 5343 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 5344 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 5345 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 5346 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 5347 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 5348 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 5349 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 5350 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 5351 | |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 5352 | case NEON::BI__builtin_neon_vsha1h_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 5353 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1h), Ops, |
| 5354 | "vsha1h"); |
| 5355 | case NEON::BI__builtin_neon_vsha1cq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 5356 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1c), Ops, |
| 5357 | "vsha1h"); |
| 5358 | case NEON::BI__builtin_neon_vsha1pq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 5359 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1p), Ops, |
| 5360 | "vsha1h"); |
| 5361 | case NEON::BI__builtin_neon_vsha1mq_u32: |
Tim Northover | 02e3860 | 2014-02-03 17:28:04 +0000 | [diff] [blame] | 5362 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_sha1m), Ops, |
| 5363 | "vsha1h"); |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 5364 | |
| 5365 | // The ARM _MoveToCoprocessor builtins put the input register value as |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 5366 | // the first argument, but the LLVM intrinsic expects it as the third one. |
| 5367 | case ARM::BI_MoveToCoprocessor: |
| 5368 | case ARM::BI_MoveToCoprocessor2: { |
| 5369 | Function *F = CGM.getIntrinsic(BuiltinID == ARM::BI_MoveToCoprocessor ? |
| 5370 | Intrinsic::arm_mcr : Intrinsic::arm_mcr2); |
| 5371 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0], |
| 5372 | Ops[3], Ops[4], Ops[5]}); |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 5373 | } |
Albert Gutowski | 2a0621e | 2016-10-12 22:01:05 +0000 | [diff] [blame] | 5374 | case ARM::BI_BitScanForward: |
| 5375 | case ARM::BI_BitScanForward64: |
| 5376 | return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanForward, E); |
| 5377 | case ARM::BI_BitScanReverse: |
| 5378 | case ARM::BI_BitScanReverse64: |
| 5379 | return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanReverse, E); |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 5380 | |
| 5381 | case ARM::BI_InterlockedAnd64: |
| 5382 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedAnd, E); |
| 5383 | case ARM::BI_InterlockedExchange64: |
| 5384 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange, E); |
| 5385 | case ARM::BI_InterlockedExchangeAdd64: |
| 5386 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchangeAdd, E); |
| 5387 | case ARM::BI_InterlockedExchangeSub64: |
| 5388 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchangeSub, E); |
| 5389 | case ARM::BI_InterlockedOr64: |
| 5390 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedOr, E); |
| 5391 | case ARM::BI_InterlockedXor64: |
| 5392 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedXor, E); |
| 5393 | case ARM::BI_InterlockedDecrement64: |
| 5394 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedDecrement, E); |
| 5395 | case ARM::BI_InterlockedIncrement64: |
| 5396 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedIncrement, E); |
Bob Wilson | 445c24f | 2011-08-13 05:03:46 +0000 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | // Get the last argument, which specifies the vector type. |
Bob Wilson | 63c9314 | 2015-06-24 06:05:20 +0000 | [diff] [blame] | 5400 | assert(HasExtraArg); |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5401 | llvm::APSInt Result; |
| 5402 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 5403 | if (!Arg->isIntegerConstantExpr(Result, getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5404 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5405 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 5406 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f || |
| 5407 | BuiltinID == ARM::BI__builtin_arm_vcvtr_d) { |
| 5408 | // Determine the overloaded type of this builtin. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 5409 | llvm::Type *Ty; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 5410 | if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f) |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 5411 | Ty = FloatTy; |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 5412 | else |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 5413 | Ty = DoubleTy; |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5414 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 5415 | // Determine whether this is an unsigned conversion or not. |
| 5416 | bool usgn = Result.getZExtValue() == 1; |
| 5417 | unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr; |
| 5418 | |
| 5419 | // Call the appropriate intrinsic. |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5420 | Function *F = CGM.getIntrinsic(Int, Ty); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 5421 | return Builder.CreateCall(F, Ops, "vcvtr"); |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 5422 | } |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5423 | |
Nate Begeman | f568b07 | 2010-08-03 21:32:34 +0000 | [diff] [blame] | 5424 | // Determine the type of this overloaded NEON intrinsic. |
Bob Wilson | 98bc98c | 2011-11-08 01:16:11 +0000 | [diff] [blame] | 5425 | NeonTypeFlags Type(Result.getZExtValue()); |
| 5426 | bool usgn = Type.isUnsigned(); |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 5427 | bool rightShift = false; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5428 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 5429 | llvm::VectorType *VTy = GetNeonType(this, Type); |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 5430 | llvm::Type *Ty = VTy; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5431 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5432 | return nullptr; |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5433 | |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 5434 | // Many NEON builtins have identical semantics and uses in ARM and |
| 5435 | // AArch64. Emit these in a single function. |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 5436 | auto IntrinsicMap = makeArrayRef(ARMSIMDIntrinsicMap); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 5437 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
| 5438 | IntrinsicMap, BuiltinID, NEONSIMDIntrinsicsProvenSorted); |
| 5439 | if (Builtin) |
| 5440 | return EmitCommonNeonBuiltinExpr( |
| 5441 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5442 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, PtrOp0, PtrOp1); |
Tim Northover | ac85c34 | 2014-01-30 14:47:57 +0000 | [diff] [blame] | 5443 | |
Rafael Espindola | 6bb986d | 2010-06-09 03:48:40 +0000 | [diff] [blame] | 5444 | unsigned Int; |
| 5445 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5446 | default: return nullptr; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5447 | case NEON::BI__builtin_neon_vld1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5448 | // Handle 64-bit integer elements as a special case. Use shuffles of |
| 5449 | // one-element vectors to avoid poor code for i64 in the backend. |
| 5450 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 5451 | // Extract the other lane. |
| 5452 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5453 | uint32_t Lane = cast<ConstantInt>(Ops[2])->getZExtValue(); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5454 | Value *SV = llvm::ConstantVector::get(ConstantInt::get(Int32Ty, 1-Lane)); |
| 5455 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
| 5456 | // Load the value as a one-element vector. |
| 5457 | Ty = llvm::VectorType::get(VTy->getElementType(), 1); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 5458 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 5459 | Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5460 | Value *Align = getAlignmentValue32(PtrOp0); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5461 | Value *Ld = Builder.CreateCall(F, {Ops[0], Align}); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5462 | // Combine them. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5463 | uint32_t Indices[] = {1 - Lane, Lane}; |
| 5464 | SV = llvm::ConstantDataVector::get(getLLVMContext(), Indices); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5465 | return Builder.CreateShuffleVector(Ops[1], Ld, SV, "vld1q_lane"); |
| 5466 | } |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 5467 | LLVM_FALLTHROUGH; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5468 | case NEON::BI__builtin_neon_vld1_lane_v: { |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5469 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
Steven Wu | 0d22f2d | 2015-09-09 01:37:18 +0000 | [diff] [blame] | 5470 | PtrOp0 = Builder.CreateElementBitCast(PtrOp0, VTy->getElementType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5471 | Value *Ld = Builder.CreateLoad(PtrOp0); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 5472 | return Builder.CreateInsertElement(Ops[1], Ld, Ops[2], "vld1_lane"); |
| 5473 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5474 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 5475 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 5476 | case NEON::BI__builtin_neon_vld4_dup_v: { |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5477 | // Handle 64-bit elements as a special-case. There is no "dup" needed. |
| 5478 | if (VTy->getElementType()->getPrimitiveSizeInBits() == 64) { |
| 5479 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5480 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5481 | Int = Intrinsic::arm_neon_vld2; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5482 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5483 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5484 | Int = Intrinsic::arm_neon_vld3; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5485 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5486 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5487 | Int = Intrinsic::arm_neon_vld4; |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5488 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5489 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5490 | } |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 5491 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 5492 | Function *F = CGM.getIntrinsic(Int, Tys); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5493 | llvm::Value *Align = getAlignmentValue32(PtrOp1); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5494 | Ops[1] = Builder.CreateCall(F, {Ops[1], Align}, "vld_dup"); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5495 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5496 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5497 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Bob Wilson | 0348af6 | 2010-12-10 22:54:58 +0000 | [diff] [blame] | 5498 | } |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5499 | switch (BuiltinID) { |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5500 | case NEON::BI__builtin_neon_vld2_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5501 | Int = Intrinsic::arm_neon_vld2lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5502 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5503 | case NEON::BI__builtin_neon_vld3_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5504 | Int = Intrinsic::arm_neon_vld3lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5505 | break; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5506 | case NEON::BI__builtin_neon_vld4_dup_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5507 | Int = Intrinsic::arm_neon_vld4lane; |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5508 | break; |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5509 | default: llvm_unreachable("unknown vld_dup intrinsic?"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5510 | } |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 5511 | llvm::Type *Tys[] = {Ty, Int8PtrTy}; |
| 5512 | Function *F = CGM.getIntrinsic(Int, Tys); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 5513 | llvm::StructType *STy = cast<llvm::StructType>(F->getReturnType()); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5514 | |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5515 | SmallVector<Value*, 6> Args; |
| 5516 | Args.push_back(Ops[1]); |
| 5517 | Args.append(STy->getNumElements(), UndefValue::get(Ty)); |
| 5518 | |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 5519 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5520 | Args.push_back(CI); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5521 | Args.push_back(getAlignmentValue32(PtrOp1)); |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5522 | |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 5523 | Ops[1] = Builder.CreateCall(F, Args, "vld_dup"); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5524 | // splat lane 0 to all elts in each vector of the result. |
| 5525 | for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { |
| 5526 | Value *Val = Builder.CreateExtractValue(Ops[1], i); |
| 5527 | Value *Elt = Builder.CreateBitCast(Val, Ty); |
| 5528 | Elt = EmitNeonSplat(Elt, CI); |
| 5529 | Elt = Builder.CreateBitCast(Elt, Val->getType()); |
| 5530 | Ops[1] = Builder.CreateInsertValue(Ops[1], Elt, i); |
| 5531 | } |
| 5532 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 5533 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5534 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Nate Begeman | ed48c85 | 2010-06-20 23:05:28 +0000 | [diff] [blame] | 5535 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5536 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Jim Grosbach | d3608f4 | 2012-09-21 00:18:27 +0000 | [diff] [blame] | 5537 | Int = |
| 5538 | usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5539 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 5540 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5541 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5542 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 5543 | Ops, "vqrshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5544 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 5545 | Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns; |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5546 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n", |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 5547 | 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5548 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5549 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftnsu, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 5550 | Ops, "vqshrun_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5551 | case NEON::BI__builtin_neon_vrecpe_v: |
| 5552 | case NEON::BI__builtin_neon_vrecpeq_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5553 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecpe, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 5554 | Ops, "vrecpe"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5555 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5556 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrshiftn, Ty), |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 5557 | Ops, "vrshrn_n", 1, true); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5558 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 5559 | case NEON::BI__builtin_neon_vrsraq_n_v: |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 5560 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 5561 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5562 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, true); |
| 5563 | Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts; |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5564 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Ty), {Ops[1], Ops[2]}); |
Nate Begeman | c6ac0ce | 2010-06-12 06:06:07 +0000 | [diff] [blame] | 5565 | return Builder.CreateAdd(Ops[0], Ops[1], "vrsra_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5566 | case NEON::BI__builtin_neon_vsri_n_v: |
| 5567 | case NEON::BI__builtin_neon_vsriq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 5568 | rightShift = true; |
Galina Kistanova | 0872d6c | 2017-06-03 06:30:46 +0000 | [diff] [blame] | 5569 | LLVM_FALLTHROUGH; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5570 | case NEON::BI__builtin_neon_vsli_n_v: |
| 5571 | case NEON::BI__builtin_neon_vsliq_n_v: |
Bob Wilson | 4fa993f | 2010-12-03 17:10:22 +0000 | [diff] [blame] | 5572 | Ops[2] = EmitNeonShiftVector(Ops[2], Ty, rightShift); |
Benjamin Kramer | 8d375ce | 2011-07-14 17:45:50 +0000 | [diff] [blame] | 5573 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftins, Ty), |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 5574 | Ops, "vsli_n"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5575 | case NEON::BI__builtin_neon_vsra_n_v: |
| 5576 | case NEON::BI__builtin_neon_vsraq_n_v: |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 5577 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 5578 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 5579 | return Builder.CreateAdd(Ops[0], Ops[1]); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5580 | case NEON::BI__builtin_neon_vst1q_lane_v: |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5581 | // Handle 64-bit integer elements as a special case. Use a shuffle to get |
| 5582 | // a one-element vector and avoid poor code for i64 in the backend. |
| 5583 | if (VTy->getElementType()->isIntegerTy(64)) { |
| 5584 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5585 | Value *SV = llvm::ConstantVector::get(cast<llvm::Constant>(Ops[2])); |
| 5586 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5587 | Ops[2] = getAlignmentValue32(PtrOp0); |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 5588 | llvm::Type *Tys[] = {Int8PtrTy, Ops[1]->getType()}; |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5589 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst1, |
Jeroen Ketema | 55a8e80 | 2015-09-30 10:56:56 +0000 | [diff] [blame] | 5590 | Tys), Ops); |
Bob Wilson | 2605fef | 2012-08-14 17:27:04 +0000 | [diff] [blame] | 5591 | } |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 5592 | LLVM_FALLTHROUGH; |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5593 | case NEON::BI__builtin_neon_vst1_lane_v: { |
Nate Begeman | 8ed060b | 2010-06-11 22:57:12 +0000 | [diff] [blame] | 5594 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 5595 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 5596 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5597 | auto St = Builder.CreateStore(Ops[1], Builder.CreateBitCast(PtrOp0, Ty)); |
Bob Wilson | 49708d4 | 2012-02-04 23:58:08 +0000 | [diff] [blame] | 5598 | return St; |
| 5599 | } |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5600 | case NEON::BI__builtin_neon_vtbl1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5601 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1), |
| 5602 | Ops, "vtbl1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5603 | case NEON::BI__builtin_neon_vtbl2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5604 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl2), |
| 5605 | Ops, "vtbl2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5606 | case NEON::BI__builtin_neon_vtbl3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5607 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl3), |
| 5608 | Ops, "vtbl3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5609 | case NEON::BI__builtin_neon_vtbl4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5610 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl4), |
| 5611 | Ops, "vtbl4"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5612 | case NEON::BI__builtin_neon_vtbx1_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5613 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx1), |
| 5614 | Ops, "vtbx1"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5615 | case NEON::BI__builtin_neon_vtbx2_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5616 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx2), |
| 5617 | Ops, "vtbx2"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5618 | case NEON::BI__builtin_neon_vtbx3_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5619 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx3), |
| 5620 | Ops, "vtbx3"); |
Tim Northover | c322f83 | 2014-01-30 14:47:51 +0000 | [diff] [blame] | 5621 | case NEON::BI__builtin_neon_vtbx4_v: |
Nate Begeman | 5548309 | 2010-06-09 01:10:23 +0000 | [diff] [blame] | 5622 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx4), |
| 5623 | Ops, "vtbx4"); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 5624 | } |
| 5625 | } |
| 5626 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5627 | static Value *EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID, |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5628 | const CallExpr *E, |
| 5629 | SmallVectorImpl<Value *> &Ops) { |
| 5630 | unsigned int Int = 0; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5631 | const char *s = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5632 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5633 | switch (BuiltinID) { |
| 5634 | default: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5635 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5636 | case NEON::BI__builtin_neon_vtbl1_v: |
| 5637 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 5638 | case NEON::BI__builtin_neon_vqtbl1q_v: |
| 5639 | case NEON::BI__builtin_neon_vtbl2_v: |
| 5640 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 5641 | case NEON::BI__builtin_neon_vqtbl2q_v: |
| 5642 | case NEON::BI__builtin_neon_vtbl3_v: |
| 5643 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 5644 | case NEON::BI__builtin_neon_vqtbl3q_v: |
| 5645 | case NEON::BI__builtin_neon_vtbl4_v: |
| 5646 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 5647 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5648 | break; |
| 5649 | case NEON::BI__builtin_neon_vtbx1_v: |
| 5650 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 5651 | case NEON::BI__builtin_neon_vqtbx1q_v: |
| 5652 | case NEON::BI__builtin_neon_vtbx2_v: |
| 5653 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 5654 | case NEON::BI__builtin_neon_vqtbx2q_v: |
| 5655 | case NEON::BI__builtin_neon_vtbx3_v: |
| 5656 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 5657 | case NEON::BI__builtin_neon_vqtbx3q_v: |
| 5658 | case NEON::BI__builtin_neon_vtbx4_v: |
| 5659 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 5660 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5661 | break; |
| 5662 | } |
| 5663 | |
| 5664 | assert(E->getNumArgs() >= 3); |
| 5665 | |
| 5666 | // Get the last argument, which specifies the vector type. |
| 5667 | llvm::APSInt Result; |
| 5668 | const Expr *Arg = E->getArg(E->getNumArgs() - 1); |
| 5669 | if (!Arg->isIntegerConstantExpr(Result, CGF.getContext())) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5670 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5671 | |
| 5672 | // Determine the type of this overloaded NEON intrinsic. |
| 5673 | NeonTypeFlags Type(Result.getZExtValue()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5674 | llvm::VectorType *Ty = GetNeonType(&CGF, Type); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5675 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5676 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5677 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5678 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 5679 | |
| 5680 | // AArch64 scalar builtins are not overloaded, they do not have an extra |
| 5681 | // argument that specifies the vector type, need to handle each case. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5682 | switch (BuiltinID) { |
| 5683 | case NEON::BI__builtin_neon_vtbl1_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5684 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 1), nullptr, |
| 5685 | Ops[1], Ty, Intrinsic::aarch64_neon_tbl1, |
| 5686 | "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5687 | } |
| 5688 | case NEON::BI__builtin_neon_vtbl2_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5689 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 2), nullptr, |
| 5690 | Ops[2], Ty, Intrinsic::aarch64_neon_tbl1, |
| 5691 | "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5692 | } |
| 5693 | case NEON::BI__builtin_neon_vtbl3_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5694 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 3), nullptr, |
| 5695 | Ops[3], Ty, Intrinsic::aarch64_neon_tbl2, |
| 5696 | "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5697 | } |
| 5698 | case NEON::BI__builtin_neon_vtbl4_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5699 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(0, 4), nullptr, |
| 5700 | Ops[4], Ty, Intrinsic::aarch64_neon_tbl2, |
| 5701 | "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5702 | } |
| 5703 | case NEON::BI__builtin_neon_vtbx1_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5704 | Value *TblRes = |
| 5705 | packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 1), nullptr, Ops[2], |
| 5706 | Ty, Intrinsic::aarch64_neon_tbl1, "vtbl1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5707 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5708 | llvm::Constant *EightV = ConstantInt::get(Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5709 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[2], EightV); |
| 5710 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 5711 | |
| 5712 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 5713 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 5714 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 5715 | } |
| 5716 | case NEON::BI__builtin_neon_vtbx2_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5717 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 2), Ops[0], |
| 5718 | Ops[3], Ty, Intrinsic::aarch64_neon_tbx1, |
| 5719 | "vtbx1"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5720 | } |
| 5721 | case NEON::BI__builtin_neon_vtbx3_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5722 | Value *TblRes = |
| 5723 | packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 3), nullptr, Ops[4], |
| 5724 | Ty, Intrinsic::aarch64_neon_tbl2, "vtbl2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5725 | |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5726 | llvm::Constant *TwentyFourV = ConstantInt::get(Ty, 24); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5727 | Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[4], |
| 5728 | TwentyFourV); |
| 5729 | CmpRes = Builder.CreateSExt(CmpRes, Ty); |
| 5730 | |
| 5731 | Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]); |
| 5732 | Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes); |
| 5733 | return Builder.CreateOr(EltsFromInput, EltsFromTbl, "vtbx"); |
| 5734 | } |
| 5735 | case NEON::BI__builtin_neon_vtbx4_v: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5736 | return packTBLDVectorList(CGF, makeArrayRef(Ops).slice(1, 4), Ops[0], |
| 5737 | Ops[5], Ty, Intrinsic::aarch64_neon_tbx2, |
| 5738 | "vtbx2"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5739 | } |
| 5740 | case NEON::BI__builtin_neon_vqtbl1_v: |
| 5741 | case NEON::BI__builtin_neon_vqtbl1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5742 | Int = Intrinsic::aarch64_neon_tbl1; s = "vtbl1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5743 | case NEON::BI__builtin_neon_vqtbl2_v: |
| 5744 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5745 | Int = Intrinsic::aarch64_neon_tbl2; s = "vtbl2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5746 | case NEON::BI__builtin_neon_vqtbl3_v: |
| 5747 | case NEON::BI__builtin_neon_vqtbl3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5748 | Int = Intrinsic::aarch64_neon_tbl3; s = "vtbl3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5749 | case NEON::BI__builtin_neon_vqtbl4_v: |
| 5750 | case NEON::BI__builtin_neon_vqtbl4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5751 | Int = Intrinsic::aarch64_neon_tbl4; s = "vtbl4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5752 | case NEON::BI__builtin_neon_vqtbx1_v: |
| 5753 | case NEON::BI__builtin_neon_vqtbx1q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5754 | Int = Intrinsic::aarch64_neon_tbx1; s = "vtbx1"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5755 | case NEON::BI__builtin_neon_vqtbx2_v: |
| 5756 | case NEON::BI__builtin_neon_vqtbx2q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5757 | Int = Intrinsic::aarch64_neon_tbx2; s = "vtbx2"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5758 | case NEON::BI__builtin_neon_vqtbx3_v: |
| 5759 | case NEON::BI__builtin_neon_vqtbx3q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5760 | Int = Intrinsic::aarch64_neon_tbx3; s = "vtbx3"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5761 | case NEON::BI__builtin_neon_vqtbx4_v: |
| 5762 | case NEON::BI__builtin_neon_vqtbx4q_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5763 | Int = Intrinsic::aarch64_neon_tbx4; s = "vtbx4"; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5764 | } |
| 5765 | } |
| 5766 | |
| 5767 | if (!Int) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 5768 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5769 | |
| 5770 | Function *F = CGF.CGM.getIntrinsic(Int, Ty); |
| 5771 | return CGF.EmitNeonCall(F, Ops, s); |
| 5772 | } |
| 5773 | |
| 5774 | Value *CodeGenFunction::vectorWrapScalar16(Value *Op) { |
| 5775 | llvm::Type *VTy = llvm::VectorType::get(Int16Ty, 4); |
| 5776 | Op = Builder.CreateBitCast(Op, Int16Ty); |
| 5777 | Value *V = UndefValue::get(VTy); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 5778 | llvm::Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5779 | Op = Builder.CreateInsertElement(V, Op, CI); |
| 5780 | return Op; |
| 5781 | } |
| 5782 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5783 | Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, |
| 5784 | const CallExpr *E) { |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 5785 | unsigned HintID = static_cast<unsigned>(-1); |
| 5786 | switch (BuiltinID) { |
| 5787 | default: break; |
Yi Kong | 4d5e23f | 2014-07-14 15:20:09 +0000 | [diff] [blame] | 5788 | case AArch64::BI__builtin_arm_nop: |
| 5789 | HintID = 0; |
| 5790 | break; |
Saleem Abdulrasool | 572250d | 2014-07-12 23:27:22 +0000 | [diff] [blame] | 5791 | case AArch64::BI__builtin_arm_yield: |
| 5792 | HintID = 1; |
| 5793 | break; |
| 5794 | case AArch64::BI__builtin_arm_wfe: |
| 5795 | HintID = 2; |
| 5796 | break; |
| 5797 | case AArch64::BI__builtin_arm_wfi: |
| 5798 | HintID = 3; |
| 5799 | break; |
| 5800 | case AArch64::BI__builtin_arm_sev: |
| 5801 | HintID = 4; |
| 5802 | break; |
| 5803 | case AArch64::BI__builtin_arm_sevl: |
| 5804 | HintID = 5; |
| 5805 | break; |
| 5806 | } |
| 5807 | |
| 5808 | if (HintID != static_cast<unsigned>(-1)) { |
| 5809 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hint); |
| 5810 | return Builder.CreateCall(F, llvm::ConstantInt::get(Int32Ty, HintID)); |
| 5811 | } |
| 5812 | |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 5813 | if (BuiltinID == AArch64::BI__builtin_arm_prefetch) { |
| 5814 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 5815 | Value *RW = EmitScalarExpr(E->getArg(1)); |
| 5816 | Value *CacheLevel = EmitScalarExpr(E->getArg(2)); |
| 5817 | Value *RetentionPolicy = EmitScalarExpr(E->getArg(3)); |
| 5818 | Value *IsData = EmitScalarExpr(E->getArg(4)); |
| 5819 | |
| 5820 | Value *Locality = nullptr; |
| 5821 | if (cast<llvm::ConstantInt>(RetentionPolicy)->isZero()) { |
| 5822 | // Temporal fetch, needs to convert cache level to locality. |
| 5823 | Locality = llvm::ConstantInt::get(Int32Ty, |
| 5824 | -cast<llvm::ConstantInt>(CacheLevel)->getValue() + 3); |
| 5825 | } else { |
| 5826 | // Streaming fetch. |
| 5827 | Locality = llvm::ConstantInt::get(Int32Ty, 0); |
| 5828 | } |
| 5829 | |
| 5830 | // FIXME: We need AArch64 specific LLVM intrinsic if we want to specify |
| 5831 | // PLDL3STRM or PLDL2STRM. |
| 5832 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5833 | return Builder.CreateCall(F, {Address, RW, Locality, IsData}); |
Yi Kong | a554843 | 2014-08-13 19:18:20 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
Jim Grosbach | 7914082 | 2014-06-16 21:56:02 +0000 | [diff] [blame] | 5836 | if (BuiltinID == AArch64::BI__builtin_arm_rbit) { |
| 5837 | assert((getContext().getTypeSize(E->getType()) == 32) && |
| 5838 | "rbit of unusual size!"); |
| 5839 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 5840 | return Builder.CreateCall( |
Chad Rosier | 5a4a1be | 2017-01-10 17:20:28 +0000 | [diff] [blame] | 5841 | CGM.getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg, "rbit"); |
Jim Grosbach | 7914082 | 2014-06-16 21:56:02 +0000 | [diff] [blame] | 5842 | } |
| 5843 | if (BuiltinID == AArch64::BI__builtin_arm_rbit64) { |
| 5844 | assert((getContext().getTypeSize(E->getType()) == 64) && |
| 5845 | "rbit of unusual size!"); |
| 5846 | llvm::Value *Arg = EmitScalarExpr(E->getArg(0)); |
| 5847 | return Builder.CreateCall( |
Chad Rosier | 5a4a1be | 2017-01-10 17:20:28 +0000 | [diff] [blame] | 5848 | CGM.getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg, "rbit"); |
Jim Grosbach | 7914082 | 2014-06-16 21:56:02 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5851 | if (BuiltinID == AArch64::BI__clear_cache) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5852 | assert(E->getNumArgs() == 2 && "__clear_cache takes 2 arguments"); |
| 5853 | const FunctionDecl *FD = E->getDirectCallee(); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5854 | Value *Ops[2]; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5855 | for (unsigned i = 0; i < 2; i++) |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 5856 | Ops[i] = EmitScalarExpr(E->getArg(i)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5857 | llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); |
| 5858 | llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty); |
| 5859 | StringRef Name = FD->getName(); |
| 5860 | return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); |
| 5861 | } |
| 5862 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5863 | if ((BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 5864 | BuiltinID == AArch64::BI__builtin_arm_ldaex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5865 | getContext().getTypeSize(E->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5866 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 5867 | ? Intrinsic::aarch64_ldaxp |
| 5868 | : Intrinsic::aarch64_ldxp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5869 | |
| 5870 | Value *LdPtr = EmitScalarExpr(E->getArg(0)); |
| 5871 | Value *Val = Builder.CreateCall(F, Builder.CreateBitCast(LdPtr, Int8PtrTy), |
| 5872 | "ldxp"); |
| 5873 | |
| 5874 | Value *Val0 = Builder.CreateExtractValue(Val, 1); |
| 5875 | Value *Val1 = Builder.CreateExtractValue(Val, 0); |
| 5876 | llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128); |
| 5877 | Val0 = Builder.CreateZExt(Val0, Int128Ty); |
| 5878 | Val1 = Builder.CreateZExt(Val1, Int128Ty); |
| 5879 | |
| 5880 | Value *ShiftCst = llvm::ConstantInt::get(Int128Ty, 64); |
| 5881 | Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */); |
| 5882 | Val = Builder.CreateOr(Val, Val1); |
| 5883 | return Builder.CreateBitCast(Val, ConvertType(E->getType())); |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5884 | } else if (BuiltinID == AArch64::BI__builtin_arm_ldrex || |
| 5885 | BuiltinID == AArch64::BI__builtin_arm_ldaex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5886 | Value *LoadAddr = EmitScalarExpr(E->getArg(0)); |
| 5887 | |
| 5888 | QualType Ty = E->getType(); |
| 5889 | llvm::Type *RealResTy = ConvertType(Ty); |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5890 | llvm::Type *PtrTy = llvm::IntegerType::get( |
| 5891 | getLLVMContext(), getContext().getTypeSize(Ty))->getPointerTo(); |
| 5892 | LoadAddr = Builder.CreateBitCast(LoadAddr, PtrTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5893 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5894 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_ldaex |
| 5895 | ? Intrinsic::aarch64_ldaxr |
| 5896 | : Intrinsic::aarch64_ldxr, |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5897 | PtrTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5898 | Value *Val = Builder.CreateCall(F, LoadAddr, "ldxr"); |
| 5899 | |
| 5900 | if (RealResTy->isPointerTy()) |
| 5901 | return Builder.CreateIntToPtr(Val, RealResTy); |
| 5902 | |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5903 | llvm::Type *IntResTy = llvm::IntegerType::get( |
| 5904 | getLLVMContext(), CGM.getDataLayout().getTypeSizeInBits(RealResTy)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5905 | Val = Builder.CreateTruncOrBitCast(Val, IntResTy); |
| 5906 | return Builder.CreateBitCast(Val, RealResTy); |
| 5907 | } |
| 5908 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5909 | if ((BuiltinID == AArch64::BI__builtin_arm_strex || |
| 5910 | BuiltinID == AArch64::BI__builtin_arm_stlex) && |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5911 | getContext().getTypeSize(E->getArg(0)->getType()) == 128) { |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5912 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 5913 | ? Intrinsic::aarch64_stlxp |
| 5914 | : Intrinsic::aarch64_stxp); |
Serge Guelton | 1d99327 | 2017-05-09 19:31:30 +0000 | [diff] [blame] | 5915 | llvm::Type *STy = llvm::StructType::get(Int64Ty, Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5916 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5917 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
| 5918 | EmitAnyExprToMem(E->getArg(0), Tmp, Qualifiers(), /*init*/ true); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5919 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 5920 | Tmp = Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(STy)); |
| 5921 | llvm::Value *Val = Builder.CreateLoad(Tmp); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5922 | |
| 5923 | Value *Arg0 = Builder.CreateExtractValue(Val, 0); |
| 5924 | Value *Arg1 = Builder.CreateExtractValue(Val, 1); |
| 5925 | Value *StPtr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), |
| 5926 | Int8PtrTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5927 | return Builder.CreateCall(F, {Arg0, Arg1, StPtr}, "stxp"); |
| 5928 | } |
| 5929 | |
| 5930 | if (BuiltinID == AArch64::BI__builtin_arm_strex || |
| 5931 | BuiltinID == AArch64::BI__builtin_arm_stlex) { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5932 | Value *StoreVal = EmitScalarExpr(E->getArg(0)); |
| 5933 | Value *StoreAddr = EmitScalarExpr(E->getArg(1)); |
| 5934 | |
| 5935 | QualType Ty = E->getArg(0)->getType(); |
| 5936 | llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), |
| 5937 | getContext().getTypeSize(Ty)); |
| 5938 | StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); |
| 5939 | |
| 5940 | if (StoreVal->getType()->isPointerTy()) |
| 5941 | StoreVal = Builder.CreatePtrToInt(StoreVal, Int64Ty); |
| 5942 | else { |
Akira Hatanaka | 6c299ca | 2016-12-01 19:25:14 +0000 | [diff] [blame] | 5943 | llvm::Type *IntTy = llvm::IntegerType::get( |
| 5944 | getLLVMContext(), |
| 5945 | CGM.getDataLayout().getTypeSizeInBits(StoreVal->getType())); |
| 5946 | StoreVal = Builder.CreateBitCast(StoreVal, IntTy); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5947 | StoreVal = Builder.CreateZExtOrBitCast(StoreVal, Int64Ty); |
| 5948 | } |
| 5949 | |
Tim Northover | 3acd6bd | 2014-07-02 12:56:02 +0000 | [diff] [blame] | 5950 | Function *F = CGM.getIntrinsic(BuiltinID == AArch64::BI__builtin_arm_stlex |
| 5951 | ? Intrinsic::aarch64_stlxr |
| 5952 | : Intrinsic::aarch64_stxr, |
| 5953 | StoreAddr->getType()); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5954 | return Builder.CreateCall(F, {StoreVal, StoreAddr}, "stxr"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5955 | } |
| 5956 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5957 | if (BuiltinID == AArch64::BI__builtin_arm_clrex) { |
| 5958 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_clrex); |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 5959 | return Builder.CreateCall(F); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | // CRC32 |
| 5963 | Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic; |
| 5964 | switch (BuiltinID) { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 5965 | case AArch64::BI__builtin_arm_crc32b: |
| 5966 | CRCIntrinsicID = Intrinsic::aarch64_crc32b; break; |
| 5967 | case AArch64::BI__builtin_arm_crc32cb: |
| 5968 | CRCIntrinsicID = Intrinsic::aarch64_crc32cb; break; |
| 5969 | case AArch64::BI__builtin_arm_crc32h: |
| 5970 | CRCIntrinsicID = Intrinsic::aarch64_crc32h; break; |
| 5971 | case AArch64::BI__builtin_arm_crc32ch: |
| 5972 | CRCIntrinsicID = Intrinsic::aarch64_crc32ch; break; |
| 5973 | case AArch64::BI__builtin_arm_crc32w: |
| 5974 | CRCIntrinsicID = Intrinsic::aarch64_crc32w; break; |
| 5975 | case AArch64::BI__builtin_arm_crc32cw: |
| 5976 | CRCIntrinsicID = Intrinsic::aarch64_crc32cw; break; |
| 5977 | case AArch64::BI__builtin_arm_crc32d: |
| 5978 | CRCIntrinsicID = Intrinsic::aarch64_crc32x; break; |
| 5979 | case AArch64::BI__builtin_arm_crc32cd: |
| 5980 | CRCIntrinsicID = Intrinsic::aarch64_crc32cx; break; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | if (CRCIntrinsicID != Intrinsic::not_intrinsic) { |
| 5984 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 5985 | Value *Arg1 = EmitScalarExpr(E->getArg(1)); |
| 5986 | Function *F = CGM.getIntrinsic(CRCIntrinsicID); |
| 5987 | |
| 5988 | llvm::Type *DataTy = F->getFunctionType()->getParamType(1); |
| 5989 | Arg1 = Builder.CreateZExtOrBitCast(Arg1, DataTy); |
| 5990 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 5991 | return Builder.CreateCall(F, {Arg0, Arg1}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 5992 | } |
| 5993 | |
Luke Cheeseman | 59b2d83 | 2015-06-15 17:51:01 +0000 | [diff] [blame] | 5994 | if (BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 5995 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 5996 | BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 5997 | BuiltinID == AArch64::BI__builtin_arm_wsr || |
| 5998 | BuiltinID == AArch64::BI__builtin_arm_wsr64 || |
| 5999 | BuiltinID == AArch64::BI__builtin_arm_wsrp) { |
| 6000 | |
| 6001 | bool IsRead = BuiltinID == AArch64::BI__builtin_arm_rsr || |
| 6002 | BuiltinID == AArch64::BI__builtin_arm_rsr64 || |
| 6003 | BuiltinID == AArch64::BI__builtin_arm_rsrp; |
| 6004 | |
| 6005 | bool IsPointerBuiltin = BuiltinID == AArch64::BI__builtin_arm_rsrp || |
| 6006 | BuiltinID == AArch64::BI__builtin_arm_wsrp; |
| 6007 | |
| 6008 | bool Is64Bit = BuiltinID != AArch64::BI__builtin_arm_rsr && |
| 6009 | BuiltinID != AArch64::BI__builtin_arm_wsr; |
| 6010 | |
| 6011 | llvm::Type *ValueType; |
| 6012 | llvm::Type *RegisterType = Int64Ty; |
| 6013 | if (IsPointerBuiltin) { |
| 6014 | ValueType = VoidPtrTy; |
| 6015 | } else if (Is64Bit) { |
| 6016 | ValueType = Int64Ty; |
| 6017 | } else { |
| 6018 | ValueType = Int32Ty; |
| 6019 | } |
| 6020 | |
| 6021 | return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, IsRead); |
| 6022 | } |
| 6023 | |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 6024 | // Find out if any arguments are required to be integer constant |
| 6025 | // expressions. |
| 6026 | unsigned ICEArguments = 0; |
| 6027 | ASTContext::GetBuiltinTypeError Error; |
| 6028 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 6029 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 6030 | |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6031 | llvm::SmallVector<Value*, 4> Ops; |
Ahmed Bougacha | 94df730 | 2015-06-04 01:43:41 +0000 | [diff] [blame] | 6032 | for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++) { |
| 6033 | if ((ICEArguments & (1 << i)) == 0) { |
| 6034 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 6035 | } else { |
| 6036 | // If this is required to be a constant, constant fold it so that we know |
| 6037 | // that the generated intrinsic gets a ConstantInt. |
| 6038 | llvm::APSInt Result; |
| 6039 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 6040 | assert(IsConst && "Constant arg isn't actually constant?"); |
| 6041 | (void)IsConst; |
| 6042 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
| 6043 | } |
| 6044 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6045 | |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 6046 | auto SISDMap = makeArrayRef(AArch64SISDIntrinsicMap); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6047 | const NeonIntrinsicInfo *Builtin = findNeonIntrinsicInMap( |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6048 | SISDMap, BuiltinID, AArch64SISDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6049 | |
| 6050 | if (Builtin) { |
| 6051 | Ops.push_back(EmitScalarExpr(E->getArg(E->getNumArgs() - 1))); |
| 6052 | Value *Result = EmitCommonNeonSISDBuiltinExpr(*this, *Builtin, Ops, E); |
| 6053 | assert(Result && "SISD intrinsic should have been handled"); |
| 6054 | return Result; |
| 6055 | } |
| 6056 | |
| 6057 | llvm::APSInt Result; |
| 6058 | const Expr *Arg = E->getArg(E->getNumArgs()-1); |
| 6059 | NeonTypeFlags Type(0); |
| 6060 | if (Arg->isIntegerConstantExpr(Result, getContext())) |
| 6061 | // Determine the type of this overloaded NEON intrinsic. |
| 6062 | Type = NeonTypeFlags(Result.getZExtValue()); |
| 6063 | |
| 6064 | bool usgn = Type.isUnsigned(); |
| 6065 | bool quad = Type.isQuad(); |
| 6066 | |
| 6067 | // Handle non-overloaded intrinsics first. |
| 6068 | switch (BuiltinID) { |
| 6069 | default: break; |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 6070 | case NEON::BI__builtin_neon_vldrq_p128: { |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 6071 | llvm::Type *Int128Ty = llvm::Type::getIntNTy(getLLVMContext(), 128); |
| 6072 | llvm::Type *Int128PTy = llvm::PointerType::get(Int128Ty, 0); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 6073 | Value *Ptr = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int128PTy); |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 6074 | return Builder.CreateAlignedLoad(Int128Ty, Ptr, |
| 6075 | CharUnits::fromQuantity(16)); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 6076 | } |
| 6077 | case NEON::BI__builtin_neon_vstrq_p128: { |
| 6078 | llvm::Type *Int128PTy = llvm::Type::getIntNPtrTy(getLLVMContext(), 128); |
| 6079 | Value *Ptr = Builder.CreateBitCast(Ops[0], Int128PTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6080 | return Builder.CreateDefaultAlignedStore(EmitScalarExpr(E->getArg(1)), Ptr); |
Tim Northover | b17f9a4 | 2014-04-01 12:23:08 +0000 | [diff] [blame] | 6081 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6082 | case NEON::BI__builtin_neon_vcvts_u32_f32: |
| 6083 | case NEON::BI__builtin_neon_vcvtd_u64_f64: |
| 6084 | usgn = true; |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 6085 | LLVM_FALLTHROUGH; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6086 | case NEON::BI__builtin_neon_vcvts_s32_f32: |
| 6087 | case NEON::BI__builtin_neon_vcvtd_s64_f64: { |
| 6088 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6089 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 6090 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 6091 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 6092 | Ops[0] = Builder.CreateBitCast(Ops[0], FTy); |
| 6093 | if (usgn) |
| 6094 | return Builder.CreateFPToUI(Ops[0], InTy); |
| 6095 | return Builder.CreateFPToSI(Ops[0], InTy); |
| 6096 | } |
| 6097 | case NEON::BI__builtin_neon_vcvts_f32_u32: |
| 6098 | case NEON::BI__builtin_neon_vcvtd_f64_u64: |
| 6099 | usgn = true; |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 6100 | LLVM_FALLTHROUGH; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6101 | case NEON::BI__builtin_neon_vcvts_f32_s32: |
| 6102 | case NEON::BI__builtin_neon_vcvtd_f64_s64: { |
| 6103 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6104 | bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64; |
| 6105 | llvm::Type *InTy = Is64 ? Int64Ty : Int32Ty; |
| 6106 | llvm::Type *FTy = Is64 ? DoubleTy : FloatTy; |
| 6107 | Ops[0] = Builder.CreateBitCast(Ops[0], InTy); |
| 6108 | if (usgn) |
| 6109 | return Builder.CreateUIToFP(Ops[0], FTy); |
| 6110 | return Builder.CreateSIToFP(Ops[0], FTy); |
| 6111 | } |
| 6112 | case NEON::BI__builtin_neon_vpaddd_s64: { |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6113 | llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6114 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 6115 | // The vector is v2f64, so make sure it's bitcast to that. |
| 6116 | Vec = Builder.CreateBitCast(Vec, Ty, "v2i64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6117 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 6118 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6119 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 6120 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 6121 | // Pairwise addition of a v2f64 into a scalar f64. |
| 6122 | return Builder.CreateAdd(Op0, Op1, "vpaddd"); |
| 6123 | } |
| 6124 | case NEON::BI__builtin_neon_vpaddd_f64: { |
| 6125 | llvm::Type *Ty = |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6126 | llvm::VectorType::get(DoubleTy, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6127 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 6128 | // The vector is v2f64, so make sure it's bitcast to that. |
| 6129 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f64"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6130 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 6131 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6132 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 6133 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 6134 | // Pairwise addition of a v2f64 into a scalar f64. |
| 6135 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 6136 | } |
| 6137 | case NEON::BI__builtin_neon_vpadds_f32: { |
| 6138 | llvm::Type *Ty = |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6139 | llvm::VectorType::get(FloatTy, 2); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6140 | Value *Vec = EmitScalarExpr(E->getArg(0)); |
| 6141 | // The vector is v2f32, so make sure it's bitcast to that. |
| 6142 | Vec = Builder.CreateBitCast(Vec, Ty, "v2f32"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6143 | llvm::Value *Idx0 = llvm::ConstantInt::get(SizeTy, 0); |
| 6144 | llvm::Value *Idx1 = llvm::ConstantInt::get(SizeTy, 1); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6145 | Value *Op0 = Builder.CreateExtractElement(Vec, Idx0, "lane0"); |
| 6146 | Value *Op1 = Builder.CreateExtractElement(Vec, Idx1, "lane1"); |
| 6147 | // Pairwise addition of a v2f32 into a scalar f32. |
| 6148 | return Builder.CreateFAdd(Op0, Op1, "vpaddd"); |
| 6149 | } |
| 6150 | case NEON::BI__builtin_neon_vceqzd_s64: |
| 6151 | case NEON::BI__builtin_neon_vceqzd_f64: |
| 6152 | case NEON::BI__builtin_neon_vceqzs_f32: |
| 6153 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6154 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 6155 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 6156 | ICmpInst::FCMP_OEQ, ICmpInst::ICMP_EQ, "vceqz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6157 | case NEON::BI__builtin_neon_vcgezd_s64: |
| 6158 | case NEON::BI__builtin_neon_vcgezd_f64: |
| 6159 | case NEON::BI__builtin_neon_vcgezs_f32: |
| 6160 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6161 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 6162 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 6163 | ICmpInst::FCMP_OGE, ICmpInst::ICMP_SGE, "vcgez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6164 | case NEON::BI__builtin_neon_vclezd_s64: |
| 6165 | case NEON::BI__builtin_neon_vclezd_f64: |
| 6166 | case NEON::BI__builtin_neon_vclezs_f32: |
| 6167 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6168 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 6169 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 6170 | ICmpInst::FCMP_OLE, ICmpInst::ICMP_SLE, "vclez"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6171 | case NEON::BI__builtin_neon_vcgtzd_s64: |
| 6172 | case NEON::BI__builtin_neon_vcgtzd_f64: |
| 6173 | case NEON::BI__builtin_neon_vcgtzs_f32: |
| 6174 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6175 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 6176 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 6177 | ICmpInst::FCMP_OGT, ICmpInst::ICMP_SGT, "vcgtz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6178 | case NEON::BI__builtin_neon_vcltzd_s64: |
| 6179 | case NEON::BI__builtin_neon_vcltzd_f64: |
| 6180 | case NEON::BI__builtin_neon_vcltzs_f32: |
| 6181 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6182 | return EmitAArch64CompareBuiltinExpr( |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 6183 | Ops[0], ConvertType(E->getCallReturnType(getContext())), |
| 6184 | ICmpInst::FCMP_OLT, ICmpInst::ICMP_SLT, "vcltz"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6185 | |
| 6186 | case NEON::BI__builtin_neon_vceqzd_u64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6187 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6188 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 6189 | Ops[0] = |
| 6190 | Builder.CreateICmpEQ(Ops[0], llvm::Constant::getNullValue(Int64Ty)); |
| 6191 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqzd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6192 | } |
| 6193 | case NEON::BI__builtin_neon_vceqd_f64: |
| 6194 | case NEON::BI__builtin_neon_vcled_f64: |
| 6195 | case NEON::BI__builtin_neon_vcltd_f64: |
| 6196 | case NEON::BI__builtin_neon_vcged_f64: |
| 6197 | case NEON::BI__builtin_neon_vcgtd_f64: { |
| 6198 | llvm::CmpInst::Predicate P; |
| 6199 | switch (BuiltinID) { |
| 6200 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 6201 | case NEON::BI__builtin_neon_vceqd_f64: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 6202 | case NEON::BI__builtin_neon_vcled_f64: P = llvm::FCmpInst::FCMP_OLE; break; |
| 6203 | case NEON::BI__builtin_neon_vcltd_f64: P = llvm::FCmpInst::FCMP_OLT; break; |
| 6204 | case NEON::BI__builtin_neon_vcged_f64: P = llvm::FCmpInst::FCMP_OGE; break; |
| 6205 | case NEON::BI__builtin_neon_vcgtd_f64: P = llvm::FCmpInst::FCMP_OGT; break; |
| 6206 | } |
| 6207 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 6208 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 6209 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 6210 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 6211 | return Builder.CreateSExt(Ops[0], Int64Ty, "vcmpd"); |
| 6212 | } |
| 6213 | case NEON::BI__builtin_neon_vceqs_f32: |
| 6214 | case NEON::BI__builtin_neon_vcles_f32: |
| 6215 | case NEON::BI__builtin_neon_vclts_f32: |
| 6216 | case NEON::BI__builtin_neon_vcges_f32: |
| 6217 | case NEON::BI__builtin_neon_vcgts_f32: { |
| 6218 | llvm::CmpInst::Predicate P; |
| 6219 | switch (BuiltinID) { |
| 6220 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 6221 | case NEON::BI__builtin_neon_vceqs_f32: P = llvm::FCmpInst::FCMP_OEQ; break; |
| 6222 | case NEON::BI__builtin_neon_vcles_f32: P = llvm::FCmpInst::FCMP_OLE; break; |
| 6223 | case NEON::BI__builtin_neon_vclts_f32: P = llvm::FCmpInst::FCMP_OLT; break; |
| 6224 | case NEON::BI__builtin_neon_vcges_f32: P = llvm::FCmpInst::FCMP_OGE; break; |
| 6225 | case NEON::BI__builtin_neon_vcgts_f32: P = llvm::FCmpInst::FCMP_OGT; break; |
| 6226 | } |
| 6227 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 6228 | Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy); |
| 6229 | Ops[1] = Builder.CreateBitCast(Ops[1], FloatTy); |
| 6230 | Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]); |
| 6231 | return Builder.CreateSExt(Ops[0], Int32Ty, "vcmpd"); |
| 6232 | } |
| 6233 | case NEON::BI__builtin_neon_vceqd_s64: |
| 6234 | case NEON::BI__builtin_neon_vceqd_u64: |
| 6235 | case NEON::BI__builtin_neon_vcgtd_s64: |
| 6236 | case NEON::BI__builtin_neon_vcgtd_u64: |
| 6237 | case NEON::BI__builtin_neon_vcltd_s64: |
| 6238 | case NEON::BI__builtin_neon_vcltd_u64: |
| 6239 | case NEON::BI__builtin_neon_vcged_u64: |
| 6240 | case NEON::BI__builtin_neon_vcged_s64: |
| 6241 | case NEON::BI__builtin_neon_vcled_u64: |
| 6242 | case NEON::BI__builtin_neon_vcled_s64: { |
| 6243 | llvm::CmpInst::Predicate P; |
| 6244 | switch (BuiltinID) { |
| 6245 | default: llvm_unreachable("missing builtin ID in switch!"); |
| 6246 | case NEON::BI__builtin_neon_vceqd_s64: |
| 6247 | case NEON::BI__builtin_neon_vceqd_u64:P = llvm::ICmpInst::ICMP_EQ;break; |
| 6248 | case NEON::BI__builtin_neon_vcgtd_s64:P = llvm::ICmpInst::ICMP_SGT;break; |
| 6249 | case NEON::BI__builtin_neon_vcgtd_u64:P = llvm::ICmpInst::ICMP_UGT;break; |
| 6250 | case NEON::BI__builtin_neon_vcltd_s64:P = llvm::ICmpInst::ICMP_SLT;break; |
| 6251 | case NEON::BI__builtin_neon_vcltd_u64:P = llvm::ICmpInst::ICMP_ULT;break; |
| 6252 | case NEON::BI__builtin_neon_vcged_u64:P = llvm::ICmpInst::ICMP_UGE;break; |
| 6253 | case NEON::BI__builtin_neon_vcged_s64:P = llvm::ICmpInst::ICMP_SGE;break; |
| 6254 | case NEON::BI__builtin_neon_vcled_u64:P = llvm::ICmpInst::ICMP_ULE;break; |
| 6255 | case NEON::BI__builtin_neon_vcled_s64:P = llvm::ICmpInst::ICMP_SLE;break; |
| 6256 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6257 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 6258 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 6259 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6260 | Ops[0] = Builder.CreateICmp(P, Ops[0], Ops[1]); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 6261 | return Builder.CreateSExt(Ops[0], Int64Ty, "vceqd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6262 | } |
| 6263 | case NEON::BI__builtin_neon_vtstd_s64: |
| 6264 | case NEON::BI__builtin_neon_vtstd_u64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6265 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6266 | Ops[0] = Builder.CreateBitCast(Ops[0], Int64Ty); |
| 6267 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6268 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]); |
| 6269 | Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0], |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6270 | llvm::Constant::getNullValue(Int64Ty)); |
| 6271 | return Builder.CreateSExt(Ops[0], Int64Ty, "vtstd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6272 | } |
| 6273 | case NEON::BI__builtin_neon_vset_lane_i8: |
| 6274 | case NEON::BI__builtin_neon_vset_lane_i16: |
| 6275 | case NEON::BI__builtin_neon_vset_lane_i32: |
| 6276 | case NEON::BI__builtin_neon_vset_lane_i64: |
| 6277 | case NEON::BI__builtin_neon_vset_lane_f32: |
| 6278 | case NEON::BI__builtin_neon_vsetq_lane_i8: |
| 6279 | case NEON::BI__builtin_neon_vsetq_lane_i16: |
| 6280 | case NEON::BI__builtin_neon_vsetq_lane_i32: |
| 6281 | case NEON::BI__builtin_neon_vsetq_lane_i64: |
| 6282 | case NEON::BI__builtin_neon_vsetq_lane_f32: |
| 6283 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 6284 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 6285 | case NEON::BI__builtin_neon_vset_lane_f64: |
| 6286 | // The vector type needs a cast for the v1f64 variant. |
| 6287 | Ops[1] = Builder.CreateBitCast(Ops[1], |
| 6288 | llvm::VectorType::get(DoubleTy, 1)); |
| 6289 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 6290 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 6291 | case NEON::BI__builtin_neon_vsetq_lane_f64: |
| 6292 | // The vector type needs a cast for the v2f64 variant. |
| 6293 | Ops[1] = Builder.CreateBitCast(Ops[1], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6294 | llvm::VectorType::get(DoubleTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6295 | Ops.push_back(EmitScalarExpr(E->getArg(2))); |
| 6296 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane"); |
| 6297 | |
| 6298 | case NEON::BI__builtin_neon_vget_lane_i8: |
| 6299 | case NEON::BI__builtin_neon_vdupb_lane_i8: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6300 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int8Ty, 8)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6301 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6302 | "vget_lane"); |
| 6303 | case NEON::BI__builtin_neon_vgetq_lane_i8: |
| 6304 | case NEON::BI__builtin_neon_vdupb_laneq_i8: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6305 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int8Ty, 16)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6306 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6307 | "vgetq_lane"); |
| 6308 | case NEON::BI__builtin_neon_vget_lane_i16: |
| 6309 | case NEON::BI__builtin_neon_vduph_lane_i16: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6310 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int16Ty, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6311 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6312 | "vget_lane"); |
| 6313 | case NEON::BI__builtin_neon_vgetq_lane_i16: |
| 6314 | case NEON::BI__builtin_neon_vduph_laneq_i16: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6315 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int16Ty, 8)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6316 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6317 | "vgetq_lane"); |
| 6318 | case NEON::BI__builtin_neon_vget_lane_i32: |
| 6319 | case NEON::BI__builtin_neon_vdups_lane_i32: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6320 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6321 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6322 | "vget_lane"); |
| 6323 | case NEON::BI__builtin_neon_vdups_lane_f32: |
| 6324 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6325 | llvm::VectorType::get(FloatTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6326 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6327 | "vdups_lane"); |
| 6328 | case NEON::BI__builtin_neon_vgetq_lane_i32: |
| 6329 | case NEON::BI__builtin_neon_vdups_laneq_i32: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6330 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6331 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6332 | "vgetq_lane"); |
| 6333 | case NEON::BI__builtin_neon_vget_lane_i64: |
| 6334 | case NEON::BI__builtin_neon_vdupd_lane_i64: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6335 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6336 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6337 | "vget_lane"); |
| 6338 | case NEON::BI__builtin_neon_vdupd_lane_f64: |
| 6339 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6340 | llvm::VectorType::get(DoubleTy, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6341 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6342 | "vdupd_lane"); |
| 6343 | case NEON::BI__builtin_neon_vgetq_lane_i64: |
| 6344 | case NEON::BI__builtin_neon_vdupd_laneq_i64: |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6345 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6346 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6347 | "vgetq_lane"); |
| 6348 | case NEON::BI__builtin_neon_vget_lane_f32: |
| 6349 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6350 | llvm::VectorType::get(FloatTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6351 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6352 | "vget_lane"); |
| 6353 | case NEON::BI__builtin_neon_vget_lane_f64: |
| 6354 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6355 | llvm::VectorType::get(DoubleTy, 1)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6356 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6357 | "vget_lane"); |
| 6358 | case NEON::BI__builtin_neon_vgetq_lane_f32: |
| 6359 | case NEON::BI__builtin_neon_vdups_laneq_f32: |
| 6360 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6361 | llvm::VectorType::get(FloatTy, 4)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6362 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6363 | "vgetq_lane"); |
| 6364 | case NEON::BI__builtin_neon_vgetq_lane_f64: |
| 6365 | case NEON::BI__builtin_neon_vdupd_laneq_f64: |
| 6366 | Ops[0] = Builder.CreateBitCast(Ops[0], |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6367 | llvm::VectorType::get(DoubleTy, 2)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6368 | return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)), |
| 6369 | "vgetq_lane"); |
| 6370 | case NEON::BI__builtin_neon_vaddd_s64: |
| 6371 | case NEON::BI__builtin_neon_vaddd_u64: |
| 6372 | return Builder.CreateAdd(Ops[0], EmitScalarExpr(E->getArg(1)), "vaddd"); |
| 6373 | case NEON::BI__builtin_neon_vsubd_s64: |
| 6374 | case NEON::BI__builtin_neon_vsubd_u64: |
| 6375 | return Builder.CreateSub(Ops[0], EmitScalarExpr(E->getArg(1)), "vsubd"); |
| 6376 | case NEON::BI__builtin_neon_vqdmlalh_s16: |
| 6377 | case NEON::BI__builtin_neon_vqdmlslh_s16: { |
| 6378 | SmallVector<Value *, 2> ProductOps; |
| 6379 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 6380 | ProductOps.push_back(vectorWrapScalar16(EmitScalarExpr(E->getArg(2)))); |
| 6381 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6382 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6383 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6384 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6385 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 6386 | |
| 6387 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlalh_s16 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6388 | ? Intrinsic::aarch64_neon_sqadd |
| 6389 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6390 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int32Ty), Ops, "vqdmlXl"); |
| 6391 | } |
| 6392 | case NEON::BI__builtin_neon_vqshlud_n_s64: { |
| 6393 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 6394 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6395 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqshlu, Int64Ty), |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 6396 | Ops, "vqshlu_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6397 | } |
| 6398 | case NEON::BI__builtin_neon_vqshld_n_u64: |
| 6399 | case NEON::BI__builtin_neon_vqshld_n_s64: { |
| 6400 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vqshld_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6401 | ? Intrinsic::aarch64_neon_uqshl |
| 6402 | : Intrinsic::aarch64_neon_sqshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6403 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
| 6404 | Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 6405 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vqshl_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6406 | } |
| 6407 | case NEON::BI__builtin_neon_vrshrd_n_u64: |
| 6408 | case NEON::BI__builtin_neon_vrshrd_n_s64: { |
| 6409 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6410 | ? Intrinsic::aarch64_neon_urshl |
| 6411 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6412 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Hao Liu | a19a2e2 | 2014-04-28 07:36:12 +0000 | [diff] [blame] | 6413 | int SV = cast<ConstantInt>(Ops[1])->getSExtValue(); |
| 6414 | Ops[1] = ConstantInt::get(Int64Ty, -SV); |
| 6415 | return EmitNeonCall(CGM.getIntrinsic(Int, Int64Ty), Ops, "vrshr_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6416 | } |
| 6417 | case NEON::BI__builtin_neon_vrsrad_n_u64: |
| 6418 | case NEON::BI__builtin_neon_vrsrad_n_s64: { |
| 6419 | unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrsrad_n_u64 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6420 | ? Intrinsic::aarch64_neon_urshl |
| 6421 | : Intrinsic::aarch64_neon_srshl; |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 6422 | Ops[1] = Builder.CreateBitCast(Ops[1], Int64Ty); |
| 6423 | Ops.push_back(Builder.CreateNeg(EmitScalarExpr(E->getArg(2)))); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6424 | Ops[1] = Builder.CreateCall(CGM.getIntrinsic(Int, Int64Ty), |
| 6425 | {Ops[1], Builder.CreateSExt(Ops[2], Int64Ty)}); |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 6426 | return Builder.CreateAdd(Ops[0], Builder.CreateBitCast(Ops[1], Int64Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6427 | } |
| 6428 | case NEON::BI__builtin_neon_vshld_n_s64: |
| 6429 | case NEON::BI__builtin_neon_vshld_n_u64: { |
| 6430 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 6431 | return Builder.CreateShl( |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 6432 | Ops[0], ConstantInt::get(Int64Ty, Amt->getZExtValue()), "shld_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6433 | } |
| 6434 | case NEON::BI__builtin_neon_vshrd_n_s64: { |
| 6435 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
| 6436 | return Builder.CreateAShr( |
| 6437 | Ops[0], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 6438 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 6439 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6440 | } |
| 6441 | case NEON::BI__builtin_neon_vshrd_n_u64: { |
| 6442 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(1))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 6443 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 6444 | // Right-shifting an unsigned value by its size yields 0. |
| 6445 | if (ShiftAmt == 64) |
| 6446 | return ConstantInt::get(Int64Ty, 0); |
| 6447 | return Builder.CreateLShr(Ops[0], ConstantInt::get(Int64Ty, ShiftAmt), |
| 6448 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6449 | } |
| 6450 | case NEON::BI__builtin_neon_vsrad_n_s64: { |
| 6451 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
| 6452 | Ops[1] = Builder.CreateAShr( |
| 6453 | Ops[1], ConstantInt::get(Int64Ty, std::min(static_cast<uint64_t>(63), |
| 6454 | Amt->getZExtValue())), |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 6455 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6456 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 6457 | } |
| 6458 | case NEON::BI__builtin_neon_vsrad_n_u64: { |
| 6459 | llvm::ConstantInt *Amt = cast<ConstantInt>(EmitScalarExpr(E->getArg(2))); |
Hao Liu | 9f9492b | 2014-05-14 08:59:30 +0000 | [diff] [blame] | 6460 | uint64_t ShiftAmt = Amt->getZExtValue(); |
| 6461 | // Right-shifting an unsigned value by its size yields 0. |
| 6462 | // As Op + 0 = Op, return Ops[0] directly. |
| 6463 | if (ShiftAmt == 64) |
| 6464 | return Ops[0]; |
| 6465 | Ops[1] = Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, ShiftAmt), |
| 6466 | "shrd_n"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6467 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 6468 | } |
| 6469 | case NEON::BI__builtin_neon_vqdmlalh_lane_s16: |
| 6470 | case NEON::BI__builtin_neon_vqdmlalh_laneq_s16: |
| 6471 | case NEON::BI__builtin_neon_vqdmlslh_lane_s16: |
| 6472 | case NEON::BI__builtin_neon_vqdmlslh_laneq_s16: { |
| 6473 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 6474 | "lane"); |
| 6475 | SmallVector<Value *, 2> ProductOps; |
| 6476 | ProductOps.push_back(vectorWrapScalar16(Ops[1])); |
| 6477 | ProductOps.push_back(vectorWrapScalar16(Ops[2])); |
| 6478 | llvm::Type *VTy = llvm::VectorType::get(Int32Ty, 4); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6479 | Ops[1] = EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmull, VTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6480 | ProductOps, "vqdmlXl"); |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 6481 | Constant *CI = ConstantInt::get(SizeTy, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6482 | Ops[1] = Builder.CreateExtractElement(Ops[1], CI, "lane0"); |
| 6483 | Ops.pop_back(); |
| 6484 | |
| 6485 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlalh_lane_s16 || |
| 6486 | BuiltinID == NEON::BI__builtin_neon_vqdmlalh_laneq_s16) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6487 | ? Intrinsic::aarch64_neon_sqadd |
| 6488 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6489 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int32Ty), Ops, "vqdmlXl"); |
| 6490 | } |
| 6491 | case NEON::BI__builtin_neon_vqdmlals_s32: |
| 6492 | case NEON::BI__builtin_neon_vqdmlsls_s32: { |
| 6493 | SmallVector<Value *, 2> ProductOps; |
| 6494 | ProductOps.push_back(Ops[1]); |
| 6495 | ProductOps.push_back(EmitScalarExpr(E->getArg(2))); |
| 6496 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6497 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6498 | ProductOps, "vqdmlXl"); |
| 6499 | |
| 6500 | unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlals_s32 |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6501 | ? Intrinsic::aarch64_neon_sqadd |
| 6502 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6503 | return EmitNeonCall(CGM.getIntrinsic(AccumInt, Int64Ty), Ops, "vqdmlXl"); |
| 6504 | } |
| 6505 | case NEON::BI__builtin_neon_vqdmlals_lane_s32: |
| 6506 | case NEON::BI__builtin_neon_vqdmlals_laneq_s32: |
| 6507 | case NEON::BI__builtin_neon_vqdmlsls_lane_s32: |
| 6508 | case NEON::BI__builtin_neon_vqdmlsls_laneq_s32: { |
| 6509 | Ops[2] = Builder.CreateExtractElement(Ops[2], EmitScalarExpr(E->getArg(3)), |
| 6510 | "lane"); |
| 6511 | SmallVector<Value *, 2> ProductOps; |
| 6512 | ProductOps.push_back(Ops[1]); |
| 6513 | ProductOps.push_back(Ops[2]); |
| 6514 | Ops[1] = |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6515 | EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_sqdmulls_scalar), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6516 | ProductOps, "vqdmlXl"); |
| 6517 | Ops.pop_back(); |
| 6518 | |
| 6519 | unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlals_lane_s32 || |
| 6520 | BuiltinID == NEON::BI__builtin_neon_vqdmlals_laneq_s32) |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6521 | ? Intrinsic::aarch64_neon_sqadd |
| 6522 | : Intrinsic::aarch64_neon_sqsub; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6523 | return EmitNeonCall(CGM.getIntrinsic(AccInt, Int64Ty), Ops, "vqdmlXl"); |
| 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | llvm::VectorType *VTy = GetNeonType(this, Type); |
| 6528 | llvm::Type *Ty = VTy; |
| 6529 | if (!Ty) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6530 | return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6531 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6532 | // 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] | 6533 | // 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] | 6534 | Builtin = findNeonIntrinsicInMap(AArch64SIMDIntrinsicMap, BuiltinID, |
| 6535 | AArch64SIMDIntrinsicsProvenSorted); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6536 | |
| 6537 | if (Builtin) |
| 6538 | return EmitCommonNeonBuiltinExpr( |
| 6539 | Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 6540 | Builtin->NameHint, Builtin->TypeModifier, E, Ops, |
| 6541 | /*never use addresses*/ Address::invalid(), Address::invalid()); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6542 | |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6543 | if (Value *V = EmitAArch64TblBuiltinExpr(*this, BuiltinID, E, Ops)) |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6544 | return V; |
| 6545 | |
| 6546 | unsigned Int; |
| 6547 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 6548 | default: return nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6549 | case NEON::BI__builtin_neon_vbsl_v: |
| 6550 | case NEON::BI__builtin_neon_vbslq_v: { |
| 6551 | llvm::Type *BitTy = llvm::VectorType::getInteger(VTy); |
| 6552 | Ops[0] = Builder.CreateBitCast(Ops[0], BitTy, "vbsl"); |
| 6553 | Ops[1] = Builder.CreateBitCast(Ops[1], BitTy, "vbsl"); |
| 6554 | Ops[2] = Builder.CreateBitCast(Ops[2], BitTy, "vbsl"); |
| 6555 | |
| 6556 | Ops[1] = Builder.CreateAnd(Ops[0], Ops[1], "vbsl"); |
| 6557 | Ops[2] = Builder.CreateAnd(Builder.CreateNot(Ops[0]), Ops[2], "vbsl"); |
| 6558 | Ops[0] = Builder.CreateOr(Ops[1], Ops[2], "vbsl"); |
| 6559 | return Builder.CreateBitCast(Ops[0], Ty); |
| 6560 | } |
| 6561 | case NEON::BI__builtin_neon_vfma_lane_v: |
| 6562 | case NEON::BI__builtin_neon_vfmaq_lane_v: { // Only used for FP types |
| 6563 | // The ARM builtins (and instructions) have the addend as the first |
| 6564 | // operand, but the 'fma' intrinsics have it last. Swap it around here. |
| 6565 | Value *Addend = Ops[0]; |
| 6566 | Value *Multiplicand = Ops[1]; |
| 6567 | Value *LaneSource = Ops[2]; |
| 6568 | Ops[0] = Multiplicand; |
| 6569 | Ops[1] = LaneSource; |
| 6570 | Ops[2] = Addend; |
| 6571 | |
| 6572 | // Now adjust things to handle the lane access. |
| 6573 | llvm::Type *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v ? |
| 6574 | llvm::VectorType::get(VTy->getElementType(), VTy->getNumElements() / 2) : |
| 6575 | VTy; |
| 6576 | llvm::Constant *cst = cast<Constant>(Ops[3]); |
| 6577 | Value *SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), cst); |
| 6578 | Ops[1] = Builder.CreateBitCast(Ops[1], SourceTy); |
| 6579 | Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV, "lane"); |
| 6580 | |
| 6581 | Ops.pop_back(); |
| 6582 | Int = Intrinsic::fma; |
| 6583 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmla"); |
| 6584 | } |
| 6585 | case NEON::BI__builtin_neon_vfma_laneq_v: { |
| 6586 | llvm::VectorType *VTy = cast<llvm::VectorType>(Ty); |
| 6587 | // v1f64 fma should be mapped to Neon scalar f64 fma |
| 6588 | if (VTy && VTy->getElementType() == DoubleTy) { |
| 6589 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 6590 | Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy); |
| 6591 | llvm::Type *VTy = GetNeonType(this, |
| 6592 | NeonTypeFlags(NeonTypeFlags::Float64, false, true)); |
| 6593 | Ops[2] = Builder.CreateBitCast(Ops[2], VTy); |
| 6594 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
| 6595 | Value *F = CGM.getIntrinsic(Intrinsic::fma, DoubleTy); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6596 | Value *Result = Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6597 | return Builder.CreateBitCast(Result, Ty); |
| 6598 | } |
| 6599 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 6600 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 6601 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6602 | |
| 6603 | llvm::Type *STy = llvm::VectorType::get(VTy->getElementType(), |
| 6604 | VTy->getNumElements() * 2); |
| 6605 | Ops[2] = Builder.CreateBitCast(Ops[2], STy); |
| 6606 | Value* SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), |
| 6607 | cast<ConstantInt>(Ops[3])); |
| 6608 | Ops[2] = Builder.CreateShuffleVector(Ops[2], Ops[2], SV, "lane"); |
| 6609 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6610 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6611 | } |
| 6612 | case NEON::BI__builtin_neon_vfmaq_laneq_v: { |
| 6613 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 6614 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 6615 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 6616 | |
| 6617 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 6618 | Ops[2] = EmitNeonSplat(Ops[2], cast<ConstantInt>(Ops[3])); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6619 | return Builder.CreateCall(F, {Ops[2], Ops[1], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6620 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6621 | case NEON::BI__builtin_neon_vfmah_lane_f16: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6622 | case NEON::BI__builtin_neon_vfmas_lane_f32: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6623 | case NEON::BI__builtin_neon_vfmah_laneq_f16: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6624 | case NEON::BI__builtin_neon_vfmas_laneq_f32: |
| 6625 | case NEON::BI__builtin_neon_vfmad_lane_f64: |
| 6626 | case NEON::BI__builtin_neon_vfmad_laneq_f64: { |
| 6627 | Ops.push_back(EmitScalarExpr(E->getArg(3))); |
David Majnemer | ced8bdf | 2015-02-25 17:36:15 +0000 | [diff] [blame] | 6628 | llvm::Type *Ty = ConvertType(E->getCallReturnType(getContext())); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6629 | Value *F = CGM.getIntrinsic(Intrinsic::fma, Ty); |
| 6630 | Ops[2] = Builder.CreateExtractElement(Ops[2], Ops[3], "extract"); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 6631 | return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0]}); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6632 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6633 | case NEON::BI__builtin_neon_vmull_v: |
| 6634 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6635 | Int = usgn ? Intrinsic::aarch64_neon_umull : Intrinsic::aarch64_neon_smull; |
| 6636 | if (Type.isPoly()) Int = Intrinsic::aarch64_neon_pmull; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6637 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull"); |
| 6638 | case NEON::BI__builtin_neon_vmax_v: |
| 6639 | case NEON::BI__builtin_neon_vmaxq_v: |
| 6640 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6641 | Int = usgn ? Intrinsic::aarch64_neon_umax : Intrinsic::aarch64_neon_smax; |
| 6642 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmax; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6643 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmax"); |
| 6644 | case NEON::BI__builtin_neon_vmin_v: |
| 6645 | case NEON::BI__builtin_neon_vminq_v: |
| 6646 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6647 | Int = usgn ? Intrinsic::aarch64_neon_umin : Intrinsic::aarch64_neon_smin; |
| 6648 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmin; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6649 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmin"); |
| 6650 | case NEON::BI__builtin_neon_vabd_v: |
| 6651 | case NEON::BI__builtin_neon_vabdq_v: |
| 6652 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6653 | Int = usgn ? Intrinsic::aarch64_neon_uabd : Intrinsic::aarch64_neon_sabd; |
| 6654 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fabd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6655 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vabd"); |
| 6656 | case NEON::BI__builtin_neon_vpadal_v: |
| 6657 | case NEON::BI__builtin_neon_vpadalq_v: { |
| 6658 | unsigned ArgElts = VTy->getNumElements(); |
| 6659 | llvm::IntegerType *EltTy = cast<IntegerType>(VTy->getElementType()); |
| 6660 | unsigned BitWidth = EltTy->getBitWidth(); |
| 6661 | llvm::Type *ArgTy = llvm::VectorType::get( |
| 6662 | llvm::IntegerType::get(getLLVMContext(), BitWidth/2), 2*ArgElts); |
| 6663 | llvm::Type* Tys[2] = { VTy, ArgTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6664 | Int = usgn ? Intrinsic::aarch64_neon_uaddlp : Intrinsic::aarch64_neon_saddlp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6665 | SmallVector<llvm::Value*, 1> TmpOps; |
| 6666 | TmpOps.push_back(Ops[1]); |
| 6667 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 6668 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vpadal"); |
| 6669 | llvm::Value *addend = Builder.CreateBitCast(Ops[0], tmp->getType()); |
| 6670 | return Builder.CreateAdd(tmp, addend); |
| 6671 | } |
| 6672 | case NEON::BI__builtin_neon_vpmin_v: |
| 6673 | case NEON::BI__builtin_neon_vpminq_v: |
| 6674 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6675 | Int = usgn ? Intrinsic::aarch64_neon_uminp : Intrinsic::aarch64_neon_sminp; |
| 6676 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fminp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6677 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmin"); |
| 6678 | case NEON::BI__builtin_neon_vpmax_v: |
| 6679 | case NEON::BI__builtin_neon_vpmaxq_v: |
| 6680 | // FIXME: improve sharing scheme to cope with 3 alternative LLVM intrinsics. |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6681 | Int = usgn ? Intrinsic::aarch64_neon_umaxp : Intrinsic::aarch64_neon_smaxp; |
| 6682 | if (Ty->isFPOrFPVectorTy()) Int = Intrinsic::aarch64_neon_fmaxp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6683 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmax"); |
| 6684 | case NEON::BI__builtin_neon_vminnm_v: |
| 6685 | case NEON::BI__builtin_neon_vminnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6686 | Int = Intrinsic::aarch64_neon_fminnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6687 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vminnm"); |
| 6688 | case NEON::BI__builtin_neon_vmaxnm_v: |
| 6689 | case NEON::BI__builtin_neon_vmaxnmq_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6690 | Int = Intrinsic::aarch64_neon_fmaxnm; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6691 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmaxnm"); |
| 6692 | case NEON::BI__builtin_neon_vrecpss_f32: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6693 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6694 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, FloatTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6695 | Ops, "vrecps"); |
| 6696 | } |
| 6697 | case NEON::BI__builtin_neon_vrecpsd_f64: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6698 | Ops.push_back(EmitScalarExpr(E->getArg(1))); |
Ahmed Bougacha | 40882bb | 2015-08-24 23:47:29 +0000 | [diff] [blame] | 6699 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_frecps, DoubleTy), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6700 | Ops, "vrecps"); |
| 6701 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6702 | case NEON::BI__builtin_neon_vqshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6703 | Int = Intrinsic::aarch64_neon_sqshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6704 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrun_n"); |
| 6705 | case NEON::BI__builtin_neon_vqrshrun_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6706 | Int = Intrinsic::aarch64_neon_sqrshrun; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6707 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrun_n"); |
| 6708 | case NEON::BI__builtin_neon_vqshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6709 | Int = usgn ? Intrinsic::aarch64_neon_uqshrn : Intrinsic::aarch64_neon_sqshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6710 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n"); |
| 6711 | case NEON::BI__builtin_neon_vrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6712 | Int = Intrinsic::aarch64_neon_rshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6713 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshrn_n"); |
| 6714 | case NEON::BI__builtin_neon_vqrshrn_n_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6715 | Int = usgn ? Intrinsic::aarch64_neon_uqrshrn : Intrinsic::aarch64_neon_sqrshrn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6716 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n"); |
| 6717 | case NEON::BI__builtin_neon_vrnda_v: |
| 6718 | case NEON::BI__builtin_neon_vrndaq_v: { |
| 6719 | Int = Intrinsic::round; |
| 6720 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrnda"); |
| 6721 | } |
| 6722 | case NEON::BI__builtin_neon_vrndi_v: |
| 6723 | case NEON::BI__builtin_neon_vrndiq_v: { |
| 6724 | Int = Intrinsic::nearbyint; |
| 6725 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndi"); |
| 6726 | } |
| 6727 | case NEON::BI__builtin_neon_vrndm_v: |
| 6728 | case NEON::BI__builtin_neon_vrndmq_v: { |
| 6729 | Int = Intrinsic::floor; |
| 6730 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndm"); |
| 6731 | } |
| 6732 | case NEON::BI__builtin_neon_vrndn_v: |
| 6733 | case NEON::BI__builtin_neon_vrndnq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6734 | Int = Intrinsic::aarch64_neon_frintn; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6735 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndn"); |
| 6736 | } |
| 6737 | case NEON::BI__builtin_neon_vrndp_v: |
| 6738 | case NEON::BI__builtin_neon_vrndpq_v: { |
| 6739 | Int = Intrinsic::ceil; |
| 6740 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndp"); |
| 6741 | } |
| 6742 | case NEON::BI__builtin_neon_vrndx_v: |
| 6743 | case NEON::BI__builtin_neon_vrndxq_v: { |
| 6744 | Int = Intrinsic::rint; |
| 6745 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndx"); |
| 6746 | } |
| 6747 | case NEON::BI__builtin_neon_vrnd_v: |
| 6748 | case NEON::BI__builtin_neon_vrndq_v: { |
| 6749 | Int = Intrinsic::trunc; |
| 6750 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrndz"); |
| 6751 | } |
| 6752 | case NEON::BI__builtin_neon_vceqz_v: |
| 6753 | case NEON::BI__builtin_neon_vceqzq_v: |
| 6754 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OEQ, |
| 6755 | ICmpInst::ICMP_EQ, "vceqz"); |
| 6756 | case NEON::BI__builtin_neon_vcgez_v: |
| 6757 | case NEON::BI__builtin_neon_vcgezq_v: |
| 6758 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGE, |
| 6759 | ICmpInst::ICMP_SGE, "vcgez"); |
| 6760 | case NEON::BI__builtin_neon_vclez_v: |
| 6761 | case NEON::BI__builtin_neon_vclezq_v: |
| 6762 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLE, |
| 6763 | ICmpInst::ICMP_SLE, "vclez"); |
| 6764 | case NEON::BI__builtin_neon_vcgtz_v: |
| 6765 | case NEON::BI__builtin_neon_vcgtzq_v: |
| 6766 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OGT, |
| 6767 | ICmpInst::ICMP_SGT, "vcgtz"); |
| 6768 | case NEON::BI__builtin_neon_vcltz_v: |
| 6769 | case NEON::BI__builtin_neon_vcltzq_v: |
| 6770 | return EmitAArch64CompareBuiltinExpr(Ops[0], Ty, ICmpInst::FCMP_OLT, |
| 6771 | ICmpInst::ICMP_SLT, "vcltz"); |
| 6772 | case NEON::BI__builtin_neon_vcvt_f64_v: |
| 6773 | case NEON::BI__builtin_neon_vcvtq_f64_v: |
| 6774 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 6775 | Ty = GetNeonType(this, NeonTypeFlags(NeonTypeFlags::Float64, false, quad)); |
| 6776 | return usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt") |
| 6777 | : Builder.CreateSIToFP(Ops[0], Ty, "vcvt"); |
| 6778 | case NEON::BI__builtin_neon_vcvt_f64_f32: { |
| 6779 | assert(Type.getEltType() == NeonTypeFlags::Float64 && quad && |
| 6780 | "unexpected vcvt_f64_f32 builtin"); |
| 6781 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float32, false, false); |
| 6782 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 6783 | |
| 6784 | return Builder.CreateFPExt(Ops[0], Ty, "vcvt"); |
| 6785 | } |
| 6786 | case NEON::BI__builtin_neon_vcvt_f32_f64: { |
| 6787 | assert(Type.getEltType() == NeonTypeFlags::Float32 && |
| 6788 | "unexpected vcvt_f32_f64 builtin"); |
| 6789 | NeonTypeFlags SrcFlag = NeonTypeFlags(NeonTypeFlags::Float64, false, true); |
| 6790 | Ops[0] = Builder.CreateBitCast(Ops[0], GetNeonType(this, SrcFlag)); |
| 6791 | |
| 6792 | return Builder.CreateFPTrunc(Ops[0], Ty, "vcvt"); |
| 6793 | } |
| 6794 | case NEON::BI__builtin_neon_vcvt_s32_v: |
| 6795 | case NEON::BI__builtin_neon_vcvt_u32_v: |
| 6796 | case NEON::BI__builtin_neon_vcvt_s64_v: |
| 6797 | case NEON::BI__builtin_neon_vcvt_u64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6798 | case NEON::BI__builtin_neon_vcvt_s16_v: |
| 6799 | case NEON::BI__builtin_neon_vcvt_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6800 | case NEON::BI__builtin_neon_vcvtq_s32_v: |
| 6801 | case NEON::BI__builtin_neon_vcvtq_u32_v: |
| 6802 | case NEON::BI__builtin_neon_vcvtq_s64_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6803 | case NEON::BI__builtin_neon_vcvtq_u64_v: |
| 6804 | case NEON::BI__builtin_neon_vcvtq_s16_v: |
| 6805 | case NEON::BI__builtin_neon_vcvtq_u16_v: { |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 6806 | Ops[0] = Builder.CreateBitCast(Ops[0], GetFloatNeonType(this, Type)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6807 | if (usgn) |
| 6808 | return Builder.CreateFPToUI(Ops[0], Ty); |
| 6809 | return Builder.CreateFPToSI(Ops[0], Ty); |
| 6810 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6811 | case NEON::BI__builtin_neon_vcvta_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6812 | case NEON::BI__builtin_neon_vcvta_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6813 | case NEON::BI__builtin_neon_vcvtaq_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6814 | case NEON::BI__builtin_neon_vcvtaq_s32_v: |
| 6815 | case NEON::BI__builtin_neon_vcvta_u32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6816 | case NEON::BI__builtin_neon_vcvtaq_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6817 | case NEON::BI__builtin_neon_vcvtaq_u32_v: |
| 6818 | case NEON::BI__builtin_neon_vcvta_s64_v: |
| 6819 | case NEON::BI__builtin_neon_vcvtaq_s64_v: |
| 6820 | case NEON::BI__builtin_neon_vcvta_u64_v: |
| 6821 | case NEON::BI__builtin_neon_vcvtaq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6822 | Int = usgn ? Intrinsic::aarch64_neon_fcvtau : Intrinsic::aarch64_neon_fcvtas; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 6823 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6824 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvta"); |
| 6825 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6826 | case NEON::BI__builtin_neon_vcvtm_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6827 | case NEON::BI__builtin_neon_vcvtm_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6828 | case NEON::BI__builtin_neon_vcvtmq_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6829 | case NEON::BI__builtin_neon_vcvtmq_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6830 | case NEON::BI__builtin_neon_vcvtm_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6831 | case NEON::BI__builtin_neon_vcvtm_u32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6832 | case NEON::BI__builtin_neon_vcvtmq_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6833 | case NEON::BI__builtin_neon_vcvtmq_u32_v: |
| 6834 | case NEON::BI__builtin_neon_vcvtm_s64_v: |
| 6835 | case NEON::BI__builtin_neon_vcvtmq_s64_v: |
| 6836 | case NEON::BI__builtin_neon_vcvtm_u64_v: |
| 6837 | case NEON::BI__builtin_neon_vcvtmq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6838 | Int = usgn ? Intrinsic::aarch64_neon_fcvtmu : Intrinsic::aarch64_neon_fcvtms; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 6839 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6840 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtm"); |
| 6841 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6842 | case NEON::BI__builtin_neon_vcvtn_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6843 | case NEON::BI__builtin_neon_vcvtn_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6844 | case NEON::BI__builtin_neon_vcvtnq_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6845 | case NEON::BI__builtin_neon_vcvtnq_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6846 | case NEON::BI__builtin_neon_vcvtn_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6847 | case NEON::BI__builtin_neon_vcvtn_u32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6848 | case NEON::BI__builtin_neon_vcvtnq_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6849 | case NEON::BI__builtin_neon_vcvtnq_u32_v: |
| 6850 | case NEON::BI__builtin_neon_vcvtn_s64_v: |
| 6851 | case NEON::BI__builtin_neon_vcvtnq_s64_v: |
| 6852 | case NEON::BI__builtin_neon_vcvtn_u64_v: |
| 6853 | case NEON::BI__builtin_neon_vcvtnq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6854 | Int = usgn ? Intrinsic::aarch64_neon_fcvtnu : Intrinsic::aarch64_neon_fcvtns; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 6855 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6856 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtn"); |
| 6857 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6858 | case NEON::BI__builtin_neon_vcvtp_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6859 | case NEON::BI__builtin_neon_vcvtp_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6860 | case NEON::BI__builtin_neon_vcvtpq_s16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6861 | case NEON::BI__builtin_neon_vcvtpq_s32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6862 | case NEON::BI__builtin_neon_vcvtp_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6863 | case NEON::BI__builtin_neon_vcvtp_u32_v: |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 6864 | case NEON::BI__builtin_neon_vcvtpq_u16_v: |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6865 | case NEON::BI__builtin_neon_vcvtpq_u32_v: |
| 6866 | case NEON::BI__builtin_neon_vcvtp_s64_v: |
| 6867 | case NEON::BI__builtin_neon_vcvtpq_s64_v: |
| 6868 | case NEON::BI__builtin_neon_vcvtp_u64_v: |
| 6869 | case NEON::BI__builtin_neon_vcvtpq_u64_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6870 | Int = usgn ? Intrinsic::aarch64_neon_fcvtpu : Intrinsic::aarch64_neon_fcvtps; |
Ahmed Bougacha | 774b5e2 | 2015-08-24 23:41:31 +0000 | [diff] [blame] | 6871 | llvm::Type *Tys[2] = { Ty, GetFloatNeonType(this, Type) }; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6872 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vcvtp"); |
| 6873 | } |
| 6874 | case NEON::BI__builtin_neon_vmulx_v: |
| 6875 | case NEON::BI__builtin_neon_vmulxq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6876 | Int = Intrinsic::aarch64_neon_fmulx; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6877 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmulx"); |
| 6878 | } |
| 6879 | case NEON::BI__builtin_neon_vmul_lane_v: |
| 6880 | case NEON::BI__builtin_neon_vmul_laneq_v: { |
| 6881 | // v1f64 vmul_lane should be mapped to Neon scalar mul lane |
| 6882 | bool Quad = false; |
| 6883 | if (BuiltinID == NEON::BI__builtin_neon_vmul_laneq_v) |
| 6884 | Quad = true; |
| 6885 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 6886 | llvm::Type *VTy = GetNeonType(this, |
| 6887 | NeonTypeFlags(NeonTypeFlags::Float64, false, Quad)); |
| 6888 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
| 6889 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2], "extract"); |
| 6890 | Value *Result = Builder.CreateFMul(Ops[0], Ops[1]); |
| 6891 | return Builder.CreateBitCast(Result, Ty); |
| 6892 | } |
Tim Northover | 0c68faa | 2014-03-31 15:47:09 +0000 | [diff] [blame] | 6893 | case NEON::BI__builtin_neon_vnegd_s64: |
| 6894 | return Builder.CreateNeg(EmitScalarExpr(E->getArg(0)), "vnegd"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6895 | case NEON::BI__builtin_neon_vpmaxnm_v: |
| 6896 | case NEON::BI__builtin_neon_vpmaxnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6897 | Int = Intrinsic::aarch64_neon_fmaxnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6898 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmaxnm"); |
| 6899 | } |
| 6900 | case NEON::BI__builtin_neon_vpminnm_v: |
| 6901 | case NEON::BI__builtin_neon_vpminnmq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6902 | Int = Intrinsic::aarch64_neon_fminnmp; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6903 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpminnm"); |
| 6904 | } |
| 6905 | case NEON::BI__builtin_neon_vsqrt_v: |
| 6906 | case NEON::BI__builtin_neon_vsqrtq_v: { |
| 6907 | Int = Intrinsic::sqrt; |
| 6908 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 6909 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqrt"); |
| 6910 | } |
| 6911 | case NEON::BI__builtin_neon_vrbit_v: |
| 6912 | case NEON::BI__builtin_neon_vrbitq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6913 | Int = Intrinsic::aarch64_neon_rbit; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6914 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrbit"); |
| 6915 | } |
| 6916 | case NEON::BI__builtin_neon_vaddv_u8: |
| 6917 | // FIXME: These are handled by the AArch64 scalar code. |
| 6918 | usgn = true; |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 6919 | LLVM_FALLTHROUGH; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6920 | case NEON::BI__builtin_neon_vaddv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6921 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6922 | Ty = Int32Ty; |
| 6923 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6924 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6925 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6926 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6927 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6928 | } |
| 6929 | case NEON::BI__builtin_neon_vaddv_u16: |
| 6930 | usgn = true; |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 6931 | LLVM_FALLTHROUGH; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6932 | case NEON::BI__builtin_neon_vaddv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6933 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6934 | Ty = Int32Ty; |
| 6935 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6936 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6937 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6938 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6939 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6940 | } |
| 6941 | case NEON::BI__builtin_neon_vaddvq_u8: |
| 6942 | usgn = true; |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 6943 | LLVM_FALLTHROUGH; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6944 | case NEON::BI__builtin_neon_vaddvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6945 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6946 | Ty = Int32Ty; |
| 6947 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6948 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6949 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6950 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6951 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6952 | } |
| 6953 | case NEON::BI__builtin_neon_vaddvq_u16: |
| 6954 | usgn = true; |
Adrian Prantl | f3b3ccd | 2017-12-19 22:06:11 +0000 | [diff] [blame] | 6955 | LLVM_FALLTHROUGH; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6956 | case NEON::BI__builtin_neon_vaddvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6957 | Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6958 | Ty = Int32Ty; |
| 6959 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6960 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6961 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6962 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6963 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6964 | } |
| 6965 | case NEON::BI__builtin_neon_vmaxv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6966 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6967 | Ty = Int32Ty; |
| 6968 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6969 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6970 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6971 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6972 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6973 | } |
| 6974 | case NEON::BI__builtin_neon_vmaxv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6975 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6976 | Ty = Int32Ty; |
| 6977 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6978 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6979 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6980 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6981 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6982 | } |
| 6983 | case NEON::BI__builtin_neon_vmaxvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6984 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6985 | Ty = Int32Ty; |
| 6986 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6987 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6988 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6989 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6990 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6991 | } |
| 6992 | case NEON::BI__builtin_neon_vmaxvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 6993 | Int = Intrinsic::aarch64_neon_umaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6994 | Ty = Int32Ty; |
| 6995 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 6996 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 6997 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 6998 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 6999 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7000 | } |
| 7001 | case NEON::BI__builtin_neon_vmaxv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7002 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7003 | Ty = Int32Ty; |
| 7004 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7005 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7006 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7007 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7008 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7009 | } |
| 7010 | case NEON::BI__builtin_neon_vmaxv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7011 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7012 | Ty = Int32Ty; |
| 7013 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7014 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7015 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7016 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7017 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7018 | } |
| 7019 | case NEON::BI__builtin_neon_vmaxvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7020 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7021 | Ty = Int32Ty; |
| 7022 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7023 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7024 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7025 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7026 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7027 | } |
| 7028 | case NEON::BI__builtin_neon_vmaxvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7029 | Int = Intrinsic::aarch64_neon_smaxv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7030 | Ty = Int32Ty; |
| 7031 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7032 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7033 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7034 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7035 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7036 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 7037 | case NEON::BI__builtin_neon_vmaxv_f16: { |
| 7038 | Int = Intrinsic::aarch64_neon_fmaxv; |
| 7039 | Ty = HalfTy; |
| 7040 | VTy = llvm::VectorType::get(HalfTy, 4); |
| 7041 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7042 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7043 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 7044 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7045 | } |
| 7046 | case NEON::BI__builtin_neon_vmaxvq_f16: { |
| 7047 | Int = Intrinsic::aarch64_neon_fmaxv; |
| 7048 | Ty = HalfTy; |
| 7049 | VTy = llvm::VectorType::get(HalfTy, 8); |
| 7050 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7051 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7052 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxv"); |
| 7053 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7054 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7055 | case NEON::BI__builtin_neon_vminv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7056 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7057 | Ty = Int32Ty; |
| 7058 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7059 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7060 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7061 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7062 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7063 | } |
| 7064 | case NEON::BI__builtin_neon_vminv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7065 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7066 | Ty = Int32Ty; |
| 7067 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7068 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7069 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7070 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7071 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7072 | } |
| 7073 | case NEON::BI__builtin_neon_vminvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7074 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7075 | Ty = Int32Ty; |
| 7076 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7077 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7078 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7079 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7080 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7081 | } |
| 7082 | case NEON::BI__builtin_neon_vminvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7083 | Int = Intrinsic::aarch64_neon_uminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7084 | Ty = Int32Ty; |
| 7085 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7086 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7087 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7088 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7089 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7090 | } |
| 7091 | case NEON::BI__builtin_neon_vminv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7092 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7093 | Ty = Int32Ty; |
| 7094 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7095 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7096 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7097 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7098 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7099 | } |
| 7100 | case NEON::BI__builtin_neon_vminv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7101 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7102 | Ty = Int32Ty; |
| 7103 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7104 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7105 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7106 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7107 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7108 | } |
| 7109 | case NEON::BI__builtin_neon_vminvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7110 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7111 | Ty = Int32Ty; |
| 7112 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7113 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7114 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7115 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7116 | return Builder.CreateTrunc(Ops[0], Int8Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7117 | } |
| 7118 | case NEON::BI__builtin_neon_vminvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7119 | Int = Intrinsic::aarch64_neon_sminv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7120 | Ty = Int32Ty; |
| 7121 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7122 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7123 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7124 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7125 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7126 | } |
Abderrazek Zaafrani | f58a132 | 2017-12-21 19:20:01 +0000 | [diff] [blame] | 7127 | case NEON::BI__builtin_neon_vminv_f16: { |
| 7128 | Int = Intrinsic::aarch64_neon_fminv; |
| 7129 | Ty = HalfTy; |
| 7130 | VTy = llvm::VectorType::get(HalfTy, 4); |
| 7131 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7132 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7133 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 7134 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7135 | } |
| 7136 | case NEON::BI__builtin_neon_vminvq_f16: { |
| 7137 | Int = Intrinsic::aarch64_neon_fminv; |
| 7138 | Ty = HalfTy; |
| 7139 | VTy = llvm::VectorType::get(HalfTy, 8); |
| 7140 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7141 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7142 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminv"); |
| 7143 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7144 | } |
| 7145 | case NEON::BI__builtin_neon_vmaxnmv_f16: { |
| 7146 | Int = Intrinsic::aarch64_neon_fmaxnmv; |
| 7147 | Ty = HalfTy; |
| 7148 | VTy = llvm::VectorType::get(HalfTy, 4); |
| 7149 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7150 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7151 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxnmv"); |
| 7152 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7153 | } |
| 7154 | case NEON::BI__builtin_neon_vmaxnmvq_f16: { |
| 7155 | Int = Intrinsic::aarch64_neon_fmaxnmv; |
| 7156 | Ty = HalfTy; |
| 7157 | VTy = llvm::VectorType::get(HalfTy, 8); |
| 7158 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7159 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7160 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vmaxnmv"); |
| 7161 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7162 | } |
| 7163 | case NEON::BI__builtin_neon_vminnmv_f16: { |
| 7164 | Int = Intrinsic::aarch64_neon_fminnmv; |
| 7165 | Ty = HalfTy; |
| 7166 | VTy = llvm::VectorType::get(HalfTy, 4); |
| 7167 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7168 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7169 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminnmv"); |
| 7170 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7171 | } |
| 7172 | case NEON::BI__builtin_neon_vminnmvq_f16: { |
| 7173 | Int = Intrinsic::aarch64_neon_fminnmv; |
| 7174 | Ty = HalfTy; |
| 7175 | VTy = llvm::VectorType::get(HalfTy, 8); |
| 7176 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7177 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7178 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vminnmv"); |
| 7179 | return Builder.CreateTrunc(Ops[0], HalfTy); |
| 7180 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7181 | case NEON::BI__builtin_neon_vmul_n_f64: { |
| 7182 | Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); |
| 7183 | Value *RHS = Builder.CreateBitCast(EmitScalarExpr(E->getArg(1)), DoubleTy); |
| 7184 | return Builder.CreateFMul(Ops[0], RHS); |
| 7185 | } |
| 7186 | case NEON::BI__builtin_neon_vaddlv_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7187 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7188 | Ty = Int32Ty; |
| 7189 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7190 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7191 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7192 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7193 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7194 | } |
| 7195 | case NEON::BI__builtin_neon_vaddlv_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7196 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7197 | Ty = Int32Ty; |
| 7198 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7199 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7200 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7201 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 7202 | } |
| 7203 | case NEON::BI__builtin_neon_vaddlvq_u8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7204 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7205 | Ty = Int32Ty; |
| 7206 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7207 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7208 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7209 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7210 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7211 | } |
| 7212 | case NEON::BI__builtin_neon_vaddlvq_u16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7213 | Int = Intrinsic::aarch64_neon_uaddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7214 | Ty = Int32Ty; |
| 7215 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7216 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7217 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7218 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 7219 | } |
| 7220 | case NEON::BI__builtin_neon_vaddlv_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7221 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7222 | Ty = Int32Ty; |
| 7223 | VTy = llvm::VectorType::get(Int8Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7224 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7225 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7226 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7227 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7228 | } |
| 7229 | case NEON::BI__builtin_neon_vaddlv_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7230 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7231 | Ty = Int32Ty; |
| 7232 | VTy = llvm::VectorType::get(Int16Ty, 4); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7233 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7234 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7235 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 7236 | } |
| 7237 | case NEON::BI__builtin_neon_vaddlvq_s8: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7238 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7239 | Ty = Int32Ty; |
| 7240 | VTy = llvm::VectorType::get(Int8Ty, 16); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7241 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7242 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7243 | Ops[0] = EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7244 | return Builder.CreateTrunc(Ops[0], Int16Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7245 | } |
| 7246 | case NEON::BI__builtin_neon_vaddlvq_s16: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7247 | Int = Intrinsic::aarch64_neon_saddlv; |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7248 | Ty = Int32Ty; |
| 7249 | VTy = llvm::VectorType::get(Int16Ty, 8); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7250 | llvm::Type *Tys[2] = { Ty, VTy }; |
| 7251 | Ops.push_back(EmitScalarExpr(E->getArg(0))); |
| 7252 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vaddlv"); |
| 7253 | } |
| 7254 | case NEON::BI__builtin_neon_vsri_n_v: |
| 7255 | case NEON::BI__builtin_neon_vsriq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7256 | Int = Intrinsic::aarch64_neon_vsri; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7257 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 7258 | return EmitNeonCall(Intrin, Ops, "vsri_n"); |
| 7259 | } |
| 7260 | case NEON::BI__builtin_neon_vsli_n_v: |
| 7261 | case NEON::BI__builtin_neon_vsliq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7262 | Int = Intrinsic::aarch64_neon_vsli; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7263 | llvm::Function *Intrin = CGM.getIntrinsic(Int, Ty); |
| 7264 | return EmitNeonCall(Intrin, Ops, "vsli_n"); |
| 7265 | } |
| 7266 | case NEON::BI__builtin_neon_vsra_n_v: |
| 7267 | case NEON::BI__builtin_neon_vsraq_n_v: |
| 7268 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
| 7269 | Ops[1] = EmitNeonRShiftImm(Ops[1], Ops[2], Ty, usgn, "vsra_n"); |
| 7270 | return Builder.CreateAdd(Ops[0], Ops[1]); |
| 7271 | case NEON::BI__builtin_neon_vrsra_n_v: |
| 7272 | case NEON::BI__builtin_neon_vrsraq_n_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7273 | Int = usgn ? Intrinsic::aarch64_neon_urshl : Intrinsic::aarch64_neon_srshl; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7274 | SmallVector<llvm::Value*,2> TmpOps; |
| 7275 | TmpOps.push_back(Ops[1]); |
| 7276 | TmpOps.push_back(Ops[2]); |
| 7277 | Function* F = CGM.getIntrinsic(Int, Ty); |
| 7278 | llvm::Value *tmp = EmitNeonCall(F, TmpOps, "vrshr_n", 1, true); |
| 7279 | Ops[0] = Builder.CreateBitCast(Ops[0], VTy); |
| 7280 | return Builder.CreateAdd(Ops[0], tmp); |
| 7281 | } |
| 7282 | // FIXME: Sharing loads & stores with 32-bit is complicated by the absence |
| 7283 | // of an Align parameter here. |
| 7284 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 7285 | case NEON::BI__builtin_neon_vld1q_x2_v: |
| 7286 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 7287 | case NEON::BI__builtin_neon_vld1q_x3_v: |
| 7288 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 7289 | case NEON::BI__builtin_neon_vld1q_x4_v: { |
| 7290 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 7291 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7292 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 7293 | unsigned Int; |
| 7294 | switch (BuiltinID) { |
| 7295 | case NEON::BI__builtin_neon_vld1_x2_v: |
| 7296 | case NEON::BI__builtin_neon_vld1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7297 | Int = Intrinsic::aarch64_neon_ld1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7298 | break; |
| 7299 | case NEON::BI__builtin_neon_vld1_x3_v: |
| 7300 | case NEON::BI__builtin_neon_vld1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7301 | Int = Intrinsic::aarch64_neon_ld1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7302 | break; |
| 7303 | case NEON::BI__builtin_neon_vld1_x4_v: |
| 7304 | case NEON::BI__builtin_neon_vld1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7305 | Int = Intrinsic::aarch64_neon_ld1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7306 | break; |
| 7307 | } |
| 7308 | Function *F = CGM.getIntrinsic(Int, Tys); |
| 7309 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld1xN"); |
| 7310 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 7311 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7312 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7313 | } |
| 7314 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 7315 | case NEON::BI__builtin_neon_vst1q_x2_v: |
| 7316 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 7317 | case NEON::BI__builtin_neon_vst1q_x3_v: |
| 7318 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 7319 | case NEON::BI__builtin_neon_vst1q_x4_v: { |
| 7320 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy->getVectorElementType()); |
| 7321 | llvm::Type *Tys[2] = { VTy, PTy }; |
| 7322 | unsigned Int; |
| 7323 | switch (BuiltinID) { |
| 7324 | case NEON::BI__builtin_neon_vst1_x2_v: |
| 7325 | case NEON::BI__builtin_neon_vst1q_x2_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7326 | Int = Intrinsic::aarch64_neon_st1x2; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7327 | break; |
| 7328 | case NEON::BI__builtin_neon_vst1_x3_v: |
| 7329 | case NEON::BI__builtin_neon_vst1q_x3_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7330 | Int = Intrinsic::aarch64_neon_st1x3; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7331 | break; |
| 7332 | case NEON::BI__builtin_neon_vst1_x4_v: |
| 7333 | case NEON::BI__builtin_neon_vst1q_x4_v: |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7334 | Int = Intrinsic::aarch64_neon_st1x4; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7335 | break; |
| 7336 | } |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7337 | std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end()); |
| 7338 | return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, ""); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7339 | } |
| 7340 | case NEON::BI__builtin_neon_vld1_v: |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 7341 | case NEON::BI__builtin_neon_vld1q_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7342 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 7343 | auto Alignment = CharUnits::fromQuantity( |
| 7344 | BuiltinID == NEON::BI__builtin_neon_vld1_v ? 8 : 16); |
| 7345 | return Builder.CreateAlignedLoad(VTy, Ops[0], Alignment); |
| 7346 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7347 | case NEON::BI__builtin_neon_vst1_v: |
| 7348 | case NEON::BI__builtin_neon_vst1q_v: |
| 7349 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(VTy)); |
| 7350 | Ops[1] = Builder.CreateBitCast(Ops[1], VTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7351 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7352 | case NEON::BI__builtin_neon_vld1_lane_v: |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 7353 | case NEON::BI__builtin_neon_vld1q_lane_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7354 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7355 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 7356 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 7357 | auto Alignment = CharUnits::fromQuantity( |
| 7358 | BuiltinID == NEON::BI__builtin_neon_vld1_lane_v ? 8 : 16); |
| 7359 | Ops[0] = |
| 7360 | Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], Alignment); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7361 | return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane"); |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 7362 | } |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7363 | case NEON::BI__builtin_neon_vld1_dup_v: |
| 7364 | case NEON::BI__builtin_neon_vld1q_dup_v: { |
| 7365 | Value *V = UndefValue::get(Ty); |
| 7366 | Ty = llvm::PointerType::getUnqual(VTy->getElementType()); |
| 7367 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
Peter Collingbourne | b367c56 | 2016-11-28 22:30:21 +0000 | [diff] [blame] | 7368 | auto Alignment = CharUnits::fromQuantity( |
| 7369 | BuiltinID == NEON::BI__builtin_neon_vld1_dup_v ? 8 : 16); |
| 7370 | Ops[0] = |
| 7371 | Builder.CreateAlignedLoad(VTy->getElementType(), Ops[0], Alignment); |
Michael J. Spencer | 5ce2668 | 2014-06-02 19:48:59 +0000 | [diff] [blame] | 7372 | llvm::Constant *CI = ConstantInt::get(Int32Ty, 0); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7373 | Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI); |
| 7374 | return EmitNeonSplat(Ops[0], CI); |
| 7375 | } |
| 7376 | case NEON::BI__builtin_neon_vst1_lane_v: |
| 7377 | case NEON::BI__builtin_neon_vst1q_lane_v: |
| 7378 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7379 | Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]); |
| 7380 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7381 | return Builder.CreateDefaultAlignedStore(Ops[1], |
| 7382 | Builder.CreateBitCast(Ops[0], Ty)); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7383 | case NEON::BI__builtin_neon_vld2_v: |
| 7384 | case NEON::BI__builtin_neon_vld2q_v: { |
| 7385 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 7386 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7387 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7388 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7389 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 7390 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 7391 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7392 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7393 | } |
| 7394 | case NEON::BI__builtin_neon_vld3_v: |
| 7395 | case NEON::BI__builtin_neon_vld3q_v: { |
| 7396 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 7397 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7398 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7399 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7400 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 7401 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 7402 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7403 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7404 | } |
| 7405 | case NEON::BI__builtin_neon_vld4_v: |
| 7406 | case NEON::BI__builtin_neon_vld4q_v: { |
| 7407 | llvm::Type *PTy = llvm::PointerType::getUnqual(VTy); |
| 7408 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7409 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7410 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7411 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 7412 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 7413 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7414 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7415 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 7416 | case NEON::BI__builtin_neon_vld2_dup_v: |
| 7417 | case NEON::BI__builtin_neon_vld2q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7418 | llvm::Type *PTy = |
| 7419 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 7420 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7421 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7422 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7423 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld2"); |
| 7424 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 7425 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7426 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7427 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 7428 | case NEON::BI__builtin_neon_vld3_dup_v: |
| 7429 | case NEON::BI__builtin_neon_vld3q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7430 | llvm::Type *PTy = |
| 7431 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 7432 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7433 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7434 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7435 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld3"); |
| 7436 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 7437 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7438 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7439 | } |
Tim Northover | 74b2def | 2014-04-01 10:37:47 +0000 | [diff] [blame] | 7440 | case NEON::BI__builtin_neon_vld4_dup_v: |
| 7441 | case NEON::BI__builtin_neon_vld4q_dup_v: { |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7442 | llvm::Type *PTy = |
| 7443 | llvm::PointerType::getUnqual(VTy->getElementType()); |
| 7444 | Ops[1] = Builder.CreateBitCast(Ops[1], PTy); |
| 7445 | llvm::Type *Tys[2] = { VTy, PTy }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7446 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4r, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7447 | Ops[1] = Builder.CreateCall(F, Ops[1], "vld4"); |
| 7448 | Ops[0] = Builder.CreateBitCast(Ops[0], |
| 7449 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7450 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7451 | } |
| 7452 | case NEON::BI__builtin_neon_vld2_lane_v: |
| 7453 | case NEON::BI__builtin_neon_vld2q_lane_v: { |
| 7454 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7455 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld2lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7456 | Ops.push_back(Ops[1]); |
| 7457 | Ops.erase(Ops.begin()+1); |
| 7458 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7459 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7460 | Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 7461 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld2_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7462 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 7463 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7464 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7465 | } |
| 7466 | case NEON::BI__builtin_neon_vld3_lane_v: |
| 7467 | case NEON::BI__builtin_neon_vld3q_lane_v: { |
| 7468 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7469 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld3lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7470 | Ops.push_back(Ops[1]); |
| 7471 | Ops.erase(Ops.begin()+1); |
| 7472 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7473 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 7474 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7475 | Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 7476 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld3_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7477 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 7478 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7479 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7480 | } |
| 7481 | case NEON::BI__builtin_neon_vld4_lane_v: |
| 7482 | case NEON::BI__builtin_neon_vld4q_lane_v: { |
| 7483 | llvm::Type *Tys[2] = { VTy, Ops[1]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7484 | Function *F = CGM.getIntrinsic(Intrinsic::aarch64_neon_ld4lane, Tys); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7485 | Ops.push_back(Ops[1]); |
| 7486 | Ops.erase(Ops.begin()+1); |
| 7487 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7488 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
| 7489 | Ops[3] = Builder.CreateBitCast(Ops[3], Ty); |
| 7490 | Ops[4] = Builder.CreateBitCast(Ops[4], Ty); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7491 | Ops[5] = Builder.CreateZExt(Ops[5], Int64Ty); |
Craig Topper | 5fc8fc2 | 2014-08-27 06:28:36 +0000 | [diff] [blame] | 7492 | Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld4_lane"); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7493 | Ty = llvm::PointerType::getUnqual(Ops[1]->getType()); |
| 7494 | Ops[0] = Builder.CreateBitCast(Ops[0], Ty); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7495 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7496 | } |
| 7497 | case NEON::BI__builtin_neon_vst2_v: |
| 7498 | case NEON::BI__builtin_neon_vst2q_v: { |
| 7499 | Ops.push_back(Ops[0]); |
| 7500 | Ops.erase(Ops.begin()); |
| 7501 | llvm::Type *Tys[2] = { VTy, Ops[2]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7502 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7503 | Ops, ""); |
| 7504 | } |
| 7505 | case NEON::BI__builtin_neon_vst2_lane_v: |
| 7506 | case NEON::BI__builtin_neon_vst2q_lane_v: { |
| 7507 | Ops.push_back(Ops[0]); |
| 7508 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7509 | Ops[2] = Builder.CreateZExt(Ops[2], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7510 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7511 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st2lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7512 | Ops, ""); |
| 7513 | } |
| 7514 | case NEON::BI__builtin_neon_vst3_v: |
| 7515 | case NEON::BI__builtin_neon_vst3q_v: { |
| 7516 | Ops.push_back(Ops[0]); |
| 7517 | Ops.erase(Ops.begin()); |
| 7518 | llvm::Type *Tys[2] = { VTy, Ops[3]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7519 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7520 | Ops, ""); |
| 7521 | } |
| 7522 | case NEON::BI__builtin_neon_vst3_lane_v: |
| 7523 | case NEON::BI__builtin_neon_vst3q_lane_v: { |
| 7524 | Ops.push_back(Ops[0]); |
| 7525 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7526 | Ops[3] = Builder.CreateZExt(Ops[3], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7527 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7528 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st3lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7529 | Ops, ""); |
| 7530 | } |
| 7531 | case NEON::BI__builtin_neon_vst4_v: |
| 7532 | case NEON::BI__builtin_neon_vst4q_v: { |
| 7533 | Ops.push_back(Ops[0]); |
| 7534 | Ops.erase(Ops.begin()); |
| 7535 | llvm::Type *Tys[2] = { VTy, Ops[4]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7536 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7537 | Ops, ""); |
| 7538 | } |
| 7539 | case NEON::BI__builtin_neon_vst4_lane_v: |
| 7540 | case NEON::BI__builtin_neon_vst4q_lane_v: { |
| 7541 | Ops.push_back(Ops[0]); |
| 7542 | Ops.erase(Ops.begin()); |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 7543 | Ops[4] = Builder.CreateZExt(Ops[4], Int64Ty); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7544 | llvm::Type *Tys[2] = { VTy, Ops[5]->getType() }; |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7545 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_st4lane, Tys), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7546 | Ops, ""); |
| 7547 | } |
| 7548 | case NEON::BI__builtin_neon_vtrn_v: |
| 7549 | case NEON::BI__builtin_neon_vtrnq_v: { |
| 7550 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 7551 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7552 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 7553 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7554 | |
| 7555 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 7556 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7557 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 7558 | Indices.push_back(i+vi); |
| 7559 | Indices.push_back(i+e+vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7560 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 7561 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 7562 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vtrn"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7563 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7564 | } |
| 7565 | return SV; |
| 7566 | } |
| 7567 | case NEON::BI__builtin_neon_vuzp_v: |
| 7568 | case NEON::BI__builtin_neon_vuzpq_v: { |
| 7569 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 7570 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7571 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 7572 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7573 | |
| 7574 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 7575 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7576 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 7577 | Indices.push_back(2*i+vi); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7578 | |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 7579 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 7580 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vuzp"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7581 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7582 | } |
| 7583 | return SV; |
| 7584 | } |
| 7585 | case NEON::BI__builtin_neon_vzip_v: |
| 7586 | case NEON::BI__builtin_neon_vzipq_v: { |
| 7587 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty)); |
| 7588 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty); |
| 7589 | Ops[2] = Builder.CreateBitCast(Ops[2], Ty); |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 7590 | Value *SV = nullptr; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7591 | |
| 7592 | for (unsigned vi = 0; vi != 2; ++vi) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 7593 | SmallVector<uint32_t, 16> Indices; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7594 | for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) { |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 7595 | Indices.push_back((i + vi*e) >> 1); |
| 7596 | Indices.push_back(((i + vi*e) >> 1)+e); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7597 | } |
David Blaikie | fb901c7a | 2015-04-04 15:12:29 +0000 | [diff] [blame] | 7598 | Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi); |
Craig Topper | 832caf0 | 2016-05-29 02:39:30 +0000 | [diff] [blame] | 7599 | SV = Builder.CreateShuffleVector(Ops[1], Ops[2], Indices, "vzip"); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 7600 | SV = Builder.CreateDefaultAlignedStore(SV, Addr); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7601 | } |
| 7602 | return SV; |
| 7603 | } |
| 7604 | case NEON::BI__builtin_neon_vqtbl1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7605 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7606 | Ops, "vtbl1"); |
| 7607 | } |
| 7608 | case NEON::BI__builtin_neon_vqtbl2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7609 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7610 | Ops, "vtbl2"); |
| 7611 | } |
| 7612 | case NEON::BI__builtin_neon_vqtbl3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7613 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7614 | Ops, "vtbl3"); |
| 7615 | } |
| 7616 | case NEON::BI__builtin_neon_vqtbl4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7617 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbl4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7618 | Ops, "vtbl4"); |
| 7619 | } |
| 7620 | case NEON::BI__builtin_neon_vqtbx1q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7621 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx1, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7622 | Ops, "vtbx1"); |
| 7623 | } |
| 7624 | case NEON::BI__builtin_neon_vqtbx2q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7625 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx2, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7626 | Ops, "vtbx2"); |
| 7627 | } |
| 7628 | case NEON::BI__builtin_neon_vqtbx3q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7629 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx3, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7630 | Ops, "vtbx3"); |
| 7631 | } |
| 7632 | case NEON::BI__builtin_neon_vqtbx4q_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7633 | return EmitNeonCall(CGM.getIntrinsic(Intrinsic::aarch64_neon_tbx4, Ty), |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7634 | Ops, "vtbx4"); |
| 7635 | } |
| 7636 | case NEON::BI__builtin_neon_vsqadd_v: |
| 7637 | case NEON::BI__builtin_neon_vsqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7638 | Int = Intrinsic::aarch64_neon_usqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7639 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vsqadd"); |
| 7640 | } |
| 7641 | case NEON::BI__builtin_neon_vuqadd_v: |
| 7642 | case NEON::BI__builtin_neon_vuqaddq_v: { |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 7643 | Int = Intrinsic::aarch64_neon_suqadd; |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 7644 | return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vuqadd"); |
| 7645 | } |
| 7646 | } |
| 7647 | } |
| 7648 | |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 7649 | llvm::Value *CodeGenFunction:: |
Bill Wendling | f1a3fca | 2012-02-22 09:30:11 +0000 | [diff] [blame] | 7650 | BuildVector(ArrayRef<llvm::Value*> Ops) { |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 7651 | assert((Ops.size() & (Ops.size() - 1)) == 0 && |
| 7652 | "Not a power-of-two sized vector!"); |
| 7653 | bool AllConstants = true; |
| 7654 | for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i) |
| 7655 | AllConstants &= isa<Constant>(Ops[i]); |
| 7656 | |
| 7657 | // If this is a constant vector, create a ConstantVector. |
| 7658 | if (AllConstants) { |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 7659 | SmallVector<llvm::Constant*, 16> CstOps; |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 7660 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
| 7661 | CstOps.push_back(cast<Constant>(Ops[i])); |
| 7662 | return llvm::ConstantVector::get(CstOps); |
| 7663 | } |
| 7664 | |
| 7665 | // Otherwise, insertelement the values to build the vector. |
| 7666 | Value *Result = |
| 7667 | llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size())); |
| 7668 | |
| 7669 | for (unsigned i = 0, e = Ops.size(); i != e; ++i) |
Chris Lattner | 2d6b7b9 | 2012-01-25 05:34:41 +0000 | [diff] [blame] | 7670 | Result = Builder.CreateInsertElement(Result, Ops[i], Builder.getInt32(i)); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 7671 | |
| 7672 | return Result; |
| 7673 | } |
| 7674 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7675 | // Convert the mask from an integer type to a vector of i1. |
| 7676 | static Value *getMaskVecValue(CodeGenFunction &CGF, Value *Mask, |
| 7677 | unsigned NumElts) { |
| 7678 | |
| 7679 | llvm::VectorType *MaskTy = llvm::VectorType::get(CGF.Builder.getInt1Ty(), |
| 7680 | cast<IntegerType>(Mask->getType())->getBitWidth()); |
| 7681 | Value *MaskVec = CGF.Builder.CreateBitCast(Mask, MaskTy); |
| 7682 | |
| 7683 | // If we have less than 8 elements, then the starting mask was an i8 and |
| 7684 | // we need to extract down to the right number of elements. |
| 7685 | if (NumElts < 8) { |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 7686 | uint32_t Indices[4]; |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7687 | for (unsigned i = 0; i != NumElts; ++i) |
| 7688 | Indices[i] = i; |
| 7689 | MaskVec = CGF.Builder.CreateShuffleVector(MaskVec, MaskVec, |
| 7690 | makeArrayRef(Indices, NumElts), |
| 7691 | "extract"); |
| 7692 | } |
| 7693 | return MaskVec; |
| 7694 | } |
| 7695 | |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 7696 | static Value *EmitX86MaskedStore(CodeGenFunction &CGF, |
| 7697 | SmallVectorImpl<Value *> &Ops, |
| 7698 | unsigned Align) { |
| 7699 | // Cast the pointer to right type. |
| 7700 | Ops[0] = CGF.Builder.CreateBitCast(Ops[0], |
| 7701 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 7702 | |
| 7703 | // If the mask is all ones just emit a regular store. |
| 7704 | if (const auto *C = dyn_cast<Constant>(Ops[2])) |
| 7705 | if (C->isAllOnesValue()) |
| 7706 | return CGF.Builder.CreateAlignedStore(Ops[1], Ops[0], Align); |
| 7707 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7708 | Value *MaskVec = getMaskVecValue(CGF, Ops[2], |
| 7709 | Ops[1]->getType()->getVectorNumElements()); |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 7710 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7711 | return CGF.Builder.CreateMaskedStore(Ops[1], Ops[0], Align, MaskVec); |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 7712 | } |
| 7713 | |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 7714 | static Value *EmitX86MaskedLoad(CodeGenFunction &CGF, |
| 7715 | SmallVectorImpl<Value *> &Ops, unsigned Align) { |
| 7716 | // Cast the pointer to right type. |
| 7717 | Ops[0] = CGF.Builder.CreateBitCast(Ops[0], |
| 7718 | llvm::PointerType::getUnqual(Ops[1]->getType())); |
| 7719 | |
| 7720 | // If the mask is all ones just emit a regular store. |
| 7721 | if (const auto *C = dyn_cast<Constant>(Ops[2])) |
| 7722 | if (C->isAllOnesValue()) |
| 7723 | return CGF.Builder.CreateAlignedLoad(Ops[0], Align); |
| 7724 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7725 | Value *MaskVec = getMaskVecValue(CGF, Ops[2], |
| 7726 | Ops[1]->getType()->getVectorNumElements()); |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 7727 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7728 | return CGF.Builder.CreateMaskedLoad(Ops[0], Align, MaskVec, Ops[1]); |
| 7729 | } |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 7730 | |
Craig Topper | 5028ace | 2017-12-16 08:26:22 +0000 | [diff] [blame] | 7731 | static Value *EmitX86MaskLogic(CodeGenFunction &CGF, Instruction::BinaryOps Opc, |
| 7732 | unsigned NumElts, SmallVectorImpl<Value *> &Ops, |
| 7733 | bool InvertLHS = false) { |
| 7734 | Value *LHS = getMaskVecValue(CGF, Ops[0], NumElts); |
| 7735 | Value *RHS = getMaskVecValue(CGF, Ops[1], NumElts); |
| 7736 | |
| 7737 | if (InvertLHS) |
| 7738 | LHS = CGF.Builder.CreateNot(LHS); |
| 7739 | |
| 7740 | return CGF.Builder.CreateBitCast(CGF.Builder.CreateBinOp(Opc, LHS, RHS), |
| 7741 | CGF.Builder.getIntNTy(std::max(NumElts, 8U))); |
| 7742 | } |
| 7743 | |
Simon Pilgrim | 2d85173 | 2016-07-22 13:58:56 +0000 | [diff] [blame] | 7744 | static Value *EmitX86SubVectorBroadcast(CodeGenFunction &CGF, |
| 7745 | SmallVectorImpl<Value *> &Ops, |
| 7746 | llvm::Type *DstTy, |
| 7747 | unsigned SrcSizeInBits, |
| 7748 | unsigned Align) { |
| 7749 | // Load the subvector. |
| 7750 | Ops[0] = CGF.Builder.CreateAlignedLoad(Ops[0], Align); |
| 7751 | |
| 7752 | // Create broadcast mask. |
| 7753 | unsigned NumDstElts = DstTy->getVectorNumElements(); |
| 7754 | unsigned NumSrcElts = SrcSizeInBits / DstTy->getScalarSizeInBits(); |
| 7755 | |
| 7756 | SmallVector<uint32_t, 8> Mask; |
| 7757 | for (unsigned i = 0; i != NumDstElts; i += NumSrcElts) |
| 7758 | for (unsigned j = 0; j != NumSrcElts; ++j) |
| 7759 | Mask.push_back(j); |
| 7760 | |
| 7761 | return CGF.Builder.CreateShuffleVector(Ops[0], Ops[0], Mask, "subvecbcst"); |
| 7762 | } |
| 7763 | |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7764 | static Value *EmitX86Select(CodeGenFunction &CGF, |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 7765 | Value *Mask, Value *Op0, Value *Op1) { |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7766 | |
| 7767 | // If the mask is all ones just return first argument. |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 7768 | if (const auto *C = dyn_cast<Constant>(Mask)) |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7769 | if (C->isAllOnesValue()) |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 7770 | return Op0; |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7771 | |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 7772 | Mask = getMaskVecValue(CGF, Mask, Op0->getType()->getVectorNumElements()); |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 7773 | |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 7774 | return CGF.Builder.CreateSelect(Mask, Op0, Op1); |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 7775 | } |
| 7776 | |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 7777 | static Value *EmitX86MaskedCompare(CodeGenFunction &CGF, unsigned CC, |
| 7778 | bool Signed, SmallVectorImpl<Value *> &Ops) { |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7779 | unsigned NumElts = Ops[0]->getType()->getVectorNumElements(); |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 7780 | Value *Cmp; |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7781 | |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 7782 | if (CC == 3) { |
| 7783 | Cmp = Constant::getNullValue( |
| 7784 | llvm::VectorType::get(CGF.Builder.getInt1Ty(), NumElts)); |
| 7785 | } else if (CC == 7) { |
| 7786 | Cmp = Constant::getAllOnesValue( |
| 7787 | llvm::VectorType::get(CGF.Builder.getInt1Ty(), NumElts)); |
| 7788 | } else { |
| 7789 | ICmpInst::Predicate Pred; |
| 7790 | switch (CC) { |
| 7791 | default: llvm_unreachable("Unknown condition code"); |
| 7792 | case 0: Pred = ICmpInst::ICMP_EQ; break; |
| 7793 | case 1: Pred = Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; |
| 7794 | case 2: Pred = Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; |
| 7795 | case 4: Pred = ICmpInst::ICMP_NE; break; |
| 7796 | case 5: Pred = Signed ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; |
| 7797 | case 6: Pred = Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; |
| 7798 | } |
| 7799 | Cmp = CGF.Builder.CreateICmp(Pred, Ops[0], Ops[1]); |
| 7800 | } |
| 7801 | |
| 7802 | const auto *C = dyn_cast<Constant>(Ops.back()); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7803 | if (!C || !C->isAllOnesValue()) |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 7804 | Cmp = CGF.Builder.CreateAnd(Cmp, getMaskVecValue(CGF, Ops.back(), NumElts)); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7805 | |
| 7806 | if (NumElts < 8) { |
| 7807 | uint32_t Indices[8]; |
| 7808 | for (unsigned i = 0; i != NumElts; ++i) |
| 7809 | Indices[i] = i; |
| 7810 | for (unsigned i = NumElts; i != 8; ++i) |
Craig Topper | ac1823f | 2016-07-04 07:09:46 +0000 | [diff] [blame] | 7811 | Indices[i] = i % NumElts + NumElts; |
Igor Breger | 2c880cf | 2016-06-29 08:14:17 +0000 | [diff] [blame] | 7812 | Cmp = CGF.Builder.CreateShuffleVector( |
| 7813 | Cmp, llvm::Constant::getNullValue(Cmp->getType()), Indices); |
Craig Topper | a54c21e | 2016-06-15 14:06:34 +0000 | [diff] [blame] | 7814 | } |
| 7815 | return CGF.Builder.CreateBitCast(Cmp, |
| 7816 | IntegerType::get(CGF.getLLVMContext(), |
| 7817 | std::max(NumElts, 8U))); |
| 7818 | } |
| 7819 | |
Uriel Korach | 3fba3c3 | 2017-09-13 09:02:02 +0000 | [diff] [blame] | 7820 | static Value *EmitX86Abs(CodeGenFunction &CGF, ArrayRef<Value *> Ops) { |
| 7821 | |
| 7822 | llvm::Type *Ty = Ops[0]->getType(); |
| 7823 | Value *Zero = llvm::Constant::getNullValue(Ty); |
| 7824 | Value *Sub = CGF.Builder.CreateSub(Zero, Ops[0]); |
| 7825 | Value *Cmp = CGF.Builder.CreateICmp(ICmpInst::ICMP_SGT, Ops[0], Zero); |
| 7826 | Value *Res = CGF.Builder.CreateSelect(Cmp, Ops[0], Sub); |
| 7827 | if (Ops.size() == 1) |
| 7828 | return Res; |
| 7829 | return EmitX86Select(CGF, Ops[2], Res, Ops[1]); |
| 7830 | } |
| 7831 | |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 7832 | static Value *EmitX86MinMax(CodeGenFunction &CGF, ICmpInst::Predicate Pred, |
| 7833 | ArrayRef<Value *> Ops) { |
| 7834 | Value *Cmp = CGF.Builder.CreateICmp(Pred, Ops[0], Ops[1]); |
| 7835 | Value *Res = CGF.Builder.CreateSelect(Cmp, Ops[0], Ops[1]); |
| 7836 | |
| 7837 | if (Ops.size() == 2) |
| 7838 | return Res; |
| 7839 | |
| 7840 | assert(Ops.size() == 4); |
| 7841 | return EmitX86Select(CGF, Ops[3], Res, Ops[2]); |
| 7842 | } |
| 7843 | |
Michael Zuckerman | 755a13d | 2017-04-04 13:29:53 +0000 | [diff] [blame] | 7844 | static Value *EmitX86SExtMask(CodeGenFunction &CGF, Value *Op, |
| 7845 | llvm::Type *DstTy) { |
| 7846 | unsigned NumberOfElements = DstTy->getVectorNumElements(); |
| 7847 | Value *Mask = getMaskVecValue(CGF, Op, NumberOfElements); |
| 7848 | return CGF.Builder.CreateSExt(Mask, DstTy, "vpmovm2"); |
| 7849 | } |
| 7850 | |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7851 | Value *CodeGenFunction::EmitX86CpuIs(const CallExpr *E) { |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7852 | const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts(); |
| 7853 | StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString(); |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7854 | return EmitX86CpuIs(CPUStr); |
| 7855 | } |
| 7856 | |
| 7857 | Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) { |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7858 | |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7859 | llvm::Type *Int32Ty = Builder.getInt32Ty(); |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7860 | |
| 7861 | // Matching the struct layout from the compiler-rt/libgcc structure that is |
| 7862 | // filled in: |
| 7863 | // unsigned int __cpu_vendor; |
| 7864 | // unsigned int __cpu_type; |
| 7865 | // unsigned int __cpu_subtype; |
| 7866 | // unsigned int __cpu_features[1]; |
| 7867 | llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty, Int32Ty, |
| 7868 | llvm::ArrayType::get(Int32Ty, 1)); |
| 7869 | |
| 7870 | // Grab the global __cpu_model. |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7871 | llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7872 | |
| 7873 | // Calculate the index needed to access the correct field based on the |
| 7874 | // range. Also adjust the expected value. |
| 7875 | unsigned Index; |
| 7876 | unsigned Value; |
Erich Keane | 8202521 | 2017-11-15 00:11:24 +0000 | [diff] [blame] | 7877 | std::tie(Index, Value) = StringSwitch<std::pair<unsigned, unsigned>>(CPUStr) |
| 7878 | #define X86_VENDOR(ENUM, STRING) \ |
| 7879 | .Case(STRING, {0u, static_cast<unsigned>(llvm::X86::ENUM)}) |
| 7880 | #define X86_CPU_TYPE_COMPAT_WITH_ALIAS(ARCHNAME, ENUM, STR, ALIAS) \ |
| 7881 | .Cases(STR, ALIAS, {1u, static_cast<unsigned>(llvm::X86::ENUM)}) |
| 7882 | #define X86_CPU_TYPE_COMPAT(ARCHNAME, ENUM, STR) \ |
| 7883 | .Case(STR, {1u, static_cast<unsigned>(llvm::X86::ENUM)}) |
| 7884 | #define X86_CPU_SUBTYPE_COMPAT(ARCHNAME, ENUM, STR) \ |
| 7885 | .Case(STR, {2u, static_cast<unsigned>(llvm::X86::ENUM)}) |
| 7886 | #include "llvm/Support/X86TargetParser.def" |
| 7887 | .Default({0, 0}); |
| 7888 | assert(Value != 0 && "Invalid CPUStr passed to CpuIs"); |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7889 | |
| 7890 | // Grab the appropriate field from __cpu_model. |
Erich Keane | 8202521 | 2017-11-15 00:11:24 +0000 | [diff] [blame] | 7891 | llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0), |
| 7892 | ConstantInt::get(Int32Ty, Index)}; |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7893 | llvm::Value *CpuValue = Builder.CreateGEP(STy, CpuModel, Idxs); |
| 7894 | CpuValue = Builder.CreateAlignedLoad(CpuValue, CharUnits::fromQuantity(4)); |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7895 | |
| 7896 | // Check the value of the field against the requested value. |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7897 | return Builder.CreateICmpEQ(CpuValue, |
Craig Topper | 699ae0c | 2017-08-10 20:28:30 +0000 | [diff] [blame] | 7898 | llvm::ConstantInt::get(Int32Ty, Value)); |
| 7899 | } |
| 7900 | |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7901 | Value *CodeGenFunction::EmitX86CpuSupports(const CallExpr *E) { |
| 7902 | const Expr *FeatureExpr = E->getArg(0)->IgnoreParenCasts(); |
| 7903 | StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString(); |
| 7904 | return EmitX86CpuSupports(FeatureStr); |
| 7905 | } |
| 7906 | |
| 7907 | Value *CodeGenFunction::EmitX86CpuSupports(ArrayRef<StringRef> FeatureStrs) { |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7908 | // Processor features and mapping to processor feature value. |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7909 | |
| 7910 | uint32_t FeaturesMask = 0; |
| 7911 | |
| 7912 | for (const StringRef &FeatureStr : FeatureStrs) { |
Erich Keane | 0a340ab | 2017-11-22 00:54:01 +0000 | [diff] [blame] | 7913 | unsigned Feature = |
| 7914 | StringSwitch<unsigned>(FeatureStr) |
| 7915 | #define X86_FEATURE_COMPAT(VAL, ENUM, STR) .Case(STR, VAL) |
| 7916 | #include "llvm/Support/X86TargetParser.def" |
| 7917 | ; |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7918 | FeaturesMask |= (1U << Feature); |
| 7919 | } |
| 7920 | |
| 7921 | // Matching the struct layout from the compiler-rt/libgcc structure that is |
| 7922 | // filled in: |
| 7923 | // unsigned int __cpu_vendor; |
| 7924 | // unsigned int __cpu_type; |
| 7925 | // unsigned int __cpu_subtype; |
| 7926 | // unsigned int __cpu_features[1]; |
| 7927 | llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty, Int32Ty, |
| 7928 | llvm::ArrayType::get(Int32Ty, 1)); |
| 7929 | |
| 7930 | // Grab the global __cpu_model. |
| 7931 | llvm::Constant *CpuModel = CGM.CreateRuntimeVariable(STy, "__cpu_model"); |
| 7932 | |
| 7933 | // Grab the first (0th) element from the field __cpu_features off of the |
| 7934 | // global in the struct STy. |
| 7935 | Value *Idxs[] = {ConstantInt::get(Int32Ty, 0), ConstantInt::get(Int32Ty, 3), |
| 7936 | ConstantInt::get(Int32Ty, 0)}; |
| 7937 | Value *CpuFeatures = Builder.CreateGEP(STy, CpuModel, Idxs); |
| 7938 | Value *Features = |
| 7939 | Builder.CreateAlignedLoad(CpuFeatures, CharUnits::fromQuantity(4)); |
| 7940 | |
| 7941 | // Check the value of the bit corresponding to the feature requested. |
| 7942 | Value *Bitset = Builder.CreateAnd( |
| 7943 | Features, llvm::ConstantInt::get(Int32Ty, FeaturesMask)); |
| 7944 | return Builder.CreateICmpNE(Bitset, llvm::ConstantInt::get(Int32Ty, 0)); |
| 7945 | } |
| 7946 | |
Erich Keane | 1fe643a | 2017-10-06 16:40:45 +0000 | [diff] [blame] | 7947 | Value *CodeGenFunction::EmitX86CpuInit() { |
| 7948 | llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, |
| 7949 | /*Variadic*/ false); |
| 7950 | llvm::Constant *Func = CGM.CreateRuntimeFunction(FTy, "__cpu_indicator_init"); |
| 7951 | return Builder.CreateCall(Func); |
| 7952 | } |
| 7953 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7954 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 7955 | const CallExpr *E) { |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7956 | if (BuiltinID == X86::BI__builtin_cpu_is) |
| 7957 | return EmitX86CpuIs(E); |
| 7958 | if (BuiltinID == X86::BI__builtin_cpu_supports) |
| 7959 | return EmitX86CpuSupports(E); |
Erich Keane | 1fe643a | 2017-10-06 16:40:45 +0000 | [diff] [blame] | 7960 | if (BuiltinID == X86::BI__builtin_cpu_init) |
| 7961 | return EmitX86CpuInit(); |
Erich Keane | 9937b13 | 2017-09-01 19:42:45 +0000 | [diff] [blame] | 7962 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7963 | SmallVector<Value*, 4> Ops; |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 7964 | |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 7965 | // Find out if any arguments are required to be integer constant expressions. |
| 7966 | unsigned ICEArguments = 0; |
| 7967 | ASTContext::GetBuiltinTypeError Error; |
| 7968 | getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); |
| 7969 | assert(Error == ASTContext::GE_None && "Should not codegen an error"); |
| 7970 | |
| 7971 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { |
| 7972 | // If this is a normal argument, just emit it as a scalar. |
| 7973 | if ((ICEArguments & (1 << i)) == 0) { |
| 7974 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 7975 | continue; |
| 7976 | } |
| 7977 | |
| 7978 | // If this is required to be a constant, constant fold it so that we know |
| 7979 | // that the generated intrinsic gets a ConstantInt. |
| 7980 | llvm::APSInt Result; |
| 7981 | bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext()); |
| 7982 | assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 7983 | Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result)); |
Chris Lattner | 64d7f2a | 2010-10-02 00:09:12 +0000 | [diff] [blame] | 7984 | } |
Anders Carlsson | 4d3094a | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 7985 | |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 7986 | // These exist so that the builtin that takes an immediate can be bounds |
| 7987 | // checked by clang to avoid passing bad immediates to the backend. Since |
| 7988 | // AVX has a larger immediate than SSE we would need separate builtins to |
| 7989 | // do the different bounds checking. Rather than create a clang specific |
| 7990 | // SSE only builtin, this implements eight separate builtins to match gcc |
| 7991 | // implementation. |
| 7992 | auto getCmpIntrinsicCall = [this, &Ops](Intrinsic::ID ID, unsigned Imm) { |
| 7993 | Ops.push_back(llvm::ConstantInt::get(Int8Ty, Imm)); |
| 7994 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 7995 | return Builder.CreateCall(F, Ops); |
| 7996 | }; |
| 7997 | |
| 7998 | // For the vector forms of FP comparisons, translate the builtins directly to |
| 7999 | // IR. |
| 8000 | // TODO: The builtins could be removed if the SSE header files used vector |
| 8001 | // extension comparisons directly (vector ordered/unordered may need |
| 8002 | // additional support via __builtin_isnan()). |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8003 | auto getVectorFCmpIR = [this, &Ops](CmpInst::Predicate Pred) { |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8004 | Value *Cmp = Builder.CreateFCmp(Pred, Ops[0], Ops[1]); |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8005 | llvm::VectorType *FPVecTy = cast<llvm::VectorType>(Ops[0]->getType()); |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8006 | llvm::VectorType *IntVecTy = llvm::VectorType::getInteger(FPVecTy); |
| 8007 | Value *Sext = Builder.CreateSExt(Cmp, IntVecTy); |
| 8008 | return Builder.CreateBitCast(Sext, FPVecTy); |
| 8009 | }; |
| 8010 | |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 8011 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 8012 | default: return nullptr; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 8013 | case X86::BI_mm_prefetch: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8014 | Value *Address = Ops[0]; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 8015 | Value *RW = ConstantInt::get(Int32Ty, 0); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8016 | Value *Locality = Ops[1]; |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 8017 | Value *Data = ConstantInt::get(Int32Ty, 1); |
| 8018 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 8019 | return Builder.CreateCall(F, {Address, RW, Locality, Data}); |
Warren Hunt | 20e4a5d | 2014-02-21 23:08:53 +0000 | [diff] [blame] | 8020 | } |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 8021 | case X86::BI_mm_clflush: { |
| 8022 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush), |
| 8023 | Ops[0]); |
| 8024 | } |
| 8025 | case X86::BI_mm_lfence: { |
| 8026 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_lfence)); |
| 8027 | } |
| 8028 | case X86::BI_mm_mfence: { |
| 8029 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_mfence)); |
| 8030 | } |
| 8031 | case X86::BI_mm_sfence: { |
| 8032 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_sfence)); |
| 8033 | } |
| 8034 | case X86::BI_mm_pause: { |
| 8035 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_pause)); |
| 8036 | } |
| 8037 | case X86::BI__rdtsc: { |
| 8038 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_rdtsc)); |
| 8039 | } |
Simon Pilgrim | 5aba992 | 2015-08-26 21:17:12 +0000 | [diff] [blame] | 8040 | case X86::BI__builtin_ia32_undef128: |
| 8041 | case X86::BI__builtin_ia32_undef256: |
| 8042 | case X86::BI__builtin_ia32_undef512: |
Sanjay Patel | e795daa | 2017-03-12 19:15:10 +0000 | [diff] [blame] | 8043 | // The x86 definition of "undef" is not the same as the LLVM definition |
| 8044 | // (PR32176). We leave optimizing away an unnecessary zero constant to the |
| 8045 | // IR optimizer and backend. |
| 8046 | // TODO: If we had a "freeze" IR instruction to generate a fixed undef |
| 8047 | // value, we should use that here instead of a zero. |
| 8048 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Bill Wendling | 65b2a96 | 2010-10-09 08:47:25 +0000 | [diff] [blame] | 8049 | case X86::BI__builtin_ia32_vec_init_v8qi: |
| 8050 | case X86::BI__builtin_ia32_vec_init_v4hi: |
| 8051 | case X86::BI__builtin_ia32_vec_init_v2si: |
| 8052 | return Builder.CreateBitCast(BuildVector(Ops), |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 8053 | llvm::Type::getX86_MMXTy(getLLVMContext())); |
Argyrios Kyrtzidis | 073c9cb | 2010-10-10 03:19:11 +0000 | [diff] [blame] | 8054 | case X86::BI__builtin_ia32_vec_ext_v2si: |
| 8055 | return Builder.CreateExtractElement(Ops[0], |
| 8056 | llvm::ConstantInt::get(Ops[1]->getType(), 0)); |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 8057 | case X86::BI_mm_setcsr: |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8058 | case X86::BI__builtin_ia32_ldmxcsr: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8059 | Address Tmp = CreateMemTemp(E->getArg(0)->getType()); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8060 | Builder.CreateStore(Ops[0], Tmp); |
| 8061 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8062 | Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8063 | } |
Albert Gutowski | 727ab8a | 2016-09-14 21:19:43 +0000 | [diff] [blame] | 8064 | case X86::BI_mm_getcsr: |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8065 | case X86::BI__builtin_ia32_stmxcsr: { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8066 | Address Tmp = CreateMemTemp(E->getType()); |
Ted Kremenek | c14efa7 | 2011-08-17 21:04:19 +0000 | [diff] [blame] | 8067 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8068 | Builder.CreateBitCast(Tmp.getPointer(), Int8PtrTy)); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8069 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 8070 | } |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 8071 | case X86::BI__builtin_ia32_xsave: |
| 8072 | case X86::BI__builtin_ia32_xsave64: |
| 8073 | case X86::BI__builtin_ia32_xrstor: |
| 8074 | case X86::BI__builtin_ia32_xrstor64: |
| 8075 | case X86::BI__builtin_ia32_xsaveopt: |
| 8076 | case X86::BI__builtin_ia32_xsaveopt64: |
| 8077 | case X86::BI__builtin_ia32_xrstors: |
| 8078 | case X86::BI__builtin_ia32_xrstors64: |
| 8079 | case X86::BI__builtin_ia32_xsavec: |
| 8080 | case X86::BI__builtin_ia32_xsavec64: |
| 8081 | case X86::BI__builtin_ia32_xsaves: |
Reid Kleckner | 66e7717 | 2016-08-16 16:04:14 +0000 | [diff] [blame] | 8082 | case X86::BI__builtin_ia32_xsaves64: { |
Amjad Aboud | 2b9b8a5 | 2015-10-13 12:29:35 +0000 | [diff] [blame] | 8083 | Intrinsic::ID ID; |
| 8084 | #define INTRINSIC_X86_XSAVE_ID(NAME) \ |
| 8085 | case X86::BI__builtin_ia32_##NAME: \ |
| 8086 | ID = Intrinsic::x86_##NAME; \ |
| 8087 | break |
| 8088 | switch (BuiltinID) { |
| 8089 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 8090 | INTRINSIC_X86_XSAVE_ID(xsave); |
| 8091 | INTRINSIC_X86_XSAVE_ID(xsave64); |
| 8092 | INTRINSIC_X86_XSAVE_ID(xrstor); |
| 8093 | INTRINSIC_X86_XSAVE_ID(xrstor64); |
| 8094 | INTRINSIC_X86_XSAVE_ID(xsaveopt); |
| 8095 | INTRINSIC_X86_XSAVE_ID(xsaveopt64); |
| 8096 | INTRINSIC_X86_XSAVE_ID(xrstors); |
| 8097 | INTRINSIC_X86_XSAVE_ID(xrstors64); |
| 8098 | INTRINSIC_X86_XSAVE_ID(xsavec); |
| 8099 | INTRINSIC_X86_XSAVE_ID(xsavec64); |
| 8100 | INTRINSIC_X86_XSAVE_ID(xsaves); |
| 8101 | INTRINSIC_X86_XSAVE_ID(xsaves64); |
| 8102 | } |
| 8103 | #undef INTRINSIC_X86_XSAVE_ID |
| 8104 | Value *Mhi = Builder.CreateTrunc( |
| 8105 | Builder.CreateLShr(Ops[1], ConstantInt::get(Int64Ty, 32)), Int32Ty); |
| 8106 | Value *Mlo = Builder.CreateTrunc(Ops[1], Int32Ty); |
| 8107 | Ops[1] = Mhi; |
| 8108 | Ops.push_back(Mlo); |
| 8109 | return Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 8110 | } |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 8111 | case X86::BI__builtin_ia32_storedqudi128_mask: |
| 8112 | case X86::BI__builtin_ia32_storedqusi128_mask: |
| 8113 | case X86::BI__builtin_ia32_storedquhi128_mask: |
| 8114 | case X86::BI__builtin_ia32_storedquqi128_mask: |
| 8115 | case X86::BI__builtin_ia32_storeupd128_mask: |
| 8116 | case X86::BI__builtin_ia32_storeups128_mask: |
| 8117 | case X86::BI__builtin_ia32_storedqudi256_mask: |
| 8118 | case X86::BI__builtin_ia32_storedqusi256_mask: |
| 8119 | case X86::BI__builtin_ia32_storedquhi256_mask: |
| 8120 | case X86::BI__builtin_ia32_storedquqi256_mask: |
| 8121 | case X86::BI__builtin_ia32_storeupd256_mask: |
| 8122 | case X86::BI__builtin_ia32_storeups256_mask: |
| 8123 | case X86::BI__builtin_ia32_storedqudi512_mask: |
| 8124 | case X86::BI__builtin_ia32_storedqusi512_mask: |
| 8125 | case X86::BI__builtin_ia32_storedquhi512_mask: |
| 8126 | case X86::BI__builtin_ia32_storedquqi512_mask: |
| 8127 | case X86::BI__builtin_ia32_storeupd512_mask: |
| 8128 | case X86::BI__builtin_ia32_storeups512_mask: |
| 8129 | return EmitX86MaskedStore(*this, Ops, 1); |
| 8130 | |
Ayman Musa | e60a41c | 2016-11-08 12:00:30 +0000 | [diff] [blame] | 8131 | case X86::BI__builtin_ia32_storess128_mask: |
| 8132 | case X86::BI__builtin_ia32_storesd128_mask: { |
| 8133 | return EmitX86MaskedStore(*this, Ops, 16); |
| 8134 | } |
Craig Topper | b846d1f | 2017-12-16 06:02:31 +0000 | [diff] [blame] | 8135 | case X86::BI__builtin_ia32_vpopcntd_128: |
| 8136 | case X86::BI__builtin_ia32_vpopcntq_128: |
| 8137 | case X86::BI__builtin_ia32_vpopcntd_256: |
| 8138 | case X86::BI__builtin_ia32_vpopcntq_256: |
Oren Ben Simhon | 140c1fb | 2017-05-25 13:44:11 +0000 | [diff] [blame] | 8139 | case X86::BI__builtin_ia32_vpopcntd_512: |
| 8140 | case X86::BI__builtin_ia32_vpopcntq_512: { |
| 8141 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8142 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 8143 | return Builder.CreateCall(F, Ops); |
| 8144 | } |
Michael Zuckerman | 755a13d | 2017-04-04 13:29:53 +0000 | [diff] [blame] | 8145 | case X86::BI__builtin_ia32_cvtmask2b128: |
| 8146 | case X86::BI__builtin_ia32_cvtmask2b256: |
| 8147 | case X86::BI__builtin_ia32_cvtmask2b512: |
| 8148 | case X86::BI__builtin_ia32_cvtmask2w128: |
| 8149 | case X86::BI__builtin_ia32_cvtmask2w256: |
| 8150 | case X86::BI__builtin_ia32_cvtmask2w512: |
| 8151 | case X86::BI__builtin_ia32_cvtmask2d128: |
| 8152 | case X86::BI__builtin_ia32_cvtmask2d256: |
| 8153 | case X86::BI__builtin_ia32_cvtmask2d512: |
| 8154 | case X86::BI__builtin_ia32_cvtmask2q128: |
| 8155 | case X86::BI__builtin_ia32_cvtmask2q256: |
| 8156 | case X86::BI__builtin_ia32_cvtmask2q512: |
| 8157 | return EmitX86SExtMask(*this, Ops[0], ConvertType(E->getType())); |
| 8158 | |
Craig Topper | 6e891fb | 2016-05-31 01:50:10 +0000 | [diff] [blame] | 8159 | case X86::BI__builtin_ia32_movdqa32store128_mask: |
| 8160 | case X86::BI__builtin_ia32_movdqa64store128_mask: |
| 8161 | case X86::BI__builtin_ia32_storeaps128_mask: |
| 8162 | case X86::BI__builtin_ia32_storeapd128_mask: |
| 8163 | case X86::BI__builtin_ia32_movdqa32store256_mask: |
| 8164 | case X86::BI__builtin_ia32_movdqa64store256_mask: |
| 8165 | case X86::BI__builtin_ia32_storeaps256_mask: |
| 8166 | case X86::BI__builtin_ia32_storeapd256_mask: |
| 8167 | case X86::BI__builtin_ia32_movdqa32store512_mask: |
| 8168 | case X86::BI__builtin_ia32_movdqa64store512_mask: |
| 8169 | case X86::BI__builtin_ia32_storeaps512_mask: |
| 8170 | case X86::BI__builtin_ia32_storeapd512_mask: { |
| 8171 | unsigned Align = |
| 8172 | getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity(); |
| 8173 | return EmitX86MaskedStore(*this, Ops, Align); |
| 8174 | } |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 8175 | case X86::BI__builtin_ia32_loadups128_mask: |
| 8176 | case X86::BI__builtin_ia32_loadups256_mask: |
| 8177 | case X86::BI__builtin_ia32_loadups512_mask: |
| 8178 | case X86::BI__builtin_ia32_loadupd128_mask: |
| 8179 | case X86::BI__builtin_ia32_loadupd256_mask: |
| 8180 | case X86::BI__builtin_ia32_loadupd512_mask: |
| 8181 | case X86::BI__builtin_ia32_loaddquqi128_mask: |
| 8182 | case X86::BI__builtin_ia32_loaddquqi256_mask: |
| 8183 | case X86::BI__builtin_ia32_loaddquqi512_mask: |
| 8184 | case X86::BI__builtin_ia32_loaddquhi128_mask: |
| 8185 | case X86::BI__builtin_ia32_loaddquhi256_mask: |
| 8186 | case X86::BI__builtin_ia32_loaddquhi512_mask: |
| 8187 | case X86::BI__builtin_ia32_loaddqusi128_mask: |
| 8188 | case X86::BI__builtin_ia32_loaddqusi256_mask: |
| 8189 | case X86::BI__builtin_ia32_loaddqusi512_mask: |
| 8190 | case X86::BI__builtin_ia32_loaddqudi128_mask: |
| 8191 | case X86::BI__builtin_ia32_loaddqudi256_mask: |
| 8192 | case X86::BI__builtin_ia32_loaddqudi512_mask: |
| 8193 | return EmitX86MaskedLoad(*this, Ops, 1); |
| 8194 | |
Ayman Musa | e60a41c | 2016-11-08 12:00:30 +0000 | [diff] [blame] | 8195 | case X86::BI__builtin_ia32_loadss128_mask: |
| 8196 | case X86::BI__builtin_ia32_loadsd128_mask: |
| 8197 | return EmitX86MaskedLoad(*this, Ops, 16); |
| 8198 | |
Craig Topper | 4b060e3 | 2016-05-31 06:58:07 +0000 | [diff] [blame] | 8199 | case X86::BI__builtin_ia32_loadaps128_mask: |
| 8200 | case X86::BI__builtin_ia32_loadaps256_mask: |
| 8201 | case X86::BI__builtin_ia32_loadaps512_mask: |
| 8202 | case X86::BI__builtin_ia32_loadapd128_mask: |
| 8203 | case X86::BI__builtin_ia32_loadapd256_mask: |
| 8204 | case X86::BI__builtin_ia32_loadapd512_mask: |
| 8205 | case X86::BI__builtin_ia32_movdqa32load128_mask: |
| 8206 | case X86::BI__builtin_ia32_movdqa32load256_mask: |
| 8207 | case X86::BI__builtin_ia32_movdqa32load512_mask: |
| 8208 | case X86::BI__builtin_ia32_movdqa64load128_mask: |
| 8209 | case X86::BI__builtin_ia32_movdqa64load256_mask: |
| 8210 | case X86::BI__builtin_ia32_movdqa64load512_mask: { |
| 8211 | unsigned Align = |
| 8212 | getContext().getTypeAlignInChars(E->getArg(1)->getType()).getQuantity(); |
| 8213 | return EmitX86MaskedLoad(*this, Ops, Align); |
| 8214 | } |
Simon Pilgrim | 2d85173 | 2016-07-22 13:58:56 +0000 | [diff] [blame] | 8215 | |
| 8216 | case X86::BI__builtin_ia32_vbroadcastf128_pd256: |
| 8217 | case X86::BI__builtin_ia32_vbroadcastf128_ps256: { |
| 8218 | llvm::Type *DstTy = ConvertType(E->getType()); |
Chandler Carruth | 4c5e8cc | 2016-08-10 07:32:47 +0000 | [diff] [blame] | 8219 | return EmitX86SubVectorBroadcast(*this, Ops, DstTy, 128, 1); |
Simon Pilgrim | 2d85173 | 2016-07-22 13:58:56 +0000 | [diff] [blame] | 8220 | } |
| 8221 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8222 | case X86::BI__builtin_ia32_storehps: |
| 8223 | case X86::BI__builtin_ia32_storelps: { |
Chris Lattner | 5e016ae | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 8224 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(Int64Ty); |
| 8225 | llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8226 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8227 | // cast val v2i64 |
| 8228 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8229 | |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8230 | // extract (0, 1) |
| 8231 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
Michael J. Spencer | dd59775 | 2014-05-31 00:22:12 +0000 | [diff] [blame] | 8232 | llvm::Value *Idx = llvm::ConstantInt::get(SizeTy, Index); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8233 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 8234 | |
| 8235 | // cast pointer to i64 & store |
| 8236 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8237 | return Builder.CreateDefaultAlignedStore(Ops[1], Ops[0]); |
Nate Begeman | 91f40e3 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 8238 | } |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8239 | case X86::BI__builtin_ia32_palignr128: |
Craig Topper | f51cc07 | 2016-06-06 06:13:01 +0000 | [diff] [blame] | 8240 | case X86::BI__builtin_ia32_palignr256: |
Craig Topper | f51cc07 | 2016-06-06 06:13:01 +0000 | [diff] [blame] | 8241 | case X86::BI__builtin_ia32_palignr512_mask: { |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8242 | unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 8243 | |
Craig Topper | f2f1a09 | 2016-07-08 02:17:35 +0000 | [diff] [blame] | 8244 | unsigned NumElts = Ops[0]->getType()->getVectorNumElements(); |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8245 | assert(NumElts % 16 == 0); |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8246 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8247 | // If palignr is shifting the pair of vectors more than the size of two |
| 8248 | // lanes, emit zero. |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 8249 | if (ShiftVal >= 32) |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8250 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 8251 | |
Craig Topper | 480e2b6 | 2015-02-17 06:37:58 +0000 | [diff] [blame] | 8252 | // 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] | 8253 | // but less than two lanes, convert to shifting in zeroes. |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 8254 | if (ShiftVal > 16) { |
| 8255 | ShiftVal -= 16; |
Benjamin Kramer | b596056 | 2015-07-20 15:31:17 +0000 | [diff] [blame] | 8256 | Ops[1] = Ops[0]; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 8257 | Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType()); |
Craig Topper | 94aba2c | 2011-12-19 07:03:25 +0000 | [diff] [blame] | 8258 | } |
| 8259 | |
Craig Topper | d1cb4ce | 2016-06-12 00:41:24 +0000 | [diff] [blame] | 8260 | uint32_t Indices[64]; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 8261 | // 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] | 8262 | for (unsigned l = 0; l != NumElts; l += 16) { |
| 8263 | for (unsigned i = 0; i != 16; ++i) { |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 8264 | unsigned Idx = ShiftVal + i; |
Craig Topper | b8b4b7e | 2016-05-29 07:06:02 +0000 | [diff] [blame] | 8265 | if (Idx >= 16) |
| 8266 | Idx += NumElts - 16; // End of lane, switch operand. |
Benjamin Kramer | c385a80 | 2015-07-28 15:40:11 +0000 | [diff] [blame] | 8267 | Indices[l + i] = Idx + l; |
Craig Topper | 96f9a57 | 2015-02-17 07:18:01 +0000 | [diff] [blame] | 8268 | } |
| 8269 | } |
| 8270 | |
Craig Topper | f51cc07 | 2016-06-06 06:13:01 +0000 | [diff] [blame] | 8271 | Value *Align = Builder.CreateShuffleVector(Ops[1], Ops[0], |
| 8272 | makeArrayRef(Indices, NumElts), |
| 8273 | "palignr"); |
| 8274 | |
| 8275 | // If this isn't a masked builtin, just return the align operation. |
| 8276 | if (Ops.size() == 3) |
| 8277 | return Align; |
| 8278 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 8279 | return EmitX86Select(*this, Ops[4], Align, Ops[3]); |
| 8280 | } |
| 8281 | |
Craig Topper | 8cd7b0c | 2017-09-15 23:00:59 +0000 | [diff] [blame] | 8282 | case X86::BI__builtin_ia32_vperm2f128_pd256: |
| 8283 | case X86::BI__builtin_ia32_vperm2f128_ps256: |
| 8284 | case X86::BI__builtin_ia32_vperm2f128_si256: |
| 8285 | case X86::BI__builtin_ia32_permti256: { |
| 8286 | unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
| 8287 | unsigned NumElts = Ops[0]->getType()->getVectorNumElements(); |
| 8288 | |
| 8289 | // This takes a very simple approach since there are two lanes and a |
| 8290 | // shuffle can have 2 inputs. So we reserve the first input for the first |
| 8291 | // lane and the second input for the second lane. This may result in |
| 8292 | // duplicate sources, but this can be dealt with in the backend. |
| 8293 | |
| 8294 | Value *OutOps[2]; |
| 8295 | uint32_t Indices[8]; |
| 8296 | for (unsigned l = 0; l != 2; ++l) { |
| 8297 | // Determine the source for this lane. |
| 8298 | if (Imm & (1 << ((l * 4) + 3))) |
| 8299 | OutOps[l] = llvm::ConstantAggregateZero::get(Ops[0]->getType()); |
| 8300 | else if (Imm & (1 << ((l * 4) + 1))) |
| 8301 | OutOps[l] = Ops[1]; |
| 8302 | else |
| 8303 | OutOps[l] = Ops[0]; |
| 8304 | |
| 8305 | for (unsigned i = 0; i != NumElts/2; ++i) { |
| 8306 | // Start with ith element of the source for this lane. |
| 8307 | unsigned Idx = (l * NumElts) + i; |
| 8308 | // If bit 0 of the immediate half is set, switch to the high half of |
| 8309 | // the source. |
| 8310 | if (Imm & (1 << (l * 4))) |
| 8311 | Idx += NumElts/2; |
| 8312 | Indices[(l * (NumElts/2)) + i] = Idx; |
| 8313 | } |
| 8314 | } |
| 8315 | |
| 8316 | return Builder.CreateShuffleVector(OutOps[0], OutOps[1], |
| 8317 | makeArrayRef(Indices, NumElts), |
| 8318 | "vperm"); |
| 8319 | } |
| 8320 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 8321 | case X86::BI__builtin_ia32_movnti: |
Simon Pilgrim | e47f2cd0 | 2016-11-11 14:38:34 +0000 | [diff] [blame] | 8322 | case X86::BI__builtin_ia32_movnti64: |
Simon Pilgrim | d39d026 | 2016-06-17 14:28:16 +0000 | [diff] [blame] | 8323 | case X86::BI__builtin_ia32_movntsd: |
| 8324 | case X86::BI__builtin_ia32_movntss: { |
| 8325 | llvm::MDNode *Node = llvm::MDNode::get( |
| 8326 | getLLVMContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1))); |
| 8327 | |
Simon Pilgrim | e47f2cd0 | 2016-11-11 14:38:34 +0000 | [diff] [blame] | 8328 | Value *Ptr = Ops[0]; |
| 8329 | Value *Src = Ops[1]; |
| 8330 | |
Simon Pilgrim | d39d026 | 2016-06-17 14:28:16 +0000 | [diff] [blame] | 8331 | // Extract the 0'th element of the source vector. |
Simon Pilgrim | e47f2cd0 | 2016-11-11 14:38:34 +0000 | [diff] [blame] | 8332 | if (BuiltinID == X86::BI__builtin_ia32_movntsd || |
| 8333 | BuiltinID == X86::BI__builtin_ia32_movntss) |
| 8334 | Src = Builder.CreateExtractElement(Src, (uint64_t)0, "extract"); |
Simon Pilgrim | d39d026 | 2016-06-17 14:28:16 +0000 | [diff] [blame] | 8335 | |
| 8336 | // Convert the type of the pointer to a pointer to the stored type. |
Simon Pilgrim | e47f2cd0 | 2016-11-11 14:38:34 +0000 | [diff] [blame] | 8337 | Value *BC = Builder.CreateBitCast( |
| 8338 | Ptr, llvm::PointerType::getUnqual(Src->getType()), "cast"); |
Simon Pilgrim | d39d026 | 2016-06-17 14:28:16 +0000 | [diff] [blame] | 8339 | |
| 8340 | // Unaligned nontemporal store of the scalar value. |
Simon Pilgrim | e47f2cd0 | 2016-11-11 14:38:34 +0000 | [diff] [blame] | 8341 | StoreInst *SI = Builder.CreateDefaultAlignedStore(Src, BC); |
Simon Pilgrim | d39d026 | 2016-06-17 14:28:16 +0000 | [diff] [blame] | 8342 | SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); |
| 8343 | SI->setAlignment(1); |
| 8344 | return SI; |
| 8345 | } |
| 8346 | |
Simon Pilgrim | 532de1c | 2016-06-13 10:05:19 +0000 | [diff] [blame] | 8347 | case X86::BI__builtin_ia32_selectb_128: |
Igor Breger | aadb876 | 2016-06-08 13:59:20 +0000 | [diff] [blame] | 8348 | case X86::BI__builtin_ia32_selectb_256: |
| 8349 | case X86::BI__builtin_ia32_selectb_512: |
| 8350 | case X86::BI__builtin_ia32_selectw_128: |
| 8351 | case X86::BI__builtin_ia32_selectw_256: |
| 8352 | case X86::BI__builtin_ia32_selectw_512: |
| 8353 | case X86::BI__builtin_ia32_selectd_128: |
| 8354 | case X86::BI__builtin_ia32_selectd_256: |
| 8355 | case X86::BI__builtin_ia32_selectd_512: |
| 8356 | case X86::BI__builtin_ia32_selectq_128: |
| 8357 | case X86::BI__builtin_ia32_selectq_256: |
| 8358 | case X86::BI__builtin_ia32_selectq_512: |
| 8359 | case X86::BI__builtin_ia32_selectps_128: |
| 8360 | case X86::BI__builtin_ia32_selectps_256: |
| 8361 | case X86::BI__builtin_ia32_selectps_512: |
| 8362 | case X86::BI__builtin_ia32_selectpd_128: |
| 8363 | case X86::BI__builtin_ia32_selectpd_256: |
| 8364 | case X86::BI__builtin_ia32_selectpd_512: |
Craig Topper | c144297 | 2016-06-09 05:15:00 +0000 | [diff] [blame] | 8365 | return EmitX86Select(*this, Ops[0], Ops[1], Ops[2]); |
Craig Topper | d1691c7 | 2016-06-22 04:47:58 +0000 | [diff] [blame] | 8366 | case X86::BI__builtin_ia32_cmpb128_mask: |
| 8367 | case X86::BI__builtin_ia32_cmpb256_mask: |
| 8368 | case X86::BI__builtin_ia32_cmpb512_mask: |
| 8369 | case X86::BI__builtin_ia32_cmpw128_mask: |
| 8370 | case X86::BI__builtin_ia32_cmpw256_mask: |
| 8371 | case X86::BI__builtin_ia32_cmpw512_mask: |
| 8372 | case X86::BI__builtin_ia32_cmpd128_mask: |
| 8373 | case X86::BI__builtin_ia32_cmpd256_mask: |
| 8374 | case X86::BI__builtin_ia32_cmpd512_mask: |
| 8375 | case X86::BI__builtin_ia32_cmpq128_mask: |
| 8376 | case X86::BI__builtin_ia32_cmpq256_mask: |
| 8377 | case X86::BI__builtin_ia32_cmpq512_mask: { |
| 8378 | unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7; |
| 8379 | return EmitX86MaskedCompare(*this, CC, true, Ops); |
| 8380 | } |
| 8381 | case X86::BI__builtin_ia32_ucmpb128_mask: |
| 8382 | case X86::BI__builtin_ia32_ucmpb256_mask: |
| 8383 | case X86::BI__builtin_ia32_ucmpb512_mask: |
| 8384 | case X86::BI__builtin_ia32_ucmpw128_mask: |
| 8385 | case X86::BI__builtin_ia32_ucmpw256_mask: |
| 8386 | case X86::BI__builtin_ia32_ucmpw512_mask: |
| 8387 | case X86::BI__builtin_ia32_ucmpd128_mask: |
| 8388 | case X86::BI__builtin_ia32_ucmpd256_mask: |
| 8389 | case X86::BI__builtin_ia32_ucmpd512_mask: |
| 8390 | case X86::BI__builtin_ia32_ucmpq128_mask: |
| 8391 | case X86::BI__builtin_ia32_ucmpq256_mask: |
| 8392 | case X86::BI__builtin_ia32_ucmpq512_mask: { |
| 8393 | unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7; |
| 8394 | return EmitX86MaskedCompare(*this, CC, false, Ops); |
| 8395 | } |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 8396 | |
Craig Topper | 5028ace | 2017-12-16 08:26:22 +0000 | [diff] [blame] | 8397 | case X86::BI__builtin_ia32_kandhi: |
| 8398 | return EmitX86MaskLogic(*this, Instruction::And, 16, Ops); |
| 8399 | case X86::BI__builtin_ia32_kandnhi: |
| 8400 | return EmitX86MaskLogic(*this, Instruction::And, 16, Ops, true); |
| 8401 | case X86::BI__builtin_ia32_korhi: |
| 8402 | return EmitX86MaskLogic(*this, Instruction::Or, 16, Ops); |
| 8403 | case X86::BI__builtin_ia32_kxnorhi: |
| 8404 | return EmitX86MaskLogic(*this, Instruction::Xor, 16, Ops, true); |
| 8405 | case X86::BI__builtin_ia32_kxorhi: |
| 8406 | return EmitX86MaskLogic(*this, Instruction::Xor, 16, Ops); |
| 8407 | case X86::BI__builtin_ia32_knothi: { |
| 8408 | Ops[0] = getMaskVecValue(*this, Ops[0], 16); |
| 8409 | return Builder.CreateBitCast(Builder.CreateNot(Ops[0]), |
| 8410 | Builder.getInt16Ty()); |
| 8411 | } |
| 8412 | |
Craig Topper | 46e7555 | 2016-07-06 04:24:29 +0000 | [diff] [blame] | 8413 | case X86::BI__builtin_ia32_vplzcntd_128_mask: |
| 8414 | case X86::BI__builtin_ia32_vplzcntd_256_mask: |
| 8415 | case X86::BI__builtin_ia32_vplzcntd_512_mask: |
| 8416 | case X86::BI__builtin_ia32_vplzcntq_128_mask: |
| 8417 | case X86::BI__builtin_ia32_vplzcntq_256_mask: |
| 8418 | case X86::BI__builtin_ia32_vplzcntq_512_mask: { |
| 8419 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, Ops[0]->getType()); |
| 8420 | return EmitX86Select(*this, Ops[2], |
| 8421 | Builder.CreateCall(F, {Ops[0],Builder.getInt1(false)}), |
| 8422 | Ops[1]); |
| 8423 | } |
| 8424 | |
Uriel Korach | 3fba3c3 | 2017-09-13 09:02:02 +0000 | [diff] [blame] | 8425 | case X86::BI__builtin_ia32_pabsb128: |
| 8426 | case X86::BI__builtin_ia32_pabsw128: |
| 8427 | case X86::BI__builtin_ia32_pabsd128: |
| 8428 | case X86::BI__builtin_ia32_pabsb256: |
| 8429 | case X86::BI__builtin_ia32_pabsw256: |
| 8430 | case X86::BI__builtin_ia32_pabsd256: |
| 8431 | case X86::BI__builtin_ia32_pabsq128_mask: |
| 8432 | case X86::BI__builtin_ia32_pabsq256_mask: |
| 8433 | case X86::BI__builtin_ia32_pabsb512_mask: |
| 8434 | case X86::BI__builtin_ia32_pabsw512_mask: |
| 8435 | case X86::BI__builtin_ia32_pabsd512_mask: |
| 8436 | case X86::BI__builtin_ia32_pabsq512_mask: |
| 8437 | return EmitX86Abs(*this, Ops); |
| 8438 | |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 8439 | case X86::BI__builtin_ia32_pmaxsb128: |
| 8440 | case X86::BI__builtin_ia32_pmaxsw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8441 | case X86::BI__builtin_ia32_pmaxsd128: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8442 | case X86::BI__builtin_ia32_pmaxsq128_mask: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8443 | case X86::BI__builtin_ia32_pmaxsb256: |
| 8444 | case X86::BI__builtin_ia32_pmaxsw256: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8445 | case X86::BI__builtin_ia32_pmaxsd256: |
| 8446 | case X86::BI__builtin_ia32_pmaxsq256_mask: |
| 8447 | case X86::BI__builtin_ia32_pmaxsb512_mask: |
| 8448 | case X86::BI__builtin_ia32_pmaxsw512_mask: |
| 8449 | case X86::BI__builtin_ia32_pmaxsd512_mask: |
| 8450 | case X86::BI__builtin_ia32_pmaxsq512_mask: |
| 8451 | return EmitX86MinMax(*this, ICmpInst::ICMP_SGT, Ops); |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 8452 | case X86::BI__builtin_ia32_pmaxub128: |
| 8453 | case X86::BI__builtin_ia32_pmaxuw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8454 | case X86::BI__builtin_ia32_pmaxud128: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8455 | case X86::BI__builtin_ia32_pmaxuq128_mask: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8456 | case X86::BI__builtin_ia32_pmaxub256: |
| 8457 | case X86::BI__builtin_ia32_pmaxuw256: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8458 | case X86::BI__builtin_ia32_pmaxud256: |
| 8459 | case X86::BI__builtin_ia32_pmaxuq256_mask: |
| 8460 | case X86::BI__builtin_ia32_pmaxub512_mask: |
| 8461 | case X86::BI__builtin_ia32_pmaxuw512_mask: |
| 8462 | case X86::BI__builtin_ia32_pmaxud512_mask: |
| 8463 | case X86::BI__builtin_ia32_pmaxuq512_mask: |
| 8464 | return EmitX86MinMax(*this, ICmpInst::ICMP_UGT, Ops); |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 8465 | case X86::BI__builtin_ia32_pminsb128: |
| 8466 | case X86::BI__builtin_ia32_pminsw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8467 | case X86::BI__builtin_ia32_pminsd128: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8468 | case X86::BI__builtin_ia32_pminsq128_mask: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8469 | case X86::BI__builtin_ia32_pminsb256: |
| 8470 | case X86::BI__builtin_ia32_pminsw256: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8471 | case X86::BI__builtin_ia32_pminsd256: |
| 8472 | case X86::BI__builtin_ia32_pminsq256_mask: |
| 8473 | case X86::BI__builtin_ia32_pminsb512_mask: |
| 8474 | case X86::BI__builtin_ia32_pminsw512_mask: |
| 8475 | case X86::BI__builtin_ia32_pminsd512_mask: |
| 8476 | case X86::BI__builtin_ia32_pminsq512_mask: |
| 8477 | return EmitX86MinMax(*this, ICmpInst::ICMP_SLT, Ops); |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 8478 | case X86::BI__builtin_ia32_pminub128: |
| 8479 | case X86::BI__builtin_ia32_pminuw128: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8480 | case X86::BI__builtin_ia32_pminud128: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8481 | case X86::BI__builtin_ia32_pminuq128_mask: |
Sanjay Patel | dbd68dd | 2016-06-16 18:45:01 +0000 | [diff] [blame] | 8482 | case X86::BI__builtin_ia32_pminub256: |
| 8483 | case X86::BI__builtin_ia32_pminuw256: |
Craig Topper | 531ce28 | 2016-10-24 04:04:24 +0000 | [diff] [blame] | 8484 | case X86::BI__builtin_ia32_pminud256: |
| 8485 | case X86::BI__builtin_ia32_pminuq256_mask: |
| 8486 | case X86::BI__builtin_ia32_pminub512_mask: |
| 8487 | case X86::BI__builtin_ia32_pminuw512_mask: |
| 8488 | case X86::BI__builtin_ia32_pminud512_mask: |
| 8489 | case X86::BI__builtin_ia32_pminuq512_mask: |
| 8490 | return EmitX86MinMax(*this, ICmpInst::ICMP_ULT, Ops); |
Sanjay Patel | 7495ec0 | 2016-06-15 17:18:50 +0000 | [diff] [blame] | 8491 | |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 8492 | // 3DNow! |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 8493 | case X86::BI__builtin_ia32_pswapdsf: |
| 8494 | case X86::BI__builtin_ia32_pswapdsi: { |
Chandler Carruth | a2a5410 | 2012-02-20 07:35:45 +0000 | [diff] [blame] | 8495 | llvm::Type *MMXTy = llvm::Type::getX86_MMXTy(getLLVMContext()); |
| 8496 | Ops[0] = Builder.CreateBitCast(Ops[0], MMXTy, "cast"); |
Craig Topper | d2f814d | 2015-02-16 21:30:08 +0000 | [diff] [blame] | 8497 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_3dnowa_pswapd); |
| 8498 | return Builder.CreateCall(F, Ops, "pswapd"); |
Michael J. Spencer | 6826eb8 | 2011-04-15 15:07:13 +0000 | [diff] [blame] | 8499 | } |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 8500 | case X86::BI__builtin_ia32_rdrand16_step: |
| 8501 | case X86::BI__builtin_ia32_rdrand32_step: |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 8502 | case X86::BI__builtin_ia32_rdrand64_step: |
| 8503 | case X86::BI__builtin_ia32_rdseed16_step: |
| 8504 | case X86::BI__builtin_ia32_rdseed32_step: |
| 8505 | case X86::BI__builtin_ia32_rdseed64_step: { |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 8506 | Intrinsic::ID ID; |
| 8507 | switch (BuiltinID) { |
| 8508 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 8509 | case X86::BI__builtin_ia32_rdrand16_step: |
| 8510 | ID = Intrinsic::x86_rdrand_16; |
| 8511 | break; |
| 8512 | case X86::BI__builtin_ia32_rdrand32_step: |
| 8513 | ID = Intrinsic::x86_rdrand_32; |
| 8514 | break; |
| 8515 | case X86::BI__builtin_ia32_rdrand64_step: |
| 8516 | ID = Intrinsic::x86_rdrand_64; |
| 8517 | break; |
Michael Liao | ffaae35 | 2013-03-29 05:17:55 +0000 | [diff] [blame] | 8518 | case X86::BI__builtin_ia32_rdseed16_step: |
| 8519 | ID = Intrinsic::x86_rdseed_16; |
| 8520 | break; |
| 8521 | case X86::BI__builtin_ia32_rdseed32_step: |
| 8522 | ID = Intrinsic::x86_rdseed_32; |
| 8523 | break; |
| 8524 | case X86::BI__builtin_ia32_rdseed64_step: |
| 8525 | ID = Intrinsic::x86_rdseed_64; |
| 8526 | break; |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 8527 | } |
| 8528 | |
David Blaikie | 4ba525b | 2015-07-14 17:27:39 +0000 | [diff] [blame] | 8529 | Value *Call = Builder.CreateCall(CGM.getIntrinsic(ID)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 8530 | Builder.CreateDefaultAlignedStore(Builder.CreateExtractValue(Call, 0), |
| 8531 | Ops[0]); |
Benjamin Kramer | a43b699 | 2012-07-12 09:33:03 +0000 | [diff] [blame] | 8532 | return Builder.CreateExtractValue(Call, 1); |
| 8533 | } |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8534 | |
| 8535 | // SSE packed comparison intrinsics |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8536 | case X86::BI__builtin_ia32_cmpeqps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8537 | case X86::BI__builtin_ia32_cmpeqpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8538 | return getVectorFCmpIR(CmpInst::FCMP_OEQ); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8539 | case X86::BI__builtin_ia32_cmpltps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8540 | case X86::BI__builtin_ia32_cmpltpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8541 | return getVectorFCmpIR(CmpInst::FCMP_OLT); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8542 | case X86::BI__builtin_ia32_cmpleps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8543 | case X86::BI__builtin_ia32_cmplepd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8544 | return getVectorFCmpIR(CmpInst::FCMP_OLE); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8545 | case X86::BI__builtin_ia32_cmpunordps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8546 | case X86::BI__builtin_ia32_cmpunordpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8547 | return getVectorFCmpIR(CmpInst::FCMP_UNO); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8548 | case X86::BI__builtin_ia32_cmpneqps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8549 | case X86::BI__builtin_ia32_cmpneqpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8550 | return getVectorFCmpIR(CmpInst::FCMP_UNE); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8551 | case X86::BI__builtin_ia32_cmpnltps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8552 | case X86::BI__builtin_ia32_cmpnltpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8553 | return getVectorFCmpIR(CmpInst::FCMP_UGE); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8554 | case X86::BI__builtin_ia32_cmpnleps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8555 | case X86::BI__builtin_ia32_cmpnlepd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8556 | return getVectorFCmpIR(CmpInst::FCMP_UGT); |
Craig Topper | 925ef0a | 2016-07-08 01:48:44 +0000 | [diff] [blame] | 8557 | case X86::BI__builtin_ia32_cmpordps: |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8558 | case X86::BI__builtin_ia32_cmpordpd: |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8559 | return getVectorFCmpIR(CmpInst::FCMP_ORD); |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 8560 | case X86::BI__builtin_ia32_cmpps: |
| 8561 | case X86::BI__builtin_ia32_cmpps256: |
| 8562 | case X86::BI__builtin_ia32_cmppd: |
| 8563 | case X86::BI__builtin_ia32_cmppd256: { |
| 8564 | unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
| 8565 | // If this one of the SSE immediates, we can use native IR. |
| 8566 | if (CC < 8) { |
| 8567 | FCmpInst::Predicate Pred; |
| 8568 | switch (CC) { |
| 8569 | case 0: Pred = FCmpInst::FCMP_OEQ; break; |
| 8570 | case 1: Pred = FCmpInst::FCMP_OLT; break; |
| 8571 | case 2: Pred = FCmpInst::FCMP_OLE; break; |
| 8572 | case 3: Pred = FCmpInst::FCMP_UNO; break; |
| 8573 | case 4: Pred = FCmpInst::FCMP_UNE; break; |
| 8574 | case 5: Pred = FCmpInst::FCMP_UGE; break; |
| 8575 | case 6: Pred = FCmpInst::FCMP_UGT; break; |
| 8576 | case 7: Pred = FCmpInst::FCMP_ORD; break; |
| 8577 | } |
Craig Topper | 0160063 | 2016-07-08 01:57:24 +0000 | [diff] [blame] | 8578 | return getVectorFCmpIR(Pred); |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 8579 | } |
| 8580 | |
| 8581 | // We can't handle 8-31 immediates with native IR, use the intrinsic. |
Dinar Temirbulatov | 7b22425 | 2017-06-16 12:09:52 +0000 | [diff] [blame] | 8582 | // Except for predicates that create constants. |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 8583 | Intrinsic::ID ID; |
| 8584 | switch (BuiltinID) { |
| 8585 | default: llvm_unreachable("Unsupported intrinsic!"); |
| 8586 | case X86::BI__builtin_ia32_cmpps: |
| 8587 | ID = Intrinsic::x86_sse_cmp_ps; |
| 8588 | break; |
| 8589 | case X86::BI__builtin_ia32_cmpps256: |
Dinar Temirbulatov | 7b22425 | 2017-06-16 12:09:52 +0000 | [diff] [blame] | 8590 | // _CMP_TRUE_UQ, _CMP_TRUE_US produce -1,-1... vector |
| 8591 | // on any input and _CMP_FALSE_OQ, _CMP_FALSE_OS produce 0, 0... |
| 8592 | if (CC == 0xf || CC == 0xb || CC == 0x1b || CC == 0x1f) { |
| 8593 | Value *Constant = (CC == 0xf || CC == 0x1f) ? |
| 8594 | llvm::Constant::getAllOnesValue(Builder.getInt32Ty()) : |
| 8595 | llvm::Constant::getNullValue(Builder.getInt32Ty()); |
| 8596 | Value *Vec = Builder.CreateVectorSplat( |
| 8597 | Ops[0]->getType()->getVectorNumElements(), Constant); |
| 8598 | return Builder.CreateBitCast(Vec, Ops[0]->getType()); |
| 8599 | } |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 8600 | ID = Intrinsic::x86_avx_cmp_ps_256; |
| 8601 | break; |
| 8602 | case X86::BI__builtin_ia32_cmppd: |
| 8603 | ID = Intrinsic::x86_sse2_cmp_pd; |
| 8604 | break; |
| 8605 | case X86::BI__builtin_ia32_cmppd256: |
Dinar Temirbulatov | 7b22425 | 2017-06-16 12:09:52 +0000 | [diff] [blame] | 8606 | // _CMP_TRUE_UQ, _CMP_TRUE_US produce -1,-1... vector |
| 8607 | // on any input and _CMP_FALSE_OQ, _CMP_FALSE_OS produce 0, 0... |
| 8608 | if (CC == 0xf || CC == 0xb || CC == 0x1b || CC == 0x1f) { |
| 8609 | Value *Constant = (CC == 0xf || CC == 0x1f) ? |
| 8610 | llvm::Constant::getAllOnesValue(Builder.getInt64Ty()) : |
| 8611 | llvm::Constant::getNullValue(Builder.getInt64Ty()); |
| 8612 | Value *Vec = Builder.CreateVectorSplat( |
| 8613 | Ops[0]->getType()->getVectorNumElements(), Constant); |
| 8614 | return Builder.CreateBitCast(Vec, Ops[0]->getType()); |
| 8615 | } |
Craig Topper | 425d02d | 2016-07-06 06:27:31 +0000 | [diff] [blame] | 8616 | ID = Intrinsic::x86_avx_cmp_pd_256; |
| 8617 | break; |
| 8618 | } |
| 8619 | |
| 8620 | return Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 8621 | } |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8622 | |
| 8623 | // SSE scalar comparison intrinsics |
| 8624 | case X86::BI__builtin_ia32_cmpeqss: |
| 8625 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 0); |
| 8626 | case X86::BI__builtin_ia32_cmpltss: |
| 8627 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 1); |
| 8628 | case X86::BI__builtin_ia32_cmpless: |
| 8629 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 2); |
| 8630 | case X86::BI__builtin_ia32_cmpunordss: |
| 8631 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 3); |
| 8632 | case X86::BI__builtin_ia32_cmpneqss: |
| 8633 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 4); |
| 8634 | case X86::BI__builtin_ia32_cmpnltss: |
| 8635 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 5); |
| 8636 | case X86::BI__builtin_ia32_cmpnless: |
| 8637 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 6); |
| 8638 | case X86::BI__builtin_ia32_cmpordss: |
| 8639 | return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 7); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8640 | case X86::BI__builtin_ia32_cmpeqsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8641 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 0); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8642 | case X86::BI__builtin_ia32_cmpltsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8643 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 1); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8644 | case X86::BI__builtin_ia32_cmplesd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8645 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 2); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8646 | case X86::BI__builtin_ia32_cmpunordsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8647 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 3); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8648 | case X86::BI__builtin_ia32_cmpneqsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8649 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 4); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8650 | case X86::BI__builtin_ia32_cmpnltsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8651 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 5); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8652 | case X86::BI__builtin_ia32_cmpnlesd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8653 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 6); |
Craig Topper | 2094d8f | 2014-12-27 06:59:57 +0000 | [diff] [blame] | 8654 | case X86::BI__builtin_ia32_cmpordsd: |
Sanjay Patel | 280cfd1 | 2016-06-15 21:20:04 +0000 | [diff] [blame] | 8655 | return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 7); |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 8656 | |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 8657 | case X86::BI__emul: |
| 8658 | case X86::BI__emulu: { |
| 8659 | llvm::Type *Int64Ty = llvm::IntegerType::get(getLLVMContext(), 64); |
| 8660 | bool isSigned = (BuiltinID == X86::BI__emul); |
| 8661 | Value *LHS = Builder.CreateIntCast(Ops[0], Int64Ty, isSigned); |
| 8662 | Value *RHS = Builder.CreateIntCast(Ops[1], Int64Ty, isSigned); |
| 8663 | return Builder.CreateMul(LHS, RHS, "", !isSigned, isSigned); |
| 8664 | } |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 8665 | case X86::BI__mulh: |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 8666 | case X86::BI__umulh: |
| 8667 | case X86::BI_mul128: |
| 8668 | case X86::BI_umul128: { |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 8669 | llvm::Type *ResType = ConvertType(E->getType()); |
| 8670 | llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128); |
| 8671 | |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 8672 | bool IsSigned = (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI_mul128); |
| 8673 | Value *LHS = Builder.CreateIntCast(Ops[0], Int128Ty, IsSigned); |
| 8674 | Value *RHS = Builder.CreateIntCast(Ops[1], Int128Ty, IsSigned); |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 8675 | |
| 8676 | Value *MulResult, *HigherBits; |
| 8677 | if (IsSigned) { |
| 8678 | MulResult = Builder.CreateNSWMul(LHS, RHS); |
| 8679 | HigherBits = Builder.CreateAShr(MulResult, 64); |
| 8680 | } else { |
| 8681 | MulResult = Builder.CreateNUWMul(LHS, RHS); |
| 8682 | HigherBits = Builder.CreateLShr(MulResult, 64); |
| 8683 | } |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 8684 | HigherBits = Builder.CreateIntCast(HigherBits, ResType, IsSigned); |
Albert Gutowski | 7216f17 | 2016-10-10 18:09:27 +0000 | [diff] [blame] | 8685 | |
| 8686 | if (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI__umulh) |
| 8687 | return HigherBits; |
| 8688 | |
| 8689 | Address HighBitsAddress = EmitPointerWithAlignment(E->getArg(2)); |
| 8690 | Builder.CreateStore(HigherBits, HighBitsAddress); |
| 8691 | return Builder.CreateIntCast(MulResult, ResType, IsSigned); |
Albert Gutowski | f3a0bce | 2016-10-04 22:29:49 +0000 | [diff] [blame] | 8692 | } |
Albert Gutowski | fcea61c | 2016-10-10 19:40:51 +0000 | [diff] [blame] | 8693 | |
| 8694 | case X86::BI__faststorefence: { |
| 8695 | return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 8696 | llvm::SyncScope::System); |
Albert Gutowski | fcea61c | 2016-10-10 19:40:51 +0000 | [diff] [blame] | 8697 | } |
| 8698 | case X86::BI_ReadWriteBarrier: |
| 8699 | case X86::BI_ReadBarrier: |
| 8700 | case X86::BI_WriteBarrier: { |
| 8701 | return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, |
Konstantin Zhuravlyov | b0beb30 | 2017-07-11 22:23:37 +0000 | [diff] [blame] | 8702 | llvm::SyncScope::SingleThread); |
Albert Gutowski | fcea61c | 2016-10-10 19:40:51 +0000 | [diff] [blame] | 8703 | } |
Albert Gutowski | 2a0621e | 2016-10-12 22:01:05 +0000 | [diff] [blame] | 8704 | case X86::BI_BitScanForward: |
| 8705 | case X86::BI_BitScanForward64: |
| 8706 | return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanForward, E); |
| 8707 | case X86::BI_BitScanReverse: |
| 8708 | case X86::BI_BitScanReverse64: |
| 8709 | return EmitMSVCBuiltinExpr(MSVCIntrin::_BitScanReverse, E); |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 8710 | |
| 8711 | case X86::BI_InterlockedAnd64: |
| 8712 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedAnd, E); |
| 8713 | case X86::BI_InterlockedExchange64: |
| 8714 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange, E); |
| 8715 | case X86::BI_InterlockedExchangeAdd64: |
| 8716 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchangeAdd, E); |
| 8717 | case X86::BI_InterlockedExchangeSub64: |
| 8718 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchangeSub, E); |
| 8719 | case X86::BI_InterlockedOr64: |
| 8720 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedOr, E); |
| 8721 | case X86::BI_InterlockedXor64: |
| 8722 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedXor, E); |
| 8723 | case X86::BI_InterlockedDecrement64: |
| 8724 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedDecrement, E); |
| 8725 | case X86::BI_InterlockedIncrement64: |
| 8726 | return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedIncrement, E); |
Reid Kleckner | 627f45f | 2017-12-14 19:00:21 +0000 | [diff] [blame] | 8727 | case X86::BI_InterlockedCompareExchange128: { |
| 8728 | // InterlockedCompareExchange128 doesn't directly refer to 128bit ints, |
| 8729 | // instead it takes pointers to 64bit ints for Destination and |
| 8730 | // ComparandResult, and exchange is taken as two 64bit ints (high & low). |
| 8731 | // The previous value is written to ComparandResult, and success is |
| 8732 | // returned. |
| 8733 | |
| 8734 | llvm::Type *Int128Ty = Builder.getInt128Ty(); |
| 8735 | llvm::Type *Int128PtrTy = Int128Ty->getPointerTo(); |
| 8736 | |
| 8737 | Value *Destination = |
| 8738 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), Int128PtrTy); |
| 8739 | Value *ExchangeHigh128 = |
| 8740 | Builder.CreateZExt(EmitScalarExpr(E->getArg(1)), Int128Ty); |
| 8741 | Value *ExchangeLow128 = |
| 8742 | Builder.CreateZExt(EmitScalarExpr(E->getArg(2)), Int128Ty); |
| 8743 | Address ComparandResult( |
| 8744 | Builder.CreateBitCast(EmitScalarExpr(E->getArg(3)), Int128PtrTy), |
| 8745 | getContext().toCharUnitsFromBits(128)); |
| 8746 | |
| 8747 | Value *Exchange = Builder.CreateOr( |
| 8748 | Builder.CreateShl(ExchangeHigh128, 64, "", false, false), |
| 8749 | ExchangeLow128); |
| 8750 | |
| 8751 | Value *Comparand = Builder.CreateLoad(ComparandResult); |
| 8752 | |
| 8753 | AtomicCmpXchgInst *CXI = |
| 8754 | Builder.CreateAtomicCmpXchg(Destination, Comparand, Exchange, |
| 8755 | AtomicOrdering::SequentiallyConsistent, |
| 8756 | AtomicOrdering::SequentiallyConsistent); |
| 8757 | CXI->setVolatile(true); |
| 8758 | |
| 8759 | // Write the result back to the inout pointer. |
| 8760 | Builder.CreateStore(Builder.CreateExtractValue(CXI, 0), ComparandResult); |
| 8761 | |
| 8762 | // Get the success boolean and zero extend it to i8. |
| 8763 | Value *Success = Builder.CreateExtractValue(CXI, 1); |
| 8764 | return Builder.CreateZExt(Success, ConvertType(E->getType())); |
| 8765 | } |
Albert Gutowski | 5e08df0 | 2016-10-13 22:35:07 +0000 | [diff] [blame] | 8766 | |
Albert Gutowski | 397d81b | 2016-10-13 16:03:42 +0000 | [diff] [blame] | 8767 | case X86::BI_AddressOfReturnAddress: { |
| 8768 | Value *F = CGM.getIntrinsic(Intrinsic::addressofreturnaddress); |
| 8769 | return Builder.CreateCall(F); |
| 8770 | } |
Albert Gutowski | 1deab38 | 2016-10-14 17:33:05 +0000 | [diff] [blame] | 8771 | case X86::BI__stosb: { |
| 8772 | // We treat __stosb as a volatile memset - it may not generate "rep stosb" |
| 8773 | // instruction, but it will create a memset that won't be optimized away. |
| 8774 | return Builder.CreateMemSet(Ops[0], Ops[1], Ops[2], 1, true); |
| 8775 | } |
Reid Kleckner | b04cb9a | 2017-03-06 19:43:16 +0000 | [diff] [blame] | 8776 | case X86::BI__ud2: |
| 8777 | // llvm.trap makes a ud2a instruction on x86. |
| 8778 | return EmitTrapCall(Intrinsic::trap); |
| 8779 | case X86::BI__int2c: { |
| 8780 | // This syscall signals a driver assertion failure in x86 NT kernels. |
| 8781 | llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false); |
| 8782 | llvm::InlineAsm *IA = |
| 8783 | llvm::InlineAsm::get(FTy, "int $$0x2c", "", /*SideEffects=*/true); |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 8784 | llvm::AttributeList NoReturnAttr = llvm::AttributeList::get( |
| 8785 | getLLVMContext(), llvm::AttributeList::FunctionIndex, |
| 8786 | llvm::Attribute::NoReturn); |
Reid Kleckner | b04cb9a | 2017-03-06 19:43:16 +0000 | [diff] [blame] | 8787 | CallSite CS = Builder.CreateCall(IA); |
| 8788 | CS.setAttributes(NoReturnAttr); |
| 8789 | return CS.getInstruction(); |
| 8790 | } |
Hans Wennborg | 043f402 | 2017-03-22 19:13:13 +0000 | [diff] [blame] | 8791 | case X86::BI__readfsbyte: |
| 8792 | case X86::BI__readfsword: |
| 8793 | case X86::BI__readfsdword: |
| 8794 | case X86::BI__readfsqword: { |
| 8795 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 8796 | Value *Ptr = Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), |
| 8797 | llvm::PointerType::get(IntTy, 257)); |
| 8798 | LoadInst *Load = Builder.CreateAlignedLoad( |
| 8799 | IntTy, Ptr, getContext().getTypeAlignInChars(E->getType())); |
| 8800 | Load->setVolatile(true); |
| 8801 | return Load; |
| 8802 | } |
| 8803 | case X86::BI__readgsbyte: |
| 8804 | case X86::BI__readgsword: |
| 8805 | case X86::BI__readgsdword: |
| 8806 | case X86::BI__readgsqword: { |
| 8807 | llvm::Type *IntTy = ConvertType(E->getType()); |
| 8808 | Value *Ptr = Builder.CreateIntToPtr(EmitScalarExpr(E->getArg(0)), |
| 8809 | llvm::PointerType::get(IntTy, 256)); |
| 8810 | LoadInst *Load = Builder.CreateAlignedLoad( |
| 8811 | IntTy, Ptr, getContext().getTypeAlignInChars(E->getType())); |
| 8812 | Load->setVolatile(true); |
| 8813 | return Load; |
| 8814 | } |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 8815 | } |
| 8816 | } |
| 8817 | |
Tony Linthicum | 76329bf | 2011-12-12 21:14:55 +0000 | [diff] [blame] | 8818 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 8819 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 13653d7 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 8820 | const CallExpr *E) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8821 | SmallVector<Value*, 4> Ops; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8822 | |
| 8823 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 8824 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 8825 | |
| 8826 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 8827 | |
| 8828 | switch (BuiltinID) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 8829 | default: return nullptr; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8830 | |
Hal Finkel | 65e1e4d | 2015-08-31 23:55:19 +0000 | [diff] [blame] | 8831 | // __builtin_ppc_get_timebase is GCC 4.8+'s PowerPC-specific name for what we |
| 8832 | // call __builtin_readcyclecounter. |
| 8833 | case PPC::BI__builtin_ppc_get_timebase: |
| 8834 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::readcyclecounter)); |
| 8835 | |
Tony Jiang | 6a49aad | 2016-11-15 14:30:56 +0000 | [diff] [blame] | 8836 | // vec_ld, vec_xl_be, vec_lvsl, vec_lvsr |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 8837 | case PPC::BI__builtin_altivec_lvx: |
| 8838 | case PPC::BI__builtin_altivec_lvxl: |
| 8839 | case PPC::BI__builtin_altivec_lvebx: |
| 8840 | case PPC::BI__builtin_altivec_lvehx: |
| 8841 | case PPC::BI__builtin_altivec_lvewx: |
| 8842 | case PPC::BI__builtin_altivec_lvsl: |
| 8843 | case PPC::BI__builtin_altivec_lvsr: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 8844 | case PPC::BI__builtin_vsx_lxvd2x: |
| 8845 | case PPC::BI__builtin_vsx_lxvw4x: |
Tony Jiang | 6a49aad | 2016-11-15 14:30:56 +0000 | [diff] [blame] | 8846 | case PPC::BI__builtin_vsx_lxvd2x_be: |
| 8847 | case PPC::BI__builtin_vsx_lxvw4x_be: |
Zaara Syeda | c1d2952 | 2016-11-15 18:04:13 +0000 | [diff] [blame] | 8848 | case PPC::BI__builtin_vsx_lxvl: |
| 8849 | case PPC::BI__builtin_vsx_lxvll: |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 8850 | { |
Zaara Syeda | c1d2952 | 2016-11-15 18:04:13 +0000 | [diff] [blame] | 8851 | if(BuiltinID == PPC::BI__builtin_vsx_lxvl || |
| 8852 | BuiltinID == PPC::BI__builtin_vsx_lxvll){ |
| 8853 | Ops[0] = Builder.CreateBitCast(Ops[0], Int8PtrTy); |
| 8854 | }else { |
| 8855 | Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); |
| 8856 | Ops[0] = Builder.CreateGEP(Ops[1], Ops[0]); |
| 8857 | Ops.pop_back(); |
| 8858 | } |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 8859 | |
| 8860 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8861 | default: llvm_unreachable("Unsupported ld/lvsl/lvsr intrinsic!"); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 8862 | case PPC::BI__builtin_altivec_lvx: |
| 8863 | ID = Intrinsic::ppc_altivec_lvx; |
| 8864 | break; |
| 8865 | case PPC::BI__builtin_altivec_lvxl: |
| 8866 | ID = Intrinsic::ppc_altivec_lvxl; |
| 8867 | break; |
| 8868 | case PPC::BI__builtin_altivec_lvebx: |
| 8869 | ID = Intrinsic::ppc_altivec_lvebx; |
| 8870 | break; |
| 8871 | case PPC::BI__builtin_altivec_lvehx: |
| 8872 | ID = Intrinsic::ppc_altivec_lvehx; |
| 8873 | break; |
| 8874 | case PPC::BI__builtin_altivec_lvewx: |
| 8875 | ID = Intrinsic::ppc_altivec_lvewx; |
| 8876 | break; |
| 8877 | case PPC::BI__builtin_altivec_lvsl: |
| 8878 | ID = Intrinsic::ppc_altivec_lvsl; |
| 8879 | break; |
| 8880 | case PPC::BI__builtin_altivec_lvsr: |
| 8881 | ID = Intrinsic::ppc_altivec_lvsr; |
| 8882 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 8883 | case PPC::BI__builtin_vsx_lxvd2x: |
| 8884 | ID = Intrinsic::ppc_vsx_lxvd2x; |
| 8885 | break; |
| 8886 | case PPC::BI__builtin_vsx_lxvw4x: |
| 8887 | ID = Intrinsic::ppc_vsx_lxvw4x; |
| 8888 | break; |
Tony Jiang | 6a49aad | 2016-11-15 14:30:56 +0000 | [diff] [blame] | 8889 | case PPC::BI__builtin_vsx_lxvd2x_be: |
| 8890 | ID = Intrinsic::ppc_vsx_lxvd2x_be; |
| 8891 | break; |
| 8892 | case PPC::BI__builtin_vsx_lxvw4x_be: |
| 8893 | ID = Intrinsic::ppc_vsx_lxvw4x_be; |
| 8894 | break; |
Zaara Syeda | c1d2952 | 2016-11-15 18:04:13 +0000 | [diff] [blame] | 8895 | case PPC::BI__builtin_vsx_lxvl: |
| 8896 | ID = Intrinsic::ppc_vsx_lxvl; |
| 8897 | break; |
| 8898 | case PPC::BI__builtin_vsx_lxvll: |
| 8899 | ID = Intrinsic::ppc_vsx_lxvll; |
| 8900 | break; |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 8901 | } |
| 8902 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 8903 | return Builder.CreateCall(F, Ops, ""); |
Anton Korobeynikov | cc50b7d | 2010-06-19 09:47:18 +0000 | [diff] [blame] | 8904 | } |
| 8905 | |
Tony Jiang | 6a49aad | 2016-11-15 14:30:56 +0000 | [diff] [blame] | 8906 | // vec_st, vec_xst_be |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8907 | case PPC::BI__builtin_altivec_stvx: |
| 8908 | case PPC::BI__builtin_altivec_stvxl: |
| 8909 | case PPC::BI__builtin_altivec_stvebx: |
| 8910 | case PPC::BI__builtin_altivec_stvehx: |
| 8911 | case PPC::BI__builtin_altivec_stvewx: |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 8912 | case PPC::BI__builtin_vsx_stxvd2x: |
| 8913 | case PPC::BI__builtin_vsx_stxvw4x: |
Tony Jiang | 6a49aad | 2016-11-15 14:30:56 +0000 | [diff] [blame] | 8914 | case PPC::BI__builtin_vsx_stxvd2x_be: |
| 8915 | case PPC::BI__builtin_vsx_stxvw4x_be: |
Zaara Syeda | c1d2952 | 2016-11-15 18:04:13 +0000 | [diff] [blame] | 8916 | case PPC::BI__builtin_vsx_stxvl: |
| 8917 | case PPC::BI__builtin_vsx_stxvll: |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8918 | { |
Zaara Syeda | c1d2952 | 2016-11-15 18:04:13 +0000 | [diff] [blame] | 8919 | if(BuiltinID == PPC::BI__builtin_vsx_stxvl || |
| 8920 | BuiltinID == PPC::BI__builtin_vsx_stxvll ){ |
| 8921 | Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy); |
| 8922 | }else { |
| 8923 | Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy); |
| 8924 | Ops[1] = Builder.CreateGEP(Ops[2], Ops[1]); |
| 8925 | Ops.pop_back(); |
| 8926 | } |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8927 | |
| 8928 | switch (BuiltinID) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 8929 | default: llvm_unreachable("Unsupported st intrinsic!"); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8930 | case PPC::BI__builtin_altivec_stvx: |
| 8931 | ID = Intrinsic::ppc_altivec_stvx; |
| 8932 | break; |
| 8933 | case PPC::BI__builtin_altivec_stvxl: |
| 8934 | ID = Intrinsic::ppc_altivec_stvxl; |
| 8935 | break; |
| 8936 | case PPC::BI__builtin_altivec_stvebx: |
| 8937 | ID = Intrinsic::ppc_altivec_stvebx; |
| 8938 | break; |
| 8939 | case PPC::BI__builtin_altivec_stvehx: |
| 8940 | ID = Intrinsic::ppc_altivec_stvehx; |
| 8941 | break; |
| 8942 | case PPC::BI__builtin_altivec_stvewx: |
| 8943 | ID = Intrinsic::ppc_altivec_stvewx; |
| 8944 | break; |
Bill Schmidt | 9ec8cea | 2014-11-12 04:19:56 +0000 | [diff] [blame] | 8945 | case PPC::BI__builtin_vsx_stxvd2x: |
| 8946 | ID = Intrinsic::ppc_vsx_stxvd2x; |
| 8947 | break; |
| 8948 | case PPC::BI__builtin_vsx_stxvw4x: |
| 8949 | ID = Intrinsic::ppc_vsx_stxvw4x; |
| 8950 | break; |
Tony Jiang | 6a49aad | 2016-11-15 14:30:56 +0000 | [diff] [blame] | 8951 | case PPC::BI__builtin_vsx_stxvd2x_be: |
| 8952 | ID = Intrinsic::ppc_vsx_stxvd2x_be; |
| 8953 | break; |
| 8954 | case PPC::BI__builtin_vsx_stxvw4x_be: |
| 8955 | ID = Intrinsic::ppc_vsx_stxvw4x_be; |
| 8956 | break; |
Zaara Syeda | c1d2952 | 2016-11-15 18:04:13 +0000 | [diff] [blame] | 8957 | case PPC::BI__builtin_vsx_stxvl: |
| 8958 | ID = Intrinsic::ppc_vsx_stxvl; |
| 8959 | break; |
| 8960 | case PPC::BI__builtin_vsx_stxvll: |
| 8961 | ID = Intrinsic::ppc_vsx_stxvll; |
| 8962 | break; |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8963 | } |
| 8964 | llvm::Function *F = CGM.getIntrinsic(ID); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 8965 | return Builder.CreateCall(F, Ops, ""); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8966 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 8967 | // Square root |
| 8968 | case PPC::BI__builtin_vsx_xvsqrtsp: |
| 8969 | case PPC::BI__builtin_vsx_xvsqrtdp: { |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 8970 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8971 | Value *X = EmitScalarExpr(E->getArg(0)); |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 8972 | ID = Intrinsic::sqrt; |
Nemanja Ivanovic | 2f1f926 | 2015-06-26 19:27:20 +0000 | [diff] [blame] | 8973 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 8974 | return Builder.CreateCall(F, X); |
Chris Lattner | dad4062 | 2010-04-14 03:54:58 +0000 | [diff] [blame] | 8975 | } |
Nemanja Ivanovic | 6c363ed | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 8976 | // Count leading zeros |
| 8977 | case PPC::BI__builtin_altivec_vclzb: |
| 8978 | case PPC::BI__builtin_altivec_vclzh: |
| 8979 | case PPC::BI__builtin_altivec_vclzw: |
| 8980 | case PPC::BI__builtin_altivec_vclzd: { |
| 8981 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8982 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8983 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 8984 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
| 8985 | return Builder.CreateCall(F, {X, Undef}); |
| 8986 | } |
Nemanja Ivanovic | 10e2b5d | 2016-09-27 10:45:22 +0000 | [diff] [blame] | 8987 | case PPC::BI__builtin_altivec_vctzb: |
| 8988 | case PPC::BI__builtin_altivec_vctzh: |
| 8989 | case PPC::BI__builtin_altivec_vctzw: |
| 8990 | case PPC::BI__builtin_altivec_vctzd: { |
| 8991 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 8992 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 8993 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 8994 | Function *F = CGM.getIntrinsic(Intrinsic::cttz, ResultType); |
| 8995 | return Builder.CreateCall(F, {X, Undef}); |
| 8996 | } |
| 8997 | case PPC::BI__builtin_altivec_vpopcntb: |
| 8998 | case PPC::BI__builtin_altivec_vpopcnth: |
| 8999 | case PPC::BI__builtin_altivec_vpopcntw: |
| 9000 | case PPC::BI__builtin_altivec_vpopcntd: { |
| 9001 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9002 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9003 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 9004 | return Builder.CreateCall(F, X); |
| 9005 | } |
Nemanja Ivanovic | 6c363ed | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 9006 | // Copy sign |
| 9007 | case PPC::BI__builtin_vsx_xvcpsgnsp: |
| 9008 | case PPC::BI__builtin_vsx_xvcpsgndp: { |
| 9009 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9010 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9011 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9012 | ID = Intrinsic::copysign; |
| 9013 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 9014 | return Builder.CreateCall(F, {X, Y}); |
| 9015 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 9016 | // Rounding/truncation |
| 9017 | case PPC::BI__builtin_vsx_xvrspip: |
| 9018 | case PPC::BI__builtin_vsx_xvrdpip: |
| 9019 | case PPC::BI__builtin_vsx_xvrdpim: |
| 9020 | case PPC::BI__builtin_vsx_xvrspim: |
| 9021 | case PPC::BI__builtin_vsx_xvrdpi: |
| 9022 | case PPC::BI__builtin_vsx_xvrspi: |
| 9023 | case PPC::BI__builtin_vsx_xvrdpic: |
| 9024 | case PPC::BI__builtin_vsx_xvrspic: |
| 9025 | case PPC::BI__builtin_vsx_xvrdpiz: |
| 9026 | case PPC::BI__builtin_vsx_xvrspiz: { |
| 9027 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9028 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9029 | if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim || |
| 9030 | BuiltinID == PPC::BI__builtin_vsx_xvrspim) |
| 9031 | ID = Intrinsic::floor; |
| 9032 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi || |
| 9033 | BuiltinID == PPC::BI__builtin_vsx_xvrspi) |
| 9034 | ID = Intrinsic::round; |
| 9035 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic || |
| 9036 | BuiltinID == PPC::BI__builtin_vsx_xvrspic) |
| 9037 | ID = Intrinsic::nearbyint; |
| 9038 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip || |
| 9039 | BuiltinID == PPC::BI__builtin_vsx_xvrspip) |
| 9040 | ID = Intrinsic::ceil; |
| 9041 | else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz || |
| 9042 | BuiltinID == PPC::BI__builtin_vsx_xvrspiz) |
| 9043 | ID = Intrinsic::trunc; |
| 9044 | llvm::Function *F = CGM.getIntrinsic(ID, ResultType); |
| 9045 | return Builder.CreateCall(F, X); |
| 9046 | } |
Kit Barton | fbab158 | 2016-03-09 19:28:31 +0000 | [diff] [blame] | 9047 | |
| 9048 | // Absolute value |
| 9049 | case PPC::BI__builtin_vsx_xvabsdp: |
| 9050 | case PPC::BI__builtin_vsx_xvabssp: { |
| 9051 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9052 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9053 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 9054 | return Builder.CreateCall(F, X); |
| 9055 | } |
| 9056 | |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 9057 | // FMA variations |
| 9058 | case PPC::BI__builtin_vsx_xvmaddadp: |
| 9059 | case PPC::BI__builtin_vsx_xvmaddasp: |
| 9060 | case PPC::BI__builtin_vsx_xvnmaddadp: |
| 9061 | case PPC::BI__builtin_vsx_xvnmaddasp: |
| 9062 | case PPC::BI__builtin_vsx_xvmsubadp: |
| 9063 | case PPC::BI__builtin_vsx_xvmsubasp: |
| 9064 | case PPC::BI__builtin_vsx_xvnmsubadp: |
| 9065 | case PPC::BI__builtin_vsx_xvnmsubasp: { |
| 9066 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9067 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9068 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9069 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 9070 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 9071 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
| 9072 | switch (BuiltinID) { |
| 9073 | case PPC::BI__builtin_vsx_xvmaddadp: |
| 9074 | case PPC::BI__builtin_vsx_xvmaddasp: |
| 9075 | return Builder.CreateCall(F, {X, Y, Z}); |
| 9076 | case PPC::BI__builtin_vsx_xvnmaddadp: |
| 9077 | case PPC::BI__builtin_vsx_xvnmaddasp: |
| 9078 | return Builder.CreateFSub(Zero, |
| 9079 | Builder.CreateCall(F, {X, Y, Z}), "sub"); |
| 9080 | case PPC::BI__builtin_vsx_xvmsubadp: |
| 9081 | case PPC::BI__builtin_vsx_xvmsubasp: |
| 9082 | return Builder.CreateCall(F, |
| 9083 | {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
| 9084 | case PPC::BI__builtin_vsx_xvnmsubadp: |
| 9085 | case PPC::BI__builtin_vsx_xvnmsubasp: |
| 9086 | Value *FsubRes = |
| 9087 | Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
| 9088 | return Builder.CreateFSub(Zero, FsubRes, "sub"); |
| 9089 | } |
| 9090 | llvm_unreachable("Unknown FMA operation"); |
| 9091 | return nullptr; // Suppress no-return warning |
| 9092 | } |
Sean Fertile | 96d9e0e | 2017-01-05 21:43:30 +0000 | [diff] [blame] | 9093 | |
| 9094 | case PPC::BI__builtin_vsx_insertword: { |
| 9095 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::ppc_vsx_xxinsertw); |
| 9096 | |
| 9097 | // Third argument is a compile time constant int. It must be clamped to |
| 9098 | // to the range [0, 12]. |
| 9099 | ConstantInt *ArgCI = dyn_cast<ConstantInt>(Ops[2]); |
| 9100 | assert(ArgCI && |
| 9101 | "Third arg to xxinsertw intrinsic must be constant integer"); |
| 9102 | const int64_t MaxIndex = 12; |
| 9103 | int64_t Index = clamp(ArgCI->getSExtValue(), 0, MaxIndex); |
| 9104 | |
| 9105 | // The builtin semantics don't exactly match the xxinsertw instructions |
| 9106 | // semantics (which ppc_vsx_xxinsertw follows). The builtin extracts the |
| 9107 | // word from the first argument, and inserts it in the second argument. The |
| 9108 | // instruction extracts the word from its second input register and inserts |
| 9109 | // it into its first input register, so swap the first and second arguments. |
| 9110 | std::swap(Ops[0], Ops[1]); |
| 9111 | |
| 9112 | // Need to cast the second argument from a vector of unsigned int to a |
| 9113 | // vector of long long. |
| 9114 | Ops[1] = Builder.CreateBitCast(Ops[1], llvm::VectorType::get(Int64Ty, 2)); |
| 9115 | |
| 9116 | if (getTarget().isLittleEndian()) { |
| 9117 | // Create a shuffle mask of (1, 0) |
| 9118 | Constant *ShuffleElts[2] = { ConstantInt::get(Int32Ty, 1), |
| 9119 | ConstantInt::get(Int32Ty, 0) |
| 9120 | }; |
| 9121 | Constant *ShuffleMask = llvm::ConstantVector::get(ShuffleElts); |
| 9122 | |
| 9123 | // Reverse the double words in the vector we will extract from. |
| 9124 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 2)); |
| 9125 | Ops[0] = Builder.CreateShuffleVector(Ops[0], Ops[0], ShuffleMask); |
| 9126 | |
| 9127 | // Reverse the index. |
| 9128 | Index = MaxIndex - Index; |
| 9129 | } |
| 9130 | |
| 9131 | // Intrinsic expects the first arg to be a vector of int. |
| 9132 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 4)); |
| 9133 | Ops[2] = ConstantInt::getSigned(Int32Ty, Index); |
| 9134 | return Builder.CreateCall(F, Ops); |
| 9135 | } |
| 9136 | |
| 9137 | case PPC::BI__builtin_vsx_extractuword: { |
| 9138 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::ppc_vsx_xxextractuw); |
| 9139 | |
| 9140 | // Intrinsic expects the first argument to be a vector of doublewords. |
| 9141 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 2)); |
| 9142 | |
| 9143 | // The second argument is a compile time constant int that needs to |
| 9144 | // be clamped to the range [0, 12]. |
| 9145 | ConstantInt *ArgCI = dyn_cast<ConstantInt>(Ops[1]); |
| 9146 | assert(ArgCI && |
| 9147 | "Second Arg to xxextractuw intrinsic must be a constant integer!"); |
| 9148 | const int64_t MaxIndex = 12; |
| 9149 | int64_t Index = clamp(ArgCI->getSExtValue(), 0, MaxIndex); |
| 9150 | |
| 9151 | if (getTarget().isLittleEndian()) { |
| 9152 | // Reverse the index. |
| 9153 | Index = MaxIndex - Index; |
| 9154 | Ops[1] = ConstantInt::getSigned(Int32Ty, Index); |
| 9155 | |
| 9156 | // Emit the call, then reverse the double words of the results vector. |
| 9157 | Value *Call = Builder.CreateCall(F, Ops); |
| 9158 | |
| 9159 | // Create a shuffle mask of (1, 0) |
| 9160 | Constant *ShuffleElts[2] = { ConstantInt::get(Int32Ty, 1), |
| 9161 | ConstantInt::get(Int32Ty, 0) |
| 9162 | }; |
| 9163 | Constant *ShuffleMask = llvm::ConstantVector::get(ShuffleElts); |
| 9164 | |
| 9165 | Value *ShuffleCall = Builder.CreateShuffleVector(Call, Call, ShuffleMask); |
| 9166 | return ShuffleCall; |
| 9167 | } else { |
| 9168 | Ops[1] = ConstantInt::getSigned(Int32Ty, Index); |
| 9169 | return Builder.CreateCall(F, Ops); |
| 9170 | } |
| 9171 | } |
Tony Jiang | bbc48e9 | 2017-05-24 15:13:32 +0000 | [diff] [blame] | 9172 | |
| 9173 | case PPC::BI__builtin_vsx_xxpermdi: { |
| 9174 | ConstantInt *ArgCI = dyn_cast<ConstantInt>(Ops[2]); |
| 9175 | assert(ArgCI && "Third arg must be constant integer!"); |
| 9176 | |
| 9177 | unsigned Index = ArgCI->getZExtValue(); |
| 9178 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int64Ty, 2)); |
| 9179 | Ops[1] = Builder.CreateBitCast(Ops[1], llvm::VectorType::get(Int64Ty, 2)); |
| 9180 | |
| 9181 | // Element zero comes from the first input vector and element one comes from |
| 9182 | // the second. The element indices within each vector are numbered in big |
| 9183 | // endian order so the shuffle mask must be adjusted for this on little |
| 9184 | // endian platforms (i.e. index is complemented and source vector reversed). |
| 9185 | unsigned ElemIdx0; |
| 9186 | unsigned ElemIdx1; |
| 9187 | if (getTarget().isLittleEndian()) { |
| 9188 | ElemIdx0 = (~Index & 1) + 2; |
| 9189 | ElemIdx1 = (~Index & 2) >> 1; |
| 9190 | } else { // BigEndian |
| 9191 | ElemIdx0 = (Index & 2) >> 1; |
| 9192 | ElemIdx1 = 2 + (Index & 1); |
| 9193 | } |
| 9194 | |
| 9195 | Constant *ShuffleElts[2] = {ConstantInt::get(Int32Ty, ElemIdx0), |
| 9196 | ConstantInt::get(Int32Ty, ElemIdx1)}; |
| 9197 | Constant *ShuffleMask = llvm::ConstantVector::get(ShuffleElts); |
| 9198 | |
| 9199 | Value *ShuffleCall = |
| 9200 | Builder.CreateShuffleVector(Ops[0], Ops[1], ShuffleMask); |
| 9201 | QualType BIRetType = E->getType(); |
| 9202 | auto RetTy = ConvertType(BIRetType); |
| 9203 | return Builder.CreateBitCast(ShuffleCall, RetTy); |
| 9204 | } |
Tony Jiang | 9aa2c03 | 2017-05-24 15:54:13 +0000 | [diff] [blame] | 9205 | |
| 9206 | case PPC::BI__builtin_vsx_xxsldwi: { |
| 9207 | ConstantInt *ArgCI = dyn_cast<ConstantInt>(Ops[2]); |
| 9208 | assert(ArgCI && "Third argument must be a compile time constant"); |
| 9209 | unsigned Index = ArgCI->getZExtValue() & 0x3; |
| 9210 | Ops[0] = Builder.CreateBitCast(Ops[0], llvm::VectorType::get(Int32Ty, 4)); |
| 9211 | Ops[1] = Builder.CreateBitCast(Ops[1], llvm::VectorType::get(Int32Ty, 4)); |
| 9212 | |
| 9213 | // Create a shuffle mask |
| 9214 | unsigned ElemIdx0; |
| 9215 | unsigned ElemIdx1; |
| 9216 | unsigned ElemIdx2; |
| 9217 | unsigned ElemIdx3; |
| 9218 | if (getTarget().isLittleEndian()) { |
| 9219 | // Little endian element N comes from element 8+N-Index of the |
| 9220 | // concatenated wide vector (of course, using modulo arithmetic on |
| 9221 | // the total number of elements). |
| 9222 | ElemIdx0 = (8 - Index) % 8; |
| 9223 | ElemIdx1 = (9 - Index) % 8; |
| 9224 | ElemIdx2 = (10 - Index) % 8; |
| 9225 | ElemIdx3 = (11 - Index) % 8; |
| 9226 | } else { |
| 9227 | // Big endian ElemIdx<N> = Index + N |
| 9228 | ElemIdx0 = Index; |
| 9229 | ElemIdx1 = Index + 1; |
| 9230 | ElemIdx2 = Index + 2; |
| 9231 | ElemIdx3 = Index + 3; |
| 9232 | } |
| 9233 | |
| 9234 | Constant *ShuffleElts[4] = {ConstantInt::get(Int32Ty, ElemIdx0), |
| 9235 | ConstantInt::get(Int32Ty, ElemIdx1), |
| 9236 | ConstantInt::get(Int32Ty, ElemIdx2), |
| 9237 | ConstantInt::get(Int32Ty, ElemIdx3)}; |
| 9238 | |
| 9239 | Constant *ShuffleMask = llvm::ConstantVector::get(ShuffleElts); |
| 9240 | Value *ShuffleCall = |
| 9241 | Builder.CreateShuffleVector(Ops[0], Ops[1], ShuffleMask); |
| 9242 | QualType BIRetType = E->getType(); |
| 9243 | auto RetTy = ConvertType(BIRetType); |
| 9244 | return Builder.CreateBitCast(ShuffleCall, RetTy); |
| 9245 | } |
Nemanja Ivanovic | 1c7ad71 | 2015-07-05 06:40:52 +0000 | [diff] [blame] | 9246 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 9247 | } |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9248 | |
Matt Arsenault | 3ea39f9 | 2015-06-19 17:54:10 +0000 | [diff] [blame] | 9249 | Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID, |
| 9250 | const CallExpr *E) { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9251 | switch (BuiltinID) { |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9252 | case AMDGPU::BI__builtin_amdgcn_div_scale: |
| 9253 | case AMDGPU::BI__builtin_amdgcn_div_scalef: { |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9254 | // Translate from the intrinsics's struct return to the builtin's out |
| 9255 | // argument. |
| 9256 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 9257 | Address FlagOutPtr = EmitPointerWithAlignment(E->getArg(3)); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9258 | |
| 9259 | llvm::Value *X = EmitScalarExpr(E->getArg(0)); |
| 9260 | llvm::Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9261 | llvm::Value *Z = EmitScalarExpr(E->getArg(2)); |
| 9262 | |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9263 | llvm::Value *Callee = CGM.getIntrinsic(Intrinsic::amdgcn_div_scale, |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9264 | X->getType()); |
| 9265 | |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9266 | llvm::Value *Tmp = Builder.CreateCall(Callee, {X, Y, Z}); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9267 | |
| 9268 | llvm::Value *Result = Builder.CreateExtractValue(Tmp, 0); |
| 9269 | llvm::Value *Flag = Builder.CreateExtractValue(Tmp, 1); |
| 9270 | |
| 9271 | llvm::Type *RealFlagType |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 9272 | = FlagOutPtr.getPointer()->getType()->getPointerElementType(); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9273 | |
| 9274 | llvm::Value *FlagExt = Builder.CreateZExt(Flag, RealFlagType); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 9275 | Builder.CreateStore(FlagExt, FlagOutPtr); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9276 | return Result; |
Matt Arsenault | 8587711 | 2014-07-15 17:23:46 +0000 | [diff] [blame] | 9277 | } |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9278 | case AMDGPU::BI__builtin_amdgcn_div_fmas: |
| 9279 | case AMDGPU::BI__builtin_amdgcn_div_fmasf: { |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 9280 | llvm::Value *Src0 = EmitScalarExpr(E->getArg(0)); |
| 9281 | llvm::Value *Src1 = EmitScalarExpr(E->getArg(1)); |
| 9282 | llvm::Value *Src2 = EmitScalarExpr(E->getArg(2)); |
| 9283 | llvm::Value *Src3 = EmitScalarExpr(E->getArg(3)); |
| 9284 | |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9285 | llvm::Value *F = CGM.getIntrinsic(Intrinsic::amdgcn_div_fmas, |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 9286 | Src0->getType()); |
| 9287 | llvm::Value *Src3ToBool = Builder.CreateIsNotNull(Src3); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9288 | return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool}); |
Matt Arsenault | 2174a9d | 2014-10-21 22:21:41 +0000 | [diff] [blame] | 9289 | } |
Changpeng Fang | 03bdd8f | 2016-08-18 22:04:54 +0000 | [diff] [blame] | 9290 | |
| 9291 | case AMDGPU::BI__builtin_amdgcn_ds_swizzle: |
| 9292 | return emitBinaryBuiltin(*this, E, Intrinsic::amdgcn_ds_swizzle); |
Yaxun Liu | 4d86799 | 2017-03-10 01:30:46 +0000 | [diff] [blame] | 9293 | case AMDGPU::BI__builtin_amdgcn_mov_dpp: { |
| 9294 | llvm::SmallVector<llvm::Value *, 5> Args; |
| 9295 | for (unsigned I = 0; I != 5; ++I) |
| 9296 | Args.push_back(EmitScalarExpr(E->getArg(I))); |
| 9297 | Value *F = CGM.getIntrinsic(Intrinsic::amdgcn_mov_dpp, |
| 9298 | Args[0]->getType()); |
| 9299 | return Builder.CreateCall(F, Args); |
| 9300 | } |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9301 | case AMDGPU::BI__builtin_amdgcn_div_fixup: |
| 9302 | case AMDGPU::BI__builtin_amdgcn_div_fixupf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9303 | case AMDGPU::BI__builtin_amdgcn_div_fixuph: |
Matt Arsenault | f652cae | 2016-07-01 17:38:14 +0000 | [diff] [blame] | 9304 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_div_fixup); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9305 | case AMDGPU::BI__builtin_amdgcn_trig_preop: |
| 9306 | case AMDGPU::BI__builtin_amdgcn_trig_preopf: |
| 9307 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_trig_preop); |
| 9308 | case AMDGPU::BI__builtin_amdgcn_rcp: |
| 9309 | case AMDGPU::BI__builtin_amdgcn_rcpf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9310 | case AMDGPU::BI__builtin_amdgcn_rcph: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 9311 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rcp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9312 | case AMDGPU::BI__builtin_amdgcn_rsq: |
| 9313 | case AMDGPU::BI__builtin_amdgcn_rsqf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9314 | case AMDGPU::BI__builtin_amdgcn_rsqh: |
Matt Arsenault | 105e892 | 2016-02-03 17:49:38 +0000 | [diff] [blame] | 9315 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq); |
Matt Arsenault | f5c1f47 | 2016-02-13 01:03:09 +0000 | [diff] [blame] | 9316 | case AMDGPU::BI__builtin_amdgcn_rsq_clamp: |
| 9317 | case AMDGPU::BI__builtin_amdgcn_rsq_clampf: |
| 9318 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_rsq_clamp); |
Matt Arsenault | 9b277b4 | 2016-02-13 01:21:09 +0000 | [diff] [blame] | 9319 | case AMDGPU::BI__builtin_amdgcn_sinf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9320 | case AMDGPU::BI__builtin_amdgcn_sinh: |
Matt Arsenault | 9b277b4 | 2016-02-13 01:21:09 +0000 | [diff] [blame] | 9321 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_sin); |
| 9322 | case AMDGPU::BI__builtin_amdgcn_cosf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9323 | case AMDGPU::BI__builtin_amdgcn_cosh: |
Matt Arsenault | 9b277b4 | 2016-02-13 01:21:09 +0000 | [diff] [blame] | 9324 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_cos); |
| 9325 | case AMDGPU::BI__builtin_amdgcn_log_clampf: |
| 9326 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_log_clamp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9327 | case AMDGPU::BI__builtin_amdgcn_ldexp: |
| 9328 | case AMDGPU::BI__builtin_amdgcn_ldexpf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9329 | case AMDGPU::BI__builtin_amdgcn_ldexph: |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9330 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_ldexp); |
Matt Arsenault | 3fb9633 | 2016-03-30 22:57:40 +0000 | [diff] [blame] | 9331 | case AMDGPU::BI__builtin_amdgcn_frexp_mant: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9332 | case AMDGPU::BI__builtin_amdgcn_frexp_mantf: |
| 9333 | case AMDGPU::BI__builtin_amdgcn_frexp_manth: |
Matt Arsenault | 3fb9633 | 2016-03-30 22:57:40 +0000 | [diff] [blame] | 9334 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_frexp_mant); |
Matt Arsenault | 3fb9633 | 2016-03-30 22:57:40 +0000 | [diff] [blame] | 9335 | case AMDGPU::BI__builtin_amdgcn_frexp_exp: |
Konstantin Zhuravlyov | 62ae8f6 | 2016-11-18 22:31:51 +0000 | [diff] [blame] | 9336 | case AMDGPU::BI__builtin_amdgcn_frexp_expf: { |
| 9337 | Value *Src0 = EmitScalarExpr(E->getArg(0)); |
| 9338 | Value *F = CGM.getIntrinsic(Intrinsic::amdgcn_frexp_exp, |
| 9339 | { Builder.getInt32Ty(), Src0->getType() }); |
| 9340 | return Builder.CreateCall(F, Src0); |
| 9341 | } |
| 9342 | case AMDGPU::BI__builtin_amdgcn_frexp_exph: { |
| 9343 | Value *Src0 = EmitScalarExpr(E->getArg(0)); |
| 9344 | Value *F = CGM.getIntrinsic(Intrinsic::amdgcn_frexp_exp, |
| 9345 | { Builder.getInt16Ty(), Src0->getType() }); |
| 9346 | return Builder.CreateCall(F, Src0); |
| 9347 | } |
Matt Arsenault | 2d51059 | 2016-05-28 00:43:27 +0000 | [diff] [blame] | 9348 | case AMDGPU::BI__builtin_amdgcn_fract: |
| 9349 | case AMDGPU::BI__builtin_amdgcn_fractf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9350 | case AMDGPU::BI__builtin_amdgcn_fracth: |
Matt Arsenault | 2d51059 | 2016-05-28 00:43:27 +0000 | [diff] [blame] | 9351 | return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_fract); |
Wei Ding | ea41f35 | 2016-07-15 16:43:03 +0000 | [diff] [blame] | 9352 | case AMDGPU::BI__builtin_amdgcn_lerp: |
| 9353 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_lerp); |
Wei Ding | 91c8450 | 2016-08-05 15:38:46 +0000 | [diff] [blame] | 9354 | case AMDGPU::BI__builtin_amdgcn_uicmp: |
| 9355 | case AMDGPU::BI__builtin_amdgcn_uicmpl: |
| 9356 | case AMDGPU::BI__builtin_amdgcn_sicmp: |
| 9357 | case AMDGPU::BI__builtin_amdgcn_sicmpl: |
| 9358 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_icmp); |
| 9359 | case AMDGPU::BI__builtin_amdgcn_fcmp: |
| 9360 | case AMDGPU::BI__builtin_amdgcn_fcmpf: |
| 9361 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_fcmp); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9362 | case AMDGPU::BI__builtin_amdgcn_class: |
| 9363 | case AMDGPU::BI__builtin_amdgcn_classf: |
Konstantin Zhuravlyov | 81a78bb | 2016-11-13 02:37:05 +0000 | [diff] [blame] | 9364 | case AMDGPU::BI__builtin_amdgcn_classh: |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9365 | return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_class); |
Matt Arsenault | a274b20 | 2017-01-31 03:42:07 +0000 | [diff] [blame] | 9366 | case AMDGPU::BI__builtin_amdgcn_fmed3f: |
Matt Arsenault | a0c6dca | 2017-02-22 20:55:59 +0000 | [diff] [blame] | 9367 | case AMDGPU::BI__builtin_amdgcn_fmed3h: |
Matt Arsenault | a274b20 | 2017-01-31 03:42:07 +0000 | [diff] [blame] | 9368 | return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_fmed3); |
Matt Arsenault | 64665bc | 2016-06-28 00:13:17 +0000 | [diff] [blame] | 9369 | case AMDGPU::BI__builtin_amdgcn_read_exec: { |
| 9370 | CallInst *CI = cast<CallInst>( |
| 9371 | EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, true, "exec")); |
| 9372 | CI->setConvergent(); |
| 9373 | return CI; |
| 9374 | } |
Matt Arsenault | f12e3b8 | 2017-10-09 20:06:37 +0000 | [diff] [blame] | 9375 | case AMDGPU::BI__builtin_amdgcn_read_exec_lo: |
| 9376 | case AMDGPU::BI__builtin_amdgcn_read_exec_hi: { |
| 9377 | StringRef RegName = BuiltinID == AMDGPU::BI__builtin_amdgcn_read_exec_lo ? |
| 9378 | "exec_lo" : "exec_hi"; |
| 9379 | CallInst *CI = cast<CallInst>( |
| 9380 | EmitSpecialRegisterBuiltin(*this, E, Int32Ty, Int32Ty, true, RegName)); |
| 9381 | CI->setConvergent(); |
| 9382 | return CI; |
| 9383 | } |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 9384 | |
| 9385 | // amdgcn workitem |
| 9386 | case AMDGPU::BI__builtin_amdgcn_workitem_id_x: |
| 9387 | return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_x, 0, 1024); |
| 9388 | case AMDGPU::BI__builtin_amdgcn_workitem_id_y: |
| 9389 | return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_y, 0, 1024); |
| 9390 | case AMDGPU::BI__builtin_amdgcn_workitem_id_z: |
| 9391 | return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_z, 0, 1024); |
| 9392 | |
Matt Arsenault | c86671d | 2016-07-15 21:33:02 +0000 | [diff] [blame] | 9393 | // r600 intrinsics |
| 9394 | case AMDGPU::BI__builtin_r600_recipsqrt_ieee: |
| 9395 | case AMDGPU::BI__builtin_r600_recipsqrt_ieeef: |
| 9396 | return emitUnaryBuiltin(*this, E, Intrinsic::r600_recipsqrt_ieee); |
Jan Vesely | d7e03a5 | 2016-07-10 22:38:04 +0000 | [diff] [blame] | 9397 | case AMDGPU::BI__builtin_r600_read_tidig_x: |
| 9398 | return emitRangedBuiltin(*this, Intrinsic::r600_read_tidig_x, 0, 1024); |
| 9399 | case AMDGPU::BI__builtin_r600_read_tidig_y: |
| 9400 | return emitRangedBuiltin(*this, Intrinsic::r600_read_tidig_y, 0, 1024); |
| 9401 | case AMDGPU::BI__builtin_r600_read_tidig_z: |
| 9402 | return emitRangedBuiltin(*this, Intrinsic::r600_read_tidig_z, 0, 1024); |
Matt Arsenault | 8a4078c | 2016-01-22 21:30:53 +0000 | [diff] [blame] | 9403 | default: |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 9404 | return nullptr; |
| 9405 | } |
| 9406 | } |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9407 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9408 | /// Handle a SystemZ function in which the final argument is a pointer |
| 9409 | /// to an int that receives the post-instruction CC value. At the LLVM level |
| 9410 | /// this is represented as a function that returns a {result, cc} pair. |
| 9411 | static Value *EmitSystemZIntrinsicWithCC(CodeGenFunction &CGF, |
| 9412 | unsigned IntrinsicID, |
| 9413 | const CallExpr *E) { |
| 9414 | unsigned NumArgs = E->getNumArgs() - 1; |
| 9415 | SmallVector<Value *, 8> Args(NumArgs); |
| 9416 | for (unsigned I = 0; I < NumArgs; ++I) |
| 9417 | Args[I] = CGF.EmitScalarExpr(E->getArg(I)); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 9418 | Address CCPtr = CGF.EmitPointerWithAlignment(E->getArg(NumArgs)); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9419 | Value *F = CGF.CGM.getIntrinsic(IntrinsicID); |
| 9420 | Value *Call = CGF.Builder.CreateCall(F, Args); |
| 9421 | Value *CC = CGF.Builder.CreateExtractValue(Call, 1); |
| 9422 | CGF.Builder.CreateStore(CC, CCPtr); |
| 9423 | return CGF.Builder.CreateExtractValue(Call, 0); |
| 9424 | } |
| 9425 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9426 | Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID, |
| 9427 | const CallExpr *E) { |
| 9428 | switch (BuiltinID) { |
| 9429 | case SystemZ::BI__builtin_tbegin: { |
| 9430 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 9431 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 9432 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9433 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9434 | } |
| 9435 | case SystemZ::BI__builtin_tbegin_nofloat: { |
| 9436 | Value *TDB = EmitScalarExpr(E->getArg(0)); |
| 9437 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff0c); |
| 9438 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbegin_nofloat); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9439 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9440 | } |
| 9441 | case SystemZ::BI__builtin_tbeginc: { |
| 9442 | Value *TDB = llvm::ConstantPointerNull::get(Int8PtrTy); |
| 9443 | Value *Control = llvm::ConstantInt::get(Int32Ty, 0xff08); |
| 9444 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tbeginc); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9445 | return Builder.CreateCall(F, {TDB, Control}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9446 | } |
| 9447 | case SystemZ::BI__builtin_tabort: { |
| 9448 | Value *Data = EmitScalarExpr(E->getArg(0)); |
| 9449 | Value *F = CGM.getIntrinsic(Intrinsic::s390_tabort); |
| 9450 | return Builder.CreateCall(F, Builder.CreateSExt(Data, Int64Ty, "tabort")); |
| 9451 | } |
| 9452 | case SystemZ::BI__builtin_non_tx_store: { |
| 9453 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 9454 | Value *Data = EmitScalarExpr(E->getArg(1)); |
| 9455 | Value *F = CGM.getIntrinsic(Intrinsic::s390_ntstg); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9456 | return Builder.CreateCall(F, {Data, Address}); |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9457 | } |
| 9458 | |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9459 | // Vector builtins. Note that most vector builtins are mapped automatically |
| 9460 | // to target-specific LLVM intrinsics. The ones handled specially here can |
| 9461 | // be represented via standard LLVM IR, which is preferable to enable common |
| 9462 | // LLVM optimizations. |
| 9463 | |
| 9464 | case SystemZ::BI__builtin_s390_vpopctb: |
| 9465 | case SystemZ::BI__builtin_s390_vpopcth: |
| 9466 | case SystemZ::BI__builtin_s390_vpopctf: |
| 9467 | case SystemZ::BI__builtin_s390_vpopctg: { |
| 9468 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9469 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9470 | Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType); |
| 9471 | return Builder.CreateCall(F, X); |
| 9472 | } |
| 9473 | |
| 9474 | case SystemZ::BI__builtin_s390_vclzb: |
| 9475 | case SystemZ::BI__builtin_s390_vclzh: |
| 9476 | case SystemZ::BI__builtin_s390_vclzf: |
| 9477 | case SystemZ::BI__builtin_s390_vclzg: { |
| 9478 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9479 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9480 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 9481 | Function *F = CGM.getIntrinsic(Intrinsic::ctlz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9482 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9483 | } |
| 9484 | |
| 9485 | case SystemZ::BI__builtin_s390_vctzb: |
| 9486 | case SystemZ::BI__builtin_s390_vctzh: |
| 9487 | case SystemZ::BI__builtin_s390_vctzf: |
| 9488 | case SystemZ::BI__builtin_s390_vctzg: { |
| 9489 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9490 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9491 | Value *Undef = ConstantInt::get(Builder.getInt1Ty(), false); |
| 9492 | Function *F = CGM.getIntrinsic(Intrinsic::cttz, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9493 | return Builder.CreateCall(F, {X, Undef}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9494 | } |
| 9495 | |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9496 | case SystemZ::BI__builtin_s390_vfsqsb: |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9497 | case SystemZ::BI__builtin_s390_vfsqdb: { |
| 9498 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9499 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9500 | Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType); |
| 9501 | return Builder.CreateCall(F, X); |
| 9502 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9503 | case SystemZ::BI__builtin_s390_vfmasb: |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9504 | case SystemZ::BI__builtin_s390_vfmadb: { |
| 9505 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9506 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9507 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9508 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 9509 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9510 | return Builder.CreateCall(F, {X, Y, Z}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9511 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9512 | case SystemZ::BI__builtin_s390_vfmssb: |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9513 | case SystemZ::BI__builtin_s390_vfmsdb: { |
| 9514 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9515 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9516 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9517 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 9518 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 9519 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9520 | return Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9521 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9522 | case SystemZ::BI__builtin_s390_vfnmasb: |
| 9523 | case SystemZ::BI__builtin_s390_vfnmadb: { |
| 9524 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9525 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9526 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9527 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 9528 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 9529 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
| 9530 | return Builder.CreateFSub(Zero, Builder.CreateCall(F, {X, Y, Z}), "sub"); |
| 9531 | } |
| 9532 | case SystemZ::BI__builtin_s390_vfnmssb: |
| 9533 | case SystemZ::BI__builtin_s390_vfnmsdb: { |
| 9534 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9535 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9536 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9537 | Value *Z = EmitScalarExpr(E->getArg(2)); |
| 9538 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 9539 | Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType); |
| 9540 | Value *NegZ = Builder.CreateFSub(Zero, Z, "sub"); |
| 9541 | return Builder.CreateFSub(Zero, Builder.CreateCall(F, {X, Y, NegZ})); |
| 9542 | } |
| 9543 | case SystemZ::BI__builtin_s390_vflpsb: |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9544 | case SystemZ::BI__builtin_s390_vflpdb: { |
| 9545 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9546 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9547 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 9548 | return Builder.CreateCall(F, X); |
| 9549 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9550 | case SystemZ::BI__builtin_s390_vflnsb: |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9551 | case SystemZ::BI__builtin_s390_vflndb: { |
| 9552 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9553 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9554 | Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType); |
| 9555 | Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType); |
| 9556 | return Builder.CreateFSub(Zero, Builder.CreateCall(F, X), "sub"); |
| 9557 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9558 | case SystemZ::BI__builtin_s390_vfisb: |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9559 | case SystemZ::BI__builtin_s390_vfidb: { |
| 9560 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9561 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9562 | // Constant-fold the M4 and M5 mask arguments. |
| 9563 | llvm::APSInt M4, M5; |
| 9564 | bool IsConstM4 = E->getArg(1)->isIntegerConstantExpr(M4, getContext()); |
| 9565 | bool IsConstM5 = E->getArg(2)->isIntegerConstantExpr(M5, getContext()); |
| 9566 | assert(IsConstM4 && IsConstM5 && "Constant arg isn't actually constant?"); |
| 9567 | (void)IsConstM4; (void)IsConstM5; |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9568 | // Check whether this instance can be represented via a LLVM standard |
| 9569 | // intrinsic. We only support some combinations of M4 and M5. |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9570 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 9571 | switch (M4.getZExtValue()) { |
| 9572 | default: break; |
| 9573 | case 0: // IEEE-inexact exception allowed |
| 9574 | switch (M5.getZExtValue()) { |
| 9575 | default: break; |
| 9576 | case 0: ID = Intrinsic::rint; break; |
| 9577 | } |
| 9578 | break; |
| 9579 | case 4: // IEEE-inexact exception suppressed |
| 9580 | switch (M5.getZExtValue()) { |
| 9581 | default: break; |
| 9582 | case 0: ID = Intrinsic::nearbyint; break; |
| 9583 | case 1: ID = Intrinsic::round; break; |
| 9584 | case 5: ID = Intrinsic::trunc; break; |
| 9585 | case 6: ID = Intrinsic::ceil; break; |
| 9586 | case 7: ID = Intrinsic::floor; break; |
| 9587 | } |
| 9588 | break; |
| 9589 | } |
| 9590 | if (ID != Intrinsic::not_intrinsic) { |
| 9591 | Function *F = CGM.getIntrinsic(ID, ResultType); |
| 9592 | return Builder.CreateCall(F, X); |
| 9593 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9594 | switch (BuiltinID) { |
| 9595 | case SystemZ::BI__builtin_s390_vfisb: ID = Intrinsic::s390_vfisb; break; |
| 9596 | case SystemZ::BI__builtin_s390_vfidb: ID = Intrinsic::s390_vfidb; break; |
| 9597 | default: llvm_unreachable("Unknown BuiltinID"); |
| 9598 | } |
| 9599 | Function *F = CGM.getIntrinsic(ID); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9600 | Value *M4Value = llvm::ConstantInt::get(getLLVMContext(), M4); |
| 9601 | Value *M5Value = llvm::ConstantInt::get(getLLVMContext(), M5); |
David Blaikie | 43f9bb7 | 2015-05-18 22:14:03 +0000 | [diff] [blame] | 9602 | return Builder.CreateCall(F, {X, M4Value, M5Value}); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9603 | } |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9604 | case SystemZ::BI__builtin_s390_vfmaxsb: |
| 9605 | case SystemZ::BI__builtin_s390_vfmaxdb: { |
| 9606 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9607 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9608 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9609 | // Constant-fold the M4 mask argument. |
| 9610 | llvm::APSInt M4; |
| 9611 | bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext()); |
| 9612 | assert(IsConstM4 && "Constant arg isn't actually constant?"); |
| 9613 | (void)IsConstM4; |
| 9614 | // Check whether this instance can be represented via a LLVM standard |
| 9615 | // intrinsic. We only support some values of M4. |
| 9616 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 9617 | switch (M4.getZExtValue()) { |
| 9618 | default: break; |
| 9619 | case 4: ID = Intrinsic::maxnum; break; |
| 9620 | } |
| 9621 | if (ID != Intrinsic::not_intrinsic) { |
| 9622 | Function *F = CGM.getIntrinsic(ID, ResultType); |
| 9623 | return Builder.CreateCall(F, {X, Y}); |
| 9624 | } |
| 9625 | switch (BuiltinID) { |
| 9626 | case SystemZ::BI__builtin_s390_vfmaxsb: ID = Intrinsic::s390_vfmaxsb; break; |
| 9627 | case SystemZ::BI__builtin_s390_vfmaxdb: ID = Intrinsic::s390_vfmaxdb; break; |
| 9628 | default: llvm_unreachable("Unknown BuiltinID"); |
| 9629 | } |
| 9630 | Function *F = CGM.getIntrinsic(ID); |
| 9631 | Value *M4Value = llvm::ConstantInt::get(getLLVMContext(), M4); |
| 9632 | return Builder.CreateCall(F, {X, Y, M4Value}); |
| 9633 | } |
| 9634 | case SystemZ::BI__builtin_s390_vfminsb: |
| 9635 | case SystemZ::BI__builtin_s390_vfmindb: { |
| 9636 | llvm::Type *ResultType = ConvertType(E->getType()); |
| 9637 | Value *X = EmitScalarExpr(E->getArg(0)); |
| 9638 | Value *Y = EmitScalarExpr(E->getArg(1)); |
| 9639 | // Constant-fold the M4 mask argument. |
| 9640 | llvm::APSInt M4; |
| 9641 | bool IsConstM4 = E->getArg(2)->isIntegerConstantExpr(M4, getContext()); |
| 9642 | assert(IsConstM4 && "Constant arg isn't actually constant?"); |
| 9643 | (void)IsConstM4; |
| 9644 | // Check whether this instance can be represented via a LLVM standard |
| 9645 | // intrinsic. We only support some values of M4. |
| 9646 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 9647 | switch (M4.getZExtValue()) { |
| 9648 | default: break; |
| 9649 | case 4: ID = Intrinsic::minnum; break; |
| 9650 | } |
| 9651 | if (ID != Intrinsic::not_intrinsic) { |
| 9652 | Function *F = CGM.getIntrinsic(ID, ResultType); |
| 9653 | return Builder.CreateCall(F, {X, Y}); |
| 9654 | } |
| 9655 | switch (BuiltinID) { |
| 9656 | case SystemZ::BI__builtin_s390_vfminsb: ID = Intrinsic::s390_vfminsb; break; |
| 9657 | case SystemZ::BI__builtin_s390_vfmindb: ID = Intrinsic::s390_vfmindb; break; |
| 9658 | default: llvm_unreachable("Unknown BuiltinID"); |
| 9659 | } |
| 9660 | Function *F = CGM.getIntrinsic(ID); |
| 9661 | Value *M4Value = llvm::ConstantInt::get(getLLVMContext(), M4); |
| 9662 | return Builder.CreateCall(F, {X, Y, M4Value}); |
| 9663 | } |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9664 | |
| 9665 | // Vector intrisincs that output the post-instruction CC value. |
| 9666 | |
| 9667 | #define INTRINSIC_WITH_CC(NAME) \ |
| 9668 | case SystemZ::BI__builtin_##NAME: \ |
| 9669 | return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E) |
| 9670 | |
| 9671 | INTRINSIC_WITH_CC(s390_vpkshs); |
| 9672 | INTRINSIC_WITH_CC(s390_vpksfs); |
| 9673 | INTRINSIC_WITH_CC(s390_vpksgs); |
| 9674 | |
| 9675 | INTRINSIC_WITH_CC(s390_vpklshs); |
| 9676 | INTRINSIC_WITH_CC(s390_vpklsfs); |
| 9677 | INTRINSIC_WITH_CC(s390_vpklsgs); |
| 9678 | |
| 9679 | INTRINSIC_WITH_CC(s390_vceqbs); |
| 9680 | INTRINSIC_WITH_CC(s390_vceqhs); |
| 9681 | INTRINSIC_WITH_CC(s390_vceqfs); |
| 9682 | INTRINSIC_WITH_CC(s390_vceqgs); |
| 9683 | |
| 9684 | INTRINSIC_WITH_CC(s390_vchbs); |
| 9685 | INTRINSIC_WITH_CC(s390_vchhs); |
| 9686 | INTRINSIC_WITH_CC(s390_vchfs); |
| 9687 | INTRINSIC_WITH_CC(s390_vchgs); |
| 9688 | |
| 9689 | INTRINSIC_WITH_CC(s390_vchlbs); |
| 9690 | INTRINSIC_WITH_CC(s390_vchlhs); |
| 9691 | INTRINSIC_WITH_CC(s390_vchlfs); |
| 9692 | INTRINSIC_WITH_CC(s390_vchlgs); |
| 9693 | |
| 9694 | INTRINSIC_WITH_CC(s390_vfaebs); |
| 9695 | INTRINSIC_WITH_CC(s390_vfaehs); |
| 9696 | INTRINSIC_WITH_CC(s390_vfaefs); |
| 9697 | |
| 9698 | INTRINSIC_WITH_CC(s390_vfaezbs); |
| 9699 | INTRINSIC_WITH_CC(s390_vfaezhs); |
| 9700 | INTRINSIC_WITH_CC(s390_vfaezfs); |
| 9701 | |
| 9702 | INTRINSIC_WITH_CC(s390_vfeebs); |
| 9703 | INTRINSIC_WITH_CC(s390_vfeehs); |
| 9704 | INTRINSIC_WITH_CC(s390_vfeefs); |
| 9705 | |
| 9706 | INTRINSIC_WITH_CC(s390_vfeezbs); |
| 9707 | INTRINSIC_WITH_CC(s390_vfeezhs); |
| 9708 | INTRINSIC_WITH_CC(s390_vfeezfs); |
| 9709 | |
| 9710 | INTRINSIC_WITH_CC(s390_vfenebs); |
| 9711 | INTRINSIC_WITH_CC(s390_vfenehs); |
| 9712 | INTRINSIC_WITH_CC(s390_vfenefs); |
| 9713 | |
| 9714 | INTRINSIC_WITH_CC(s390_vfenezbs); |
| 9715 | INTRINSIC_WITH_CC(s390_vfenezhs); |
| 9716 | INTRINSIC_WITH_CC(s390_vfenezfs); |
| 9717 | |
| 9718 | INTRINSIC_WITH_CC(s390_vistrbs); |
| 9719 | INTRINSIC_WITH_CC(s390_vistrhs); |
| 9720 | INTRINSIC_WITH_CC(s390_vistrfs); |
| 9721 | |
| 9722 | INTRINSIC_WITH_CC(s390_vstrcbs); |
| 9723 | INTRINSIC_WITH_CC(s390_vstrchs); |
| 9724 | INTRINSIC_WITH_CC(s390_vstrcfs); |
| 9725 | |
| 9726 | INTRINSIC_WITH_CC(s390_vstrczbs); |
| 9727 | INTRINSIC_WITH_CC(s390_vstrczhs); |
| 9728 | INTRINSIC_WITH_CC(s390_vstrczfs); |
| 9729 | |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9730 | INTRINSIC_WITH_CC(s390_vfcesbs); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9731 | INTRINSIC_WITH_CC(s390_vfcedbs); |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9732 | INTRINSIC_WITH_CC(s390_vfchsbs); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9733 | INTRINSIC_WITH_CC(s390_vfchdbs); |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9734 | INTRINSIC_WITH_CC(s390_vfchesbs); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9735 | INTRINSIC_WITH_CC(s390_vfchedbs); |
| 9736 | |
Ulrich Weigand | cac24ab | 2017-07-17 17:45:57 +0000 | [diff] [blame] | 9737 | INTRINSIC_WITH_CC(s390_vftcisb); |
Ulrich Weigand | 5722c0f | 2015-05-05 19:36:42 +0000 | [diff] [blame] | 9738 | INTRINSIC_WITH_CC(s390_vftcidb); |
| 9739 | |
| 9740 | #undef INTRINSIC_WITH_CC |
| 9741 | |
Ulrich Weigand | 3a610eb | 2015-04-01 12:54:25 +0000 | [diff] [blame] | 9742 | default: |
| 9743 | return nullptr; |
| 9744 | } |
| 9745 | } |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9746 | |
| 9747 | Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, |
| 9748 | const CallExpr *E) { |
Justin Lebar | 2e4ecfd | 2016-05-19 22:49:13 +0000 | [diff] [blame] | 9749 | auto MakeLdg = [&](unsigned IntrinsicID) { |
| 9750 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
Justin Lebar | 2e4ecfd | 2016-05-19 22:49:13 +0000 | [diff] [blame] | 9751 | clang::CharUnits Align = |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 9752 | getNaturalPointeeTypeAlignment(E->getArg(0)->getType()); |
Justin Lebar | 2e4ecfd | 2016-05-19 22:49:13 +0000 | [diff] [blame] | 9753 | return Builder.CreateCall( |
| 9754 | CGM.getIntrinsic(IntrinsicID, {Ptr->getType()->getPointerElementType(), |
| 9755 | Ptr->getType()}), |
| 9756 | {Ptr, ConstantInt::get(Builder.getInt32Ty(), Align.getQuantity())}); |
| 9757 | }; |
Artem Belevich | fda9905 | 2016-09-28 17:47:35 +0000 | [diff] [blame] | 9758 | auto MakeScopedAtomic = [&](unsigned IntrinsicID) { |
| 9759 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9760 | return Builder.CreateCall( |
| 9761 | CGM.getIntrinsic(IntrinsicID, {Ptr->getType()->getPointerElementType(), |
| 9762 | Ptr->getType()}), |
| 9763 | {Ptr, EmitScalarExpr(E->getArg(1))}); |
| 9764 | }; |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9765 | switch (BuiltinID) { |
| 9766 | case NVPTX::BI__nvvm_atom_add_gen_i: |
| 9767 | case NVPTX::BI__nvvm_atom_add_gen_l: |
| 9768 | case NVPTX::BI__nvvm_atom_add_gen_ll: |
| 9769 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Add, E); |
| 9770 | |
| 9771 | case NVPTX::BI__nvvm_atom_sub_gen_i: |
| 9772 | case NVPTX::BI__nvvm_atom_sub_gen_l: |
| 9773 | case NVPTX::BI__nvvm_atom_sub_gen_ll: |
| 9774 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Sub, E); |
| 9775 | |
| 9776 | case NVPTX::BI__nvvm_atom_and_gen_i: |
| 9777 | case NVPTX::BI__nvvm_atom_and_gen_l: |
| 9778 | case NVPTX::BI__nvvm_atom_and_gen_ll: |
| 9779 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::And, E); |
| 9780 | |
| 9781 | case NVPTX::BI__nvvm_atom_or_gen_i: |
| 9782 | case NVPTX::BI__nvvm_atom_or_gen_l: |
| 9783 | case NVPTX::BI__nvvm_atom_or_gen_ll: |
| 9784 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Or, E); |
| 9785 | |
| 9786 | case NVPTX::BI__nvvm_atom_xor_gen_i: |
| 9787 | case NVPTX::BI__nvvm_atom_xor_gen_l: |
| 9788 | case NVPTX::BI__nvvm_atom_xor_gen_ll: |
| 9789 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xor, E); |
| 9790 | |
| 9791 | case NVPTX::BI__nvvm_atom_xchg_gen_i: |
| 9792 | case NVPTX::BI__nvvm_atom_xchg_gen_l: |
| 9793 | case NVPTX::BI__nvvm_atom_xchg_gen_ll: |
| 9794 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Xchg, E); |
| 9795 | |
| 9796 | case NVPTX::BI__nvvm_atom_max_gen_i: |
| 9797 | case NVPTX::BI__nvvm_atom_max_gen_l: |
| 9798 | case NVPTX::BI__nvvm_atom_max_gen_ll: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 9799 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Max, E); |
| 9800 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9801 | case NVPTX::BI__nvvm_atom_max_gen_ui: |
| 9802 | case NVPTX::BI__nvvm_atom_max_gen_ul: |
| 9803 | case NVPTX::BI__nvvm_atom_max_gen_ull: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 9804 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMax, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9805 | |
| 9806 | case NVPTX::BI__nvvm_atom_min_gen_i: |
| 9807 | case NVPTX::BI__nvvm_atom_min_gen_l: |
| 9808 | case NVPTX::BI__nvvm_atom_min_gen_ll: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 9809 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::Min, E); |
| 9810 | |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9811 | case NVPTX::BI__nvvm_atom_min_gen_ui: |
| 9812 | case NVPTX::BI__nvvm_atom_min_gen_ul: |
| 9813 | case NVPTX::BI__nvvm_atom_min_gen_ull: |
Jingyue Wu | 2d69f96 | 2015-08-31 17:25:51 +0000 | [diff] [blame] | 9814 | return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9815 | |
| 9816 | case NVPTX::BI__nvvm_atom_cas_gen_i: |
| 9817 | case NVPTX::BI__nvvm_atom_cas_gen_l: |
| 9818 | case NVPTX::BI__nvvm_atom_cas_gen_ll: |
Jingyue Wu | f1eca25 | 2015-09-30 21:49:32 +0000 | [diff] [blame] | 9819 | // __nvvm_atom_cas_gen_* should return the old value rather than the |
| 9820 | // success flag. |
| 9821 | return MakeAtomicCmpXchgValue(*this, E, /*ReturnBool=*/false); |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 9822 | |
| 9823 | case NVPTX::BI__nvvm_atom_add_gen_f: { |
| 9824 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9825 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 9826 | // atomicrmw only deals with integer arguments so we need to use |
| 9827 | // LLVM's nvvm_atomic_load_add_f32 intrinsic for that. |
| 9828 | Value *FnALAF32 = |
| 9829 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_add_f32, Ptr->getType()); |
| 9830 | return Builder.CreateCall(FnALAF32, {Ptr, Val}); |
| 9831 | } |
| 9832 | |
Justin Lebar | da9e0bd | 2017-11-07 22:10:54 +0000 | [diff] [blame] | 9833 | case NVPTX::BI__nvvm_atom_add_gen_d: { |
| 9834 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9835 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 9836 | // atomicrmw only deals with integer arguments, so we need to use |
| 9837 | // LLVM's nvvm_atomic_load_add_f64 intrinsic. |
| 9838 | Value *FnALAF64 = |
| 9839 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_add_f64, Ptr->getType()); |
| 9840 | return Builder.CreateCall(FnALAF64, {Ptr, Val}); |
| 9841 | } |
| 9842 | |
Justin Lebar | 717d2b0 | 2016-03-22 00:09:28 +0000 | [diff] [blame] | 9843 | case NVPTX::BI__nvvm_atom_inc_gen_ui: { |
| 9844 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9845 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 9846 | Value *FnALI32 = |
| 9847 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_inc_32, Ptr->getType()); |
| 9848 | return Builder.CreateCall(FnALI32, {Ptr, Val}); |
| 9849 | } |
| 9850 | |
| 9851 | case NVPTX::BI__nvvm_atom_dec_gen_ui: { |
| 9852 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9853 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 9854 | Value *FnALD32 = |
| 9855 | CGM.getIntrinsic(Intrinsic::nvvm_atomic_load_dec_32, Ptr->getType()); |
| 9856 | return Builder.CreateCall(FnALD32, {Ptr, Val}); |
| 9857 | } |
| 9858 | |
Justin Lebar | 2e4ecfd | 2016-05-19 22:49:13 +0000 | [diff] [blame] | 9859 | case NVPTX::BI__nvvm_ldg_c: |
| 9860 | case NVPTX::BI__nvvm_ldg_c2: |
| 9861 | case NVPTX::BI__nvvm_ldg_c4: |
| 9862 | case NVPTX::BI__nvvm_ldg_s: |
| 9863 | case NVPTX::BI__nvvm_ldg_s2: |
| 9864 | case NVPTX::BI__nvvm_ldg_s4: |
| 9865 | case NVPTX::BI__nvvm_ldg_i: |
| 9866 | case NVPTX::BI__nvvm_ldg_i2: |
| 9867 | case NVPTX::BI__nvvm_ldg_i4: |
| 9868 | case NVPTX::BI__nvvm_ldg_l: |
| 9869 | case NVPTX::BI__nvvm_ldg_ll: |
| 9870 | case NVPTX::BI__nvvm_ldg_ll2: |
| 9871 | case NVPTX::BI__nvvm_ldg_uc: |
| 9872 | case NVPTX::BI__nvvm_ldg_uc2: |
| 9873 | case NVPTX::BI__nvvm_ldg_uc4: |
| 9874 | case NVPTX::BI__nvvm_ldg_us: |
| 9875 | case NVPTX::BI__nvvm_ldg_us2: |
| 9876 | case NVPTX::BI__nvvm_ldg_us4: |
| 9877 | case NVPTX::BI__nvvm_ldg_ui: |
| 9878 | case NVPTX::BI__nvvm_ldg_ui2: |
| 9879 | case NVPTX::BI__nvvm_ldg_ui4: |
| 9880 | case NVPTX::BI__nvvm_ldg_ul: |
| 9881 | case NVPTX::BI__nvvm_ldg_ull: |
| 9882 | case NVPTX::BI__nvvm_ldg_ull2: |
| 9883 | // PTX Interoperability section 2.2: "For a vector with an even number of |
| 9884 | // elements, its alignment is set to number of elements times the alignment |
| 9885 | // of its member: n*alignof(t)." |
| 9886 | return MakeLdg(Intrinsic::nvvm_ldg_global_i); |
| 9887 | case NVPTX::BI__nvvm_ldg_f: |
| 9888 | case NVPTX::BI__nvvm_ldg_f2: |
| 9889 | case NVPTX::BI__nvvm_ldg_f4: |
| 9890 | case NVPTX::BI__nvvm_ldg_d: |
| 9891 | case NVPTX::BI__nvvm_ldg_d2: |
| 9892 | return MakeLdg(Intrinsic::nvvm_ldg_global_f); |
Artem Belevich | fda9905 | 2016-09-28 17:47:35 +0000 | [diff] [blame] | 9893 | |
| 9894 | case NVPTX::BI__nvvm_atom_cta_add_gen_i: |
| 9895 | case NVPTX::BI__nvvm_atom_cta_add_gen_l: |
| 9896 | case NVPTX::BI__nvvm_atom_cta_add_gen_ll: |
| 9897 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_cta); |
| 9898 | case NVPTX::BI__nvvm_atom_sys_add_gen_i: |
| 9899 | case NVPTX::BI__nvvm_atom_sys_add_gen_l: |
| 9900 | case NVPTX::BI__nvvm_atom_sys_add_gen_ll: |
| 9901 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_sys); |
| 9902 | case NVPTX::BI__nvvm_atom_cta_add_gen_f: |
| 9903 | case NVPTX::BI__nvvm_atom_cta_add_gen_d: |
| 9904 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_cta); |
| 9905 | case NVPTX::BI__nvvm_atom_sys_add_gen_f: |
| 9906 | case NVPTX::BI__nvvm_atom_sys_add_gen_d: |
| 9907 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_sys); |
| 9908 | case NVPTX::BI__nvvm_atom_cta_xchg_gen_i: |
| 9909 | case NVPTX::BI__nvvm_atom_cta_xchg_gen_l: |
| 9910 | case NVPTX::BI__nvvm_atom_cta_xchg_gen_ll: |
| 9911 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_cta); |
| 9912 | case NVPTX::BI__nvvm_atom_sys_xchg_gen_i: |
| 9913 | case NVPTX::BI__nvvm_atom_sys_xchg_gen_l: |
| 9914 | case NVPTX::BI__nvvm_atom_sys_xchg_gen_ll: |
| 9915 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_sys); |
| 9916 | case NVPTX::BI__nvvm_atom_cta_max_gen_i: |
| 9917 | case NVPTX::BI__nvvm_atom_cta_max_gen_ui: |
| 9918 | case NVPTX::BI__nvvm_atom_cta_max_gen_l: |
| 9919 | case NVPTX::BI__nvvm_atom_cta_max_gen_ul: |
| 9920 | case NVPTX::BI__nvvm_atom_cta_max_gen_ll: |
| 9921 | case NVPTX::BI__nvvm_atom_cta_max_gen_ull: |
| 9922 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_cta); |
| 9923 | case NVPTX::BI__nvvm_atom_sys_max_gen_i: |
| 9924 | case NVPTX::BI__nvvm_atom_sys_max_gen_ui: |
| 9925 | case NVPTX::BI__nvvm_atom_sys_max_gen_l: |
| 9926 | case NVPTX::BI__nvvm_atom_sys_max_gen_ul: |
| 9927 | case NVPTX::BI__nvvm_atom_sys_max_gen_ll: |
| 9928 | case NVPTX::BI__nvvm_atom_sys_max_gen_ull: |
| 9929 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_sys); |
| 9930 | case NVPTX::BI__nvvm_atom_cta_min_gen_i: |
| 9931 | case NVPTX::BI__nvvm_atom_cta_min_gen_ui: |
| 9932 | case NVPTX::BI__nvvm_atom_cta_min_gen_l: |
| 9933 | case NVPTX::BI__nvvm_atom_cta_min_gen_ul: |
| 9934 | case NVPTX::BI__nvvm_atom_cta_min_gen_ll: |
| 9935 | case NVPTX::BI__nvvm_atom_cta_min_gen_ull: |
| 9936 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_cta); |
| 9937 | case NVPTX::BI__nvvm_atom_sys_min_gen_i: |
| 9938 | case NVPTX::BI__nvvm_atom_sys_min_gen_ui: |
| 9939 | case NVPTX::BI__nvvm_atom_sys_min_gen_l: |
| 9940 | case NVPTX::BI__nvvm_atom_sys_min_gen_ul: |
| 9941 | case NVPTX::BI__nvvm_atom_sys_min_gen_ll: |
| 9942 | case NVPTX::BI__nvvm_atom_sys_min_gen_ull: |
| 9943 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_sys); |
| 9944 | case NVPTX::BI__nvvm_atom_cta_inc_gen_ui: |
| 9945 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_cta); |
| 9946 | case NVPTX::BI__nvvm_atom_cta_dec_gen_ui: |
| 9947 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_cta); |
| 9948 | case NVPTX::BI__nvvm_atom_sys_inc_gen_ui: |
| 9949 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_sys); |
| 9950 | case NVPTX::BI__nvvm_atom_sys_dec_gen_ui: |
| 9951 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_sys); |
| 9952 | case NVPTX::BI__nvvm_atom_cta_and_gen_i: |
| 9953 | case NVPTX::BI__nvvm_atom_cta_and_gen_l: |
| 9954 | case NVPTX::BI__nvvm_atom_cta_and_gen_ll: |
| 9955 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_cta); |
| 9956 | case NVPTX::BI__nvvm_atom_sys_and_gen_i: |
| 9957 | case NVPTX::BI__nvvm_atom_sys_and_gen_l: |
| 9958 | case NVPTX::BI__nvvm_atom_sys_and_gen_ll: |
| 9959 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_sys); |
| 9960 | case NVPTX::BI__nvvm_atom_cta_or_gen_i: |
| 9961 | case NVPTX::BI__nvvm_atom_cta_or_gen_l: |
| 9962 | case NVPTX::BI__nvvm_atom_cta_or_gen_ll: |
| 9963 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_cta); |
| 9964 | case NVPTX::BI__nvvm_atom_sys_or_gen_i: |
| 9965 | case NVPTX::BI__nvvm_atom_sys_or_gen_l: |
| 9966 | case NVPTX::BI__nvvm_atom_sys_or_gen_ll: |
| 9967 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_sys); |
| 9968 | case NVPTX::BI__nvvm_atom_cta_xor_gen_i: |
| 9969 | case NVPTX::BI__nvvm_atom_cta_xor_gen_l: |
| 9970 | case NVPTX::BI__nvvm_atom_cta_xor_gen_ll: |
| 9971 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_cta); |
| 9972 | case NVPTX::BI__nvvm_atom_sys_xor_gen_i: |
| 9973 | case NVPTX::BI__nvvm_atom_sys_xor_gen_l: |
| 9974 | case NVPTX::BI__nvvm_atom_sys_xor_gen_ll: |
| 9975 | return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys); |
| 9976 | case NVPTX::BI__nvvm_atom_cta_cas_gen_i: |
| 9977 | case NVPTX::BI__nvvm_atom_cta_cas_gen_l: |
| 9978 | case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: { |
| 9979 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9980 | return Builder.CreateCall( |
| 9981 | CGM.getIntrinsic( |
| 9982 | Intrinsic::nvvm_atomic_cas_gen_i_cta, |
| 9983 | {Ptr->getType()->getPointerElementType(), Ptr->getType()}), |
| 9984 | {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))}); |
| 9985 | } |
| 9986 | case NVPTX::BI__nvvm_atom_sys_cas_gen_i: |
| 9987 | case NVPTX::BI__nvvm_atom_sys_cas_gen_l: |
| 9988 | case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: { |
| 9989 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 9990 | return Builder.CreateCall( |
| 9991 | CGM.getIntrinsic( |
| 9992 | Intrinsic::nvvm_atomic_cas_gen_i_sys, |
| 9993 | {Ptr->getType()->getPointerElementType(), Ptr->getType()}), |
| 9994 | {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))}); |
| 9995 | } |
Artem Belevich | bab95c7 | 2017-09-26 17:07:23 +0000 | [diff] [blame] | 9996 | case NVPTX::BI__nvvm_match_all_sync_i32p: |
| 9997 | case NVPTX::BI__nvvm_match_all_sync_i64p: { |
| 9998 | Value *Mask = EmitScalarExpr(E->getArg(0)); |
| 9999 | Value *Val = EmitScalarExpr(E->getArg(1)); |
| 10000 | Address PredOutPtr = EmitPointerWithAlignment(E->getArg(2)); |
| 10001 | Value *ResultPair = Builder.CreateCall( |
| 10002 | CGM.getIntrinsic(BuiltinID == NVPTX::BI__nvvm_match_all_sync_i32p |
| 10003 | ? Intrinsic::nvvm_match_all_sync_i32p |
| 10004 | : Intrinsic::nvvm_match_all_sync_i64p), |
| 10005 | {Mask, Val}); |
| 10006 | Value *Pred = Builder.CreateZExt(Builder.CreateExtractValue(ResultPair, 1), |
| 10007 | PredOutPtr.getElementType()); |
| 10008 | Builder.CreateStore(Pred, PredOutPtr); |
| 10009 | return Builder.CreateExtractValue(ResultPair, 0); |
| 10010 | } |
Artem Belevich | 91cc00b | 2017-10-12 21:32:19 +0000 | [diff] [blame] | 10011 | case NVPTX::BI__hmma_m16n16k16_ld_a: |
| 10012 | case NVPTX::BI__hmma_m16n16k16_ld_b: |
| 10013 | case NVPTX::BI__hmma_m16n16k16_ld_c_f16: |
| 10014 | case NVPTX::BI__hmma_m16n16k16_ld_c_f32: { |
| 10015 | Address Dst = EmitPointerWithAlignment(E->getArg(0)); |
| 10016 | Value *Src = EmitScalarExpr(E->getArg(1)); |
| 10017 | Value *Ldm = EmitScalarExpr(E->getArg(2)); |
| 10018 | llvm::APSInt isColMajorArg; |
| 10019 | if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext())) |
| 10020 | return nullptr; |
| 10021 | bool isColMajor = isColMajorArg.getSExtValue(); |
| 10022 | unsigned IID; |
| 10023 | unsigned NumResults; |
| 10024 | switch (BuiltinID) { |
| 10025 | case NVPTX::BI__hmma_m16n16k16_ld_a: |
| 10026 | IID = isColMajor ? Intrinsic::nvvm_wmma_load_a_f16_col_stride |
| 10027 | : Intrinsic::nvvm_wmma_load_a_f16_row_stride; |
| 10028 | NumResults = 8; |
| 10029 | break; |
| 10030 | case NVPTX::BI__hmma_m16n16k16_ld_b: |
| 10031 | IID = isColMajor ? Intrinsic::nvvm_wmma_load_b_f16_col_stride |
| 10032 | : Intrinsic::nvvm_wmma_load_b_f16_row_stride; |
| 10033 | NumResults = 8; |
| 10034 | break; |
| 10035 | case NVPTX::BI__hmma_m16n16k16_ld_c_f16: |
| 10036 | IID = isColMajor ? Intrinsic::nvvm_wmma_load_c_f16_col_stride |
| 10037 | : Intrinsic::nvvm_wmma_load_c_f16_row_stride; |
| 10038 | NumResults = 4; |
| 10039 | break; |
| 10040 | case NVPTX::BI__hmma_m16n16k16_ld_c_f32: |
| 10041 | IID = isColMajor ? Intrinsic::nvvm_wmma_load_c_f32_col_stride |
| 10042 | : Intrinsic::nvvm_wmma_load_c_f32_row_stride; |
| 10043 | NumResults = 8; |
| 10044 | break; |
| 10045 | default: |
| 10046 | llvm_unreachable("Unexpected builtin ID."); |
| 10047 | } |
| 10048 | Value *Result = |
| 10049 | Builder.CreateCall(CGM.getIntrinsic(IID), |
| 10050 | {Builder.CreatePointerCast(Src, VoidPtrTy), Ldm}); |
| 10051 | |
| 10052 | // Save returned values. |
| 10053 | for (unsigned i = 0; i < NumResults; ++i) { |
| 10054 | Builder.CreateAlignedStore( |
| 10055 | Builder.CreateBitCast(Builder.CreateExtractValue(Result, i), |
| 10056 | Dst.getElementType()), |
| 10057 | Builder.CreateGEP(Dst.getPointer(), llvm::ConstantInt::get(IntTy, i)), |
| 10058 | CharUnits::fromQuantity(4)); |
| 10059 | } |
| 10060 | return Result; |
| 10061 | } |
| 10062 | |
| 10063 | case NVPTX::BI__hmma_m16n16k16_st_c_f16: |
| 10064 | case NVPTX::BI__hmma_m16n16k16_st_c_f32: { |
| 10065 | Value *Dst = EmitScalarExpr(E->getArg(0)); |
| 10066 | Address Src = EmitPointerWithAlignment(E->getArg(1)); |
| 10067 | Value *Ldm = EmitScalarExpr(E->getArg(2)); |
| 10068 | llvm::APSInt isColMajorArg; |
| 10069 | if (!E->getArg(3)->isIntegerConstantExpr(isColMajorArg, getContext())) |
| 10070 | return nullptr; |
| 10071 | bool isColMajor = isColMajorArg.getSExtValue(); |
| 10072 | unsigned IID; |
| 10073 | unsigned NumResults = 8; |
| 10074 | // PTX Instructions (and LLVM instrinsics) are defined for slice _d_, yet |
| 10075 | // for some reason nvcc builtins use _c_. |
| 10076 | switch (BuiltinID) { |
| 10077 | case NVPTX::BI__hmma_m16n16k16_st_c_f16: |
| 10078 | IID = isColMajor ? Intrinsic::nvvm_wmma_store_d_f16_col_stride |
| 10079 | : Intrinsic::nvvm_wmma_store_d_f16_row_stride; |
| 10080 | NumResults = 4; |
| 10081 | break; |
| 10082 | case NVPTX::BI__hmma_m16n16k16_st_c_f32: |
| 10083 | IID = isColMajor ? Intrinsic::nvvm_wmma_store_d_f32_col_stride |
| 10084 | : Intrinsic::nvvm_wmma_store_d_f32_row_stride; |
| 10085 | break; |
| 10086 | default: |
| 10087 | llvm_unreachable("Unexpected builtin ID."); |
| 10088 | } |
| 10089 | Function *Intrinsic = CGM.getIntrinsic(IID); |
| 10090 | llvm::Type *ParamType = Intrinsic->getFunctionType()->getParamType(1); |
| 10091 | SmallVector<Value *, 10> Values; |
| 10092 | Values.push_back(Builder.CreatePointerCast(Dst, VoidPtrTy)); |
| 10093 | for (unsigned i = 0; i < NumResults; ++i) { |
| 10094 | Value *V = Builder.CreateAlignedLoad( |
| 10095 | Builder.CreateGEP(Src.getPointer(), llvm::ConstantInt::get(IntTy, i)), |
| 10096 | CharUnits::fromQuantity(4)); |
| 10097 | Values.push_back(Builder.CreateBitCast(V, ParamType)); |
| 10098 | } |
| 10099 | Values.push_back(Ldm); |
| 10100 | Value *Result = Builder.CreateCall(Intrinsic, Values); |
| 10101 | return Result; |
| 10102 | } |
| 10103 | |
| 10104 | // BI__hmma_m16n16k16_mma_<Dtype><CType>(d, a, b, c, layout, satf) |
| 10105 | // --> Intrinsic::nvvm_wmma_mma_sync<layout A,B><DType><CType><Satf> |
| 10106 | case NVPTX::BI__hmma_m16n16k16_mma_f16f16: |
| 10107 | case NVPTX::BI__hmma_m16n16k16_mma_f32f16: |
| 10108 | case NVPTX::BI__hmma_m16n16k16_mma_f32f32: |
| 10109 | case NVPTX::BI__hmma_m16n16k16_mma_f16f32: { |
| 10110 | Address Dst = EmitPointerWithAlignment(E->getArg(0)); |
| 10111 | Address SrcA = EmitPointerWithAlignment(E->getArg(1)); |
| 10112 | Address SrcB = EmitPointerWithAlignment(E->getArg(2)); |
| 10113 | Address SrcC = EmitPointerWithAlignment(E->getArg(3)); |
| 10114 | llvm::APSInt LayoutArg; |
| 10115 | if (!E->getArg(4)->isIntegerConstantExpr(LayoutArg, getContext())) |
| 10116 | return nullptr; |
| 10117 | int Layout = LayoutArg.getSExtValue(); |
| 10118 | if (Layout < 0 || Layout > 3) |
| 10119 | return nullptr; |
| 10120 | llvm::APSInt SatfArg; |
| 10121 | if (!E->getArg(5)->isIntegerConstantExpr(SatfArg, getContext())) |
| 10122 | return nullptr; |
| 10123 | bool Satf = SatfArg.getSExtValue(); |
| 10124 | |
| 10125 | // clang-format off |
| 10126 | #define MMA_VARIANTS(type) {{ \ |
| 10127 | Intrinsic::nvvm_wmma_mma_sync_row_row_##type, \ |
| 10128 | Intrinsic::nvvm_wmma_mma_sync_row_row_##type##_satfinite, \ |
| 10129 | Intrinsic::nvvm_wmma_mma_sync_row_col_##type, \ |
| 10130 | Intrinsic::nvvm_wmma_mma_sync_row_col_##type##_satfinite, \ |
| 10131 | Intrinsic::nvvm_wmma_mma_sync_col_row_##type, \ |
| 10132 | Intrinsic::nvvm_wmma_mma_sync_col_row_##type##_satfinite, \ |
| 10133 | Intrinsic::nvvm_wmma_mma_sync_col_col_##type, \ |
| 10134 | Intrinsic::nvvm_wmma_mma_sync_col_col_##type##_satfinite \ |
| 10135 | }} |
| 10136 | // clang-format on |
| 10137 | |
| 10138 | auto getMMAIntrinsic = [Layout, Satf](std::array<unsigned, 8> Variants) { |
| 10139 | unsigned Index = Layout * 2 + Satf; |
| 10140 | assert(Index < 8); |
| 10141 | return Variants[Index]; |
| 10142 | }; |
| 10143 | unsigned IID; |
| 10144 | unsigned NumEltsC; |
| 10145 | unsigned NumEltsD; |
| 10146 | switch (BuiltinID) { |
| 10147 | case NVPTX::BI__hmma_m16n16k16_mma_f16f16: |
| 10148 | IID = getMMAIntrinsic(MMA_VARIANTS(f16_f16)); |
| 10149 | NumEltsC = 4; |
| 10150 | NumEltsD = 4; |
| 10151 | break; |
| 10152 | case NVPTX::BI__hmma_m16n16k16_mma_f32f16: |
| 10153 | IID = getMMAIntrinsic(MMA_VARIANTS(f32_f16)); |
| 10154 | NumEltsC = 4; |
| 10155 | NumEltsD = 8; |
| 10156 | break; |
| 10157 | case NVPTX::BI__hmma_m16n16k16_mma_f16f32: |
| 10158 | IID = getMMAIntrinsic(MMA_VARIANTS(f16_f32)); |
| 10159 | NumEltsC = 8; |
| 10160 | NumEltsD = 4; |
| 10161 | break; |
| 10162 | case NVPTX::BI__hmma_m16n16k16_mma_f32f32: |
| 10163 | IID = getMMAIntrinsic(MMA_VARIANTS(f32_f32)); |
| 10164 | NumEltsC = 8; |
| 10165 | NumEltsD = 8; |
| 10166 | break; |
| 10167 | default: |
| 10168 | llvm_unreachable("Unexpected builtin ID."); |
| 10169 | } |
| 10170 | #undef MMA_VARIANTS |
| 10171 | |
| 10172 | SmallVector<Value *, 24> Values; |
| 10173 | Function *Intrinsic = CGM.getIntrinsic(IID); |
| 10174 | llvm::Type *ABType = Intrinsic->getFunctionType()->getParamType(0); |
| 10175 | // Load A |
| 10176 | for (unsigned i = 0; i < 8; ++i) { |
| 10177 | Value *V = Builder.CreateAlignedLoad( |
| 10178 | Builder.CreateGEP(SrcA.getPointer(), |
| 10179 | llvm::ConstantInt::get(IntTy, i)), |
| 10180 | CharUnits::fromQuantity(4)); |
| 10181 | Values.push_back(Builder.CreateBitCast(V, ABType)); |
| 10182 | } |
| 10183 | // Load B |
| 10184 | for (unsigned i = 0; i < 8; ++i) { |
| 10185 | Value *V = Builder.CreateAlignedLoad( |
| 10186 | Builder.CreateGEP(SrcB.getPointer(), |
| 10187 | llvm::ConstantInt::get(IntTy, i)), |
| 10188 | CharUnits::fromQuantity(4)); |
| 10189 | Values.push_back(Builder.CreateBitCast(V, ABType)); |
| 10190 | } |
| 10191 | // Load C |
| 10192 | llvm::Type *CType = Intrinsic->getFunctionType()->getParamType(16); |
| 10193 | for (unsigned i = 0; i < NumEltsC; ++i) { |
| 10194 | Value *V = Builder.CreateAlignedLoad( |
| 10195 | Builder.CreateGEP(SrcC.getPointer(), |
| 10196 | llvm::ConstantInt::get(IntTy, i)), |
| 10197 | CharUnits::fromQuantity(4)); |
| 10198 | Values.push_back(Builder.CreateBitCast(V, CType)); |
| 10199 | } |
| 10200 | Value *Result = Builder.CreateCall(Intrinsic, Values); |
| 10201 | llvm::Type *DType = Dst.getElementType(); |
| 10202 | for (unsigned i = 0; i < NumEltsD; ++i) |
| 10203 | Builder.CreateAlignedStore( |
| 10204 | Builder.CreateBitCast(Builder.CreateExtractValue(Result, i), DType), |
| 10205 | Builder.CreateGEP(Dst.getPointer(), llvm::ConstantInt::get(IntTy, i)), |
| 10206 | CharUnits::fromQuantity(4)); |
| 10207 | return Result; |
| 10208 | } |
Artem Belevich | d21e5c6 | 2015-06-25 18:29:42 +0000 | [diff] [blame] | 10209 | default: |
| 10210 | return nullptr; |
| 10211 | } |
| 10212 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 10213 | |
| 10214 | Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, |
| 10215 | const CallExpr *E) { |
| 10216 | switch (BuiltinID) { |
Derek Schuff | dbd24b4 | 2016-05-02 17:26:19 +0000 | [diff] [blame] | 10217 | case WebAssembly::BI__builtin_wasm_current_memory: { |
Dan Gohman | d4c5fb5 | 2015-10-02 19:38:47 +0000 | [diff] [blame] | 10218 | llvm::Type *ResultType = ConvertType(E->getType()); |
Derek Schuff | dbd24b4 | 2016-05-02 17:26:19 +0000 | [diff] [blame] | 10219 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_current_memory, ResultType); |
Dan Gohman | d4c5fb5 | 2015-10-02 19:38:47 +0000 | [diff] [blame] | 10220 | return Builder.CreateCall(Callee); |
| 10221 | } |
Dan Gohman | 24f0a08 | 2015-11-05 20:16:37 +0000 | [diff] [blame] | 10222 | case WebAssembly::BI__builtin_wasm_grow_memory: { |
Dan Gohman | 266b38a | 2015-10-02 20:20:01 +0000 | [diff] [blame] | 10223 | Value *X = EmitScalarExpr(E->getArg(0)); |
Dan Gohman | 24f0a08 | 2015-11-05 20:16:37 +0000 | [diff] [blame] | 10224 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_grow_memory, X->getType()); |
Dan Gohman | 266b38a | 2015-10-02 20:20:01 +0000 | [diff] [blame] | 10225 | return Builder.CreateCall(Callee, X); |
| 10226 | } |
Heejin Ahn | b92440e | 2017-06-30 00:44:01 +0000 | [diff] [blame] | 10227 | case WebAssembly::BI__builtin_wasm_throw: { |
| 10228 | Value *Tag = EmitScalarExpr(E->getArg(0)); |
| 10229 | Value *Obj = EmitScalarExpr(E->getArg(1)); |
| 10230 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_throw); |
| 10231 | return Builder.CreateCall(Callee, {Tag, Obj}); |
| 10232 | } |
Heejin Ahn | b29a17b | 2017-09-16 01:07:43 +0000 | [diff] [blame] | 10233 | case WebAssembly::BI__builtin_wasm_rethrow: { |
| 10234 | Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_rethrow); |
| 10235 | return Builder.CreateCall(Callee); |
| 10236 | } |
Dan Gohman | c285307 | 2015-09-03 22:51:53 +0000 | [diff] [blame] | 10237 | |
| 10238 | default: |
| 10239 | return nullptr; |
| 10240 | } |
| 10241 | } |
Krzysztof Parzyszek | 5a65583 | 2017-12-13 19:56:03 +0000 | [diff] [blame] | 10242 | |
| 10243 | Value *CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID, |
| 10244 | const CallExpr *E) { |
| 10245 | SmallVector<llvm::Value *, 4> Ops; |
| 10246 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 10247 | |
| 10248 | switch (BuiltinID) { |
| 10249 | case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry: |
| 10250 | case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry_128B: { |
| 10251 | Address Dest = EmitPointerWithAlignment(E->getArg(2)); |
| 10252 | unsigned Size; |
| 10253 | if (BuiltinID == Hexagon::BI__builtin_HEXAGON_V6_vaddcarry) { |
| 10254 | Size = 512; |
| 10255 | ID = Intrinsic::hexagon_V6_vaddcarry; |
| 10256 | } else { |
| 10257 | Size = 1024; |
| 10258 | ID = Intrinsic::hexagon_V6_vaddcarry_128B; |
| 10259 | } |
| 10260 | Dest = Builder.CreateBitCast(Dest, |
| 10261 | llvm::VectorType::get(Builder.getInt1Ty(), Size)->getPointerTo(0)); |
| 10262 | LoadInst *QLd = Builder.CreateLoad(Dest); |
| 10263 | Ops = { EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1)), QLd }; |
| 10264 | llvm::Value *Result = Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 10265 | llvm::Value *Vprd = Builder.CreateExtractValue(Result, 1); |
| 10266 | llvm::Value *Base = Builder.CreateBitCast(EmitScalarExpr(E->getArg(2)), |
| 10267 | Vprd->getType()->getPointerTo(0)); |
| 10268 | Builder.CreateAlignedStore(Vprd, Base, Dest.getAlignment()); |
| 10269 | return Builder.CreateExtractValue(Result, 0); |
| 10270 | } |
| 10271 | case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry: |
| 10272 | case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B: { |
| 10273 | Address Dest = EmitPointerWithAlignment(E->getArg(2)); |
| 10274 | unsigned Size; |
| 10275 | if (BuiltinID == Hexagon::BI__builtin_HEXAGON_V6_vsubcarry) { |
| 10276 | Size = 512; |
| 10277 | ID = Intrinsic::hexagon_V6_vsubcarry; |
| 10278 | } else { |
| 10279 | Size = 1024; |
| 10280 | ID = Intrinsic::hexagon_V6_vsubcarry_128B; |
| 10281 | } |
| 10282 | Dest = Builder.CreateBitCast(Dest, |
| 10283 | llvm::VectorType::get(Builder.getInt1Ty(), Size)->getPointerTo(0)); |
| 10284 | LoadInst *QLd = Builder.CreateLoad(Dest); |
| 10285 | Ops = { EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1)), QLd }; |
| 10286 | llvm::Value *Result = Builder.CreateCall(CGM.getIntrinsic(ID), Ops); |
| 10287 | llvm::Value *Vprd = Builder.CreateExtractValue(Result, 1); |
| 10288 | llvm::Value *Base = Builder.CreateBitCast(EmitScalarExpr(E->getArg(2)), |
| 10289 | Vprd->getType()->getPointerTo(0)); |
| 10290 | Builder.CreateAlignedStore(Vprd, Base, Dest.getAlignment()); |
| 10291 | return Builder.CreateExtractValue(Result, 0); |
| 10292 | } |
| 10293 | } // switch |
| 10294 | |
| 10295 | return nullptr; |
| 10296 | } |