CGBuiltin.cpp revision 3e41d60eb627dc227c770f1c1c87d06909cf05fd
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 261ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang/// Utility to insert an atomic instruction based Instrinsic::ID and 271ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang// the expression node 281ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wangstatic RValue EmitBinaryAtomic(CodeGenFunction& CFG, 291ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Intrinsic::ID Id, const CallExpr *E) { 30c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang const llvm::Type *ResType[2]; 31c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang ResType[0] = CFG.ConvertType(E->getType()); 32c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang ResType[1] = CFG.ConvertType(E->getArg(0)->getType()); 33c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang Value *AtomF = CFG.CGM.getIntrinsic(Id, ResType, 2); 341ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return RValue::get(CFG.Builder.CreateCall2(AtomF, 351ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang CFG.EmitScalarExpr(E->getArg(0)), 361ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang CFG.EmitScalarExpr(E->getArg(1)))); 371ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang} 381ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang 396de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris LattnerRValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { 40564ea2a99b3afeac9ded332730a56db1f6358a58Chris Lattner // See if we can constant fold this builtin. If so, don't emit it at all. 41f35d35a2316dcb65d078844696c2032b71a7f103Anders Carlsson Expr::EvalResult Result; 426ee7aa154e8bbb21a21254293410b944f78b0bfeChris Lattner if (E->Evaluate(Result, CGM.getContext())) { 43f35d35a2316dcb65d078844696c2032b71a7f103Anders Carlsson if (Result.Val.isInt()) 44f35d35a2316dcb65d078844696c2032b71a7f103Anders Carlsson return RValue::get(llvm::ConstantInt::get(Result.Val.getInt())); 453941b18b8e441c8c466efecd557de60b9a32d10bEli Friedman else if (Result.Val.isFloat()) 463941b18b8e441c8c466efecd557de60b9a32d10bEli Friedman return RValue::get(llvm::ConstantFP::get(Result.Val.getFloat())); 471f32999ec79a980576e100d64d5f3267eb19ea49Chris Lattner } 481f32999ec79a980576e100d64d5f3267eb19ea49Chris Lattner 49564ea2a99b3afeac9ded332730a56db1f6358a58Chris Lattner switch (BuiltinID) { 50564ea2a99b3afeac9ded332730a56db1f6358a58Chris Lattner default: break; // Handle intrinsics and libm functions below. 51506ff88f44562df267b6a06608ab841b76df2a2bChris Lattner case Builtin::BI__builtin___CFStringMakeConstantString: 52506ff88f44562df267b6a06608ab841b76df2a2bChris Lattner return RValue::get(CGM.EmitConstantExpr(E, 0)); 536a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner case Builtin::BI__builtin_stdarg_start: 54793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson case Builtin::BI__builtin_va_start: 55793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson case Builtin::BI__builtin_va_end: { 560785570af3ef5f8c5a0377129e41efe6f3f8d770Daniel Dunbar Value *ArgValue = EmitVAListRef(E->getArg(0)); 57ddc23f3e6fdc4f83dd46ef7e20394cfbd6063ff9Christopher Lamb const llvm::Type *DestType = 58ddc23f3e6fdc4f83dd46ef7e20394cfbd6063ff9Christopher Lamb llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 59793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson if (ArgValue->getType() != DestType) 60793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson ArgValue = Builder.CreateBitCast(ArgValue, DestType, 61793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson ArgValue->getNameStart()); 62793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson 636a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ? 646a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner Intrinsic::vaend : Intrinsic::vastart; 657acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); 66793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson } 67a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson case Builtin::BI__builtin_va_copy: { 684fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman Value *DstPtr = EmitVAListRef(E->getArg(0)); 694fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman Value *SrcPtr = EmitVAListRef(E->getArg(1)); 70a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 71a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson const llvm::Type *Type = 72a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 73a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 74a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson DstPtr = Builder.CreateBitCast(DstPtr, Type); 75a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson SrcPtr = Builder.CreateBitCast(SrcPtr, Type); 763eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), 773eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner DstPtr, SrcPtr)); 78a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson } 79c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson case Builtin::BI__builtin_abs: { 801feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 81c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson 829a847f598c4907a72b8593b364b9e6b94b086e75Chris Lattner Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); 831feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *CmpResult = 849a847f598c4907a72b8593b364b9e6b94b086e75Chris Lattner Builder.CreateICmpSGE(ArgValue, Constant::getNullValue(ArgValue->getType()), 859a847f598c4907a72b8593b364b9e6b94b086e75Chris Lattner "abscond"); 861feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *Result = 87c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); 88c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson 89c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson return RValue::get(Result); 90c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson } 913a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctz: 923a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctzl: 933a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctzll: { 943a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *ArgValue = EmitScalarExpr(E->getArg(0)); 953a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson 963a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson const llvm::Type *ArgType = ArgValue->getType(); 973a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); 983a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson 993a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson const llvm::Type *ResultType = ConvertType(E->getType()); 1003a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 1013a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson if (Result->getType() != ResultType) 1023a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Result = Builder.CreateIntCast(Result, ResultType, "cast"); 1033a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson return RValue::get(Result); 1043a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson } 105f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clz: 106f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clzl: 107f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clzll: { 108f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *ArgValue = EmitScalarExpr(E->getArg(0)); 109f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman 110f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman const llvm::Type *ArgType = ArgValue->getType(); 111f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1); 112f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman 113f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman const llvm::Type *ResultType = ConvertType(E->getType()); 114f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 115f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman if (Result->getType() != ResultType) 116f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Result = Builder.CreateIntCast(Result, ResultType, "cast"); 117f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman return RValue::get(Result); 118f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman } 11904b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_ffs: 12004b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_ffsl: 12104b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_ffsll: { 12204b290030eee33295600728450f348989d1a627eDaniel Dunbar // ffs(x) -> x ? cttz(x) + 1 : 0 12304b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *ArgValue = EmitScalarExpr(E->getArg(0)); 12404b290030eee33295600728450f348989d1a627eDaniel Dunbar 12504b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ArgType = ArgValue->getType(); 12604b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); 12704b290030eee33295600728450f348989d1a627eDaniel Dunbar 12804b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ResultType = ConvertType(E->getType()); 12904b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Tmp = Builder.CreateAdd(Builder.CreateCall(F, ArgValue, "tmp"), 13004b290030eee33295600728450f348989d1a627eDaniel Dunbar ConstantInt::get(ArgType, 1), "tmp"); 13104b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Zero = llvm::Constant::getNullValue(ArgType); 13204b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); 13304b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); 13404b290030eee33295600728450f348989d1a627eDaniel Dunbar if (Result->getType() != ResultType) 13504b290030eee33295600728450f348989d1a627eDaniel Dunbar Result = Builder.CreateIntCast(Result, ResultType, "cast"); 13604b290030eee33295600728450f348989d1a627eDaniel Dunbar return RValue::get(Result); 13704b290030eee33295600728450f348989d1a627eDaniel Dunbar } 13804b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_parity: 13904b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_parityl: 14004b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_parityll: { 14104b290030eee33295600728450f348989d1a627eDaniel Dunbar // parity(x) -> ctpop(x) & 1 14204b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *ArgValue = EmitScalarExpr(E->getArg(0)); 14304b290030eee33295600728450f348989d1a627eDaniel Dunbar 14404b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ArgType = ArgValue->getType(); 14504b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); 14604b290030eee33295600728450f348989d1a627eDaniel Dunbar 14704b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ResultType = ConvertType(E->getType()); 14804b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Tmp = Builder.CreateCall(F, ArgValue, "tmp"); 14904b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Result = Builder.CreateAnd(Tmp, ConstantInt::get(ArgType, 1), 15004b290030eee33295600728450f348989d1a627eDaniel Dunbar "tmp"); 15104b290030eee33295600728450f348989d1a627eDaniel Dunbar if (Result->getType() != ResultType) 15204b290030eee33295600728450f348989d1a627eDaniel Dunbar Result = Builder.CreateIntCast(Result, ResultType, "cast"); 15304b290030eee33295600728450f348989d1a627eDaniel Dunbar return RValue::get(Result); 15404b290030eee33295600728450f348989d1a627eDaniel Dunbar } 15504b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_popcount: 15604b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_popcountl: 15704b290030eee33295600728450f348989d1a627eDaniel Dunbar case Builtin::BI__builtin_popcountll: { 15804b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *ArgValue = EmitScalarExpr(E->getArg(0)); 15904b290030eee33295600728450f348989d1a627eDaniel Dunbar 16004b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ArgType = ArgValue->getType(); 16104b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); 16204b290030eee33295600728450f348989d1a627eDaniel Dunbar 16304b290030eee33295600728450f348989d1a627eDaniel Dunbar const llvm::Type *ResultType = ConvertType(E->getType()); 16404b290030eee33295600728450f348989d1a627eDaniel Dunbar Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 16504b290030eee33295600728450f348989d1a627eDaniel Dunbar if (Result->getType() != ResultType) 16604b290030eee33295600728450f348989d1a627eDaniel Dunbar Result = Builder.CreateIntCast(Result, ResultType, "cast"); 16704b290030eee33295600728450f348989d1a627eDaniel Dunbar return RValue::get(Result); 16804b290030eee33295600728450f348989d1a627eDaniel Dunbar } 1691feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner case Builtin::BI__builtin_expect: 170a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar // FIXME: pass expect through to LLVM 1711feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(EmitScalarExpr(E->getArg(0))); 172df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson case Builtin::BI__builtin_bswap32: 173df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson case Builtin::BI__builtin_bswap64: { 1741feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 175df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson const llvm::Type *ArgType = ArgValue->getType(); 1767acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1); 1771feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); 1784493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar } 179d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar case Builtin::BI__builtin_object_size: { 180d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar // FIXME: Implement. For now we just always fail and pretend we 181d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar // don't know the object size. 182d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar llvm::APSInt TypeArg = 183d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar E->getArg(1)->getIntegerConstantExprValue(CGM.getContext()); 184d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar const llvm::Type *ResType = ConvertType(E->getType()); 185d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar // bool UseSubObject = TypeArg.getZExtValue() & 1; 186d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar bool UseMinimum = TypeArg.getZExtValue() & 2; 187d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar return RValue::get(ConstantInt::get(ResType, UseMinimum ? 0 : -1LL)); 188d5f8a4fd4d6dfb0415b93bb7ab721bba5cab1332Daniel Dunbar } 1894493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar case Builtin::BI__builtin_prefetch: { 1904493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); 1914493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar // FIXME: Technically these constants should of type 'int', yes? 1924493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : 1934493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar ConstantInt::get(llvm::Type::Int32Ty, 0); 1944493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : 1954493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar ConstantInt::get(llvm::Type::Int32Ty, 3); 1964493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); 1974493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); 1984493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar } 1994493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar case Builtin::BI__builtin_trap: { 2004493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0); 2014493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar return RValue::get(Builder.CreateCall(F)); 202df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson } 2034493f79fce48cd9cbd9f55fa9d452cde736747a0Daniel Dunbar 204a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar case Builtin::BI__builtin_powi: 205a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar case Builtin::BI__builtin_powif: 206a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar case Builtin::BI__builtin_powil: { 207a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar Value *Base = EmitScalarExpr(E->getArg(0)); 208a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar Value *Exponent = EmitScalarExpr(E->getArg(1)); 209a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar const llvm::Type *ArgType = Base->getType(); 210a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1); 211a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); 212a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar } 213a933c3c052bbd87b01cc6fc7a7745e1c4b1757fbDaniel Dunbar 214fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreater: 215fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreaterequal: 216fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isless: 217fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessequal: 218fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessgreater: 219fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isunordered: { 220fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // Ordered comparisons: we know the arguments to these are matching scalar 221fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // floating point values. 222fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner Value *LHS = EmitScalarExpr(E->getArg(0)); 223fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner Value *RHS = EmitScalarExpr(E->getArg(1)); 224fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner 225fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner switch (BuiltinID) { 226fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner default: assert(0 && "Unknown ordered comparison"); 227fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreater: 228fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); 229fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 230fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreaterequal: 231fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); 232fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 233fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isless: 234fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); 235fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 236fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessequal: 237fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); 238fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 239fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessgreater: 240fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); 241fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 242fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isunordered: 243fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); 244fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 245fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner } 246fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // ZExt bool to int type. 247fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()), 248fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner "tmp")); 249fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner } 2509e800e3dd80d77f6c47054738177bf824089f55aChris Lattner case Builtin::BI__builtin_alloca: { 2519e800e3dd80d77f6c47054738177bf824089f55aChris Lattner // FIXME: LLVM IR Should allow alloca with an i64 size! 2529e800e3dd80d77f6c47054738177bf824089f55aChris Lattner Value *Size = EmitScalarExpr(E->getArg(0)); 2539e800e3dd80d77f6c47054738177bf824089f55aChris Lattner Size = Builder.CreateIntCast(Size, llvm::Type::Int32Ty, false, "tmp"); 2541caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size, "tmp")); 2551caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar } 2561caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar case Builtin::BI__builtin_bzero: { 2571caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2581caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemSetFn(), Address, 2591caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int8Ty, 0), 2601caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2611caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2621caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 2639e800e3dd80d77f6c47054738177bf824089f55aChris Lattner } 264d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman case Builtin::BI__builtin_memcpy: { 2651caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2661caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemCpyFn(), Address, 2671caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2681caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(2)), 2691caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2701caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 2711caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar } 2721caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar case Builtin::BI__builtin_memmove: { 2731caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2741caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemMoveFn(), Address, 2751caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2761caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(2)), 2771caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2781caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 2791caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar } 2801caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar case Builtin::BI__builtin_memset: { 2811caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Value *Address = EmitScalarExpr(E->getArg(0)); 2821caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar Builder.CreateCall4(CGM.getMemSetFn(), Address, 2831caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(1)), 2841caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar EmitScalarExpr(E->getArg(2)), 2851caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); 2861caae959017b355e9bb61250d5a0d04edbf468b0Daniel Dunbar return RValue::get(Address); 287d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman } 288256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman case Builtin::BI__builtin_return_address: { 289256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); 290256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); 291256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman } 292256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman case Builtin::BI__builtin_frame_address: { 293256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); 294256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); 295256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman } 2961ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_add: 29709b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_add, E); 2981ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_sub: 29909b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_sub, E); 3001ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_min: 3011ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E); 3021ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_max: 3031ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E); 3041ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_umin: 3051ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E); 3061ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_umax: 3071ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E); 3081ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_and: 3091ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E); 3101ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_or: 3111ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E); 3121ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_xor: 3131ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E); 3141ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_val_compare_and_swap: { 315c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang const llvm::Type *ResType[2]; 316c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang ResType[0]= ConvertType(E->getType()); 317c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang ResType[1] = ConvertType(E->getArg(0)->getType()); 318c5004516489c931cf839bdbdde5a76e4074cc888Mon P Wang Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2); 319958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson return RValue::get(Builder.CreateCall3(AtomF, 320958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson EmitScalarExpr(E->getArg(0)), 321958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson EmitScalarExpr(E->getArg(1)), 322958444659c5287a81a43188bfaa2a4902752b947Anders Carlsson EmitScalarExpr(E->getArg(2)))); 323022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson } 3241ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_lock_test_and_set: 3257ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E); 3267ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 327b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 328b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If this is an alias for a libm function (e.g. __builtin_sin) turn it into 329b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // that function. 3303e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor if (getContext().BuiltinInfo.isLibFunction(BuiltinID) || 3313e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) 332b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), 333b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner E->getCallee()->getType(), E->arg_begin(), 334b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner E->arg_end()); 335b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 336b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // See if we have a target specific intrinsic. 337a6f80ef997f0363386749087b325607eaa5adcfcDale Johannesen const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); 338a6f80ef997f0363386749087b325607eaa5adcfcDale Johannesen Intrinsic::ID IntrinsicID = 339a6f80ef997f0363386749087b325607eaa5adcfcDale Johannesen Intrinsic::getIntrinsicForGCCBuiltin(Target.getTargetPrefix(), Name); 340b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 341b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (IntrinsicID != Intrinsic::not_intrinsic) { 342b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner SmallVector<Value*, 16> Args; 343b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 344b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Function *F = CGM.getIntrinsic(IntrinsicID); 345b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::FunctionType *FTy = F->getFunctionType(); 346b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 347b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { 348b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(i)); 349b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 350b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If the intrinsic arg type is different from the builtin arg type 351b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // we need to do a bit cast. 352b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::Type *PTy = FTy->getParamType(i); 353b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (PTy != ArgValue->getType()) { 354b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && 355b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner "Must be able to losslessly bit cast to param"); 356b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner ArgValue = Builder.CreateBitCast(ArgValue, PTy); 357b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 358b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 359b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Args.push_back(ArgValue); 360b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 361b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 362b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size()); 363b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner QualType BuiltinRetType = E->getType(); 364b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 365b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::Type *RetTy = llvm::Type::VoidTy; 366b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); 367b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 368b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (RetTy != V->getType()) { 369b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(V->getType()->canLosslesslyBitCastTo(RetTy) && 370b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner "Must be able to losslessly bit cast result type"); 371b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner V = Builder.CreateBitCast(V, RetTy); 372b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 373b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 374b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(V); 375b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 376b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 377b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // See if we have a target specific builtin that needs to be lowered. 378f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) 379b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(V); 380b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 381488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar ErrorUnsupported(E, "builtin function"); 382b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 383b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // Unknown builtin, for now just dump it out and return undef. 384b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (hasAggregateLLVMType(E->getType())) 385b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType()))); 386b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(UndefValue::get(ConvertType(E->getType()))); 387b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 388564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 389f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel DunbarValue *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, 390f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar const CallExpr *E) { 391f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar const char *TargetPrefix = Target.getTargetPrefix(); 392f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar if (strcmp(TargetPrefix, "x86") == 0) 393f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar return EmitX86BuiltinExpr(BuiltinID, E); 394f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar else if (strcmp(TargetPrefix, "ppc") == 0) 395f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar return EmitPPCBuiltinExpr(BuiltinID, E); 396f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar return 0; 397f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar} 398f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 3991feedd84221e8dbcc3faf3de27cc42b559db845dChris LattnerValue *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, 4001feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner const CallExpr *E) { 4012929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 4022929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson llvm::SmallVector<Value*, 4> Ops; 4032929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 4042929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) 4052929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops.push_back(EmitScalarExpr(E->getArg(i))); 4062929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 407564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson switch (BuiltinID) { 40846a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson default: return 0; 40946a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson case X86::BI__builtin_ia32_mulps: 4102929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateMul(Ops[0], Ops[1], "mulps"); 411e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_mulpd: 412e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateMul(Ops[0], Ops[1], "mulpd"); 4134e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_pand: 414e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pand128: 4152929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateAnd(Ops[0], Ops[1], "pand"); 4164e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_por: 417e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_por128: 418e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateOr(Ops[0], Ops[1], "por"); 4194e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_pxor: 420e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pxor128: 421e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateXor(Ops[0], Ops[1], "pxor"); 422e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pandn: 423e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pandn128: 4242929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[0] = Builder.CreateNot(Ops[0], "tmp"); 4252929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateAnd(Ops[0], Ops[1], "pandn"); 4264e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddb: 427e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddb128: 4284e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddd: 429e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddd128: 4304e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddq: 431e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddq128: 4324e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddw: 433e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddw128: 434cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_addps: 435e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_addpd: 436cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateAdd(Ops[0], Ops[1], "add"); 4374e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubb: 438e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubb128: 4394e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubd: 440e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubd128: 4414e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubq: 442e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubq128: 4434e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubw: 444e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubw128: 445cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_subps: 446e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_subpd: 447cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateSub(Ops[0], Ops[1], "sub"); 448cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_divps: 449cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateFDiv(Ops[0], Ops[1], "divps"); 450e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_divpd: 451e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateFDiv(Ops[0], Ops[1], "divpd"); 452db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_pmullw: 453e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pmullw128: 4542929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateMul(Ops[0], Ops[1], "pmul"); 455db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhbw: 4567acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, 457db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson "punpckhbw"); 458e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhbw128: 459e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 8, 24, 9, 25, 10, 26, 11, 27, 460e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 12, 28, 13, 29, 14, 30, 15, 31, 461e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman "punpckhbw"); 462db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhwd: 4637acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhwd"); 464e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhwd128: 465e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, 466e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman "punpckhwd"); 467db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhdq: 4687acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhdq"); 469e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhdq128: 470e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhdq"); 471abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_punpckhqdq128: 472abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhqdq"); 473db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpcklbw: 4747acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, 475db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson "punpcklbw"); 476db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpcklwd: 4777acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpcklwd"); 478db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckldq: 4797acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpckldq"); 480e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckldq128: 481e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpckldq"); 482abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_punpcklqdq128: 483abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpcklqdq"); 484e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 485e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 486e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 487e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 488e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 489e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 490e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 491e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: { 492e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); 493e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); 494e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); 495e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), 496e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1], Zero, "insert"); 497e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); 498e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const char *name = 0; 499e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Intrinsic::ID ID = Intrinsic::not_intrinsic; 500e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 501e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman switch (BuiltinID) { 502e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman default: assert(0 && "Unsupported shift intrinsic!"); 503e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 504e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "pslldi"; 505e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_d; 506e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 507e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 508e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllqi"; 509e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_q; 510e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 511e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 512e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllwi"; 513e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_w; 514e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 515e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 516e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psradi"; 517e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_d; 518e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 519e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 520e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrawi"; 521e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_w; 522e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 523e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 524e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrldi"; 525e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_d; 526e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 527e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 528e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlqi"; 529e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_q; 530e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 531e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: 532e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlwi"; 533e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_w; 534e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 535e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 536e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F = CGM.getIntrinsic(ID); 537e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 538e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 5392929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pslldi: 5402929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllqi: 5412929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllwi: 5422929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psradi: 5432929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrawi: 5442929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrldi: 5452929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlqi: 5462929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlwi: { 5472929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); 5482929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1); 5492929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); 5502929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson const char *name = 0; 5512929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Intrinsic::ID ID = Intrinsic::not_intrinsic; 5524e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson 5532929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson switch (BuiltinID) { 5542929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson default: assert(0 && "Unsupported shift intrinsic!"); 5552929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pslldi: 5562929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "pslldi"; 5572929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_d; 5582929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5592929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllqi: 5602929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psllqi"; 5612929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_q; 5622929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5632929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllwi: 5642929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psllwi"; 5652929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_w; 5662929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5672929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psradi: 5682929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psradi"; 5692929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psra_d; 5702929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5712929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrawi: 5722929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrawi"; 5732929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psra_w; 5742929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5752929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrldi: 5762929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrldi"; 5772929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_d; 5782929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5792929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlqi: 5802929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrlqi"; 5812929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_q; 5822929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5832929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlwi: 5842929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrlwi"; 5852929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_w; 5862929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5872929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson } 5887acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner llvm::Function *F = CGM.getIntrinsic(ID); 5892929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 5902929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson } 5914ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson case X86::BI__builtin_ia32_pshufw: { 5924ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 5934ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson return EmitShuffleVector(Ops[0], Ops[0], 5944ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson i & 0x3, (i & 0xc) >> 2, 5954ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson (i & 0x30) >> 4, (i & 0xc0) >> 6, 5964ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson "pshufw"); 5974ee51b464fb0d452fb2a996dd2e86203eb70b0d7Anders Carlsson } 5987ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman case X86::BI__builtin_ia32_pshuflw: { 5997ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 6007ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitShuffleVector(Ops[0], Ops[0], 6017ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman i & 0x3, (i & 0xc) >> 2, 6027ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman (i & 0x30) >> 4, (i & 0xc0) >> 6, 4, 5, 6, 7, 6037ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman "pshuflw"); 6047ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 6057ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman case X86::BI__builtin_ia32_pshufhw: { 6067ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 6077ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitShuffleVector(Ops[0], Ops[0], 0, 1, 2, 3, 6087ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman 4 + (i & 0x3), 4 + ((i & 0xc) >> 2), 6097ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman 4 + ((i & 0x30) >> 4), 4 + ((i & 0xc0) >> 6), 6107ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman "pshufhw"); 6117ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 6122929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pshufd: { 6137acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 6142929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return EmitShuffleVector(Ops[0], Ops[0], 6154e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson i & 0x3, (i & 0xc) >> 2, 6164e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson (i & 0x30) >> 4, (i & 0xc0) >> 6, 6174e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson "pshufd"); 6184e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson } 6196086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v4hi: 6206086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v8qi: 6216086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v2si: 6226086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson return EmitVector(&Ops[0], Ops.size()); 6236086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_ext_v2si: 624e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v2di: 625e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4sf: 626e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4si: 6276fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman case X86::BI__builtin_ia32_vec_ext_v8hi: 6286fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4hi: 629e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v2df: 6306086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson return Builder.CreateExtractElement(Ops[0], Ops[1], "result"); 631cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordss: 632e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordsd: 633cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordss: 634e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordsd: 635e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqss: 636e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqsd: 637e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltss: 638e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltsd: 639cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpless: 640e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplesd: 641cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqss: 642e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqsd: 643e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltss: 644e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltsd: 645e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnless: 646e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlesd: { 6477acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = 0; 648cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson const char *name = 0; 649cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson switch (BuiltinID) { 650cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson default: assert(0 && "Unknown compare builtin!"); 651cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpeqss: 652e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqsd: 653cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 0; 654e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpeq"; 655cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 656cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpltss: 657e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltsd: 658cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 1; 659e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmplt"; 660cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 661cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpless: 662e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplesd: 663cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 2; 664e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmple"; 665cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 666cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordss: 667e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordsd: 668cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 3; 669e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpunord"; 670cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 671cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqss: 672e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqsd: 673cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 4; 674e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpneq"; 675cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 676cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnltss: 677e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltsd: 678cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 5; 679e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpntl"; 680cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 681cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnless: 682e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlesd: 683cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 6; 684e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpnle"; 685cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 686cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordss: 687e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordsd: 688cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 7; 689e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpord"; 690cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 691cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 692cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 693e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F; 694e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == 695e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type::FloatTy) 696e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss); 697e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman else 698e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd); 699e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 700cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); 701cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 702cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 703e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_ldmxcsr: { 704e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 705e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); 706e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); 707e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Builder.CreateStore(Ops[0], Tmp); 708e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), 7093eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner Builder.CreateBitCast(Tmp, PtrTy)); 710e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 711e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_stmxcsr: { 712e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 713e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); 714e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); 715e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), 7163eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner Builder.CreateBitCast(Tmp, PtrTy)); 717e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateLoad(Tmp, "stmxcsr"); 718e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 719cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordps: 720e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordpd: 721cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordps: 722e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordpd: 723cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpeqps: 724e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqpd: 725cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpltps: 726e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltpd: 727cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpleps: 728e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplepd: 729cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqps: 730e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqpd: 731cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngtps: 732e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngtpd: 733cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnltps: 734e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltpd: 735cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgtps: 736e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgtpd: 737cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgeps: 738e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgepd: 739cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngeps: 740e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngepd: 741e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnleps: 742e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlepd: { 7437acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = 0; 744cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson const char *name = 0; 745cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson bool ShouldSwap = false; 746cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson switch (BuiltinID) { 747cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson default: assert(0 && "Unknown compare builtin!"); 748e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqps: 749e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqpd: i = 0; name = "cmpeq"; break; 750e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltps: 751e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltpd: i = 1; name = "cmplt"; break; 752e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpleps: 753e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplepd: i = 2; name = "cmple"; break; 754e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordps: 755e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordpd: i = 3; name = "cmpunord"; break; 756e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqps: 757e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqpd: i = 4; name = "cmpneq"; break; 758e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltps: 759e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltpd: i = 5; name = "cmpntl"; break; 760e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnleps: 761e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlepd: i = 6; name = "cmpnle"; break; 762e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordps: 763e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordpd: i = 7; name = "cmpord"; break; 764cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgtps: 765e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgtpd: 7667acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner ShouldSwap = true; 767cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 1; 768e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpgt"; 769cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 770cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgeps: 771e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgepd: 772cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 2; 773e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpge"; 774cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 775cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 776cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngtps: 777e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngtpd: 778cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 5; 779e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpngt"; 780cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 781cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 782cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngeps: 783e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngepd: 784cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 6; 785e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpnge"; 786cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 787cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 788cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 789cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 790cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson if (ShouldSwap) 791cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson std::swap(Ops[0], Ops[1]); 792e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 793e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F; 794e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == 795e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type::FloatTy) 796e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps); 797e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman else 798e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd); 799cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 800cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); 801cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 802cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 803cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_movss: 804cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return EmitShuffleVector(Ops[0], Ops[1], 4, 1, 2, 3, "movss"); 805730f2c13e8ff0a2a3cc54fce9913add68107cb51Torok Edwin case X86::BI__builtin_ia32_shufps: { 8067acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); 807cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return EmitShuffleVector(Ops[0], Ops[1], 808cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i & 0x3, (i & 0xc) >> 2, 809cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ((i & 0x30) >> 4) + 4, 81009b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang ((i & 0xc0) >> 6) + 4, "shufps"); 811730f2c13e8ff0a2a3cc54fce9913add68107cb51Torok Edwin } 8126c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang case X86::BI__builtin_ia32_shufpd: { 8136c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); 8146c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang return EmitShuffleVector(Ops[0], Ops[1], i & 1, (i & 2) + 2, "shufpd"); 8156c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang } 816dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman case X86::BI__builtin_ia32_punpcklbw128: 817dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 16, 1, 17, 2, 18, 3, 19, 818dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman 4, 20, 5, 21, 6, 22, 7, 23, 819dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman "punpcklbw"); 820dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman case X86::BI__builtin_ia32_punpcklwd128: 821dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, 822dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman "punpcklwd"); 823e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movlhps: 824e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 1, 4, 5, "movlhps"); 825e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movhlps: 826e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 6, 7, 2, 3, "movhlps"); 827e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_unpckhps: 828e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "unpckhps"); 829e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_unpcklps: 830e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "unpcklps"); 831abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_unpckhpd: 832abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "unpckhpd"); 833abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_unpcklpd: 834abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "unpcklpd"); 835abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman case X86::BI__builtin_ia32_movsd: 836abfaf9984eee3d076ded8770bf9fce156f10c185Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 1, "movsd"); 837e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movqv4si: { 838e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); 839e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], Ty); 840e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 841e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadlps: 842e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadhps: { 843e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // FIXME: This should probably be represented as 844e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // shuffle (dst, (v4f32 (insert undef, (load i64), 0)), shuf mask hi/lo) 845e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::DoubleTy; 846e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 847e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *OrigTy = Ops[0]->getType(); 848e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlps ? 0 : 1; 849e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 850e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], llvm::PointerType::getUnqual(EltTy)); 851e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateLoad(Ops[1], "tmp"); 852e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); 853e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadps"); 854e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], OrigTy, "loadps"); 855e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 8567f57b000f232bc596dca627c976ace250c8171e3Mon P Wang case X86::BI__builtin_ia32_loadlpd: 8577f57b000f232bc596dca627c976ace250c8171e3Mon P Wang case X86::BI__builtin_ia32_loadhpd: { 8587f57b000f232bc596dca627c976ace250c8171e3Mon P Wang Ops[1] = Builder.CreateLoad(Ops[1], "tmp"); 8597f57b000f232bc596dca627c976ace250c8171e3Mon P Wang unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlpd ? 0 : 1; 8607f57b000f232bc596dca627c976ace250c8171e3Mon P Wang llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 8617f57b000f232bc596dca627c976ace250c8171e3Mon P Wang return Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadpd"); 8627f57b000f232bc596dca627c976ace250c8171e3Mon P Wang } 863e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_storehps: 864e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_storelps: { 865e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::Int64Ty; 866e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); 867e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 868e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 869e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // cast val v2i64 870e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); 871e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 872e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // extract (0, 1) 873e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; 874e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 875e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); 876e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 877e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // cast pointer to i64 & store 878e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); 879e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateStore(Ops[1], Ops[0]); 880e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 881e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadlv4si: { 882e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // load i64 883e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::Int64Ty; 884e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); 885e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); 886e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateLoad(Ops[0], "load"); 887e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 888e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // scalar to vector: insert i64 into 2 x i64 undef 889e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 890e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); 891e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateInsertElement(llvm::UndefValue::get(VecTy), 892e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0], Zero, "s2v"); 893e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 894e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // shuffle into zero vector. 895e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman std::vector<llvm::Constant *>Elts; 896e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Elts.resize(2, llvm::ConstantInt::get(EltTy, 0)); 897e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *ZV = ConstantVector::get(Elts); 898e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = EmitShuffleVector(ZV, Ops[0], 2, 1, "loadl"); 899e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 900e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // bitcast to result. 901e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], 902e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::VectorType::get(llvm::Type::Int32Ty, 4)); 903e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 90424512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman case X86::BI__builtin_ia32_vec_set_v4hi: 90524512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman case X86::BI__builtin_ia32_vec_set_v8hi: 90624512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrw"); 907bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang case X86::BI__builtin_ia32_vec_set_v4si: 908bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrd"); 909bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang case X86::BI__builtin_ia32_vec_set_v2di: 910bc4f4030e245e36642f894d848f6a8bf94426cc2Mon P Wang return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrq"); 911e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andps: 912e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andpd: 913e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnps: 914e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnpd: 915e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orps: 916e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orpd: 917e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorpd: 918e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorps: { 919e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *ITy = llvm::VectorType::get(llvm::Type::Int32Ty, 4); 920e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *FTy = Ops[0]->getType(); 921e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], ITy, "bitcast"); 922e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], ITy, "bitcast"); 923e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman switch (BuiltinID) { 924e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andps: 925e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andps"); 926e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 927e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andpd: 928e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andpd"); 929e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 930e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnps: 931e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateNot(Ops[0], "not"); 932e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnps"); 933e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 934e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnpd: 935e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateNot(Ops[0], "not"); 936e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnpd"); 937e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 938e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orps: 939e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orps"); 940e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 941e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orpd: 942e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orpd"); 943e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 944e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorps: 945e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorps"); 946e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 947e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorpd: 948e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorpd"); 949e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 950e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 951e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], FTy, "bitcast"); 952e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 953564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson } 954564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson} 955564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 9561feedd84221e8dbcc3faf3de27cc42b559db845dChris LattnerValue *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, 9571feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner const CallExpr *E) { 958564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson switch (BuiltinID) { 95946a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson default: return 0; 960564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson } 961564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson} 962