Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 1 | //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Anders Carlsson and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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 | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 16 | #include "clang/Basic/TargetInfo.h" |
Chris Lattner | ab862cc | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/Builtins.h" |
| 19 | #include "clang/AST/Expr.h" |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 20 | #include "clang/AST/TargetBuiltins.h" |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
Chris Lattner | 02c60f5 | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 22 | #include "llvm/Function.h" |
Anders Carlsson | cebb8d6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 23 | #include "llvm/Intrinsics.h" |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using namespace CodeGen; |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 28 | RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { |
| 29 | switch (BuiltinID) { |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 30 | default: { |
Chris Lattner | 02c60f5 | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 31 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID)) |
| 32 | return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), E); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 33 | |
| 34 | // See if we have a target specific intrinsic. |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 35 | Intrinsic::ID IntrinsicID; |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 36 | const char *TargetPrefix = Target.getTargetPrefix(); |
| 37 | const char *BuiltinName = getContext().BuiltinInfo.GetName(BuiltinID); |
| 38 | #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 39 | #include "llvm/Intrinsics.gen" |
| 40 | #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 41 | |
| 42 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 43 | SmallVector<Value*, 16> Args; |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 45 | Function *F = Intrinsic::getDeclaration(&CGM.getModule(), IntrinsicID); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 46 | const llvm::FunctionType *FTy = F->getFunctionType(); |
| 47 | |
| 48 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 49 | Value *ArgValue = EmitScalarExpr(E->getArg(i)); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 50 | |
| 51 | // If the intrinsic arg type is different from the builtin arg type |
| 52 | // we need to do a bit cast. |
| 53 | const llvm::Type *PTy = FTy->getParamType(i); |
| 54 | if (PTy != ArgValue->getType()) { |
| 55 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 56 | "Must be able to losslessly bit cast to param"); |
| 57 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 58 | } |
| 59 | |
| 60 | Args.push_back(ArgValue); |
| 61 | } |
| 62 | |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 63 | Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size()); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 64 | QualType BuiltinRetType = E->getType(); |
| 65 | |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 66 | const llvm::Type *RetTy = llvm::Type::VoidTy; |
| 67 | if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 68 | |
| 69 | if (RetTy != V->getType()) { |
| 70 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 71 | "Must be able to losslessly bit cast result type"); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 72 | V = Builder.CreateBitCast(V, RetTy); |
| 73 | } |
| 74 | |
| 75 | return RValue::get(V); |
| 76 | } |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 77 | |
| 78 | // See if we have a target specific builtin that needs to be lowered. |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 79 | Value *V = 0; |
Chris Lattner | 02c60f5 | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 80 | |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 81 | if (strcmp(TargetPrefix, "x86") == 0) |
| 82 | V = EmitX86BuiltinExpr(BuiltinID, E); |
| 83 | else if (strcmp(TargetPrefix, "ppc") == 0) |
| 84 | V = EmitPPCBuiltinExpr(BuiltinID, E); |
| 85 | |
| 86 | if (V) |
| 87 | return RValue::get(V); |
| 88 | |
Chris Lattner | e8f4963 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 89 | WarnUnsupported(E, "builtin function"); |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 90 | |
| 91 | // Unknown builtin, for now just dump it out and return undef. |
| 92 | if (hasAggregateLLVMType(E->getType())) |
| 93 | return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType()))); |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 94 | return RValue::get(UndefValue::get(ConvertType(E->getType()))); |
Anders Carlsson | 6f6c648 | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 95 | } |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 96 | case Builtin::BI__builtin___CFStringMakeConstantString: { |
| 97 | const Expr *Arg = E->getArg(0); |
| 98 | |
Anders Carlsson | 783e143 | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 99 | while (1) { |
| 100 | if (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg)) |
| 101 | Arg = PE->getSubExpr(); |
| 102 | else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Arg)) |
| 103 | Arg = CE->getSubExpr(); |
| 104 | else |
| 105 | break; |
| 106 | } |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 107 | |
| 108 | const StringLiteral *Literal = cast<StringLiteral>(Arg); |
| 109 | std::string S(Literal->getStrData(), Literal->getByteLength()); |
| 110 | |
| 111 | return RValue::get(CGM.GetAddrOfConstantCFString(S)); |
Anders Carlsson | cebb8d6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 112 | } |
| 113 | case Builtin::BI__builtin_va_start: |
| 114 | case Builtin::BI__builtin_va_end: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 115 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | cebb8d6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 116 | const llvm::Type *DestType = llvm::PointerType::get(llvm::Type::Int8Ty); |
| 117 | if (ArgValue->getType() != DestType) |
| 118 | ArgValue = Builder.CreateBitCast(ArgValue, DestType, |
| 119 | ArgValue->getNameStart()); |
| 120 | |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 121 | Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_start) ? |
| 122 | Intrinsic::vastart : Intrinsic::vaend; |
| 123 | Value *F = Intrinsic::getDeclaration(&CGM.getModule(), inst); |
| 124 | Value *V = Builder.CreateCall(F, ArgValue); |
Anders Carlsson | cebb8d6 | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 125 | |
| 126 | return RValue::get(V); |
| 127 | } |
Anders Carlsson | 4043840 | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 128 | case Builtin::BI__builtin_classify_type: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 129 | APSInt Result(32); |
Anders Carlsson | 4043840 | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 130 | if (!E->isBuiltinClassifyType(Result)) |
| 131 | assert(0 && "Expr not __builtin_classify_type!"); |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 132 | return RValue::get(ConstantInt::get(Result)); |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 133 | } |
Anders Carlsson | 783e143 | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 134 | case Builtin::BI__builtin_constant_p: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 135 | APSInt Result(32); |
Anders Carlsson | 783e143 | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 136 | // FIXME: Analyze the parameter and check if it is a constant. |
| 137 | Result = 0; |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 138 | return RValue::get(ConstantInt::get(Result)); |
Anders Carlsson | 783e143 | 2007-11-01 00:39:26 +0000 | [diff] [blame] | 139 | } |
Anders Carlsson | e79dbe2 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 140 | case Builtin::BI__builtin_abs: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 141 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | e79dbe2 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 142 | |
| 143 | llvm::BinaryOperator *NegOp = |
| 144 | Builder.CreateNeg(ArgValue, (ArgValue->getName() + "neg").c_str()); |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 145 | Value *CmpResult = |
Anders Carlsson | e79dbe2 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 146 | Builder.CreateICmpSGE(ArgValue, NegOp->getOperand(0), "abscond"); |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 147 | Value *Result = |
Anders Carlsson | e79dbe2 | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 148 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
| 149 | |
| 150 | return RValue::get(Result); |
| 151 | } |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 152 | case Builtin::BI__builtin_expect: |
| 153 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
Anders Carlsson | 5611800 | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 154 | case Builtin::BI__builtin_bswap32: |
| 155 | case Builtin::BI__builtin_bswap64: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 156 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | 5611800 | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 157 | const llvm::Type *ArgType = ArgValue->getType(); |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 158 | Value *F = Intrinsic::getDeclaration(&CGM.getModule(), Intrinsic::bswap, |
| 159 | &ArgType, 1); |
| 160 | return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); |
Anders Carlsson | 5611800 | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 161 | } |
Anders Carlsson | a8897f0 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 162 | case Builtin::BI__builtin_inff: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 163 | APFloat f(APFloat::IEEEsingle, APFloat::fcInfinity, false); |
| 164 | return RValue::get(ConstantFP::get(llvm::Type::FloatTy, f)); |
Anders Carlsson | a8897f0 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 165 | } |
| 166 | case Builtin::BI__builtin_inf: |
| 167 | // FIXME: mapping long double onto double. |
| 168 | case Builtin::BI__builtin_infl: { |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 169 | APFloat f(APFloat::IEEEdouble, APFloat::fcInfinity, false); |
| 170 | return RValue::get(ConstantFP::get(llvm::Type::DoubleTy, f)); |
Anders Carlsson | a8897f0 | 2007-12-05 07:22:48 +0000 | [diff] [blame] | 171 | } |
Anders Carlsson | 4043840 | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 172 | } |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 173 | return RValue::get(0); |
| 174 | } |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 175 | |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 176 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
| 177 | const CallExpr *E) { |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 178 | |
| 179 | llvm::SmallVector<Value*, 4> Ops; |
| 180 | |
| 181 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 182 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 183 | |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 184 | switch (BuiltinID) { |
Anders Carlsson | 0a35a81 | 2007-12-09 23:39:18 +0000 | [diff] [blame] | 185 | default: return 0; |
| 186 | case X86::BI__builtin_ia32_mulps: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 187 | return Builder.CreateMul(Ops[0], Ops[1], "mulps"); |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 188 | case X86::BI__builtin_ia32_pand: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 189 | return Builder.CreateAnd(Ops[0], Ops[1], "pand"); |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 190 | case X86::BI__builtin_ia32_por: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 191 | return Builder.CreateAnd(Ops[0], Ops[1], "por"); |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 192 | case X86::BI__builtin_ia32_pxor: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 193 | return Builder.CreateAnd(Ops[0], Ops[1], "pxor"); |
Chris Lattner | 7037629 | 2007-12-11 04:33:00 +0000 | [diff] [blame] | 194 | case X86::BI__builtin_ia32_pandn: { |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 195 | Ops[0] = Builder.CreateNot(Ops[0], "tmp"); |
| 196 | return Builder.CreateAnd(Ops[0], Ops[1], "pandn"); |
Chris Lattner | 7037629 | 2007-12-11 04:33:00 +0000 | [diff] [blame] | 197 | } |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 198 | case X86::BI__builtin_ia32_paddb: |
| 199 | case X86::BI__builtin_ia32_paddd: |
| 200 | case X86::BI__builtin_ia32_paddq: |
| 201 | case X86::BI__builtin_ia32_paddw: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 202 | return Builder.CreateAdd(Ops[0], Ops[1], "padd"); |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 203 | case X86::BI__builtin_ia32_psubb: |
| 204 | case X86::BI__builtin_ia32_psubd: |
| 205 | case X86::BI__builtin_ia32_psubq: |
| 206 | case X86::BI__builtin_ia32_psubw: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 207 | return Builder.CreateSub(Ops[0], Ops[1], "psub"); |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 208 | case X86::BI__builtin_ia32_pmullw: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 209 | return Builder.CreateMul(Ops[0], Ops[1], "pmul"); |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 210 | case X86::BI__builtin_ia32_punpckhbw: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 211 | return EmitShuffleVector(Ops[0], Ops[1], |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 212 | 4, 12, 5, 13, 6, 14, 7, 15, |
| 213 | "punpckhbw"); |
| 214 | case X86::BI__builtin_ia32_punpckhwd: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 215 | return EmitShuffleVector(Ops[0], Ops[1], |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 216 | 2, 6, 3, 7, |
| 217 | "punpckhwd"); |
| 218 | case X86::BI__builtin_ia32_punpckhdq: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 219 | return EmitShuffleVector(Ops[0], Ops[1], |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 220 | 1, 3, |
| 221 | "punpckhdq"); |
| 222 | case X86::BI__builtin_ia32_punpcklbw: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 223 | return EmitShuffleVector(Ops[0], Ops[1], |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 224 | 0, 8, 1, 9, 2, 10, 3, 11, |
| 225 | "punpcklbw"); |
| 226 | case X86::BI__builtin_ia32_punpcklwd: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 227 | return EmitShuffleVector(Ops[0], Ops[1], |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 228 | 0, 4, 1, 5, |
| 229 | "punpcklwd"); |
| 230 | case X86::BI__builtin_ia32_punpckldq: |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 231 | return EmitShuffleVector(Ops[0], Ops[1], |
Anders Carlsson | 820cb74 | 2007-12-11 03:09:22 +0000 | [diff] [blame] | 232 | 0, 2, |
| 233 | "punpckldq"); |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 234 | case X86::BI__builtin_ia32_pslldi: |
| 235 | case X86::BI__builtin_ia32_psllqi: |
| 236 | case X86::BI__builtin_ia32_psllwi: |
| 237 | case X86::BI__builtin_ia32_psradi: |
| 238 | case X86::BI__builtin_ia32_psrawi: |
| 239 | case X86::BI__builtin_ia32_psrldi: |
| 240 | case X86::BI__builtin_ia32_psrlqi: |
| 241 | case X86::BI__builtin_ia32_psrlwi: { |
| 242 | Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); |
| 243 | const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1); |
| 244 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 245 | |
Anders Carlsson | 04c4b75 | 2007-12-14 17:48:24 +0000 | [diff] [blame^] | 246 | const char *name = 0; |
| 247 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
| 248 | |
| 249 | switch (BuiltinID) { |
| 250 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 251 | case X86::BI__builtin_ia32_pslldi: |
| 252 | name = "pslldi"; |
| 253 | ID = Intrinsic::x86_mmx_psll_d; |
| 254 | break; |
| 255 | case X86::BI__builtin_ia32_psllqi: |
| 256 | name = "psllqi"; |
| 257 | ID = Intrinsic::x86_mmx_psll_q; |
| 258 | break; |
| 259 | case X86::BI__builtin_ia32_psllwi: |
| 260 | name = "psllwi"; |
| 261 | ID = Intrinsic::x86_mmx_psll_w; |
| 262 | break; |
| 263 | case X86::BI__builtin_ia32_psradi: |
| 264 | name = "psradi"; |
| 265 | ID = Intrinsic::x86_mmx_psra_d; |
| 266 | break; |
| 267 | case X86::BI__builtin_ia32_psrawi: |
| 268 | name = "psrawi"; |
| 269 | ID = Intrinsic::x86_mmx_psra_w; |
| 270 | break; |
| 271 | case X86::BI__builtin_ia32_psrldi: |
| 272 | name = "psrldi"; |
| 273 | ID = Intrinsic::x86_mmx_psrl_d; |
| 274 | break; |
| 275 | case X86::BI__builtin_ia32_psrlqi: |
| 276 | name = "psrlqi"; |
| 277 | ID = Intrinsic::x86_mmx_psrl_q; |
| 278 | break; |
| 279 | case X86::BI__builtin_ia32_psrlwi: |
| 280 | name = "psrlwi"; |
| 281 | ID = Intrinsic::x86_mmx_psrl_w; |
| 282 | break; |
| 283 | } |
| 284 | |
| 285 | llvm::Function *F = Intrinsic::getDeclaration(&CGM.getModule(), ID); |
| 286 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
| 287 | } |
| 288 | case X86::BI__builtin_ia32_pshufd: { |
| 289 | int i = cast<ConstantInt>(Ops[1])->getZExtValue(); |
| 290 | |
| 291 | return EmitShuffleVector(Ops[0], Ops[0], |
Anders Carlsson | 17b80c1 | 2007-12-11 02:25:54 +0000 | [diff] [blame] | 292 | i & 0x3, (i & 0xc) >> 2, |
| 293 | (i & 0x30) >> 4, (i & 0xc0) >> 6, |
| 294 | "pshufd"); |
| 295 | } |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Chris Lattner | 9d37e13 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 299 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
| 300 | const CallExpr *E) { |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 301 | switch (BuiltinID) { |
Anders Carlsson | 0a35a81 | 2007-12-09 23:39:18 +0000 | [diff] [blame] | 302 | default: return 0; |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 303 | } |
| 304 | } |