blob: d14bb53e6f447a37c6c829bfaba5e9a920e8b081 [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
14#include "CodeGenFunction.h"
15#include "CodeGenModule.h"
Anders Carlssonca6fcfa2007-12-09 21:20:04 +000016#include "clang/Basic/TargetInfo.h"
Chris Lattner1f329992008-10-06 06:09:18 +000017#include "clang/AST/APValue.h"
Chris Lattnerbef20ac2007-08-31 04:31:45 +000018#include "clang/AST/ASTContext.h"
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +000019#include "clang/AST/Decl.h"
Anders Carlsson564f1de2007-12-09 23:17:02 +000020#include "clang/AST/TargetBuiltins.h"
Anders Carlsson793680e2007-10-12 23:56:29 +000021#include "llvm/Intrinsics.h"
Anders Carlsson022012e2007-08-20 18:05:56 +000022using namespace clang;
23using namespace CodeGen;
Anders Carlssonca6fcfa2007-12-09 21:20:04 +000024using namespace llvm;
25
Daniel Dunbar0002d232009-04-07 00:55:51 +000026/// Utility to insert an atomic instruction based on Instrinsic::ID
27/// and the expression node.
28static RValue EmitBinaryAtomic(CodeGenFunction& CGF,
Mon P Wang1ffe2812008-05-09 22:40:52 +000029 Intrinsic::ID Id, const CallExpr *E) {
Mon P Wangc5004512008-07-31 03:28:23 +000030 const llvm::Type *ResType[2];
Daniel Dunbar0002d232009-04-07 00:55:51 +000031 ResType[0] = CGF.ConvertType(E->getType());
32 ResType[1] = CGF.ConvertType(E->getArg(0)->getType());
33 Value *AtomF = CGF.CGM.getIntrinsic(Id, ResType, 2);
34 return RValue::get(CGF.Builder.CreateCall2(AtomF,
35 CGF.EmitScalarExpr(E->getArg(0)),
36 CGF.EmitScalarExpr(E->getArg(1))));
37}
38
39/// Utility to insert an atomic instruction based Instrinsic::ID and
40// the expression node, where the return value is the result of the
41// operation.
42static RValue EmitBinaryAtomicPost(CodeGenFunction& CGF,
43 Intrinsic::ID Id, const CallExpr *E,
44 Instruction::BinaryOps Op) {
45 const llvm::Type *ResType[2];
46 ResType[0] = CGF.ConvertType(E->getType());
47 ResType[1] = CGF.ConvertType(E->getArg(0)->getType());
48 Value *AtomF = CGF.CGM.getIntrinsic(Id, ResType, 2);
49 Value *Ptr = CGF.EmitScalarExpr(E->getArg(0));
50 Value *Operand = CGF.EmitScalarExpr(E->getArg(1));
51 Value *Result = CGF.Builder.CreateCall2(AtomF, Ptr, Operand);
52 return RValue::get(CGF.Builder.CreateBinOp(Op, Result, Operand));
Mon P Wang1ffe2812008-05-09 22:40:52 +000053}
54
Daniel Dunbaref2abfe2009-02-16 22:43:43 +000055RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
56 unsigned BuiltinID, const CallExpr *E) {
Chris Lattner564ea2a2008-10-06 06:56:41 +000057 // See if we can constant fold this builtin. If so, don't emit it at all.
Anders Carlssonf35d35a2008-12-01 02:31:41 +000058 Expr::EvalResult Result;
Chris Lattner6ee7aa12008-11-16 21:24:15 +000059 if (E->Evaluate(Result, CGM.getContext())) {
Anders Carlssonf35d35a2008-12-01 02:31:41 +000060 if (Result.Val.isInt())
61 return RValue::get(llvm::ConstantInt::get(Result.Val.getInt()));
Eli Friedman3941b182009-01-25 01:54:01 +000062 else if (Result.Val.isFloat())
63 return RValue::get(llvm::ConstantFP::get(Result.Val.getFloat()));
Chris Lattner1f329992008-10-06 06:09:18 +000064 }
65
Chris Lattner564ea2a2008-10-06 06:56:41 +000066 switch (BuiltinID) {
67 default: break; // Handle intrinsics and libm functions below.
Chris Lattner506ff882008-10-06 07:26:43 +000068 case Builtin::BI__builtin___CFStringMakeConstantString:
Anders Carlssone9352cc2009-04-08 04:48:15 +000069 return RValue::get(CGM.EmitConstantExpr(E, E->getType(), 0));
Chris Lattner6a705f02008-07-09 17:28:44 +000070 case Builtin::BI__builtin_stdarg_start:
Anders Carlsson793680e2007-10-12 23:56:29 +000071 case Builtin::BI__builtin_va_start:
72 case Builtin::BI__builtin_va_end: {
Daniel Dunbar07855702009-02-11 22:25:55 +000073 Value *ArgValue = EmitVAListRef(E->getArg(0));
Christopher Lambddc23f32007-12-17 01:11:20 +000074 const llvm::Type *DestType =
75 llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
Anders Carlsson793680e2007-10-12 23:56:29 +000076 if (ArgValue->getType() != DestType)
77 ArgValue = Builder.CreateBitCast(ArgValue, DestType,
78 ArgValue->getNameStart());
79
Chris Lattner6a705f02008-07-09 17:28:44 +000080 Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ?
81 Intrinsic::vaend : Intrinsic::vastart;
Chris Lattner7acda7c2007-12-18 00:25:38 +000082 return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue));
Anders Carlsson793680e2007-10-12 23:56:29 +000083 }
Anders Carlssona28ef8b2008-02-09 20:26:43 +000084 case Builtin::BI__builtin_va_copy: {
Eli Friedman4fd0aa52009-01-20 17:46:04 +000085 Value *DstPtr = EmitVAListRef(E->getArg(0));
86 Value *SrcPtr = EmitVAListRef(E->getArg(1));
Anders Carlssona28ef8b2008-02-09 20:26:43 +000087
88 const llvm::Type *Type =
89 llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
90
91 DstPtr = Builder.CreateBitCast(DstPtr, Type);
92 SrcPtr = Builder.CreateBitCast(SrcPtr, Type);
Chris Lattner3eae03e2008-05-06 00:56:42 +000093 return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy),
94 DstPtr, SrcPtr));
Anders Carlssona28ef8b2008-02-09 20:26:43 +000095 }
Anders Carlssonc2251dc2007-11-20 19:05:17 +000096 case Builtin::BI__builtin_abs: {
Chris Lattner1feedd82007-12-13 07:34:23 +000097 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Anders Carlssonc2251dc2007-11-20 19:05:17 +000098
Chris Lattner9a847f52008-07-23 06:53:34 +000099 Value *NegOp = Builder.CreateNeg(ArgValue, "neg");
Chris Lattner1feedd82007-12-13 07:34:23 +0000100 Value *CmpResult =
Chris Lattner9a847f52008-07-23 06:53:34 +0000101 Builder.CreateICmpSGE(ArgValue, Constant::getNullValue(ArgValue->getType()),
102 "abscond");
Chris Lattner1feedd82007-12-13 07:34:23 +0000103 Value *Result =
Anders Carlssonc2251dc2007-11-20 19:05:17 +0000104 Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs");
105
106 return RValue::get(Result);
107 }
Anders Carlsson3a31d602008-02-06 07:19:27 +0000108 case Builtin::BI__builtin_ctz:
109 case Builtin::BI__builtin_ctzl:
110 case Builtin::BI__builtin_ctzll: {
111 Value *ArgValue = EmitScalarExpr(E->getArg(0));
112
113 const llvm::Type *ArgType = ArgValue->getType();
114 Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1);
115
116 const llvm::Type *ResultType = ConvertType(E->getType());
117 Value *Result = Builder.CreateCall(F, ArgValue, "tmp");
118 if (Result->getType() != ResultType)
119 Result = Builder.CreateIntCast(Result, ResultType, "cast");
120 return RValue::get(Result);
121 }
Eli Friedmanf4e85332008-05-27 15:32:46 +0000122 case Builtin::BI__builtin_clz:
123 case Builtin::BI__builtin_clzl:
124 case Builtin::BI__builtin_clzll: {
125 Value *ArgValue = EmitScalarExpr(E->getArg(0));
126
127 const llvm::Type *ArgType = ArgValue->getType();
128 Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1);
129
130 const llvm::Type *ResultType = ConvertType(E->getType());
131 Value *Result = Builder.CreateCall(F, ArgValue, "tmp");
132 if (Result->getType() != ResultType)
133 Result = Builder.CreateIntCast(Result, ResultType, "cast");
134 return RValue::get(Result);
135 }
Daniel Dunbar04b29002008-07-21 17:19:41 +0000136 case Builtin::BI__builtin_ffs:
137 case Builtin::BI__builtin_ffsl:
138 case Builtin::BI__builtin_ffsll: {
139 // ffs(x) -> x ? cttz(x) + 1 : 0
140 Value *ArgValue = EmitScalarExpr(E->getArg(0));
141
142 const llvm::Type *ArgType = ArgValue->getType();
143 Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1);
144
145 const llvm::Type *ResultType = ConvertType(E->getType());
146 Value *Tmp = Builder.CreateAdd(Builder.CreateCall(F, ArgValue, "tmp"),
147 ConstantInt::get(ArgType, 1), "tmp");
148 Value *Zero = llvm::Constant::getNullValue(ArgType);
149 Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero");
150 Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs");
151 if (Result->getType() != ResultType)
152 Result = Builder.CreateIntCast(Result, ResultType, "cast");
153 return RValue::get(Result);
154 }
155 case Builtin::BI__builtin_parity:
156 case Builtin::BI__builtin_parityl:
157 case Builtin::BI__builtin_parityll: {
158 // parity(x) -> ctpop(x) & 1
159 Value *ArgValue = EmitScalarExpr(E->getArg(0));
160
161 const llvm::Type *ArgType = ArgValue->getType();
162 Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1);
163
164 const llvm::Type *ResultType = ConvertType(E->getType());
165 Value *Tmp = Builder.CreateCall(F, ArgValue, "tmp");
166 Value *Result = Builder.CreateAnd(Tmp, ConstantInt::get(ArgType, 1),
167 "tmp");
168 if (Result->getType() != ResultType)
169 Result = Builder.CreateIntCast(Result, ResultType, "cast");
170 return RValue::get(Result);
171 }
172 case Builtin::BI__builtin_popcount:
173 case Builtin::BI__builtin_popcountl:
174 case Builtin::BI__builtin_popcountll: {
175 Value *ArgValue = EmitScalarExpr(E->getArg(0));
176
177 const llvm::Type *ArgType = ArgValue->getType();
178 Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1);
179
180 const llvm::Type *ResultType = ConvertType(E->getType());
181 Value *Result = Builder.CreateCall(F, ArgValue, "tmp");
182 if (Result->getType() != ResultType)
183 Result = Builder.CreateIntCast(Result, ResultType, "cast");
184 return RValue::get(Result);
185 }
Chris Lattner1feedd82007-12-13 07:34:23 +0000186 case Builtin::BI__builtin_expect:
Daniel Dunbara933c3c2008-07-21 18:44:41 +0000187 // FIXME: pass expect through to LLVM
Chris Lattner1feedd82007-12-13 07:34:23 +0000188 return RValue::get(EmitScalarExpr(E->getArg(0)));
Anders Carlssondf4852a2007-12-02 21:58:10 +0000189 case Builtin::BI__builtin_bswap32:
190 case Builtin::BI__builtin_bswap64: {
Chris Lattner1feedd82007-12-13 07:34:23 +0000191 Value *ArgValue = EmitScalarExpr(E->getArg(0));
Anders Carlssondf4852a2007-12-02 21:58:10 +0000192 const llvm::Type *ArgType = ArgValue->getType();
Chris Lattner7acda7c2007-12-18 00:25:38 +0000193 Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1);
Chris Lattner1feedd82007-12-13 07:34:23 +0000194 return RValue::get(Builder.CreateCall(F, ArgValue, "tmp"));
Daniel Dunbar4493f792008-07-21 22:59:13 +0000195 }
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +0000196 case Builtin::BI__builtin_object_size: {
197 // FIXME: Implement. For now we just always fail and pretend we
198 // don't know the object size.
Eli Friedman9a901bb2009-04-26 19:19:15 +0000199 llvm::APSInt TypeArg = E->getArg(1)->EvaluateAsInt(CGM.getContext());
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +0000200 const llvm::Type *ResType = ConvertType(E->getType());
201 // bool UseSubObject = TypeArg.getZExtValue() & 1;
202 bool UseMinimum = TypeArg.getZExtValue() & 2;
203 return RValue::get(ConstantInt::get(ResType, UseMinimum ? 0 : -1LL));
204 }
Daniel Dunbar4493f792008-07-21 22:59:13 +0000205 case Builtin::BI__builtin_prefetch: {
206 Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));
207 // FIXME: Technically these constants should of type 'int', yes?
208 RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) :
209 ConstantInt::get(llvm::Type::Int32Ty, 0);
210 Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) :
211 ConstantInt::get(llvm::Type::Int32Ty, 3);
212 Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0);
213 return RValue::get(Builder.CreateCall3(F, Address, RW, Locality));
Anders Carlssondf4852a2007-12-02 21:58:10 +0000214 }
Daniel Dunbar4493f792008-07-21 22:59:13 +0000215 case Builtin::BI__builtin_trap: {
216 Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0);
217 return RValue::get(Builder.CreateCall(F));
218 }
219
Daniel Dunbara933c3c2008-07-21 18:44:41 +0000220 case Builtin::BI__builtin_powi:
221 case Builtin::BI__builtin_powif:
222 case Builtin::BI__builtin_powil: {
223 Value *Base = EmitScalarExpr(E->getArg(0));
224 Value *Exponent = EmitScalarExpr(E->getArg(1));
Daniel Dunbara933c3c2008-07-21 18:44:41 +0000225 const llvm::Type *ArgType = Base->getType();
226 Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1);
Daniel Dunbara933c3c2008-07-21 18:44:41 +0000227 return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp"));
228 }
229
Chris Lattnerfe23e212007-12-20 00:44:32 +0000230 case Builtin::BI__builtin_isgreater:
231 case Builtin::BI__builtin_isgreaterequal:
232 case Builtin::BI__builtin_isless:
233 case Builtin::BI__builtin_islessequal:
234 case Builtin::BI__builtin_islessgreater:
235 case Builtin::BI__builtin_isunordered: {
236 // Ordered comparisons: we know the arguments to these are matching scalar
237 // floating point values.
238 Value *LHS = EmitScalarExpr(E->getArg(0));
239 Value *RHS = EmitScalarExpr(E->getArg(1));
240
241 switch (BuiltinID) {
242 default: assert(0 && "Unknown ordered comparison");
243 case Builtin::BI__builtin_isgreater:
244 LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp");
245 break;
246 case Builtin::BI__builtin_isgreaterequal:
247 LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp");
248 break;
249 case Builtin::BI__builtin_isless:
250 LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp");
251 break;
252 case Builtin::BI__builtin_islessequal:
253 LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp");
254 break;
255 case Builtin::BI__builtin_islessgreater:
256 LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp");
257 break;
258 case Builtin::BI__builtin_isunordered:
259 LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp");
260 break;
261 }
262 // ZExt bool to int type.
263 return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()),
264 "tmp"));
265 }
Chris Lattner9e800e32008-06-16 17:15:14 +0000266 case Builtin::BI__builtin_alloca: {
267 // FIXME: LLVM IR Should allow alloca with an i64 size!
268 Value *Size = EmitScalarExpr(E->getArg(0));
269 Size = Builder.CreateIntCast(Size, llvm::Type::Int32Ty, false, "tmp");
Daniel Dunbar1caae952008-07-22 00:26:45 +0000270 return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size, "tmp"));
271 }
272 case Builtin::BI__builtin_bzero: {
273 Value *Address = EmitScalarExpr(E->getArg(0));
274 Builder.CreateCall4(CGM.getMemSetFn(), Address,
275 llvm::ConstantInt::get(llvm::Type::Int8Ty, 0),
276 EmitScalarExpr(E->getArg(1)),
277 llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
278 return RValue::get(Address);
Chris Lattner9e800e32008-06-16 17:15:14 +0000279 }
Eli Friedmand4b32e42008-05-19 23:27:48 +0000280 case Builtin::BI__builtin_memcpy: {
Daniel Dunbar1caae952008-07-22 00:26:45 +0000281 Value *Address = EmitScalarExpr(E->getArg(0));
282 Builder.CreateCall4(CGM.getMemCpyFn(), Address,
283 EmitScalarExpr(E->getArg(1)),
284 EmitScalarExpr(E->getArg(2)),
285 llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
286 return RValue::get(Address);
287 }
288 case Builtin::BI__builtin_memmove: {
289 Value *Address = EmitScalarExpr(E->getArg(0));
290 Builder.CreateCall4(CGM.getMemMoveFn(), Address,
291 EmitScalarExpr(E->getArg(1)),
292 EmitScalarExpr(E->getArg(2)),
293 llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
294 return RValue::get(Address);
295 }
296 case Builtin::BI__builtin_memset: {
297 Value *Address = EmitScalarExpr(E->getArg(0));
298 Builder.CreateCall4(CGM.getMemSetFn(), Address,
Daniel Dunbar62c29c62009-02-16 21:52:05 +0000299 Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
300 llvm::Type::Int8Ty),
Daniel Dunbar1caae952008-07-22 00:26:45 +0000301 EmitScalarExpr(E->getArg(2)),
302 llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
303 return RValue::get(Address);
Eli Friedmand4b32e42008-05-19 23:27:48 +0000304 }
Eli Friedman256f77e2008-05-20 08:59:34 +0000305 case Builtin::BI__builtin_return_address: {
306 Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0);
307 return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0))));
308 }
309 case Builtin::BI__builtin_frame_address: {
310 Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0);
311 return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0))));
312 }
Eli Friedman3b660ef2009-05-03 19:23:23 +0000313 case Builtin::BI__builtin_extract_return_addr: {
314 // FIXME: There should be a target hook for this
315 return RValue::get(EmitScalarExpr(E->getArg(0)));
316 }
Mon P Wang1ffe2812008-05-09 22:40:52 +0000317 case Builtin::BI__sync_fetch_and_add:
Mon P Wang09b6bf52008-06-25 08:21:36 +0000318 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_add, E);
Mon P Wang1ffe2812008-05-09 22:40:52 +0000319 case Builtin::BI__sync_fetch_and_sub:
Mon P Wang09b6bf52008-06-25 08:21:36 +0000320 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_sub, E);
Mon P Wang1ffe2812008-05-09 22:40:52 +0000321 case Builtin::BI__sync_fetch_and_min:
322 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E);
323 case Builtin::BI__sync_fetch_and_max:
324 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E);
325 case Builtin::BI__sync_fetch_and_umin:
326 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E);
327 case Builtin::BI__sync_fetch_and_umax:
328 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E);
329 case Builtin::BI__sync_fetch_and_and:
330 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E);
331 case Builtin::BI__sync_fetch_and_or:
332 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E);
333 case Builtin::BI__sync_fetch_and_xor:
334 return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E);
Daniel Dunbar0002d232009-04-07 00:55:51 +0000335
336 case Builtin::BI__sync_add_and_fetch:
337 return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_add, E,
338 llvm::Instruction::Add);
339 case Builtin::BI__sync_sub_and_fetch:
340 return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_sub, E,
341 llvm::Instruction::Sub);
342 case Builtin::BI__sync_and_and_fetch:
343 return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_and, E,
344 llvm::Instruction::And);
345 case Builtin::BI__sync_or_and_fetch:
346 return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_or, E,
347 llvm::Instruction::Or);
348 case Builtin::BI__sync_xor_and_fetch:
349 return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_xor, E,
350 llvm::Instruction::Xor);
351
Mon P Wang1ffe2812008-05-09 22:40:52 +0000352 case Builtin::BI__sync_val_compare_and_swap: {
Mon P Wangc5004512008-07-31 03:28:23 +0000353 const llvm::Type *ResType[2];
354 ResType[0]= ConvertType(E->getType());
355 ResType[1] = ConvertType(E->getArg(0)->getType());
356 Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2);
Anders Carlsson95844462008-08-30 16:17:45 +0000357 return RValue::get(Builder.CreateCall3(AtomF,
358 EmitScalarExpr(E->getArg(0)),
359 EmitScalarExpr(E->getArg(1)),
360 EmitScalarExpr(E->getArg(2))));
Anders Carlsson89799cf2007-10-29 02:59:40 +0000361 }
Daniel Dunbar0002d232009-04-07 00:55:51 +0000362
363 case Builtin::BI__sync_bool_compare_and_swap: {
364 const llvm::Type *ResType[2];
365 ResType[0]= ConvertType(E->getType());
366 ResType[1] = ConvertType(E->getArg(0)->getType());
367 Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2);
368 Value *OldVal = EmitScalarExpr(E->getArg(1));
369 Value *PrevVal = Builder.CreateCall3(AtomF,
370 EmitScalarExpr(E->getArg(0)),
371 OldVal,
372 EmitScalarExpr(E->getArg(2)));
373 Value *Result = Builder.CreateICmpEQ(PrevVal, OldVal);
374 // zext bool to int.
375 return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType())));
376 }
377
Mon P Wang1ffe2812008-05-09 22:40:52 +0000378 case Builtin::BI__sync_lock_test_and_set:
Nate Begeman7ea2e3f2008-05-15 07:38:03 +0000379 return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E);
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000380
381
382 // Library functions with special handling.
383
384 case Builtin::BIsqrt:
385 case Builtin::BIsqrtf:
386 case Builtin::BIsqrtl: {
387 // Rewrite sqrt to intrinsic if allowed.
Daniel Dunbarb11fa0d2009-04-13 21:08:27 +0000388 if (!FD->hasAttr<ConstAttr>())
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000389 break;
390 Value *Arg0 = EmitScalarExpr(E->getArg(0));
391 const llvm::Type *ArgType = Arg0->getType();
392 Value *F = CGM.getIntrinsic(Intrinsic::sqrt, &ArgType, 1);
393 return RValue::get(Builder.CreateCall(F, Arg0, "tmp"));
394 }
395
396 case Builtin::BIpow:
397 case Builtin::BIpowf:
398 case Builtin::BIpowl: {
399 // Rewrite sqrt to intrinsic if allowed.
Daniel Dunbarb11fa0d2009-04-13 21:08:27 +0000400 if (!FD->hasAttr<ConstAttr>())
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000401 break;
402 Value *Base = EmitScalarExpr(E->getArg(0));
403 Value *Exponent = EmitScalarExpr(E->getArg(1));
404 const llvm::Type *ArgType = Base->getType();
405 Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1);
406 return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp"));
407 }
Nate Begeman7ea2e3f2008-05-15 07:38:03 +0000408 }
Chris Lattnerb7cfe882008-06-30 18:32:54 +0000409
410 // If this is an alias for a libm function (e.g. __builtin_sin) turn it into
411 // that function.
Douglas Gregor3e41d602009-02-13 23:20:09 +0000412 if (getContext().BuiltinInfo.isLibFunction(BuiltinID) ||
413 getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID))
Chris Lattnerb7cfe882008-06-30 18:32:54 +0000414 return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID),
415 E->getCallee()->getType(), E->arg_begin(),
416 E->arg_end());
417
418 // See if we have a target specific intrinsic.
Dale Johannesena6f80ef2009-02-05 01:50:47 +0000419 const char *Name = getContext().BuiltinInfo.GetName(BuiltinID);
420 Intrinsic::ID IntrinsicID =
421 Intrinsic::getIntrinsicForGCCBuiltin(Target.getTargetPrefix(), Name);
Chris Lattnerb7cfe882008-06-30 18:32:54 +0000422
423 if (IntrinsicID != Intrinsic::not_intrinsic) {
424 SmallVector<Value*, 16> Args;
425
426 Function *F = CGM.getIntrinsic(IntrinsicID);
427 const llvm::FunctionType *FTy = F->getFunctionType();
428
429 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
430 Value *ArgValue = EmitScalarExpr(E->getArg(i));
431
432 // If the intrinsic arg type is different from the builtin arg type
433 // we need to do a bit cast.
434 const llvm::Type *PTy = FTy->getParamType(i);
435 if (PTy != ArgValue->getType()) {
436 assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) &&
437 "Must be able to losslessly bit cast to param");
438 ArgValue = Builder.CreateBitCast(ArgValue, PTy);
439 }
440
441 Args.push_back(ArgValue);
442 }
443
444 Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size());
445 QualType BuiltinRetType = E->getType();
446
447 const llvm::Type *RetTy = llvm::Type::VoidTy;
448 if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType);
449
450 if (RetTy != V->getType()) {
451 assert(V->getType()->canLosslesslyBitCastTo(RetTy) &&
452 "Must be able to losslessly bit cast result type");
453 V = Builder.CreateBitCast(V, RetTy);
454 }
455
456 return RValue::get(V);
457 }
458
459 // See if we have a target specific builtin that needs to be lowered.
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +0000460 if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E))
Chris Lattnerb7cfe882008-06-30 18:32:54 +0000461 return RValue::get(V);
462
Daniel Dunbar488e9932008-08-16 00:56:44 +0000463 ErrorUnsupported(E, "builtin function");
Chris Lattnerb7cfe882008-06-30 18:32:54 +0000464
465 // Unknown builtin, for now just dump it out and return undef.
466 if (hasAggregateLLVMType(E->getType()))
467 return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType())));
468 return RValue::get(UndefValue::get(ConvertType(E->getType())));
469}
Anders Carlsson564f1de2007-12-09 23:17:02 +0000470
Daniel Dunbarf02e9dd2008-10-10 00:24:54 +0000471Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID,
472 const CallExpr *E) {
473 const char *TargetPrefix = Target.getTargetPrefix();
474 if (strcmp(TargetPrefix, "x86") == 0)
475 return EmitX86BuiltinExpr(BuiltinID, E);
476 else if (strcmp(TargetPrefix, "ppc") == 0)
477 return EmitPPCBuiltinExpr(BuiltinID, E);
478 return 0;
479}
480
Chris Lattner1feedd82007-12-13 07:34:23 +0000481Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
482 const CallExpr *E) {
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000483
484 llvm::SmallVector<Value*, 4> Ops;
485
486 for (unsigned i = 0, e = E->getNumArgs(); i != e; i++)
487 Ops.push_back(EmitScalarExpr(E->getArg(i)));
488
Anders Carlsson564f1de2007-12-09 23:17:02 +0000489 switch (BuiltinID) {
Anders Carlsson46a26b02007-12-09 23:39:18 +0000490 default: return 0;
491 case X86::BI__builtin_ia32_mulps:
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000492 return Builder.CreateMul(Ops[0], Ops[1], "mulps");
Nate Begemane7722102008-04-14 04:49:57 +0000493 case X86::BI__builtin_ia32_mulpd:
494 return Builder.CreateMul(Ops[0], Ops[1], "mulpd");
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000495 case X86::BI__builtin_ia32_pand:
Nate Begemane7722102008-04-14 04:49:57 +0000496 case X86::BI__builtin_ia32_pand128:
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000497 return Builder.CreateAnd(Ops[0], Ops[1], "pand");
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000498 case X86::BI__builtin_ia32_por:
Nate Begemane7722102008-04-14 04:49:57 +0000499 case X86::BI__builtin_ia32_por128:
500 return Builder.CreateOr(Ops[0], Ops[1], "por");
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000501 case X86::BI__builtin_ia32_pxor:
Nate Begemane7722102008-04-14 04:49:57 +0000502 case X86::BI__builtin_ia32_pxor128:
503 return Builder.CreateXor(Ops[0], Ops[1], "pxor");
504 case X86::BI__builtin_ia32_pandn:
505 case X86::BI__builtin_ia32_pandn128:
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000506 Ops[0] = Builder.CreateNot(Ops[0], "tmp");
507 return Builder.CreateAnd(Ops[0], Ops[1], "pandn");
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000508 case X86::BI__builtin_ia32_paddb:
Nate Begemane7722102008-04-14 04:49:57 +0000509 case X86::BI__builtin_ia32_paddb128:
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000510 case X86::BI__builtin_ia32_paddd:
Nate Begemane7722102008-04-14 04:49:57 +0000511 case X86::BI__builtin_ia32_paddd128:
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000512 case X86::BI__builtin_ia32_paddq:
Nate Begemane7722102008-04-14 04:49:57 +0000513 case X86::BI__builtin_ia32_paddq128:
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000514 case X86::BI__builtin_ia32_paddw:
Nate Begemane7722102008-04-14 04:49:57 +0000515 case X86::BI__builtin_ia32_paddw128:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000516 case X86::BI__builtin_ia32_addps:
Nate Begemane7722102008-04-14 04:49:57 +0000517 case X86::BI__builtin_ia32_addpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000518 return Builder.CreateAdd(Ops[0], Ops[1], "add");
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000519 case X86::BI__builtin_ia32_psubb:
Nate Begemane7722102008-04-14 04:49:57 +0000520 case X86::BI__builtin_ia32_psubb128:
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000521 case X86::BI__builtin_ia32_psubd:
Nate Begemane7722102008-04-14 04:49:57 +0000522 case X86::BI__builtin_ia32_psubd128:
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000523 case X86::BI__builtin_ia32_psubq:
Nate Begemane7722102008-04-14 04:49:57 +0000524 case X86::BI__builtin_ia32_psubq128:
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000525 case X86::BI__builtin_ia32_psubw:
Nate Begemane7722102008-04-14 04:49:57 +0000526 case X86::BI__builtin_ia32_psubw128:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000527 case X86::BI__builtin_ia32_subps:
Nate Begemane7722102008-04-14 04:49:57 +0000528 case X86::BI__builtin_ia32_subpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000529 return Builder.CreateSub(Ops[0], Ops[1], "sub");
530 case X86::BI__builtin_ia32_divps:
531 return Builder.CreateFDiv(Ops[0], Ops[1], "divps");
Nate Begemane7722102008-04-14 04:49:57 +0000532 case X86::BI__builtin_ia32_divpd:
533 return Builder.CreateFDiv(Ops[0], Ops[1], "divpd");
Anders Carlssondb832302007-12-11 03:09:22 +0000534 case X86::BI__builtin_ia32_pmullw:
Nate Begemane7722102008-04-14 04:49:57 +0000535 case X86::BI__builtin_ia32_pmullw128:
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000536 return Builder.CreateMul(Ops[0], Ops[1], "pmul");
Anders Carlssondb832302007-12-11 03:09:22 +0000537 case X86::BI__builtin_ia32_punpckhbw:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000538 return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15,
Anders Carlssondb832302007-12-11 03:09:22 +0000539 "punpckhbw");
Nate Begemane7722102008-04-14 04:49:57 +0000540 case X86::BI__builtin_ia32_punpckhbw128:
541 return EmitShuffleVector(Ops[0], Ops[1], 8, 24, 9, 25, 10, 26, 11, 27,
542 12, 28, 13, 29, 14, 30, 15, 31,
543 "punpckhbw");
Anders Carlssondb832302007-12-11 03:09:22 +0000544 case X86::BI__builtin_ia32_punpckhwd:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000545 return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhwd");
Nate Begemane7722102008-04-14 04:49:57 +0000546 case X86::BI__builtin_ia32_punpckhwd128:
547 return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15,
548 "punpckhwd");
Anders Carlssondb832302007-12-11 03:09:22 +0000549 case X86::BI__builtin_ia32_punpckhdq:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000550 return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhdq");
Nate Begemane7722102008-04-14 04:49:57 +0000551 case X86::BI__builtin_ia32_punpckhdq128:
552 return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhdq");
Nate Begemanabfaf992008-07-25 20:17:24 +0000553 case X86::BI__builtin_ia32_punpckhqdq128:
554 return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhqdq");
Anders Carlssondb832302007-12-11 03:09:22 +0000555 case X86::BI__builtin_ia32_punpcklbw:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000556 return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11,
Anders Carlssondb832302007-12-11 03:09:22 +0000557 "punpcklbw");
558 case X86::BI__builtin_ia32_punpcklwd:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000559 return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpcklwd");
Anders Carlssondb832302007-12-11 03:09:22 +0000560 case X86::BI__builtin_ia32_punpckldq:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000561 return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpckldq");
Nate Begemane7722102008-04-14 04:49:57 +0000562 case X86::BI__builtin_ia32_punpckldq128:
563 return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpckldq");
Nate Begemanabfaf992008-07-25 20:17:24 +0000564 case X86::BI__builtin_ia32_punpcklqdq128:
565 return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpcklqdq");
Nate Begemane7722102008-04-14 04:49:57 +0000566 case X86::BI__builtin_ia32_pslldi128:
567 case X86::BI__builtin_ia32_psllqi128:
568 case X86::BI__builtin_ia32_psllwi128:
569 case X86::BI__builtin_ia32_psradi128:
570 case X86::BI__builtin_ia32_psrawi128:
571 case X86::BI__builtin_ia32_psrldi128:
572 case X86::BI__builtin_ia32_psrlqi128:
573 case X86::BI__builtin_ia32_psrlwi128: {
574 Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext");
575 const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2);
576 llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
577 Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty),
578 Ops[1], Zero, "insert");
579 Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast");
580 const char *name = 0;
581 Intrinsic::ID ID = Intrinsic::not_intrinsic;
582
583 switch (BuiltinID) {
584 default: assert(0 && "Unsupported shift intrinsic!");
585 case X86::BI__builtin_ia32_pslldi128:
586 name = "pslldi";
587 ID = Intrinsic::x86_sse2_psll_d;
588 break;
589 case X86::BI__builtin_ia32_psllqi128:
590 name = "psllqi";
591 ID = Intrinsic::x86_sse2_psll_q;
592 break;
593 case X86::BI__builtin_ia32_psllwi128:
594 name = "psllwi";
595 ID = Intrinsic::x86_sse2_psll_w;
596 break;
597 case X86::BI__builtin_ia32_psradi128:
598 name = "psradi";
599 ID = Intrinsic::x86_sse2_psra_d;
600 break;
601 case X86::BI__builtin_ia32_psrawi128:
602 name = "psrawi";
603 ID = Intrinsic::x86_sse2_psra_w;
604 break;
605 case X86::BI__builtin_ia32_psrldi128:
606 name = "psrldi";
607 ID = Intrinsic::x86_sse2_psrl_d;
608 break;
609 case X86::BI__builtin_ia32_psrlqi128:
610 name = "psrlqi";
611 ID = Intrinsic::x86_sse2_psrl_q;
612 break;
613 case X86::BI__builtin_ia32_psrlwi128:
614 name = "psrlwi";
615 ID = Intrinsic::x86_sse2_psrl_w;
616 break;
617 }
618 llvm::Function *F = CGM.getIntrinsic(ID);
619 return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
620 }
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000621 case X86::BI__builtin_ia32_pslldi:
622 case X86::BI__builtin_ia32_psllqi:
623 case X86::BI__builtin_ia32_psllwi:
624 case X86::BI__builtin_ia32_psradi:
625 case X86::BI__builtin_ia32_psrawi:
626 case X86::BI__builtin_ia32_psrldi:
627 case X86::BI__builtin_ia32_psrlqi:
628 case X86::BI__builtin_ia32_psrlwi: {
629 Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext");
630 const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1);
631 Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast");
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000632 const char *name = 0;
633 Intrinsic::ID ID = Intrinsic::not_intrinsic;
634
635 switch (BuiltinID) {
636 default: assert(0 && "Unsupported shift intrinsic!");
637 case X86::BI__builtin_ia32_pslldi:
638 name = "pslldi";
639 ID = Intrinsic::x86_mmx_psll_d;
640 break;
641 case X86::BI__builtin_ia32_psllqi:
642 name = "psllqi";
643 ID = Intrinsic::x86_mmx_psll_q;
644 break;
645 case X86::BI__builtin_ia32_psllwi:
646 name = "psllwi";
647 ID = Intrinsic::x86_mmx_psll_w;
648 break;
649 case X86::BI__builtin_ia32_psradi:
650 name = "psradi";
651 ID = Intrinsic::x86_mmx_psra_d;
652 break;
653 case X86::BI__builtin_ia32_psrawi:
654 name = "psrawi";
655 ID = Intrinsic::x86_mmx_psra_w;
656 break;
657 case X86::BI__builtin_ia32_psrldi:
658 name = "psrldi";
659 ID = Intrinsic::x86_mmx_psrl_d;
660 break;
661 case X86::BI__builtin_ia32_psrlqi:
662 name = "psrlqi";
663 ID = Intrinsic::x86_mmx_psrl_q;
664 break;
665 case X86::BI__builtin_ia32_psrlwi:
666 name = "psrlwi";
667 ID = Intrinsic::x86_mmx_psrl_w;
668 break;
669 }
Chris Lattner7acda7c2007-12-18 00:25:38 +0000670 llvm::Function *F = CGM.getIntrinsic(ID);
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000671 return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
672 }
Anders Carlsson4ee51b42008-12-22 04:54:32 +0000673 case X86::BI__builtin_ia32_pshufw: {
674 unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
675 return EmitShuffleVector(Ops[0], Ops[0],
676 i & 0x3, (i & 0xc) >> 2,
677 (i & 0x30) >> 4, (i & 0xc0) >> 6,
678 "pshufw");
679 }
Nate Begeman7ea2e3f2008-05-15 07:38:03 +0000680 case X86::BI__builtin_ia32_pshuflw: {
681 unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
682 return EmitShuffleVector(Ops[0], Ops[0],
683 i & 0x3, (i & 0xc) >> 2,
684 (i & 0x30) >> 4, (i & 0xc0) >> 6, 4, 5, 6, 7,
685 "pshuflw");
686 }
687 case X86::BI__builtin_ia32_pshufhw: {
688 unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
689 return EmitShuffleVector(Ops[0], Ops[0], 0, 1, 2, 3,
690 4 + (i & 0x3), 4 + ((i & 0xc) >> 2),
691 4 + ((i & 0x30) >> 4), 4 + ((i & 0xc0) >> 6),
692 "pshufhw");
693 }
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000694 case X86::BI__builtin_ia32_pshufd: {
Chris Lattner7acda7c2007-12-18 00:25:38 +0000695 unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
Anders Carlsson2929cfa2007-12-14 17:48:24 +0000696 return EmitShuffleVector(Ops[0], Ops[0],
Anders Carlsson4e4ee212007-12-11 02:25:54 +0000697 i & 0x3, (i & 0xc) >> 2,
698 (i & 0x30) >> 4, (i & 0xc0) >> 6,
699 "pshufd");
700 }
Anders Carlsson6086bbd2007-12-15 21:23:30 +0000701 case X86::BI__builtin_ia32_vec_init_v4hi:
702 case X86::BI__builtin_ia32_vec_init_v8qi:
703 case X86::BI__builtin_ia32_vec_init_v2si:
704 return EmitVector(&Ops[0], Ops.size());
705 case X86::BI__builtin_ia32_vec_ext_v2si:
Nate Begemane7722102008-04-14 04:49:57 +0000706 case X86::BI__builtin_ia32_vec_ext_v2di:
707 case X86::BI__builtin_ia32_vec_ext_v4sf:
708 case X86::BI__builtin_ia32_vec_ext_v4si:
Nate Begeman6fe7c8a2009-01-18 06:42:49 +0000709 case X86::BI__builtin_ia32_vec_ext_v8hi:
710 case X86::BI__builtin_ia32_vec_ext_v4hi:
Nate Begemane7722102008-04-14 04:49:57 +0000711 case X86::BI__builtin_ia32_vec_ext_v2df:
Anders Carlsson6086bbd2007-12-15 21:23:30 +0000712 return Builder.CreateExtractElement(Ops[0], Ops[1], "result");
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000713 case X86::BI__builtin_ia32_cmpordss:
Nate Begemane7722102008-04-14 04:49:57 +0000714 case X86::BI__builtin_ia32_cmpordsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000715 case X86::BI__builtin_ia32_cmpunordss:
Nate Begemane7722102008-04-14 04:49:57 +0000716 case X86::BI__builtin_ia32_cmpunordsd:
717 case X86::BI__builtin_ia32_cmpeqss:
718 case X86::BI__builtin_ia32_cmpeqsd:
719 case X86::BI__builtin_ia32_cmpltss:
720 case X86::BI__builtin_ia32_cmpltsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000721 case X86::BI__builtin_ia32_cmpless:
Nate Begemane7722102008-04-14 04:49:57 +0000722 case X86::BI__builtin_ia32_cmplesd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000723 case X86::BI__builtin_ia32_cmpneqss:
Nate Begemane7722102008-04-14 04:49:57 +0000724 case X86::BI__builtin_ia32_cmpneqsd:
725 case X86::BI__builtin_ia32_cmpnltss:
726 case X86::BI__builtin_ia32_cmpnltsd:
727 case X86::BI__builtin_ia32_cmpnless:
728 case X86::BI__builtin_ia32_cmpnlesd: {
Chris Lattner7acda7c2007-12-18 00:25:38 +0000729 unsigned i = 0;
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000730 const char *name = 0;
731 switch (BuiltinID) {
732 default: assert(0 && "Unknown compare builtin!");
733 case X86::BI__builtin_ia32_cmpeqss:
Nate Begemane7722102008-04-14 04:49:57 +0000734 case X86::BI__builtin_ia32_cmpeqsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000735 i = 0;
Nate Begemane7722102008-04-14 04:49:57 +0000736 name = "cmpeq";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000737 break;
738 case X86::BI__builtin_ia32_cmpltss:
Nate Begemane7722102008-04-14 04:49:57 +0000739 case X86::BI__builtin_ia32_cmpltsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000740 i = 1;
Nate Begemane7722102008-04-14 04:49:57 +0000741 name = "cmplt";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000742 break;
743 case X86::BI__builtin_ia32_cmpless:
Nate Begemane7722102008-04-14 04:49:57 +0000744 case X86::BI__builtin_ia32_cmplesd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000745 i = 2;
Nate Begemane7722102008-04-14 04:49:57 +0000746 name = "cmple";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000747 break;
748 case X86::BI__builtin_ia32_cmpunordss:
Nate Begemane7722102008-04-14 04:49:57 +0000749 case X86::BI__builtin_ia32_cmpunordsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000750 i = 3;
Nate Begemane7722102008-04-14 04:49:57 +0000751 name = "cmpunord";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000752 break;
753 case X86::BI__builtin_ia32_cmpneqss:
Nate Begemane7722102008-04-14 04:49:57 +0000754 case X86::BI__builtin_ia32_cmpneqsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000755 i = 4;
Nate Begemane7722102008-04-14 04:49:57 +0000756 name = "cmpneq";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000757 break;
758 case X86::BI__builtin_ia32_cmpnltss:
Nate Begemane7722102008-04-14 04:49:57 +0000759 case X86::BI__builtin_ia32_cmpnltsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000760 i = 5;
Nate Begemane7722102008-04-14 04:49:57 +0000761 name = "cmpntl";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000762 break;
763 case X86::BI__builtin_ia32_cmpnless:
Nate Begemane7722102008-04-14 04:49:57 +0000764 case X86::BI__builtin_ia32_cmpnlesd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000765 i = 6;
Nate Begemane7722102008-04-14 04:49:57 +0000766 name = "cmpnle";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000767 break;
768 case X86::BI__builtin_ia32_cmpordss:
Nate Begemane7722102008-04-14 04:49:57 +0000769 case X86::BI__builtin_ia32_cmpordsd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000770 i = 7;
Nate Begemane7722102008-04-14 04:49:57 +0000771 name = "cmpord";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000772 break;
773 }
774
Nate Begemane7722102008-04-14 04:49:57 +0000775 llvm::Function *F;
776 if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() ==
777 llvm::Type::FloatTy)
778 F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss);
779 else
780 F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd);
781
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000782 Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i));
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000783 return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
784 }
Nate Begemane7722102008-04-14 04:49:57 +0000785 case X86::BI__builtin_ia32_ldmxcsr: {
786 llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
787 Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
788 Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp");
Nate Begemane7722102008-04-14 04:49:57 +0000789 Builder.CreateStore(Ops[0], Tmp);
790 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr),
Chris Lattner3eae03e2008-05-06 00:56:42 +0000791 Builder.CreateBitCast(Tmp, PtrTy));
Nate Begemane7722102008-04-14 04:49:57 +0000792 }
793 case X86::BI__builtin_ia32_stmxcsr: {
794 llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
795 Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
796 Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp");
Nate Begemane7722102008-04-14 04:49:57 +0000797 One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr),
Chris Lattner3eae03e2008-05-06 00:56:42 +0000798 Builder.CreateBitCast(Tmp, PtrTy));
Nate Begemane7722102008-04-14 04:49:57 +0000799 return Builder.CreateLoad(Tmp, "stmxcsr");
800 }
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000801 case X86::BI__builtin_ia32_cmpordps:
Nate Begemane7722102008-04-14 04:49:57 +0000802 case X86::BI__builtin_ia32_cmpordpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000803 case X86::BI__builtin_ia32_cmpunordps:
Nate Begemane7722102008-04-14 04:49:57 +0000804 case X86::BI__builtin_ia32_cmpunordpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000805 case X86::BI__builtin_ia32_cmpeqps:
Nate Begemane7722102008-04-14 04:49:57 +0000806 case X86::BI__builtin_ia32_cmpeqpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000807 case X86::BI__builtin_ia32_cmpltps:
Nate Begemane7722102008-04-14 04:49:57 +0000808 case X86::BI__builtin_ia32_cmpltpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000809 case X86::BI__builtin_ia32_cmpleps:
Nate Begemane7722102008-04-14 04:49:57 +0000810 case X86::BI__builtin_ia32_cmplepd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000811 case X86::BI__builtin_ia32_cmpneqps:
Nate Begemane7722102008-04-14 04:49:57 +0000812 case X86::BI__builtin_ia32_cmpneqpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000813 case X86::BI__builtin_ia32_cmpngtps:
Nate Begemane7722102008-04-14 04:49:57 +0000814 case X86::BI__builtin_ia32_cmpngtpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000815 case X86::BI__builtin_ia32_cmpnltps:
Nate Begemane7722102008-04-14 04:49:57 +0000816 case X86::BI__builtin_ia32_cmpnltpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000817 case X86::BI__builtin_ia32_cmpgtps:
Nate Begemane7722102008-04-14 04:49:57 +0000818 case X86::BI__builtin_ia32_cmpgtpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000819 case X86::BI__builtin_ia32_cmpgeps:
Nate Begemane7722102008-04-14 04:49:57 +0000820 case X86::BI__builtin_ia32_cmpgepd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000821 case X86::BI__builtin_ia32_cmpngeps:
Nate Begemane7722102008-04-14 04:49:57 +0000822 case X86::BI__builtin_ia32_cmpngepd:
823 case X86::BI__builtin_ia32_cmpnleps:
824 case X86::BI__builtin_ia32_cmpnlepd: {
Chris Lattner7acda7c2007-12-18 00:25:38 +0000825 unsigned i = 0;
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000826 const char *name = 0;
827 bool ShouldSwap = false;
828 switch (BuiltinID) {
829 default: assert(0 && "Unknown compare builtin!");
Nate Begemane7722102008-04-14 04:49:57 +0000830 case X86::BI__builtin_ia32_cmpeqps:
831 case X86::BI__builtin_ia32_cmpeqpd: i = 0; name = "cmpeq"; break;
832 case X86::BI__builtin_ia32_cmpltps:
833 case X86::BI__builtin_ia32_cmpltpd: i = 1; name = "cmplt"; break;
834 case X86::BI__builtin_ia32_cmpleps:
835 case X86::BI__builtin_ia32_cmplepd: i = 2; name = "cmple"; break;
836 case X86::BI__builtin_ia32_cmpunordps:
837 case X86::BI__builtin_ia32_cmpunordpd: i = 3; name = "cmpunord"; break;
838 case X86::BI__builtin_ia32_cmpneqps:
839 case X86::BI__builtin_ia32_cmpneqpd: i = 4; name = "cmpneq"; break;
840 case X86::BI__builtin_ia32_cmpnltps:
841 case X86::BI__builtin_ia32_cmpnltpd: i = 5; name = "cmpntl"; break;
842 case X86::BI__builtin_ia32_cmpnleps:
843 case X86::BI__builtin_ia32_cmpnlepd: i = 6; name = "cmpnle"; break;
844 case X86::BI__builtin_ia32_cmpordps:
845 case X86::BI__builtin_ia32_cmpordpd: i = 7; name = "cmpord"; break;
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000846 case X86::BI__builtin_ia32_cmpgtps:
Nate Begemane7722102008-04-14 04:49:57 +0000847 case X86::BI__builtin_ia32_cmpgtpd:
Chris Lattner7acda7c2007-12-18 00:25:38 +0000848 ShouldSwap = true;
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000849 i = 1;
Nate Begemane7722102008-04-14 04:49:57 +0000850 name = "cmpgt";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000851 break;
852 case X86::BI__builtin_ia32_cmpgeps:
Nate Begemane7722102008-04-14 04:49:57 +0000853 case X86::BI__builtin_ia32_cmpgepd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000854 i = 2;
Nate Begemane7722102008-04-14 04:49:57 +0000855 name = "cmpge";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000856 ShouldSwap = true;
857 break;
858 case X86::BI__builtin_ia32_cmpngtps:
Nate Begemane7722102008-04-14 04:49:57 +0000859 case X86::BI__builtin_ia32_cmpngtpd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000860 i = 5;
Nate Begemane7722102008-04-14 04:49:57 +0000861 name = "cmpngt";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000862 ShouldSwap = true;
863 break;
864 case X86::BI__builtin_ia32_cmpngeps:
Nate Begemane7722102008-04-14 04:49:57 +0000865 case X86::BI__builtin_ia32_cmpngepd:
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000866 i = 6;
Nate Begemane7722102008-04-14 04:49:57 +0000867 name = "cmpnge";
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000868 ShouldSwap = true;
869 break;
870 }
871
872 if (ShouldSwap)
873 std::swap(Ops[0], Ops[1]);
Nate Begemane7722102008-04-14 04:49:57 +0000874
875 llvm::Function *F;
876 if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() ==
877 llvm::Type::FloatTy)
878 F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps);
879 else
880 F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd);
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000881
882 Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i));
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000883 return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
884 }
885 case X86::BI__builtin_ia32_movss:
886 return EmitShuffleVector(Ops[0], Ops[1], 4, 1, 2, 3, "movss");
Torok Edwin730f2c12008-04-04 06:16:25 +0000887 case X86::BI__builtin_ia32_shufps: {
Chris Lattner7acda7c2007-12-18 00:25:38 +0000888 unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue();
Anders Carlssoncc8b7f92007-12-16 22:33:50 +0000889 return EmitShuffleVector(Ops[0], Ops[1],
890 i & 0x3, (i & 0xc) >> 2,
891 ((i & 0x30) >> 4) + 4,
Mon P Wang09b6bf52008-06-25 08:21:36 +0000892 ((i & 0xc0) >> 6) + 4, "shufps");
Torok Edwin730f2c12008-04-04 06:16:25 +0000893 }
Mon P Wang6c5df7f2008-07-18 00:14:09 +0000894 case X86::BI__builtin_ia32_shufpd: {
895 unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue();
Chris Lattnerf29c8ad2009-04-18 07:01:54 +0000896 return EmitShuffleVector(Ops[0], Ops[1], i & 1,
897 ((i & 2) >> 1)+2, "shufpd");
Mon P Wang6c5df7f2008-07-18 00:14:09 +0000898 }
Nate Begemandbebb732008-04-03 19:58:06 +0000899 case X86::BI__builtin_ia32_punpcklbw128:
900 return EmitShuffleVector(Ops[0], Ops[1], 0, 16, 1, 17, 2, 18, 3, 19,
901 4, 20, 5, 21, 6, 22, 7, 23,
902 "punpcklbw");
903 case X86::BI__builtin_ia32_punpcklwd128:
904 return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11,
905 "punpcklwd");
Nate Begemane7722102008-04-14 04:49:57 +0000906 case X86::BI__builtin_ia32_movlhps:
907 return EmitShuffleVector(Ops[0], Ops[1], 0, 1, 4, 5, "movlhps");
908 case X86::BI__builtin_ia32_movhlps:
909 return EmitShuffleVector(Ops[0], Ops[1], 6, 7, 2, 3, "movhlps");
910 case X86::BI__builtin_ia32_unpckhps:
911 return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "unpckhps");
912 case X86::BI__builtin_ia32_unpcklps:
913 return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "unpcklps");
Nate Begemanabfaf992008-07-25 20:17:24 +0000914 case X86::BI__builtin_ia32_unpckhpd:
915 return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "unpckhpd");
916 case X86::BI__builtin_ia32_unpcklpd:
917 return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "unpcklpd");
918 case X86::BI__builtin_ia32_movsd:
919 return EmitShuffleVector(Ops[0], Ops[1], 2, 1, "movsd");
Nate Begemane7722102008-04-14 04:49:57 +0000920 case X86::BI__builtin_ia32_movqv4si: {
921 llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2);
922 return Builder.CreateBitCast(Ops[0], Ty);
923 }
924 case X86::BI__builtin_ia32_loadlps:
925 case X86::BI__builtin_ia32_loadhps: {
926 // FIXME: This should probably be represented as
927 // shuffle (dst, (v4f32 (insert undef, (load i64), 0)), shuf mask hi/lo)
928 const llvm::Type *EltTy = llvm::Type::DoubleTy;
929 const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
930 const llvm::Type *OrigTy = Ops[0]->getType();
931 unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlps ? 0 : 1;
932 llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index);
933 Ops[1] = Builder.CreateBitCast(Ops[1], llvm::PointerType::getUnqual(EltTy));
934 Ops[1] = Builder.CreateLoad(Ops[1], "tmp");
935 Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast");
936 Ops[0] = Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadps");
937 return Builder.CreateBitCast(Ops[0], OrigTy, "loadps");
938 }
Mon P Wang7f57b002008-09-30 05:31:27 +0000939 case X86::BI__builtin_ia32_loadlpd:
940 case X86::BI__builtin_ia32_loadhpd: {
941 Ops[1] = Builder.CreateLoad(Ops[1], "tmp");
942 unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlpd ? 0 : 1;
943 llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index);
944 return Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadpd");
945 }
Nate Begemane7722102008-04-14 04:49:57 +0000946 case X86::BI__builtin_ia32_storehps:
947 case X86::BI__builtin_ia32_storelps: {
948 const llvm::Type *EltTy = llvm::Type::Int64Ty;
949 llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy);
950 llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
951
952 // cast val v2i64
953 Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast");
954
955 // extract (0, 1)
956 unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1;
957 llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index);
958 Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract");
959
960 // cast pointer to i64 & store
961 Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy);
962 return Builder.CreateStore(Ops[1], Ops[0]);
963 }
964 case X86::BI__builtin_ia32_loadlv4si: {
965 // load i64
966 const llvm::Type *EltTy = llvm::Type::Int64Ty;
967 llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy);
968 Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy);
969 Ops[0] = Builder.CreateLoad(Ops[0], "load");
970
971 // scalar to vector: insert i64 into 2 x i64 undef
972 llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
973 llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
974 Ops[0] = Builder.CreateInsertElement(llvm::UndefValue::get(VecTy),
975 Ops[0], Zero, "s2v");
976
977 // shuffle into zero vector.
978 std::vector<llvm::Constant *>Elts;
979 Elts.resize(2, llvm::ConstantInt::get(EltTy, 0));
980 llvm::Value *ZV = ConstantVector::get(Elts);
981 Ops[0] = EmitShuffleVector(ZV, Ops[0], 2, 1, "loadl");
982
983 // bitcast to result.
984 return Builder.CreateBitCast(Ops[0],
985 llvm::VectorType::get(llvm::Type::Int32Ty, 4));
986 }
Nate Begeman24512502008-05-16 18:59:42 +0000987 case X86::BI__builtin_ia32_vec_set_v4hi:
988 case X86::BI__builtin_ia32_vec_set_v8hi:
989 return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrw");
Mon P Wangbc4f4032008-10-15 06:18:34 +0000990 case X86::BI__builtin_ia32_vec_set_v4si:
991 return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrd");
992 case X86::BI__builtin_ia32_vec_set_v2di:
993 return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrq");
Nate Begemane7722102008-04-14 04:49:57 +0000994 case X86::BI__builtin_ia32_andps:
995 case X86::BI__builtin_ia32_andpd:
996 case X86::BI__builtin_ia32_andnps:
997 case X86::BI__builtin_ia32_andnpd:
998 case X86::BI__builtin_ia32_orps:
999 case X86::BI__builtin_ia32_orpd:
1000 case X86::BI__builtin_ia32_xorpd:
1001 case X86::BI__builtin_ia32_xorps: {
1002 const llvm::Type *ITy = llvm::VectorType::get(llvm::Type::Int32Ty, 4);
1003 const llvm::Type *FTy = Ops[0]->getType();
1004 Ops[0] = Builder.CreateBitCast(Ops[0], ITy, "bitcast");
1005 Ops[1] = Builder.CreateBitCast(Ops[1], ITy, "bitcast");
1006 switch (BuiltinID) {
1007 case X86::BI__builtin_ia32_andps:
1008 Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andps");
1009 break;
1010 case X86::BI__builtin_ia32_andpd:
1011 Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andpd");
1012 break;
1013 case X86::BI__builtin_ia32_andnps:
1014 Ops[0] = Builder.CreateNot(Ops[0], "not");
1015 Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnps");
1016 break;
1017 case X86::BI__builtin_ia32_andnpd:
1018 Ops[0] = Builder.CreateNot(Ops[0], "not");
1019 Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnpd");
1020 break;
1021 case X86::BI__builtin_ia32_orps:
1022 Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orps");
1023 break;
1024 case X86::BI__builtin_ia32_orpd:
1025 Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orpd");
1026 break;
1027 case X86::BI__builtin_ia32_xorps:
1028 Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorps");
1029 break;
1030 case X86::BI__builtin_ia32_xorpd:
1031 Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorpd");
1032 break;
1033 }
1034 return Builder.CreateBitCast(Ops[0], FTy, "bitcast");
1035 }
Anders Carlsson564f1de2007-12-09 23:17:02 +00001036 }
1037}
1038
Chris Lattner1feedd82007-12-13 07:34:23 +00001039Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
1040 const CallExpr *E) {
Anders Carlsson564f1de2007-12-09 23:17:02 +00001041 switch (BuiltinID) {
Anders Carlsson46a26b02007-12-09 23:39:18 +00001042 default: return 0;
Anders Carlsson564f1de2007-12-09 23:17:02 +00001043 }
1044}