blob: 3e5a6772ebb72067e38d7008d3e2a401a6f16d40 [file] [log] [blame]
Anders Carlsson022012e2007-08-20 18:05:56 +00001//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Anders Carlsson022012e2007-08-20 18:05:56 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This contains code to emit Builtin calls as LLVM code.
11//
12//===----------------------------------------------------------------------===//
13
John McCalld0b76ca2010-03-02 03:50:12 +000014#include "TargetInfo.h"
Anders Carlsson022012e2007-08-20 18:05:56 +000015#include "CodeGenFunction.h"
16#include "CodeGenModule.h"
Fariborz Jahanian55bcace2010-06-15 22:44:06 +000017#include "CGObjCRuntime.h"
Anders Carlssonca6fcfa2007-12-09 21:20:04 +000018#include "clang/Basic/TargetInfo.h"
Chris Lattnerbef20ac2007-08-31 04:31:45 +000019#include "clang/AST/ASTContext.h"
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +000020#include "clang/AST/Decl.h"
Chris Lattner6b15cdc2009-06-14 01:05:48 +000021#include "clang/Basic/TargetBuiltins.h"
Anders Carlsson793680e2007-10-12 23:56:29 +000022#include "llvm/Intrinsics.h"
John McCalld0b76ca2010-03-02 03:50:12 +000023#include "llvm/Target/TargetData.h"
Jakub Staszak558229f2011-07-08 22:45:14 +000024
Anders Carlsson022012e2007-08-20 18:05:56 +000025using namespace clang;
26using namespace CodeGen;
Anders Carlssonca6fcfa2007-12-09 21:20:04 +000027using namespace llvm;
28
John McCalla45680b2011-09-13 23:05:03 +000029/// getBuiltinLibFunction - Given a builtin id for a function like
30/// "__builtin_fabsf", return a Function* for "fabsf".
31llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
32 unsigned BuiltinID) {
33 assert(Context.BuiltinInfo.isLibFunction(BuiltinID));
34
35 // Get the name, skip over the __builtin_ prefix (if necessary).
36 StringRef Name;
37 GlobalDecl D(FD);
38
39 // If the builtin has been declared explicitly with an assembler label,
40 // use the mangled name. This differs from the plain label on platforms
41 // that prefix labels.
42 if (FD->hasAttr<AsmLabelAttr>())
43 Name = getMangledName(D);
44 else
45 Name = Context.BuiltinInfo.GetName(BuiltinID) + 10;
46
47 llvm::FunctionType *Ty =
48 cast<llvm::FunctionType>(getTypes().ConvertType(FD->getType()));
49
50 return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable=*/false);
51}
52
John McCall26815d92010-10-27 20:58:56 +000053/// Emit the conversions required to turn the given value into an
54/// integer of the given size.
55static Value *EmitToInt(CodeGenFunction &CGF, llvm::Value *V,
Chris Lattner2acc6e32011-07-18 04:24:23 +000056 QualType T, llvm::IntegerType *IntType) {
John McCall26815d92010-10-27 20:58:56 +000057 V = CGF.EmitToMemory(V, T);
Chris Lattnera1aa9e32010-10-01 23:43:16 +000058
John McCall26815d92010-10-27 20:58:56 +000059 if (V->getType()->isPointerTy())
60 return CGF.Builder.CreatePtrToInt(V, IntType);
61
62 assert(V->getType() == IntType);
63 return V;
Chandler Carruthdb4325b2010-07-18 07:23:17 +000064}
65
John McCall26815d92010-10-27 20:58:56 +000066static Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V,
Chris Lattner2acc6e32011-07-18 04:24:23 +000067 QualType T, llvm::Type *ResultType) {
John McCall26815d92010-10-27 20:58:56 +000068 V = CGF.EmitFromMemory(V, T);
69
70 if (ResultType->isPointerTy())
71 return CGF.Builder.CreateIntToPtr(V, ResultType);
72
73 assert(V->getType() == ResultType);
74 return V;
Chandler Carruthdb4325b2010-07-18 07:23:17 +000075}
76
Daniel Dunbar0002d232009-04-07 00:55:51 +000077/// Utility to insert an atomic instruction based on Instrinsic::ID
78/// and the expression node.
Daniel Dunbarcb61a7b2010-03-20 07:04:11 +000079static RValue EmitBinaryAtomic(CodeGenFunction &CGF,
Eli Friedmanc83b9752011-09-07 01:41:24 +000080 llvm::AtomicRMWInst::BinOp Kind,
81 const CallExpr *E) {
John McCall26815d92010-10-27 20:58:56 +000082 QualType T = E->getType();
83 assert(E->getArg(0)->getType()->isPointerType());
84 assert(CGF.getContext().hasSameUnqualifiedType(T,
85 E->getArg(0)->getType()->getPointeeType()));
86 assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
87
Chris Lattner4f209442010-09-21 23:40:48 +000088 llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
89 unsigned AddrSpace =
90 cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
John McCall789a1592010-10-26 22:09:15 +000091
Chris Lattner9cbe4f02011-07-09 17:41:47 +000092 llvm::IntegerType *IntType =
John McCall26815d92010-10-27 20:58:56 +000093 llvm::IntegerType::get(CGF.getLLVMContext(),
94 CGF.getContext().getTypeSize(T));
Chris Lattner9cbe4f02011-07-09 17:41:47 +000095 llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace);
John McCall26815d92010-10-27 20:58:56 +000096
John McCall26815d92010-10-27 20:58:56 +000097 llvm::Value *Args[2];
98 Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
99 Args[1] = CGF.EmitScalarExpr(E->getArg(1));
Chris Lattner2acc6e32011-07-18 04:24:23 +0000100 llvm::Type *ValueType = Args[1]->getType();
John McCall26815d92010-10-27 20:58:56 +0000101 Args[1] = EmitToInt(CGF, Args[1], T, IntType);
102
Eli Friedmanc83b9752011-09-07 01:41:24 +0000103 llvm::Value *Result =
104 CGF.Builder.CreateAtomicRMW(Kind, Args[0], Args[1],
105 llvm::SequentiallyConsistent);
John McCall26815d92010-10-27 20:58:56 +0000106 Result = EmitFromInt(CGF, Result, T, ValueType);
107 return RValue::get(Result);
Daniel Dunbar0002d232009-04-07 00:55:51 +0000108}
109
110/// Utility to insert an atomic instruction based Instrinsic::ID and
John McCall26815d92010-10-27 20:58:56 +0000111/// the expression node, where the return value is the result of the
112/// operation.
Chris Lattner420b1182010-05-06 05:35:16 +0000113static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF,
Eli Friedmanc83b9752011-09-07 01:41:24 +0000114 llvm::AtomicRMWInst::BinOp Kind,
115 const CallExpr *E,
Daniel Dunbar0002d232009-04-07 00:55:51 +0000116 Instruction::BinaryOps Op) {
John McCall26815d92010-10-27 20:58:56 +0000117 QualType T = E->getType();
118 assert(E->getArg(0)->getType()->isPointerType());
119 assert(CGF.getContext().hasSameUnqualifiedType(T,
120 E->getArg(0)->getType()->getPointeeType()));
121 assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
122
Chris Lattner4f209442010-09-21 23:40:48 +0000123 llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
124 unsigned AddrSpace =
125 cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
John McCall789a1592010-10-26 22:09:15 +0000126
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000127 llvm::IntegerType *IntType =
John McCall26815d92010-10-27 20:58:56 +0000128 llvm::IntegerType::get(CGF.getLLVMContext(),
129 CGF.getContext().getTypeSize(T));
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000130 llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace);
John McCall26815d92010-10-27 20:58:56 +0000131
John McCall26815d92010-10-27 20:58:56 +0000132 llvm::Value *Args[2];
133 Args[1] = CGF.EmitScalarExpr(E->getArg(1));
Chris Lattner2acc6e32011-07-18 04:24:23 +0000134 llvm::Type *ValueType = Args[1]->getType();
John McCall26815d92010-10-27 20:58:56 +0000135 Args[1] = EmitToInt(CGF, Args[1], T, IntType);
136 Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
137
Eli Friedmanc83b9752011-09-07 01:41:24 +0000138 llvm::Value *Result =
139 CGF.Builder.CreateAtomicRMW(Kind, Args[0], Args[1],
140 llvm::SequentiallyConsistent);
John McCall26815d92010-10-27 20:58:56 +0000141 Result = CGF.Builder.CreateBinOp(Op, Result, Args[1]);
142 Result = EmitFromInt(CGF, Result, T, ValueType);
143 return RValue::get(Result);
Mon P Wang1ffe2812008-05-09 22:40:52 +0000144}
145
Chris Lattner420b1182010-05-06 05:35:16 +0000146/// EmitFAbs - Emit a call to fabs/fabsf/fabsl, depending on the type of ValTy,
147/// which must be a scalar floating point type.
148static Value *EmitFAbs(CodeGenFunction &CGF, Value *V, QualType ValTy) {
149 const BuiltinType *ValTyP = ValTy->getAs<BuiltinType>();
150 assert(ValTyP && "isn't scalar fp type!");
151
152 StringRef FnName;
153 switch (ValTyP->getKind()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000154 default: llvm_unreachable("Isn't a scalar fp type!");
Chris Lattner420b1182010-05-06 05:35:16 +0000155 case BuiltinType::Float: FnName = "fabsf"; break;
156 case BuiltinType::Double: FnName = "fabs"; break;
157 case BuiltinType::LongDouble: FnName = "fabsl"; break;
158 }
159
160 // The prototype is something that takes and returns whatever V's type is.
Jay Foadda549e82011-07-29 13:56:53 +0000161 llvm::FunctionType *FT = llvm::FunctionType::get(V->getType(), V->getType(),
Benjamin Kramer95d318c2011-05-28 14:26:31 +0000162 false);
Chris Lattner420b1182010-05-06 05:35:16 +0000163 llvm::Value *Fn = CGF.CGM.CreateRuntimeFunction(FT, FnName);
164
165 return CGF.Builder.CreateCall(Fn, V, "abs");
166}
167
John McCalla45680b2011-09-13 23:05:03 +0000168static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *Fn,
169 const CallExpr *E, llvm::Value *calleeValue) {
170 return CGF.EmitCall(E->getCallee()->getType(), calleeValue,
171 ReturnValueSlot(), E->arg_begin(), E->arg_end(), Fn);
172}
173
Mike Stump1eb44332009-09-09 15:08:12 +0000174RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000175 unsigned BuiltinID, const CallExpr *E) {
Chris Lattner564ea2a2008-10-06 06:56:41 +0000176 // See if we can constant fold this builtin. If so, don't emit it at all.
Anders Carlssonf35d35a2008-12-01 02:31:41 +0000177 Expr::EvalResult Result;
Eli Friedman52a27f52012-01-06 20:03:09 +0000178 if (E->EvaluateAsRValue(Result, CGM.getContext()) &&
Fariborz Jahaniandd697bc2011-04-25 23:10:07 +0000179 !Result.hasSideEffects()) {
Anders Carlssonf35d35a2008-12-01 02:31:41 +0000180 if (Result.Val.isInt())
John McCalld16c2cf2011-02-08 08:22:06 +0000181 return RValue::get(llvm::ConstantInt::get(getLLVMContext(),
Owen Anderson4a28d5d2009-07-24 23:12:58 +0000182 Result.Val.getInt()));
Chris Lattnera1aa9e32010-10-01 23:43:16 +0000183 if (Result.Val.isFloat())
John McCalld16c2cf2011-02-08 08:22:06 +0000184 return RValue::get(llvm::ConstantFP::get(getLLVMContext(),
185 Result.Val.getFloat()));
Chris Lattner1f329992008-10-06 06:09:18 +0000186 }
Mike Stump1eb44332009-09-09 15:08:12 +0000187
Chris Lattner564ea2a2008-10-06 06:56:41 +0000188 switch (BuiltinID) {
189 default: break; // Handle intrinsics and libm functions below.
Chris Lattner506ff882008-10-06 07:26:43 +0000190 case Builtin::BI__builtin___CFStringMakeConstantString:
David Chisnall0d13f6f2010-01-23 02:40:42 +0000191 case Builtin::BI__builtin___NSStringMakeConstantString:
Anders Carlssone9352cc2009-04-08 04:48:15 +0000192 return RValue::get(CGM.EmitConstantExpr(E, E->getType(), 0));
Chris Lattner6a705f02008-07-09 17:28:44 +0000193 case Builtin::BI__builtin_stdarg_start:
Anders Carlsson793680e2007-10-12 23:56:29 +0000194 case Builtin::BI__builtin_va_start:
195 case Builtin::BI__builtin_va_end: {
Daniel Dunbar07855702009-02-11 22:25:55 +0000196 Value *ArgValue = EmitVAListRef(E->getArg(0));
Chris Lattner2acc6e32011-07-18 04:24:23 +0000197 llvm::Type *DestType = Int8PtrTy;
Anders Carlsson793680e2007-10-12 23:56:29 +0000198 if (ArgValue->getType() != DestType)
Mike Stump1eb44332009-09-09 15:08:12 +0000199 ArgValue = Builder.CreateBitCast(ArgValue, DestType,
Daniel Dunbarb27ffbe2009-07-26 09:28:40 +0000200 ArgValue->getName().data());
Anders Carlsson793680e2007-10-12 23:56:29 +0000201
Mike Stump1eb44332009-09-09 15:08:12 +0000202 Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ?
Chris Lattner6a705f02008-07-09 17:28:44 +0000203 Intrinsic::vaend : Intrinsic::vastart;
Chris Lattner7acda7c2007-12-18 00:25:38 +0000204 return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue));
Anders Carlsson793680e2007-10-12 23:56:29 +0000205 }
Anders Carlssona28ef8b2008-02-09 20:26:43 +0000206 case Builtin::BI__builtin_va_copy: {
Eli Friedman4fd0aa52009-01-20 17:46:04 +0000207 Value *DstPtr = EmitVAListRef(E->getArg(0));
208 Value *SrcPtr = EmitVAListRef(E->getArg(1));
Anders Carlssona28ef8b2008-02-09 20:26:43 +0000209
Chris Lattner2acc6e32011-07-18 04:24:23 +0000210 llvm::Type *Type = Int8PtrTy;
Anders Carlssona28ef8b2008-02-09 20:26:43 +0000211
212 DstPtr = Builder.CreateBitCast(DstPtr, Type);
213 SrcPtr = Builder.CreateBitCast(SrcPtr, Type);
Mike Stump1eb44332009-09-09 15:08:12 +0000214 return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy),
Chris Lattner3eae03e2008-05-06 00:56:42 +0000215 DstPtr, SrcPtr));
Anders Carlssona28ef8b2008-02-09 20:26:43 +0000216 }
Anders Carlssonc2251dc2007-11-20 19:05:17 +0000217 case Builtin::BI__builtin_abs: {
Mike Stump1eb44332009-09-09 15:08:12 +0000218 Value *ArgValue = EmitScalarExpr(E->getArg(0));
219
Chris Lattner9a847f52008-07-23 06:53:34 +0000220 Value *NegOp = Builder.CreateNeg(ArgValue, "neg");
Mike Stump1eb44332009-09-09 15:08:12 +0000221 Value *CmpResult =
222 Builder.CreateICmpSGE(ArgValue,
Owen Andersonc9c88b42009-07-31 20:28:54 +0000223 llvm::Constant::getNullValue(ArgValue->getType()),
Chris Lattner9a847f52008-07-23 06:53:34 +0000224 "abscond");
Mike Stump1eb44332009-09-09 15:08:12 +0000225 Value *Result =
Anders Carlssonc2251dc2007-11-20 19:05:17 +0000226 Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs");
Mike Stump1eb44332009-09-09 15:08:12 +0000227
Anders Carlssonc2251dc2007-11-20 19:05:17 +0000228 return RValue::get(Result);
229 }
Anders Carlsson3a31d602008-02-06 07:19:27 +0000230 case Builtin::BI__builtin_ctz:
231 case Builtin::BI__builtin_ctzl:
232 case Builtin::BI__builtin_ctzll: {
233 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Mike Stump1eb44332009-09-09 15:08:12 +0000234
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000235 llvm::Type *ArgType = ArgValue->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000236 Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
Anders Carlsson3a31d602008-02-06 07:19:27 +0000237
Chris Lattner2acc6e32011-07-18 04:24:23 +0000238 llvm::Type *ResultType = ConvertType(E->getType());
Chandler Carruth50058ec2011-12-12 04:28:35 +0000239 Value *Result = Builder.CreateCall2(F, ArgValue, Builder.getTrue());
Anders Carlsson3a31d602008-02-06 07:19:27 +0000240 if (Result->getType() != ResultType)
Duncan Sandseac73e52009-11-16 13:11:21 +0000241 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
242 "cast");
Anders Carlsson3a31d602008-02-06 07:19:27 +0000243 return RValue::get(Result);
244 }
Eli Friedmanf4e85332008-05-27 15:32:46 +0000245 case Builtin::BI__builtin_clz:
246 case Builtin::BI__builtin_clzl:
247 case Builtin::BI__builtin_clzll: {
248 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Mike Stump1eb44332009-09-09 15:08:12 +0000249
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000250 llvm::Type *ArgType = ArgValue->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000251 Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
Eli Friedmanf4e85332008-05-27 15:32:46 +0000252
Chris Lattner2acc6e32011-07-18 04:24:23 +0000253 llvm::Type *ResultType = ConvertType(E->getType());
Chandler Carruth50058ec2011-12-12 04:28:35 +0000254 Value *Result = Builder.CreateCall2(F, ArgValue, Builder.getTrue());
Eli Friedmanf4e85332008-05-27 15:32:46 +0000255 if (Result->getType() != ResultType)
Duncan Sandseac73e52009-11-16 13:11:21 +0000256 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
257 "cast");
Eli Friedmanf4e85332008-05-27 15:32:46 +0000258 return RValue::get(Result);
259 }
Daniel Dunbar04b29002008-07-21 17:19:41 +0000260 case Builtin::BI__builtin_ffs:
261 case Builtin::BI__builtin_ffsl:
262 case Builtin::BI__builtin_ffsll: {
263 // ffs(x) -> x ? cttz(x) + 1 : 0
264 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Mike Stump1eb44332009-09-09 15:08:12 +0000265
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000266 llvm::Type *ArgType = ArgValue->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000267 Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Chris Lattner2acc6e32011-07-18 04:24:23 +0000269 llvm::Type *ResultType = ConvertType(E->getType());
Chandler Carruth50058ec2011-12-12 04:28:35 +0000270 Value *Tmp = Builder.CreateAdd(Builder.CreateCall2(F, ArgValue,
271 Builder.getTrue()),
Benjamin Kramer578faa82011-09-27 21:06:10 +0000272 llvm::ConstantInt::get(ArgType, 1));
Owen Andersonc9c88b42009-07-31 20:28:54 +0000273 Value *Zero = llvm::Constant::getNullValue(ArgType);
Daniel Dunbar04b29002008-07-21 17:19:41 +0000274 Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero");
275 Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs");
276 if (Result->getType() != ResultType)
Duncan Sandseac73e52009-11-16 13:11:21 +0000277 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
278 "cast");
Daniel Dunbar04b29002008-07-21 17:19:41 +0000279 return RValue::get(Result);
280 }
281 case Builtin::BI__builtin_parity:
282 case Builtin::BI__builtin_parityl:
283 case Builtin::BI__builtin_parityll: {
284 // parity(x) -> ctpop(x) & 1
285 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000287 llvm::Type *ArgType = ArgValue->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000288 Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
Chris Lattner2acc6e32011-07-18 04:24:23 +0000290 llvm::Type *ResultType = ConvertType(E->getType());
Benjamin Kramer578faa82011-09-27 21:06:10 +0000291 Value *Tmp = Builder.CreateCall(F, ArgValue);
292 Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1));
Daniel Dunbar04b29002008-07-21 17:19:41 +0000293 if (Result->getType() != ResultType)
Duncan Sandseac73e52009-11-16 13:11:21 +0000294 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
295 "cast");
Daniel Dunbar04b29002008-07-21 17:19:41 +0000296 return RValue::get(Result);
297 }
298 case Builtin::BI__builtin_popcount:
299 case Builtin::BI__builtin_popcountl:
300 case Builtin::BI__builtin_popcountll: {
301 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000303 llvm::Type *ArgType = ArgValue->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000304 Value *F = CGM.getIntrinsic(Intrinsic::ctpop, ArgType);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Chris Lattner2acc6e32011-07-18 04:24:23 +0000306 llvm::Type *ResultType = ConvertType(E->getType());
Benjamin Kramer578faa82011-09-27 21:06:10 +0000307 Value *Result = Builder.CreateCall(F, ArgValue);
Daniel Dunbar04b29002008-07-21 17:19:41 +0000308 if (Result->getType() != ResultType)
Duncan Sandseac73e52009-11-16 13:11:21 +0000309 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
310 "cast");
Daniel Dunbar04b29002008-07-21 17:19:41 +0000311 return RValue::get(Result);
312 }
Fariborz Jahaniane42b8a52010-07-26 23:11:03 +0000313 case Builtin::BI__builtin_expect: {
Fariborz Jahaniandd697bc2011-04-25 23:10:07 +0000314 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000315 llvm::Type *ArgType = ArgValue->getType();
Jakub Staszak558229f2011-07-08 22:45:14 +0000316
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000317 Value *FnExpect = CGM.getIntrinsic(Intrinsic::expect, ArgType);
Jakub Staszak558229f2011-07-08 22:45:14 +0000318 Value *ExpectedValue = EmitScalarExpr(E->getArg(1));
319
320 Value *Result = Builder.CreateCall2(FnExpect, ArgValue, ExpectedValue,
321 "expval");
322 return RValue::get(Result);
Fariborz Jahaniane42b8a52010-07-26 23:11:03 +0000323 }
Anders Carlssondf4852a2007-12-02 21:58:10 +0000324 case Builtin::BI__builtin_bswap32:
325 case Builtin::BI__builtin_bswap64: {
Chris Lattner1feedd82007-12-13 07:34:23 +0000326 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000327 llvm::Type *ArgType = ArgValue->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000328 Value *F = CGM.getIntrinsic(Intrinsic::bswap, ArgType);
Benjamin Kramer578faa82011-09-27 21:06:10 +0000329 return RValue::get(Builder.CreateCall(F, ArgValue));
Mike Stump1eb44332009-09-09 15:08:12 +0000330 }
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +0000331 case Builtin::BI__builtin_object_size: {
Mike Stumpb16d32f2009-10-26 23:39:48 +0000332 // We pass this builtin onto the optimizer so that it can
333 // figure out the object size in more complex cases.
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000334 llvm::Type *ResType = ConvertType(E->getType());
Eric Christopherfee667f2009-12-23 03:49:37 +0000335
336 // LLVM only supports 0 and 2, make sure that we pass along that
337 // as a boolean.
338 Value *Ty = EmitScalarExpr(E->getArg(1));
339 ConstantInt *CI = dyn_cast<ConstantInt>(Ty);
340 assert(CI);
341 uint64_t val = CI->getZExtValue();
John McCalld16c2cf2011-02-08 08:22:06 +0000342 CI = ConstantInt::get(Builder.getInt1Ty(), (val & 0x2) >> 1);
Eric Christopherfee667f2009-12-23 03:49:37 +0000343
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000344 Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType);
Mike Stumpc4c90452009-10-27 22:09:17 +0000345 return RValue::get(Builder.CreateCall2(F,
346 EmitScalarExpr(E->getArg(0)),
Eric Christopherfee667f2009-12-23 03:49:37 +0000347 CI));
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +0000348 }
Daniel Dunbar4493f792008-07-21 22:59:13 +0000349 case Builtin::BI__builtin_prefetch: {
350 Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));
351 // FIXME: Technically these constants should of type 'int', yes?
Mike Stump1eb44332009-09-09 15:08:12 +0000352 RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) :
Chris Lattner77b89b82010-06-27 07:15:29 +0000353 llvm::ConstantInt::get(Int32Ty, 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000354 Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) :
Chris Lattner77b89b82010-06-27 07:15:29 +0000355 llvm::ConstantInt::get(Int32Ty, 3);
Bruno Cardoso Lopes2eccb672011-06-14 05:00:30 +0000356 Value *Data = llvm::ConstantInt::get(Int32Ty, 1);
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000357 Value *F = CGM.getIntrinsic(Intrinsic::prefetch);
Bruno Cardoso Lopes2eccb672011-06-14 05:00:30 +0000358 return RValue::get(Builder.CreateCall4(F, Address, RW, Locality, Data));
Anders Carlssondf4852a2007-12-02 21:58:10 +0000359 }
Daniel Dunbar4493f792008-07-21 22:59:13 +0000360 case Builtin::BI__builtin_trap: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000361 Value *F = CGM.getIntrinsic(Intrinsic::trap);
Daniel Dunbar4493f792008-07-21 22:59:13 +0000362 return RValue::get(Builder.CreateCall(F));
363 }
Chris Lattner21190d52009-09-21 03:09:59 +0000364 case Builtin::BI__builtin_unreachable: {
John McCallcd5b22e2011-01-12 03:41:02 +0000365 if (CatchUndefined)
Mike Stumpfba565d2009-12-16 03:07:12 +0000366 EmitBranch(getTrapBB());
John McCallcd5b22e2011-01-12 03:41:02 +0000367 else
368 Builder.CreateUnreachable();
369
370 // We do need to preserve an insertion point.
John McCalld16c2cf2011-02-08 08:22:06 +0000371 EmitBlock(createBasicBlock("unreachable.cont"));
John McCallcd5b22e2011-01-12 03:41:02 +0000372
373 return RValue::get(0);
Chris Lattner21190d52009-09-21 03:09:59 +0000374 }
375
Daniel Dunbara933c3c2008-07-21 18:44:41 +0000376 case Builtin::BI__builtin_powi:
377 case Builtin::BI__builtin_powif:
378 case Builtin::BI__builtin_powil: {
379 Value *Base = EmitScalarExpr(E->getArg(0));
380 Value *Exponent = EmitScalarExpr(E->getArg(1));
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000381 llvm::Type *ArgType = Base->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000382 Value *F = CGM.getIntrinsic(Intrinsic::powi, ArgType);
Benjamin Kramer578faa82011-09-27 21:06:10 +0000383 return RValue::get(Builder.CreateCall2(F, Base, Exponent));
Daniel Dunbara933c3c2008-07-21 18:44:41 +0000384 }
385
Chris Lattnerfe23e212007-12-20 00:44:32 +0000386 case Builtin::BI__builtin_isgreater:
387 case Builtin::BI__builtin_isgreaterequal:
388 case Builtin::BI__builtin_isless:
389 case Builtin::BI__builtin_islessequal:
390 case Builtin::BI__builtin_islessgreater:
391 case Builtin::BI__builtin_isunordered: {
392 // Ordered comparisons: we know the arguments to these are matching scalar
393 // floating point values.
Mike Stump1eb44332009-09-09 15:08:12 +0000394 Value *LHS = EmitScalarExpr(E->getArg(0));
Chris Lattnerfe23e212007-12-20 00:44:32 +0000395 Value *RHS = EmitScalarExpr(E->getArg(1));
Mike Stump1eb44332009-09-09 15:08:12 +0000396
Chris Lattnerfe23e212007-12-20 00:44:32 +0000397 switch (BuiltinID) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000398 default: llvm_unreachable("Unknown ordered comparison");
Chris Lattnerfe23e212007-12-20 00:44:32 +0000399 case Builtin::BI__builtin_isgreater:
400 LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp");
401 break;
402 case Builtin::BI__builtin_isgreaterequal:
403 LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp");
404 break;
405 case Builtin::BI__builtin_isless:
406 LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp");
407 break;
408 case Builtin::BI__builtin_islessequal:
409 LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp");
410 break;
411 case Builtin::BI__builtin_islessgreater:
412 LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp");
413 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000414 case Builtin::BI__builtin_isunordered:
Chris Lattnerfe23e212007-12-20 00:44:32 +0000415 LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp");
416 break;
417 }
418 // ZExt bool to int type.
Benjamin Kramer578faa82011-09-27 21:06:10 +0000419 return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType())));
Chris Lattnerfe23e212007-12-20 00:44:32 +0000420 }
Eli Friedmand6139892009-09-01 04:19:44 +0000421 case Builtin::BI__builtin_isnan: {
422 Value *V = EmitScalarExpr(E->getArg(0));
423 V = Builder.CreateFCmpUNO(V, V, "cmp");
Benjamin Kramer578faa82011-09-27 21:06:10 +0000424 return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType())));
Eli Friedmand6139892009-09-01 04:19:44 +0000425 }
Chris Lattner420b1182010-05-06 05:35:16 +0000426
427 case Builtin::BI__builtin_isinf: {
428 // isinf(x) --> fabs(x) == infinity
429 Value *V = EmitScalarExpr(E->getArg(0));
430 V = EmitFAbs(*this, V, E->getArg(0)->getType());
431
432 V = Builder.CreateFCmpOEQ(V, ConstantFP::getInfinity(V->getType()),"isinf");
Benjamin Kramer578faa82011-09-27 21:06:10 +0000433 return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType())));
Chris Lattner420b1182010-05-06 05:35:16 +0000434 }
Chris Lattner58ae5b42010-05-06 06:13:53 +0000435
436 // TODO: BI__builtin_isinf_sign
437 // isinf_sign(x) -> isinf(x) ? (signbit(x) ? -1 : 1) : 0
Benjamin Kramer6349ce92010-05-19 11:24:26 +0000438
439 case Builtin::BI__builtin_isnormal: {
440 // isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min
441 Value *V = EmitScalarExpr(E->getArg(0));
442 Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq");
443
444 Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType());
445 Value *IsLessThanInf =
446 Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf");
447 APFloat Smallest = APFloat::getSmallestNormalized(
448 getContext().getFloatTypeSemantics(E->getArg(0)->getType()));
449 Value *IsNormal =
450 Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest),
451 "isnormal");
452 V = Builder.CreateAnd(Eq, IsLessThanInf, "and");
453 V = Builder.CreateAnd(V, IsNormal, "and");
454 return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType())));
455 }
456
Chris Lattnered074152010-05-06 06:04:13 +0000457 case Builtin::BI__builtin_isfinite: {
Julien Lerougeef004ec2011-09-09 22:46:39 +0000458 // isfinite(x) --> x == x && fabs(x) != infinity;
Chris Lattnered074152010-05-06 06:04:13 +0000459 Value *V = EmitScalarExpr(E->getArg(0));
460 Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq");
461
462 Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType());
463 Value *IsNotInf =
464 Builder.CreateFCmpUNE(Abs, ConstantFP::getInfinity(V->getType()),"isinf");
465
466 V = Builder.CreateAnd(Eq, IsNotInf, "and");
467 return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType())));
468 }
Benjamin Kramer7867f1a2010-06-14 10:30:41 +0000469
470 case Builtin::BI__builtin_fpclassify: {
471 Value *V = EmitScalarExpr(E->getArg(5));
Chris Lattner2acc6e32011-07-18 04:24:23 +0000472 llvm::Type *Ty = ConvertType(E->getArg(5)->getType());
Benjamin Kramer7867f1a2010-06-14 10:30:41 +0000473
474 // Create Result
475 BasicBlock *Begin = Builder.GetInsertBlock();
476 BasicBlock *End = createBasicBlock("fpclassify_end", this->CurFn);
477 Builder.SetInsertPoint(End);
478 PHINode *Result =
Jay Foadbbf3bac2011-03-30 11:28:58 +0000479 Builder.CreatePHI(ConvertType(E->getArg(0)->getType()), 4,
Benjamin Kramer7867f1a2010-06-14 10:30:41 +0000480 "fpclassify_result");
481
482 // if (V==0) return FP_ZERO
483 Builder.SetInsertPoint(Begin);
484 Value *IsZero = Builder.CreateFCmpOEQ(V, Constant::getNullValue(Ty),
485 "iszero");
486 Value *ZeroLiteral = EmitScalarExpr(E->getArg(4));
487 BasicBlock *NotZero = createBasicBlock("fpclassify_not_zero", this->CurFn);
488 Builder.CreateCondBr(IsZero, End, NotZero);
489 Result->addIncoming(ZeroLiteral, Begin);
490
491 // if (V != V) return FP_NAN
492 Builder.SetInsertPoint(NotZero);
493 Value *IsNan = Builder.CreateFCmpUNO(V, V, "cmp");
494 Value *NanLiteral = EmitScalarExpr(E->getArg(0));
495 BasicBlock *NotNan = createBasicBlock("fpclassify_not_nan", this->CurFn);
496 Builder.CreateCondBr(IsNan, End, NotNan);
497 Result->addIncoming(NanLiteral, NotZero);
498
499 // if (fabs(V) == infinity) return FP_INFINITY
500 Builder.SetInsertPoint(NotNan);
501 Value *VAbs = EmitFAbs(*this, V, E->getArg(5)->getType());
502 Value *IsInf =
503 Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(V->getType()),
504 "isinf");
505 Value *InfLiteral = EmitScalarExpr(E->getArg(1));
506 BasicBlock *NotInf = createBasicBlock("fpclassify_not_inf", this->CurFn);
507 Builder.CreateCondBr(IsInf, End, NotInf);
508 Result->addIncoming(InfLiteral, NotNan);
509
510 // if (fabs(V) >= MIN_NORMAL) return FP_NORMAL else FP_SUBNORMAL
511 Builder.SetInsertPoint(NotInf);
512 APFloat Smallest = APFloat::getSmallestNormalized(
513 getContext().getFloatTypeSemantics(E->getArg(5)->getType()));
514 Value *IsNormal =
515 Builder.CreateFCmpUGE(VAbs, ConstantFP::get(V->getContext(), Smallest),
516 "isnormal");
517 Value *NormalResult =
518 Builder.CreateSelect(IsNormal, EmitScalarExpr(E->getArg(2)),
519 EmitScalarExpr(E->getArg(3)));
520 Builder.CreateBr(End);
521 Result->addIncoming(NormalResult, NotInf);
522
523 // return Result
524 Builder.SetInsertPoint(End);
525 return RValue::get(Result);
526 }
Chris Lattnered074152010-05-06 06:04:13 +0000527
Eli Friedmanb52fe9c2009-06-02 07:10:30 +0000528 case Builtin::BIalloca:
Chris Lattner9e800e32008-06-16 17:15:14 +0000529 case Builtin::BI__builtin_alloca: {
Chris Lattner9e800e32008-06-16 17:15:14 +0000530 Value *Size = EmitScalarExpr(E->getArg(0));
Benjamin Kramer578faa82011-09-27 21:06:10 +0000531 return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
Daniel Dunbar1caae952008-07-22 00:26:45 +0000532 }
Eli Friedmane6dddfd2010-01-23 19:00:10 +0000533 case Builtin::BIbzero:
Daniel Dunbar1caae952008-07-22 00:26:45 +0000534 case Builtin::BI__builtin_bzero: {
535 Value *Address = EmitScalarExpr(E->getArg(0));
Mon P Wang3ecd7852010-04-04 03:10:52 +0000536 Value *SizeVal = EmitScalarExpr(E->getArg(1));
Benjamin Kramer9f0c7cc2010-12-30 00:13:21 +0000537 Builder.CreateMemSet(Address, Builder.getInt8(0), SizeVal, 1, false);
Daniel Dunbar1caae952008-07-22 00:26:45 +0000538 return RValue::get(Address);
Chris Lattner9e800e32008-06-16 17:15:14 +0000539 }
Eli Friedmane6ec2052009-12-17 00:14:28 +0000540 case Builtin::BImemcpy:
Eli Friedmand4b32e42008-05-19 23:27:48 +0000541 case Builtin::BI__builtin_memcpy: {
Daniel Dunbar1caae952008-07-22 00:26:45 +0000542 Value *Address = EmitScalarExpr(E->getArg(0));
Mon P Wang3ecd7852010-04-04 03:10:52 +0000543 Value *SrcAddr = EmitScalarExpr(E->getArg(1));
544 Value *SizeVal = EmitScalarExpr(E->getArg(2));
Benjamin Kramer9f0c7cc2010-12-30 00:13:21 +0000545 Builder.CreateMemCpy(Address, SrcAddr, SizeVal, 1, false);
Daniel Dunbar1caae952008-07-22 00:26:45 +0000546 return RValue::get(Address);
547 }
Fariborz Jahanian55bcace2010-06-15 22:44:06 +0000548
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000549 case Builtin::BI__builtin___memcpy_chk: {
550 // fold __builtin_memcpy_chk(x, y, cst1, cst2) to memset iff cst1<=cst2.
Richard Smitha6b8b2c2011-10-10 18:28:20 +0000551 llvm::APSInt Size, DstSize;
552 if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||
553 !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000554 break;
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000555 if (Size.ugt(DstSize))
556 break;
557 Value *Dest = EmitScalarExpr(E->getArg(0));
558 Value *Src = EmitScalarExpr(E->getArg(1));
559 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
560 Builder.CreateMemCpy(Dest, Src, SizeVal, 1, false);
Chris Lattner42f681b2011-04-20 23:14:50 +0000561 return RValue::get(Dest);
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000562 }
563
Fariborz Jahanian8e2eab22010-06-16 16:22:04 +0000564 case Builtin::BI__builtin_objc_memmove_collectable: {
Fariborz Jahanian55bcace2010-06-15 22:44:06 +0000565 Value *Address = EmitScalarExpr(E->getArg(0));
566 Value *SrcAddr = EmitScalarExpr(E->getArg(1));
567 Value *SizeVal = EmitScalarExpr(E->getArg(2));
568 CGM.getObjCRuntime().EmitGCMemmoveCollectable(*this,
569 Address, SrcAddr, SizeVal);
570 return RValue::get(Address);
571 }
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000572
573 case Builtin::BI__builtin___memmove_chk: {
574 // fold __builtin_memmove_chk(x, y, cst1, cst2) to memset iff cst1<=cst2.
Richard Smitha6b8b2c2011-10-10 18:28:20 +0000575 llvm::APSInt Size, DstSize;
576 if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||
577 !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000578 break;
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000579 if (Size.ugt(DstSize))
580 break;
581 Value *Dest = EmitScalarExpr(E->getArg(0));
582 Value *Src = EmitScalarExpr(E->getArg(1));
583 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
584 Builder.CreateMemMove(Dest, Src, SizeVal, 1, false);
Chris Lattner42f681b2011-04-20 23:14:50 +0000585 return RValue::get(Dest);
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000586 }
587
Eli Friedmane6ec2052009-12-17 00:14:28 +0000588 case Builtin::BImemmove:
Daniel Dunbar1caae952008-07-22 00:26:45 +0000589 case Builtin::BI__builtin_memmove: {
590 Value *Address = EmitScalarExpr(E->getArg(0));
Mon P Wang3ecd7852010-04-04 03:10:52 +0000591 Value *SrcAddr = EmitScalarExpr(E->getArg(1));
592 Value *SizeVal = EmitScalarExpr(E->getArg(2));
Benjamin Kramer9f0c7cc2010-12-30 00:13:21 +0000593 Builder.CreateMemMove(Address, SrcAddr, SizeVal, 1, false);
Daniel Dunbar1caae952008-07-22 00:26:45 +0000594 return RValue::get(Address);
595 }
Eli Friedmane6ec2052009-12-17 00:14:28 +0000596 case Builtin::BImemset:
Daniel Dunbar1caae952008-07-22 00:26:45 +0000597 case Builtin::BI__builtin_memset: {
598 Value *Address = EmitScalarExpr(E->getArg(0));
Benjamin Kramer9f0c7cc2010-12-30 00:13:21 +0000599 Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
600 Builder.getInt8Ty());
Mon P Wang3ecd7852010-04-04 03:10:52 +0000601 Value *SizeVal = EmitScalarExpr(E->getArg(2));
Benjamin Kramer9f0c7cc2010-12-30 00:13:21 +0000602 Builder.CreateMemSet(Address, ByteVal, SizeVal, 1, false);
Daniel Dunbar1caae952008-07-22 00:26:45 +0000603 return RValue::get(Address);
Eli Friedmand4b32e42008-05-19 23:27:48 +0000604 }
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000605 case Builtin::BI__builtin___memset_chk: {
606 // fold __builtin_memset_chk(x, y, cst1, cst2) to memset iff cst1<=cst2.
Richard Smitha6b8b2c2011-10-10 18:28:20 +0000607 llvm::APSInt Size, DstSize;
608 if (!E->getArg(2)->EvaluateAsInt(Size, CGM.getContext()) ||
609 !E->getArg(3)->EvaluateAsInt(DstSize, CGM.getContext()))
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000610 break;
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000611 if (Size.ugt(DstSize))
612 break;
613 Value *Address = EmitScalarExpr(E->getArg(0));
614 Value *ByteVal = Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
615 Builder.getInt8Ty());
616 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
617 Builder.CreateMemSet(Address, ByteVal, SizeVal, 1, false);
618
Chris Lattner42f681b2011-04-20 23:14:50 +0000619 return RValue::get(Address);
Chris Lattnera5e5e0f2011-04-17 00:40:24 +0000620 }
John McCallfb17a562010-03-03 10:30:05 +0000621 case Builtin::BI__builtin_dwarf_cfa: {
622 // The offset in bytes from the first argument to the CFA.
623 //
624 // Why on earth is this in the frontend? Is there any reason at
625 // all that the backend can't reasonably determine this while
626 // lowering llvm.eh.dwarf.cfa()?
627 //
628 // TODO: If there's a satisfactory reason, add a target hook for
629 // this instead of hard-coding 0, which is correct for most targets.
630 int32_t Offset = 0;
631
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000632 Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa);
Chris Lattner77b89b82010-06-27 07:15:29 +0000633 return RValue::get(Builder.CreateCall(F,
634 llvm::ConstantInt::get(Int32Ty, Offset)));
John McCallfb17a562010-03-03 10:30:05 +0000635 }
Eli Friedman256f77e2008-05-20 08:59:34 +0000636 case Builtin::BI__builtin_return_address: {
Anton Korobeynikov83c2a982009-12-27 14:27:22 +0000637 Value *Depth = EmitScalarExpr(E->getArg(0));
Benjamin Kramer578faa82011-09-27 21:06:10 +0000638 Depth = Builder.CreateIntCast(Depth, Int32Ty, false);
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000639 Value *F = CGM.getIntrinsic(Intrinsic::returnaddress);
Anton Korobeynikov83c2a982009-12-27 14:27:22 +0000640 return RValue::get(Builder.CreateCall(F, Depth));
Eli Friedman256f77e2008-05-20 08:59:34 +0000641 }
642 case Builtin::BI__builtin_frame_address: {
Anton Korobeynikov83c2a982009-12-27 14:27:22 +0000643 Value *Depth = EmitScalarExpr(E->getArg(0));
Benjamin Kramer578faa82011-09-27 21:06:10 +0000644 Depth = Builder.CreateIntCast(Depth, Int32Ty, false);
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000645 Value *F = CGM.getIntrinsic(Intrinsic::frameaddress);
Anton Korobeynikov83c2a982009-12-27 14:27:22 +0000646 return RValue::get(Builder.CreateCall(F, Depth));
Eli Friedman256f77e2008-05-20 08:59:34 +0000647 }
Eli Friedman3b660ef2009-05-03 19:23:23 +0000648 case Builtin::BI__builtin_extract_return_addr: {
John McCall492c4f92010-03-03 04:15:11 +0000649 Value *Address = EmitScalarExpr(E->getArg(0));
650 Value *Result = getTargetHooks().decodeReturnAddress(*this, Address);
651 return RValue::get(Result);
652 }
653 case Builtin::BI__builtin_frob_return_addr: {
654 Value *Address = EmitScalarExpr(E->getArg(0));
655 Value *Result = getTargetHooks().encodeReturnAddress(*this, Address);
656 return RValue::get(Result);
Eli Friedman3b660ef2009-05-03 19:23:23 +0000657 }
John McCall6374c332010-03-06 00:35:14 +0000658 case Builtin::BI__builtin_dwarf_sp_column: {
Chris Lattner2acc6e32011-07-18 04:24:23 +0000659 llvm::IntegerType *Ty
John McCall6374c332010-03-06 00:35:14 +0000660 = cast<llvm::IntegerType>(ConvertType(E->getType()));
661 int Column = getTargetHooks().getDwarfEHStackPointer(CGM);
662 if (Column == -1) {
663 CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column");
664 return RValue::get(llvm::UndefValue::get(Ty));
665 }
666 return RValue::get(llvm::ConstantInt::get(Ty, Column, true));
667 }
668 case Builtin::BI__builtin_init_dwarf_reg_size_table: {
669 Value *Address = EmitScalarExpr(E->getArg(0));
670 if (getTargetHooks().initDwarfEHRegSizeTable(*this, Address))
671 CGM.ErrorUnsupported(E, "__builtin_init_dwarf_reg_size_table");
672 return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
673 }
John McCall7ada1112010-03-03 05:38:58 +0000674 case Builtin::BI__builtin_eh_return: {
675 Value *Int = EmitScalarExpr(E->getArg(0));
676 Value *Ptr = EmitScalarExpr(E->getArg(1));
677
Chris Lattner2acc6e32011-07-18 04:24:23 +0000678 llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType());
John McCall7ada1112010-03-03 05:38:58 +0000679 assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) &&
680 "LLVM's __builtin_eh_return only supports 32- and 64-bit variants");
681 Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32
682 ? Intrinsic::eh_return_i32
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000683 : Intrinsic::eh_return_i64);
John McCall7ada1112010-03-03 05:38:58 +0000684 Builder.CreateCall2(F, Int, Ptr);
John McCallcd5b22e2011-01-12 03:41:02 +0000685 Builder.CreateUnreachable();
686
687 // We do need to preserve an insertion point.
John McCalld16c2cf2011-02-08 08:22:06 +0000688 EmitBlock(createBasicBlock("builtin_eh_return.cont"));
John McCallcd5b22e2011-01-12 03:41:02 +0000689
690 return RValue::get(0);
John McCall7ada1112010-03-03 05:38:58 +0000691 }
Eli Friedmana6d75c02009-06-02 09:37:50 +0000692 case Builtin::BI__builtin_unwind_init: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +0000693 Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init);
Eli Friedmana6d75c02009-06-02 09:37:50 +0000694 return RValue::get(Builder.CreateCall(F));
695 }
John McCall5e110852010-03-02 02:31:24 +0000696 case Builtin::BI__builtin_extend_pointer: {
697 // Extends a pointer to the size of an _Unwind_Word, which is
John McCalld0b76ca2010-03-02 03:50:12 +0000698 // uint64_t on all platforms. Generally this gets poked into a
699 // register and eventually used as an address, so if the
700 // addressing registers are wider than pointers and the platform
701 // doesn't implicitly ignore high-order bits when doing
702 // addressing, we need to make sure we zext / sext based on
703 // the platform's expectations.
John McCall5e110852010-03-02 02:31:24 +0000704 //
705 // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html
John McCalld0b76ca2010-03-02 03:50:12 +0000706
John McCalld0b76ca2010-03-02 03:50:12 +0000707 // Cast the pointer to intptr_t.
John McCall5e110852010-03-02 02:31:24 +0000708 Value *Ptr = EmitScalarExpr(E->getArg(0));
John McCalld0b76ca2010-03-02 03:50:12 +0000709 Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast");
710
711 // If that's 64 bits, we're done.
712 if (IntPtrTy->getBitWidth() == 64)
713 return RValue::get(Result);
714
715 // Otherwise, ask the codegen data what to do.
John McCall492c4f92010-03-03 04:15:11 +0000716 if (getTargetHooks().extendPointerWithSExt())
John McCalld0b76ca2010-03-02 03:50:12 +0000717 return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext"));
718 else
719 return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext"));
John McCall5e110852010-03-02 02:31:24 +0000720 }
Eli Friedmana6d75c02009-06-02 09:37:50 +0000721 case Builtin::BI__builtin_setjmp: {
John McCall78673d92010-05-27 18:47:06 +0000722 // Buffer is a void**.
Eli Friedmana6d75c02009-06-02 09:37:50 +0000723 Value *Buf = EmitScalarExpr(E->getArg(0));
John McCall78673d92010-05-27 18:47:06 +0000724
725 // Store the frame pointer to the setjmp buffer.
Eli Friedmana6d75c02009-06-02 09:37:50 +0000726 Value *FrameAddr =
John McCall78673d92010-05-27 18:47:06 +0000727 Builder.CreateCall(CGM.getIntrinsic(Intrinsic::frameaddress),
Chris Lattner77b89b82010-06-27 07:15:29 +0000728 ConstantInt::get(Int32Ty, 0));
Eli Friedmana6d75c02009-06-02 09:37:50 +0000729 Builder.CreateStore(FrameAddr, Buf);
John McCall78673d92010-05-27 18:47:06 +0000730
Jim Grosbach6d172e22010-05-27 23:54:20 +0000731 // Store the stack pointer to the setjmp buffer.
732 Value *StackAddr =
733 Builder.CreateCall(CGM.getIntrinsic(Intrinsic::stacksave));
734 Value *StackSaveSlot =
Chris Lattner77b89b82010-06-27 07:15:29 +0000735 Builder.CreateGEP(Buf, ConstantInt::get(Int32Ty, 2));
Jim Grosbach6d172e22010-05-27 23:54:20 +0000736 Builder.CreateStore(StackAddr, StackSaveSlot);
737
John McCall78673d92010-05-27 18:47:06 +0000738 // Call LLVM's EH setjmp, which is lightweight.
739 Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp);
John McCalld16c2cf2011-02-08 08:22:06 +0000740 Buf = Builder.CreateBitCast(Buf, Int8PtrTy);
Eli Friedmana6d75c02009-06-02 09:37:50 +0000741 return RValue::get(Builder.CreateCall(F, Buf));
742 }
743 case Builtin::BI__builtin_longjmp: {
Eli Friedmana6d75c02009-06-02 09:37:50 +0000744 Value *Buf = EmitScalarExpr(E->getArg(0));
John McCalld16c2cf2011-02-08 08:22:06 +0000745 Buf = Builder.CreateBitCast(Buf, Int8PtrTy);
John McCall78673d92010-05-27 18:47:06 +0000746
747 // Call LLVM's EH longjmp, which is lightweight.
748 Builder.CreateCall(CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp), Buf);
749
John McCallcd5b22e2011-01-12 03:41:02 +0000750 // longjmp doesn't return; mark this as unreachable.
751 Builder.CreateUnreachable();
752
753 // We do need to preserve an insertion point.
John McCalld16c2cf2011-02-08 08:22:06 +0000754 EmitBlock(createBasicBlock("longjmp.cont"));
John McCallcd5b22e2011-01-12 03:41:02 +0000755
756 return RValue::get(0);
Eli Friedmana6d75c02009-06-02 09:37:50 +0000757 }
Mon P Wang1ffe2812008-05-09 22:40:52 +0000758 case Builtin::BI__sync_fetch_and_add:
Mon P Wang1ffe2812008-05-09 22:40:52 +0000759 case Builtin::BI__sync_fetch_and_sub:
Chris Lattner5caa3702009-05-08 06:58:22 +0000760 case Builtin::BI__sync_fetch_and_or:
761 case Builtin::BI__sync_fetch_and_and:
762 case Builtin::BI__sync_fetch_and_xor:
763 case Builtin::BI__sync_add_and_fetch:
764 case Builtin::BI__sync_sub_and_fetch:
765 case Builtin::BI__sync_and_and_fetch:
766 case Builtin::BI__sync_or_and_fetch:
767 case Builtin::BI__sync_xor_and_fetch:
768 case Builtin::BI__sync_val_compare_and_swap:
769 case Builtin::BI__sync_bool_compare_and_swap:
770 case Builtin::BI__sync_lock_test_and_set:
771 case Builtin::BI__sync_lock_release:
Chris Lattner23aa9c82011-04-09 03:57:26 +0000772 case Builtin::BI__sync_swap:
David Blaikieb219cfc2011-09-23 05:06:16 +0000773 llvm_unreachable("Shouldn't make it through sema");
Chris Lattner5caa3702009-05-08 06:58:22 +0000774 case Builtin::BI__sync_fetch_and_add_1:
775 case Builtin::BI__sync_fetch_and_add_2:
776 case Builtin::BI__sync_fetch_and_add_4:
777 case Builtin::BI__sync_fetch_and_add_8:
778 case Builtin::BI__sync_fetch_and_add_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000779 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Add, E);
Chris Lattner5caa3702009-05-08 06:58:22 +0000780 case Builtin::BI__sync_fetch_and_sub_1:
781 case Builtin::BI__sync_fetch_and_sub_2:
782 case Builtin::BI__sync_fetch_and_sub_4:
783 case Builtin::BI__sync_fetch_and_sub_8:
784 case Builtin::BI__sync_fetch_and_sub_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000785 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Sub, E);
Chris Lattner5caa3702009-05-08 06:58:22 +0000786 case Builtin::BI__sync_fetch_and_or_1:
787 case Builtin::BI__sync_fetch_and_or_2:
788 case Builtin::BI__sync_fetch_and_or_4:
789 case Builtin::BI__sync_fetch_and_or_8:
790 case Builtin::BI__sync_fetch_and_or_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000791 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Or, E);
Chris Lattner5caa3702009-05-08 06:58:22 +0000792 case Builtin::BI__sync_fetch_and_and_1:
793 case Builtin::BI__sync_fetch_and_and_2:
794 case Builtin::BI__sync_fetch_and_and_4:
795 case Builtin::BI__sync_fetch_and_and_8:
796 case Builtin::BI__sync_fetch_and_and_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000797 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::And, E);
Chris Lattner5caa3702009-05-08 06:58:22 +0000798 case Builtin::BI__sync_fetch_and_xor_1:
799 case Builtin::BI__sync_fetch_and_xor_2:
800 case Builtin::BI__sync_fetch_and_xor_4:
801 case Builtin::BI__sync_fetch_and_xor_8:
802 case Builtin::BI__sync_fetch_and_xor_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000803 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xor, E);
Mike Stump1eb44332009-09-09 15:08:12 +0000804
Chris Lattner5caa3702009-05-08 06:58:22 +0000805 // Clang extensions: not overloaded yet.
Mon P Wang1ffe2812008-05-09 22:40:52 +0000806 case Builtin::BI__sync_fetch_and_min:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000807 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Min, E);
Mon P Wang1ffe2812008-05-09 22:40:52 +0000808 case Builtin::BI__sync_fetch_and_max:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000809 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Max, E);
Mon P Wang1ffe2812008-05-09 22:40:52 +0000810 case Builtin::BI__sync_fetch_and_umin:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000811 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMin, E);
Mon P Wang1ffe2812008-05-09 22:40:52 +0000812 case Builtin::BI__sync_fetch_and_umax:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000813 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::UMax, E);
Daniel Dunbar0002d232009-04-07 00:55:51 +0000814
Chris Lattner5caa3702009-05-08 06:58:22 +0000815 case Builtin::BI__sync_add_and_fetch_1:
816 case Builtin::BI__sync_add_and_fetch_2:
817 case Builtin::BI__sync_add_and_fetch_4:
818 case Builtin::BI__sync_add_and_fetch_8:
819 case Builtin::BI__sync_add_and_fetch_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000820 return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Add, E,
Daniel Dunbar0002d232009-04-07 00:55:51 +0000821 llvm::Instruction::Add);
Chris Lattner5caa3702009-05-08 06:58:22 +0000822 case Builtin::BI__sync_sub_and_fetch_1:
823 case Builtin::BI__sync_sub_and_fetch_2:
824 case Builtin::BI__sync_sub_and_fetch_4:
825 case Builtin::BI__sync_sub_and_fetch_8:
826 case Builtin::BI__sync_sub_and_fetch_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000827 return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Sub, E,
Daniel Dunbar0002d232009-04-07 00:55:51 +0000828 llvm::Instruction::Sub);
Chris Lattner5caa3702009-05-08 06:58:22 +0000829 case Builtin::BI__sync_and_and_fetch_1:
830 case Builtin::BI__sync_and_and_fetch_2:
831 case Builtin::BI__sync_and_and_fetch_4:
832 case Builtin::BI__sync_and_and_fetch_8:
833 case Builtin::BI__sync_and_and_fetch_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000834 return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::And, E,
Daniel Dunbar0002d232009-04-07 00:55:51 +0000835 llvm::Instruction::And);
Chris Lattner5caa3702009-05-08 06:58:22 +0000836 case Builtin::BI__sync_or_and_fetch_1:
837 case Builtin::BI__sync_or_and_fetch_2:
838 case Builtin::BI__sync_or_and_fetch_4:
839 case Builtin::BI__sync_or_and_fetch_8:
840 case Builtin::BI__sync_or_and_fetch_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000841 return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Or, E,
Daniel Dunbar0002d232009-04-07 00:55:51 +0000842 llvm::Instruction::Or);
Chris Lattner5caa3702009-05-08 06:58:22 +0000843 case Builtin::BI__sync_xor_and_fetch_1:
844 case Builtin::BI__sync_xor_and_fetch_2:
845 case Builtin::BI__sync_xor_and_fetch_4:
846 case Builtin::BI__sync_xor_and_fetch_8:
847 case Builtin::BI__sync_xor_and_fetch_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000848 return EmitBinaryAtomicPost(*this, llvm::AtomicRMWInst::Xor, E,
Daniel Dunbar0002d232009-04-07 00:55:51 +0000849 llvm::Instruction::Xor);
Mike Stump1eb44332009-09-09 15:08:12 +0000850
Chris Lattner5caa3702009-05-08 06:58:22 +0000851 case Builtin::BI__sync_val_compare_and_swap_1:
852 case Builtin::BI__sync_val_compare_and_swap_2:
853 case Builtin::BI__sync_val_compare_and_swap_4:
854 case Builtin::BI__sync_val_compare_and_swap_8:
Daniel Dunbarcb61a7b2010-03-20 07:04:11 +0000855 case Builtin::BI__sync_val_compare_and_swap_16: {
John McCall26815d92010-10-27 20:58:56 +0000856 QualType T = E->getType();
John McCalld16c2cf2011-02-08 08:22:06 +0000857 llvm::Value *DestPtr = EmitScalarExpr(E->getArg(0));
Chris Lattner780a2eb2010-09-21 23:35:30 +0000858 unsigned AddrSpace =
Chris Lattner4f209442010-09-21 23:40:48 +0000859 cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
John McCall26815d92010-10-27 20:58:56 +0000860
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000861 llvm::IntegerType *IntType =
John McCalld16c2cf2011-02-08 08:22:06 +0000862 llvm::IntegerType::get(getLLVMContext(),
863 getContext().getTypeSize(T));
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000864 llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace);
Chandler Carruthdb4325b2010-07-18 07:23:17 +0000865
John McCall26815d92010-10-27 20:58:56 +0000866 Value *Args[3];
867 Args[0] = Builder.CreateBitCast(DestPtr, IntPtrType);
John McCalld16c2cf2011-02-08 08:22:06 +0000868 Args[1] = EmitScalarExpr(E->getArg(1));
Chris Lattner2acc6e32011-07-18 04:24:23 +0000869 llvm::Type *ValueType = Args[1]->getType();
John McCalld16c2cf2011-02-08 08:22:06 +0000870 Args[1] = EmitToInt(*this, Args[1], T, IntType);
871 Args[2] = EmitToInt(*this, EmitScalarExpr(E->getArg(2)), T, IntType);
John McCall26815d92010-10-27 20:58:56 +0000872
Eli Friedmanc83b9752011-09-07 01:41:24 +0000873 Value *Result = Builder.CreateAtomicCmpXchg(Args[0], Args[1], Args[2],
874 llvm::SequentiallyConsistent);
John McCalld16c2cf2011-02-08 08:22:06 +0000875 Result = EmitFromInt(*this, Result, T, ValueType);
John McCall26815d92010-10-27 20:58:56 +0000876 return RValue::get(Result);
Anders Carlsson89799cf2007-10-29 02:59:40 +0000877 }
Daniel Dunbar0002d232009-04-07 00:55:51 +0000878
Chris Lattner5caa3702009-05-08 06:58:22 +0000879 case Builtin::BI__sync_bool_compare_and_swap_1:
880 case Builtin::BI__sync_bool_compare_and_swap_2:
881 case Builtin::BI__sync_bool_compare_and_swap_4:
882 case Builtin::BI__sync_bool_compare_and_swap_8:
Daniel Dunbarcb61a7b2010-03-20 07:04:11 +0000883 case Builtin::BI__sync_bool_compare_and_swap_16: {
John McCall26815d92010-10-27 20:58:56 +0000884 QualType T = E->getArg(1)->getType();
John McCalld16c2cf2011-02-08 08:22:06 +0000885 llvm::Value *DestPtr = EmitScalarExpr(E->getArg(0));
Chris Lattnerf2b95272010-09-21 23:24:52 +0000886 unsigned AddrSpace =
Chris Lattner4f209442010-09-21 23:40:48 +0000887 cast<llvm::PointerType>(DestPtr->getType())->getAddressSpace();
John McCall26815d92010-10-27 20:58:56 +0000888
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000889 llvm::IntegerType *IntType =
John McCalld16c2cf2011-02-08 08:22:06 +0000890 llvm::IntegerType::get(getLLVMContext(),
891 getContext().getTypeSize(T));
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000892 llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace);
Chandler Carruthdb4325b2010-07-18 07:23:17 +0000893
John McCall26815d92010-10-27 20:58:56 +0000894 Value *Args[3];
895 Args[0] = Builder.CreateBitCast(DestPtr, IntPtrType);
John McCalld16c2cf2011-02-08 08:22:06 +0000896 Args[1] = EmitToInt(*this, EmitScalarExpr(E->getArg(1)), T, IntType);
897 Args[2] = EmitToInt(*this, EmitScalarExpr(E->getArg(2)), T, IntType);
John McCall26815d92010-10-27 20:58:56 +0000898
Chandler Carruthdb4325b2010-07-18 07:23:17 +0000899 Value *OldVal = Args[1];
Eli Friedmanc83b9752011-09-07 01:41:24 +0000900 Value *PrevVal = Builder.CreateAtomicCmpXchg(Args[0], Args[1], Args[2],
901 llvm::SequentiallyConsistent);
Daniel Dunbar0002d232009-04-07 00:55:51 +0000902 Value *Result = Builder.CreateICmpEQ(PrevVal, OldVal);
903 // zext bool to int.
John McCall26815d92010-10-27 20:58:56 +0000904 Result = Builder.CreateZExt(Result, ConvertType(E->getType()));
905 return RValue::get(Result);
Daniel Dunbar0002d232009-04-07 00:55:51 +0000906 }
907
Chris Lattner23aa9c82011-04-09 03:57:26 +0000908 case Builtin::BI__sync_swap_1:
909 case Builtin::BI__sync_swap_2:
910 case Builtin::BI__sync_swap_4:
911 case Builtin::BI__sync_swap_8:
912 case Builtin::BI__sync_swap_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000913 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E);
Chris Lattner23aa9c82011-04-09 03:57:26 +0000914
Chris Lattner5caa3702009-05-08 06:58:22 +0000915 case Builtin::BI__sync_lock_test_and_set_1:
916 case Builtin::BI__sync_lock_test_and_set_2:
917 case Builtin::BI__sync_lock_test_and_set_4:
918 case Builtin::BI__sync_lock_test_and_set_8:
919 case Builtin::BI__sync_lock_test_and_set_16:
Eli Friedmanc83b9752011-09-07 01:41:24 +0000920 return EmitBinaryAtomic(*this, llvm::AtomicRMWInst::Xchg, E);
Daniel Dunbarcb61a7b2010-03-20 07:04:11 +0000921
Chris Lattner5caa3702009-05-08 06:58:22 +0000922 case Builtin::BI__sync_lock_release_1:
923 case Builtin::BI__sync_lock_release_2:
924 case Builtin::BI__sync_lock_release_4:
925 case Builtin::BI__sync_lock_release_8:
Chris Lattnerf58cd9b2009-05-13 04:46:13 +0000926 case Builtin::BI__sync_lock_release_16: {
927 Value *Ptr = EmitScalarExpr(E->getArg(0));
Eli Friedmaneb43f4a2011-09-13 22:21:56 +0000928 llvm::Type *ElLLVMTy =
Chris Lattnerf58cd9b2009-05-13 04:46:13 +0000929 cast<llvm::PointerType>(Ptr->getType())->getElementType();
Daniel Dunbar007b5672009-11-29 21:11:47 +0000930 llvm::StoreInst *Store =
Eli Friedmaneb43f4a2011-09-13 22:21:56 +0000931 Builder.CreateStore(llvm::Constant::getNullValue(ElLLVMTy), Ptr);
932 QualType ElTy = E->getArg(0)->getType()->getPointeeType();
933 CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy);
934 Store->setAlignment(StoreSize.getQuantity());
935 Store->setAtomic(llvm::Release);
Daniel Dunbareb4f81e2009-05-27 23:45:33 +0000936 return RValue::get(0);
Chris Lattnerf58cd9b2009-05-13 04:46:13 +0000937 }
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000938
Chris Lattnerf58cd9b2009-05-13 04:46:13 +0000939 case Builtin::BI__sync_synchronize: {
Eli Friedmanc83b9752011-09-07 01:41:24 +0000940 // We assume this is supposed to correspond to a C++0x-style
941 // sequentially-consistent fence (i.e. this is only usable for
942 // synchonization, not device I/O or anything like that). This intrinsic
943 // is really badly designed in the sense that in theory, there isn't
944 // any way to safely use it... but in practice, it mostly works
945 // to use it with non-atomic loads and stores to get acquire/release
946 // semantics.
947 Builder.CreateFence(llvm::SequentiallyConsistent);
Daniel Dunbareb4f81e2009-05-27 23:45:33 +0000948 return RValue::get(0);
Chris Lattnerf58cd9b2009-05-13 04:46:13 +0000949 }
Mike Stump1eb44332009-09-09 15:08:12 +0000950
Eli Friedman276b0612011-10-11 02:20:01 +0000951 case Builtin::BI__atomic_thread_fence:
952 case Builtin::BI__atomic_signal_fence: {
953 llvm::SynchronizationScope Scope;
954 if (BuiltinID == Builtin::BI__atomic_signal_fence)
955 Scope = llvm::SingleThread;
956 else
957 Scope = llvm::CrossThread;
958 Value *Order = EmitScalarExpr(E->getArg(0));
959 if (isa<llvm::ConstantInt>(Order)) {
960 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
961 switch (ord) {
962 case 0: // memory_order_relaxed
963 default: // invalid order
964 break;
965 case 1: // memory_order_consume
966 case 2: // memory_order_acquire
967 Builder.CreateFence(llvm::Acquire, Scope);
968 break;
969 case 3: // memory_order_release
970 Builder.CreateFence(llvm::Release, Scope);
971 break;
972 case 4: // memory_order_acq_rel
973 Builder.CreateFence(llvm::AcquireRelease, Scope);
974 break;
975 case 5: // memory_order_seq_cst
976 Builder.CreateFence(llvm::SequentiallyConsistent, Scope);
977 break;
978 }
979 return RValue::get(0);
980 }
981
982 llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB;
983 AcquireBB = createBasicBlock("acquire", CurFn);
984 ReleaseBB = createBasicBlock("release", CurFn);
985 AcqRelBB = createBasicBlock("acqrel", CurFn);
986 SeqCstBB = createBasicBlock("seqcst", CurFn);
987 llvm::BasicBlock *ContBB = createBasicBlock("atomic.continue", CurFn);
988
989 Order = Builder.CreateIntCast(Order, Builder.getInt32Ty(), false);
990 llvm::SwitchInst *SI = Builder.CreateSwitch(Order, ContBB);
991
992 Builder.SetInsertPoint(AcquireBB);
993 Builder.CreateFence(llvm::Acquire, Scope);
994 Builder.CreateBr(ContBB);
995 SI->addCase(Builder.getInt32(1), AcquireBB);
996 SI->addCase(Builder.getInt32(2), AcquireBB);
997
998 Builder.SetInsertPoint(ReleaseBB);
999 Builder.CreateFence(llvm::Release, Scope);
1000 Builder.CreateBr(ContBB);
1001 SI->addCase(Builder.getInt32(3), ReleaseBB);
1002
1003 Builder.SetInsertPoint(AcqRelBB);
1004 Builder.CreateFence(llvm::AcquireRelease, Scope);
1005 Builder.CreateBr(ContBB);
1006 SI->addCase(Builder.getInt32(4), AcqRelBB);
1007
1008 Builder.SetInsertPoint(SeqCstBB);
1009 Builder.CreateFence(llvm::SequentiallyConsistent, Scope);
1010 Builder.CreateBr(ContBB);
1011 SI->addCase(Builder.getInt32(5), SeqCstBB);
1012
1013 Builder.SetInsertPoint(ContBB);
1014 return RValue::get(0);
1015 }
1016
Daniel Dunbaref2abfe2009-02-16 22:43:43 +00001017 // Library functions with special handling.
Daniel Dunbaref2abfe2009-02-16 22:43:43 +00001018 case Builtin::BIsqrt:
1019 case Builtin::BIsqrtf:
1020 case Builtin::BIsqrtl: {
John McCallbeb41282010-04-07 08:20:20 +00001021 // TODO: there is currently no set of optimizer flags
1022 // sufficient for us to rewrite sqrt to @llvm.sqrt.
1023 // -fmath-errno=0 is not good enough; we need finiteness.
1024 // We could probably precondition the call with an ult
1025 // against 0, but is that worth the complexity?
1026 break;
Daniel Dunbaref2abfe2009-02-16 22:43:43 +00001027 }
1028
1029 case Builtin::BIpow:
1030 case Builtin::BIpowf:
1031 case Builtin::BIpowl: {
1032 // Rewrite sqrt to intrinsic if allowed.
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +00001033 if (!FD->hasAttr<ConstAttr>())
Daniel Dunbaref2abfe2009-02-16 22:43:43 +00001034 break;
1035 Value *Base = EmitScalarExpr(E->getArg(0));
1036 Value *Exponent = EmitScalarExpr(E->getArg(1));
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001037 llvm::Type *ArgType = Base->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001038 Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType);
Benjamin Kramer578faa82011-09-27 21:06:10 +00001039 return RValue::get(Builder.CreateCall2(F, Base, Exponent));
Daniel Dunbaref2abfe2009-02-16 22:43:43 +00001040 }
Eli Friedmanba68b082010-03-06 02:17:52 +00001041
Cameron Zwarich094240a2011-07-08 21:39:34 +00001042 case Builtin::BIfma:
1043 case Builtin::BIfmaf:
1044 case Builtin::BIfmal:
1045 case Builtin::BI__builtin_fma:
1046 case Builtin::BI__builtin_fmaf:
1047 case Builtin::BI__builtin_fmal: {
1048 // Rewrite fma to intrinsic.
1049 Value *FirstArg = EmitScalarExpr(E->getArg(0));
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001050 llvm::Type *ArgType = FirstArg->getType();
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001051 Value *F = CGM.getIntrinsic(Intrinsic::fma, ArgType);
Cameron Zwarich094240a2011-07-08 21:39:34 +00001052 return RValue::get(Builder.CreateCall3(F, FirstArg,
1053 EmitScalarExpr(E->getArg(1)),
Benjamin Kramer578faa82011-09-27 21:06:10 +00001054 EmitScalarExpr(E->getArg(2))));
Cameron Zwarich094240a2011-07-08 21:39:34 +00001055 }
1056
Eli Friedmanba68b082010-03-06 02:17:52 +00001057 case Builtin::BI__builtin_signbit:
1058 case Builtin::BI__builtin_signbitf:
1059 case Builtin::BI__builtin_signbitl: {
1060 LLVMContext &C = CGM.getLLVMContext();
1061
1062 Value *Arg = EmitScalarExpr(E->getArg(0));
Chris Lattner2acc6e32011-07-18 04:24:23 +00001063 llvm::Type *ArgTy = Arg->getType();
Eli Friedmanba68b082010-03-06 02:17:52 +00001064 if (ArgTy->isPPC_FP128Ty())
1065 break; // FIXME: I'm not sure what the right implementation is here.
1066 int ArgWidth = ArgTy->getPrimitiveSizeInBits();
Chris Lattner2acc6e32011-07-18 04:24:23 +00001067 llvm::Type *ArgIntTy = llvm::IntegerType::get(C, ArgWidth);
Eli Friedmanba68b082010-03-06 02:17:52 +00001068 Value *BCArg = Builder.CreateBitCast(Arg, ArgIntTy);
1069 Value *ZeroCmp = llvm::Constant::getNullValue(ArgIntTy);
1070 Value *Result = Builder.CreateICmpSLT(BCArg, ZeroCmp);
1071 return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType())));
1072 }
Julien Lerouge77f68bb2011-09-09 22:41:49 +00001073 case Builtin::BI__builtin_annotation: {
1074 llvm::Value *AnnVal = EmitScalarExpr(E->getArg(0));
1075 llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::annotation,
1076 AnnVal->getType());
1077
1078 // Get the annotation string, go through casts. Sema requires this to be a
1079 // non-wide string literal, potentially casted, so the cast<> is safe.
1080 const Expr *AnnotationStrExpr = E->getArg(1)->IgnoreParenCasts();
1081 llvm::StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString();
1082 return RValue::get(EmitAnnotationCall(F, AnnVal, Str, E->getExprLoc()));
1083 }
Nate Begeman7ea2e3f2008-05-15 07:38:03 +00001084 }
Mike Stump1eb44332009-09-09 15:08:12 +00001085
John McCalla45680b2011-09-13 23:05:03 +00001086 // If this is an alias for a lib function (e.g. __builtin_sin), emit
1087 // the call using the normal call path, but using the unmangled
1088 // version of the function name.
1089 if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
1090 return emitLibraryCall(*this, FD, E,
1091 CGM.getBuiltinLibFunction(FD, BuiltinID));
1092
1093 // If this is a predefined lib function (e.g. malloc), emit the call
1094 // using exactly the normal call path.
1095 if (getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID))
1096 return emitLibraryCall(*this, FD, E, EmitScalarExpr(E->getCallee()));
Mike Stump1eb44332009-09-09 15:08:12 +00001097
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001098 // See if we have a target specific intrinsic.
Dale Johannesena6f80ef2009-02-05 01:50:47 +00001099 const char *Name = getContext().BuiltinInfo.GetName(BuiltinID);
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001100 Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic;
1101 if (const char *Prefix =
Mike Stump1eb44332009-09-09 15:08:12 +00001102 llvm::Triple::getArchTypePrefix(Target.getTriple().getArch()))
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001103 IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name);
Mike Stump1eb44332009-09-09 15:08:12 +00001104
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001105 if (IntrinsicID != Intrinsic::not_intrinsic) {
1106 SmallVector<Value*, 16> Args;
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Chris Lattner46c55912010-10-02 00:09:12 +00001108 // Find out if any arguments are required to be integer constant
1109 // expressions.
1110 unsigned ICEArguments = 0;
1111 ASTContext::GetBuiltinTypeError Error;
1112 getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
1113 assert(Error == ASTContext::GE_None && "Should not codegen an error");
1114
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001115 Function *F = CGM.getIntrinsic(IntrinsicID);
Chris Lattner2acc6e32011-07-18 04:24:23 +00001116 llvm::FunctionType *FTy = F->getFunctionType();
Mike Stump1eb44332009-09-09 15:08:12 +00001117
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001118 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
Chris Lattner46c55912010-10-02 00:09:12 +00001119 Value *ArgValue;
1120 // If this is a normal argument, just emit it as a scalar.
1121 if ((ICEArguments & (1 << i)) == 0) {
1122 ArgValue = EmitScalarExpr(E->getArg(i));
1123 } else {
1124 // If this is required to be a constant, constant fold it so that we
1125 // know that the generated intrinsic gets a ConstantInt.
1126 llvm::APSInt Result;
1127 bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result,getContext());
1128 assert(IsConst && "Constant arg isn't actually constant?");
1129 (void)IsConst;
John McCalld16c2cf2011-02-08 08:22:06 +00001130 ArgValue = llvm::ConstantInt::get(getLLVMContext(), Result);
Chris Lattner46c55912010-10-02 00:09:12 +00001131 }
Mike Stump1eb44332009-09-09 15:08:12 +00001132
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001133 // If the intrinsic arg type is different from the builtin arg type
1134 // we need to do a bit cast.
Chris Lattner2acc6e32011-07-18 04:24:23 +00001135 llvm::Type *PTy = FTy->getParamType(i);
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001136 if (PTy != ArgValue->getType()) {
1137 assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) &&
1138 "Must be able to losslessly bit cast to param");
1139 ArgValue = Builder.CreateBitCast(ArgValue, PTy);
1140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001142 Args.push_back(ArgValue);
1143 }
Mike Stump1eb44332009-09-09 15:08:12 +00001144
Jay Foad4c7d9f12011-07-15 08:37:34 +00001145 Value *V = Builder.CreateCall(F, Args);
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001146 QualType BuiltinRetType = E->getType();
Mike Stump1eb44332009-09-09 15:08:12 +00001147
Chris Lattner2acc6e32011-07-18 04:24:23 +00001148 llvm::Type *RetTy = llvm::Type::getVoidTy(getLLVMContext());
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001149 if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType);
Mike Stump1eb44332009-09-09 15:08:12 +00001150
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001151 if (RetTy != V->getType()) {
1152 assert(V->getType()->canLosslesslyBitCastTo(RetTy) &&
1153 "Must be able to losslessly bit cast result type");
1154 V = Builder.CreateBitCast(V, RetTy);
1155 }
Mike Stump1eb44332009-09-09 15:08:12 +00001156
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001157 return RValue::get(V);
1158 }
Mike Stump1eb44332009-09-09 15:08:12 +00001159
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001160 // See if we have a target specific builtin that needs to be lowered.
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +00001161 if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E))
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001162 return RValue::get(V);
Mike Stump1eb44332009-09-09 15:08:12 +00001163
Daniel Dunbar488e9932008-08-16 00:56:44 +00001164 ErrorUnsupported(E, "builtin function");
Mike Stump1eb44332009-09-09 15:08:12 +00001165
Chris Lattnerb7cfe882008-06-30 18:32:54 +00001166 // Unknown builtin, for now just dump it out and return undef.
1167 if (hasAggregateLLVMType(E->getType()))
Daniel Dunbar195337d2010-02-09 02:48:28 +00001168 return RValue::getAggregate(CreateMemTemp(E->getType()));
Owen Anderson03e20502009-07-30 23:11:26 +00001169 return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
Mike Stump1eb44332009-09-09 15:08:12 +00001170}
Anders Carlsson564f1de2007-12-09 23:17:02 +00001171
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +00001172Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID,
1173 const CallExpr *E) {
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001174 switch (Target.getTriple().getArch()) {
Chris Lattner2752c012010-03-03 19:03:45 +00001175 case llvm::Triple::arm:
1176 case llvm::Triple::thumb:
1177 return EmitARMBuiltinExpr(BuiltinID, E);
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001178 case llvm::Triple::x86:
1179 case llvm::Triple::x86_64:
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +00001180 return EmitX86BuiltinExpr(BuiltinID, E);
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001181 case llvm::Triple::ppc:
1182 case llvm::Triple::ppc64:
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +00001183 return EmitPPCBuiltinExpr(BuiltinID, E);
Tony Linthicum96319392011-12-12 21:14:55 +00001184 case llvm::Triple::hexagon:
1185 return EmitHexagonBuiltinExpr(BuiltinID, E);
Daniel Dunbar55cc2ed2009-08-24 09:54:37 +00001186 default:
1187 return 0;
1188 }
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +00001189}
1190
NAKAMURA Takumi83084c82011-11-08 03:27:04 +00001191static llvm::VectorType *GetNeonType(LLVMContext &C, NeonTypeFlags TypeFlags) {
1192 int IsQuad = TypeFlags.isQuad();
1193 switch (TypeFlags.getEltType()) {
Bob Wilsonda95f732011-11-08 01:16:11 +00001194 default: break;
1195 case NeonTypeFlags::Int8:
1196 case NeonTypeFlags::Poly8:
1197 return llvm::VectorType::get(llvm::Type::getInt8Ty(C), 8 << IsQuad);
1198 case NeonTypeFlags::Int16:
1199 case NeonTypeFlags::Poly16:
1200 case NeonTypeFlags::Float16:
1201 return llvm::VectorType::get(llvm::Type::getInt16Ty(C), 4 << IsQuad);
1202 case NeonTypeFlags::Int32:
1203 return llvm::VectorType::get(llvm::Type::getInt32Ty(C), 2 << IsQuad);
1204 case NeonTypeFlags::Int64:
1205 return llvm::VectorType::get(llvm::Type::getInt64Ty(C), 1 << IsQuad);
1206 case NeonTypeFlags::Float32:
1207 return llvm::VectorType::get(llvm::Type::getFloatTy(C), 2 << IsQuad);
Nate Begeman998622c2010-06-07 16:01:56 +00001208 };
1209 return 0;
1210}
1211
Bob Wilsoncf556522010-12-07 22:40:02 +00001212Value *CodeGenFunction::EmitNeonSplat(Value *V, Constant *C) {
Nate Begemand075c012010-06-10 00:17:56 +00001213 unsigned nElts = cast<llvm::VectorType>(V->getType())->getNumElements();
1214 SmallVector<Constant*, 16> Indices(nElts, C);
Chris Lattnerfb018d12011-02-15 00:14:06 +00001215 Value* SV = llvm::ConstantVector::get(Indices);
Nate Begemand075c012010-06-10 00:17:56 +00001216 return Builder.CreateShuffleVector(V, V, SV, "lane");
1217}
1218
Nate Begeman30d91712010-06-08 06:03:01 +00001219Value *CodeGenFunction::EmitNeonCall(Function *F, SmallVectorImpl<Value*> &Ops,
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001220 const char *name,
Nate Begeman61eecf52010-06-14 05:21:25 +00001221 unsigned shift, bool rightshift) {
Nate Begeman30d91712010-06-08 06:03:01 +00001222 unsigned j = 0;
1223 for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
1224 ai != ae; ++ai, ++j)
Nate Begeman61eecf52010-06-14 05:21:25 +00001225 if (shift > 0 && shift == j)
1226 Ops[j] = EmitNeonShiftVector(Ops[j], ai->getType(), rightshift);
1227 else
1228 Ops[j] = Builder.CreateBitCast(Ops[j], ai->getType(), name);
Nate Begeman30d91712010-06-08 06:03:01 +00001229
Jay Foad4c7d9f12011-07-15 08:37:34 +00001230 return Builder.CreateCall(F, Ops, name);
Nate Begeman30d91712010-06-08 06:03:01 +00001231}
1232
Chris Lattner2acc6e32011-07-18 04:24:23 +00001233Value *CodeGenFunction::EmitNeonShiftVector(Value *V, llvm::Type *Ty,
Nate Begeman464ccb62010-06-11 22:57:12 +00001234 bool neg) {
1235 ConstantInt *CI = cast<ConstantInt>(V);
1236 int SV = CI->getSExtValue();
1237
Chris Lattner2acc6e32011-07-18 04:24:23 +00001238 llvm::VectorType *VTy = cast<llvm::VectorType>(Ty);
Nate Begeman464ccb62010-06-11 22:57:12 +00001239 llvm::Constant *C = ConstantInt::get(VTy->getElementType(), neg ? -SV : SV);
1240 SmallVector<llvm::Constant*, 16> CV(VTy->getNumElements(), C);
Chris Lattnerfb018d12011-02-15 00:14:06 +00001241 return llvm::ConstantVector::get(CV);
Nate Begeman464ccb62010-06-11 22:57:12 +00001242}
1243
Bob Wilson06b6c582010-08-27 17:14:29 +00001244/// GetPointeeAlignment - Given an expression with a pointer type, find the
1245/// alignment of the type referenced by the pointer. Skip over implicit
1246/// casts.
1247static Value *GetPointeeAlignment(CodeGenFunction &CGF, const Expr *Addr) {
1248 unsigned Align = 1;
1249 // Check if the type is a pointer. The implicit cast operand might not be.
1250 while (Addr->getType()->isPointerType()) {
1251 QualType PtTy = Addr->getType()->getPointeeType();
1252 unsigned NewA = CGF.getContext().getTypeAlignInChars(PtTy).getQuantity();
1253 if (NewA > Align)
1254 Align = NewA;
1255
1256 // If the address is an implicit cast, repeat with the cast operand.
1257 if (const ImplicitCastExpr *CastAddr = dyn_cast<ImplicitCastExpr>(Addr)) {
1258 Addr = CastAddr->getSubExpr();
1259 continue;
1260 }
1261 break;
1262 }
1263 return llvm::ConstantInt::get(CGF.Int32Ty, Align);
1264}
1265
Chris Lattner2752c012010-03-03 19:03:45 +00001266Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
1267 const CallExpr *E) {
Rafael Espindolae140af32010-06-09 03:48:40 +00001268 if (BuiltinID == ARM::BI__clear_cache) {
Rafael Espindola79ba5092010-06-07 17:26:50 +00001269 const FunctionDecl *FD = E->getDirectCallee();
Eric Christopher8a37c792011-03-14 20:30:34 +00001270 // Oddly people write this call without args on occasion and gcc accepts
1271 // it - it's also marked as varargs in the description file.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001272 SmallVector<Value*, 2> Ops;
Eric Christopher8a37c792011-03-14 20:30:34 +00001273 for (unsigned i = 0; i < E->getNumArgs(); i++)
1274 Ops.push_back(EmitScalarExpr(E->getArg(i)));
Chris Lattner2acc6e32011-07-18 04:24:23 +00001275 llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType());
1276 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
Chris Lattner5f9e2722011-07-23 10:55:15 +00001277 StringRef Name = FD->getName();
Jay Foad4c7d9f12011-07-15 08:37:34 +00001278 return Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), Ops);
Chris Lattner2752c012010-03-03 19:03:45 +00001279 }
Rafael Espindolae140af32010-06-09 03:48:40 +00001280
Bruno Cardoso Lopes26c1b8d2011-05-28 04:11:33 +00001281 if (BuiltinID == ARM::BI__builtin_arm_ldrexd) {
1282 Function *F = CGM.getIntrinsic(Intrinsic::arm_ldrexd);
1283
1284 Value *LdPtr = EmitScalarExpr(E->getArg(0));
1285 Value *Val = Builder.CreateCall(F, LdPtr, "ldrexd");
1286
1287 Value *Val0 = Builder.CreateExtractValue(Val, 1);
1288 Value *Val1 = Builder.CreateExtractValue(Val, 0);
1289 Val0 = Builder.CreateZExt(Val0, Int64Ty);
1290 Val1 = Builder.CreateZExt(Val1, Int64Ty);
1291
1292 Value *ShiftCst = llvm::ConstantInt::get(Int64Ty, 32);
1293 Val = Builder.CreateShl(Val0, ShiftCst, "shl", true /* nuw */);
1294 return Builder.CreateOr(Val, Val1);
1295 }
1296
1297 if (BuiltinID == ARM::BI__builtin_arm_strexd) {
1298 Function *F = CGM.getIntrinsic(Intrinsic::arm_strexd);
Chris Lattner7650d952011-06-18 22:49:11 +00001299 llvm::Type *STy = llvm::StructType::get(Int32Ty, Int32Ty, NULL);
Bruno Cardoso Lopes26c1b8d2011-05-28 04:11:33 +00001300
1301 Value *One = llvm::ConstantInt::get(Int32Ty, 1);
Benjamin Kramer578faa82011-09-27 21:06:10 +00001302 Value *Tmp = Builder.CreateAlloca(Int64Ty, One);
Bruno Cardoso Lopes26c1b8d2011-05-28 04:11:33 +00001303 Value *Val = EmitScalarExpr(E->getArg(0));
1304 Builder.CreateStore(Val, Tmp);
1305
1306 Value *LdPtr = Builder.CreateBitCast(Tmp,llvm::PointerType::getUnqual(STy));
1307 Val = Builder.CreateLoad(LdPtr);
1308
1309 Value *Arg0 = Builder.CreateExtractValue(Val, 0);
1310 Value *Arg1 = Builder.CreateExtractValue(Val, 1);
1311 Value *StPtr = EmitScalarExpr(E->getArg(1));
1312 return Builder.CreateCall3(F, Arg0, Arg1, StPtr, "strexd");
1313 }
1314
Chris Lattner5f9e2722011-07-23 10:55:15 +00001315 SmallVector<Value*, 4> Ops;
Rafael Espindolae140af32010-06-09 03:48:40 +00001316 for (unsigned i = 0, e = E->getNumArgs() - 1; i != e; i++)
1317 Ops.push_back(EmitScalarExpr(E->getArg(i)));
1318
Bob Wilson83bbba12011-08-13 05:03:46 +00001319 // vget_lane and vset_lane are not overloaded and do not have an extra
1320 // argument that specifies the vector type.
1321 switch (BuiltinID) {
1322 default: break;
1323 case ARM::BI__builtin_neon_vget_lane_i8:
1324 case ARM::BI__builtin_neon_vget_lane_i16:
1325 case ARM::BI__builtin_neon_vget_lane_i32:
1326 case ARM::BI__builtin_neon_vget_lane_i64:
1327 case ARM::BI__builtin_neon_vget_lane_f32:
1328 case ARM::BI__builtin_neon_vgetq_lane_i8:
1329 case ARM::BI__builtin_neon_vgetq_lane_i16:
1330 case ARM::BI__builtin_neon_vgetq_lane_i32:
1331 case ARM::BI__builtin_neon_vgetq_lane_i64:
1332 case ARM::BI__builtin_neon_vgetq_lane_f32:
1333 return Builder.CreateExtractElement(Ops[0], EmitScalarExpr(E->getArg(1)),
1334 "vget_lane");
1335 case ARM::BI__builtin_neon_vset_lane_i8:
1336 case ARM::BI__builtin_neon_vset_lane_i16:
1337 case ARM::BI__builtin_neon_vset_lane_i32:
1338 case ARM::BI__builtin_neon_vset_lane_i64:
1339 case ARM::BI__builtin_neon_vset_lane_f32:
1340 case ARM::BI__builtin_neon_vsetq_lane_i8:
1341 case ARM::BI__builtin_neon_vsetq_lane_i16:
1342 case ARM::BI__builtin_neon_vsetq_lane_i32:
1343 case ARM::BI__builtin_neon_vsetq_lane_i64:
1344 case ARM::BI__builtin_neon_vsetq_lane_f32:
1345 Ops.push_back(EmitScalarExpr(E->getArg(2)));
1346 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vset_lane");
1347 }
1348
1349 // Get the last argument, which specifies the vector type.
Rafael Espindolae140af32010-06-09 03:48:40 +00001350 llvm::APSInt Result;
1351 const Expr *Arg = E->getArg(E->getNumArgs()-1);
1352 if (!Arg->isIntegerConstantExpr(Result, getContext()))
1353 return 0;
1354
Nate Begeman99c40bb2010-08-03 21:32:34 +00001355 if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f ||
1356 BuiltinID == ARM::BI__builtin_arm_vcvtr_d) {
1357 // Determine the overloaded type of this builtin.
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001358 llvm::Type *Ty;
Nate Begeman99c40bb2010-08-03 21:32:34 +00001359 if (BuiltinID == ARM::BI__builtin_arm_vcvtr_f)
John McCalld16c2cf2011-02-08 08:22:06 +00001360 Ty = llvm::Type::getFloatTy(getLLVMContext());
Nate Begeman99c40bb2010-08-03 21:32:34 +00001361 else
John McCalld16c2cf2011-02-08 08:22:06 +00001362 Ty = llvm::Type::getDoubleTy(getLLVMContext());
Nate Begeman99c40bb2010-08-03 21:32:34 +00001363
1364 // Determine whether this is an unsigned conversion or not.
1365 bool usgn = Result.getZExtValue() == 1;
1366 unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
1367
1368 // Call the appropriate intrinsic.
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001369 Function *F = CGM.getIntrinsic(Int, Ty);
Jay Foad4c7d9f12011-07-15 08:37:34 +00001370 return Builder.CreateCall(F, Ops, "vcvtr");
Nate Begeman99c40bb2010-08-03 21:32:34 +00001371 }
1372
1373 // Determine the type of this overloaded NEON intrinsic.
Bob Wilsonda95f732011-11-08 01:16:11 +00001374 NeonTypeFlags Type(Result.getZExtValue());
1375 bool usgn = Type.isUnsigned();
1376 bool quad = Type.isQuad();
Bob Wilson79653962010-12-03 17:10:22 +00001377 bool rightShift = false;
Rafael Espindolae140af32010-06-09 03:48:40 +00001378
Bob Wilsonda95f732011-11-08 01:16:11 +00001379 llvm::VectorType *VTy = GetNeonType(getLLVMContext(), Type);
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001380 llvm::Type *Ty = VTy;
Rafael Espindolae140af32010-06-09 03:48:40 +00001381 if (!Ty)
1382 return 0;
1383
1384 unsigned Int;
1385 switch (BuiltinID) {
1386 default: return 0;
Bob Wilson537c346112011-06-24 22:13:26 +00001387 case ARM::BI__builtin_neon_vabd_v:
1388 case ARM::BI__builtin_neon_vabdq_v:
Nate Begeman998622c2010-06-07 16:01:56 +00001389 Int = usgn ? Intrinsic::arm_neon_vabdu : Intrinsic::arm_neon_vabds;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001390 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vabd");
Bob Wilson537c346112011-06-24 22:13:26 +00001391 case ARM::BI__builtin_neon_vabs_v:
1392 case ARM::BI__builtin_neon_vabsq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001393 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vabs, Ty),
Nate Begeman548f7da2010-06-10 18:11:55 +00001394 Ops, "vabs");
Bob Wilson537c346112011-06-24 22:13:26 +00001395 case ARM::BI__builtin_neon_vaddhn_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001396 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vaddhn, Ty),
Nate Begeman548f7da2010-06-10 18:11:55 +00001397 Ops, "vaddhn");
Bob Wilson537c346112011-06-24 22:13:26 +00001398 case ARM::BI__builtin_neon_vcale_v:
Nate Begeman9eb65a52010-06-08 00:17:19 +00001399 std::swap(Ops[0], Ops[1]);
Bob Wilson537c346112011-06-24 22:13:26 +00001400 case ARM::BI__builtin_neon_vcage_v: {
Bob Wilsond1850352010-12-10 01:11:38 +00001401 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacged);
Nate Begeman30d91712010-06-08 06:03:01 +00001402 return EmitNeonCall(F, Ops, "vcage");
1403 }
Bob Wilson537c346112011-06-24 22:13:26 +00001404 case ARM::BI__builtin_neon_vcaleq_v:
Nate Begeman9eb65a52010-06-08 00:17:19 +00001405 std::swap(Ops[0], Ops[1]);
Bob Wilson537c346112011-06-24 22:13:26 +00001406 case ARM::BI__builtin_neon_vcageq_v: {
Bob Wilsond1850352010-12-10 01:11:38 +00001407 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacgeq);
Nate Begeman30d91712010-06-08 06:03:01 +00001408 return EmitNeonCall(F, Ops, "vcage");
1409 }
Bob Wilson537c346112011-06-24 22:13:26 +00001410 case ARM::BI__builtin_neon_vcalt_v:
Nate Begeman9eb65a52010-06-08 00:17:19 +00001411 std::swap(Ops[0], Ops[1]);
Bob Wilson537c346112011-06-24 22:13:26 +00001412 case ARM::BI__builtin_neon_vcagt_v: {
Bob Wilsond1850352010-12-10 01:11:38 +00001413 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacgtd);
Nate Begeman30d91712010-06-08 06:03:01 +00001414 return EmitNeonCall(F, Ops, "vcagt");
1415 }
Bob Wilson537c346112011-06-24 22:13:26 +00001416 case ARM::BI__builtin_neon_vcaltq_v:
Nate Begeman9eb65a52010-06-08 00:17:19 +00001417 std::swap(Ops[0], Ops[1]);
Bob Wilson537c346112011-06-24 22:13:26 +00001418 case ARM::BI__builtin_neon_vcagtq_v: {
Bob Wilsond1850352010-12-10 01:11:38 +00001419 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vacgtq);
Nate Begeman30d91712010-06-08 06:03:01 +00001420 return EmitNeonCall(F, Ops, "vcagt");
1421 }
Bob Wilson537c346112011-06-24 22:13:26 +00001422 case ARM::BI__builtin_neon_vcls_v:
1423 case ARM::BI__builtin_neon_vclsq_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001424 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vcls, Ty);
Nate Begeman30d91712010-06-08 06:03:01 +00001425 return EmitNeonCall(F, Ops, "vcls");
Nate Begeman9eb65a52010-06-08 00:17:19 +00001426 }
Bob Wilson537c346112011-06-24 22:13:26 +00001427 case ARM::BI__builtin_neon_vclz_v:
1428 case ARM::BI__builtin_neon_vclzq_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001429 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vclz, Ty);
Nate Begeman30d91712010-06-08 06:03:01 +00001430 return EmitNeonCall(F, Ops, "vclz");
Nate Begeman9eb65a52010-06-08 00:17:19 +00001431 }
Bob Wilson537c346112011-06-24 22:13:26 +00001432 case ARM::BI__builtin_neon_vcnt_v:
1433 case ARM::BI__builtin_neon_vcntq_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001434 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vcnt, Ty);
Nate Begeman30d91712010-06-08 06:03:01 +00001435 return EmitNeonCall(F, Ops, "vcnt");
Nate Begeman9eb65a52010-06-08 00:17:19 +00001436 }
Bob Wilson537c346112011-06-24 22:13:26 +00001437 case ARM::BI__builtin_neon_vcvt_f16_v: {
Bob Wilsonda95f732011-11-08 01:16:11 +00001438 assert(Type.getEltType() == NeonTypeFlags::Float16 && !quad &&
1439 "unexpected vcvt_f16_v builtin");
Bob Wilson46e392a2010-12-15 23:36:44 +00001440 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vcvtfp2hf);
1441 return EmitNeonCall(F, Ops, "vcvt");
1442 }
Bob Wilson537c346112011-06-24 22:13:26 +00001443 case ARM::BI__builtin_neon_vcvt_f32_f16: {
Bob Wilsonda95f732011-11-08 01:16:11 +00001444 assert(Type.getEltType() == NeonTypeFlags::Float16 && !quad &&
1445 "unexpected vcvt_f32_f16 builtin");
Bob Wilson46e392a2010-12-15 23:36:44 +00001446 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vcvthf2fp);
1447 return EmitNeonCall(F, Ops, "vcvt");
1448 }
Bob Wilson537c346112011-06-24 22:13:26 +00001449 case ARM::BI__builtin_neon_vcvt_f32_v:
Bob Wilsonda95f732011-11-08 01:16:11 +00001450 case ARM::BI__builtin_neon_vcvtq_f32_v:
Nate Begeman30d91712010-06-08 06:03:01 +00001451 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
Bob Wilsonda95f732011-11-08 01:16:11 +00001452 Ty = GetNeonType(getLLVMContext(),
1453 NeonTypeFlags(NeonTypeFlags::Float32, false, quad));
Nate Begeman9eb65a52010-06-08 00:17:19 +00001454 return usgn ? Builder.CreateUIToFP(Ops[0], Ty, "vcvt")
1455 : Builder.CreateSIToFP(Ops[0], Ty, "vcvt");
Bob Wilson537c346112011-06-24 22:13:26 +00001456 case ARM::BI__builtin_neon_vcvt_s32_v:
1457 case ARM::BI__builtin_neon_vcvt_u32_v:
1458 case ARM::BI__builtin_neon_vcvtq_s32_v:
1459 case ARM::BI__builtin_neon_vcvtq_u32_v: {
Bob Wilsonda95f732011-11-08 01:16:11 +00001460 llvm::Type *FloatTy =
1461 GetNeonType(getLLVMContext(),
1462 NeonTypeFlags(NeonTypeFlags::Float32, false, quad));
1463 Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy);
Nate Begeman9eb65a52010-06-08 00:17:19 +00001464 return usgn ? Builder.CreateFPToUI(Ops[0], Ty, "vcvt")
1465 : Builder.CreateFPToSI(Ops[0], Ty, "vcvt");
1466 }
Bob Wilson537c346112011-06-24 22:13:26 +00001467 case ARM::BI__builtin_neon_vcvt_n_f32_v:
1468 case ARM::BI__builtin_neon_vcvtq_n_f32_v: {
Bob Wilsonda95f732011-11-08 01:16:11 +00001469 llvm::Type *FloatTy =
1470 GetNeonType(getLLVMContext(),
1471 NeonTypeFlags(NeonTypeFlags::Float32, false, quad));
1472 llvm::Type *Tys[2] = { FloatTy, Ty };
1473 Int = usgn ? Intrinsic::arm_neon_vcvtfxu2fp
1474 : Intrinsic::arm_neon_vcvtfxs2fp;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001475 Function *F = CGM.getIntrinsic(Int, Tys);
Nate Begeman30d91712010-06-08 06:03:01 +00001476 return EmitNeonCall(F, Ops, "vcvt_n");
Nate Begeman9eb65a52010-06-08 00:17:19 +00001477 }
Bob Wilson537c346112011-06-24 22:13:26 +00001478 case ARM::BI__builtin_neon_vcvt_n_s32_v:
1479 case ARM::BI__builtin_neon_vcvt_n_u32_v:
1480 case ARM::BI__builtin_neon_vcvtq_n_s32_v:
1481 case ARM::BI__builtin_neon_vcvtq_n_u32_v: {
Bob Wilsonda95f732011-11-08 01:16:11 +00001482 llvm::Type *FloatTy =
1483 GetNeonType(getLLVMContext(),
1484 NeonTypeFlags(NeonTypeFlags::Float32, false, quad));
1485 llvm::Type *Tys[2] = { Ty, FloatTy };
1486 Int = usgn ? Intrinsic::arm_neon_vcvtfp2fxu
1487 : Intrinsic::arm_neon_vcvtfp2fxs;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001488 Function *F = CGM.getIntrinsic(Int, Tys);
Nate Begeman30d91712010-06-08 06:03:01 +00001489 return EmitNeonCall(F, Ops, "vcvt_n");
1490 }
Bob Wilson537c346112011-06-24 22:13:26 +00001491 case ARM::BI__builtin_neon_vext_v:
1492 case ARM::BI__builtin_neon_vextq_v: {
Chris Lattnerfb018d12011-02-15 00:14:06 +00001493 int CV = cast<ConstantInt>(Ops[2])->getSExtValue();
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001494 SmallVector<Constant*, 16> Indices;
Nate Begeman4be54302010-06-20 23:05:28 +00001495 for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
Chris Lattner77b89b82010-06-27 07:15:29 +00001496 Indices.push_back(ConstantInt::get(Int32Ty, i+CV));
Nate Begeman30d91712010-06-08 06:03:01 +00001497
1498 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1499 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
Chris Lattnerfb018d12011-02-15 00:14:06 +00001500 Value *SV = llvm::ConstantVector::get(Indices);
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001501 return Builder.CreateShuffleVector(Ops[0], Ops[1], SV, "vext");
1502 }
Bob Wilson537c346112011-06-24 22:13:26 +00001503 case ARM::BI__builtin_neon_vhadd_v:
1504 case ARM::BI__builtin_neon_vhaddq_v:
Nate Begemandf98e1d2010-06-09 18:04:15 +00001505 Int = usgn ? Intrinsic::arm_neon_vhaddu : Intrinsic::arm_neon_vhadds;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001506 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vhadd");
Bob Wilson537c346112011-06-24 22:13:26 +00001507 case ARM::BI__builtin_neon_vhsub_v:
1508 case ARM::BI__builtin_neon_vhsubq_v:
Nate Begemandf98e1d2010-06-09 18:04:15 +00001509 Int = usgn ? Intrinsic::arm_neon_vhsubu : Intrinsic::arm_neon_vhsubs;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001510 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vhsub");
Bob Wilson537c346112011-06-24 22:13:26 +00001511 case ARM::BI__builtin_neon_vld1_v:
1512 case ARM::BI__builtin_neon_vld1q_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001513 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001514 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vld1, Ty),
Nate Begeman4be54302010-06-20 23:05:28 +00001515 Ops, "vld1");
Bob Wilson537c346112011-06-24 22:13:26 +00001516 case ARM::BI__builtin_neon_vld1_lane_v:
1517 case ARM::BI__builtin_neon_vld1q_lane_v:
Nate Begeman4be54302010-06-20 23:05:28 +00001518 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
1519 Ty = llvm::PointerType::getUnqual(VTy->getElementType());
1520 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1521 Ops[0] = Builder.CreateLoad(Ops[0]);
1522 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2], "vld1_lane");
Bob Wilson537c346112011-06-24 22:13:26 +00001523 case ARM::BI__builtin_neon_vld1_dup_v:
1524 case ARM::BI__builtin_neon_vld1q_dup_v: {
Nate Begeman4be54302010-06-20 23:05:28 +00001525 Value *V = UndefValue::get(Ty);
1526 Ty = llvm::PointerType::getUnqual(VTy->getElementType());
1527 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1528 Ops[0] = Builder.CreateLoad(Ops[0]);
Chris Lattner77b89b82010-06-27 07:15:29 +00001529 llvm::Constant *CI = ConstantInt::get(Int32Ty, 0);
Nate Begeman4be54302010-06-20 23:05:28 +00001530 Ops[0] = Builder.CreateInsertElement(V, Ops[0], CI);
1531 return EmitNeonSplat(Ops[0], CI);
1532 }
Bob Wilson537c346112011-06-24 22:13:26 +00001533 case ARM::BI__builtin_neon_vld2_v:
1534 case ARM::BI__builtin_neon_vld2q_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001535 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld2, Ty);
Bob Wilson06b6c582010-08-27 17:14:29 +00001536 Value *Align = GetPointeeAlignment(*this, E->getArg(1));
1537 Ops[1] = Builder.CreateCall2(F, Ops[1], Align, "vld2");
Nate Begeman4be54302010-06-20 23:05:28 +00001538 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1539 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1540 return Builder.CreateStore(Ops[1], Ops[0]);
1541 }
Bob Wilson537c346112011-06-24 22:13:26 +00001542 case ARM::BI__builtin_neon_vld3_v:
1543 case ARM::BI__builtin_neon_vld3q_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001544 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld3, Ty);
Bob Wilson06b6c582010-08-27 17:14:29 +00001545 Value *Align = GetPointeeAlignment(*this, E->getArg(1));
1546 Ops[1] = Builder.CreateCall2(F, Ops[1], Align, "vld3");
Nate Begeman4be54302010-06-20 23:05:28 +00001547 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1548 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1549 return Builder.CreateStore(Ops[1], Ops[0]);
1550 }
Bob Wilson537c346112011-06-24 22:13:26 +00001551 case ARM::BI__builtin_neon_vld4_v:
1552 case ARM::BI__builtin_neon_vld4q_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001553 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld4, Ty);
Bob Wilson06b6c582010-08-27 17:14:29 +00001554 Value *Align = GetPointeeAlignment(*this, E->getArg(1));
1555 Ops[1] = Builder.CreateCall2(F, Ops[1], Align, "vld4");
Nate Begeman4be54302010-06-20 23:05:28 +00001556 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1557 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1558 return Builder.CreateStore(Ops[1], Ops[0]);
1559 }
Bob Wilson537c346112011-06-24 22:13:26 +00001560 case ARM::BI__builtin_neon_vld2_lane_v:
1561 case ARM::BI__builtin_neon_vld2q_lane_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001562 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld2lane, Ty);
Nate Begeman4be54302010-06-20 23:05:28 +00001563 Ops[2] = Builder.CreateBitCast(Ops[2], Ty);
1564 Ops[3] = Builder.CreateBitCast(Ops[3], Ty);
Bob Wilson06b6c582010-08-27 17:14:29 +00001565 Ops.push_back(GetPointeeAlignment(*this, E->getArg(1)));
Frits van Bommel1cbac8a2011-07-25 15:13:01 +00001566 Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld2_lane");
Nate Begeman4be54302010-06-20 23:05:28 +00001567 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1568 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1569 return Builder.CreateStore(Ops[1], Ops[0]);
1570 }
Bob Wilson537c346112011-06-24 22:13:26 +00001571 case ARM::BI__builtin_neon_vld3_lane_v:
1572 case ARM::BI__builtin_neon_vld3q_lane_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001573 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld3lane, Ty);
Nate Begeman4be54302010-06-20 23:05:28 +00001574 Ops[2] = Builder.CreateBitCast(Ops[2], Ty);
1575 Ops[3] = Builder.CreateBitCast(Ops[3], Ty);
1576 Ops[4] = Builder.CreateBitCast(Ops[4], Ty);
Bob Wilson06b6c582010-08-27 17:14:29 +00001577 Ops.push_back(GetPointeeAlignment(*this, E->getArg(1)));
Frits van Bommel1cbac8a2011-07-25 15:13:01 +00001578 Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld3_lane");
Nate Begeman4be54302010-06-20 23:05:28 +00001579 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1580 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1581 return Builder.CreateStore(Ops[1], Ops[0]);
1582 }
Bob Wilson537c346112011-06-24 22:13:26 +00001583 case ARM::BI__builtin_neon_vld4_lane_v:
1584 case ARM::BI__builtin_neon_vld4q_lane_v: {
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001585 Function *F = CGM.getIntrinsic(Intrinsic::arm_neon_vld4lane, Ty);
Nate Begeman4be54302010-06-20 23:05:28 +00001586 Ops[2] = Builder.CreateBitCast(Ops[2], Ty);
1587 Ops[3] = Builder.CreateBitCast(Ops[3], Ty);
1588 Ops[4] = Builder.CreateBitCast(Ops[4], Ty);
1589 Ops[5] = Builder.CreateBitCast(Ops[5], Ty);
Bob Wilson06b6c582010-08-27 17:14:29 +00001590 Ops.push_back(GetPointeeAlignment(*this, E->getArg(1)));
Frits van Bommel1cbac8a2011-07-25 15:13:01 +00001591 Ops[1] = Builder.CreateCall(F, makeArrayRef(Ops).slice(1), "vld3_lane");
Nate Begeman4be54302010-06-20 23:05:28 +00001592 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1593 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1594 return Builder.CreateStore(Ops[1], Ops[0]);
1595 }
Bob Wilson537c346112011-06-24 22:13:26 +00001596 case ARM::BI__builtin_neon_vld2_dup_v:
1597 case ARM::BI__builtin_neon_vld3_dup_v:
1598 case ARM::BI__builtin_neon_vld4_dup_v: {
Bob Wilsona0eb23b2010-12-10 22:54:58 +00001599 // Handle 64-bit elements as a special-case. There is no "dup" needed.
1600 if (VTy->getElementType()->getPrimitiveSizeInBits() == 64) {
1601 switch (BuiltinID) {
Bob Wilson537c346112011-06-24 22:13:26 +00001602 case ARM::BI__builtin_neon_vld2_dup_v:
Bob Wilsona0eb23b2010-12-10 22:54:58 +00001603 Int = Intrinsic::arm_neon_vld2;
1604 break;
Bob Wilson537c346112011-06-24 22:13:26 +00001605 case ARM::BI__builtin_neon_vld3_dup_v:
Bob Wilsona0eb23b2010-12-10 22:54:58 +00001606 Int = Intrinsic::arm_neon_vld2;
1607 break;
Bob Wilson537c346112011-06-24 22:13:26 +00001608 case ARM::BI__builtin_neon_vld4_dup_v:
Bob Wilsona0eb23b2010-12-10 22:54:58 +00001609 Int = Intrinsic::arm_neon_vld2;
1610 break;
David Blaikieb219cfc2011-09-23 05:06:16 +00001611 default: llvm_unreachable("unknown vld_dup intrinsic?");
Bob Wilsona0eb23b2010-12-10 22:54:58 +00001612 }
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001613 Function *F = CGM.getIntrinsic(Int, Ty);
Bob Wilsona0eb23b2010-12-10 22:54:58 +00001614 Value *Align = GetPointeeAlignment(*this, E->getArg(1));
1615 Ops[1] = Builder.CreateCall2(F, Ops[1], Align, "vld_dup");
1616 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1617 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1618 return Builder.CreateStore(Ops[1], Ops[0]);
1619 }
Nate Begeman4be54302010-06-20 23:05:28 +00001620 switch (BuiltinID) {
Bob Wilson537c346112011-06-24 22:13:26 +00001621 case ARM::BI__builtin_neon_vld2_dup_v:
Nate Begeman4be54302010-06-20 23:05:28 +00001622 Int = Intrinsic::arm_neon_vld2lane;
1623 break;
Bob Wilson537c346112011-06-24 22:13:26 +00001624 case ARM::BI__builtin_neon_vld3_dup_v:
Nate Begeman4be54302010-06-20 23:05:28 +00001625 Int = Intrinsic::arm_neon_vld2lane;
1626 break;
Bob Wilson537c346112011-06-24 22:13:26 +00001627 case ARM::BI__builtin_neon_vld4_dup_v:
Nate Begeman4be54302010-06-20 23:05:28 +00001628 Int = Intrinsic::arm_neon_vld2lane;
1629 break;
David Blaikieb219cfc2011-09-23 05:06:16 +00001630 default: llvm_unreachable("unknown vld_dup intrinsic?");
Nate Begeman4be54302010-06-20 23:05:28 +00001631 }
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001632 Function *F = CGM.getIntrinsic(Int, Ty);
Chris Lattner2acc6e32011-07-18 04:24:23 +00001633 llvm::StructType *STy = cast<llvm::StructType>(F->getReturnType());
Nate Begeman4be54302010-06-20 23:05:28 +00001634
1635 SmallVector<Value*, 6> Args;
1636 Args.push_back(Ops[1]);
1637 Args.append(STy->getNumElements(), UndefValue::get(Ty));
1638
Chris Lattner77b89b82010-06-27 07:15:29 +00001639 llvm::Constant *CI = ConstantInt::get(Int32Ty, 0);
Nate Begeman4be54302010-06-20 23:05:28 +00001640 Args.push_back(CI);
Bob Wilson06b6c582010-08-27 17:14:29 +00001641 Args.push_back(GetPointeeAlignment(*this, E->getArg(1)));
Nate Begeman4be54302010-06-20 23:05:28 +00001642
Jay Foad4c7d9f12011-07-15 08:37:34 +00001643 Ops[1] = Builder.CreateCall(F, Args, "vld_dup");
Nate Begeman4be54302010-06-20 23:05:28 +00001644 // splat lane 0 to all elts in each vector of the result.
1645 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1646 Value *Val = Builder.CreateExtractValue(Ops[1], i);
1647 Value *Elt = Builder.CreateBitCast(Val, Ty);
1648 Elt = EmitNeonSplat(Elt, CI);
1649 Elt = Builder.CreateBitCast(Elt, Val->getType());
1650 Ops[1] = Builder.CreateInsertValue(Ops[1], Elt, i);
1651 }
1652 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1653 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1654 return Builder.CreateStore(Ops[1], Ops[0]);
1655 }
Bob Wilson537c346112011-06-24 22:13:26 +00001656 case ARM::BI__builtin_neon_vmax_v:
1657 case ARM::BI__builtin_neon_vmaxq_v:
Nate Begemandf98e1d2010-06-09 18:04:15 +00001658 Int = usgn ? Intrinsic::arm_neon_vmaxu : Intrinsic::arm_neon_vmaxs;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001659 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmax");
Bob Wilson537c346112011-06-24 22:13:26 +00001660 case ARM::BI__builtin_neon_vmin_v:
1661 case ARM::BI__builtin_neon_vminq_v:
Nate Begemandf98e1d2010-06-09 18:04:15 +00001662 Int = usgn ? Intrinsic::arm_neon_vminu : Intrinsic::arm_neon_vmins;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001663 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmin");
Bob Wilson537c346112011-06-24 22:13:26 +00001664 case ARM::BI__builtin_neon_vmovl_v: {
Chris Lattner2acc6e32011-07-18 04:24:23 +00001665 llvm::Type *DTy =llvm::VectorType::getTruncatedElementVectorType(VTy);
Bob Wilson22359412010-09-02 22:37:30 +00001666 Ops[0] = Builder.CreateBitCast(Ops[0], DTy);
Bob Wilson7cea3222010-08-20 03:36:08 +00001667 if (usgn)
1668 return Builder.CreateZExt(Ops[0], Ty, "vmovl");
1669 return Builder.CreateSExt(Ops[0], Ty, "vmovl");
Bob Wilson22359412010-09-02 22:37:30 +00001670 }
Bob Wilson537c346112011-06-24 22:13:26 +00001671 case ARM::BI__builtin_neon_vmovn_v: {
Chris Lattner2acc6e32011-07-18 04:24:23 +00001672 llvm::Type *QTy = llvm::VectorType::getExtendedElementVectorType(VTy);
Bob Wilson22359412010-09-02 22:37:30 +00001673 Ops[0] = Builder.CreateBitCast(Ops[0], QTy);
Bob Wilson3b6081b2010-08-30 19:57:13 +00001674 return Builder.CreateTrunc(Ops[0], Ty, "vmovn");
Bob Wilson22359412010-09-02 22:37:30 +00001675 }
Bob Wilson537c346112011-06-24 22:13:26 +00001676 case ARM::BI__builtin_neon_vmul_v:
1677 case ARM::BI__builtin_neon_vmulq_v:
Bob Wilsonda95f732011-11-08 01:16:11 +00001678 assert(Type.isPoly() && "vmul builtin only supported for polynomial types");
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001679 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vmulp, Ty),
Bob Wilson953d5132010-12-03 17:29:39 +00001680 Ops, "vmul");
Bob Wilson537c346112011-06-24 22:13:26 +00001681 case ARM::BI__builtin_neon_vmull_v:
Bob Wilson2d33e422011-03-31 00:09:00 +00001682 Int = usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls;
Bob Wilsonda95f732011-11-08 01:16:11 +00001683 Int = Type.isPoly() ? (unsigned)Intrinsic::arm_neon_vmullp : Int;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001684 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vmull");
Bob Wilson537c346112011-06-24 22:13:26 +00001685 case ARM::BI__builtin_neon_vpadal_v:
1686 case ARM::BI__builtin_neon_vpadalq_v: {
Nate Begemandf98e1d2010-06-09 18:04:15 +00001687 Int = usgn ? Intrinsic::arm_neon_vpadalu : Intrinsic::arm_neon_vpadals;
Bob Wilsonc1fa01b2010-12-10 05:51:07 +00001688 // The source operand type has twice as many elements of half the size.
1689 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
Chris Lattner2acc6e32011-07-18 04:24:23 +00001690 llvm::Type *EltTy =
John McCalld16c2cf2011-02-08 08:22:06 +00001691 llvm::IntegerType::get(getLLVMContext(), EltBits / 2);
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001692 llvm::Type *NarrowTy =
Bob Wilsonc1fa01b2010-12-10 05:51:07 +00001693 llvm::VectorType::get(EltTy, VTy->getNumElements() * 2);
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001694 llvm::Type *Tys[2] = { Ty, NarrowTy };
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001695 return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vpadal");
Bob Wilsonc1fa01b2010-12-10 05:51:07 +00001696 }
Bob Wilson537c346112011-06-24 22:13:26 +00001697 case ARM::BI__builtin_neon_vpadd_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001698 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vpadd, Ty),
Nate Begeman548f7da2010-06-10 18:11:55 +00001699 Ops, "vpadd");
Bob Wilson537c346112011-06-24 22:13:26 +00001700 case ARM::BI__builtin_neon_vpaddl_v:
1701 case ARM::BI__builtin_neon_vpaddlq_v: {
Nate Begeman548f7da2010-06-10 18:11:55 +00001702 Int = usgn ? Intrinsic::arm_neon_vpaddlu : Intrinsic::arm_neon_vpaddls;
Bob Wilsonc1fa01b2010-12-10 05:51:07 +00001703 // The source operand type has twice as many elements of half the size.
1704 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
Chris Lattner2acc6e32011-07-18 04:24:23 +00001705 llvm::Type *EltTy = llvm::IntegerType::get(getLLVMContext(), EltBits / 2);
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001706 llvm::Type *NarrowTy =
Bob Wilsonc1fa01b2010-12-10 05:51:07 +00001707 llvm::VectorType::get(EltTy, VTy->getNumElements() * 2);
Chris Lattner9cbe4f02011-07-09 17:41:47 +00001708 llvm::Type *Tys[2] = { Ty, NarrowTy };
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001709 return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vpaddl");
Bob Wilsonc1fa01b2010-12-10 05:51:07 +00001710 }
Bob Wilson537c346112011-06-24 22:13:26 +00001711 case ARM::BI__builtin_neon_vpmax_v:
Nate Begeman548f7da2010-06-10 18:11:55 +00001712 Int = usgn ? Intrinsic::arm_neon_vpmaxu : Intrinsic::arm_neon_vpmaxs;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001713 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmax");
Bob Wilson537c346112011-06-24 22:13:26 +00001714 case ARM::BI__builtin_neon_vpmin_v:
Nate Begeman548f7da2010-06-10 18:11:55 +00001715 Int = usgn ? Intrinsic::arm_neon_vpminu : Intrinsic::arm_neon_vpmins;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001716 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vpmin");
Bob Wilson537c346112011-06-24 22:13:26 +00001717 case ARM::BI__builtin_neon_vqabs_v:
1718 case ARM::BI__builtin_neon_vqabsq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001719 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqabs, Ty),
Nate Begeman548f7da2010-06-10 18:11:55 +00001720 Ops, "vqabs");
Bob Wilson537c346112011-06-24 22:13:26 +00001721 case ARM::BI__builtin_neon_vqadd_v:
1722 case ARM::BI__builtin_neon_vqaddq_v:
Nate Begeman548f7da2010-06-10 18:11:55 +00001723 Int = usgn ? Intrinsic::arm_neon_vqaddu : Intrinsic::arm_neon_vqadds;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001724 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqadd");
Bob Wilson537c346112011-06-24 22:13:26 +00001725 case ARM::BI__builtin_neon_vqdmlal_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001726 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmlal, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001727 Ops, "vqdmlal");
Bob Wilson537c346112011-06-24 22:13:26 +00001728 case ARM::BI__builtin_neon_vqdmlsl_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001729 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmlsl, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001730 Ops, "vqdmlsl");
Bob Wilson537c346112011-06-24 22:13:26 +00001731 case ARM::BI__builtin_neon_vqdmulh_v:
1732 case ARM::BI__builtin_neon_vqdmulhq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001733 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmulh, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001734 Ops, "vqdmulh");
Bob Wilson537c346112011-06-24 22:13:26 +00001735 case ARM::BI__builtin_neon_vqdmull_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001736 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqdmull, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001737 Ops, "vqdmull");
Bob Wilson537c346112011-06-24 22:13:26 +00001738 case ARM::BI__builtin_neon_vqmovn_v:
Nate Begeman548f7da2010-06-10 18:11:55 +00001739 Int = usgn ? Intrinsic::arm_neon_vqmovnu : Intrinsic::arm_neon_vqmovns;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001740 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqmovn");
Bob Wilson537c346112011-06-24 22:13:26 +00001741 case ARM::BI__builtin_neon_vqmovun_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001742 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqmovnsu, Ty),
Nate Begeman548f7da2010-06-10 18:11:55 +00001743 Ops, "vqdmull");
Bob Wilson537c346112011-06-24 22:13:26 +00001744 case ARM::BI__builtin_neon_vqneg_v:
1745 case ARM::BI__builtin_neon_vqnegq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001746 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqneg, Ty),
Nate Begeman61eecf52010-06-14 05:21:25 +00001747 Ops, "vqneg");
Bob Wilson537c346112011-06-24 22:13:26 +00001748 case ARM::BI__builtin_neon_vqrdmulh_v:
1749 case ARM::BI__builtin_neon_vqrdmulhq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001750 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrdmulh, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001751 Ops, "vqrdmulh");
Bob Wilson537c346112011-06-24 22:13:26 +00001752 case ARM::BI__builtin_neon_vqrshl_v:
1753 case ARM::BI__builtin_neon_vqrshlq_v:
Nate Begeman548f7da2010-06-10 18:11:55 +00001754 Int = usgn ? Intrinsic::arm_neon_vqrshiftu : Intrinsic::arm_neon_vqrshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001755 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshl");
Bob Wilson537c346112011-06-24 22:13:26 +00001756 case ARM::BI__builtin_neon_vqrshrn_n_v:
Nate Begeman548f7da2010-06-10 18:11:55 +00001757 Int = usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001758 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqrshrn_n",
Nate Begeman61eecf52010-06-14 05:21:25 +00001759 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001760 case ARM::BI__builtin_neon_vqrshrun_n_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001761 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqrshiftnsu, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001762 Ops, "vqrshrun_n", 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001763 case ARM::BI__builtin_neon_vqshl_v:
1764 case ARM::BI__builtin_neon_vqshlq_v:
Nate Begeman61eecf52010-06-14 05:21:25 +00001765 Int = usgn ? Intrinsic::arm_neon_vqshiftu : Intrinsic::arm_neon_vqshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001766 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshl");
Bob Wilson537c346112011-06-24 22:13:26 +00001767 case ARM::BI__builtin_neon_vqshl_n_v:
1768 case ARM::BI__builtin_neon_vqshlq_n_v:
Nate Begeman61eecf52010-06-14 05:21:25 +00001769 Int = usgn ? Intrinsic::arm_neon_vqshiftu : Intrinsic::arm_neon_vqshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001770 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshl_n",
Nate Begeman61eecf52010-06-14 05:21:25 +00001771 1, false);
Bob Wilson537c346112011-06-24 22:13:26 +00001772 case ARM::BI__builtin_neon_vqshlu_n_v:
1773 case ARM::BI__builtin_neon_vqshluq_n_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001774 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftsu, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001775 Ops, "vqshlu", 1, false);
Bob Wilson537c346112011-06-24 22:13:26 +00001776 case ARM::BI__builtin_neon_vqshrn_n_v:
Nate Begeman61eecf52010-06-14 05:21:25 +00001777 Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001778 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqshrn_n",
Nate Begeman61eecf52010-06-14 05:21:25 +00001779 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001780 case ARM::BI__builtin_neon_vqshrun_n_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001781 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vqshiftnsu, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001782 Ops, "vqshrun_n", 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001783 case ARM::BI__builtin_neon_vqsub_v:
1784 case ARM::BI__builtin_neon_vqsubq_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001785 Int = usgn ? Intrinsic::arm_neon_vqsubu : Intrinsic::arm_neon_vqsubs;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001786 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vqsub");
Bob Wilson537c346112011-06-24 22:13:26 +00001787 case ARM::BI__builtin_neon_vraddhn_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001788 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vraddhn, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001789 Ops, "vraddhn");
Bob Wilson537c346112011-06-24 22:13:26 +00001790 case ARM::BI__builtin_neon_vrecpe_v:
1791 case ARM::BI__builtin_neon_vrecpeq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001792 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecpe, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001793 Ops, "vrecpe");
Bob Wilson537c346112011-06-24 22:13:26 +00001794 case ARM::BI__builtin_neon_vrecps_v:
1795 case ARM::BI__builtin_neon_vrecpsq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001796 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrecps, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001797 Ops, "vrecps");
Bob Wilson537c346112011-06-24 22:13:26 +00001798 case ARM::BI__builtin_neon_vrhadd_v:
1799 case ARM::BI__builtin_neon_vrhaddq_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001800 Int = usgn ? Intrinsic::arm_neon_vrhaddu : Intrinsic::arm_neon_vrhadds;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001801 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrhadd");
Bob Wilson537c346112011-06-24 22:13:26 +00001802 case ARM::BI__builtin_neon_vrshl_v:
1803 case ARM::BI__builtin_neon_vrshlq_v:
Nate Begeman5af93ef2010-06-12 06:06:07 +00001804 Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001805 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshl");
Bob Wilson537c346112011-06-24 22:13:26 +00001806 case ARM::BI__builtin_neon_vrshrn_n_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001807 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrshiftn, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001808 Ops, "vrshrn_n", 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001809 case ARM::BI__builtin_neon_vrshr_n_v:
1810 case ARM::BI__builtin_neon_vrshrq_n_v:
Nate Begeman5af93ef2010-06-12 06:06:07 +00001811 Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001812 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vrshr_n", 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001813 case ARM::BI__builtin_neon_vrsqrte_v:
1814 case ARM::BI__builtin_neon_vrsqrteq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001815 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrsqrte, Ty),
Nate Begeman5af93ef2010-06-12 06:06:07 +00001816 Ops, "vrsqrte");
Bob Wilson537c346112011-06-24 22:13:26 +00001817 case ARM::BI__builtin_neon_vrsqrts_v:
1818 case ARM::BI__builtin_neon_vrsqrtsq_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001819 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrsqrts, Ty),
Nate Begeman5af93ef2010-06-12 06:06:07 +00001820 Ops, "vrsqrts");
Bob Wilson537c346112011-06-24 22:13:26 +00001821 case ARM::BI__builtin_neon_vrsra_n_v:
1822 case ARM::BI__builtin_neon_vrsraq_n_v:
Nate Begeman5af93ef2010-06-12 06:06:07 +00001823 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1824 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
1825 Ops[2] = EmitNeonShiftVector(Ops[2], Ty, true);
1826 Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001827 Ops[1] = Builder.CreateCall2(CGM.getIntrinsic(Int, Ty), Ops[1], Ops[2]);
Nate Begeman5af93ef2010-06-12 06:06:07 +00001828 return Builder.CreateAdd(Ops[0], Ops[1], "vrsra_n");
Bob Wilson537c346112011-06-24 22:13:26 +00001829 case ARM::BI__builtin_neon_vrsubhn_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001830 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vrsubhn, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001831 Ops, "vrsubhn");
Bob Wilson537c346112011-06-24 22:13:26 +00001832 case ARM::BI__builtin_neon_vshl_v:
1833 case ARM::BI__builtin_neon_vshlq_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001834 Int = usgn ? Intrinsic::arm_neon_vshiftu : Intrinsic::arm_neon_vshifts;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001835 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vshl");
Bob Wilson537c346112011-06-24 22:13:26 +00001836 case ARM::BI__builtin_neon_vshll_n_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001837 Int = usgn ? Intrinsic::arm_neon_vshiftlu : Intrinsic::arm_neon_vshiftls;
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001838 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vshll", 1);
Bob Wilson537c346112011-06-24 22:13:26 +00001839 case ARM::BI__builtin_neon_vshl_n_v:
1840 case ARM::BI__builtin_neon_vshlq_n_v:
Nate Begeman61eecf52010-06-14 05:21:25 +00001841 Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false);
1842 return Builder.CreateShl(Builder.CreateBitCast(Ops[0],Ty), Ops[1], "vshl_n");
Bob Wilson537c346112011-06-24 22:13:26 +00001843 case ARM::BI__builtin_neon_vshrn_n_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001844 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftn, Ty),
Bob Wilsondb3d4d02010-12-08 22:37:56 +00001845 Ops, "vshrn_n", 1, true);
Bob Wilson537c346112011-06-24 22:13:26 +00001846 case ARM::BI__builtin_neon_vshr_n_v:
1847 case ARM::BI__builtin_neon_vshrq_n_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001848 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
Nate Begeman61eecf52010-06-14 05:21:25 +00001849 Ops[1] = EmitNeonShiftVector(Ops[1], Ty, false);
Nate Begeman464ccb62010-06-11 22:57:12 +00001850 if (usgn)
1851 return Builder.CreateLShr(Ops[0], Ops[1], "vshr_n");
1852 else
1853 return Builder.CreateAShr(Ops[0], Ops[1], "vshr_n");
Bob Wilson537c346112011-06-24 22:13:26 +00001854 case ARM::BI__builtin_neon_vsri_n_v:
1855 case ARM::BI__builtin_neon_vsriq_n_v:
Bob Wilson79653962010-12-03 17:10:22 +00001856 rightShift = true;
Bob Wilson537c346112011-06-24 22:13:26 +00001857 case ARM::BI__builtin_neon_vsli_n_v:
1858 case ARM::BI__builtin_neon_vsliq_n_v:
Bob Wilson79653962010-12-03 17:10:22 +00001859 Ops[2] = EmitNeonShiftVector(Ops[2], Ty, rightShift);
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001860 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vshiftins, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001861 Ops, "vsli_n");
Bob Wilson537c346112011-06-24 22:13:26 +00001862 case ARM::BI__builtin_neon_vsra_n_v:
1863 case ARM::BI__builtin_neon_vsraq_n_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001864 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1865 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
Nate Begeman61eecf52010-06-14 05:21:25 +00001866 Ops[2] = EmitNeonShiftVector(Ops[2], Ty, false);
Nate Begeman464ccb62010-06-11 22:57:12 +00001867 if (usgn)
1868 Ops[1] = Builder.CreateLShr(Ops[1], Ops[2], "vsra_n");
1869 else
1870 Ops[1] = Builder.CreateAShr(Ops[1], Ops[2], "vsra_n");
1871 return Builder.CreateAdd(Ops[0], Ops[1]);
Bob Wilson537c346112011-06-24 22:13:26 +00001872 case ARM::BI__builtin_neon_vst1_v:
1873 case ARM::BI__builtin_neon_vst1q_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001874 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001875 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst1, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001876 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001877 case ARM::BI__builtin_neon_vst1_lane_v:
1878 case ARM::BI__builtin_neon_vst1q_lane_v:
Nate Begeman464ccb62010-06-11 22:57:12 +00001879 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
1880 Ops[1] = Builder.CreateExtractElement(Ops[1], Ops[2]);
1881 Ty = llvm::PointerType::getUnqual(Ops[1]->getType());
1882 return Builder.CreateStore(Ops[1], Builder.CreateBitCast(Ops[0], Ty));
Bob Wilson537c346112011-06-24 22:13:26 +00001883 case ARM::BI__builtin_neon_vst2_v:
1884 case ARM::BI__builtin_neon_vst2q_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001885 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001886 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst2, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001887 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001888 case ARM::BI__builtin_neon_vst2_lane_v:
1889 case ARM::BI__builtin_neon_vst2q_lane_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001890 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001891 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst2lane, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001892 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001893 case ARM::BI__builtin_neon_vst3_v:
1894 case ARM::BI__builtin_neon_vst3q_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001895 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001896 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst3, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001897 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001898 case ARM::BI__builtin_neon_vst3_lane_v:
1899 case ARM::BI__builtin_neon_vst3q_lane_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001900 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001901 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst3lane, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001902 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001903 case ARM::BI__builtin_neon_vst4_v:
1904 case ARM::BI__builtin_neon_vst4q_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001905 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001906 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst4, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001907 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001908 case ARM::BI__builtin_neon_vst4_lane_v:
1909 case ARM::BI__builtin_neon_vst4q_lane_v:
Bob Wilson06b6c582010-08-27 17:14:29 +00001910 Ops.push_back(GetPointeeAlignment(*this, E->getArg(0)));
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001911 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vst4lane, Ty),
Nate Begeman464ccb62010-06-11 22:57:12 +00001912 Ops, "");
Bob Wilson537c346112011-06-24 22:13:26 +00001913 case ARM::BI__builtin_neon_vsubhn_v:
Benjamin Kramer8dd55a32011-07-14 17:45:50 +00001914 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vsubhn, Ty),
Nate Begeman548f7da2010-06-10 18:11:55 +00001915 Ops, "vsubhn");
Bob Wilson537c346112011-06-24 22:13:26 +00001916 case ARM::BI__builtin_neon_vtbl1_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001917 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl1),
1918 Ops, "vtbl1");
Bob Wilson537c346112011-06-24 22:13:26 +00001919 case ARM::BI__builtin_neon_vtbl2_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001920 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl2),
1921 Ops, "vtbl2");
Bob Wilson537c346112011-06-24 22:13:26 +00001922 case ARM::BI__builtin_neon_vtbl3_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001923 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl3),
1924 Ops, "vtbl3");
Bob Wilson537c346112011-06-24 22:13:26 +00001925 case ARM::BI__builtin_neon_vtbl4_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001926 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbl4),
1927 Ops, "vtbl4");
Bob Wilson537c346112011-06-24 22:13:26 +00001928 case ARM::BI__builtin_neon_vtbx1_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001929 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx1),
1930 Ops, "vtbx1");
Bob Wilson537c346112011-06-24 22:13:26 +00001931 case ARM::BI__builtin_neon_vtbx2_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001932 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx2),
1933 Ops, "vtbx2");
Bob Wilson537c346112011-06-24 22:13:26 +00001934 case ARM::BI__builtin_neon_vtbx3_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001935 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx3),
1936 Ops, "vtbx3");
Bob Wilson537c346112011-06-24 22:13:26 +00001937 case ARM::BI__builtin_neon_vtbx4_v:
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001938 return EmitNeonCall(CGM.getIntrinsic(Intrinsic::arm_neon_vtbx4),
1939 Ops, "vtbx4");
Bob Wilson537c346112011-06-24 22:13:26 +00001940 case ARM::BI__builtin_neon_vtst_v:
1941 case ARM::BI__builtin_neon_vtstq_v: {
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001942 Ops[0] = Builder.CreateBitCast(Ops[0], Ty);
1943 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
1944 Ops[0] = Builder.CreateAnd(Ops[0], Ops[1]);
1945 Ops[0] = Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0],
1946 ConstantAggregateZero::get(Ty));
1947 return Builder.CreateSExt(Ops[0], Ty, "vtst");
1948 }
Bob Wilson537c346112011-06-24 22:13:26 +00001949 case ARM::BI__builtin_neon_vtrn_v:
1950 case ARM::BI__builtin_neon_vtrnq_v: {
Nate Begeman4be54302010-06-20 23:05:28 +00001951 Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty));
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001952 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
Nate Begeman4be54302010-06-20 23:05:28 +00001953 Ops[2] = Builder.CreateBitCast(Ops[2], Ty);
Ted Kremenek9577abc2011-01-23 17:04:59 +00001954 Value *SV = 0;
Nate Begeman4be54302010-06-20 23:05:28 +00001955
1956 for (unsigned vi = 0; vi != 2; ++vi) {
1957 SmallVector<Constant*, 16> Indices;
1958 for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
Chris Lattner77b89b82010-06-27 07:15:29 +00001959 Indices.push_back(ConstantInt::get(Int32Ty, i+vi));
1960 Indices.push_back(ConstantInt::get(Int32Ty, i+e+vi));
Nate Begeman4be54302010-06-20 23:05:28 +00001961 }
1962 Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi);
Chris Lattnerfb018d12011-02-15 00:14:06 +00001963 SV = llvm::ConstantVector::get(Indices);
Nate Begeman4be54302010-06-20 23:05:28 +00001964 SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vtrn");
1965 SV = Builder.CreateStore(SV, Addr);
1966 }
1967 return SV;
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001968 }
Bob Wilson537c346112011-06-24 22:13:26 +00001969 case ARM::BI__builtin_neon_vuzp_v:
1970 case ARM::BI__builtin_neon_vuzpq_v: {
Nate Begeman4be54302010-06-20 23:05:28 +00001971 Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty));
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001972 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
Nate Begeman4be54302010-06-20 23:05:28 +00001973 Ops[2] = Builder.CreateBitCast(Ops[2], Ty);
Ted Kremenek9577abc2011-01-23 17:04:59 +00001974 Value *SV = 0;
Nate Begeman4be54302010-06-20 23:05:28 +00001975
1976 for (unsigned vi = 0; vi != 2; ++vi) {
1977 SmallVector<Constant*, 16> Indices;
1978 for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
Chris Lattner77b89b82010-06-27 07:15:29 +00001979 Indices.push_back(ConstantInt::get(Int32Ty, 2*i+vi));
Nate Begeman4be54302010-06-20 23:05:28 +00001980
1981 Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi);
Chris Lattnerfb018d12011-02-15 00:14:06 +00001982 SV = llvm::ConstantVector::get(Indices);
Nate Begeman4be54302010-06-20 23:05:28 +00001983 SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vuzp");
1984 SV = Builder.CreateStore(SV, Addr);
1985 }
1986 return SV;
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001987 }
Bob Wilson537c346112011-06-24 22:13:26 +00001988 case ARM::BI__builtin_neon_vzip_v:
1989 case ARM::BI__builtin_neon_vzipq_v: {
Nate Begeman4be54302010-06-20 23:05:28 +00001990 Ops[0] = Builder.CreateBitCast(Ops[0], llvm::PointerType::getUnqual(Ty));
Nate Begeman1c2a88c2010-06-09 01:10:23 +00001991 Ops[1] = Builder.CreateBitCast(Ops[1], Ty);
Nate Begeman4be54302010-06-20 23:05:28 +00001992 Ops[2] = Builder.CreateBitCast(Ops[2], Ty);
Ted Kremenek9577abc2011-01-23 17:04:59 +00001993 Value *SV = 0;
Nate Begeman4be54302010-06-20 23:05:28 +00001994
1995 for (unsigned vi = 0; vi != 2; ++vi) {
1996 SmallVector<Constant*, 16> Indices;
1997 for (unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
Daniel Dunbare361cc32010-08-26 00:55:57 +00001998 Indices.push_back(ConstantInt::get(Int32Ty, (i + vi*e) >> 1));
1999 Indices.push_back(ConstantInt::get(Int32Ty, ((i + vi*e) >> 1)+e));
Nate Begeman4be54302010-06-20 23:05:28 +00002000 }
2001 Value *Addr = Builder.CreateConstInBoundsGEP1_32(Ops[0], vi);
Chris Lattnerfb018d12011-02-15 00:14:06 +00002002 SV = llvm::ConstantVector::get(Indices);
Nate Begeman4be54302010-06-20 23:05:28 +00002003 SV = Builder.CreateShuffleVector(Ops[1], Ops[2], SV, "vzip");
2004 SV = Builder.CreateStore(SV, Addr);
2005 }
2006 return SV;
Nate Begeman9eb65a52010-06-08 00:17:19 +00002007 }
Chris Lattner2752c012010-03-03 19:03:45 +00002008 }
2009}
2010
Bill Wendlingaa51e512010-10-09 08:47:25 +00002011llvm::Value *CodeGenFunction::
Chris Lattner5f9e2722011-07-23 10:55:15 +00002012BuildVector(const SmallVectorImpl<llvm::Value*> &Ops) {
Bill Wendlingaa51e512010-10-09 08:47:25 +00002013 assert((Ops.size() & (Ops.size() - 1)) == 0 &&
2014 "Not a power-of-two sized vector!");
2015 bool AllConstants = true;
2016 for (unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i)
2017 AllConstants &= isa<Constant>(Ops[i]);
2018
2019 // If this is a constant vector, create a ConstantVector.
2020 if (AllConstants) {
2021 std::vector<llvm::Constant*> CstOps;
2022 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
2023 CstOps.push_back(cast<Constant>(Ops[i]));
2024 return llvm::ConstantVector::get(CstOps);
2025 }
2026
2027 // Otherwise, insertelement the values to build the vector.
2028 Value *Result =
2029 llvm::UndefValue::get(llvm::VectorType::get(Ops[0]->getType(), Ops.size()));
2030
2031 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
2032 Result = Builder.CreateInsertElement(Result, Ops[i],
John McCalld16c2cf2011-02-08 08:22:06 +00002033 llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), i));
Bill Wendlingaa51e512010-10-09 08:47:25 +00002034
2035 return Result;
2036}
2037
Mike Stump1eb44332009-09-09 15:08:12 +00002038Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
Chris Lattner1feedd82007-12-13 07:34:23 +00002039 const CallExpr *E) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00002040 SmallVector<Value*, 4> Ops;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002041
Chris Lattner46c55912010-10-02 00:09:12 +00002042 // Find out if any arguments are required to be integer constant expressions.
2043 unsigned ICEArguments = 0;
2044 ASTContext::GetBuiltinTypeError Error;
2045 getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
2046 assert(Error == ASTContext::GE_None && "Should not codegen an error");
2047
2048 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
2049 // If this is a normal argument, just emit it as a scalar.
2050 if ((ICEArguments & (1 << i)) == 0) {
2051 Ops.push_back(EmitScalarExpr(E->getArg(i)));
2052 continue;
2053 }
2054
2055 // If this is required to be a constant, constant fold it so that we know
2056 // that the generated intrinsic gets a ConstantInt.
2057 llvm::APSInt Result;
2058 bool IsConst = E->getArg(i)->isIntegerConstantExpr(Result, getContext());
2059 assert(IsConst && "Constant arg isn't actually constant?"); (void)IsConst;
John McCalld16c2cf2011-02-08 08:22:06 +00002060 Ops.push_back(llvm::ConstantInt::get(getLLVMContext(), Result));
Chris Lattner46c55912010-10-02 00:09:12 +00002061 }
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002062
Anders Carlsson564f1de2007-12-09 23:17:02 +00002063 switch (BuiltinID) {
Anders Carlsson46a26b02007-12-09 23:39:18 +00002064 default: return 0;
Craig Topper5c752082011-12-25 06:25:37 +00002065 case X86::BI__builtin_clzs: {
2066 Value *ArgValue = EmitScalarExpr(E->getArg(0));
2067
2068 llvm::Type *ArgType = ArgValue->getType();
2069 Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
2070
2071 llvm::Type *ResultType = ConvertType(E->getType());
2072 Value *Result = Builder.CreateCall2(F, ArgValue, Builder.getTrue());
2073 if (Result->getType() != ResultType)
2074 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
2075 "cast");
2076 return Result;
2077 }
2078 case X86::BI__builtin_ctzs: {
2079 Value *ArgValue = EmitScalarExpr(E->getArg(0));
2080
2081 llvm::Type *ArgType = ArgValue->getType();
2082 Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
2083
2084 llvm::Type *ResultType = ConvertType(E->getType());
2085 Value *Result = Builder.CreateCall2(F, ArgValue, Builder.getTrue());
2086 if (Result->getType() != ResultType)
2087 Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
2088 "cast");
2089 return Result;
2090 }
Mike Stump1eb44332009-09-09 15:08:12 +00002091 case X86::BI__builtin_ia32_pslldi128:
Nate Begemane7722102008-04-14 04:49:57 +00002092 case X86::BI__builtin_ia32_psllqi128:
Mike Stump1eb44332009-09-09 15:08:12 +00002093 case X86::BI__builtin_ia32_psllwi128:
Nate Begemane7722102008-04-14 04:49:57 +00002094 case X86::BI__builtin_ia32_psradi128:
2095 case X86::BI__builtin_ia32_psrawi128:
2096 case X86::BI__builtin_ia32_psrldi128:
2097 case X86::BI__builtin_ia32_psrlqi128:
2098 case X86::BI__builtin_ia32_psrlwi128: {
Chris Lattner77b89b82010-06-27 07:15:29 +00002099 Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty, "zext");
Chris Lattner2acc6e32011-07-18 04:24:23 +00002100 llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 2);
Chris Lattner77b89b82010-06-27 07:15:29 +00002101 llvm::Value *Zero = llvm::ConstantInt::get(Int32Ty, 0);
Owen Anderson03e20502009-07-30 23:11:26 +00002102 Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty),
Nate Begemane7722102008-04-14 04:49:57 +00002103 Ops[1], Zero, "insert");
2104 Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast");
2105 const char *name = 0;
2106 Intrinsic::ID ID = Intrinsic::not_intrinsic;
Mike Stump1eb44332009-09-09 15:08:12 +00002107
Nate Begemane7722102008-04-14 04:49:57 +00002108 switch (BuiltinID) {
David Blaikieb219cfc2011-09-23 05:06:16 +00002109 default: llvm_unreachable("Unsupported shift intrinsic!");
Nate Begemane7722102008-04-14 04:49:57 +00002110 case X86::BI__builtin_ia32_pslldi128:
2111 name = "pslldi";
2112 ID = Intrinsic::x86_sse2_psll_d;
2113 break;
2114 case X86::BI__builtin_ia32_psllqi128:
2115 name = "psllqi";
2116 ID = Intrinsic::x86_sse2_psll_q;
2117 break;
2118 case X86::BI__builtin_ia32_psllwi128:
2119 name = "psllwi";
2120 ID = Intrinsic::x86_sse2_psll_w;
2121 break;
2122 case X86::BI__builtin_ia32_psradi128:
2123 name = "psradi";
2124 ID = Intrinsic::x86_sse2_psra_d;
2125 break;
2126 case X86::BI__builtin_ia32_psrawi128:
2127 name = "psrawi";
2128 ID = Intrinsic::x86_sse2_psra_w;
2129 break;
2130 case X86::BI__builtin_ia32_psrldi128:
2131 name = "psrldi";
2132 ID = Intrinsic::x86_sse2_psrl_d;
2133 break;
2134 case X86::BI__builtin_ia32_psrlqi128:
2135 name = "psrlqi";
2136 ID = Intrinsic::x86_sse2_psrl_q;
2137 break;
2138 case X86::BI__builtin_ia32_psrlwi128:
2139 name = "psrlwi";
2140 ID = Intrinsic::x86_sse2_psrl_w;
2141 break;
2142 }
2143 llvm::Function *F = CGM.getIntrinsic(ID);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002144 return Builder.CreateCall(F, Ops, name);
Nate Begemane7722102008-04-14 04:49:57 +00002145 }
Bill Wendlingaa51e512010-10-09 08:47:25 +00002146 case X86::BI__builtin_ia32_vec_init_v8qi:
2147 case X86::BI__builtin_ia32_vec_init_v4hi:
2148 case X86::BI__builtin_ia32_vec_init_v2si:
2149 return Builder.CreateBitCast(BuildVector(Ops),
John McCalld16c2cf2011-02-08 08:22:06 +00002150 llvm::Type::getX86_MMXTy(getLLVMContext()));
Argyrios Kyrtzidis1944ec12010-10-10 03:19:11 +00002151 case X86::BI__builtin_ia32_vec_ext_v2si:
2152 return Builder.CreateExtractElement(Ops[0],
2153 llvm::ConstantInt::get(Ops[1]->getType(), 0));
Mike Stump1eb44332009-09-09 15:08:12 +00002154 case X86::BI__builtin_ia32_pslldi:
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002155 case X86::BI__builtin_ia32_psllqi:
Mike Stump1eb44332009-09-09 15:08:12 +00002156 case X86::BI__builtin_ia32_psllwi:
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002157 case X86::BI__builtin_ia32_psradi:
2158 case X86::BI__builtin_ia32_psrawi:
2159 case X86::BI__builtin_ia32_psrldi:
2160 case X86::BI__builtin_ia32_psrlqi:
2161 case X86::BI__builtin_ia32_psrlwi: {
Chris Lattner77b89b82010-06-27 07:15:29 +00002162 Ops[1] = Builder.CreateZExt(Ops[1], Int64Ty, "zext");
Chris Lattner2acc6e32011-07-18 04:24:23 +00002163 llvm::Type *Ty = llvm::VectorType::get(Int64Ty, 1);
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002164 Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast");
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002165 const char *name = 0;
2166 Intrinsic::ID ID = Intrinsic::not_intrinsic;
Mike Stump1eb44332009-09-09 15:08:12 +00002167
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002168 switch (BuiltinID) {
David Blaikieb219cfc2011-09-23 05:06:16 +00002169 default: llvm_unreachable("Unsupported shift intrinsic!");
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002170 case X86::BI__builtin_ia32_pslldi:
2171 name = "pslldi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002172 ID = Intrinsic::x86_mmx_psll_d;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002173 break;
2174 case X86::BI__builtin_ia32_psllqi:
2175 name = "psllqi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002176 ID = Intrinsic::x86_mmx_psll_q;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002177 break;
2178 case X86::BI__builtin_ia32_psllwi:
2179 name = "psllwi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002180 ID = Intrinsic::x86_mmx_psll_w;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002181 break;
2182 case X86::BI__builtin_ia32_psradi:
2183 name = "psradi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002184 ID = Intrinsic::x86_mmx_psra_d;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002185 break;
2186 case X86::BI__builtin_ia32_psrawi:
2187 name = "psrawi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002188 ID = Intrinsic::x86_mmx_psra_w;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002189 break;
2190 case X86::BI__builtin_ia32_psrldi:
2191 name = "psrldi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002192 ID = Intrinsic::x86_mmx_psrl_d;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002193 break;
2194 case X86::BI__builtin_ia32_psrlqi:
2195 name = "psrlqi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002196 ID = Intrinsic::x86_mmx_psrl_q;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002197 break;
2198 case X86::BI__builtin_ia32_psrlwi:
2199 name = "psrlwi";
Bill Wendlingdf4d4822010-09-27 21:22:25 +00002200 ID = Intrinsic::x86_mmx_psrl_w;
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002201 break;
2202 }
Chris Lattner7acda7c2007-12-18 00:25:38 +00002203 llvm::Function *F = CGM.getIntrinsic(ID);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002204 return Builder.CreateCall(F, Ops, name);
Anders Carlsson2929cfa2007-12-14 17:48:24 +00002205 }
Anders Carlsson79dcf5f2009-05-18 19:16:46 +00002206 case X86::BI__builtin_ia32_cmpps: {
2207 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002208 return Builder.CreateCall(F, Ops, "cmpps");
Anders Carlsson79dcf5f2009-05-18 19:16:46 +00002209 }
2210 case X86::BI__builtin_ia32_cmpss: {
2211 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002212 return Builder.CreateCall(F, Ops, "cmpss");
Anders Carlssoncc8b7f92007-12-16 22:33:50 +00002213 }
Nate Begemane7722102008-04-14 04:49:57 +00002214 case X86::BI__builtin_ia32_ldmxcsr: {
Chris Lattner2acc6e32011-07-18 04:24:23 +00002215 llvm::Type *PtrTy = Int8PtrTy;
Chris Lattner77b89b82010-06-27 07:15:29 +00002216 Value *One = llvm::ConstantInt::get(Int32Ty, 1);
Benjamin Kramer578faa82011-09-27 21:06:10 +00002217 Value *Tmp = Builder.CreateAlloca(Int32Ty, One);
Nate Begemane7722102008-04-14 04:49:57 +00002218 Builder.CreateStore(Ops[0], Tmp);
2219 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr),
Chris Lattner3eae03e2008-05-06 00:56:42 +00002220 Builder.CreateBitCast(Tmp, PtrTy));
Nate Begemane7722102008-04-14 04:49:57 +00002221 }
2222 case X86::BI__builtin_ia32_stmxcsr: {
Chris Lattner2acc6e32011-07-18 04:24:23 +00002223 llvm::Type *PtrTy = Int8PtrTy;
Chris Lattner77b89b82010-06-27 07:15:29 +00002224 Value *One = llvm::ConstantInt::get(Int32Ty, 1);
Benjamin Kramer578faa82011-09-27 21:06:10 +00002225 Value *Tmp = Builder.CreateAlloca(Int32Ty, One);
Ted Kremenek012614e2011-08-17 21:04:19 +00002226 Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr),
2227 Builder.CreateBitCast(Tmp, PtrTy));
Nate Begemane7722102008-04-14 04:49:57 +00002228 return Builder.CreateLoad(Tmp, "stmxcsr");
2229 }
Anders Carlsson79dcf5f2009-05-18 19:16:46 +00002230 case X86::BI__builtin_ia32_cmppd: {
2231 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002232 return Builder.CreateCall(F, Ops, "cmppd");
Anders Carlsson79dcf5f2009-05-18 19:16:46 +00002233 }
2234 case X86::BI__builtin_ia32_cmpsd: {
2235 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002236 return Builder.CreateCall(F, Ops, "cmpsd");
Anders Carlssoncc8b7f92007-12-16 22:33:50 +00002237 }
Nate Begemane7722102008-04-14 04:49:57 +00002238 case X86::BI__builtin_ia32_storehps:
2239 case X86::BI__builtin_ia32_storelps: {
Chris Lattner77b89b82010-06-27 07:15:29 +00002240 llvm::Type *PtrTy = llvm::PointerType::getUnqual(Int64Ty);
2241 llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2);
Mike Stump1eb44332009-09-09 15:08:12 +00002242
Nate Begemane7722102008-04-14 04:49:57 +00002243 // cast val v2i64
2244 Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast");
Mike Stump1eb44332009-09-09 15:08:12 +00002245
Nate Begemane7722102008-04-14 04:49:57 +00002246 // extract (0, 1)
2247 unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1;
Chris Lattner77b89b82010-06-27 07:15:29 +00002248 llvm::Value *Idx = llvm::ConstantInt::get(Int32Ty, Index);
Nate Begemane7722102008-04-14 04:49:57 +00002249 Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract");
2250
2251 // cast pointer to i64 & store
2252 Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy);
2253 return Builder.CreateStore(Ops[1], Ops[0]);
2254 }
Bill Wendling28cab382010-09-28 01:28:56 +00002255 case X86::BI__builtin_ia32_palignr: {
2256 unsigned shiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
2257
2258 // If palignr is shifting the pair of input vectors less than 9 bytes,
2259 // emit a shuffle instruction.
2260 if (shiftVal <= 8) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00002261 SmallVector<llvm::Constant*, 8> Indices;
Bill Wendling28cab382010-09-28 01:28:56 +00002262 for (unsigned i = 0; i != 8; ++i)
2263 Indices.push_back(llvm::ConstantInt::get(Int32Ty, shiftVal + i));
2264
Chris Lattnerfb018d12011-02-15 00:14:06 +00002265 Value* SV = llvm::ConstantVector::get(Indices);
Bill Wendling28cab382010-09-28 01:28:56 +00002266 return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr");
2267 }
2268
2269 // If palignr is shifting the pair of input vectors more than 8 but less
2270 // than 16 bytes, emit a logical right shift of the destination.
2271 if (shiftVal < 16) {
2272 // MMX has these as 1 x i64 vectors for some odd optimization reasons.
Chris Lattner2acc6e32011-07-18 04:24:23 +00002273 llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 1);
Bill Wendling28cab382010-09-28 01:28:56 +00002274
2275 Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast");
2276 Ops[1] = llvm::ConstantInt::get(VecTy, (shiftVal-8) * 8);
2277
2278 // create i32 constant
2279 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_mmx_psrl_q);
Frits van Bommele9c02652011-07-18 12:00:32 +00002280 return Builder.CreateCall(F, makeArrayRef(&Ops[0], 2), "palignr");
Bill Wendling28cab382010-09-28 01:28:56 +00002281 }
2282
Eli Friedman5c22ad22011-09-14 00:52:45 +00002283 // If palignr is shifting the pair of vectors more than 16 bytes, emit zero.
Bill Wendling28cab382010-09-28 01:28:56 +00002284 return llvm::Constant::getNullValue(ConvertType(E->getType()));
2285 }
Nate Begemanc3420ff2009-12-14 05:15:02 +00002286 case X86::BI__builtin_ia32_palignr128: {
Nate Begemance5818a2009-12-14 04:57:03 +00002287 unsigned shiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
2288
2289 // If palignr is shifting the pair of input vectors less than 17 bytes,
2290 // emit a shuffle instruction.
2291 if (shiftVal <= 16) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00002292 SmallVector<llvm::Constant*, 16> Indices;
Nate Begemance5818a2009-12-14 04:57:03 +00002293 for (unsigned i = 0; i != 16; ++i)
Chris Lattner77b89b82010-06-27 07:15:29 +00002294 Indices.push_back(llvm::ConstantInt::get(Int32Ty, shiftVal + i));
Nate Begemance5818a2009-12-14 04:57:03 +00002295
Chris Lattnerfb018d12011-02-15 00:14:06 +00002296 Value* SV = llvm::ConstantVector::get(Indices);
Nate Begemance5818a2009-12-14 04:57:03 +00002297 return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr");
2298 }
2299
2300 // If palignr is shifting the pair of input vectors more than 16 but less
2301 // than 32 bytes, emit a logical right shift of the destination.
2302 if (shiftVal < 32) {
Chris Lattner2acc6e32011-07-18 04:24:23 +00002303 llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 2);
Nate Begemance5818a2009-12-14 04:57:03 +00002304
2305 Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast");
Chris Lattner77b89b82010-06-27 07:15:29 +00002306 Ops[1] = llvm::ConstantInt::get(Int32Ty, (shiftVal-16) * 8);
Nate Begemance5818a2009-12-14 04:57:03 +00002307
2308 // create i32 constant
2309 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_psrl_dq);
Frits van Bommele9c02652011-07-18 12:00:32 +00002310 return Builder.CreateCall(F, makeArrayRef(&Ops[0], 2), "palignr");
Nate Begemance5818a2009-12-14 04:57:03 +00002311 }
2312
2313 // If palignr is shifting the pair of vectors more than 32 bytes, emit zero.
2314 return llvm::Constant::getNullValue(ConvertType(E->getType()));
Eric Christopher91b59272009-12-01 05:00:51 +00002315 }
Craig Topper9c2ffd82011-12-19 07:03:25 +00002316 case X86::BI__builtin_ia32_palignr256: {
2317 unsigned shiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
2318
2319 // If palignr is shifting the pair of input vectors less than 17 bytes,
2320 // emit a shuffle instruction.
2321 if (shiftVal <= 16) {
2322 SmallVector<llvm::Constant*, 32> Indices;
2323 // 256-bit palignr operates on 128-bit lanes so we need to handle that
2324 for (unsigned l = 0; l != 2; ++l) {
2325 unsigned LaneStart = l * 16;
2326 unsigned LaneEnd = (l+1) * 16;
2327 for (unsigned i = 0; i != 16; ++i) {
2328 unsigned Idx = shiftVal + i + LaneStart;
2329 if (Idx >= LaneEnd) Idx += 16; // end of lane, switch operand
2330 Indices.push_back(llvm::ConstantInt::get(Int32Ty, Idx));
2331 }
2332 }
2333
2334 Value* SV = llvm::ConstantVector::get(Indices);
2335 return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr");
2336 }
2337
2338 // If palignr is shifting the pair of input vectors more than 16 but less
2339 // than 32 bytes, emit a logical right shift of the destination.
2340 if (shiftVal < 32) {
2341 llvm::Type *VecTy = llvm::VectorType::get(Int64Ty, 4);
2342
2343 Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast");
2344 Ops[1] = llvm::ConstantInt::get(Int32Ty, (shiftVal-16) * 8);
2345
2346 // create i32 constant
2347 llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_avx2_psrl_dq);
2348 return Builder.CreateCall(F, makeArrayRef(&Ops[0], 2), "palignr");
2349 }
2350
2351 // If palignr is shifting the pair of vectors more than 32 bytes, emit zero.
2352 return llvm::Constant::getNullValue(ConvertType(E->getType()));
2353 }
Bill Wendlingb51bdda2011-05-04 02:40:38 +00002354 case X86::BI__builtin_ia32_movntps:
2355 case X86::BI__builtin_ia32_movntpd:
2356 case X86::BI__builtin_ia32_movntdq:
2357 case X86::BI__builtin_ia32_movnti: {
Bill Wendlingb107dd02011-05-04 20:28:12 +00002358 llvm::MDNode *Node = llvm::MDNode::get(getLLVMContext(),
2359 Builder.getInt32(1));
Bill Wendlingb51bdda2011-05-04 02:40:38 +00002360
2361 // Convert the type of the pointer to a pointer to the stored type.
2362 Value *BC = Builder.CreateBitCast(Ops[0],
2363 llvm::PointerType::getUnqual(Ops[1]->getType()),
2364 "cast");
2365 StoreInst *SI = Builder.CreateStore(Ops[1], BC);
2366 SI->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node);
2367 SI->setAlignment(16);
2368 return SI;
2369 }
Michael J. Spencer8b36a9e2011-04-15 15:07:13 +00002370 // 3DNow!
2371 case X86::BI__builtin_ia32_pavgusb:
2372 case X86::BI__builtin_ia32_pf2id:
2373 case X86::BI__builtin_ia32_pfacc:
2374 case X86::BI__builtin_ia32_pfadd:
2375 case X86::BI__builtin_ia32_pfcmpeq:
2376 case X86::BI__builtin_ia32_pfcmpge:
2377 case X86::BI__builtin_ia32_pfcmpgt:
2378 case X86::BI__builtin_ia32_pfmax:
2379 case X86::BI__builtin_ia32_pfmin:
2380 case X86::BI__builtin_ia32_pfmul:
2381 case X86::BI__builtin_ia32_pfrcp:
2382 case X86::BI__builtin_ia32_pfrcpit1:
2383 case X86::BI__builtin_ia32_pfrcpit2:
2384 case X86::BI__builtin_ia32_pfrsqrt:
2385 case X86::BI__builtin_ia32_pfrsqit1:
2386 case X86::BI__builtin_ia32_pfrsqrtit1:
2387 case X86::BI__builtin_ia32_pfsub:
2388 case X86::BI__builtin_ia32_pfsubr:
2389 case X86::BI__builtin_ia32_pi2fd:
2390 case X86::BI__builtin_ia32_pmulhrw:
2391 case X86::BI__builtin_ia32_pf2iw:
2392 case X86::BI__builtin_ia32_pfnacc:
2393 case X86::BI__builtin_ia32_pfpnacc:
2394 case X86::BI__builtin_ia32_pi2fw:
2395 case X86::BI__builtin_ia32_pswapdsf:
2396 case X86::BI__builtin_ia32_pswapdsi: {
2397 const char *name = 0;
2398 Intrinsic::ID ID = Intrinsic::not_intrinsic;
2399 switch(BuiltinID) {
2400 case X86::BI__builtin_ia32_pavgusb:
2401 name = "pavgusb";
2402 ID = Intrinsic::x86_3dnow_pavgusb;
2403 break;
2404 case X86::BI__builtin_ia32_pf2id:
2405 name = "pf2id";
2406 ID = Intrinsic::x86_3dnow_pf2id;
2407 break;
2408 case X86::BI__builtin_ia32_pfacc:
2409 name = "pfacc";
2410 ID = Intrinsic::x86_3dnow_pfacc;
2411 break;
2412 case X86::BI__builtin_ia32_pfadd:
2413 name = "pfadd";
2414 ID = Intrinsic::x86_3dnow_pfadd;
2415 break;
2416 case X86::BI__builtin_ia32_pfcmpeq:
2417 name = "pfcmpeq";
2418 ID = Intrinsic::x86_3dnow_pfcmpeq;
2419 break;
2420 case X86::BI__builtin_ia32_pfcmpge:
2421 name = "pfcmpge";
2422 ID = Intrinsic::x86_3dnow_pfcmpge;
2423 break;
2424 case X86::BI__builtin_ia32_pfcmpgt:
2425 name = "pfcmpgt";
2426 ID = Intrinsic::x86_3dnow_pfcmpgt;
2427 break;
2428 case X86::BI__builtin_ia32_pfmax:
2429 name = "pfmax";
2430 ID = Intrinsic::x86_3dnow_pfmax;
2431 break;
2432 case X86::BI__builtin_ia32_pfmin:
2433 name = "pfmin";
2434 ID = Intrinsic::x86_3dnow_pfmin;
2435 break;
2436 case X86::BI__builtin_ia32_pfmul:
2437 name = "pfmul";
2438 ID = Intrinsic::x86_3dnow_pfmul;
2439 break;
2440 case X86::BI__builtin_ia32_pfrcp:
2441 name = "pfrcp";
2442 ID = Intrinsic::x86_3dnow_pfrcp;
2443 break;
2444 case X86::BI__builtin_ia32_pfrcpit1:
2445 name = "pfrcpit1";
2446 ID = Intrinsic::x86_3dnow_pfrcpit1;
2447 break;
2448 case X86::BI__builtin_ia32_pfrcpit2:
2449 name = "pfrcpit2";
2450 ID = Intrinsic::x86_3dnow_pfrcpit2;
2451 break;
2452 case X86::BI__builtin_ia32_pfrsqrt:
2453 name = "pfrsqrt";
2454 ID = Intrinsic::x86_3dnow_pfrsqrt;
2455 break;
2456 case X86::BI__builtin_ia32_pfrsqit1:
2457 case X86::BI__builtin_ia32_pfrsqrtit1:
2458 name = "pfrsqit1";
2459 ID = Intrinsic::x86_3dnow_pfrsqit1;
2460 break;
2461 case X86::BI__builtin_ia32_pfsub:
2462 name = "pfsub";
2463 ID = Intrinsic::x86_3dnow_pfsub;
2464 break;
2465 case X86::BI__builtin_ia32_pfsubr:
2466 name = "pfsubr";
2467 ID = Intrinsic::x86_3dnow_pfsubr;
2468 break;
2469 case X86::BI__builtin_ia32_pi2fd:
2470 name = "pi2fd";
2471 ID = Intrinsic::x86_3dnow_pi2fd;
2472 break;
2473 case X86::BI__builtin_ia32_pmulhrw:
2474 name = "pmulhrw";
2475 ID = Intrinsic::x86_3dnow_pmulhrw;
2476 break;
2477 case X86::BI__builtin_ia32_pf2iw:
2478 name = "pf2iw";
2479 ID = Intrinsic::x86_3dnowa_pf2iw;
2480 break;
2481 case X86::BI__builtin_ia32_pfnacc:
2482 name = "pfnacc";
2483 ID = Intrinsic::x86_3dnowa_pfnacc;
2484 break;
2485 case X86::BI__builtin_ia32_pfpnacc:
2486 name = "pfpnacc";
2487 ID = Intrinsic::x86_3dnowa_pfpnacc;
2488 break;
2489 case X86::BI__builtin_ia32_pi2fw:
2490 name = "pi2fw";
2491 ID = Intrinsic::x86_3dnowa_pi2fw;
2492 break;
2493 case X86::BI__builtin_ia32_pswapdsf:
2494 case X86::BI__builtin_ia32_pswapdsi:
2495 name = "pswapd";
2496 ID = Intrinsic::x86_3dnowa_pswapd;
2497 break;
2498 }
2499 llvm::Function *F = CGM.getIntrinsic(ID);
Jay Foad4c7d9f12011-07-15 08:37:34 +00002500 return Builder.CreateCall(F, Ops, name);
Michael J. Spencer8b36a9e2011-04-15 15:07:13 +00002501 }
Anders Carlsson564f1de2007-12-09 23:17:02 +00002502 }
2503}
2504
Tony Linthicum96319392011-12-12 21:14:55 +00002505
2506Value *CodeGenFunction::EmitHexagonBuiltinExpr(unsigned BuiltinID,
2507 const CallExpr *E) {
2508 llvm::SmallVector<Value*, 4> Ops;
2509
2510 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++)
2511 Ops.push_back(EmitScalarExpr(E->getArg(i)));
2512
2513 Intrinsic::ID ID = Intrinsic::not_intrinsic;
2514
2515 switch (BuiltinID) {
2516 default: return 0;
2517
2518 case Hexagon::BI__builtin_HEXAGON_C2_cmpeq:
2519 ID = Intrinsic::hexagon_C2_cmpeq; break;
2520
2521 case Hexagon::BI__builtin_HEXAGON_C2_cmpgt:
2522 ID = Intrinsic::hexagon_C2_cmpgt; break;
2523
2524 case Hexagon::BI__builtin_HEXAGON_C2_cmpgtu:
2525 ID = Intrinsic::hexagon_C2_cmpgtu; break;
2526
2527 case Hexagon::BI__builtin_HEXAGON_C2_cmpeqp:
2528 ID = Intrinsic::hexagon_C2_cmpeqp; break;
2529
2530 case Hexagon::BI__builtin_HEXAGON_C2_cmpgtp:
2531 ID = Intrinsic::hexagon_C2_cmpgtp; break;
2532
2533 case Hexagon::BI__builtin_HEXAGON_C2_cmpgtup:
2534 ID = Intrinsic::hexagon_C2_cmpgtup; break;
2535
2536 case Hexagon::BI__builtin_HEXAGON_C2_bitsset:
2537 ID = Intrinsic::hexagon_C2_bitsset; break;
2538
2539 case Hexagon::BI__builtin_HEXAGON_C2_bitsclr:
2540 ID = Intrinsic::hexagon_C2_bitsclr; break;
2541
2542 case Hexagon::BI__builtin_HEXAGON_C2_cmpeqi:
2543 ID = Intrinsic::hexagon_C2_cmpeqi; break;
2544
2545 case Hexagon::BI__builtin_HEXAGON_C2_cmpgti:
2546 ID = Intrinsic::hexagon_C2_cmpgti; break;
2547
2548 case Hexagon::BI__builtin_HEXAGON_C2_cmpgtui:
2549 ID = Intrinsic::hexagon_C2_cmpgtui; break;
2550
2551 case Hexagon::BI__builtin_HEXAGON_C2_cmpgei:
2552 ID = Intrinsic::hexagon_C2_cmpgei; break;
2553
2554 case Hexagon::BI__builtin_HEXAGON_C2_cmpgeui:
2555 ID = Intrinsic::hexagon_C2_cmpgeui; break;
2556
2557 case Hexagon::BI__builtin_HEXAGON_C2_cmplt:
2558 ID = Intrinsic::hexagon_C2_cmplt; break;
2559
2560 case Hexagon::BI__builtin_HEXAGON_C2_cmpltu:
2561 ID = Intrinsic::hexagon_C2_cmpltu; break;
2562
2563 case Hexagon::BI__builtin_HEXAGON_C2_bitsclri:
2564 ID = Intrinsic::hexagon_C2_bitsclri; break;
2565
2566 case Hexagon::BI__builtin_HEXAGON_C2_and:
2567 ID = Intrinsic::hexagon_C2_and; break;
2568
2569 case Hexagon::BI__builtin_HEXAGON_C2_or:
2570 ID = Intrinsic::hexagon_C2_or; break;
2571
2572 case Hexagon::BI__builtin_HEXAGON_C2_xor:
2573 ID = Intrinsic::hexagon_C2_xor; break;
2574
2575 case Hexagon::BI__builtin_HEXAGON_C2_andn:
2576 ID = Intrinsic::hexagon_C2_andn; break;
2577
2578 case Hexagon::BI__builtin_HEXAGON_C2_not:
2579 ID = Intrinsic::hexagon_C2_not; break;
2580
2581 case Hexagon::BI__builtin_HEXAGON_C2_orn:
2582 ID = Intrinsic::hexagon_C2_orn; break;
2583
2584 case Hexagon::BI__builtin_HEXAGON_C2_pxfer_map:
2585 ID = Intrinsic::hexagon_C2_pxfer_map; break;
2586
2587 case Hexagon::BI__builtin_HEXAGON_C2_any8:
2588 ID = Intrinsic::hexagon_C2_any8; break;
2589
2590 case Hexagon::BI__builtin_HEXAGON_C2_all8:
2591 ID = Intrinsic::hexagon_C2_all8; break;
2592
2593 case Hexagon::BI__builtin_HEXAGON_C2_vitpack:
2594 ID = Intrinsic::hexagon_C2_vitpack; break;
2595
2596 case Hexagon::BI__builtin_HEXAGON_C2_mux:
2597 ID = Intrinsic::hexagon_C2_mux; break;
2598
2599 case Hexagon::BI__builtin_HEXAGON_C2_muxii:
2600 ID = Intrinsic::hexagon_C2_muxii; break;
2601
2602 case Hexagon::BI__builtin_HEXAGON_C2_muxir:
2603 ID = Intrinsic::hexagon_C2_muxir; break;
2604
2605 case Hexagon::BI__builtin_HEXAGON_C2_muxri:
2606 ID = Intrinsic::hexagon_C2_muxri; break;
2607
2608 case Hexagon::BI__builtin_HEXAGON_C2_vmux:
2609 ID = Intrinsic::hexagon_C2_vmux; break;
2610
2611 case Hexagon::BI__builtin_HEXAGON_C2_mask:
2612 ID = Intrinsic::hexagon_C2_mask; break;
2613
2614 case Hexagon::BI__builtin_HEXAGON_A2_vcmpbeq:
2615 ID = Intrinsic::hexagon_A2_vcmpbeq; break;
2616
2617 case Hexagon::BI__builtin_HEXAGON_A2_vcmpbgtu:
2618 ID = Intrinsic::hexagon_A2_vcmpbgtu; break;
2619
2620 case Hexagon::BI__builtin_HEXAGON_A2_vcmpheq:
2621 ID = Intrinsic::hexagon_A2_vcmpheq; break;
2622
2623 case Hexagon::BI__builtin_HEXAGON_A2_vcmphgt:
2624 ID = Intrinsic::hexagon_A2_vcmphgt; break;
2625
2626 case Hexagon::BI__builtin_HEXAGON_A2_vcmphgtu:
2627 ID = Intrinsic::hexagon_A2_vcmphgtu; break;
2628
2629 case Hexagon::BI__builtin_HEXAGON_A2_vcmpweq:
2630 ID = Intrinsic::hexagon_A2_vcmpweq; break;
2631
2632 case Hexagon::BI__builtin_HEXAGON_A2_vcmpwgt:
2633 ID = Intrinsic::hexagon_A2_vcmpwgt; break;
2634
2635 case Hexagon::BI__builtin_HEXAGON_A2_vcmpwgtu:
2636 ID = Intrinsic::hexagon_A2_vcmpwgtu; break;
2637
2638 case Hexagon::BI__builtin_HEXAGON_C2_tfrpr:
2639 ID = Intrinsic::hexagon_C2_tfrpr; break;
2640
2641 case Hexagon::BI__builtin_HEXAGON_C2_tfrrp:
2642 ID = Intrinsic::hexagon_C2_tfrrp; break;
2643
2644 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_hh_s0:
2645 ID = Intrinsic::hexagon_M2_mpy_acc_hh_s0; break;
2646
2647 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_hh_s1:
2648 ID = Intrinsic::hexagon_M2_mpy_acc_hh_s1; break;
2649
2650 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_hl_s0:
2651 ID = Intrinsic::hexagon_M2_mpy_acc_hl_s0; break;
2652
2653 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_hl_s1:
2654 ID = Intrinsic::hexagon_M2_mpy_acc_hl_s1; break;
2655
2656 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_lh_s0:
2657 ID = Intrinsic::hexagon_M2_mpy_acc_lh_s0; break;
2658
2659 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_lh_s1:
2660 ID = Intrinsic::hexagon_M2_mpy_acc_lh_s1; break;
2661
2662 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_ll_s0:
2663 ID = Intrinsic::hexagon_M2_mpy_acc_ll_s0; break;
2664
2665 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_ll_s1:
2666 ID = Intrinsic::hexagon_M2_mpy_acc_ll_s1; break;
2667
2668 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_hh_s0:
2669 ID = Intrinsic::hexagon_M2_mpy_nac_hh_s0; break;
2670
2671 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_hh_s1:
2672 ID = Intrinsic::hexagon_M2_mpy_nac_hh_s1; break;
2673
2674 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_hl_s0:
2675 ID = Intrinsic::hexagon_M2_mpy_nac_hl_s0; break;
2676
2677 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_hl_s1:
2678 ID = Intrinsic::hexagon_M2_mpy_nac_hl_s1; break;
2679
2680 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_lh_s0:
2681 ID = Intrinsic::hexagon_M2_mpy_nac_lh_s0; break;
2682
2683 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_lh_s1:
2684 ID = Intrinsic::hexagon_M2_mpy_nac_lh_s1; break;
2685
2686 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_ll_s0:
2687 ID = Intrinsic::hexagon_M2_mpy_nac_ll_s0; break;
2688
2689 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_ll_s1:
2690 ID = Intrinsic::hexagon_M2_mpy_nac_ll_s1; break;
2691
2692 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_hh_s0:
2693 ID = Intrinsic::hexagon_M2_mpy_acc_sat_hh_s0; break;
2694
2695 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_hh_s1:
2696 ID = Intrinsic::hexagon_M2_mpy_acc_sat_hh_s1; break;
2697
2698 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_hl_s0:
2699 ID = Intrinsic::hexagon_M2_mpy_acc_sat_hl_s0; break;
2700
2701 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_hl_s1:
2702 ID = Intrinsic::hexagon_M2_mpy_acc_sat_hl_s1; break;
2703
2704 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_lh_s0:
2705 ID = Intrinsic::hexagon_M2_mpy_acc_sat_lh_s0; break;
2706
2707 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_lh_s1:
2708 ID = Intrinsic::hexagon_M2_mpy_acc_sat_lh_s1; break;
2709
2710 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_ll_s0:
2711 ID = Intrinsic::hexagon_M2_mpy_acc_sat_ll_s0; break;
2712
2713 case Hexagon::BI__builtin_HEXAGON_M2_mpy_acc_sat_ll_s1:
2714 ID = Intrinsic::hexagon_M2_mpy_acc_sat_ll_s1; break;
2715
2716 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_hh_s0:
2717 ID = Intrinsic::hexagon_M2_mpy_nac_sat_hh_s0; break;
2718
2719 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_hh_s1:
2720 ID = Intrinsic::hexagon_M2_mpy_nac_sat_hh_s1; break;
2721
2722 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_hl_s0:
2723 ID = Intrinsic::hexagon_M2_mpy_nac_sat_hl_s0; break;
2724
2725 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_hl_s1:
2726 ID = Intrinsic::hexagon_M2_mpy_nac_sat_hl_s1; break;
2727
2728 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_lh_s0:
2729 ID = Intrinsic::hexagon_M2_mpy_nac_sat_lh_s0; break;
2730
2731 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_lh_s1:
2732 ID = Intrinsic::hexagon_M2_mpy_nac_sat_lh_s1; break;
2733
2734 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_ll_s0:
2735 ID = Intrinsic::hexagon_M2_mpy_nac_sat_ll_s0; break;
2736
2737 case Hexagon::BI__builtin_HEXAGON_M2_mpy_nac_sat_ll_s1:
2738 ID = Intrinsic::hexagon_M2_mpy_nac_sat_ll_s1; break;
2739
2740 case Hexagon::BI__builtin_HEXAGON_M2_mpy_hh_s0:
2741 ID = Intrinsic::hexagon_M2_mpy_hh_s0; break;
2742
2743 case Hexagon::BI__builtin_HEXAGON_M2_mpy_hh_s1:
2744 ID = Intrinsic::hexagon_M2_mpy_hh_s1; break;
2745
2746 case Hexagon::BI__builtin_HEXAGON_M2_mpy_hl_s0:
2747 ID = Intrinsic::hexagon_M2_mpy_hl_s0; break;
2748
2749 case Hexagon::BI__builtin_HEXAGON_M2_mpy_hl_s1:
2750 ID = Intrinsic::hexagon_M2_mpy_hl_s1; break;
2751
2752 case Hexagon::BI__builtin_HEXAGON_M2_mpy_lh_s0:
2753 ID = Intrinsic::hexagon_M2_mpy_lh_s0; break;
2754
2755 case Hexagon::BI__builtin_HEXAGON_M2_mpy_lh_s1:
2756 ID = Intrinsic::hexagon_M2_mpy_lh_s1; break;
2757
2758 case Hexagon::BI__builtin_HEXAGON_M2_mpy_ll_s0:
2759 ID = Intrinsic::hexagon_M2_mpy_ll_s0; break;
2760
2761 case Hexagon::BI__builtin_HEXAGON_M2_mpy_ll_s1:
2762 ID = Intrinsic::hexagon_M2_mpy_ll_s1; break;
2763
2764 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_hh_s0:
2765 ID = Intrinsic::hexagon_M2_mpy_sat_hh_s0; break;
2766
2767 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_hh_s1:
2768 ID = Intrinsic::hexagon_M2_mpy_sat_hh_s1; break;
2769
2770 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_hl_s0:
2771 ID = Intrinsic::hexagon_M2_mpy_sat_hl_s0; break;
2772
2773 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_hl_s1:
2774 ID = Intrinsic::hexagon_M2_mpy_sat_hl_s1; break;
2775
2776 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_lh_s0:
2777 ID = Intrinsic::hexagon_M2_mpy_sat_lh_s0; break;
2778
2779 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_lh_s1:
2780 ID = Intrinsic::hexagon_M2_mpy_sat_lh_s1; break;
2781
2782 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_ll_s0:
2783 ID = Intrinsic::hexagon_M2_mpy_sat_ll_s0; break;
2784
2785 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_ll_s1:
2786 ID = Intrinsic::hexagon_M2_mpy_sat_ll_s1; break;
2787
2788 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_hh_s0:
2789 ID = Intrinsic::hexagon_M2_mpy_rnd_hh_s0; break;
2790
2791 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_hh_s1:
2792 ID = Intrinsic::hexagon_M2_mpy_rnd_hh_s1; break;
2793
2794 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_hl_s0:
2795 ID = Intrinsic::hexagon_M2_mpy_rnd_hl_s0; break;
2796
2797 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_hl_s1:
2798 ID = Intrinsic::hexagon_M2_mpy_rnd_hl_s1; break;
2799
2800 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_lh_s0:
2801 ID = Intrinsic::hexagon_M2_mpy_rnd_lh_s0; break;
2802
2803 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_lh_s1:
2804 ID = Intrinsic::hexagon_M2_mpy_rnd_lh_s1; break;
2805
2806 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_ll_s0:
2807 ID = Intrinsic::hexagon_M2_mpy_rnd_ll_s0; break;
2808
2809 case Hexagon::BI__builtin_HEXAGON_M2_mpy_rnd_ll_s1:
2810 ID = Intrinsic::hexagon_M2_mpy_rnd_ll_s1; break;
2811
2812 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_hh_s0:
2813 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_hh_s0; break;
2814
2815 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_hh_s1:
2816 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_hh_s1; break;
2817
2818 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_hl_s0:
2819 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_hl_s0; break;
2820
2821 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_hl_s1:
2822 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_hl_s1; break;
2823
2824 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_lh_s0:
2825 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_lh_s0; break;
2826
2827 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_lh_s1:
2828 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_lh_s1; break;
2829
2830 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_ll_s0:
2831 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_ll_s0; break;
2832
2833 case Hexagon::BI__builtin_HEXAGON_M2_mpy_sat_rnd_ll_s1:
2834 ID = Intrinsic::hexagon_M2_mpy_sat_rnd_ll_s1; break;
2835
2836 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_hh_s0:
2837 ID = Intrinsic::hexagon_M2_mpyd_acc_hh_s0; break;
2838
2839 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_hh_s1:
2840 ID = Intrinsic::hexagon_M2_mpyd_acc_hh_s1; break;
2841
2842 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_hl_s0:
2843 ID = Intrinsic::hexagon_M2_mpyd_acc_hl_s0; break;
2844
2845 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_hl_s1:
2846 ID = Intrinsic::hexagon_M2_mpyd_acc_hl_s1; break;
2847
2848 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_lh_s0:
2849 ID = Intrinsic::hexagon_M2_mpyd_acc_lh_s0; break;
2850
2851 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_lh_s1:
2852 ID = Intrinsic::hexagon_M2_mpyd_acc_lh_s1; break;
2853
2854 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_ll_s0:
2855 ID = Intrinsic::hexagon_M2_mpyd_acc_ll_s0; break;
2856
2857 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_acc_ll_s1:
2858 ID = Intrinsic::hexagon_M2_mpyd_acc_ll_s1; break;
2859
2860 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_hh_s0:
2861 ID = Intrinsic::hexagon_M2_mpyd_nac_hh_s0; break;
2862
2863 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_hh_s1:
2864 ID = Intrinsic::hexagon_M2_mpyd_nac_hh_s1; break;
2865
2866 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_hl_s0:
2867 ID = Intrinsic::hexagon_M2_mpyd_nac_hl_s0; break;
2868
2869 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_hl_s1:
2870 ID = Intrinsic::hexagon_M2_mpyd_nac_hl_s1; break;
2871
2872 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_lh_s0:
2873 ID = Intrinsic::hexagon_M2_mpyd_nac_lh_s0; break;
2874
2875 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_lh_s1:
2876 ID = Intrinsic::hexagon_M2_mpyd_nac_lh_s1; break;
2877
2878 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_ll_s0:
2879 ID = Intrinsic::hexagon_M2_mpyd_nac_ll_s0; break;
2880
2881 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_nac_ll_s1:
2882 ID = Intrinsic::hexagon_M2_mpyd_nac_ll_s1; break;
2883
2884 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_hh_s0:
2885 ID = Intrinsic::hexagon_M2_mpyd_hh_s0; break;
2886
2887 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_hh_s1:
2888 ID = Intrinsic::hexagon_M2_mpyd_hh_s1; break;
2889
2890 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_hl_s0:
2891 ID = Intrinsic::hexagon_M2_mpyd_hl_s0; break;
2892
2893 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_hl_s1:
2894 ID = Intrinsic::hexagon_M2_mpyd_hl_s1; break;
2895
2896 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_lh_s0:
2897 ID = Intrinsic::hexagon_M2_mpyd_lh_s0; break;
2898
2899 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_lh_s1:
2900 ID = Intrinsic::hexagon_M2_mpyd_lh_s1; break;
2901
2902 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_ll_s0:
2903 ID = Intrinsic::hexagon_M2_mpyd_ll_s0; break;
2904
2905 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_ll_s1:
2906 ID = Intrinsic::hexagon_M2_mpyd_ll_s1; break;
2907
2908 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_hh_s0:
2909 ID = Intrinsic::hexagon_M2_mpyd_rnd_hh_s0; break;
2910
2911 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_hh_s1:
2912 ID = Intrinsic::hexagon_M2_mpyd_rnd_hh_s1; break;
2913
2914 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_hl_s0:
2915 ID = Intrinsic::hexagon_M2_mpyd_rnd_hl_s0; break;
2916
2917 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_hl_s1:
2918 ID = Intrinsic::hexagon_M2_mpyd_rnd_hl_s1; break;
2919
2920 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_lh_s0:
2921 ID = Intrinsic::hexagon_M2_mpyd_rnd_lh_s0; break;
2922
2923 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_lh_s1:
2924 ID = Intrinsic::hexagon_M2_mpyd_rnd_lh_s1; break;
2925
2926 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_ll_s0:
2927 ID = Intrinsic::hexagon_M2_mpyd_rnd_ll_s0; break;
2928
2929 case Hexagon::BI__builtin_HEXAGON_M2_mpyd_rnd_ll_s1:
2930 ID = Intrinsic::hexagon_M2_mpyd_rnd_ll_s1; break;
2931
2932 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_hh_s0:
2933 ID = Intrinsic::hexagon_M2_mpyu_acc_hh_s0; break;
2934
2935 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_hh_s1:
2936 ID = Intrinsic::hexagon_M2_mpyu_acc_hh_s1; break;
2937
2938 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_hl_s0:
2939 ID = Intrinsic::hexagon_M2_mpyu_acc_hl_s0; break;
2940
2941 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_hl_s1:
2942 ID = Intrinsic::hexagon_M2_mpyu_acc_hl_s1; break;
2943
2944 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_lh_s0:
2945 ID = Intrinsic::hexagon_M2_mpyu_acc_lh_s0; break;
2946
2947 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_lh_s1:
2948 ID = Intrinsic::hexagon_M2_mpyu_acc_lh_s1; break;
2949
2950 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_ll_s0:
2951 ID = Intrinsic::hexagon_M2_mpyu_acc_ll_s0; break;
2952
2953 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_acc_ll_s1:
2954 ID = Intrinsic::hexagon_M2_mpyu_acc_ll_s1; break;
2955
2956 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_hh_s0:
2957 ID = Intrinsic::hexagon_M2_mpyu_nac_hh_s0; break;
2958
2959 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_hh_s1:
2960 ID = Intrinsic::hexagon_M2_mpyu_nac_hh_s1; break;
2961
2962 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_hl_s0:
2963 ID = Intrinsic::hexagon_M2_mpyu_nac_hl_s0; break;
2964
2965 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_hl_s1:
2966 ID = Intrinsic::hexagon_M2_mpyu_nac_hl_s1; break;
2967
2968 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_lh_s0:
2969 ID = Intrinsic::hexagon_M2_mpyu_nac_lh_s0; break;
2970
2971 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_lh_s1:
2972 ID = Intrinsic::hexagon_M2_mpyu_nac_lh_s1; break;
2973
2974 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_ll_s0:
2975 ID = Intrinsic::hexagon_M2_mpyu_nac_ll_s0; break;
2976
2977 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_nac_ll_s1:
2978 ID = Intrinsic::hexagon_M2_mpyu_nac_ll_s1; break;
2979
2980 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_hh_s0:
2981 ID = Intrinsic::hexagon_M2_mpyu_hh_s0; break;
2982
2983 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_hh_s1:
2984 ID = Intrinsic::hexagon_M2_mpyu_hh_s1; break;
2985
2986 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_hl_s0:
2987 ID = Intrinsic::hexagon_M2_mpyu_hl_s0; break;
2988
2989 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_hl_s1:
2990 ID = Intrinsic::hexagon_M2_mpyu_hl_s1; break;
2991
2992 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_lh_s0:
2993 ID = Intrinsic::hexagon_M2_mpyu_lh_s0; break;
2994
2995 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_lh_s1:
2996 ID = Intrinsic::hexagon_M2_mpyu_lh_s1; break;
2997
2998 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_ll_s0:
2999 ID = Intrinsic::hexagon_M2_mpyu_ll_s0; break;
3000
3001 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_ll_s1:
3002 ID = Intrinsic::hexagon_M2_mpyu_ll_s1; break;
3003
3004 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_hh_s0:
3005 ID = Intrinsic::hexagon_M2_mpyud_acc_hh_s0; break;
3006
3007 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_hh_s1:
3008 ID = Intrinsic::hexagon_M2_mpyud_acc_hh_s1; break;
3009
3010 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_hl_s0:
3011 ID = Intrinsic::hexagon_M2_mpyud_acc_hl_s0; break;
3012
3013 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_hl_s1:
3014 ID = Intrinsic::hexagon_M2_mpyud_acc_hl_s1; break;
3015
3016 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_lh_s0:
3017 ID = Intrinsic::hexagon_M2_mpyud_acc_lh_s0; break;
3018
3019 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_lh_s1:
3020 ID = Intrinsic::hexagon_M2_mpyud_acc_lh_s1; break;
3021
3022 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_ll_s0:
3023 ID = Intrinsic::hexagon_M2_mpyud_acc_ll_s0; break;
3024
3025 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_acc_ll_s1:
3026 ID = Intrinsic::hexagon_M2_mpyud_acc_ll_s1; break;
3027
3028 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_hh_s0:
3029 ID = Intrinsic::hexagon_M2_mpyud_nac_hh_s0; break;
3030
3031 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_hh_s1:
3032 ID = Intrinsic::hexagon_M2_mpyud_nac_hh_s1; break;
3033
3034 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_hl_s0:
3035 ID = Intrinsic::hexagon_M2_mpyud_nac_hl_s0; break;
3036
3037 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_hl_s1:
3038 ID = Intrinsic::hexagon_M2_mpyud_nac_hl_s1; break;
3039
3040 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_lh_s0:
3041 ID = Intrinsic::hexagon_M2_mpyud_nac_lh_s0; break;
3042
3043 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_lh_s1:
3044 ID = Intrinsic::hexagon_M2_mpyud_nac_lh_s1; break;
3045
3046 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_ll_s0:
3047 ID = Intrinsic::hexagon_M2_mpyud_nac_ll_s0; break;
3048
3049 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_nac_ll_s1:
3050 ID = Intrinsic::hexagon_M2_mpyud_nac_ll_s1; break;
3051
3052 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_hh_s0:
3053 ID = Intrinsic::hexagon_M2_mpyud_hh_s0; break;
3054
3055 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_hh_s1:
3056 ID = Intrinsic::hexagon_M2_mpyud_hh_s1; break;
3057
3058 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_hl_s0:
3059 ID = Intrinsic::hexagon_M2_mpyud_hl_s0; break;
3060
3061 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_hl_s1:
3062 ID = Intrinsic::hexagon_M2_mpyud_hl_s1; break;
3063
3064 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_lh_s0:
3065 ID = Intrinsic::hexagon_M2_mpyud_lh_s0; break;
3066
3067 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_lh_s1:
3068 ID = Intrinsic::hexagon_M2_mpyud_lh_s1; break;
3069
3070 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_ll_s0:
3071 ID = Intrinsic::hexagon_M2_mpyud_ll_s0; break;
3072
3073 case Hexagon::BI__builtin_HEXAGON_M2_mpyud_ll_s1:
3074 ID = Intrinsic::hexagon_M2_mpyud_ll_s1; break;
3075
3076 case Hexagon::BI__builtin_HEXAGON_M2_mpysmi:
3077 ID = Intrinsic::hexagon_M2_mpysmi; break;
3078
3079 case Hexagon::BI__builtin_HEXAGON_M2_macsip:
3080 ID = Intrinsic::hexagon_M2_macsip; break;
3081
3082 case Hexagon::BI__builtin_HEXAGON_M2_macsin:
3083 ID = Intrinsic::hexagon_M2_macsin; break;
3084
3085 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyss_s0:
3086 ID = Intrinsic::hexagon_M2_dpmpyss_s0; break;
3087
3088 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyss_acc_s0:
3089 ID = Intrinsic::hexagon_M2_dpmpyss_acc_s0; break;
3090
3091 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyss_nac_s0:
3092 ID = Intrinsic::hexagon_M2_dpmpyss_nac_s0; break;
3093
3094 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyuu_s0:
3095 ID = Intrinsic::hexagon_M2_dpmpyuu_s0; break;
3096
3097 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyuu_acc_s0:
3098 ID = Intrinsic::hexagon_M2_dpmpyuu_acc_s0; break;
3099
3100 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyuu_nac_s0:
3101 ID = Intrinsic::hexagon_M2_dpmpyuu_nac_s0; break;
3102
3103 case Hexagon::BI__builtin_HEXAGON_M2_mpy_up:
3104 ID = Intrinsic::hexagon_M2_mpy_up; break;
3105
3106 case Hexagon::BI__builtin_HEXAGON_M2_mpyu_up:
3107 ID = Intrinsic::hexagon_M2_mpyu_up; break;
3108
3109 case Hexagon::BI__builtin_HEXAGON_M2_dpmpyss_rnd_s0:
3110 ID = Intrinsic::hexagon_M2_dpmpyss_rnd_s0; break;
3111
3112 case Hexagon::BI__builtin_HEXAGON_M2_mpyi:
3113 ID = Intrinsic::hexagon_M2_mpyi; break;
3114
3115 case Hexagon::BI__builtin_HEXAGON_M2_mpyui:
3116 ID = Intrinsic::hexagon_M2_mpyui; break;
3117
3118 case Hexagon::BI__builtin_HEXAGON_M2_maci:
3119 ID = Intrinsic::hexagon_M2_maci; break;
3120
3121 case Hexagon::BI__builtin_HEXAGON_M2_acci:
3122 ID = Intrinsic::hexagon_M2_acci; break;
3123
3124 case Hexagon::BI__builtin_HEXAGON_M2_accii:
3125 ID = Intrinsic::hexagon_M2_accii; break;
3126
3127 case Hexagon::BI__builtin_HEXAGON_M2_nacci:
3128 ID = Intrinsic::hexagon_M2_nacci; break;
3129
3130 case Hexagon::BI__builtin_HEXAGON_M2_naccii:
3131 ID = Intrinsic::hexagon_M2_naccii; break;
3132
3133 case Hexagon::BI__builtin_HEXAGON_M2_subacc:
3134 ID = Intrinsic::hexagon_M2_subacc; break;
3135
3136 case Hexagon::BI__builtin_HEXAGON_M2_vmpy2s_s0:
3137 ID = Intrinsic::hexagon_M2_vmpy2s_s0; break;
3138
3139 case Hexagon::BI__builtin_HEXAGON_M2_vmpy2s_s1:
3140 ID = Intrinsic::hexagon_M2_vmpy2s_s1; break;
3141
3142 case Hexagon::BI__builtin_HEXAGON_M2_vmac2s_s0:
3143 ID = Intrinsic::hexagon_M2_vmac2s_s0; break;
3144
3145 case Hexagon::BI__builtin_HEXAGON_M2_vmac2s_s1:
3146 ID = Intrinsic::hexagon_M2_vmac2s_s1; break;
3147
3148 case Hexagon::BI__builtin_HEXAGON_M2_vmpy2s_s0pack:
3149 ID = Intrinsic::hexagon_M2_vmpy2s_s0pack; break;
3150
3151 case Hexagon::BI__builtin_HEXAGON_M2_vmpy2s_s1pack:
3152 ID = Intrinsic::hexagon_M2_vmpy2s_s1pack; break;
3153
3154 case Hexagon::BI__builtin_HEXAGON_M2_vmac2:
3155 ID = Intrinsic::hexagon_M2_vmac2; break;
3156
3157 case Hexagon::BI__builtin_HEXAGON_M2_vmpy2es_s0:
3158 ID = Intrinsic::hexagon_M2_vmpy2es_s0; break;
3159
3160 case Hexagon::BI__builtin_HEXAGON_M2_vmpy2es_s1:
3161 ID = Intrinsic::hexagon_M2_vmpy2es_s1; break;
3162
3163 case Hexagon::BI__builtin_HEXAGON_M2_vmac2es_s0:
3164 ID = Intrinsic::hexagon_M2_vmac2es_s0; break;
3165
3166 case Hexagon::BI__builtin_HEXAGON_M2_vmac2es_s1:
3167 ID = Intrinsic::hexagon_M2_vmac2es_s1; break;
3168
3169 case Hexagon::BI__builtin_HEXAGON_M2_vmac2es:
3170 ID = Intrinsic::hexagon_M2_vmac2es; break;
3171
3172 case Hexagon::BI__builtin_HEXAGON_M2_vrmac_s0:
3173 ID = Intrinsic::hexagon_M2_vrmac_s0; break;
3174
3175 case Hexagon::BI__builtin_HEXAGON_M2_vrmpy_s0:
3176 ID = Intrinsic::hexagon_M2_vrmpy_s0; break;
3177
3178 case Hexagon::BI__builtin_HEXAGON_M2_vdmpyrs_s0:
3179 ID = Intrinsic::hexagon_M2_vdmpyrs_s0; break;
3180
3181 case Hexagon::BI__builtin_HEXAGON_M2_vdmpyrs_s1:
3182 ID = Intrinsic::hexagon_M2_vdmpyrs_s1; break;
3183
3184 case Hexagon::BI__builtin_HEXAGON_M2_vdmacs_s0:
3185 ID = Intrinsic::hexagon_M2_vdmacs_s0; break;
3186
3187 case Hexagon::BI__builtin_HEXAGON_M2_vdmacs_s1:
3188 ID = Intrinsic::hexagon_M2_vdmacs_s1; break;
3189
3190 case Hexagon::BI__builtin_HEXAGON_M2_vdmpys_s0:
3191 ID = Intrinsic::hexagon_M2_vdmpys_s0; break;
3192
3193 case Hexagon::BI__builtin_HEXAGON_M2_vdmpys_s1:
3194 ID = Intrinsic::hexagon_M2_vdmpys_s1; break;
3195
3196 case Hexagon::BI__builtin_HEXAGON_M2_cmpyrs_s0:
3197 ID = Intrinsic::hexagon_M2_cmpyrs_s0; break;
3198
3199 case Hexagon::BI__builtin_HEXAGON_M2_cmpyrs_s1:
3200 ID = Intrinsic::hexagon_M2_cmpyrs_s1; break;
3201
3202 case Hexagon::BI__builtin_HEXAGON_M2_cmpyrsc_s0:
3203 ID = Intrinsic::hexagon_M2_cmpyrsc_s0; break;
3204
3205 case Hexagon::BI__builtin_HEXAGON_M2_cmpyrsc_s1:
3206 ID = Intrinsic::hexagon_M2_cmpyrsc_s1; break;
3207
3208 case Hexagon::BI__builtin_HEXAGON_M2_cmacs_s0:
3209 ID = Intrinsic::hexagon_M2_cmacs_s0; break;
3210
3211 case Hexagon::BI__builtin_HEXAGON_M2_cmacs_s1:
3212 ID = Intrinsic::hexagon_M2_cmacs_s1; break;
3213
3214 case Hexagon::BI__builtin_HEXAGON_M2_cmacsc_s0:
3215 ID = Intrinsic::hexagon_M2_cmacsc_s0; break;
3216
3217 case Hexagon::BI__builtin_HEXAGON_M2_cmacsc_s1:
3218 ID = Intrinsic::hexagon_M2_cmacsc_s1; break;
3219
3220 case Hexagon::BI__builtin_HEXAGON_M2_cmpys_s0:
3221 ID = Intrinsic::hexagon_M2_cmpys_s0; break;
3222
3223 case Hexagon::BI__builtin_HEXAGON_M2_cmpys_s1:
3224 ID = Intrinsic::hexagon_M2_cmpys_s1; break;
3225
3226 case Hexagon::BI__builtin_HEXAGON_M2_cmpysc_s0:
3227 ID = Intrinsic::hexagon_M2_cmpysc_s0; break;
3228
3229 case Hexagon::BI__builtin_HEXAGON_M2_cmpysc_s1:
3230 ID = Intrinsic::hexagon_M2_cmpysc_s1; break;
3231
3232 case Hexagon::BI__builtin_HEXAGON_M2_cnacs_s0:
3233 ID = Intrinsic::hexagon_M2_cnacs_s0; break;
3234
3235 case Hexagon::BI__builtin_HEXAGON_M2_cnacs_s1:
3236 ID = Intrinsic::hexagon_M2_cnacs_s1; break;
3237
3238 case Hexagon::BI__builtin_HEXAGON_M2_cnacsc_s0:
3239 ID = Intrinsic::hexagon_M2_cnacsc_s0; break;
3240
3241 case Hexagon::BI__builtin_HEXAGON_M2_cnacsc_s1:
3242 ID = Intrinsic::hexagon_M2_cnacsc_s1; break;
3243
3244 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpys_s1:
3245 ID = Intrinsic::hexagon_M2_vrcmpys_s1; break;
3246
3247 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpys_acc_s1:
3248 ID = Intrinsic::hexagon_M2_vrcmpys_acc_s1; break;
3249
3250 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpys_s1rp:
3251 ID = Intrinsic::hexagon_M2_vrcmpys_s1rp; break;
3252
3253 case Hexagon::BI__builtin_HEXAGON_M2_mmacls_s0:
3254 ID = Intrinsic::hexagon_M2_mmacls_s0; break;
3255
3256 case Hexagon::BI__builtin_HEXAGON_M2_mmacls_s1:
3257 ID = Intrinsic::hexagon_M2_mmacls_s1; break;
3258
3259 case Hexagon::BI__builtin_HEXAGON_M2_mmachs_s0:
3260 ID = Intrinsic::hexagon_M2_mmachs_s0; break;
3261
3262 case Hexagon::BI__builtin_HEXAGON_M2_mmachs_s1:
3263 ID = Intrinsic::hexagon_M2_mmachs_s1; break;
3264
3265 case Hexagon::BI__builtin_HEXAGON_M2_mmpyl_s0:
3266 ID = Intrinsic::hexagon_M2_mmpyl_s0; break;
3267
3268 case Hexagon::BI__builtin_HEXAGON_M2_mmpyl_s1:
3269 ID = Intrinsic::hexagon_M2_mmpyl_s1; break;
3270
3271 case Hexagon::BI__builtin_HEXAGON_M2_mmpyh_s0:
3272 ID = Intrinsic::hexagon_M2_mmpyh_s0; break;
3273
3274 case Hexagon::BI__builtin_HEXAGON_M2_mmpyh_s1:
3275 ID = Intrinsic::hexagon_M2_mmpyh_s1; break;
3276
3277 case Hexagon::BI__builtin_HEXAGON_M2_mmacls_rs0:
3278 ID = Intrinsic::hexagon_M2_mmacls_rs0; break;
3279
3280 case Hexagon::BI__builtin_HEXAGON_M2_mmacls_rs1:
3281 ID = Intrinsic::hexagon_M2_mmacls_rs1; break;
3282
3283 case Hexagon::BI__builtin_HEXAGON_M2_mmachs_rs0:
3284 ID = Intrinsic::hexagon_M2_mmachs_rs0; break;
3285
3286 case Hexagon::BI__builtin_HEXAGON_M2_mmachs_rs1:
3287 ID = Intrinsic::hexagon_M2_mmachs_rs1; break;
3288
3289 case Hexagon::BI__builtin_HEXAGON_M2_mmpyl_rs0:
3290 ID = Intrinsic::hexagon_M2_mmpyl_rs0; break;
3291
3292 case Hexagon::BI__builtin_HEXAGON_M2_mmpyl_rs1:
3293 ID = Intrinsic::hexagon_M2_mmpyl_rs1; break;
3294
3295 case Hexagon::BI__builtin_HEXAGON_M2_mmpyh_rs0:
3296 ID = Intrinsic::hexagon_M2_mmpyh_rs0; break;
3297
3298 case Hexagon::BI__builtin_HEXAGON_M2_mmpyh_rs1:
3299 ID = Intrinsic::hexagon_M2_mmpyh_rs1; break;
3300
3301 case Hexagon::BI__builtin_HEXAGON_M2_hmmpyl_rs1:
3302 ID = Intrinsic::hexagon_M2_hmmpyl_rs1; break;
3303
3304 case Hexagon::BI__builtin_HEXAGON_M2_hmmpyh_rs1:
3305 ID = Intrinsic::hexagon_M2_hmmpyh_rs1; break;
3306
3307 case Hexagon::BI__builtin_HEXAGON_M2_mmaculs_s0:
3308 ID = Intrinsic::hexagon_M2_mmaculs_s0; break;
3309
3310 case Hexagon::BI__builtin_HEXAGON_M2_mmaculs_s1:
3311 ID = Intrinsic::hexagon_M2_mmaculs_s1; break;
3312
3313 case Hexagon::BI__builtin_HEXAGON_M2_mmacuhs_s0:
3314 ID = Intrinsic::hexagon_M2_mmacuhs_s0; break;
3315
3316 case Hexagon::BI__builtin_HEXAGON_M2_mmacuhs_s1:
3317 ID = Intrinsic::hexagon_M2_mmacuhs_s1; break;
3318
3319 case Hexagon::BI__builtin_HEXAGON_M2_mmpyul_s0:
3320 ID = Intrinsic::hexagon_M2_mmpyul_s0; break;
3321
3322 case Hexagon::BI__builtin_HEXAGON_M2_mmpyul_s1:
3323 ID = Intrinsic::hexagon_M2_mmpyul_s1; break;
3324
3325 case Hexagon::BI__builtin_HEXAGON_M2_mmpyuh_s0:
3326 ID = Intrinsic::hexagon_M2_mmpyuh_s0; break;
3327
3328 case Hexagon::BI__builtin_HEXAGON_M2_mmpyuh_s1:
3329 ID = Intrinsic::hexagon_M2_mmpyuh_s1; break;
3330
3331 case Hexagon::BI__builtin_HEXAGON_M2_mmaculs_rs0:
3332 ID = Intrinsic::hexagon_M2_mmaculs_rs0; break;
3333
3334 case Hexagon::BI__builtin_HEXAGON_M2_mmaculs_rs1:
3335 ID = Intrinsic::hexagon_M2_mmaculs_rs1; break;
3336
3337 case Hexagon::BI__builtin_HEXAGON_M2_mmacuhs_rs0:
3338 ID = Intrinsic::hexagon_M2_mmacuhs_rs0; break;
3339
3340 case Hexagon::BI__builtin_HEXAGON_M2_mmacuhs_rs1:
3341 ID = Intrinsic::hexagon_M2_mmacuhs_rs1; break;
3342
3343 case Hexagon::BI__builtin_HEXAGON_M2_mmpyul_rs0:
3344 ID = Intrinsic::hexagon_M2_mmpyul_rs0; break;
3345
3346 case Hexagon::BI__builtin_HEXAGON_M2_mmpyul_rs1:
3347 ID = Intrinsic::hexagon_M2_mmpyul_rs1; break;
3348
3349 case Hexagon::BI__builtin_HEXAGON_M2_mmpyuh_rs0:
3350 ID = Intrinsic::hexagon_M2_mmpyuh_rs0; break;
3351
3352 case Hexagon::BI__builtin_HEXAGON_M2_mmpyuh_rs1:
3353 ID = Intrinsic::hexagon_M2_mmpyuh_rs1; break;
3354
3355 case Hexagon::BI__builtin_HEXAGON_M2_vrcmaci_s0:
3356 ID = Intrinsic::hexagon_M2_vrcmaci_s0; break;
3357
3358 case Hexagon::BI__builtin_HEXAGON_M2_vrcmacr_s0:
3359 ID = Intrinsic::hexagon_M2_vrcmacr_s0; break;
3360
3361 case Hexagon::BI__builtin_HEXAGON_M2_vrcmaci_s0c:
3362 ID = Intrinsic::hexagon_M2_vrcmaci_s0c; break;
3363
3364 case Hexagon::BI__builtin_HEXAGON_M2_vrcmacr_s0c:
3365 ID = Intrinsic::hexagon_M2_vrcmacr_s0c; break;
3366
3367 case Hexagon::BI__builtin_HEXAGON_M2_cmaci_s0:
3368 ID = Intrinsic::hexagon_M2_cmaci_s0; break;
3369
3370 case Hexagon::BI__builtin_HEXAGON_M2_cmacr_s0:
3371 ID = Intrinsic::hexagon_M2_cmacr_s0; break;
3372
3373 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpyi_s0:
3374 ID = Intrinsic::hexagon_M2_vrcmpyi_s0; break;
3375
3376 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpyr_s0:
3377 ID = Intrinsic::hexagon_M2_vrcmpyr_s0; break;
3378
3379 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpyi_s0c:
3380 ID = Intrinsic::hexagon_M2_vrcmpyi_s0c; break;
3381
3382 case Hexagon::BI__builtin_HEXAGON_M2_vrcmpyr_s0c:
3383 ID = Intrinsic::hexagon_M2_vrcmpyr_s0c; break;
3384
3385 case Hexagon::BI__builtin_HEXAGON_M2_cmpyi_s0:
3386 ID = Intrinsic::hexagon_M2_cmpyi_s0; break;
3387
3388 case Hexagon::BI__builtin_HEXAGON_M2_cmpyr_s0:
3389 ID = Intrinsic::hexagon_M2_cmpyr_s0; break;
3390
3391 case Hexagon::BI__builtin_HEXAGON_M2_vcmpy_s0_sat_i:
3392 ID = Intrinsic::hexagon_M2_vcmpy_s0_sat_i; break;
3393
3394 case Hexagon::BI__builtin_HEXAGON_M2_vcmpy_s0_sat_r:
3395 ID = Intrinsic::hexagon_M2_vcmpy_s0_sat_r; break;
3396
3397 case Hexagon::BI__builtin_HEXAGON_M2_vcmpy_s1_sat_i:
3398 ID = Intrinsic::hexagon_M2_vcmpy_s1_sat_i; break;
3399
3400 case Hexagon::BI__builtin_HEXAGON_M2_vcmpy_s1_sat_r:
3401 ID = Intrinsic::hexagon_M2_vcmpy_s1_sat_r; break;
3402
3403 case Hexagon::BI__builtin_HEXAGON_M2_vcmac_s0_sat_i:
3404 ID = Intrinsic::hexagon_M2_vcmac_s0_sat_i; break;
3405
3406 case Hexagon::BI__builtin_HEXAGON_M2_vcmac_s0_sat_r:
3407 ID = Intrinsic::hexagon_M2_vcmac_s0_sat_r; break;
3408
3409 case Hexagon::BI__builtin_HEXAGON_S2_vcrotate:
3410 ID = Intrinsic::hexagon_S2_vcrotate; break;
3411
3412 case Hexagon::BI__builtin_HEXAGON_A2_add:
3413 ID = Intrinsic::hexagon_A2_add; break;
3414
3415 case Hexagon::BI__builtin_HEXAGON_A2_sub:
3416 ID = Intrinsic::hexagon_A2_sub; break;
3417
3418 case Hexagon::BI__builtin_HEXAGON_A2_addsat:
3419 ID = Intrinsic::hexagon_A2_addsat; break;
3420
3421 case Hexagon::BI__builtin_HEXAGON_A2_subsat:
3422 ID = Intrinsic::hexagon_A2_subsat; break;
3423
3424 case Hexagon::BI__builtin_HEXAGON_A2_addi:
3425 ID = Intrinsic::hexagon_A2_addi; break;
3426
3427 case Hexagon::BI__builtin_HEXAGON_A2_addh_l16_ll:
3428 ID = Intrinsic::hexagon_A2_addh_l16_ll; break;
3429
3430 case Hexagon::BI__builtin_HEXAGON_A2_addh_l16_hl:
3431 ID = Intrinsic::hexagon_A2_addh_l16_hl; break;
3432
3433 case Hexagon::BI__builtin_HEXAGON_A2_addh_l16_sat_ll:
3434 ID = Intrinsic::hexagon_A2_addh_l16_sat_ll; break;
3435
3436 case Hexagon::BI__builtin_HEXAGON_A2_addh_l16_sat_hl:
3437 ID = Intrinsic::hexagon_A2_addh_l16_sat_hl; break;
3438
3439 case Hexagon::BI__builtin_HEXAGON_A2_subh_l16_ll:
3440 ID = Intrinsic::hexagon_A2_subh_l16_ll; break;
3441
3442 case Hexagon::BI__builtin_HEXAGON_A2_subh_l16_hl:
3443 ID = Intrinsic::hexagon_A2_subh_l16_hl; break;
3444
3445 case Hexagon::BI__builtin_HEXAGON_A2_subh_l16_sat_ll:
3446 ID = Intrinsic::hexagon_A2_subh_l16_sat_ll; break;
3447
3448 case Hexagon::BI__builtin_HEXAGON_A2_subh_l16_sat_hl:
3449 ID = Intrinsic::hexagon_A2_subh_l16_sat_hl; break;
3450
3451 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_ll:
3452 ID = Intrinsic::hexagon_A2_addh_h16_ll; break;
3453
3454 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_lh:
3455 ID = Intrinsic::hexagon_A2_addh_h16_lh; break;
3456
3457 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_hl:
3458 ID = Intrinsic::hexagon_A2_addh_h16_hl; break;
3459
3460 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_hh:
3461 ID = Intrinsic::hexagon_A2_addh_h16_hh; break;
3462
3463 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_sat_ll:
3464 ID = Intrinsic::hexagon_A2_addh_h16_sat_ll; break;
3465
3466 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_sat_lh:
3467 ID = Intrinsic::hexagon_A2_addh_h16_sat_lh; break;
3468
3469 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_sat_hl:
3470 ID = Intrinsic::hexagon_A2_addh_h16_sat_hl; break;
3471
3472 case Hexagon::BI__builtin_HEXAGON_A2_addh_h16_sat_hh:
3473 ID = Intrinsic::hexagon_A2_addh_h16_sat_hh; break;
3474
3475 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_ll:
3476 ID = Intrinsic::hexagon_A2_subh_h16_ll; break;
3477
3478 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_lh:
3479 ID = Intrinsic::hexagon_A2_subh_h16_lh; break;
3480
3481 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_hl:
3482 ID = Intrinsic::hexagon_A2_subh_h16_hl; break;
3483
3484 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_hh:
3485 ID = Intrinsic::hexagon_A2_subh_h16_hh; break;
3486
3487 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_sat_ll:
3488 ID = Intrinsic::hexagon_A2_subh_h16_sat_ll; break;
3489
3490 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_sat_lh:
3491 ID = Intrinsic::hexagon_A2_subh_h16_sat_lh; break;
3492
3493 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_sat_hl:
3494 ID = Intrinsic::hexagon_A2_subh_h16_sat_hl; break;
3495
3496 case Hexagon::BI__builtin_HEXAGON_A2_subh_h16_sat_hh:
3497 ID = Intrinsic::hexagon_A2_subh_h16_sat_hh; break;
3498
3499 case Hexagon::BI__builtin_HEXAGON_A2_aslh:
3500 ID = Intrinsic::hexagon_A2_aslh; break;
3501
3502 case Hexagon::BI__builtin_HEXAGON_A2_asrh:
3503 ID = Intrinsic::hexagon_A2_asrh; break;
3504
3505 case Hexagon::BI__builtin_HEXAGON_A2_addp:
3506 ID = Intrinsic::hexagon_A2_addp; break;
3507
3508 case Hexagon::BI__builtin_HEXAGON_A2_addpsat:
3509 ID = Intrinsic::hexagon_A2_addpsat; break;
3510
3511 case Hexagon::BI__builtin_HEXAGON_A2_addsp:
3512 ID = Intrinsic::hexagon_A2_addsp; break;
3513
3514 case Hexagon::BI__builtin_HEXAGON_A2_subp:
3515 ID = Intrinsic::hexagon_A2_subp; break;
3516
3517 case Hexagon::BI__builtin_HEXAGON_A2_neg:
3518 ID = Intrinsic::hexagon_A2_neg; break;
3519
3520 case Hexagon::BI__builtin_HEXAGON_A2_negsat:
3521 ID = Intrinsic::hexagon_A2_negsat; break;
3522
3523 case Hexagon::BI__builtin_HEXAGON_A2_abs:
3524 ID = Intrinsic::hexagon_A2_abs; break;
3525
3526 case Hexagon::BI__builtin_HEXAGON_A2_abssat:
3527 ID = Intrinsic::hexagon_A2_abssat; break;
3528
3529 case Hexagon::BI__builtin_HEXAGON_A2_vconj:
3530 ID = Intrinsic::hexagon_A2_vconj; break;
3531
3532 case Hexagon::BI__builtin_HEXAGON_A2_negp:
3533 ID = Intrinsic::hexagon_A2_negp; break;
3534
3535 case Hexagon::BI__builtin_HEXAGON_A2_absp:
3536 ID = Intrinsic::hexagon_A2_absp; break;
3537
3538 case Hexagon::BI__builtin_HEXAGON_A2_max:
3539 ID = Intrinsic::hexagon_A2_max; break;
3540
3541 case Hexagon::BI__builtin_HEXAGON_A2_maxu:
3542 ID = Intrinsic::hexagon_A2_maxu; break;
3543
3544 case Hexagon::BI__builtin_HEXAGON_A2_min:
3545 ID = Intrinsic::hexagon_A2_min; break;
3546
3547 case Hexagon::BI__builtin_HEXAGON_A2_minu:
3548 ID = Intrinsic::hexagon_A2_minu; break;
3549
3550 case Hexagon::BI__builtin_HEXAGON_A2_maxp:
3551 ID = Intrinsic::hexagon_A2_maxp; break;
3552
3553 case Hexagon::BI__builtin_HEXAGON_A2_maxup:
3554 ID = Intrinsic::hexagon_A2_maxup; break;
3555
3556 case Hexagon::BI__builtin_HEXAGON_A2_minp:
3557 ID = Intrinsic::hexagon_A2_minp; break;
3558
3559 case Hexagon::BI__builtin_HEXAGON_A2_minup:
3560 ID = Intrinsic::hexagon_A2_minup; break;
3561
3562 case Hexagon::BI__builtin_HEXAGON_A2_tfr:
3563 ID = Intrinsic::hexagon_A2_tfr; break;
3564
3565 case Hexagon::BI__builtin_HEXAGON_A2_tfrsi:
3566 ID = Intrinsic::hexagon_A2_tfrsi; break;
3567
3568 case Hexagon::BI__builtin_HEXAGON_A2_tfrp:
3569 ID = Intrinsic::hexagon_A2_tfrp; break;
3570
3571 case Hexagon::BI__builtin_HEXAGON_A2_tfrpi:
3572 ID = Intrinsic::hexagon_A2_tfrpi; break;
3573
3574 case Hexagon::BI__builtin_HEXAGON_A2_zxtb:
3575 ID = Intrinsic::hexagon_A2_zxtb; break;
3576
3577 case Hexagon::BI__builtin_HEXAGON_A2_sxtb:
3578 ID = Intrinsic::hexagon_A2_sxtb; break;
3579
3580 case Hexagon::BI__builtin_HEXAGON_A2_zxth:
3581 ID = Intrinsic::hexagon_A2_zxth; break;
3582
3583 case Hexagon::BI__builtin_HEXAGON_A2_sxth:
3584 ID = Intrinsic::hexagon_A2_sxth; break;
3585
3586 case Hexagon::BI__builtin_HEXAGON_A2_combinew:
3587 ID = Intrinsic::hexagon_A2_combinew; break;
3588
3589 case Hexagon::BI__builtin_HEXAGON_A2_combineii:
3590 ID = Intrinsic::hexagon_A2_combineii; break;
3591
3592 case Hexagon::BI__builtin_HEXAGON_A2_combine_hh:
3593 ID = Intrinsic::hexagon_A2_combine_hh; break;
3594
3595 case Hexagon::BI__builtin_HEXAGON_A2_combine_hl:
3596 ID = Intrinsic::hexagon_A2_combine_hl; break;
3597
3598 case Hexagon::BI__builtin_HEXAGON_A2_combine_lh:
3599 ID = Intrinsic::hexagon_A2_combine_lh; break;
3600
3601 case Hexagon::BI__builtin_HEXAGON_A2_combine_ll:
3602 ID = Intrinsic::hexagon_A2_combine_ll; break;
3603
3604 case Hexagon::BI__builtin_HEXAGON_A2_tfril:
3605 ID = Intrinsic::hexagon_A2_tfril; break;
3606
3607 case Hexagon::BI__builtin_HEXAGON_A2_tfrih:
3608 ID = Intrinsic::hexagon_A2_tfrih; break;
3609
3610 case Hexagon::BI__builtin_HEXAGON_A2_and:
3611 ID = Intrinsic::hexagon_A2_and; break;
3612
3613 case Hexagon::BI__builtin_HEXAGON_A2_or:
3614 ID = Intrinsic::hexagon_A2_or; break;
3615
3616 case Hexagon::BI__builtin_HEXAGON_A2_xor:
3617 ID = Intrinsic::hexagon_A2_xor; break;
3618
3619 case Hexagon::BI__builtin_HEXAGON_A2_not:
3620 ID = Intrinsic::hexagon_A2_not; break;
3621
3622 case Hexagon::BI__builtin_HEXAGON_M2_xor_xacc:
3623 ID = Intrinsic::hexagon_M2_xor_xacc; break;
3624
3625 case Hexagon::BI__builtin_HEXAGON_A2_subri:
3626 ID = Intrinsic::hexagon_A2_subri; break;
3627
3628 case Hexagon::BI__builtin_HEXAGON_A2_andir:
3629 ID = Intrinsic::hexagon_A2_andir; break;
3630
3631 case Hexagon::BI__builtin_HEXAGON_A2_orir:
3632 ID = Intrinsic::hexagon_A2_orir; break;
3633
3634 case Hexagon::BI__builtin_HEXAGON_A2_andp:
3635 ID = Intrinsic::hexagon_A2_andp; break;
3636
3637 case Hexagon::BI__builtin_HEXAGON_A2_orp:
3638 ID = Intrinsic::hexagon_A2_orp; break;
3639
3640 case Hexagon::BI__builtin_HEXAGON_A2_xorp:
3641 ID = Intrinsic::hexagon_A2_xorp; break;
3642
3643 case Hexagon::BI__builtin_HEXAGON_A2_notp:
3644 ID = Intrinsic::hexagon_A2_notp; break;
3645
3646 case Hexagon::BI__builtin_HEXAGON_A2_sxtw:
3647 ID = Intrinsic::hexagon_A2_sxtw; break;
3648
3649 case Hexagon::BI__builtin_HEXAGON_A2_sat:
3650 ID = Intrinsic::hexagon_A2_sat; break;
3651
3652 case Hexagon::BI__builtin_HEXAGON_A2_sath:
3653 ID = Intrinsic::hexagon_A2_sath; break;
3654
3655 case Hexagon::BI__builtin_HEXAGON_A2_satuh:
3656 ID = Intrinsic::hexagon_A2_satuh; break;
3657
3658 case Hexagon::BI__builtin_HEXAGON_A2_satub:
3659 ID = Intrinsic::hexagon_A2_satub; break;
3660
3661 case Hexagon::BI__builtin_HEXAGON_A2_satb:
3662 ID = Intrinsic::hexagon_A2_satb; break;
3663
3664 case Hexagon::BI__builtin_HEXAGON_A2_vaddub:
3665 ID = Intrinsic::hexagon_A2_vaddub; break;
3666
3667 case Hexagon::BI__builtin_HEXAGON_A2_vaddubs:
3668 ID = Intrinsic::hexagon_A2_vaddubs; break;
3669
3670 case Hexagon::BI__builtin_HEXAGON_A2_vaddh:
3671 ID = Intrinsic::hexagon_A2_vaddh; break;
3672
3673 case Hexagon::BI__builtin_HEXAGON_A2_vaddhs:
3674 ID = Intrinsic::hexagon_A2_vaddhs; break;
3675
3676 case Hexagon::BI__builtin_HEXAGON_A2_vadduhs:
3677 ID = Intrinsic::hexagon_A2_vadduhs; break;
3678
3679 case Hexagon::BI__builtin_HEXAGON_A2_vaddw:
3680 ID = Intrinsic::hexagon_A2_vaddw; break;
3681
3682 case Hexagon::BI__builtin_HEXAGON_A2_vaddws:
3683 ID = Intrinsic::hexagon_A2_vaddws; break;
3684
3685 case Hexagon::BI__builtin_HEXAGON_A2_svavgh:
3686 ID = Intrinsic::hexagon_A2_svavgh; break;
3687
3688 case Hexagon::BI__builtin_HEXAGON_A2_svavghs:
3689 ID = Intrinsic::hexagon_A2_svavghs; break;
3690
3691 case Hexagon::BI__builtin_HEXAGON_A2_svnavgh:
3692 ID = Intrinsic::hexagon_A2_svnavgh; break;
3693
3694 case Hexagon::BI__builtin_HEXAGON_A2_svaddh:
3695 ID = Intrinsic::hexagon_A2_svaddh; break;
3696
3697 case Hexagon::BI__builtin_HEXAGON_A2_svaddhs:
3698 ID = Intrinsic::hexagon_A2_svaddhs; break;
3699
3700 case Hexagon::BI__builtin_HEXAGON_A2_svadduhs:
3701 ID = Intrinsic::hexagon_A2_svadduhs; break;
3702
3703 case Hexagon::BI__builtin_HEXAGON_A2_svsubh:
3704 ID = Intrinsic::hexagon_A2_svsubh; break;
3705
3706 case Hexagon::BI__builtin_HEXAGON_A2_svsubhs:
3707 ID = Intrinsic::hexagon_A2_svsubhs; break;
3708
3709 case Hexagon::BI__builtin_HEXAGON_A2_svsubuhs:
3710 ID = Intrinsic::hexagon_A2_svsubuhs; break;
3711
3712 case Hexagon::BI__builtin_HEXAGON_A2_vraddub:
3713 ID = Intrinsic::hexagon_A2_vraddub; break;
3714
3715 case Hexagon::BI__builtin_HEXAGON_A2_vraddub_acc:
3716 ID = Intrinsic::hexagon_A2_vraddub_acc; break;
3717
3718 case Hexagon::BI__builtin_HEXAGON_M2_vradduh:
3719 ID = Intrinsic::hexagon_M2_vradduh; break;
3720
3721 case Hexagon::BI__builtin_HEXAGON_A2_vsubub:
3722 ID = Intrinsic::hexagon_A2_vsubub; break;
3723
3724 case Hexagon::BI__builtin_HEXAGON_A2_vsububs:
3725 ID = Intrinsic::hexagon_A2_vsububs; break;
3726
3727 case Hexagon::BI__builtin_HEXAGON_A2_vsubh:
3728 ID = Intrinsic::hexagon_A2_vsubh; break;
3729
3730 case Hexagon::BI__builtin_HEXAGON_A2_vsubhs:
3731 ID = Intrinsic::hexagon_A2_vsubhs; break;
3732
3733 case Hexagon::BI__builtin_HEXAGON_A2_vsubuhs:
3734 ID = Intrinsic::hexagon_A2_vsubuhs; break;
3735
3736 case Hexagon::BI__builtin_HEXAGON_A2_vsubw:
3737 ID = Intrinsic::hexagon_A2_vsubw; break;
3738
3739 case Hexagon::BI__builtin_HEXAGON_A2_vsubws:
3740 ID = Intrinsic::hexagon_A2_vsubws; break;
3741
3742 case Hexagon::BI__builtin_HEXAGON_A2_vabsh:
3743 ID = Intrinsic::hexagon_A2_vabsh; break;
3744
3745 case Hexagon::BI__builtin_HEXAGON_A2_vabshsat:
3746 ID = Intrinsic::hexagon_A2_vabshsat; break;
3747
3748 case Hexagon::BI__builtin_HEXAGON_A2_vabsw:
3749 ID = Intrinsic::hexagon_A2_vabsw; break;
3750
3751 case Hexagon::BI__builtin_HEXAGON_A2_vabswsat:
3752 ID = Intrinsic::hexagon_A2_vabswsat; break;
3753
3754 case Hexagon::BI__builtin_HEXAGON_M2_vabsdiffw:
3755 ID = Intrinsic::hexagon_M2_vabsdiffw; break;
3756
3757 case Hexagon::BI__builtin_HEXAGON_M2_vabsdiffh:
3758 ID = Intrinsic::hexagon_M2_vabsdiffh; break;
3759
3760 case Hexagon::BI__builtin_HEXAGON_A2_vrsadub:
3761 ID = Intrinsic::hexagon_A2_vrsadub; break;
3762
3763 case Hexagon::BI__builtin_HEXAGON_A2_vrsadub_acc:
3764 ID = Intrinsic::hexagon_A2_vrsadub_acc; break;
3765
3766 case Hexagon::BI__builtin_HEXAGON_A2_vavgub:
3767 ID = Intrinsic::hexagon_A2_vavgub; break;
3768
3769 case Hexagon::BI__builtin_HEXAGON_A2_vavguh:
3770 ID = Intrinsic::hexagon_A2_vavguh; break;
3771
3772 case Hexagon::BI__builtin_HEXAGON_A2_vavgh:
3773 ID = Intrinsic::hexagon_A2_vavgh; break;
3774
3775 case Hexagon::BI__builtin_HEXAGON_A2_vnavgh:
3776 ID = Intrinsic::hexagon_A2_vnavgh; break;
3777
3778 case Hexagon::BI__builtin_HEXAGON_A2_vavgw:
3779 ID = Intrinsic::hexagon_A2_vavgw; break;
3780
3781 case Hexagon::BI__builtin_HEXAGON_A2_vnavgw:
3782 ID = Intrinsic::hexagon_A2_vnavgw; break;
3783
3784 case Hexagon::BI__builtin_HEXAGON_A2_vavgwr:
3785 ID = Intrinsic::hexagon_A2_vavgwr; break;
3786
3787 case Hexagon::BI__builtin_HEXAGON_A2_vnavgwr:
3788 ID = Intrinsic::hexagon_A2_vnavgwr; break;
3789
3790 case Hexagon::BI__builtin_HEXAGON_A2_vavgwcr:
3791 ID = Intrinsic::hexagon_A2_vavgwcr; break;
3792
3793 case Hexagon::BI__builtin_HEXAGON_A2_vnavgwcr:
3794 ID = Intrinsic::hexagon_A2_vnavgwcr; break;
3795
3796 case Hexagon::BI__builtin_HEXAGON_A2_vavghcr:
3797 ID = Intrinsic::hexagon_A2_vavghcr; break;
3798
3799 case Hexagon::BI__builtin_HEXAGON_A2_vnavghcr:
3800 ID = Intrinsic::hexagon_A2_vnavghcr; break;
3801
3802 case Hexagon::BI__builtin_HEXAGON_A2_vavguw:
3803 ID = Intrinsic::hexagon_A2_vavguw; break;
3804
3805 case Hexagon::BI__builtin_HEXAGON_A2_vavguwr:
3806 ID = Intrinsic::hexagon_A2_vavguwr; break;
3807
3808 case Hexagon::BI__builtin_HEXAGON_A2_vavgubr:
3809 ID = Intrinsic::hexagon_A2_vavgubr; break;
3810
3811 case Hexagon::BI__builtin_HEXAGON_A2_vavguhr:
3812 ID = Intrinsic::hexagon_A2_vavguhr; break;
3813
3814 case Hexagon::BI__builtin_HEXAGON_A2_vavghr:
3815 ID = Intrinsic::hexagon_A2_vavghr; break;
3816
3817 case Hexagon::BI__builtin_HEXAGON_A2_vnavghr:
3818 ID = Intrinsic::hexagon_A2_vnavghr; break;
3819
3820 case Hexagon::BI__builtin_HEXAGON_A2_vminh:
3821 ID = Intrinsic::hexagon_A2_vminh; break;
3822
3823 case Hexagon::BI__builtin_HEXAGON_A2_vmaxh:
3824 ID = Intrinsic::hexagon_A2_vmaxh; break;
3825
3826 case Hexagon::BI__builtin_HEXAGON_A2_vminub:
3827 ID = Intrinsic::hexagon_A2_vminub; break;
3828
3829 case Hexagon::BI__builtin_HEXAGON_A2_vmaxub:
3830 ID = Intrinsic::hexagon_A2_vmaxub; break;
3831
3832 case Hexagon::BI__builtin_HEXAGON_A2_vminuh:
3833 ID = Intrinsic::hexagon_A2_vminuh; break;
3834
3835 case Hexagon::BI__builtin_HEXAGON_A2_vmaxuh:
3836 ID = Intrinsic::hexagon_A2_vmaxuh; break;
3837
3838 case Hexagon::BI__builtin_HEXAGON_A2_vminw:
3839 ID = Intrinsic::hexagon_A2_vminw; break;
3840
3841 case Hexagon::BI__builtin_HEXAGON_A2_vmaxw:
3842 ID = Intrinsic::hexagon_A2_vmaxw; break;
3843
3844 case Hexagon::BI__builtin_HEXAGON_A2_vminuw:
3845 ID = Intrinsic::hexagon_A2_vminuw; break;
3846
3847 case Hexagon::BI__builtin_HEXAGON_A2_vmaxuw:
3848 ID = Intrinsic::hexagon_A2_vmaxuw; break;
3849
3850 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_r:
3851 ID = Intrinsic::hexagon_S2_asr_r_r; break;
3852
3853 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_r:
3854 ID = Intrinsic::hexagon_S2_asl_r_r; break;
3855
3856 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_r:
3857 ID = Intrinsic::hexagon_S2_lsr_r_r; break;
3858
3859 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_r:
3860 ID = Intrinsic::hexagon_S2_lsl_r_r; break;
3861
3862 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_p:
3863 ID = Intrinsic::hexagon_S2_asr_r_p; break;
3864
3865 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_p:
3866 ID = Intrinsic::hexagon_S2_asl_r_p; break;
3867
3868 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_p:
3869 ID = Intrinsic::hexagon_S2_lsr_r_p; break;
3870
3871 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_p:
3872 ID = Intrinsic::hexagon_S2_lsl_r_p; break;
3873
3874 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_r_acc:
3875 ID = Intrinsic::hexagon_S2_asr_r_r_acc; break;
3876
3877 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_r_acc:
3878 ID = Intrinsic::hexagon_S2_asl_r_r_acc; break;
3879
3880 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_r_acc:
3881 ID = Intrinsic::hexagon_S2_lsr_r_r_acc; break;
3882
3883 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_r_acc:
3884 ID = Intrinsic::hexagon_S2_lsl_r_r_acc; break;
3885
3886 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_p_acc:
3887 ID = Intrinsic::hexagon_S2_asr_r_p_acc; break;
3888
3889 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_p_acc:
3890 ID = Intrinsic::hexagon_S2_asl_r_p_acc; break;
3891
3892 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_p_acc:
3893 ID = Intrinsic::hexagon_S2_lsr_r_p_acc; break;
3894
3895 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_p_acc:
3896 ID = Intrinsic::hexagon_S2_lsl_r_p_acc; break;
3897
3898 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_r_nac:
3899 ID = Intrinsic::hexagon_S2_asr_r_r_nac; break;
3900
3901 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_r_nac:
3902 ID = Intrinsic::hexagon_S2_asl_r_r_nac; break;
3903
3904 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_r_nac:
3905 ID = Intrinsic::hexagon_S2_lsr_r_r_nac; break;
3906
3907 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_r_nac:
3908 ID = Intrinsic::hexagon_S2_lsl_r_r_nac; break;
3909
3910 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_p_nac:
3911 ID = Intrinsic::hexagon_S2_asr_r_p_nac; break;
3912
3913 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_p_nac:
3914 ID = Intrinsic::hexagon_S2_asl_r_p_nac; break;
3915
3916 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_p_nac:
3917 ID = Intrinsic::hexagon_S2_lsr_r_p_nac; break;
3918
3919 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_p_nac:
3920 ID = Intrinsic::hexagon_S2_lsl_r_p_nac; break;
3921
3922 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_r_and:
3923 ID = Intrinsic::hexagon_S2_asr_r_r_and; break;
3924
3925 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_r_and:
3926 ID = Intrinsic::hexagon_S2_asl_r_r_and; break;
3927
3928 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_r_and:
3929 ID = Intrinsic::hexagon_S2_lsr_r_r_and; break;
3930
3931 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_r_and:
3932 ID = Intrinsic::hexagon_S2_lsl_r_r_and; break;
3933
3934 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_r_or:
3935 ID = Intrinsic::hexagon_S2_asr_r_r_or; break;
3936
3937 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_r_or:
3938 ID = Intrinsic::hexagon_S2_asl_r_r_or; break;
3939
3940 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_r_or:
3941 ID = Intrinsic::hexagon_S2_lsr_r_r_or; break;
3942
3943 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_r_or:
3944 ID = Intrinsic::hexagon_S2_lsl_r_r_or; break;
3945
3946 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_p_and:
3947 ID = Intrinsic::hexagon_S2_asr_r_p_and; break;
3948
3949 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_p_and:
3950 ID = Intrinsic::hexagon_S2_asl_r_p_and; break;
3951
3952 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_p_and:
3953 ID = Intrinsic::hexagon_S2_lsr_r_p_and; break;
3954
3955 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_p_and:
3956 ID = Intrinsic::hexagon_S2_lsl_r_p_and; break;
3957
3958 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_p_or:
3959 ID = Intrinsic::hexagon_S2_asr_r_p_or; break;
3960
3961 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_p_or:
3962 ID = Intrinsic::hexagon_S2_asl_r_p_or; break;
3963
3964 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_p_or:
3965 ID = Intrinsic::hexagon_S2_lsr_r_p_or; break;
3966
3967 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_p_or:
3968 ID = Intrinsic::hexagon_S2_lsl_r_p_or; break;
3969
3970 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_r_sat:
3971 ID = Intrinsic::hexagon_S2_asr_r_r_sat; break;
3972
3973 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_r_sat:
3974 ID = Intrinsic::hexagon_S2_asl_r_r_sat; break;
3975
3976 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r:
3977 ID = Intrinsic::hexagon_S2_asr_i_r; break;
3978
3979 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r:
3980 ID = Intrinsic::hexagon_S2_lsr_i_r; break;
3981
3982 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r:
3983 ID = Intrinsic::hexagon_S2_asl_i_r; break;
3984
3985 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_p:
3986 ID = Intrinsic::hexagon_S2_asr_i_p; break;
3987
3988 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p:
3989 ID = Intrinsic::hexagon_S2_lsr_i_p; break;
3990
3991 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_p:
3992 ID = Intrinsic::hexagon_S2_asl_i_p; break;
3993
3994 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_acc:
3995 ID = Intrinsic::hexagon_S2_asr_i_r_acc; break;
3996
3997 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_acc:
3998 ID = Intrinsic::hexagon_S2_lsr_i_r_acc; break;
3999
4000 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_acc:
4001 ID = Intrinsic::hexagon_S2_asl_i_r_acc; break;
4002
4003 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_acc:
4004 ID = Intrinsic::hexagon_S2_asr_i_p_acc; break;
4005
4006 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_acc:
4007 ID = Intrinsic::hexagon_S2_lsr_i_p_acc; break;
4008
4009 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_acc:
4010 ID = Intrinsic::hexagon_S2_asl_i_p_acc; break;
4011
4012 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_nac:
4013 ID = Intrinsic::hexagon_S2_asr_i_r_nac; break;
4014
4015 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_nac:
4016 ID = Intrinsic::hexagon_S2_lsr_i_r_nac; break;
4017
4018 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_nac:
4019 ID = Intrinsic::hexagon_S2_asl_i_r_nac; break;
4020
4021 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_nac:
4022 ID = Intrinsic::hexagon_S2_asr_i_p_nac; break;
4023
4024 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_nac:
4025 ID = Intrinsic::hexagon_S2_lsr_i_p_nac; break;
4026
4027 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_nac:
4028 ID = Intrinsic::hexagon_S2_asl_i_p_nac; break;
4029
4030 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_xacc:
4031 ID = Intrinsic::hexagon_S2_lsr_i_r_xacc; break;
4032
4033 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_xacc:
4034 ID = Intrinsic::hexagon_S2_asl_i_r_xacc; break;
4035
4036 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_xacc:
4037 ID = Intrinsic::hexagon_S2_lsr_i_p_xacc; break;
4038
4039 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_xacc:
4040 ID = Intrinsic::hexagon_S2_asl_i_p_xacc; break;
4041
4042 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_and:
4043 ID = Intrinsic::hexagon_S2_asr_i_r_and; break;
4044
4045 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_and:
4046 ID = Intrinsic::hexagon_S2_lsr_i_r_and; break;
4047
4048 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_and:
4049 ID = Intrinsic::hexagon_S2_asl_i_r_and; break;
4050
4051 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_or:
4052 ID = Intrinsic::hexagon_S2_asr_i_r_or; break;
4053
4054 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_r_or:
4055 ID = Intrinsic::hexagon_S2_lsr_i_r_or; break;
4056
4057 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_or:
4058 ID = Intrinsic::hexagon_S2_asl_i_r_or; break;
4059
4060 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_and:
4061 ID = Intrinsic::hexagon_S2_asr_i_p_and; break;
4062
4063 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_and:
4064 ID = Intrinsic::hexagon_S2_lsr_i_p_and; break;
4065
4066 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_and:
4067 ID = Intrinsic::hexagon_S2_asl_i_p_and; break;
4068
4069 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_p_or:
4070 ID = Intrinsic::hexagon_S2_asr_i_p_or; break;
4071
4072 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_p_or:
4073 ID = Intrinsic::hexagon_S2_lsr_i_p_or; break;
4074
4075 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_p_or:
4076 ID = Intrinsic::hexagon_S2_asl_i_p_or; break;
4077
4078 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_r_sat:
4079 ID = Intrinsic::hexagon_S2_asl_i_r_sat; break;
4080
4081 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd:
4082 ID = Intrinsic::hexagon_S2_asr_i_r_rnd; break;
4083
4084 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_r_rnd_goodsyntax:
4085 ID = Intrinsic::hexagon_S2_asr_i_r_rnd_goodsyntax; break;
4086
4087 case Hexagon::BI__builtin_HEXAGON_S2_addasl_rrri:
4088 ID = Intrinsic::hexagon_S2_addasl_rrri; break;
4089
4090 case Hexagon::BI__builtin_HEXAGON_S2_valignib:
4091 ID = Intrinsic::hexagon_S2_valignib; break;
4092
4093 case Hexagon::BI__builtin_HEXAGON_S2_valignrb:
4094 ID = Intrinsic::hexagon_S2_valignrb; break;
4095
4096 case Hexagon::BI__builtin_HEXAGON_S2_vspliceib:
4097 ID = Intrinsic::hexagon_S2_vspliceib; break;
4098
4099 case Hexagon::BI__builtin_HEXAGON_S2_vsplicerb:
4100 ID = Intrinsic::hexagon_S2_vsplicerb; break;
4101
4102 case Hexagon::BI__builtin_HEXAGON_S2_vsplatrh:
4103 ID = Intrinsic::hexagon_S2_vsplatrh; break;
4104
4105 case Hexagon::BI__builtin_HEXAGON_S2_vsplatrb:
4106 ID = Intrinsic::hexagon_S2_vsplatrb; break;
4107
4108 case Hexagon::BI__builtin_HEXAGON_S2_insert:
4109 ID = Intrinsic::hexagon_S2_insert; break;
4110
4111 case Hexagon::BI__builtin_HEXAGON_S2_tableidxb_goodsyntax:
4112 ID = Intrinsic::hexagon_S2_tableidxb_goodsyntax; break;
4113
4114 case Hexagon::BI__builtin_HEXAGON_S2_tableidxh_goodsyntax:
4115 ID = Intrinsic::hexagon_S2_tableidxh_goodsyntax; break;
4116
4117 case Hexagon::BI__builtin_HEXAGON_S2_tableidxw_goodsyntax:
4118 ID = Intrinsic::hexagon_S2_tableidxw_goodsyntax; break;
4119
4120 case Hexagon::BI__builtin_HEXAGON_S2_tableidxd_goodsyntax:
4121 ID = Intrinsic::hexagon_S2_tableidxd_goodsyntax; break;
4122
4123 case Hexagon::BI__builtin_HEXAGON_S2_extractu:
4124 ID = Intrinsic::hexagon_S2_extractu; break;
4125
4126 case Hexagon::BI__builtin_HEXAGON_S2_insertp:
4127 ID = Intrinsic::hexagon_S2_insertp; break;
4128
4129 case Hexagon::BI__builtin_HEXAGON_S2_extractup:
4130 ID = Intrinsic::hexagon_S2_extractup; break;
4131
4132 case Hexagon::BI__builtin_HEXAGON_S2_insert_rp:
4133 ID = Intrinsic::hexagon_S2_insert_rp; break;
4134
4135 case Hexagon::BI__builtin_HEXAGON_S2_extractu_rp:
4136 ID = Intrinsic::hexagon_S2_extractu_rp; break;
4137
4138 case Hexagon::BI__builtin_HEXAGON_S2_insertp_rp:
4139 ID = Intrinsic::hexagon_S2_insertp_rp; break;
4140
4141 case Hexagon::BI__builtin_HEXAGON_S2_extractup_rp:
4142 ID = Intrinsic::hexagon_S2_extractup_rp; break;
4143
4144 case Hexagon::BI__builtin_HEXAGON_S2_tstbit_i:
4145 ID = Intrinsic::hexagon_S2_tstbit_i; break;
4146
4147 case Hexagon::BI__builtin_HEXAGON_S2_setbit_i:
4148 ID = Intrinsic::hexagon_S2_setbit_i; break;
4149
4150 case Hexagon::BI__builtin_HEXAGON_S2_togglebit_i:
4151 ID = Intrinsic::hexagon_S2_togglebit_i; break;
4152
4153 case Hexagon::BI__builtin_HEXAGON_S2_clrbit_i:
4154 ID = Intrinsic::hexagon_S2_clrbit_i; break;
4155
4156 case Hexagon::BI__builtin_HEXAGON_S2_tstbit_r:
4157 ID = Intrinsic::hexagon_S2_tstbit_r; break;
4158
4159 case Hexagon::BI__builtin_HEXAGON_S2_setbit_r:
4160 ID = Intrinsic::hexagon_S2_setbit_r; break;
4161
4162 case Hexagon::BI__builtin_HEXAGON_S2_togglebit_r:
4163 ID = Intrinsic::hexagon_S2_togglebit_r; break;
4164
4165 case Hexagon::BI__builtin_HEXAGON_S2_clrbit_r:
4166 ID = Intrinsic::hexagon_S2_clrbit_r; break;
4167
4168 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_vh:
4169 ID = Intrinsic::hexagon_S2_asr_i_vh; break;
4170
4171 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vh:
4172 ID = Intrinsic::hexagon_S2_lsr_i_vh; break;
4173
4174 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_vh:
4175 ID = Intrinsic::hexagon_S2_asl_i_vh; break;
4176
4177 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_vh:
4178 ID = Intrinsic::hexagon_S2_asr_r_vh; break;
4179
4180 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_vh:
4181 ID = Intrinsic::hexagon_S2_asl_r_vh; break;
4182
4183 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_vh:
4184 ID = Intrinsic::hexagon_S2_lsr_r_vh; break;
4185
4186 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_vh:
4187 ID = Intrinsic::hexagon_S2_lsl_r_vh; break;
4188
4189 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_vw:
4190 ID = Intrinsic::hexagon_S2_asr_i_vw; break;
4191
4192 case Hexagon::BI__builtin_HEXAGON_S2_asr_i_svw_trun:
4193 ID = Intrinsic::hexagon_S2_asr_i_svw_trun; break;
4194
4195 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_svw_trun:
4196 ID = Intrinsic::hexagon_S2_asr_r_svw_trun; break;
4197
4198 case Hexagon::BI__builtin_HEXAGON_S2_lsr_i_vw:
4199 ID = Intrinsic::hexagon_S2_lsr_i_vw; break;
4200
4201 case Hexagon::BI__builtin_HEXAGON_S2_asl_i_vw:
4202 ID = Intrinsic::hexagon_S2_asl_i_vw; break;
4203
4204 case Hexagon::BI__builtin_HEXAGON_S2_asr_r_vw:
4205 ID = Intrinsic::hexagon_S2_asr_r_vw; break;
4206
4207 case Hexagon::BI__builtin_HEXAGON_S2_asl_r_vw:
4208 ID = Intrinsic::hexagon_S2_asl_r_vw; break;
4209
4210 case Hexagon::BI__builtin_HEXAGON_S2_lsr_r_vw:
4211 ID = Intrinsic::hexagon_S2_lsr_r_vw; break;
4212
4213 case Hexagon::BI__builtin_HEXAGON_S2_lsl_r_vw:
4214 ID = Intrinsic::hexagon_S2_lsl_r_vw; break;
4215
4216 case Hexagon::BI__builtin_HEXAGON_S2_vrndpackwh:
4217 ID = Intrinsic::hexagon_S2_vrndpackwh; break;
4218
4219 case Hexagon::BI__builtin_HEXAGON_S2_vrndpackwhs:
4220 ID = Intrinsic::hexagon_S2_vrndpackwhs; break;
4221
4222 case Hexagon::BI__builtin_HEXAGON_S2_vsxtbh:
4223 ID = Intrinsic::hexagon_S2_vsxtbh; break;
4224
4225 case Hexagon::BI__builtin_HEXAGON_S2_vzxtbh:
4226 ID = Intrinsic::hexagon_S2_vzxtbh; break;
4227
4228 case Hexagon::BI__builtin_HEXAGON_S2_vsathub:
4229 ID = Intrinsic::hexagon_S2_vsathub; break;
4230
4231 case Hexagon::BI__builtin_HEXAGON_S2_svsathub:
4232 ID = Intrinsic::hexagon_S2_svsathub; break;
4233
4234 case Hexagon::BI__builtin_HEXAGON_S2_svsathb:
4235 ID = Intrinsic::hexagon_S2_svsathb; break;
4236
4237 case Hexagon::BI__builtin_HEXAGON_S2_vsathb:
4238 ID = Intrinsic::hexagon_S2_vsathb; break;
4239
4240 case Hexagon::BI__builtin_HEXAGON_S2_vtrunohb:
4241 ID = Intrinsic::hexagon_S2_vtrunohb; break;
4242
4243 case Hexagon::BI__builtin_HEXAGON_S2_vtrunewh:
4244 ID = Intrinsic::hexagon_S2_vtrunewh; break;
4245
4246 case Hexagon::BI__builtin_HEXAGON_S2_vtrunowh:
4247 ID = Intrinsic::hexagon_S2_vtrunowh; break;
4248
4249 case Hexagon::BI__builtin_HEXAGON_S2_vtrunehb:
4250 ID = Intrinsic::hexagon_S2_vtrunehb; break;
4251
4252 case Hexagon::BI__builtin_HEXAGON_S2_vsxthw:
4253 ID = Intrinsic::hexagon_S2_vsxthw; break;
4254
4255 case Hexagon::BI__builtin_HEXAGON_S2_vzxthw:
4256 ID = Intrinsic::hexagon_S2_vzxthw; break;
4257
4258 case Hexagon::BI__builtin_HEXAGON_S2_vsatwh:
4259 ID = Intrinsic::hexagon_S2_vsatwh; break;
4260
4261 case Hexagon::BI__builtin_HEXAGON_S2_vsatwuh:
4262 ID = Intrinsic::hexagon_S2_vsatwuh; break;
4263
4264 case Hexagon::BI__builtin_HEXAGON_S2_packhl:
4265 ID = Intrinsic::hexagon_S2_packhl; break;
4266
4267 case Hexagon::BI__builtin_HEXAGON_A2_swiz:
4268 ID = Intrinsic::hexagon_A2_swiz; break;
4269
4270 case Hexagon::BI__builtin_HEXAGON_S2_vsathub_nopack:
4271 ID = Intrinsic::hexagon_S2_vsathub_nopack; break;
4272
4273 case Hexagon::BI__builtin_HEXAGON_S2_vsathb_nopack:
4274 ID = Intrinsic::hexagon_S2_vsathb_nopack; break;
4275
4276 case Hexagon::BI__builtin_HEXAGON_S2_vsatwh_nopack:
4277 ID = Intrinsic::hexagon_S2_vsatwh_nopack; break;
4278
4279 case Hexagon::BI__builtin_HEXAGON_S2_vsatwuh_nopack:
4280 ID = Intrinsic::hexagon_S2_vsatwuh_nopack; break;
4281
4282 case Hexagon::BI__builtin_HEXAGON_S2_shuffob:
4283 ID = Intrinsic::hexagon_S2_shuffob; break;
4284
4285 case Hexagon::BI__builtin_HEXAGON_S2_shuffeb:
4286 ID = Intrinsic::hexagon_S2_shuffeb; break;
4287
4288 case Hexagon::BI__builtin_HEXAGON_S2_shuffoh:
4289 ID = Intrinsic::hexagon_S2_shuffoh; break;
4290
4291 case Hexagon::BI__builtin_HEXAGON_S2_shuffeh:
4292 ID = Intrinsic::hexagon_S2_shuffeh; break;
4293
4294 case Hexagon::BI__builtin_HEXAGON_S2_parityp:
4295 ID = Intrinsic::hexagon_S2_parityp; break;
4296
4297 case Hexagon::BI__builtin_HEXAGON_S2_lfsp:
4298 ID = Intrinsic::hexagon_S2_lfsp; break;
4299
4300 case Hexagon::BI__builtin_HEXAGON_S2_clbnorm:
4301 ID = Intrinsic::hexagon_S2_clbnorm; break;
4302
4303 case Hexagon::BI__builtin_HEXAGON_S2_clb:
4304 ID = Intrinsic::hexagon_S2_clb; break;
4305
4306 case Hexagon::BI__builtin_HEXAGON_S2_cl0:
4307 ID = Intrinsic::hexagon_S2_cl0; break;
4308
4309 case Hexagon::BI__builtin_HEXAGON_S2_cl1:
4310 ID = Intrinsic::hexagon_S2_cl1; break;
4311
4312 case Hexagon::BI__builtin_HEXAGON_S2_clbp:
4313 ID = Intrinsic::hexagon_S2_clbp; break;
4314
4315 case Hexagon::BI__builtin_HEXAGON_S2_cl0p:
4316 ID = Intrinsic::hexagon_S2_cl0p; break;
4317
4318 case Hexagon::BI__builtin_HEXAGON_S2_cl1p:
4319 ID = Intrinsic::hexagon_S2_cl1p; break;
4320
4321 case Hexagon::BI__builtin_HEXAGON_S2_brev:
4322 ID = Intrinsic::hexagon_S2_brev; break;
4323
4324 case Hexagon::BI__builtin_HEXAGON_S2_ct0:
4325 ID = Intrinsic::hexagon_S2_ct0; break;
4326
4327 case Hexagon::BI__builtin_HEXAGON_S2_ct1:
4328 ID = Intrinsic::hexagon_S2_ct1; break;
4329
4330 case Hexagon::BI__builtin_HEXAGON_S2_interleave:
4331 ID = Intrinsic::hexagon_S2_interleave; break;
4332
4333 case Hexagon::BI__builtin_HEXAGON_S2_deinterleave:
4334 ID = Intrinsic::hexagon_S2_deinterleave; break;
4335
4336 case Hexagon::BI__builtin_SI_to_SXTHI_asrh:
4337 ID = Intrinsic::hexagon_SI_to_SXTHI_asrh; break;
4338
4339 case Hexagon::BI__builtin_HEXAGON_A4_orn:
4340 ID = Intrinsic::hexagon_A4_orn; break;
4341
4342 case Hexagon::BI__builtin_HEXAGON_A4_andn:
4343 ID = Intrinsic::hexagon_A4_andn; break;
4344
4345 case Hexagon::BI__builtin_HEXAGON_A4_ornp:
4346 ID = Intrinsic::hexagon_A4_ornp; break;
4347
4348 case Hexagon::BI__builtin_HEXAGON_A4_andnp:
4349 ID = Intrinsic::hexagon_A4_andnp; break;
4350
4351 case Hexagon::BI__builtin_HEXAGON_A4_combineir:
4352 ID = Intrinsic::hexagon_A4_combineir; break;
4353
4354 case Hexagon::BI__builtin_HEXAGON_A4_combineri:
4355 ID = Intrinsic::hexagon_A4_combineri; break;
4356
4357 case Hexagon::BI__builtin_HEXAGON_C4_cmpneqi:
4358 ID = Intrinsic::hexagon_C4_cmpneqi; break;
4359
4360 case Hexagon::BI__builtin_HEXAGON_C4_cmpneq:
4361 ID = Intrinsic::hexagon_C4_cmpneq; break;
4362
4363 case Hexagon::BI__builtin_HEXAGON_C4_cmpltei:
4364 ID = Intrinsic::hexagon_C4_cmpltei; break;
4365
4366 case Hexagon::BI__builtin_HEXAGON_C4_cmplte:
4367 ID = Intrinsic::hexagon_C4_cmplte; break;
4368
4369 case Hexagon::BI__builtin_HEXAGON_C4_cmplteui:
4370 ID = Intrinsic::hexagon_C4_cmplteui; break;
4371
4372 case Hexagon::BI__builtin_HEXAGON_C4_cmplteu:
4373 ID = Intrinsic::hexagon_C4_cmplteu; break;
4374
4375 case Hexagon::BI__builtin_HEXAGON_A4_rcmpneq:
4376 ID = Intrinsic::hexagon_A4_rcmpneq; break;
4377
4378 case Hexagon::BI__builtin_HEXAGON_A4_rcmpneqi:
4379 ID = Intrinsic::hexagon_A4_rcmpneqi; break;
4380
4381 case Hexagon::BI__builtin_HEXAGON_A4_rcmpeq:
4382 ID = Intrinsic::hexagon_A4_rcmpeq; break;
4383
4384 case Hexagon::BI__builtin_HEXAGON_A4_rcmpeqi:
4385 ID = Intrinsic::hexagon_A4_rcmpeqi; break;
4386
4387 case Hexagon::BI__builtin_HEXAGON_C4_fastcorner9:
4388 ID = Intrinsic::hexagon_C4_fastcorner9; break;
4389
4390 case Hexagon::BI__builtin_HEXAGON_C4_fastcorner9_not:
4391 ID = Intrinsic::hexagon_C4_fastcorner9_not; break;
4392
4393 case Hexagon::BI__builtin_HEXAGON_C4_and_andn:
4394 ID = Intrinsic::hexagon_C4_and_andn; break;
4395
4396 case Hexagon::BI__builtin_HEXAGON_C4_and_and:
4397 ID = Intrinsic::hexagon_C4_and_and; break;
4398
4399 case Hexagon::BI__builtin_HEXAGON_C4_and_orn:
4400 ID = Intrinsic::hexagon_C4_and_orn; break;
4401
4402 case Hexagon::BI__builtin_HEXAGON_C4_and_or:
4403 ID = Intrinsic::hexagon_C4_and_or; break;
4404
4405 case Hexagon::BI__builtin_HEXAGON_C4_or_andn:
4406 ID = Intrinsic::hexagon_C4_or_andn; break;
4407
4408 case Hexagon::BI__builtin_HEXAGON_C4_or_and:
4409 ID = Intrinsic::hexagon_C4_or_and; break;
4410
4411 case Hexagon::BI__builtin_HEXAGON_C4_or_orn:
4412 ID = Intrinsic::hexagon_C4_or_orn; break;
4413
4414 case Hexagon::BI__builtin_HEXAGON_C4_or_or:
4415 ID = Intrinsic::hexagon_C4_or_or; break;
4416
4417 case Hexagon::BI__builtin_HEXAGON_S4_addaddi:
4418 ID = Intrinsic::hexagon_S4_addaddi; break;
4419
4420 case Hexagon::BI__builtin_HEXAGON_S4_subaddi:
4421 ID = Intrinsic::hexagon_S4_subaddi; break;
4422
4423 case Hexagon::BI__builtin_HEXAGON_M4_xor_xacc:
4424 ID = Intrinsic::hexagon_M4_xor_xacc; break;
4425
4426 case Hexagon::BI__builtin_HEXAGON_M4_and_and:
4427 ID = Intrinsic::hexagon_M4_and_and; break;
4428
4429 case Hexagon::BI__builtin_HEXAGON_M4_and_or:
4430 ID = Intrinsic::hexagon_M4_and_or; break;
4431
4432 case Hexagon::BI__builtin_HEXAGON_M4_and_xor:
4433 ID = Intrinsic::hexagon_M4_and_xor; break;
4434
4435 case Hexagon::BI__builtin_HEXAGON_M4_and_andn:
4436 ID = Intrinsic::hexagon_M4_and_andn; break;
4437
4438 case Hexagon::BI__builtin_HEXAGON_M4_xor_and:
4439 ID = Intrinsic::hexagon_M4_xor_and; break;
4440
4441 case Hexagon::BI__builtin_HEXAGON_M4_xor_or:
4442 ID = Intrinsic::hexagon_M4_xor_or; break;
4443
4444 case Hexagon::BI__builtin_HEXAGON_M4_xor_andn:
4445 ID = Intrinsic::hexagon_M4_xor_andn; break;
4446
4447 case Hexagon::BI__builtin_HEXAGON_M4_or_and:
4448 ID = Intrinsic::hexagon_M4_or_and; break;
4449
4450 case Hexagon::BI__builtin_HEXAGON_M4_or_or:
4451 ID = Intrinsic::hexagon_M4_or_or; break;
4452
4453 case Hexagon::BI__builtin_HEXAGON_M4_or_xor:
4454 ID = Intrinsic::hexagon_M4_or_xor; break;
4455
4456 case Hexagon::BI__builtin_HEXAGON_M4_or_andn:
4457 ID = Intrinsic::hexagon_M4_or_andn; break;
4458
4459 case Hexagon::BI__builtin_HEXAGON_S4_or_andix:
4460 ID = Intrinsic::hexagon_S4_or_andix; break;
4461
4462 case Hexagon::BI__builtin_HEXAGON_S4_or_andi:
4463 ID = Intrinsic::hexagon_S4_or_andi; break;
4464
4465 case Hexagon::BI__builtin_HEXAGON_S4_or_ori:
4466 ID = Intrinsic::hexagon_S4_or_ori; break;
4467
4468 case Hexagon::BI__builtin_HEXAGON_A4_modwrapu:
4469 ID = Intrinsic::hexagon_A4_modwrapu; break;
4470
4471 case Hexagon::BI__builtin_HEXAGON_A4_cround_rr:
4472 ID = Intrinsic::hexagon_A4_cround_rr; break;
4473
4474 case Hexagon::BI__builtin_HEXAGON_A4_round_ri:
4475 ID = Intrinsic::hexagon_A4_round_ri; break;
4476
4477 case Hexagon::BI__builtin_HEXAGON_A4_round_rr:
4478 ID = Intrinsic::hexagon_A4_round_rr; break;
4479
4480 case Hexagon::BI__builtin_HEXAGON_A4_round_ri_sat:
4481 ID = Intrinsic::hexagon_A4_round_ri_sat; break;
4482
4483 case Hexagon::BI__builtin_HEXAGON_A4_round_rr_sat:
4484 ID = Intrinsic::hexagon_A4_round_rr_sat; break;
4485
4486 }
4487
4488 llvm::Function *F = CGM.getIntrinsic(ID);
4489 return Builder.CreateCall(F, Ops, "");
4490}
4491
Mike Stump1eb44332009-09-09 15:08:12 +00004492Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
Chris Lattner1feedd82007-12-13 07:34:23 +00004493 const CallExpr *E) {
Chris Lattner5f9e2722011-07-23 10:55:15 +00004494 SmallVector<Value*, 4> Ops;
Chris Lattnerdd173942010-04-14 03:54:58 +00004495
4496 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++)
4497 Ops.push_back(EmitScalarExpr(E->getArg(i)));
4498
4499 Intrinsic::ID ID = Intrinsic::not_intrinsic;
4500
4501 switch (BuiltinID) {
4502 default: return 0;
4503
Anton Korobeynikov4d3a7b02010-06-19 09:47:18 +00004504 // vec_ld, vec_lvsl, vec_lvsr
4505 case PPC::BI__builtin_altivec_lvx:
4506 case PPC::BI__builtin_altivec_lvxl:
4507 case PPC::BI__builtin_altivec_lvebx:
4508 case PPC::BI__builtin_altivec_lvehx:
4509 case PPC::BI__builtin_altivec_lvewx:
4510 case PPC::BI__builtin_altivec_lvsl:
4511 case PPC::BI__builtin_altivec_lvsr:
4512 {
John McCalld16c2cf2011-02-08 08:22:06 +00004513 Ops[1] = Builder.CreateBitCast(Ops[1], Int8PtrTy);
Anton Korobeynikov4d3a7b02010-06-19 09:47:18 +00004514
Benjamin Kramer578faa82011-09-27 21:06:10 +00004515 Ops[0] = Builder.CreateGEP(Ops[1], Ops[0]);
Anton Korobeynikov4d3a7b02010-06-19 09:47:18 +00004516 Ops.pop_back();
4517
4518 switch (BuiltinID) {
David Blaikieb219cfc2011-09-23 05:06:16 +00004519 default: llvm_unreachable("Unsupported ld/lvsl/lvsr intrinsic!");
Anton Korobeynikov4d3a7b02010-06-19 09:47:18 +00004520 case PPC::BI__builtin_altivec_lvx:
4521 ID = Intrinsic::ppc_altivec_lvx;
4522 break;
4523 case PPC::BI__builtin_altivec_lvxl:
4524 ID = Intrinsic::ppc_altivec_lvxl;
4525 break;
4526 case PPC::BI__builtin_altivec_lvebx:
4527 ID = Intrinsic::ppc_altivec_lvebx;
4528 break;
4529 case PPC::BI__builtin_altivec_lvehx:
4530 ID = Intrinsic::ppc_altivec_lvehx;
4531 break;
4532 case PPC::BI__builtin_altivec_lvewx:
4533 ID = Intrinsic::ppc_altivec_lvewx;
4534 break;
4535 case PPC::BI__builtin_altivec_lvsl:
4536 ID = Intrinsic::ppc_altivec_lvsl;
4537 break;
4538 case PPC::BI__builtin_altivec_lvsr:
4539 ID = Intrinsic::ppc_altivec_lvsr;
4540 break;
4541 }
4542 llvm::Function *F = CGM.getIntrinsic(ID);
Jay Foad4c7d9f12011-07-15 08:37:34 +00004543 return Builder.CreateCall(F, Ops, "");
Anton Korobeynikov4d3a7b02010-06-19 09:47:18 +00004544 }
4545
Chris Lattnerdd173942010-04-14 03:54:58 +00004546 // vec_st
4547 case PPC::BI__builtin_altivec_stvx:
4548 case PPC::BI__builtin_altivec_stvxl:
4549 case PPC::BI__builtin_altivec_stvebx:
4550 case PPC::BI__builtin_altivec_stvehx:
4551 case PPC::BI__builtin_altivec_stvewx:
4552 {
John McCalld16c2cf2011-02-08 08:22:06 +00004553 Ops[2] = Builder.CreateBitCast(Ops[2], Int8PtrTy);
Benjamin Kramer578faa82011-09-27 21:06:10 +00004554 Ops[1] = Builder.CreateGEP(Ops[2], Ops[1]);
Chris Lattnerdd173942010-04-14 03:54:58 +00004555 Ops.pop_back();
4556
4557 switch (BuiltinID) {
David Blaikieb219cfc2011-09-23 05:06:16 +00004558 default: llvm_unreachable("Unsupported st intrinsic!");
Chris Lattnerdd173942010-04-14 03:54:58 +00004559 case PPC::BI__builtin_altivec_stvx:
4560 ID = Intrinsic::ppc_altivec_stvx;
4561 break;
4562 case PPC::BI__builtin_altivec_stvxl:
4563 ID = Intrinsic::ppc_altivec_stvxl;
4564 break;
4565 case PPC::BI__builtin_altivec_stvebx:
4566 ID = Intrinsic::ppc_altivec_stvebx;
4567 break;
4568 case PPC::BI__builtin_altivec_stvehx:
4569 ID = Intrinsic::ppc_altivec_stvehx;
4570 break;
4571 case PPC::BI__builtin_altivec_stvewx:
4572 ID = Intrinsic::ppc_altivec_stvewx;
4573 break;
4574 }
4575 llvm::Function *F = CGM.getIntrinsic(ID);
Jay Foad4c7d9f12011-07-15 08:37:34 +00004576 return Builder.CreateCall(F, Ops, "");
Chris Lattnerdd173942010-04-14 03:54:58 +00004577 }
4578 }
Daniel Dunbarb0b84382009-12-18 20:58:47 +00004579 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00004580}