CGBuiltin.cpp revision 6c5df7f54f40090df6032a74e650b8e4d1c96207
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" 17bef20ac367a09555b30d6eb3847a81ec164caf88Chris Lattner#include "clang/AST/ASTContext.h" 18022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson#include "clang/AST/Builtins.h" 19022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson#include "clang/AST/Expr.h" 20564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson#include "clang/AST/TargetBuiltins.h" 216de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner#include "llvm/Constants.h" 22c5e940fa551840ecd71e8116c316c9131490f5faChris Lattner#include "llvm/Function.h" 23793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson#include "llvm/Intrinsics.h" 24022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlssonusing namespace clang; 25022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlssonusing namespace CodeGen; 26ca6fcfad547dcec3fdd17790b4fab0918df74b37Anders Carlssonusing namespace llvm; 27ca6fcfad547dcec3fdd17790b4fab0918df74b37Anders Carlsson 281ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang/// Utility to insert an atomic instruction based Instrinsic::ID and 291ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang// the expression node 301ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wangstatic RValue EmitBinaryAtomic(CodeGenFunction& CFG, 311ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Intrinsic::ID Id, const CallExpr *E) { 321ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang const llvm::Type *ResType = CFG.ConvertType(E->getType()); 331ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Value *AtomF = CFG.CGM.getIntrinsic(Id, &ResType, 1); 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) { 406de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner switch (BuiltinID) { 41b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner default: break; // Handle intrinsics and libm functions below. 42ca6fcfad547dcec3fdd17790b4fab0918df74b37Anders Carlsson 436de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner case Builtin::BI__builtin___CFStringMakeConstantString: { 446de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner const Expr *Arg = E->getArg(0); 456de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner 46d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson while (1) { 47d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson if (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg)) 48d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson Arg = PE->getSubExpr(); 49d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Arg)) 50d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson Arg = CE->getSubExpr(); 51d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson else 52d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson break; 53d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson } 546de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner 556de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner const StringLiteral *Literal = cast<StringLiteral>(Arg); 566de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner std::string S(Literal->getStrData(), Literal->getByteLength()); 576de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner 586de93ff81c5fe89b96a589ef13ea2beb4d7c3775Chris Lattner return RValue::get(CGM.GetAddrOfConstantCFString(S)); 59793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson } 606a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner case Builtin::BI__builtin_stdarg_start: 61793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson case Builtin::BI__builtin_va_start: 62793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson case Builtin::BI__builtin_va_end: { 631feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 64ddc23f3e6fdc4f83dd46ef7e20394cfbd6063ff9Christopher Lamb const llvm::Type *DestType = 65ddc23f3e6fdc4f83dd46ef7e20394cfbd6063ff9Christopher Lamb llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 66793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson if (ArgValue->getType() != DestType) 67793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson ArgValue = Builder.CreateBitCast(ArgValue, DestType, 68793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson ArgValue->getNameStart()); 69793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson 706a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ? 716a705f0443f8398ece14d80e71d8e8c9e71aa84aChris Lattner Intrinsic::vaend : Intrinsic::vastart; 727acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); 73793680ed8104bf088d1b382b963a8badcb3f07deAnders Carlsson } 74a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson case Builtin::BI__builtin_va_copy: { 75a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson // FIXME: This does not yet handle architectures where va_list is a struct. 76a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson Value *DstPtr = EmitScalarExpr(E->getArg(0)); 77a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson Value *SrcValue = EmitScalarExpr(E->getArg(1)); 78a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 79a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson Value *SrcPtr = CreateTempAlloca(SrcValue->getType(), "dst_ptr"); 80a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 81a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson Builder.CreateStore(SrcValue, SrcPtr, false); 82a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 83a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson const llvm::Type *Type = 84a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 85a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson 86a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson DstPtr = Builder.CreateBitCast(DstPtr, Type); 87a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson SrcPtr = Builder.CreateBitCast(SrcPtr, Type); 883eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), 893eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner DstPtr, SrcPtr)); 90a28ef8b5c6ea452472d89041128fac8b683fe968Anders Carlsson } 9189799cf254c91ca110f113a33eebe8b1b4d1a761Anders Carlsson case Builtin::BI__builtin_classify_type: { 921feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner APSInt Result(32); 9389799cf254c91ca110f113a33eebe8b1b4d1a761Anders Carlsson if (!E->isBuiltinClassifyType(Result)) 9489799cf254c91ca110f113a33eebe8b1b4d1a761Anders Carlsson assert(0 && "Expr not __builtin_classify_type!"); 951feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(ConstantInt::get(Result)); 9689799cf254c91ca110f113a33eebe8b1b4d1a761Anders Carlsson } 97d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson case Builtin::BI__builtin_constant_p: { 981feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner APSInt Result(32); 99d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson // FIXME: Analyze the parameter and check if it is a constant. 100d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson Result = 0; 1011feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(ConstantInt::get(Result)); 102d6a275f9a27d1c91e4084398d04030719b5b8f18Anders Carlsson } 103c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson case Builtin::BI__builtin_abs: { 1041feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 105c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson 106c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson llvm::BinaryOperator *NegOp = 107c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson Builder.CreateNeg(ArgValue, (ArgValue->getName() + "neg").c_str()); 1081feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *CmpResult = 109c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson Builder.CreateICmpSGE(ArgValue, NegOp->getOperand(0), "abscond"); 1101feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *Result = 111c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); 112c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson 113c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson return RValue::get(Result); 114c2251dc59b0edc28f9303637dec970a7520939adAnders Carlsson } 1153a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctz: 1163a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctzl: 1173a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson case Builtin::BI__builtin_ctzll: { 1183a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *ArgValue = EmitScalarExpr(E->getArg(0)); 1193a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson 1203a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson const llvm::Type *ArgType = ArgValue->getType(); 1213a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); 1223a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson 1233a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson const llvm::Type *ResultType = ConvertType(E->getType()); 1243a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 1253a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson if (Result->getType() != ResultType) 1263a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson Result = Builder.CreateIntCast(Result, ResultType, "cast"); 1273a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson return RValue::get(Result); 1283a31d60cffedfb7c9e6d129a5c9ba15fa74f179aAnders Carlsson } 129f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clz: 130f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clzl: 131f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman case Builtin::BI__builtin_clzll: { 132f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *ArgValue = EmitScalarExpr(E->getArg(0)); 133f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman 134f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman const llvm::Type *ArgType = ArgValue->getType(); 135f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1); 136f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman 137f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman const llvm::Type *ResultType = ConvertType(E->getType()); 138f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); 139f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman if (Result->getType() != ResultType) 140f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman Result = Builder.CreateIntCast(Result, ResultType, "cast"); 141f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman return RValue::get(Result); 142f4e853340590d5c32e58379e8c379ea1777d3101Eli Friedman } 1431feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner case Builtin::BI__builtin_expect: 1441feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(EmitScalarExpr(E->getArg(0))); 145df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson case Builtin::BI__builtin_bswap32: 146df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson case Builtin::BI__builtin_bswap64: { 1471feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(0)); 148df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson const llvm::Type *ArgType = ArgValue->getType(); 1497acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1); 1501feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); 151df4852ac816e6050d53b808b86d7c1c9738eb99eAnders Carlsson } 152b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case Builtin::BI__builtin_inff: 153478547cd2163d86ed9d691aa8fe45949eebf6cbfAnders Carlsson case Builtin::BI__builtin_huge_val: 154c8ee7988c4ea9ec784625d2a47a8575feb191421Anders Carlsson case Builtin::BI__builtin_inf: 155c8ee7988c4ea9ec784625d2a47a8575feb191421Anders Carlsson case Builtin::BI__builtin_infl: { 156b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::fltSemantics &Sem = 157b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner CGM.getContext().getFloatTypeSemantics(E->getType()); 158b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(ConstantFP::get(APFloat::getInf(Sem))); 159b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 160b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case Builtin::BI__builtin_nanf: 161b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case Builtin::BI__builtin_nan: 162b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case Builtin::BI__builtin_nanl: { 163b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If this is __builtin_nan("") turn this into a simple nan, otherwise just 164b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // call libm nan. 165b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (const StringLiteral *S = 166b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner dyn_cast<StringLiteral>(E->getArg(0)->IgnoreParenCasts())) { 167b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (!S->isWide() && S->getByteLength() == 0) { // empty string. 168b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::fltSemantics &Sem = 169b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner CGM.getContext().getFloatTypeSemantics(E->getType()); 170b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(ConstantFP::get(APFloat::getNaN(Sem))); 171b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 172b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 173b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // Otherwise, call libm 'nan'. 174b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner break; 175c8ee7988c4ea9ec784625d2a47a8575feb191421Anders Carlsson } 176fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreater: 177fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreaterequal: 178fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isless: 179fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessequal: 180fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessgreater: 181fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isunordered: { 182fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // Ordered comparisons: we know the arguments to these are matching scalar 183fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // floating point values. 184fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner Value *LHS = EmitScalarExpr(E->getArg(0)); 185fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner Value *RHS = EmitScalarExpr(E->getArg(1)); 186fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner 187fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner switch (BuiltinID) { 188fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner default: assert(0 && "Unknown ordered comparison"); 189fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreater: 190fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); 191fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 192fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isgreaterequal: 193fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); 194fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 195fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isless: 196fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); 197fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 198fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessequal: 199fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); 200fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 201fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_islessgreater: 202fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); 203fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 204fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner case Builtin::BI__builtin_isunordered: 205fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); 206fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner break; 207fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner } 208fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner // ZExt bool to int type. 209fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()), 210fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner "tmp")); 211fe23e217774aaec350086fab839210d7d9e1e3f4Chris Lattner } 2129e800e3dd80d77f6c47054738177bf824089f55aChris Lattner case Builtin::BI__builtin_alloca: { 2139e800e3dd80d77f6c47054738177bf824089f55aChris Lattner // FIXME: LLVM IR Should allow alloca with an i64 size! 2149e800e3dd80d77f6c47054738177bf824089f55aChris Lattner Value *Size = EmitScalarExpr(E->getArg(0)); 2159e800e3dd80d77f6c47054738177bf824089f55aChris Lattner Size = Builder.CreateIntCast(Size, llvm::Type::Int32Ty, false, "tmp"); 2169e800e3dd80d77f6c47054738177bf824089f55aChris Lattner return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size, 2174efe45919836728a2a38a50b8d79cd36432e1708Nate Begeman "tmp")); 2189e800e3dd80d77f6c47054738177bf824089f55aChris Lattner } 219d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman case Builtin::BI__builtin_memcpy: { 220d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman Value* MemCpyOps[4] = { 221d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman EmitScalarExpr(E->getArg(0)), 222d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman EmitScalarExpr(E->getArg(1)), 223d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman EmitScalarExpr(E->getArg(2)), 224d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman llvm::ConstantInt::get(llvm::Type::Int32Ty, 0) 225d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman }; 226d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman Builder.CreateCall(CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4); 227d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman return RValue::get(MemCpyOps[0]); 228d4b32e46517358f34e8cfbea35010adfcc3786e0Eli Friedman } 229256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman case Builtin::BI__builtin_return_address: { 230256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); 231256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); 232256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman } 233256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman case Builtin::BI__builtin_frame_address: { 234256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); 235256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman return RValue::get(Builder.CreateCall(F, EmitScalarExpr(E->getArg(0)))); 236256f77e431bc6b920ec94cf0bb4ad339ca21b8c9Eli Friedman } 2371ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_add: 23809b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_add, E); 2391ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_sub: 24009b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_sub, E); 2411ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_min: 2421ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E); 2431ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_max: 2441ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E); 2451ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_umin: 2461ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E); 2471ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_umax: 2481ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E); 2491ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_and: 2501ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E); 2511ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_or: 2521ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E); 2531ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_fetch_and_xor: 2541ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E); 2551ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_val_compare_and_swap: { 2561ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Value *Args[3]; 2571ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Args[0]= EmitScalarExpr(E->getArg(0)); 2581ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Args[1] = EmitScalarExpr(E->getArg(1)); 2591ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang Args[2] = EmitScalarExpr(E->getArg(2)); 2601ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang const llvm::Type *ResType = ConvertType(E->getType()); 26109b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, &ResType, 1); 2621ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang return RValue::get(Builder.CreateCall(AtomF, &Args[0], &Args[1]+2)); 263022012e6e5626c3372e1a5493c0929dfc1fa9e47Anders Carlsson } 2641ffe281890f3cd7728316b45a1f3dd4d3120af7bMon P Wang case Builtin::BI__sync_lock_test_and_set: 2657ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E); 2667ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 267b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 268b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If this is an alias for a libm function (e.g. __builtin_sin) turn it into 269b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // that function. 270b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) 271b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), 272b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner E->getCallee()->getType(), E->arg_begin(), 273b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner E->arg_end()); 274b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 275b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // See if we have a target specific intrinsic. 276b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Intrinsic::ID IntrinsicID; 277b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const char *TargetPrefix = Target.getTargetPrefix(); 278b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const char *BuiltinName = getContext().BuiltinInfo.GetName(BuiltinID); 279b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN 280b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner#include "llvm/Intrinsics.gen" 281b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN 282b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 283b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (IntrinsicID != Intrinsic::not_intrinsic) { 284b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner SmallVector<Value*, 16> Args; 285b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 286b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Function *F = CGM.getIntrinsic(IntrinsicID); 287b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::FunctionType *FTy = F->getFunctionType(); 288b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 289b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { 290b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *ArgValue = EmitScalarExpr(E->getArg(i)); 291b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 292b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // If the intrinsic arg type is different from the builtin arg type 293b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // we need to do a bit cast. 294b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::Type *PTy = FTy->getParamType(i); 295b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (PTy != ArgValue->getType()) { 296b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && 297b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner "Must be able to losslessly bit cast to param"); 298b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner ArgValue = Builder.CreateBitCast(ArgValue, PTy); 299b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 300b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 301b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Args.push_back(ArgValue); 302b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 303b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 304b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size()); 305b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner QualType BuiltinRetType = E->getType(); 306b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 307b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const llvm::Type *RetTy = llvm::Type::VoidTy; 308b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); 309b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 310b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (RetTy != V->getType()) { 311b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(V->getType()->canLosslesslyBitCastTo(RetTy) && 312b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner "Must be able to losslessly bit cast result type"); 313b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner V = Builder.CreateBitCast(V, RetTy); 314b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 315b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 316b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(V); 317b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 318b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 319b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // See if we have a target specific builtin that needs to be lowered. 320b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner Value *V = 0; 321b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 322b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (strcmp(TargetPrefix, "x86") == 0) 323b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner V = EmitX86BuiltinExpr(BuiltinID, E); 324b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner else if (strcmp(TargetPrefix, "ppc") == 0) 325b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner V = EmitPPCBuiltinExpr(BuiltinID, E); 326b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 327b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (V) 328b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(V); 329b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 330b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner WarnUnsupported(E, "builtin function"); 331b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 332b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner // Unknown builtin, for now just dump it out and return undef. 333b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner if (hasAggregateLLVMType(E->getType())) 334b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType()))); 335b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner return RValue::get(UndefValue::get(ConvertType(E->getType()))); 336b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 337564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 3381feedd84221e8dbcc3faf3de27cc42b559db845dChris LattnerValue *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, 3391feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner const CallExpr *E) { 3402929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 3412929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson llvm::SmallVector<Value*, 4> Ops; 3422929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 3432929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) 3442929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops.push_back(EmitScalarExpr(E->getArg(i))); 3452929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson 346564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson switch (BuiltinID) { 34746a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson default: return 0; 34846a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson case X86::BI__builtin_ia32_mulps: 3492929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateMul(Ops[0], Ops[1], "mulps"); 350e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_mulpd: 351e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateMul(Ops[0], Ops[1], "mulpd"); 3524e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_pand: 353e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pand128: 3542929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateAnd(Ops[0], Ops[1], "pand"); 3554e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_por: 356e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_por128: 357e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateOr(Ops[0], Ops[1], "por"); 3584e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_pxor: 359e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pxor128: 360e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateXor(Ops[0], Ops[1], "pxor"); 361e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pandn: 362e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pandn128: 3632929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[0] = Builder.CreateNot(Ops[0], "tmp"); 3642929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateAnd(Ops[0], Ops[1], "pandn"); 3654e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddb: 366e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddb128: 3674e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddd: 368e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddd128: 3694e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddq: 370e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddq128: 3714e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_paddw: 372e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_paddw128: 373cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_addps: 374e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_addpd: 375cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateAdd(Ops[0], Ops[1], "add"); 3764e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubb: 377e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubb128: 3784e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubd: 379e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubd128: 3804e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubq: 381e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubq128: 3824e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson case X86::BI__builtin_ia32_psubw: 383e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psubw128: 384cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_subps: 385e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_subpd: 386cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateSub(Ops[0], Ops[1], "sub"); 387cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_divps: 388cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateFDiv(Ops[0], Ops[1], "divps"); 389e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_divpd: 390e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateFDiv(Ops[0], Ops[1], "divpd"); 391db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_pmullw: 392e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pmullw128: 3932929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateMul(Ops[0], Ops[1], "pmul"); 394db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhbw: 3957acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, 396db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson "punpckhbw"); 397e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhbw128: 398e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 8, 24, 9, 25, 10, 26, 11, 27, 399e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 12, 28, 13, 29, 14, 30, 15, 31, 400e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman "punpckhbw"); 401db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhwd: 4027acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhwd"); 403e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhwd128: 404e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, 405e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman "punpckhwd"); 406db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckhdq: 4077acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhdq"); 408e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckhdq128: 409e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhdq"); 410db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpcklbw: 4117acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, 412db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson "punpcklbw"); 413db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpcklwd: 4147acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpcklwd"); 415db832305d35a7c9ef08bbafcf79d8da162af3374Anders Carlsson case X86::BI__builtin_ia32_punpckldq: 4167acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpckldq"); 417e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_punpckldq128: 418e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpckldq"); 419e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 420e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 421e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 422e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 423e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 424e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 425e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 426e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: { 427e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); 428e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); 429e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); 430e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), 431e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1], Zero, "insert"); 432e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); 433e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const char *name = 0; 434e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Intrinsic::ID ID = Intrinsic::not_intrinsic; 435e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 436e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman switch (BuiltinID) { 437e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman default: assert(0 && "Unsupported shift intrinsic!"); 438e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 439e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "pslldi"; 440e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_d; 441e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 442e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 443e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllqi"; 444e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_q; 445e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 446e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 447e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllwi"; 448e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_w; 449e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 450e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 451e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psradi"; 452e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_d; 453e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 454e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 455e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrawi"; 456e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_w; 457e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 458e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 459e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrldi"; 460e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_d; 461e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 462e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 463e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlqi"; 464e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_q; 465e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 466e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: 467e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlwi"; 468e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_w; 469e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 470e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 471e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F = CGM.getIntrinsic(ID); 472e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 473e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 4742929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pslldi: 4752929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllqi: 4762929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllwi: 4772929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psradi: 4782929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrawi: 4792929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrldi: 4802929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlqi: 4812929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlwi: { 4822929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); 4832929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1); 4842929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); 4852929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson const char *name = 0; 4862929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson Intrinsic::ID ID = Intrinsic::not_intrinsic; 4874e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson 4882929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson switch (BuiltinID) { 4892929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson default: assert(0 && "Unsupported shift intrinsic!"); 4902929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pslldi: 4912929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "pslldi"; 4922929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_d; 4932929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 4942929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllqi: 4952929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psllqi"; 4962929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_q; 4972929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 4982929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psllwi: 4992929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psllwi"; 5002929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psll_w; 5012929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5022929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psradi: 5032929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psradi"; 5042929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psra_d; 5052929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5062929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrawi: 5072929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrawi"; 5082929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psra_w; 5092929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5102929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrldi: 5112929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrldi"; 5122929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_d; 5132929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5142929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlqi: 5152929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrlqi"; 5162929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_q; 5172929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 5182929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_psrlwi: 5192929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson name = "psrlwi"; 5202929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson ID = Intrinsic::x86_mmx_psrl_w; 5212929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson break; 522e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_pslldi128: 523e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "pslldi"; 524e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_d; 525e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 526e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllqi128: 527e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllqi"; 528e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_q; 529e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 530e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psllwi128: 531e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psllwi"; 532e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psll_w; 533e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 534e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psradi128: 535e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psradi"; 536e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_d; 537e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 538e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrawi128: 539e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrawi"; 540e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psra_w; 541e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 542e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrldi128: 543e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrldi"; 544e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_d; 545e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 546e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlqi128: 547e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlqi"; 548e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_q; 549e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 550e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_psrlwi128: 551e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "psrlwi"; 552e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman ID = Intrinsic::x86_sse2_psrl_w; 553e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 5542929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson } 5557acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner llvm::Function *F = CGM.getIntrinsic(ID); 5562929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 5572929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson } 5587ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman case X86::BI__builtin_ia32_pshuflw: { 5597ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 5607ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitShuffleVector(Ops[0], Ops[0], 5617ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman i & 0x3, (i & 0xc) >> 2, 5627ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman (i & 0x30) >> 4, (i & 0xc0) >> 6, 4, 5, 6, 7, 5637ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman "pshuflw"); 5647ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 5657ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman case X86::BI__builtin_ia32_pshufhw: { 5667ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 5677ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman return EmitShuffleVector(Ops[0], Ops[0], 0, 1, 2, 3, 5687ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman 4 + (i & 0x3), 4 + ((i & 0xc) >> 2), 5697ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman 4 + ((i & 0x30) >> 4), 4 + ((i & 0xc0) >> 6), 5707ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman "pshufhw"); 5717ea2e3f6aae9b7511686d3d26dee690fee81c3aaNate Begeman } 5722929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson case X86::BI__builtin_ia32_pshufd: { 5737acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); 5742929cfa9b7df1d5b0571b54161783e4d791a0b77Anders Carlsson return EmitShuffleVector(Ops[0], Ops[0], 5754e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson i & 0x3, (i & 0xc) >> 2, 5764e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson (i & 0x30) >> 4, (i & 0xc0) >> 6, 5774e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson "pshufd"); 5784e4ee211b56e3276df80b350a6194f7cbf04b92cAnders Carlsson } 5796086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v4hi: 5806086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v8qi: 5816086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_init_v2si: 5826086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson return EmitVector(&Ops[0], Ops.size()); 5836086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson case X86::BI__builtin_ia32_vec_ext_v2si: 584e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v2di: 585e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4sf: 586e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v4si: 587e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_vec_ext_v2df: 5886086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson return Builder.CreateExtractElement(Ops[0], Ops[1], "result"); 589cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordss: 590e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordsd: 591cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordss: 592e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordsd: 593e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqss: 594e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqsd: 595e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltss: 596e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltsd: 597cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpless: 598e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplesd: 599cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqss: 600e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqsd: 601e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltss: 602e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltsd: 603e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnless: 604e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlesd: { 6057acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = 0; 606cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson const char *name = 0; 607cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson switch (BuiltinID) { 608cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson default: assert(0 && "Unknown compare builtin!"); 609cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpeqss: 610e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqsd: 611cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 0; 612e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpeq"; 613cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 614cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpltss: 615e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltsd: 616cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 1; 617e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmplt"; 618cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 619cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpless: 620e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplesd: 621cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 2; 622e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmple"; 623cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 624cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordss: 625e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordsd: 626cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 3; 627e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpunord"; 628cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 629cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqss: 630e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqsd: 631cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 4; 632e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpneq"; 633cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 634cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnltss: 635e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltsd: 636cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 5; 637e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpntl"; 638cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 639cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnless: 640e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlesd: 641cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 6; 642e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpnle"; 643cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 644cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordss: 645e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordsd: 646cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 7; 647e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpord"; 648cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 649cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 650cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 651e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F; 652e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == 653e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type::FloatTy) 654e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss); 655e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman else 656e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd); 657e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 658cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); 659cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 660cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 661e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_ldmxcsr: { 662e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 663e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); 664e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); 665e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Builder.CreateStore(Ops[0], Tmp); 666e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), 6673eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner Builder.CreateBitCast(Tmp, PtrTy)); 668e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 669e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_stmxcsr: { 670e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); 671e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); 672e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); 673e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), 6743eae03e7d165f20a863a9a4d7122ba2a691ab16dChris Lattner Builder.CreateBitCast(Tmp, PtrTy)); 675e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateLoad(Tmp, "stmxcsr"); 676e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 677cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpordps: 678e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordpd: 679cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpunordps: 680e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordpd: 681cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpeqps: 682e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqpd: 683cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpltps: 684e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltpd: 685cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpleps: 686e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplepd: 687cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpneqps: 688e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqpd: 689cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngtps: 690e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngtpd: 691cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpnltps: 692e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltpd: 693cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgtps: 694e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgtpd: 695cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgeps: 696e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgepd: 697cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngeps: 698e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngepd: 699e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnleps: 700e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlepd: { 7017acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = 0; 702cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson const char *name = 0; 703cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson bool ShouldSwap = false; 704cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson switch (BuiltinID) { 705cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson default: assert(0 && "Unknown compare builtin!"); 706e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqps: 707e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpeqpd: i = 0; name = "cmpeq"; break; 708e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltps: 709e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpltpd: i = 1; name = "cmplt"; break; 710e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpleps: 711e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmplepd: i = 2; name = "cmple"; break; 712e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordps: 713e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpunordpd: i = 3; name = "cmpunord"; break; 714e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqps: 715e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpneqpd: i = 4; name = "cmpneq"; break; 716e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltps: 717e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnltpd: i = 5; name = "cmpntl"; break; 718e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnleps: 719e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpnlepd: i = 6; name = "cmpnle"; break; 720e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordps: 721e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpordpd: i = 7; name = "cmpord"; break; 722cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgtps: 723e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgtpd: 7247acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner ShouldSwap = true; 725cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 1; 726e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpgt"; 727cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 728cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpgeps: 729e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpgepd: 730cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 2; 731e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpge"; 732cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 733cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 734cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngtps: 735e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngtpd: 736cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 5; 737e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpngt"; 738cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 739cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 740cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_cmpngeps: 741e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_cmpngepd: 742cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i = 6; 743e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman name = "cmpnge"; 744cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ShouldSwap = true; 745cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson break; 746cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 747cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 748cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson if (ShouldSwap) 749cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson std::swap(Ops[0], Ops[1]); 750e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 751e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Function *F; 752e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == 753e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type::FloatTy) 754e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps); 755e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman else 756e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd); 757cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson 758cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); 759cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); 760cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson } 761cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson case X86::BI__builtin_ia32_movss: 762cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return EmitShuffleVector(Ops[0], Ops[1], 4, 1, 2, 3, "movss"); 763730f2c13e8ff0a2a3cc54fce9913add68107cb51Torok Edwin case X86::BI__builtin_ia32_shufps: { 7647acda7c4a0e4aec6c003b3169ca45a5f3bc7e033Chris Lattner unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); 765cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson return EmitShuffleVector(Ops[0], Ops[1], 766cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson i & 0x3, (i & 0xc) >> 2, 767cc8b7f911892b3257e381677d0a82d43bf7b067cAnders Carlsson ((i & 0x30) >> 4) + 4, 76809b6bf5bfa2ba9cbbd353cbd7846af8f49b020e7Mon P Wang ((i & 0xc0) >> 6) + 4, "shufps"); 769730f2c13e8ff0a2a3cc54fce9913add68107cb51Torok Edwin } 7706c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang case X86::BI__builtin_ia32_shufpd: { 7716c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); 7726c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang return EmitShuffleVector(Ops[0], Ops[1], i & 1, (i & 2) + 2, "shufpd"); 7736c5df7f54f40090df6032a74e650b8e4d1c96207Mon P Wang } 774dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman case X86::BI__builtin_ia32_punpcklbw128: 775dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 16, 1, 17, 2, 18, 3, 19, 776dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman 4, 20, 5, 21, 6, 22, 7, 23, 777dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman "punpcklbw"); 778dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman case X86::BI__builtin_ia32_punpcklwd128: 779dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, 780dbebb73b86d9fe56c2227bf75c13ea3a49248261Nate Begeman "punpcklwd"); 781e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movlhps: 782e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 1, 4, 5, "movlhps"); 783e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movhlps: 784e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 6, 7, 2, 3, "movhlps"); 785e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_unpckhps: 786e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "unpckhps"); 787e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_unpcklps: 788e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "unpcklps"); 789e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_movqv4si: { 790e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); 791e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], Ty); 792e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 793e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadlps: 794e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadhps: { 795e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // FIXME: This should probably be represented as 796e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // shuffle (dst, (v4f32 (insert undef, (load i64), 0)), shuf mask hi/lo) 797e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::DoubleTy; 798e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 799e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *OrigTy = Ops[0]->getType(); 800e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlps ? 0 : 1; 801e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 802e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], llvm::PointerType::getUnqual(EltTy)); 803e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateLoad(Ops[1], "tmp"); 804e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); 805e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadps"); 806e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], OrigTy, "loadps"); 807e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 808e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_storehps: 809e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_storelps: { 810e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::Int64Ty; 811e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); 812e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 813e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 814e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // cast val v2i64 815e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); 816e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 817e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // extract (0, 1) 818e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; 819e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); 820e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); 821e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 822e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // cast pointer to i64 & store 823e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); 824e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateStore(Ops[1], Ops[0]); 825e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 826e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_loadlv4si: { 827e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // load i64 828e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *EltTy = llvm::Type::Int64Ty; 829e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); 830e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); 831e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateLoad(Ops[0], "load"); 832e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 833e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // scalar to vector: insert i64 into 2 x i64 undef 834e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); 835e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); 836e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateInsertElement(llvm::UndefValue::get(VecTy), 837e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0], Zero, "s2v"); 838e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 839e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // shuffle into zero vector. 840e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman std::vector<llvm::Constant *>Elts; 841e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Elts.resize(2, llvm::ConstantInt::get(EltTy, 0)); 842e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::Value *ZV = ConstantVector::get(Elts); 843e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = EmitShuffleVector(ZV, Ops[0], 2, 1, "loadl"); 844e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman 845e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman // bitcast to result. 846e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], 847e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman llvm::VectorType::get(llvm::Type::Int32Ty, 4)); 848e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 84924512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman case X86::BI__builtin_ia32_vec_set_v4hi: 85024512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman case X86::BI__builtin_ia32_vec_set_v8hi: 85124512501319aa6d7f70b1bd79470df0197b832c8Nate Begeman return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrw"); 852e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andps: 853e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andpd: 854e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnps: 855e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnpd: 856e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orps: 857e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orpd: 858e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorpd: 859e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorps: { 860e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *ITy = llvm::VectorType::get(llvm::Type::Int32Ty, 4); 861e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman const llvm::Type *FTy = Ops[0]->getType(); 862e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateBitCast(Ops[0], ITy, "bitcast"); 863e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[1] = Builder.CreateBitCast(Ops[1], ITy, "bitcast"); 864e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman switch (BuiltinID) { 865e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andps: 866e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andps"); 867e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 868e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andpd: 869e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andpd"); 870e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 871e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnps: 872e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateNot(Ops[0], "not"); 873e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnps"); 874e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 875e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_andnpd: 876e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateNot(Ops[0], "not"); 877e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnpd"); 878e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 879e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orps: 880e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orps"); 881e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 882e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_orpd: 883e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orpd"); 884e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 885e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorps: 886e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorps"); 887e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 888e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman case X86::BI__builtin_ia32_xorpd: 889e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorpd"); 890e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman break; 891e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 892e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman return Builder.CreateBitCast(Ops[0], FTy, "bitcast"); 893e7722103abc4583366c914374d6aa8560e145fa1Nate Begeman } 894564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson } 895564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson} 896564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 8971feedd84221e8dbcc3faf3de27cc42b559db845dChris LattnerValue *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, 8981feedd84221e8dbcc3faf3de27cc42b559db845dChris Lattner const CallExpr *E) { 899564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson switch (BuiltinID) { 90046a26b0b0e2ec1557bad9b70e8e20836524ebdfcAnders Carlsson default: return 0; 901564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson } 902564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson} 903