Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 1 | //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Builtin calls as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenFunction.h" |
| 15 | #include "CodeGenModule.h" |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 16 | #include "clang/Basic/TargetInfo.h" |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/Builtins.h" |
| 19 | #include "clang/AST/Expr.h" |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 20 | #include "clang/AST/TargetBuiltins.h" |
Chris Lattner | 6de93ff | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
Chris Lattner | c5e940f | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 22 | #include "llvm/Function.h" |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 23 | #include "llvm/Intrinsics.h" |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using namespace CodeGen; |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chris Lattner | 6de93ff | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 28 | RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { |
| 29 | switch (BuiltinID) { |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 30 | default: { |
Chris Lattner | c5e940f | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 31 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) |
Nate Begeman | eed5058 | 2008-01-17 18:06:09 +0000 | [diff] [blame] | 32 | return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), |
Eli Friedman | 5193b8a | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 33 | E->getCallee()->getType(), E->arg_begin(), |
| 34 | E->getNumArgs()); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 35 | |
| 36 | // See if we have a target specific intrinsic. |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 37 | Intrinsic::ID IntrinsicID; |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 38 | const char *TargetPrefix = Target.getTargetPrefix(); |
| 39 | const char *BuiltinName = getContext().BuiltinInfo.GetName(BuiltinID); |
| 40 | #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 41 | #include "llvm/Intrinsics.gen" |
| 42 | #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 43 | |
| 44 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 45 | SmallVector<Value*, 16> Args; |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 47 | Function *F = CGM.getIntrinsic(IntrinsicID); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 48 | const llvm::FunctionType *FTy = F->getFunctionType(); |
| 49 | |
| 50 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 51 | Value *ArgValue = EmitScalarExpr(E->getArg(i)); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 52 | |
| 53 | // If the intrinsic arg type is different from the builtin arg type |
| 54 | // we need to do a bit cast. |
| 55 | const llvm::Type *PTy = FTy->getParamType(i); |
| 56 | if (PTy != ArgValue->getType()) { |
| 57 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 58 | "Must be able to losslessly bit cast to param"); |
| 59 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 60 | } |
| 61 | |
| 62 | Args.push_back(ArgValue); |
| 63 | } |
| 64 | |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 65 | Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size()); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 66 | QualType BuiltinRetType = E->getType(); |
| 67 | |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 68 | const llvm::Type *RetTy = llvm::Type::VoidTy; |
| 69 | if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 70 | |
| 71 | if (RetTy != V->getType()) { |
| 72 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 73 | "Must be able to losslessly bit cast result type"); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 74 | V = Builder.CreateBitCast(V, RetTy); |
| 75 | } |
| 76 | |
| 77 | return RValue::get(V); |
| 78 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 79 | |
| 80 | // See if we have a target specific builtin that needs to be lowered. |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 81 | Value *V = 0; |
Chris Lattner | c5e940f | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 82 | |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 83 | if (strcmp(TargetPrefix, "x86") == 0) |
| 84 | V = EmitX86BuiltinExpr(BuiltinID, E); |
| 85 | else if (strcmp(TargetPrefix, "ppc") == 0) |
| 86 | V = EmitPPCBuiltinExpr(BuiltinID, E); |
| 87 | |
| 88 | if (V) |
| 89 | return RValue::get(V); |
| 90 | |
Chris Lattner | dc4d280 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 91 | WarnUnsupported(E, "builtin function"); |
Chris Lattner | 6de93ff | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 92 | |
| 93 | // Unknown builtin, for now just dump it out and return undef. |
| 94 | if (hasAggregateLLVMType(E->getType())) |
| 95 | return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType()))); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 96 | return RValue::get(UndefValue::get(ConvertType(E->getType()))); |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 97 | } |
Chris Lattner | 6de93ff | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 98 | case Builtin::BI__builtin___CFStringMakeConstantString: { |
| 99 | const Expr *Arg = E->getArg(0); |
| 100 | |
Anders Carlsson | d6a275f | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 101 | while (1) { |
| 102 | if (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg)) |
| 103 | Arg = PE->getSubExpr(); |
| 104 | else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Arg)) |
| 105 | Arg = CE->getSubExpr(); |
| 106 | else |
| 107 | break; |
| 108 | } |
Chris Lattner | 6de93ff | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 109 | |
| 110 | const StringLiteral *Literal = cast<StringLiteral>(Arg); |
| 111 | std::string S(Literal->getStrData(), Literal->getByteLength()); |
| 112 | |
| 113 | return RValue::get(CGM.GetAddrOfConstantCFString(S)); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 114 | } |
| 115 | case Builtin::BI__builtin_va_start: |
| 116 | case Builtin::BI__builtin_va_end: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 117 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Christopher Lamb | ddc23f3 | 2007-12-17 01:11:20 +0000 | [diff] [blame] | 118 | const llvm::Type *DestType = |
| 119 | llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 120 | if (ArgValue->getType() != DestType) |
| 121 | ArgValue = Builder.CreateBitCast(ArgValue, DestType, |
| 122 | ArgValue->getNameStart()); |
| 123 | |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 124 | Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_start) ? |
| 125 | Intrinsic::vastart : Intrinsic::vaend; |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 126 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 127 | } |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 128 | case Builtin::BI__builtin_va_copy: { |
| 129 | // FIXME: This does not yet handle architectures where va_list is a struct. |
| 130 | Value *DstPtr = EmitScalarExpr(E->getArg(0)); |
| 131 | Value *SrcValue = EmitScalarExpr(E->getArg(1)); |
| 132 | |
| 133 | Value *SrcPtr = CreateTempAlloca(SrcValue->getType(), "dst_ptr"); |
| 134 | |
| 135 | // FIXME: Volatile |
| 136 | Builder.CreateStore(SrcValue, SrcPtr, false); |
| 137 | |
| 138 | const llvm::Type *Type = |
| 139 | llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
| 140 | |
| 141 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 142 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame^] | 143 | return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), |
| 144 | DstPtr, SrcPtr)); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 145 | } |
Anders Carlsson | 89799cf | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 146 | case Builtin::BI__builtin_classify_type: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 147 | APSInt Result(32); |
Anders Carlsson | 89799cf | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 148 | if (!E->isBuiltinClassifyType(Result)) |
| 149 | assert(0 && "Expr not __builtin_classify_type!"); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 150 | return RValue::get(ConstantInt::get(Result)); |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 151 | } |
Anders Carlsson | d6a275f | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 152 | case Builtin::BI__builtin_constant_p: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 153 | APSInt Result(32); |
Anders Carlsson | d6a275f | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 154 | // FIXME: Analyze the parameter and check if it is a constant. |
| 155 | Result = 0; |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 156 | return RValue::get(ConstantInt::get(Result)); |
Anders Carlsson | d6a275f | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 157 | } |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 158 | case Builtin::BI__builtin_abs: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 159 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 160 | |
| 161 | llvm::BinaryOperator *NegOp = |
| 162 | Builder.CreateNeg(ArgValue, (ArgValue->getName() + "neg").c_str()); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 163 | Value *CmpResult = |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 164 | Builder.CreateICmpSGE(ArgValue, NegOp->getOperand(0), "abscond"); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 165 | Value *Result = |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 166 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
| 167 | |
| 168 | return RValue::get(Result); |
| 169 | } |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 170 | case Builtin::BI__builtin_ctz: |
| 171 | case Builtin::BI__builtin_ctzl: |
| 172 | case Builtin::BI__builtin_ctzll: { |
| 173 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 174 | |
| 175 | const llvm::Type *ArgType = ArgValue->getType(); |
| 176 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); |
| 177 | |
| 178 | const llvm::Type *ResultType = ConvertType(E->getType()); |
| 179 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 180 | if (Result->getType() != ResultType) |
| 181 | Result = Builder.CreateIntCast(Result, ResultType, "cast"); |
| 182 | return RValue::get(Result); |
| 183 | } |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 184 | case Builtin::BI__builtin_expect: |
| 185 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 186 | case Builtin::BI__builtin_bswap32: |
| 187 | case Builtin::BI__builtin_bswap64: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 188 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 189 | const llvm::Type *ArgType = ArgValue->getType(); |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 190 | Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 191 | return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 192 | } |
Anders Carlsson | c8ee798 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 193 | case Builtin::BI__builtin_inff: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 194 | APFloat f(APFloat::IEEEsingle, APFloat::fcInfinity, false); |
Chris Lattner | 2c62a1a | 2008-05-04 18:23:51 +0000 | [diff] [blame] | 195 | return RValue::get(ConstantFP::get(f)); |
Anders Carlsson | c8ee798 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 196 | } |
Anders Carlsson | 478547c | 2008-02-01 16:06:34 +0000 | [diff] [blame] | 197 | case Builtin::BI__builtin_huge_val: |
Anders Carlsson | c8ee798 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 198 | case Builtin::BI__builtin_inf: |
| 199 | // FIXME: mapping long double onto double. |
| 200 | case Builtin::BI__builtin_infl: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 201 | APFloat f(APFloat::IEEEdouble, APFloat::fcInfinity, false); |
Chris Lattner | 2c62a1a | 2008-05-04 18:23:51 +0000 | [diff] [blame] | 202 | return RValue::get(ConstantFP::get(f)); |
Anders Carlsson | c8ee798 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 203 | } |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 204 | case Builtin::BI__builtin_isgreater: |
| 205 | case Builtin::BI__builtin_isgreaterequal: |
| 206 | case Builtin::BI__builtin_isless: |
| 207 | case Builtin::BI__builtin_islessequal: |
| 208 | case Builtin::BI__builtin_islessgreater: |
| 209 | case Builtin::BI__builtin_isunordered: { |
| 210 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 211 | // floating point values. |
| 212 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
| 213 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
| 214 | |
| 215 | switch (BuiltinID) { |
| 216 | default: assert(0 && "Unknown ordered comparison"); |
| 217 | case Builtin::BI__builtin_isgreater: |
| 218 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 219 | break; |
| 220 | case Builtin::BI__builtin_isgreaterequal: |
| 221 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 222 | break; |
| 223 | case Builtin::BI__builtin_isless: |
| 224 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 225 | break; |
| 226 | case Builtin::BI__builtin_islessequal: |
| 227 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 228 | break; |
| 229 | case Builtin::BI__builtin_islessgreater: |
| 230 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 231 | break; |
| 232 | case Builtin::BI__builtin_isunordered: |
| 233 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 234 | break; |
| 235 | } |
| 236 | // ZExt bool to int type. |
| 237 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()), |
| 238 | "tmp")); |
| 239 | } |
Nate Begeman | 4efe459 | 2008-02-06 00:02:50 +0000 | [diff] [blame] | 240 | case Builtin::BI__builtin_alloca: |
| 241 | return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, |
| 242 | EmitScalarExpr(E->getArg(0)), |
| 243 | "tmp")); |
Anders Carlsson | 89799cf | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 244 | } |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 245 | return RValue::get(0); |
| 246 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 247 | |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 248 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
| 249 | const CallExpr *E) { |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 250 | |
| 251 | llvm::SmallVector<Value*, 4> Ops; |
| 252 | |
| 253 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 254 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 255 | |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 256 | switch (BuiltinID) { |
Anders Carlsson | 46a26b0 | 2007-12-09 23:39:18 +0000 | [diff] [blame] | 257 | default: return 0; |
| 258 | case X86::BI__builtin_ia32_mulps: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 259 | return Builder.CreateMul(Ops[0], Ops[1], "mulps"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 260 | case X86::BI__builtin_ia32_mulpd: |
| 261 | return Builder.CreateMul(Ops[0], Ops[1], "mulpd"); |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 262 | case X86::BI__builtin_ia32_pand: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 263 | case X86::BI__builtin_ia32_pand128: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 264 | return Builder.CreateAnd(Ops[0], Ops[1], "pand"); |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 265 | case X86::BI__builtin_ia32_por: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 266 | case X86::BI__builtin_ia32_por128: |
| 267 | return Builder.CreateOr(Ops[0], Ops[1], "por"); |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 268 | case X86::BI__builtin_ia32_pxor: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 269 | case X86::BI__builtin_ia32_pxor128: |
| 270 | return Builder.CreateXor(Ops[0], Ops[1], "pxor"); |
| 271 | case X86::BI__builtin_ia32_pandn: |
| 272 | case X86::BI__builtin_ia32_pandn128: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 273 | Ops[0] = Builder.CreateNot(Ops[0], "tmp"); |
| 274 | return Builder.CreateAnd(Ops[0], Ops[1], "pandn"); |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 275 | case X86::BI__builtin_ia32_paddb: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 276 | case X86::BI__builtin_ia32_paddb128: |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 277 | case X86::BI__builtin_ia32_paddd: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 278 | case X86::BI__builtin_ia32_paddd128: |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 279 | case X86::BI__builtin_ia32_paddq: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 280 | case X86::BI__builtin_ia32_paddq128: |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 281 | case X86::BI__builtin_ia32_paddw: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 282 | case X86::BI__builtin_ia32_paddw128: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 283 | case X86::BI__builtin_ia32_addps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 284 | case X86::BI__builtin_ia32_addpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 285 | return Builder.CreateAdd(Ops[0], Ops[1], "add"); |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 286 | case X86::BI__builtin_ia32_psubb: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 287 | case X86::BI__builtin_ia32_psubb128: |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 288 | case X86::BI__builtin_ia32_psubd: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 289 | case X86::BI__builtin_ia32_psubd128: |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 290 | case X86::BI__builtin_ia32_psubq: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 291 | case X86::BI__builtin_ia32_psubq128: |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 292 | case X86::BI__builtin_ia32_psubw: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 293 | case X86::BI__builtin_ia32_psubw128: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 294 | case X86::BI__builtin_ia32_subps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 295 | case X86::BI__builtin_ia32_subpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 296 | return Builder.CreateSub(Ops[0], Ops[1], "sub"); |
| 297 | case X86::BI__builtin_ia32_divps: |
| 298 | return Builder.CreateFDiv(Ops[0], Ops[1], "divps"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 299 | case X86::BI__builtin_ia32_divpd: |
| 300 | return Builder.CreateFDiv(Ops[0], Ops[1], "divpd"); |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 301 | case X86::BI__builtin_ia32_pmullw: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 302 | case X86::BI__builtin_ia32_pmullw128: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 303 | return Builder.CreateMul(Ops[0], Ops[1], "pmul"); |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 304 | case X86::BI__builtin_ia32_punpckhbw: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 305 | return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 306 | "punpckhbw"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 307 | case X86::BI__builtin_ia32_punpckhbw128: |
| 308 | return EmitShuffleVector(Ops[0], Ops[1], 8, 24, 9, 25, 10, 26, 11, 27, |
| 309 | 12, 28, 13, 29, 14, 30, 15, 31, |
| 310 | "punpckhbw"); |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 311 | case X86::BI__builtin_ia32_punpckhwd: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 312 | return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhwd"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 313 | case X86::BI__builtin_ia32_punpckhwd128: |
| 314 | return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15, |
| 315 | "punpckhwd"); |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 316 | case X86::BI__builtin_ia32_punpckhdq: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 317 | return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhdq"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 318 | case X86::BI__builtin_ia32_punpckhdq128: |
| 319 | return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhdq"); |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 320 | case X86::BI__builtin_ia32_punpcklbw: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 321 | return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 322 | "punpcklbw"); |
| 323 | case X86::BI__builtin_ia32_punpcklwd: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 324 | return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpcklwd"); |
Anders Carlsson | db83230 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 325 | case X86::BI__builtin_ia32_punpckldq: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 326 | return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpckldq"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 327 | case X86::BI__builtin_ia32_punpckldq128: |
| 328 | return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpckldq"); |
| 329 | case X86::BI__builtin_ia32_pslldi128: |
| 330 | case X86::BI__builtin_ia32_psllqi128: |
| 331 | case X86::BI__builtin_ia32_psllwi128: |
| 332 | case X86::BI__builtin_ia32_psradi128: |
| 333 | case X86::BI__builtin_ia32_psrawi128: |
| 334 | case X86::BI__builtin_ia32_psrldi128: |
| 335 | case X86::BI__builtin_ia32_psrlqi128: |
| 336 | case X86::BI__builtin_ia32_psrlwi128: { |
| 337 | Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); |
| 338 | const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); |
| 339 | llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); |
| 340 | Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), |
| 341 | Ops[1], Zero, "insert"); |
| 342 | Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); |
| 343 | const char *name = 0; |
| 344 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 345 | |
| 346 | switch (BuiltinID) { |
| 347 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 348 | case X86::BI__builtin_ia32_pslldi128: |
| 349 | name = "pslldi"; |
| 350 | ID = Intrinsic::x86_sse2_psll_d; |
| 351 | break; |
| 352 | case X86::BI__builtin_ia32_psllqi128: |
| 353 | name = "psllqi"; |
| 354 | ID = Intrinsic::x86_sse2_psll_q; |
| 355 | break; |
| 356 | case X86::BI__builtin_ia32_psllwi128: |
| 357 | name = "psllwi"; |
| 358 | ID = Intrinsic::x86_sse2_psll_w; |
| 359 | break; |
| 360 | case X86::BI__builtin_ia32_psradi128: |
| 361 | name = "psradi"; |
| 362 | ID = Intrinsic::x86_sse2_psra_d; |
| 363 | break; |
| 364 | case X86::BI__builtin_ia32_psrawi128: |
| 365 | name = "psrawi"; |
| 366 | ID = Intrinsic::x86_sse2_psra_w; |
| 367 | break; |
| 368 | case X86::BI__builtin_ia32_psrldi128: |
| 369 | name = "psrldi"; |
| 370 | ID = Intrinsic::x86_sse2_psrl_d; |
| 371 | break; |
| 372 | case X86::BI__builtin_ia32_psrlqi128: |
| 373 | name = "psrlqi"; |
| 374 | ID = Intrinsic::x86_sse2_psrl_q; |
| 375 | break; |
| 376 | case X86::BI__builtin_ia32_psrlwi128: |
| 377 | name = "psrlwi"; |
| 378 | ID = Intrinsic::x86_sse2_psrl_w; |
| 379 | break; |
| 380 | } |
| 381 | llvm::Function *F = CGM.getIntrinsic(ID); |
| 382 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
| 383 | } |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 384 | case X86::BI__builtin_ia32_pslldi: |
| 385 | case X86::BI__builtin_ia32_psllqi: |
| 386 | case X86::BI__builtin_ia32_psllwi: |
| 387 | case X86::BI__builtin_ia32_psradi: |
| 388 | case X86::BI__builtin_ia32_psrawi: |
| 389 | case X86::BI__builtin_ia32_psrldi: |
| 390 | case X86::BI__builtin_ia32_psrlqi: |
| 391 | case X86::BI__builtin_ia32_psrlwi: { |
| 392 | Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); |
| 393 | const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1); |
| 394 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 395 | const char *name = 0; |
| 396 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 397 | |
| 398 | switch (BuiltinID) { |
| 399 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 400 | case X86::BI__builtin_ia32_pslldi: |
| 401 | name = "pslldi"; |
| 402 | ID = Intrinsic::x86_mmx_psll_d; |
| 403 | break; |
| 404 | case X86::BI__builtin_ia32_psllqi: |
| 405 | name = "psllqi"; |
| 406 | ID = Intrinsic::x86_mmx_psll_q; |
| 407 | break; |
| 408 | case X86::BI__builtin_ia32_psllwi: |
| 409 | name = "psllwi"; |
| 410 | ID = Intrinsic::x86_mmx_psll_w; |
| 411 | break; |
| 412 | case X86::BI__builtin_ia32_psradi: |
| 413 | name = "psradi"; |
| 414 | ID = Intrinsic::x86_mmx_psra_d; |
| 415 | break; |
| 416 | case X86::BI__builtin_ia32_psrawi: |
| 417 | name = "psrawi"; |
| 418 | ID = Intrinsic::x86_mmx_psra_w; |
| 419 | break; |
| 420 | case X86::BI__builtin_ia32_psrldi: |
| 421 | name = "psrldi"; |
| 422 | ID = Intrinsic::x86_mmx_psrl_d; |
| 423 | break; |
| 424 | case X86::BI__builtin_ia32_psrlqi: |
| 425 | name = "psrlqi"; |
| 426 | ID = Intrinsic::x86_mmx_psrl_q; |
| 427 | break; |
| 428 | case X86::BI__builtin_ia32_psrlwi: |
| 429 | name = "psrlwi"; |
| 430 | ID = Intrinsic::x86_mmx_psrl_w; |
| 431 | break; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 432 | case X86::BI__builtin_ia32_pslldi128: |
| 433 | name = "pslldi"; |
| 434 | ID = Intrinsic::x86_sse2_psll_d; |
| 435 | break; |
| 436 | case X86::BI__builtin_ia32_psllqi128: |
| 437 | name = "psllqi"; |
| 438 | ID = Intrinsic::x86_sse2_psll_q; |
| 439 | break; |
| 440 | case X86::BI__builtin_ia32_psllwi128: |
| 441 | name = "psllwi"; |
| 442 | ID = Intrinsic::x86_sse2_psll_w; |
| 443 | break; |
| 444 | case X86::BI__builtin_ia32_psradi128: |
| 445 | name = "psradi"; |
| 446 | ID = Intrinsic::x86_sse2_psra_d; |
| 447 | break; |
| 448 | case X86::BI__builtin_ia32_psrawi128: |
| 449 | name = "psrawi"; |
| 450 | ID = Intrinsic::x86_sse2_psra_w; |
| 451 | break; |
| 452 | case X86::BI__builtin_ia32_psrldi128: |
| 453 | name = "psrldi"; |
| 454 | ID = Intrinsic::x86_sse2_psrl_d; |
| 455 | break; |
| 456 | case X86::BI__builtin_ia32_psrlqi128: |
| 457 | name = "psrlqi"; |
| 458 | ID = Intrinsic::x86_sse2_psrl_q; |
| 459 | break; |
| 460 | case X86::BI__builtin_ia32_psrlwi128: |
| 461 | name = "psrlwi"; |
| 462 | ID = Intrinsic::x86_sse2_psrl_w; |
| 463 | break; |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 464 | } |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 465 | llvm::Function *F = CGM.getIntrinsic(ID); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 466 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
| 467 | } |
| 468 | case X86::BI__builtin_ia32_pshufd: { |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 469 | unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue(); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 470 | return EmitShuffleVector(Ops[0], Ops[0], |
Anders Carlsson | 4e4ee21 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 471 | i & 0x3, (i & 0xc) >> 2, |
| 472 | (i & 0x30) >> 4, (i & 0xc0) >> 6, |
| 473 | "pshufd"); |
| 474 | } |
Anders Carlsson | 6086bbd | 2007-12-15 21:23:30 +0000 | [diff] [blame] | 475 | case X86::BI__builtin_ia32_vec_init_v4hi: |
| 476 | case X86::BI__builtin_ia32_vec_init_v8qi: |
| 477 | case X86::BI__builtin_ia32_vec_init_v2si: |
| 478 | return EmitVector(&Ops[0], Ops.size()); |
| 479 | case X86::BI__builtin_ia32_vec_ext_v2si: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 480 | case X86::BI__builtin_ia32_vec_ext_v2di: |
| 481 | case X86::BI__builtin_ia32_vec_ext_v4sf: |
| 482 | case X86::BI__builtin_ia32_vec_ext_v4si: |
| 483 | case X86::BI__builtin_ia32_vec_ext_v2df: |
Anders Carlsson | 6086bbd | 2007-12-15 21:23:30 +0000 | [diff] [blame] | 484 | return Builder.CreateExtractElement(Ops[0], Ops[1], "result"); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 485 | case X86::BI__builtin_ia32_cmpordss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 486 | case X86::BI__builtin_ia32_cmpordsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 487 | case X86::BI__builtin_ia32_cmpunordss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 488 | case X86::BI__builtin_ia32_cmpunordsd: |
| 489 | case X86::BI__builtin_ia32_cmpeqss: |
| 490 | case X86::BI__builtin_ia32_cmpeqsd: |
| 491 | case X86::BI__builtin_ia32_cmpltss: |
| 492 | case X86::BI__builtin_ia32_cmpltsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 493 | case X86::BI__builtin_ia32_cmpless: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 494 | case X86::BI__builtin_ia32_cmplesd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 495 | case X86::BI__builtin_ia32_cmpneqss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 496 | case X86::BI__builtin_ia32_cmpneqsd: |
| 497 | case X86::BI__builtin_ia32_cmpnltss: |
| 498 | case X86::BI__builtin_ia32_cmpnltsd: |
| 499 | case X86::BI__builtin_ia32_cmpnless: |
| 500 | case X86::BI__builtin_ia32_cmpnlesd: { |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 501 | unsigned i = 0; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 502 | const char *name = 0; |
| 503 | switch (BuiltinID) { |
| 504 | default: assert(0 && "Unknown compare builtin!"); |
| 505 | case X86::BI__builtin_ia32_cmpeqss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 506 | case X86::BI__builtin_ia32_cmpeqsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 507 | i = 0; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 508 | name = "cmpeq"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 509 | break; |
| 510 | case X86::BI__builtin_ia32_cmpltss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 511 | case X86::BI__builtin_ia32_cmpltsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 512 | i = 1; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 513 | name = "cmplt"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 514 | break; |
| 515 | case X86::BI__builtin_ia32_cmpless: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 516 | case X86::BI__builtin_ia32_cmplesd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 517 | i = 2; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 518 | name = "cmple"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 519 | break; |
| 520 | case X86::BI__builtin_ia32_cmpunordss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 521 | case X86::BI__builtin_ia32_cmpunordsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 522 | i = 3; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 523 | name = "cmpunord"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 524 | break; |
| 525 | case X86::BI__builtin_ia32_cmpneqss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 526 | case X86::BI__builtin_ia32_cmpneqsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 527 | i = 4; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 528 | name = "cmpneq"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 529 | break; |
| 530 | case X86::BI__builtin_ia32_cmpnltss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 531 | case X86::BI__builtin_ia32_cmpnltsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 532 | i = 5; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 533 | name = "cmpntl"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 534 | break; |
| 535 | case X86::BI__builtin_ia32_cmpnless: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 536 | case X86::BI__builtin_ia32_cmpnlesd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 537 | i = 6; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 538 | name = "cmpnle"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 539 | break; |
| 540 | case X86::BI__builtin_ia32_cmpordss: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 541 | case X86::BI__builtin_ia32_cmpordsd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 542 | i = 7; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 543 | name = "cmpord"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 544 | break; |
| 545 | } |
| 546 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 547 | llvm::Function *F; |
| 548 | if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == |
| 549 | llvm::Type::FloatTy) |
| 550 | F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss); |
| 551 | else |
| 552 | F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd); |
| 553 | |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 554 | Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 555 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
| 556 | } |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 557 | case X86::BI__builtin_ia32_ldmxcsr: { |
| 558 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
| 559 | Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); |
| 560 | Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 561 | Builder.CreateStore(Ops[0], Tmp); |
| 562 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame^] | 563 | Builder.CreateBitCast(Tmp, PtrTy)); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 564 | } |
| 565 | case X86::BI__builtin_ia32_stmxcsr: { |
| 566 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
| 567 | Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); |
| 568 | Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 569 | One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame^] | 570 | Builder.CreateBitCast(Tmp, PtrTy)); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 571 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 572 | } |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 573 | case X86::BI__builtin_ia32_cmpordps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 574 | case X86::BI__builtin_ia32_cmpordpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 575 | case X86::BI__builtin_ia32_cmpunordps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 576 | case X86::BI__builtin_ia32_cmpunordpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 577 | case X86::BI__builtin_ia32_cmpeqps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 578 | case X86::BI__builtin_ia32_cmpeqpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 579 | case X86::BI__builtin_ia32_cmpltps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 580 | case X86::BI__builtin_ia32_cmpltpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 581 | case X86::BI__builtin_ia32_cmpleps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 582 | case X86::BI__builtin_ia32_cmplepd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 583 | case X86::BI__builtin_ia32_cmpneqps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 584 | case X86::BI__builtin_ia32_cmpneqpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 585 | case X86::BI__builtin_ia32_cmpngtps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 586 | case X86::BI__builtin_ia32_cmpngtpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 587 | case X86::BI__builtin_ia32_cmpnltps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 588 | case X86::BI__builtin_ia32_cmpnltpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 589 | case X86::BI__builtin_ia32_cmpgtps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 590 | case X86::BI__builtin_ia32_cmpgtpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 591 | case X86::BI__builtin_ia32_cmpgeps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 592 | case X86::BI__builtin_ia32_cmpgepd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 593 | case X86::BI__builtin_ia32_cmpngeps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 594 | case X86::BI__builtin_ia32_cmpngepd: |
| 595 | case X86::BI__builtin_ia32_cmpnleps: |
| 596 | case X86::BI__builtin_ia32_cmpnlepd: { |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 597 | unsigned i = 0; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 598 | const char *name = 0; |
| 599 | bool ShouldSwap = false; |
| 600 | switch (BuiltinID) { |
| 601 | default: assert(0 && "Unknown compare builtin!"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 602 | case X86::BI__builtin_ia32_cmpeqps: |
| 603 | case X86::BI__builtin_ia32_cmpeqpd: i = 0; name = "cmpeq"; break; |
| 604 | case X86::BI__builtin_ia32_cmpltps: |
| 605 | case X86::BI__builtin_ia32_cmpltpd: i = 1; name = "cmplt"; break; |
| 606 | case X86::BI__builtin_ia32_cmpleps: |
| 607 | case X86::BI__builtin_ia32_cmplepd: i = 2; name = "cmple"; break; |
| 608 | case X86::BI__builtin_ia32_cmpunordps: |
| 609 | case X86::BI__builtin_ia32_cmpunordpd: i = 3; name = "cmpunord"; break; |
| 610 | case X86::BI__builtin_ia32_cmpneqps: |
| 611 | case X86::BI__builtin_ia32_cmpneqpd: i = 4; name = "cmpneq"; break; |
| 612 | case X86::BI__builtin_ia32_cmpnltps: |
| 613 | case X86::BI__builtin_ia32_cmpnltpd: i = 5; name = "cmpntl"; break; |
| 614 | case X86::BI__builtin_ia32_cmpnleps: |
| 615 | case X86::BI__builtin_ia32_cmpnlepd: i = 6; name = "cmpnle"; break; |
| 616 | case X86::BI__builtin_ia32_cmpordps: |
| 617 | case X86::BI__builtin_ia32_cmpordpd: i = 7; name = "cmpord"; break; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 618 | case X86::BI__builtin_ia32_cmpgtps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 619 | case X86::BI__builtin_ia32_cmpgtpd: |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 620 | ShouldSwap = true; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 621 | i = 1; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 622 | name = "cmpgt"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 623 | break; |
| 624 | case X86::BI__builtin_ia32_cmpgeps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 625 | case X86::BI__builtin_ia32_cmpgepd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 626 | i = 2; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 627 | name = "cmpge"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 628 | ShouldSwap = true; |
| 629 | break; |
| 630 | case X86::BI__builtin_ia32_cmpngtps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 631 | case X86::BI__builtin_ia32_cmpngtpd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 632 | i = 5; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 633 | name = "cmpngt"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 634 | ShouldSwap = true; |
| 635 | break; |
| 636 | case X86::BI__builtin_ia32_cmpngeps: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 637 | case X86::BI__builtin_ia32_cmpngepd: |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 638 | i = 6; |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 639 | name = "cmpnge"; |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 640 | ShouldSwap = true; |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | if (ShouldSwap) |
| 645 | std::swap(Ops[0], Ops[1]); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 646 | |
| 647 | llvm::Function *F; |
| 648 | if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() == |
| 649 | llvm::Type::FloatTy) |
| 650 | F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps); |
| 651 | else |
| 652 | F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 653 | |
| 654 | Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i)); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 655 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
| 656 | } |
| 657 | case X86::BI__builtin_ia32_movss: |
| 658 | return EmitShuffleVector(Ops[0], Ops[1], 4, 1, 2, 3, "movss"); |
Torok Edwin | 730f2c1 | 2008-04-04 06:16:25 +0000 | [diff] [blame] | 659 | case X86::BI__builtin_ia32_shufps: { |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 660 | unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue(); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 661 | return EmitShuffleVector(Ops[0], Ops[1], |
| 662 | i & 0x3, (i & 0xc) >> 2, |
| 663 | ((i & 0x30) >> 4) + 4, |
| 664 | ((i & 0x60) >> 6) + 4, "shufps"); |
Torok Edwin | 730f2c1 | 2008-04-04 06:16:25 +0000 | [diff] [blame] | 665 | } |
Nate Begeman | dbebb73 | 2008-04-03 19:58:06 +0000 | [diff] [blame] | 666 | case X86::BI__builtin_ia32_punpcklbw128: |
| 667 | return EmitShuffleVector(Ops[0], Ops[1], 0, 16, 1, 17, 2, 18, 3, 19, |
| 668 | 4, 20, 5, 21, 6, 22, 7, 23, |
| 669 | "punpcklbw"); |
| 670 | case X86::BI__builtin_ia32_punpcklwd128: |
| 671 | return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11, |
| 672 | "punpcklwd"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 673 | case X86::BI__builtin_ia32_movlhps: |
| 674 | return EmitShuffleVector(Ops[0], Ops[1], 0, 1, 4, 5, "movlhps"); |
| 675 | case X86::BI__builtin_ia32_movhlps: |
| 676 | return EmitShuffleVector(Ops[0], Ops[1], 6, 7, 2, 3, "movhlps"); |
| 677 | case X86::BI__builtin_ia32_unpckhps: |
| 678 | return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "unpckhps"); |
| 679 | case X86::BI__builtin_ia32_unpcklps: |
| 680 | return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "unpcklps"); |
| 681 | case X86::BI__builtin_ia32_movqv4si: { |
| 682 | llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); |
| 683 | return Builder.CreateBitCast(Ops[0], Ty); |
| 684 | } |
| 685 | case X86::BI__builtin_ia32_loadlps: |
| 686 | case X86::BI__builtin_ia32_loadhps: { |
| 687 | // FIXME: This should probably be represented as |
| 688 | // shuffle (dst, (v4f32 (insert undef, (load i64), 0)), shuf mask hi/lo) |
| 689 | const llvm::Type *EltTy = llvm::Type::DoubleTy; |
| 690 | const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); |
| 691 | const llvm::Type *OrigTy = Ops[0]->getType(); |
| 692 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlps ? 0 : 1; |
| 693 | llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); |
| 694 | Ops[1] = Builder.CreateBitCast(Ops[1], llvm::PointerType::getUnqual(EltTy)); |
| 695 | Ops[1] = Builder.CreateLoad(Ops[1], "tmp"); |
| 696 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 697 | Ops[0] = Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadps"); |
| 698 | return Builder.CreateBitCast(Ops[0], OrigTy, "loadps"); |
| 699 | } |
| 700 | case X86::BI__builtin_ia32_storehps: |
| 701 | case X86::BI__builtin_ia32_storelps: { |
| 702 | const llvm::Type *EltTy = llvm::Type::Int64Ty; |
| 703 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); |
| 704 | llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); |
| 705 | |
| 706 | // cast val v2i64 |
| 707 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
| 708 | |
| 709 | // extract (0, 1) |
| 710 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
| 711 | llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); |
| 712 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 713 | |
| 714 | // cast pointer to i64 & store |
| 715 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
| 716 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 717 | } |
| 718 | case X86::BI__builtin_ia32_loadlv4si: { |
| 719 | // load i64 |
| 720 | const llvm::Type *EltTy = llvm::Type::Int64Ty; |
| 721 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); |
| 722 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
| 723 | Ops[0] = Builder.CreateLoad(Ops[0], "load"); |
| 724 | |
| 725 | // scalar to vector: insert i64 into 2 x i64 undef |
| 726 | llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); |
| 727 | llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); |
| 728 | Ops[0] = Builder.CreateInsertElement(llvm::UndefValue::get(VecTy), |
| 729 | Ops[0], Zero, "s2v"); |
| 730 | |
| 731 | // shuffle into zero vector. |
| 732 | std::vector<llvm::Constant *>Elts; |
| 733 | Elts.resize(2, llvm::ConstantInt::get(EltTy, 0)); |
| 734 | llvm::Value *ZV = ConstantVector::get(Elts); |
| 735 | Ops[0] = EmitShuffleVector(ZV, Ops[0], 2, 1, "loadl"); |
| 736 | |
| 737 | // bitcast to result. |
| 738 | return Builder.CreateBitCast(Ops[0], |
| 739 | llvm::VectorType::get(llvm::Type::Int32Ty, 4)); |
| 740 | } |
| 741 | case X86::BI__builtin_ia32_andps: |
| 742 | case X86::BI__builtin_ia32_andpd: |
| 743 | case X86::BI__builtin_ia32_andnps: |
| 744 | case X86::BI__builtin_ia32_andnpd: |
| 745 | case X86::BI__builtin_ia32_orps: |
| 746 | case X86::BI__builtin_ia32_orpd: |
| 747 | case X86::BI__builtin_ia32_xorpd: |
| 748 | case X86::BI__builtin_ia32_xorps: { |
| 749 | const llvm::Type *ITy = llvm::VectorType::get(llvm::Type::Int32Ty, 4); |
| 750 | const llvm::Type *FTy = Ops[0]->getType(); |
| 751 | Ops[0] = Builder.CreateBitCast(Ops[0], ITy, "bitcast"); |
| 752 | Ops[1] = Builder.CreateBitCast(Ops[1], ITy, "bitcast"); |
| 753 | switch (BuiltinID) { |
| 754 | case X86::BI__builtin_ia32_andps: |
| 755 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andps"); |
| 756 | break; |
| 757 | case X86::BI__builtin_ia32_andpd: |
| 758 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andpd"); |
| 759 | break; |
| 760 | case X86::BI__builtin_ia32_andnps: |
| 761 | Ops[0] = Builder.CreateNot(Ops[0], "not"); |
| 762 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnps"); |
| 763 | break; |
| 764 | case X86::BI__builtin_ia32_andnpd: |
| 765 | Ops[0] = Builder.CreateNot(Ops[0], "not"); |
| 766 | Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnpd"); |
| 767 | break; |
| 768 | case X86::BI__builtin_ia32_orps: |
| 769 | Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orps"); |
| 770 | break; |
| 771 | case X86::BI__builtin_ia32_orpd: |
| 772 | Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orpd"); |
| 773 | break; |
| 774 | case X86::BI__builtin_ia32_xorps: |
| 775 | Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorps"); |
| 776 | break; |
| 777 | case X86::BI__builtin_ia32_xorpd: |
| 778 | Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorpd"); |
| 779 | break; |
| 780 | } |
| 781 | return Builder.CreateBitCast(Ops[0], FTy, "bitcast"); |
| 782 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 786 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
| 787 | const CallExpr *E) { |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 788 | switch (BuiltinID) { |
Anders Carlsson | 46a26b0 | 2007-12-09 23:39:18 +0000 | [diff] [blame] | 789 | default: return 0; |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 790 | } |
| 791 | } |