CGBuiltin.cpp revision eebd9d2165a705ce6a8a6b6a7327864189d02785
1022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// 2022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// 3022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// The LLVM Compiler Infrastructure 4022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 7022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// 8022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson//===----------------------------------------------------------------------===// 9022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// 10022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// This contains code to emit Builtin calls as LLVM code. 11022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson// 12022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson//===----------------------------------------------------------------------===// 13022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson 14022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson#include "CodeGenFunction.h" 15022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson#include "CodeGenModule.h" 16ca6fcfad547dcec3fdd17790b4fab0918df74b37Anders Carlsson#include "clang/Basic/TargetInfo.h" 171f32999ec79a980576e100d64d5f3267eb19ea49Chris Lattner#include "clang/AST/APValue.h" 18bef20ac367a09555b30d6eb3847a81ec164caf88Chris Lattner#include "clang/AST/ASTContext.h" 19c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Decl.h" 20564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson#include "clang/AST/TargetBuiltins.h" 21793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson#include "llvm/Intrinsics.h" 22022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlssonusing namespace clang; 23022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlssonusing namespace CodeGen; 24ca6fcfad547dcec3fdd17790b4fab0918df74b37Anders Carlssonusing namespace llvm; 25ca6fcfad547dcec3fdd17790b4fab0918df74b37Anders Carlsson 260002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar/// Utility to insert an atomic instruction based on Instrinsic::ID 270002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar/// and the expression node. 280002d23aaf10f307273dab5facda01c137283d22Daniel Dunbarstatic RValue EmitBinaryAtomic(CodeGenFunction& CGF, 291ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Intrinsic::ID Id, const CallExpr *E) { 30c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang const llvm::Type *ResType[2]; 310002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar ResType[0] = CGF.ConvertType(E->getType()); 320002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar ResType[1] = CGF.ConvertType(E->getArg(0)->getType()); 330002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *AtomF = CGF.CGM.getIntrinsic(Id, ResType, 2); 340002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return RValue::get(CGF.Builder.CreateCall2(AtomF, 350002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar CGF.EmitScalarExpr(E->getArg(0)), 360002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar CGF.EmitScalarExpr(E->getArg(1)))); 370002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar} 380002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar 390002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar/// Utility to insert an atomic instruction based Instrinsic::ID and 400002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar// the expression node, where the return value is the result of the 410002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar// operation. 420002d23aaf10f307273dab5facda01c137283d22Daniel Dunbarstatic RValue EmitBinaryAtomicPost(CodeGenFunction& CGF, 430002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Intrinsic::ID Id, const CallExpr *E, 440002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Instruction::BinaryOps Op) { 450002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar const llvm::Type *ResType[2]; 460002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar ResType[0] = CGF.ConvertType(E->getType()); 470002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar ResType[1] = CGF.ConvertType(E->getArg(0)->getType()); 480002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *AtomF = CGF.CGM.getIntrinsic(Id, ResType, 2); 490002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *Ptr = CGF.EmitScalarExpr(E->getArg(0)); 500002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *Operand = CGF.EmitScalarExpr(E->getArg(1)); 510002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *Result = CGF.Builder.CreateCall2(AtomF, Ptr, Operand); 52eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner 53eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner if (Id == Intrinsic::atomic_load_nand) 54eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner Result = CGF.Builder.CreateNot(Result); 55eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner 56eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner 570002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return RValue::get(CGF.Builder.CreateBinOp(Op, Result, Operand)); 581ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang} 591ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang 60ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel DunbarRValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, 61ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar unsigned BuiltinID, const CallExpr *E) { 62564ea2a99b3afeac9ded332730a56db1f6358a58Chris Lattner // See if we can constant fold this builtin. If so, don't emit it at all. 63f35d35a2316dcb65d078844696c2032b71a7f103Anders Carlsson Expr::EvalResult Result; 646ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner if (E->Evaluate(Result, CGM.getContext())) { 65f35d35a2316dcb65d078844696c2032b71a7f103Anders Carlsson if (Result.Val.isInt()) 66f35d35a2316dcb65d078844696c2032b71a7f103Anders Carlsson return RValue::get(llvm::ConstantInt::get(Result.Val.getInt())); 673941b18b8e441c8c466efecd557de60b9a32d10bEli Friedman else if (Result.Val.isFloat()) 683941b18b8e441c8c466efecd557de60b9a32d10bEli Friedman return RValue::get(llvm::ConstantFP::get(Result.Val.getFloat())); 691f32999ec79a980576e100d64d5f3267eb19ea49Chris Lattner } 701f32999ec79a980576e100d64d5f3267eb19ea49Chris Lattner 71564ea2a99b3afeac9ded332730a56db1f6358a58Chris Lattner switch (BuiltinID) { 72564ea2a99b3afeac9ded332730a56db1f6358a58Chris Lattner default: break; // Handle intrinsics and libm functions below. 73506ff88f44562df267b6a06608ab841b76df2a2bChris Lattner case Builtin::BI__builtin___CFStringMakeConstantString: 74e9352cc9818ba59e7cf88500ef048991c90f3821Anders Carlsson return RValue::get(CGM.EmitConstantExpr(E, E->getType(), 0)); 756a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner case Builtin::BI__builtin_stdarg_start: 76793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson case Builtin::BI__builtin_va_start: 77793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson case Builtin::BI__builtin_va_end: { 780785570af3ef5f8c5a0377129e41efe6f3f8d770Daniel Dunbar Value *ArgValue = EmitVAListRef(E->getArg(0)); 79ddc23f3e6fdc4f83dd46ef7e20394cfbd6063ff9Christopher Lamb const llvm::Type *DestType = 80ddc23f3e6fdc4f83dd46ef7e20394cfbd6063ff9Christopher Lamb llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 81793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson if (ArgValue->getType() != DestType) 82793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson ArgValue = Builder.CreateBitCast(ArgValue, DestType, 83793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson ArgValue->getNameStart()); 84793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson 856a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ? 866a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner Intrinsic::vaend : Intrinsic::vastart; 877acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); 88793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson } 89a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson case Builtin::BI__builtin_va_copy: { 904fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman Value *DstPtr = EmitVAListRef(E->getArg(0)); 914fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman Value *SrcPtr = EmitVAListRef(E->getArg(1)); 92a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 93a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson const llvm::Type *Type = 94a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 95a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 96a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson DstPtr = Builder.CreateBitCast(DstPtr, Type); 97a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson SrcPtr = Builder.CreateBitCast(SrcPtr, Type); 983eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), 993eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner DstPtr, SrcPtr)); 100a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson } 101c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson case Builtin::BI__builtin_abs: { 1021feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 103c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson 1049a847f598c4907a72b8593b364b9e6b94b086e75Chris Lattner Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); 1051feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *CmpResult = 1069a847f598c4907a72b8593b364b9e6b94b086e75Chris Lattner Builder.CreateICmpSGE(ArgValue, Constant::getNullValue(ArgValue->getType()), 1079a847f598c4907a72b8593b364b9e6b94b086e75Chris Lattner "abscond"); 1081feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *Result = 109c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); 110c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson 111c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson return RValue::get(Result); 112c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson } 1133a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctz: 1143a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctzl: 1153a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctzll: { 1163a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *ArgValue = EmitScalarExpr(E->getArg(0)); 1173a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson 1183a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson const llvm::Type *ArgType = ArgValue->getType(); 1193a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); 1203a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson 1213a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson const llvm::Type *ResultType = ConvertType(E->getType()); 1223a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 1233a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson if (Result->getType() != ResultType) 1243a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Result = Builder.CreateIntCast(Result, ResultType, "cast"); 1253a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson return RValue::get(Result); 1263a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson } 127f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clz: 128f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clzl: 129f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clzll: { 130f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *ArgValue = EmitScalarExpr(E->getArg(0)); 131f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman 132f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman const llvm::Type *ArgType = ArgValue->getType(); 133f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1); 134f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman 135f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman const llvm::Type *ResultType = ConvertType(E->getType()); 136f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 137f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman if (Result->getType() != ResultType) 138f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Result = Builder.CreateIntCast(Result, ResultType, "cast"); 139f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman return RValue::get(Result); 140f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman } 14104b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_ffs: 14204b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_ffsl: 14304b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_ffsll: { 14404b290030eee33295600728450f348989d1a627eDaniel Dunbar // ffs(x) -> x ? cttz(x) + 1 : 0 14504b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *ArgValue = EmitScalarExpr(E->getArg(0)); 14604b290030eee33295600728450f348989d1a627eDaniel Dunbar 14704b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ArgType = ArgValue->getType(); 14804b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); 14904b290030eee33295600728450f348989d1a627eDaniel Dunbar 15004b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ResultType = ConvertType(E->getType()); 15104b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Tmp = Builder.CreateAdd(Builder.CreateCall(F, ArgValue, "tmp"), 15204b290030eee33295600728450f348989d1a627eDaniel Dunbar ConstantInt::get(ArgType, 1), "tmp"); 15304b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Zero = llvm::Constant::getNullValue(ArgType); 15404b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); 15504b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); 15604b290030eee33295600728450f348989d1a627eDaniel Dunbar if (Result->getType() != ResultType) 15704b290030eee33295600728450f348989d1a627eDaniel Dunbar Result = Builder.CreateIntCast(Result, ResultType, "cast"); 15804b290030eee33295600728450f348989d1a627eDaniel Dunbar return RValue::get(Result); 15904b290030eee33295600728450f348989d1a627eDaniel Dunbar } 16004b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_parity: 16104b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_parityl: 16204b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_parityll: { 16304b290030eee33295600728450f348989d1a627eDaniel Dunbar // parity(x) -> ctpop(x) & 1 16404b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *ArgValue = EmitScalarExpr(E->getArg(0)); 16504b290030eee33295600728450f348989d1a627eDaniel Dunbar 16604b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ArgType = ArgValue->getType(); 16704b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); 16804b290030eee33295600728450f348989d1a627eDaniel Dunbar 16904b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ResultType = ConvertType(E->getType()); 17004b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Tmp = Builder.CreateCall(F, ArgValue, "tmp"); 17104b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Result = Builder.CreateAnd(Tmp, ConstantInt::get(ArgType, 1), 17204b290030eee33295600728450f348989d1a627eDaniel Dunbar "tmp"); 17304b290030eee33295600728450f348989d1a627eDaniel Dunbar if (Result->getType() != ResultType) 17404b290030eee33295600728450f348989d1a627eDaniel Dunbar Result = Builder.CreateIntCast(Result, ResultType, "cast"); 17504b290030eee33295600728450f348989d1a627eDaniel Dunbar return RValue::get(Result); 17604b290030eee33295600728450f348989d1a627eDaniel Dunbar } 17704b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_popcount: 17804b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_popcountl: 17904b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_popcountll: { 18004b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *ArgValue = EmitScalarExpr(E->getArg(0)); 18104b290030eee33295600728450f348989d1a627eDaniel Dunbar 18204b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ArgType = ArgValue->getType(); 18304b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); 18404b290030eee33295600728450f348989d1a627eDaniel Dunbar 18504b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ResultType = ConvertType(E->getType()); 18604b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 18704b290030eee33295600728450f348989d1a627eDaniel Dunbar if (Result->getType() != ResultType) 18804b290030eee33295600728450f348989d1a627eDaniel Dunbar Result = Builder.CreateIntCast(Result, ResultType, "cast"); 18904b290030eee33295600728450f348989d1a627eDaniel Dunbar return RValue::get(Result); 19004b290030eee33295600728450f348989d1a627eDaniel Dunbar } 1911feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner case Builtin::BI__builtin_expect: 192a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar // FIXME: pass expect through to LLVM 1931feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(EmitScalarExpr(E->getArg(0))); 194df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson case Builtin::BI__builtin_bswap32: 195df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson case Builtin::BI__builtin_bswap64: { 1961feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 197df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson const llvm::Type *ArgType = ArgValue->getType(); 1987acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1); 1991feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); 2004493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar } 201d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar case Builtin::BI__builtin_object_size: { 202d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar // FIXME: Implement. For now we just always fail and pretend we 203d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar // don't know the object size. 2049a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman llvm::APSInt TypeArg = E->getArg(1)->EvaluateAsInt(CGM.getContext()); 205d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar const llvm::Type *ResType = ConvertType(E->getType()); 206d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar // bool UseSubObject = TypeArg.getZExtValue() & 1; 207d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar bool UseMinimum = TypeArg.getZExtValue() & 2; 208d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar return RValue::get(ConstantInt::get(ResType, UseMinimum ? 0 : -1LL)); 209d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar } 2104493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar case Builtin::BI__builtin_prefetch: { 2114493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); 2124493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar // FIXME: Technically these constants should of type 'int', yes? 2134493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : 2144493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar ConstantInt::get(llvm::Type::Int32Ty, 0); 2154493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : 2164493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar ConstantInt::get(llvm::Type::Int32Ty, 3); 2174493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); 2184493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); 2194493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar } 2204493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar case Builtin::BI__builtin_trap: { 2214493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0); 2224493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar return RValue::get(Builder.CreateCall(F)); 223df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson } 2244493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar 225a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar case Builtin::BI__builtin_powi: 226a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar case Builtin::BI__builtin_powif: 227a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar case Builtin::BI__builtin_powil: { 228a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar Value *Base = EmitScalarExpr(E->getArg(0)); 229a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar Value *Exponent = EmitScalarExpr(E->getArg(1)); 230a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar const llvm::Type *ArgType = Base->getType(); 231a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1); 232a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); 233a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar } 234a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar 235fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreater: 236fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreaterequal: 237fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isless: 238fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessequal: 239fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessgreater: 240fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isunordered: { 241fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // Ordered comparisons: we know the arguments to these are matching scalar 242fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // floating point values. 243fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner Value *LHS = EmitScalarExpr(E->getArg(0)); 244fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner Value *RHS = EmitScalarExpr(E->getArg(1)); 245fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner 246fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner switch (BuiltinID) { 247fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner default: assert(0 && "Unknown ordered comparison"); 248fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreater: 249fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); 250fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 251fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreaterequal: 252fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); 253fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 254fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isless: 255fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); 256fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 257fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessequal: 258fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); 259fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 260fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessgreater: 261fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); 262fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 263fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isunordered: 264fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); 265fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 266fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner } 267fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // ZExt bool to int type. 268fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()), 269fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner "tmp")); 270fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner } 2719e800e3dd80d77f6c47054738177bf824089f55aChris Lattner case Builtin::BI__builtin_alloca: { 2729e800e3dd80d77f6c47054738177bf824089f55aChris Lattner // FIXME: LLVM IR Should allow alloca with an i64 size! 2739e800e3dd80d77f6c47054738177bf824089f55aChris Lattner Value *Size = EmitScalarExpr(E->getArg(0)); 2749e800e3dd80d77f6c47054738177bf824089f55aChris Lattner Size = Builder.CreateIntCast(Size, llvm::Type::Int32Ty, false, "tmp"); 2751caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size, "tmp")); 2761caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar } 2771caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar case Builtin::BI__builtin_bzero: { 2781caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2791caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemSetFn(), Address, 2801caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int8Ty, 0), 2811caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2821caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2831caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 2849e800e3dd80d77f6c47054738177bf824089f55aChris Lattner } 285d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman case Builtin::BI__builtin_memcpy: { 2861caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2871caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemCpyFn(), Address, 2881caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2891caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(2)), 2901caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2911caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 2921caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar } 2931caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar case Builtin::BI__builtin_memmove: { 2941caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2951caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemMoveFn(), Address, 2961caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2971caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(2)), 2981caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2991caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 3001caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar } 3011caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar case Builtin::BI__builtin_memset: { 3021caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 3031caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemSetFn(), Address, 30462c29c667f5bcb854e99ccb3aec1280c84115951Daniel Dunbar Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), 30562c29c667f5bcb854e99ccb3aec1280c84115951Daniel Dunbar llvm::Type::Int8Ty), 3061caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(2)), 3071caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 3081caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 309d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman } 310256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman case Builtin::BI__builtin_return_address: { 311256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); 312256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); 313256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman } 314256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman case Builtin::BI__builtin_frame_address: { 315256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); 316256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); 317256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman } 3183b660efb9f9fa3e87096f4a96a2093cd17c43c2eEli Friedman case Builtin::BI__builtin_extract_return_addr: { 3193b660efb9f9fa3e87096f4a96a2093cd17c43c2eEli Friedman // FIXME: There should be a target hook for this 3203b660efb9f9fa3e87096f4a96a2093cd17c43c2eEli Friedman return RValue::get(EmitScalarExpr(E->getArg(0))); 3213b660efb9f9fa3e87096f4a96a2093cd17c43c2eEli Friedman } 3221ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_add: 3231ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_sub: 3245caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_or: 3255caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_and: 3265caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_xor: 3275caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_add_and_fetch: 3285caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_sub_and_fetch: 3295caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_and_and_fetch: 3305caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_or_and_fetch: 3315caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_xor_and_fetch: 3325caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_val_compare_and_swap: 3335caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_bool_compare_and_swap: 3345caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_test_and_set: 3355caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_release: 3365caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner assert(0 && "Shouldn't make it through sema"); 3375caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_add_1: 3385caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_add_2: 3395caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_add_4: 3405caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_add_8: 3415caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_add_16: 3425caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner return EmitBinaryAtomic(*this, Intrinsic::atomic_load_add, E); 3435caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_sub_1: 3445caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_sub_2: 3455caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_sub_4: 3465caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_sub_8: 3475caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_sub_16: 34809b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_sub, E); 3495caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_or_1: 3505caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_or_2: 3515caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_or_4: 3525caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_or_8: 3535caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_or_16: 3545caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E); 3555caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_and_1: 3565caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_and_2: 3575caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_and_4: 3585caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_and_8: 3595caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_and_16: 3605caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E); 3615caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_xor_1: 3625caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_xor_2: 3635caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_xor_4: 3645caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_xor_8: 3655caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_fetch_and_xor_16: 3665caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E); 367eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_fetch_and_nand_1: 368eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_fetch_and_nand_2: 369eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_fetch_and_nand_4: 370eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_fetch_and_nand_8: 371eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_fetch_and_nand_16: 372eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner return EmitBinaryAtomic(*this, Intrinsic::atomic_load_nand, E); 373eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner 3745caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner // Clang extensions: not overloaded yet. 3751ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_min: 3761ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E); 3771ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_max: 3781ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E); 3791ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_umin: 3801ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E); 3811ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_umax: 3821ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E); 3830002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar 3845caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_add_and_fetch_1: 3855caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_add_and_fetch_2: 3865caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_add_and_fetch_4: 3875caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_add_and_fetch_8: 3885caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_add_and_fetch_16: 3890002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_add, E, 3900002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar llvm::Instruction::Add); 3915caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_sub_and_fetch_1: 3925caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_sub_and_fetch_2: 3935caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_sub_and_fetch_4: 3945caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_sub_and_fetch_8: 3955caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_sub_and_fetch_16: 3960002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_sub, E, 3970002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar llvm::Instruction::Sub); 3985caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_and_and_fetch_1: 3995caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_and_and_fetch_2: 4005caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_and_and_fetch_4: 4015caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_and_and_fetch_8: 4025caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_and_and_fetch_16: 4030002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_and, E, 4040002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar llvm::Instruction::And); 4055caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_or_and_fetch_1: 4065caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_or_and_fetch_2: 4075caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_or_and_fetch_4: 4085caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_or_and_fetch_8: 4095caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_or_and_fetch_16: 4100002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_or, E, 4110002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar llvm::Instruction::Or); 4125caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_xor_and_fetch_1: 4135caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_xor_and_fetch_2: 4145caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_xor_and_fetch_4: 4155caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_xor_and_fetch_8: 4165caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_xor_and_fetch_16: 4170002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_xor, E, 4180002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar llvm::Instruction::Xor); 419eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_nand_and_fetch_1: 420eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_nand_and_fetch_2: 421eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_nand_and_fetch_4: 422eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_nand_and_fetch_8: 423eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner case Builtin::BI__sync_nand_and_fetch_16: 424eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_nand, E, 425eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner llvm::Instruction::And); 426eebd9d2165a705ce6a8a6b6a7327864189d02785Chris Lattner 4275caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_val_compare_and_swap_1: 4285caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_val_compare_and_swap_2: 4295caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_val_compare_and_swap_4: 4305caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_val_compare_and_swap_8: 4315caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_val_compare_and_swap_16: 4325caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner { 433c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang const llvm::Type *ResType[2]; 434c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang ResType[0]= ConvertType(E->getType()); 435c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang ResType[1] = ConvertType(E->getArg(0)->getType()); 436c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2); 437958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson return RValue::get(Builder.CreateCall3(AtomF, 438958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson EmitScalarExpr(E->getArg(0)), 439958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson EmitScalarExpr(E->getArg(1)), 440958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson EmitScalarExpr(E->getArg(2)))); 441022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson } 4420002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar 4435caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_bool_compare_and_swap_1: 4445caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_bool_compare_and_swap_2: 4455caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_bool_compare_and_swap_4: 4465caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_bool_compare_and_swap_8: 4475caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_bool_compare_and_swap_16: 4485caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner { 4490002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar const llvm::Type *ResType[2]; 4505caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner ResType[0]= ConvertType(E->getArg(1)->getType()); 4515caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner ResType[1] = llvm::PointerType::getUnqual(ResType[0]); 4520002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2); 4530002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *OldVal = EmitScalarExpr(E->getArg(1)); 4540002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *PrevVal = Builder.CreateCall3(AtomF, 4550002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar EmitScalarExpr(E->getArg(0)), 4560002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar OldVal, 4570002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar EmitScalarExpr(E->getArg(2))); 4580002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar Value *Result = Builder.CreateICmpEQ(PrevVal, OldVal); 4590002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar // zext bool to int. 4600002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType()))); 4610002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar } 4620002d23aaf10f307273dab5facda01c137283d22Daniel Dunbar 4635caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_test_and_set_1: 4645caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_test_and_set_2: 4655caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_test_and_set_4: 4665caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_test_and_set_8: 4675caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_test_and_set_16: 4687ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E); 4695caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_release_1: 4705caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_release_2: 4715caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_release_4: 4725caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_release_8: 4735caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner case Builtin::BI__sync_lock_release_16: 4745caa370ea6f70bd3e7e4a9cc3b69ac1a849c8534Chris Lattner assert(0 && "FIXME: Implement"); 475ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar 476ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar // Library functions with special handling. 477ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar 478ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar case Builtin::BIsqrt: 479ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar case Builtin::BIsqrtf: 480ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar case Builtin::BIsqrtl: { 481ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar // Rewrite sqrt to intrinsic if allowed. 482b11fa0d25d86169f0e0a29d5398116c0212bb787Daniel Dunbar if (!FD->hasAttr<ConstAttr>()) 483ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar break; 484ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar Value *Arg0 = EmitScalarExpr(E->getArg(0)); 485ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar const llvm::Type *ArgType = Arg0->getType(); 486ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::sqrt, &ArgType, 1); 487ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar return RValue::get(Builder.CreateCall(F, Arg0, "tmp")); 488ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar } 489ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar 490ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar case Builtin::BIpow: 491ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar case Builtin::BIpowf: 492ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar case Builtin::BIpowl: { 493ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar // Rewrite sqrt to intrinsic if allowed. 494b11fa0d25d86169f0e0a29d5398116c0212bb787Daniel Dunbar if (!FD->hasAttr<ConstAttr>()) 495ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar break; 496ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar Value *Base = EmitScalarExpr(E->getArg(0)); 497ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar Value *Exponent = EmitScalarExpr(E->getArg(1)); 498ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar const llvm::Type *ArgType = Base->getType(); 499ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1); 500ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); 501ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar } 5027ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 503b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 504b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If this is an alias for a libm function (e.g. __builtin_sin) turn it into 505b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // that function. 5063e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor if (getContext().BuiltinInfo.isLibFunction(BuiltinID) || 5073e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) 508b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), 509b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner E->getCallee()->getType(), E->arg_begin(), 510b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner E->arg_end()); 511b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 512b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // See if we have a target specific intrinsic. 513a6f80ef997f0363386749087b325607eaa5adcfcDale Johannesen const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); 514a6f80ef997f0363386749087b325607eaa5adcfcDale Johannesen Intrinsic::ID IntrinsicID = 515a6f80ef997f0363386749087b325607eaa5adcfcDale Johannesen Intrinsic::getIntrinsicForGCCBuiltin(Target.getTargetPrefix(), Name); 516b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 517b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (IntrinsicID != Intrinsic::not_intrinsic) { 518b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner SmallVector<Value*, 16> Args; 519b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 520b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Function *F = CGM.getIntrinsic(IntrinsicID); 521b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::FunctionType *FTy = F->getFunctionType(); 522b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 523b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { 524b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(i)); 525b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 526b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If the intrinsic arg type is different from the builtin arg type 527b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // we need to do a bit cast. 528b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::Type *PTy = FTy->getParamType(i); 529b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (PTy != ArgValue->getType()) { 530b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && 531b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner "Must be able to losslessly bit cast to param"); 532b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner ArgValue = Builder.CreateBitCast(ArgValue, PTy); 533b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 534b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 535b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Args.push_back(ArgValue); 536b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 537b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 538b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size()); 539b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner QualType BuiltinRetType = E->getType(); 540b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 541b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::Type *RetTy = llvm::Type::VoidTy; 542b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); 543b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 544b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (RetTy != V->getType()) { 545b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(V->getType()->canLosslesslyBitCastTo(RetTy) && 546b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner "Must be able to losslessly bit cast result type"); 547b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner V = Builder.CreateBitCast(V, RetTy); 548b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 549b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 550b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(V); 551b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 552b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 553b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // See if we have a target specific builtin that needs to be lowered. 554f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) 555b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(V); 556b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 557488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar ErrorUnsupported(E, "builtin function"); 558b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 559b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // Unknown builtin, for now just dump it out and return undef. 560b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (hasAggregateLLVMType(E->getType())) 561b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType()))); 562b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(UndefValue::get(ConvertType(E->getType()))); 563b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 564564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 565f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel DunbarValue *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, 566f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar const CallExpr *E) { 567f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar const char *TargetPrefix = Target.getTargetPrefix(); 568f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar if (strcmp(TargetPrefix, "x86") == 0) 569f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar return EmitX86BuiltinExpr(BuiltinID, E); 570f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar else if (strcmp(TargetPrefix, "ppc") == 0) 571f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar return EmitPPCBuiltinExpr(BuiltinID, E); 572f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar return 0; 573f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar} 574f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 5751feedd84221e8dbcc3faf3de27cc42b559db845dChris LattnerValue *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, 5761feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner const CallExpr *E) { 5772929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 5782929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson llvm::SmallVector<Value*, 4> Ops; 5792929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 5802929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) 5812929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops.push_back(EmitScalarExpr(E->getArg(i))); 5822929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 583564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson switch (BuiltinID) { 58446a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson default: return 0; 58546a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson case X86::BI__builtin_ia32_mulps: 5862929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateMul(Ops[0], Ops[1], "mulps"); 587e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_mulpd: 588e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateMul(Ops[0], Ops[1], "mulpd"); 5894e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_pand: 590e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pand128: 5912929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateAnd(Ops[0], Ops[1], "pand"); 5924e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_por: 593e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_por128: 594e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateOr(Ops[0], Ops[1], "por"); 5954e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_pxor: 596e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pxor128: 597e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateXor(Ops[0], Ops[1], "pxor"); 598e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pandn: 599e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pandn128: 6002929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[0] = Builder.CreateNot(Ops[0], "tmp"); 6012929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateAnd(Ops[0], Ops[1], "pandn"); 6024e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddb: 603e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddb128: 6044e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddd: 605e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddd128: 6064e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddq: 607e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddq128: 6084e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddw: 609e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddw128: 610cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_addps: 611e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_addpd: 612cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateAdd(Ops[0], Ops[1], "add"); 6134e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubb: 614e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubb128: 6154e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubd: 616e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubd128: 6174e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubq: 618e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubq128: 6194e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubw: 620e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubw128: 621cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_subps: 622e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_subpd: 623cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateSub(Ops[0], Ops[1], "sub"); 624cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_divps: 625cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateFDiv(Ops[0], Ops[1], "divps"); 626e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_divpd: 627e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateFDiv(Ops[0], Ops[1], "divpd"); 628db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_pmullw: 629e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pmullw128: 6302929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateMul(Ops[0], Ops[1], "pmul"); 631db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhbw: 6327acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, 633db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson "punpckhbw"); 634e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhbw128: 635e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 8, 24, 9, 25, 10, 26, 11, 27, 636e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 12, 28, 13, 29, 14, 30, 15, 31, 637e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman "punpckhbw"); 638db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhwd: 6397acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhwd"); 640e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhwd128: 641e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, 642e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman "punpckhwd"); 643db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhdq: 6447acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhdq"); 645e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhdq128: 646e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhdq"); 647abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_punpckhqdq128: 648abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhqdq"); 649db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpcklbw: 6507acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, 651db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson "punpcklbw"); 652db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpcklwd: 6537acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpcklwd"); 654db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckldq: 6557acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpckldq"); 656e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckldq128: 657e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpckldq"); 658abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_punpcklqdq128: 659abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpcklqdq"); 660e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 661e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 662e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 663e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 664e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 665e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 666e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 667e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: { 668e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); 669e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); 670e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); 671e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), 672e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1], Zero, "insert"); 673e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); 674e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const char *name = 0; 675e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Intrinsic::ID ID = Intrinsic::not_intrinsic; 676e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 677e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman switch (BuiltinID) { 678e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman default: assert(0 && "Unsupported shift intrinsic!"); 679e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 680e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "pslldi"; 681e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_d; 682e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 683e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 684e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllqi"; 685e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_q; 686e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 687e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 688e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllwi"; 689e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_w; 690e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 691e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 692e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psradi"; 693e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_d; 694e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 695e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 696e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrawi"; 697e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_w; 698e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 699e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 700e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrldi"; 701e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_d; 702e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 703e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 704e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlqi"; 705e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_q; 706e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 707e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: 708e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlwi"; 709e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_w; 710e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 711e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 712e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F = CGM.getIntrinsic(ID); 713e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 714e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 7152929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pslldi: 7162929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllqi: 7172929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllwi: 7182929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psradi: 7192929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrawi: 7202929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrldi: 7212929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlqi: 7222929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlwi: { 7232929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); 7242929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1); 7252929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); 7262929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson const char *name = 0; 7272929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Intrinsic::ID ID = Intrinsic::not_intrinsic; 7284e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson 7292929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson switch (BuiltinID) { 7302929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson default: assert(0 && "Unsupported shift intrinsic!"); 7312929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pslldi: 7322929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "pslldi"; 7332929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_d; 7342929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7352929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllqi: 7362929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psllqi"; 7372929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_q; 7382929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7392929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllwi: 7402929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psllwi"; 7412929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_w; 7422929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7432929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psradi: 7442929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psradi"; 7452929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psra_d; 7462929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7472929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrawi: 7482929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrawi"; 7492929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psra_w; 7502929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7512929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrldi: 7522929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrldi"; 7532929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_d; 7542929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7552929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlqi: 7562929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrlqi"; 7572929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_q; 7582929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7592929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlwi: 7602929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrlwi"; 7612929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_w; 7622929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 7632929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson } 7647acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner llvm::Function *F = CGM.getIntrinsic(ID); 7652929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 7662929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson } 7674ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson case X86::BI__builtin_ia32_pshufw: { 7684ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 7694ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson return EmitShuffleVector(Ops[0], Ops[0], 7704ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson i & 0x3, (i & 0xc) >> 2, 7714ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson (i & 0x30) >> 4, (i & 0xc0) >> 6, 7724ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson "pshufw"); 7734ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson } 7747ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman case X86::BI__builtin_ia32_pshuflw: { 7757ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 7767ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitShuffleVector(Ops[0], Ops[0], 7777ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman i & 0x3, (i & 0xc) >> 2, 7787ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman (i & 0x30) >> 4, (i & 0xc0) >> 6, 4, 5, 6, 7, 7797ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman "pshuflw"); 7807ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 7817ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman case X86::BI__builtin_ia32_pshufhw: { 7827ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 7837ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitShuffleVector(Ops[0], Ops[0], 0, 1, 2, 3, 7847ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman 4 + (i & 0x3), 4 + ((i & 0xc) >> 2), 7857ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman 4 + ((i & 0x30) >> 4), 4 + ((i & 0xc0) >> 6), 7867ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman "pshufhw"); 7877ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 7882929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pshufd: { 7897acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 7902929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return EmitShuffleVector(Ops[0], Ops[0], 7914e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson i & 0x3, (i & 0xc) >> 2, 7924e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson (i & 0x30) >> 4, (i & 0xc0) >> 6, 7934e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson "pshufd"); 7944e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson } 7956086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v4hi: 7966086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v8qi: 7976086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v2si: 7986086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson return EmitVector(&Ops[0], Ops.size()); 7996086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_ext_v2si: 800e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v2di: 801e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4sf: 802e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4si: 8036fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman case X86::BI__builtin_ia32_vec_ext_v8hi: 8046fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4hi: 805e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v2df: 8066086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson return Builder.CreateExtractElement(Ops[0], Ops[1], "result"); 807cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordss: 808e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordsd: 809cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordss: 810e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordsd: 811e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqss: 812e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqsd: 813e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltss: 814e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltsd: 815cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpless: 816e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplesd: 817cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqss: 818e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqsd: 819e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltss: 820e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltsd: 821e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnless: 822e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlesd: { 8237acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = 0; 824cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson const char *name = 0; 825cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson switch (BuiltinID) { 826cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson default: assert(0 && "Unknown compare builtin!"); 827cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpeqss: 828e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqsd: 829cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 0; 830e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpeq"; 831cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 832cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpltss: 833e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltsd: 834cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 1; 835e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmplt"; 836cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 837cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpless: 838e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplesd: 839cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 2; 840e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmple"; 841cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 842cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordss: 843e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordsd: 844cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 3; 845e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpunord"; 846cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 847cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqss: 848e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqsd: 849cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 4; 850e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpneq"; 851cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 852cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnltss: 853e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltsd: 854cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 5; 855e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpntl"; 856cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 857cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnless: 858e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlesd: 859cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 6; 860e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpnle"; 861cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 862cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordss: 863e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordsd: 864cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 7; 865e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpord"; 866cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 867cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 868cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 869e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F; 870e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == 871e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type::FloatTy) 872e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss); 873e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman else 874e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd); 875e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 876cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); 877cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 878cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 879e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_ldmxcsr: { 880e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 881e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); 882e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); 883e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Builder.CreateStore(Ops[0], Tmp); 884e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), 8853eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner Builder.CreateBitCast(Tmp, PtrTy)); 886e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 887e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_stmxcsr: { 888e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 889e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); 890e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); 891e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), 8923eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner Builder.CreateBitCast(Tmp, PtrTy)); 893e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateLoad(Tmp, "stmxcsr"); 894e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 895cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordps: 896e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordpd: 897cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordps: 898e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordpd: 899cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpeqps: 900e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqpd: 901cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpltps: 902e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltpd: 903cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpleps: 904e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplepd: 905cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqps: 906e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqpd: 907cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngtps: 908e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngtpd: 909cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnltps: 910e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltpd: 911cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgtps: 912e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgtpd: 913cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgeps: 914e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgepd: 915cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngeps: 916e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngepd: 917e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnleps: 918e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlepd: { 9197acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = 0; 920cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson const char *name = 0; 921cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson bool ShouldSwap = false; 922cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson switch (BuiltinID) { 923cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson default: assert(0 && "Unknown compare builtin!"); 924e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqps: 925e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqpd: i = 0; name = "cmpeq"; break; 926e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltps: 927e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltpd: i = 1; name = "cmplt"; break; 928e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpleps: 929e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplepd: i = 2; name = "cmple"; break; 930e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordps: 931e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordpd: i = 3; name = "cmpunord"; break; 932e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqps: 933e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqpd: i = 4; name = "cmpneq"; break; 934e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltps: 935e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltpd: i = 5; name = "cmpntl"; break; 936e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnleps: 937e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlepd: i = 6; name = "cmpnle"; break; 938e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordps: 939e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordpd: i = 7; name = "cmpord"; break; 940cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgtps: 941e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgtpd: 9427acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner ShouldSwap = true; 943cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 1; 944e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpgt"; 945cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 946cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgeps: 947e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgepd: 948cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 2; 949e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpge"; 950cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 951cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 952cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngtps: 953e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngtpd: 954cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 5; 955e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpngt"; 956cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 957cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 958cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngeps: 959e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngepd: 960cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 6; 961e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpnge"; 962cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 963cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 964cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 965cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 966cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson if (ShouldSwap) 967cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson std::swap(Ops[0], Ops[1]); 968e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 969e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F; 970e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == 971e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type::FloatTy) 972e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps); 973e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman else 974e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd); 975cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 976cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); 977cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 978cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 979cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_movss: 980cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return EmitShuffleVector(Ops[0], Ops[1], 4, 1, 2, 3, "movss"); 981730f2c13e8ff0a2a3cc54fce9913add68107cb51Torok Edwin case X86::BI__builtin_ia32_shufps: { 9827acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); 983cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return EmitShuffleVector(Ops[0], Ops[1], 984cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i & 0x3, (i & 0xc) >> 2, 985cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ((i & 0x30) >> 4) + 4, 98609b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang ((i & 0xc0) >> 6) + 4, "shufps"); 987730f2c13e8ff0a2a3cc54fce9913add68107cb51Torok Edwin } 9886c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang case X86::BI__builtin_ia32_shufpd: { 9896c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); 990f29c8ad917e5fdc8fdd3d43707073be217bad625Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], i & 1, 991f29c8ad917e5fdc8fdd3d43707073be217bad625Chris Lattner ((i & 2) >> 1)+2, "shufpd"); 9926c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang } 993dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman case X86::BI__builtin_ia32_punpcklbw128: 994dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 16, 1, 17, 2, 18, 3, 19, 995dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman 4, 20, 5, 21, 6, 22, 7, 23, 996dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman "punpcklbw"); 997dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman case X86::BI__builtin_ia32_punpcklwd128: 998dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, 999dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman "punpcklwd"); 1000e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movlhps: 1001e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 1, 4, 5, "movlhps"); 1002e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movhlps: 1003e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 6, 7, 2, 3, "movhlps"); 1004e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_unpckhps: 1005e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "unpckhps"); 1006e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_unpcklps: 1007e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "unpcklps"); 1008abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_unpckhpd: 1009abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "unpckhpd"); 1010abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_unpcklpd: 1011abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "unpcklpd"); 1012abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_movsd: 1013abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 1, "movsd"); 1014e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movqv4si: { 1015e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); 1016e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], Ty); 1017e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 1018e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadlps: 1019e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadhps: { 1020e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // FIXME: This should probably be represented as 1021e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // shuffle (dst, (v4f32 (insert undef, (load i64), 0)), shuf mask hi/lo) 1022e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::DoubleTy; 1023e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 1024e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *OrigTy = Ops[0]->getType(); 1025e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlps ? 0 : 1; 1026e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 1027e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], llvm::PointerType::getUnqual(EltTy)); 1028e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateLoad(Ops[1], "tmp"); 1029e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); 1030e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadps"); 1031e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], OrigTy, "loadps"); 1032e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 10337f57b000f232bc596dca627c976ace250c8171e3Mon P Wang case X86::BI__builtin_ia32_loadlpd: 10347f57b000f232bc596dca627c976ace250c8171e3Mon P Wang case X86::BI__builtin_ia32_loadhpd: { 10357f57b000f232bc596dca627c976ace250c8171e3Mon P Wang Ops[1] = Builder.CreateLoad(Ops[1], "tmp"); 10367f57b000f232bc596dca627c976ace250c8171e3Mon P Wang unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlpd ? 0 : 1; 10377f57b000f232bc596dca627c976ace250c8171e3Mon P Wang llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 10387f57b000f232bc596dca627c976ace250c8171e3Mon P Wang return Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadpd"); 10397f57b000f232bc596dca627c976ace250c8171e3Mon P Wang } 1040e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_storehps: 1041e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_storelps: { 1042e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::Int64Ty; 1043e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); 1044e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 1045e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 1046e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // cast val v2i64 1047e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); 1048e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 1049e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // extract (0, 1) 1050e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; 1051e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 1052e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); 1053e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 1054e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // cast pointer to i64 & store 1055e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); 1056e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateStore(Ops[1], Ops[0]); 1057e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 1058e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadlv4si: { 1059e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // load i64 1060e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::Int64Ty; 1061e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); 1062e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); 1063e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateLoad(Ops[0], "load"); 1064e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 1065e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // scalar to vector: insert i64 into 2 x i64 undef 1066e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 1067e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); 1068e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateInsertElement(llvm::UndefValue::get(VecTy), 1069e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0], Zero, "s2v"); 1070e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 1071e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // shuffle into zero vector. 1072e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman std::vector<llvm::Constant *>Elts; 1073e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Elts.resize(2, llvm::ConstantInt::get(EltTy, 0)); 1074e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *ZV = ConstantVector::get(Elts); 1075e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = EmitShuffleVector(ZV, Ops[0], 2, 1, "loadl"); 1076e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 1077e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // bitcast to result. 1078e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], 1079e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::VectorType::get(llvm::Type::Int32Ty, 4)); 1080e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 108124512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman case X86::BI__builtin_ia32_vec_set_v4hi: 108224512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman case X86::BI__builtin_ia32_vec_set_v8hi: 108324512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrw"); 1084bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang case X86::BI__builtin_ia32_vec_set_v4si: 1085bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrd"); 1086bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang case X86::BI__builtin_ia32_vec_set_v2di: 1087bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrq"); 1088e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andps: 1089e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andpd: 1090e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnps: 1091e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnpd: 1092e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orps: 1093e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orpd: 1094e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorpd: 1095e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorps: { 1096e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *ITy = llvm::VectorType::get(llvm::Type::Int32Ty, 4); 1097e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *FTy = Ops[0]->getType(); 1098e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], ITy, "bitcast"); 1099e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], ITy, "bitcast"); 1100e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman switch (BuiltinID) { 1101e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andps: 1102e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andps"); 1103e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1104e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andpd: 1105e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andpd"); 1106e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1107e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnps: 1108e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateNot(Ops[0], "not"); 1109e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnps"); 1110e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1111e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnpd: 1112e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateNot(Ops[0], "not"); 1113e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnpd"); 1114e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1115e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orps: 1116e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orps"); 1117e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1118e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orpd: 1119e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orpd"); 1120e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1121e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorps: 1122e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorps"); 1123e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1124e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorpd: 1125e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorpd"); 1126e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 1127e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 1128e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], FTy, "bitcast"); 1129e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 1130564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson } 1131564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson} 1132564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 11331feedd84221e8dbcc3faf3de27cc42b559db845dChris LattnerValue *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, 11341feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner const CallExpr *E) { 1135564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson switch (BuiltinID) { 113646a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson default: return 0; 1137564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson } 1138564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson} 1139