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 | |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 14 | #include "TargetInfo.h" |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 15 | #include "CodeGenFunction.h" |
| 16 | #include "CodeGenModule.h" |
Anders Carlsson | ca6fcfa | 2007-12-09 21:20:04 +0000 | [diff] [blame] | 17 | #include "clang/Basic/TargetInfo.h" |
Chris Lattner | 1f32999 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 18 | #include "clang/AST/APValue.h" |
Chris Lattner | bef20ac | 2007-08-31 04:31:45 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
Chris Lattner | 6b15cdc | 2009-06-14 01:05:48 +0000 | [diff] [blame] | 21 | #include "clang/Basic/TargetBuiltins.h" |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 22 | #include "llvm/Intrinsics.h" |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetData.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 | |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 28 | /// Utility to insert an atomic instruction based on Instrinsic::ID |
| 29 | /// and the expression node. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 30 | static RValue EmitBinaryAtomic(CodeGenFunction& CGF, |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 31 | Intrinsic::ID Id, const CallExpr *E) { |
Mon P Wang | c500451 | 2008-07-31 03:28:23 +0000 | [diff] [blame] | 32 | const llvm::Type *ResType[2]; |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 33 | ResType[0] = CGF.ConvertType(E->getType()); |
| 34 | ResType[1] = CGF.ConvertType(E->getArg(0)->getType()); |
| 35 | Value *AtomF = CGF.CGM.getIntrinsic(Id, ResType, 2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 36 | return RValue::get(CGF.Builder.CreateCall2(AtomF, |
| 37 | CGF.EmitScalarExpr(E->getArg(0)), |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 38 | CGF.EmitScalarExpr(E->getArg(1)))); |
| 39 | } |
| 40 | |
| 41 | /// Utility to insert an atomic instruction based Instrinsic::ID and |
| 42 | // the expression node, where the return value is the result of the |
| 43 | // operation. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 44 | static RValue EmitBinaryAtomicPost(CodeGenFunction& CGF, |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 45 | Intrinsic::ID Id, const CallExpr *E, |
| 46 | Instruction::BinaryOps Op) { |
| 47 | const llvm::Type *ResType[2]; |
| 48 | ResType[0] = CGF.ConvertType(E->getType()); |
| 49 | ResType[1] = CGF.ConvertType(E->getArg(0)->getType()); |
| 50 | Value *AtomF = CGF.CGM.getIntrinsic(Id, ResType, 2); |
| 51 | Value *Ptr = CGF.EmitScalarExpr(E->getArg(0)); |
| 52 | Value *Operand = CGF.EmitScalarExpr(E->getArg(1)); |
| 53 | Value *Result = CGF.Builder.CreateCall2(AtomF, Ptr, Operand); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | |
Chris Lattner | eebd9d2 | 2009-05-13 04:37:52 +0000 | [diff] [blame] | 55 | if (Id == Intrinsic::atomic_load_nand) |
| 56 | Result = CGF.Builder.CreateNot(Result); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 57 | |
| 58 | |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 59 | return RValue::get(CGF.Builder.CreateBinOp(Op, Result, Operand)); |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 60 | } |
| 61 | |
John McCall | fb17a56 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 62 | static llvm::ConstantInt *getInt32(llvm::LLVMContext &Context, int32_t Value) { |
| 63 | return llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), Value); |
| 64 | } |
| 65 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 66 | RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 67 | unsigned BuiltinID, const CallExpr *E) { |
Chris Lattner | 564ea2a | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 68 | // See if we can constant fold this builtin. If so, don't emit it at all. |
Anders Carlsson | f35d35a | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 69 | Expr::EvalResult Result; |
Chris Lattner | 6ee7aa1 | 2008-11-16 21:24:15 +0000 | [diff] [blame] | 70 | if (E->Evaluate(Result, CGM.getContext())) { |
Anders Carlsson | f35d35a | 2008-12-01 02:31:41 +0000 | [diff] [blame] | 71 | if (Result.Val.isInt()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 72 | return RValue::get(llvm::ConstantInt::get(VMContext, |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 73 | Result.Val.getInt())); |
Eli Friedman | 3941b18 | 2009-01-25 01:54:01 +0000 | [diff] [blame] | 74 | else if (Result.Val.isFloat()) |
Owen Anderson | bc0a222 | 2009-07-27 21:00:51 +0000 | [diff] [blame] | 75 | return RValue::get(ConstantFP::get(VMContext, Result.Val.getFloat())); |
Chris Lattner | 1f32999 | 2008-10-06 06:09:18 +0000 | [diff] [blame] | 76 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 564ea2a | 2008-10-06 06:56:41 +0000 | [diff] [blame] | 78 | switch (BuiltinID) { |
| 79 | default: break; // Handle intrinsics and libm functions below. |
Chris Lattner | 506ff88 | 2008-10-06 07:26:43 +0000 | [diff] [blame] | 80 | case Builtin::BI__builtin___CFStringMakeConstantString: |
David Chisnall | 0d13f6f | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 81 | case Builtin::BI__builtin___NSStringMakeConstantString: |
Anders Carlsson | e9352cc | 2009-04-08 04:48:15 +0000 | [diff] [blame] | 82 | return RValue::get(CGM.EmitConstantExpr(E, E->getType(), 0)); |
Chris Lattner | 6a705f0 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 83 | case Builtin::BI__builtin_stdarg_start: |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 84 | case Builtin::BI__builtin_va_start: |
| 85 | case Builtin::BI__builtin_va_end: { |
Daniel Dunbar | 0785570 | 2009-02-11 22:25:55 +0000 | [diff] [blame] | 86 | Value *ArgValue = EmitVAListRef(E->getArg(0)); |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 87 | const llvm::Type *DestType = llvm::Type::getInt8PtrTy(VMContext); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 88 | if (ArgValue->getType() != DestType) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | ArgValue = Builder.CreateBitCast(ArgValue, DestType, |
Daniel Dunbar | b27ffbe | 2009-07-26 09:28:40 +0000 | [diff] [blame] | 90 | ArgValue->getName().data()); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 91 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 92 | Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_end) ? |
Chris Lattner | 6a705f0 | 2008-07-09 17:28:44 +0000 | [diff] [blame] | 93 | Intrinsic::vaend : Intrinsic::vastart; |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 94 | return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue)); |
Anders Carlsson | 793680e | 2007-10-12 23:56:29 +0000 | [diff] [blame] | 95 | } |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 96 | case Builtin::BI__builtin_va_copy: { |
Eli Friedman | 4fd0aa5 | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 97 | Value *DstPtr = EmitVAListRef(E->getArg(0)); |
| 98 | Value *SrcPtr = EmitVAListRef(E->getArg(1)); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 99 | |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 100 | const llvm::Type *Type = llvm::Type::getInt8PtrTy(VMContext); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 101 | |
| 102 | DstPtr = Builder.CreateBitCast(DstPtr, Type); |
| 103 | SrcPtr = Builder.CreateBitCast(SrcPtr, Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 104 | return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame] | 105 | DstPtr, SrcPtr)); |
Anders Carlsson | a28ef8b | 2008-02-09 20:26:43 +0000 | [diff] [blame] | 106 | } |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 107 | case Builtin::BI__builtin_abs: { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
| 109 | |
Chris Lattner | 9a847f5 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 110 | Value *NegOp = Builder.CreateNeg(ArgValue, "neg"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | Value *CmpResult = |
| 112 | Builder.CreateICmpSGE(ArgValue, |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 113 | llvm::Constant::getNullValue(ArgValue->getType()), |
Chris Lattner | 9a847f5 | 2008-07-23 06:53:34 +0000 | [diff] [blame] | 114 | "abscond"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | Value *Result = |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 116 | Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Anders Carlsson | c2251dc | 2007-11-20 19:05:17 +0000 | [diff] [blame] | 118 | return RValue::get(Result); |
| 119 | } |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 120 | case Builtin::BI__builtin_ctz: |
| 121 | case Builtin::BI__builtin_ctzl: |
| 122 | case Builtin::BI__builtin_ctzll: { |
| 123 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 125 | const llvm::Type *ArgType = ArgValue->getType(); |
| 126 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); |
| 127 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | const llvm::Type *ResultType = ConvertType(E->getType()); |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 129 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 130 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 131 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 132 | "cast"); |
Anders Carlsson | 3a31d60 | 2008-02-06 07:19:27 +0000 | [diff] [blame] | 133 | return RValue::get(Result); |
| 134 | } |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 135 | case Builtin::BI__builtin_clz: |
| 136 | case Builtin::BI__builtin_clzl: |
| 137 | case Builtin::BI__builtin_clzll: { |
| 138 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 140 | const llvm::Type *ArgType = ArgValue->getType(); |
| 141 | Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1); |
| 142 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 143 | const llvm::Type *ResultType = ConvertType(E->getType()); |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 144 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 145 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 146 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 147 | "cast"); |
Eli Friedman | f4e8533 | 2008-05-27 15:32:46 +0000 | [diff] [blame] | 148 | return RValue::get(Result); |
| 149 | } |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 150 | case Builtin::BI__builtin_ffs: |
| 151 | case Builtin::BI__builtin_ffsl: |
| 152 | case Builtin::BI__builtin_ffsll: { |
| 153 | // ffs(x) -> x ? cttz(x) + 1 : 0 |
| 154 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 156 | const llvm::Type *ArgType = ArgValue->getType(); |
| 157 | Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 159 | const llvm::Type *ResultType = ConvertType(E->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | Value *Tmp = Builder.CreateAdd(Builder.CreateCall(F, ArgValue, "tmp"), |
Owen Anderson | 4a28d5d | 2009-07-24 23:12:58 +0000 | [diff] [blame] | 161 | llvm::ConstantInt::get(ArgType, 1), "tmp"); |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 162 | Value *Zero = llvm::Constant::getNullValue(ArgType); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 163 | Value *IsZero = Builder.CreateICmpEQ(ArgValue, Zero, "iszero"); |
| 164 | Value *Result = Builder.CreateSelect(IsZero, Zero, Tmp, "ffs"); |
| 165 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 166 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 167 | "cast"); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 168 | return RValue::get(Result); |
| 169 | } |
| 170 | case Builtin::BI__builtin_parity: |
| 171 | case Builtin::BI__builtin_parityl: |
| 172 | case Builtin::BI__builtin_parityll: { |
| 173 | // parity(x) -> ctpop(x) & 1 |
| 174 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 176 | const llvm::Type *ArgType = ArgValue->getType(); |
| 177 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 179 | const llvm::Type *ResultType = ConvertType(E->getType()); |
| 180 | Value *Tmp = Builder.CreateCall(F, ArgValue, "tmp"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | Value *Result = Builder.CreateAnd(Tmp, llvm::ConstantInt::get(ArgType, 1), |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 182 | "tmp"); |
| 183 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 184 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 185 | "cast"); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 186 | return RValue::get(Result); |
| 187 | } |
| 188 | case Builtin::BI__builtin_popcount: |
| 189 | case Builtin::BI__builtin_popcountl: |
| 190 | case Builtin::BI__builtin_popcountll: { |
| 191 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 192 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 193 | const llvm::Type *ArgType = ArgValue->getType(); |
| 194 | Value *F = CGM.getIntrinsic(Intrinsic::ctpop, &ArgType, 1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 195 | |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 196 | const llvm::Type *ResultType = ConvertType(E->getType()); |
| 197 | Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); |
| 198 | if (Result->getType() != ResultType) |
Duncan Sands | eac73e5 | 2009-11-16 13:11:21 +0000 | [diff] [blame] | 199 | Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true, |
| 200 | "cast"); |
Daniel Dunbar | 04b2900 | 2008-07-21 17:19:41 +0000 | [diff] [blame] | 201 | return RValue::get(Result); |
| 202 | } |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 203 | case Builtin::BI__builtin_expect: |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 204 | // FIXME: pass expect through to LLVM |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 205 | return RValue::get(EmitScalarExpr(E->getArg(0))); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 206 | case Builtin::BI__builtin_bswap32: |
| 207 | case Builtin::BI__builtin_bswap64: { |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 208 | Value *ArgValue = EmitScalarExpr(E->getArg(0)); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 209 | const llvm::Type *ArgType = ArgValue->getType(); |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 210 | Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1); |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 211 | return RValue::get(Builder.CreateCall(F, ArgValue, "tmp")); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | } |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 213 | case Builtin::BI__builtin_object_size: { |
Mike Stump | b16d32f | 2009-10-26 23:39:48 +0000 | [diff] [blame] | 214 | // We pass this builtin onto the optimizer so that it can |
| 215 | // figure out the object size in more complex cases. |
Mike Stump | c4c9045 | 2009-10-27 22:09:17 +0000 | [diff] [blame] | 216 | const llvm::Type *ResType[] = { |
| 217 | ConvertType(E->getType()) |
| 218 | }; |
Eric Christopher | fee667f | 2009-12-23 03:49:37 +0000 | [diff] [blame] | 219 | |
| 220 | // LLVM only supports 0 and 2, make sure that we pass along that |
| 221 | // as a boolean. |
| 222 | Value *Ty = EmitScalarExpr(E->getArg(1)); |
| 223 | ConstantInt *CI = dyn_cast<ConstantInt>(Ty); |
| 224 | assert(CI); |
| 225 | uint64_t val = CI->getZExtValue(); |
| 226 | CI = ConstantInt::get(llvm::Type::getInt1Ty(VMContext), (val & 0x2) >> 1); |
| 227 | |
Mike Stump | c4c9045 | 2009-10-27 22:09:17 +0000 | [diff] [blame] | 228 | Value *F = CGM.getIntrinsic(Intrinsic::objectsize, ResType, 1); |
| 229 | return RValue::get(Builder.CreateCall2(F, |
| 230 | EmitScalarExpr(E->getArg(0)), |
Eric Christopher | fee667f | 2009-12-23 03:49:37 +0000 | [diff] [blame] | 231 | CI)); |
Daniel Dunbar | d5f8a4f | 2008-09-03 21:13:56 +0000 | [diff] [blame] | 232 | } |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 233 | case Builtin::BI__builtin_prefetch: { |
| 234 | Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); |
| 235 | // FIXME: Technically these constants should of type 'int', yes? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 236 | RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 237 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 238 | Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 239 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 3); |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 240 | Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); |
| 241 | return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); |
Anders Carlsson | df4852a | 2007-12-02 21:58:10 +0000 | [diff] [blame] | 242 | } |
Daniel Dunbar | 4493f79 | 2008-07-21 22:59:13 +0000 | [diff] [blame] | 243 | case Builtin::BI__builtin_trap: { |
| 244 | Value *F = CGM.getIntrinsic(Intrinsic::trap, 0, 0); |
| 245 | return RValue::get(Builder.CreateCall(F)); |
| 246 | } |
Chris Lattner | 21190d5 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 247 | case Builtin::BI__builtin_unreachable: { |
Mike Stump | fba565d | 2009-12-16 03:07:12 +0000 | [diff] [blame] | 248 | if (CatchUndefined && HaveInsertPoint()) |
| 249 | EmitBranch(getTrapBB()); |
Chris Lattner | 21190d5 | 2009-09-21 03:09:59 +0000 | [diff] [blame] | 250 | Value *V = Builder.CreateUnreachable(); |
| 251 | Builder.ClearInsertionPoint(); |
| 252 | return RValue::get(V); |
| 253 | } |
| 254 | |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 255 | case Builtin::BI__builtin_powi: |
| 256 | case Builtin::BI__builtin_powif: |
| 257 | case Builtin::BI__builtin_powil: { |
| 258 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 259 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 260 | const llvm::Type *ArgType = Base->getType(); |
| 261 | Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1); |
Daniel Dunbar | a933c3c | 2008-07-21 18:44:41 +0000 | [diff] [blame] | 262 | return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); |
| 263 | } |
| 264 | |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 265 | case Builtin::BI__builtin_isgreater: |
| 266 | case Builtin::BI__builtin_isgreaterequal: |
| 267 | case Builtin::BI__builtin_isless: |
| 268 | case Builtin::BI__builtin_islessequal: |
| 269 | case Builtin::BI__builtin_islessgreater: |
| 270 | case Builtin::BI__builtin_isunordered: { |
| 271 | // Ordered comparisons: we know the arguments to these are matching scalar |
| 272 | // floating point values. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | Value *LHS = EmitScalarExpr(E->getArg(0)); |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 274 | Value *RHS = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 276 | switch (BuiltinID) { |
| 277 | default: assert(0 && "Unknown ordered comparison"); |
| 278 | case Builtin::BI__builtin_isgreater: |
| 279 | LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp"); |
| 280 | break; |
| 281 | case Builtin::BI__builtin_isgreaterequal: |
| 282 | LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp"); |
| 283 | break; |
| 284 | case Builtin::BI__builtin_isless: |
| 285 | LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp"); |
| 286 | break; |
| 287 | case Builtin::BI__builtin_islessequal: |
| 288 | LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp"); |
| 289 | break; |
| 290 | case Builtin::BI__builtin_islessgreater: |
| 291 | LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp"); |
| 292 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | case Builtin::BI__builtin_isunordered: |
Chris Lattner | fe23e21 | 2007-12-20 00:44:32 +0000 | [diff] [blame] | 294 | LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp"); |
| 295 | break; |
| 296 | } |
| 297 | // ZExt bool to int type. |
| 298 | return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()), |
| 299 | "tmp")); |
| 300 | } |
Eli Friedman | d613989 | 2009-09-01 04:19:44 +0000 | [diff] [blame] | 301 | case Builtin::BI__builtin_isnan: { |
| 302 | Value *V = EmitScalarExpr(E->getArg(0)); |
| 303 | V = Builder.CreateFCmpUNO(V, V, "cmp"); |
| 304 | return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType()), "tmp")); |
| 305 | } |
Eli Friedman | b52fe9c | 2009-06-02 07:10:30 +0000 | [diff] [blame] | 306 | case Builtin::BIalloca: |
Chris Lattner | 9e800e3 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 307 | case Builtin::BI__builtin_alloca: { |
| 308 | // FIXME: LLVM IR Should allow alloca with an i64 size! |
| 309 | Value *Size = EmitScalarExpr(E->getArg(0)); |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 310 | Size = Builder.CreateIntCast(Size, llvm::Type::getInt32Ty(VMContext), false, "tmp"); |
| 311 | return RValue::get(Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), Size, "tmp")); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 312 | } |
Eli Friedman | e6dddfd | 2010-01-23 19:00:10 +0000 | [diff] [blame] | 313 | case Builtin::BIbzero: |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 314 | case Builtin::BI__builtin_bzero: { |
| 315 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 316 | Builder.CreateCall4(CGM.getMemSetFn(), Address, |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 317 | llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0), |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 318 | EmitScalarExpr(E->getArg(1)), |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 319 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 320 | return RValue::get(Address); |
Chris Lattner | 9e800e3 | 2008-06-16 17:15:14 +0000 | [diff] [blame] | 321 | } |
Eli Friedman | e6ec205 | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 322 | case Builtin::BImemcpy: |
Eli Friedman | d4b32e4 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 323 | case Builtin::BI__builtin_memcpy: { |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 324 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 325 | Builder.CreateCall4(CGM.getMemCpyFn(), Address, |
| 326 | EmitScalarExpr(E->getArg(1)), |
| 327 | EmitScalarExpr(E->getArg(2)), |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 328 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 329 | return RValue::get(Address); |
| 330 | } |
Eli Friedman | e6ec205 | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 331 | case Builtin::BImemmove: |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 332 | case Builtin::BI__builtin_memmove: { |
| 333 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 334 | Builder.CreateCall4(CGM.getMemMoveFn(), Address, |
| 335 | EmitScalarExpr(E->getArg(1)), |
| 336 | EmitScalarExpr(E->getArg(2)), |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 337 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 338 | return RValue::get(Address); |
| 339 | } |
Eli Friedman | e6ec205 | 2009-12-17 00:14:28 +0000 | [diff] [blame] | 340 | case Builtin::BImemset: |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 341 | case Builtin::BI__builtin_memset: { |
| 342 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 343 | Builder.CreateCall4(CGM.getMemSetFn(), Address, |
Daniel Dunbar | 62c29c6 | 2009-02-16 21:52:05 +0000 | [diff] [blame] | 344 | Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 345 | llvm::Type::getInt8Ty(VMContext)), |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 346 | EmitScalarExpr(E->getArg(2)), |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 347 | llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1)); |
Daniel Dunbar | 1caae95 | 2008-07-22 00:26:45 +0000 | [diff] [blame] | 348 | return RValue::get(Address); |
Eli Friedman | d4b32e4 | 2008-05-19 23:27:48 +0000 | [diff] [blame] | 349 | } |
John McCall | fb17a56 | 2010-03-03 10:30:05 +0000 | [diff] [blame] | 350 | case Builtin::BI__builtin_dwarf_cfa: { |
| 351 | // The offset in bytes from the first argument to the CFA. |
| 352 | // |
| 353 | // Why on earth is this in the frontend? Is there any reason at |
| 354 | // all that the backend can't reasonably determine this while |
| 355 | // lowering llvm.eh.dwarf.cfa()? |
| 356 | // |
| 357 | // TODO: If there's a satisfactory reason, add a target hook for |
| 358 | // this instead of hard-coding 0, which is correct for most targets. |
| 359 | int32_t Offset = 0; |
| 360 | |
| 361 | Value *F = CGM.getIntrinsic(Intrinsic::eh_dwarf_cfa, 0, 0); |
| 362 | return RValue::get(Builder.CreateCall(F, getInt32(VMContext, Offset))); |
| 363 | } |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 364 | case Builtin::BI__builtin_return_address: { |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 365 | Value *Depth = EmitScalarExpr(E->getArg(0)); |
| 366 | Depth = Builder.CreateIntCast(Depth, |
| 367 | llvm::Type::getInt32Ty(VMContext), |
| 368 | false, "tmp"); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 369 | Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0); |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 370 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 371 | } |
| 372 | case Builtin::BI__builtin_frame_address: { |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 373 | Value *Depth = EmitScalarExpr(E->getArg(0)); |
| 374 | Depth = Builder.CreateIntCast(Depth, |
| 375 | llvm::Type::getInt32Ty(VMContext), |
| 376 | false, "tmp"); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 377 | Value *F = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); |
Anton Korobeynikov | 83c2a98 | 2009-12-27 14:27:22 +0000 | [diff] [blame] | 378 | return RValue::get(Builder.CreateCall(F, Depth)); |
Eli Friedman | 256f77e | 2008-05-20 08:59:34 +0000 | [diff] [blame] | 379 | } |
Eli Friedman | 3b660ef | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 380 | case Builtin::BI__builtin_extract_return_addr: { |
John McCall | 492c4f9 | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 381 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 382 | Value *Result = getTargetHooks().decodeReturnAddress(*this, Address); |
| 383 | return RValue::get(Result); |
| 384 | } |
| 385 | case Builtin::BI__builtin_frob_return_addr: { |
| 386 | Value *Address = EmitScalarExpr(E->getArg(0)); |
| 387 | Value *Result = getTargetHooks().encodeReturnAddress(*this, Address); |
| 388 | return RValue::get(Result); |
Eli Friedman | 3b660ef | 2009-05-03 19:23:23 +0000 | [diff] [blame] | 389 | } |
John McCall | 7ada111 | 2010-03-03 05:38:58 +0000 | [diff] [blame] | 390 | case Builtin::BI__builtin_eh_return: { |
| 391 | Value *Int = EmitScalarExpr(E->getArg(0)); |
| 392 | Value *Ptr = EmitScalarExpr(E->getArg(1)); |
| 393 | |
| 394 | const llvm::IntegerType *IntTy = cast<llvm::IntegerType>(Int->getType()); |
| 395 | assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && |
| 396 | "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); |
| 397 | Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 |
| 398 | ? Intrinsic::eh_return_i32 |
| 399 | : Intrinsic::eh_return_i64, |
| 400 | 0, 0); |
| 401 | Builder.CreateCall2(F, Int, Ptr); |
| 402 | Value *V = Builder.CreateUnreachable(); |
| 403 | Builder.ClearInsertionPoint(); |
| 404 | return RValue::get(V); |
| 405 | } |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 406 | case Builtin::BI__builtin_unwind_init: { |
| 407 | Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init, 0, 0); |
| 408 | return RValue::get(Builder.CreateCall(F)); |
| 409 | } |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 410 | case Builtin::BI__builtin_extend_pointer: { |
| 411 | // Extends a pointer to the size of an _Unwind_Word, which is |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 412 | // uint64_t on all platforms. Generally this gets poked into a |
| 413 | // register and eventually used as an address, so if the |
| 414 | // addressing registers are wider than pointers and the platform |
| 415 | // doesn't implicitly ignore high-order bits when doing |
| 416 | // addressing, we need to make sure we zext / sext based on |
| 417 | // the platform's expectations. |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 418 | // |
| 419 | // See: http://gcc.gnu.org/ml/gcc-bugs/2002-02/msg00237.html |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 420 | |
| 421 | LLVMContext &C = CGM.getLLVMContext(); |
| 422 | |
| 423 | // Cast the pointer to intptr_t. |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 424 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 425 | const llvm::IntegerType *IntPtrTy = CGM.getTargetData().getIntPtrType(C); |
| 426 | Value *Result = Builder.CreatePtrToInt(Ptr, IntPtrTy, "extend.cast"); |
| 427 | |
| 428 | // If that's 64 bits, we're done. |
| 429 | if (IntPtrTy->getBitWidth() == 64) |
| 430 | return RValue::get(Result); |
| 431 | |
| 432 | // Otherwise, ask the codegen data what to do. |
| 433 | const llvm::IntegerType *Int64Ty = llvm::IntegerType::get(C, 64); |
John McCall | 492c4f9 | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 434 | if (getTargetHooks().extendPointerWithSExt()) |
John McCall | d0b76ca | 2010-03-02 03:50:12 +0000 | [diff] [blame] | 435 | return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext")); |
| 436 | else |
| 437 | return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext")); |
John McCall | 5e11085 | 2010-03-02 02:31:24 +0000 | [diff] [blame] | 438 | } |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 439 | #if 0 |
| 440 | // FIXME: Finish/enable when LLVM backend support stabilizes |
| 441 | case Builtin::BI__builtin_setjmp: { |
| 442 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
| 443 | // Store the frame pointer to the buffer |
| 444 | Value *FrameAddrF = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); |
| 445 | Value *FrameAddr = |
| 446 | Builder.CreateCall(FrameAddrF, |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 447 | Constant::getNullValue(llvm::Type::getInt32Ty(VMContext))); |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 448 | Builder.CreateStore(FrameAddr, Buf); |
| 449 | // Call the setjmp intrinsic |
| 450 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp, 0, 0); |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 451 | const llvm::Type *DestType = llvm::Type::getInt8PtrTy(VMContext); |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 452 | Buf = Builder.CreateBitCast(Buf, DestType); |
| 453 | return RValue::get(Builder.CreateCall(F, Buf)); |
| 454 | } |
| 455 | case Builtin::BI__builtin_longjmp: { |
| 456 | Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp, 0, 0); |
| 457 | Value *Buf = EmitScalarExpr(E->getArg(0)); |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 458 | const llvm::Type *DestType = llvm::Type::getInt8PtrTy(VMContext); |
Eli Friedman | a6d75c0 | 2009-06-02 09:37:50 +0000 | [diff] [blame] | 459 | Buf = Builder.CreateBitCast(Buf, DestType); |
| 460 | return RValue::get(Builder.CreateCall(F, Buf)); |
| 461 | } |
| 462 | #endif |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 463 | case Builtin::BI__sync_fetch_and_add: |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 464 | case Builtin::BI__sync_fetch_and_sub: |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 465 | case Builtin::BI__sync_fetch_and_or: |
| 466 | case Builtin::BI__sync_fetch_and_and: |
| 467 | case Builtin::BI__sync_fetch_and_xor: |
| 468 | case Builtin::BI__sync_add_and_fetch: |
| 469 | case Builtin::BI__sync_sub_and_fetch: |
| 470 | case Builtin::BI__sync_and_and_fetch: |
| 471 | case Builtin::BI__sync_or_and_fetch: |
| 472 | case Builtin::BI__sync_xor_and_fetch: |
| 473 | case Builtin::BI__sync_val_compare_and_swap: |
| 474 | case Builtin::BI__sync_bool_compare_and_swap: |
| 475 | case Builtin::BI__sync_lock_test_and_set: |
| 476 | case Builtin::BI__sync_lock_release: |
| 477 | assert(0 && "Shouldn't make it through sema"); |
| 478 | case Builtin::BI__sync_fetch_and_add_1: |
| 479 | case Builtin::BI__sync_fetch_and_add_2: |
| 480 | case Builtin::BI__sync_fetch_and_add_4: |
| 481 | case Builtin::BI__sync_fetch_and_add_8: |
| 482 | case Builtin::BI__sync_fetch_and_add_16: |
| 483 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_add, E); |
| 484 | case Builtin::BI__sync_fetch_and_sub_1: |
| 485 | case Builtin::BI__sync_fetch_and_sub_2: |
| 486 | case Builtin::BI__sync_fetch_and_sub_4: |
| 487 | case Builtin::BI__sync_fetch_and_sub_8: |
| 488 | case Builtin::BI__sync_fetch_and_sub_16: |
Mon P Wang | 09b6bf5 | 2008-06-25 08:21:36 +0000 | [diff] [blame] | 489 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_sub, E); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 490 | case Builtin::BI__sync_fetch_and_or_1: |
| 491 | case Builtin::BI__sync_fetch_and_or_2: |
| 492 | case Builtin::BI__sync_fetch_and_or_4: |
| 493 | case Builtin::BI__sync_fetch_and_or_8: |
| 494 | case Builtin::BI__sync_fetch_and_or_16: |
| 495 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E); |
| 496 | case Builtin::BI__sync_fetch_and_and_1: |
| 497 | case Builtin::BI__sync_fetch_and_and_2: |
| 498 | case Builtin::BI__sync_fetch_and_and_4: |
| 499 | case Builtin::BI__sync_fetch_and_and_8: |
| 500 | case Builtin::BI__sync_fetch_and_and_16: |
| 501 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E); |
| 502 | case Builtin::BI__sync_fetch_and_xor_1: |
| 503 | case Builtin::BI__sync_fetch_and_xor_2: |
| 504 | case Builtin::BI__sync_fetch_and_xor_4: |
| 505 | case Builtin::BI__sync_fetch_and_xor_8: |
| 506 | case Builtin::BI__sync_fetch_and_xor_16: |
| 507 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E); |
Chris Lattner | eebd9d2 | 2009-05-13 04:37:52 +0000 | [diff] [blame] | 508 | case Builtin::BI__sync_fetch_and_nand_1: |
| 509 | case Builtin::BI__sync_fetch_and_nand_2: |
| 510 | case Builtin::BI__sync_fetch_and_nand_4: |
| 511 | case Builtin::BI__sync_fetch_and_nand_8: |
| 512 | case Builtin::BI__sync_fetch_and_nand_16: |
| 513 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_nand, E); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 515 | // Clang extensions: not overloaded yet. |
Mon P Wang | 1ffe281 | 2008-05-09 22:40:52 +0000 | [diff] [blame] | 516 | case Builtin::BI__sync_fetch_and_min: |
| 517 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E); |
| 518 | case Builtin::BI__sync_fetch_and_max: |
| 519 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E); |
| 520 | case Builtin::BI__sync_fetch_and_umin: |
| 521 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E); |
| 522 | case Builtin::BI__sync_fetch_and_umax: |
| 523 | return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 524 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 525 | case Builtin::BI__sync_add_and_fetch_1: |
| 526 | case Builtin::BI__sync_add_and_fetch_2: |
| 527 | case Builtin::BI__sync_add_and_fetch_4: |
| 528 | case Builtin::BI__sync_add_and_fetch_8: |
| 529 | case Builtin::BI__sync_add_and_fetch_16: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_add, E, |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 531 | llvm::Instruction::Add); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 532 | case Builtin::BI__sync_sub_and_fetch_1: |
| 533 | case Builtin::BI__sync_sub_and_fetch_2: |
| 534 | case Builtin::BI__sync_sub_and_fetch_4: |
| 535 | case Builtin::BI__sync_sub_and_fetch_8: |
| 536 | case Builtin::BI__sync_sub_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 537 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_sub, E, |
| 538 | llvm::Instruction::Sub); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 539 | case Builtin::BI__sync_and_and_fetch_1: |
| 540 | case Builtin::BI__sync_and_and_fetch_2: |
| 541 | case Builtin::BI__sync_and_and_fetch_4: |
| 542 | case Builtin::BI__sync_and_and_fetch_8: |
| 543 | case Builtin::BI__sync_and_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 544 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_and, E, |
| 545 | llvm::Instruction::And); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 546 | case Builtin::BI__sync_or_and_fetch_1: |
| 547 | case Builtin::BI__sync_or_and_fetch_2: |
| 548 | case Builtin::BI__sync_or_and_fetch_4: |
| 549 | case Builtin::BI__sync_or_and_fetch_8: |
| 550 | case Builtin::BI__sync_or_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 551 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_or, E, |
| 552 | llvm::Instruction::Or); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 553 | case Builtin::BI__sync_xor_and_fetch_1: |
| 554 | case Builtin::BI__sync_xor_and_fetch_2: |
| 555 | case Builtin::BI__sync_xor_and_fetch_4: |
| 556 | case Builtin::BI__sync_xor_and_fetch_8: |
| 557 | case Builtin::BI__sync_xor_and_fetch_16: |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 558 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_xor, E, |
| 559 | llvm::Instruction::Xor); |
Chris Lattner | eebd9d2 | 2009-05-13 04:37:52 +0000 | [diff] [blame] | 560 | case Builtin::BI__sync_nand_and_fetch_1: |
| 561 | case Builtin::BI__sync_nand_and_fetch_2: |
| 562 | case Builtin::BI__sync_nand_and_fetch_4: |
| 563 | case Builtin::BI__sync_nand_and_fetch_8: |
| 564 | case Builtin::BI__sync_nand_and_fetch_16: |
| 565 | return EmitBinaryAtomicPost(*this, Intrinsic::atomic_load_nand, E, |
| 566 | llvm::Instruction::And); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 568 | case Builtin::BI__sync_val_compare_and_swap_1: |
| 569 | case Builtin::BI__sync_val_compare_and_swap_2: |
| 570 | case Builtin::BI__sync_val_compare_and_swap_4: |
| 571 | case Builtin::BI__sync_val_compare_and_swap_8: |
| 572 | case Builtin::BI__sync_val_compare_and_swap_16: |
| 573 | { |
Mon P Wang | c500451 | 2008-07-31 03:28:23 +0000 | [diff] [blame] | 574 | const llvm::Type *ResType[2]; |
| 575 | ResType[0]= ConvertType(E->getType()); |
| 576 | ResType[1] = ConvertType(E->getArg(0)->getType()); |
| 577 | Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | return RValue::get(Builder.CreateCall3(AtomF, |
Anders Carlsson | 9584446 | 2008-08-30 16:17:45 +0000 | [diff] [blame] | 579 | EmitScalarExpr(E->getArg(0)), |
| 580 | EmitScalarExpr(E->getArg(1)), |
| 581 | EmitScalarExpr(E->getArg(2)))); |
Anders Carlsson | 89799cf | 2007-10-29 02:59:40 +0000 | [diff] [blame] | 582 | } |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 583 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 584 | case Builtin::BI__sync_bool_compare_and_swap_1: |
| 585 | case Builtin::BI__sync_bool_compare_and_swap_2: |
| 586 | case Builtin::BI__sync_bool_compare_and_swap_4: |
| 587 | case Builtin::BI__sync_bool_compare_and_swap_8: |
| 588 | case Builtin::BI__sync_bool_compare_and_swap_16: |
| 589 | { |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 590 | const llvm::Type *ResType[2]; |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 591 | ResType[0]= ConvertType(E->getArg(1)->getType()); |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 592 | ResType[1] = llvm::PointerType::getUnqual(ResType[0]); |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 593 | Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_cmp_swap, ResType, 2); |
| 594 | Value *OldVal = EmitScalarExpr(E->getArg(1)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | Value *PrevVal = Builder.CreateCall3(AtomF, |
Daniel Dunbar | 0002d23 | 2009-04-07 00:55:51 +0000 | [diff] [blame] | 596 | EmitScalarExpr(E->getArg(0)), |
| 597 | OldVal, |
| 598 | EmitScalarExpr(E->getArg(2))); |
| 599 | Value *Result = Builder.CreateICmpEQ(PrevVal, OldVal); |
| 600 | // zext bool to int. |
| 601 | return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType()))); |
| 602 | } |
| 603 | |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 604 | case Builtin::BI__sync_lock_test_and_set_1: |
| 605 | case Builtin::BI__sync_lock_test_and_set_2: |
| 606 | case Builtin::BI__sync_lock_test_and_set_4: |
| 607 | case Builtin::BI__sync_lock_test_and_set_8: |
| 608 | case Builtin::BI__sync_lock_test_and_set_16: |
Nate Begeman | 7ea2e3f | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 609 | return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E); |
Chris Lattner | 5caa370 | 2009-05-08 06:58:22 +0000 | [diff] [blame] | 610 | case Builtin::BI__sync_lock_release_1: |
| 611 | case Builtin::BI__sync_lock_release_2: |
| 612 | case Builtin::BI__sync_lock_release_4: |
| 613 | case Builtin::BI__sync_lock_release_8: |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 614 | case Builtin::BI__sync_lock_release_16: { |
| 615 | Value *Ptr = EmitScalarExpr(E->getArg(0)); |
| 616 | const llvm::Type *ElTy = |
| 617 | cast<llvm::PointerType>(Ptr->getType())->getElementType(); |
Daniel Dunbar | 007b567 | 2009-11-29 21:11:47 +0000 | [diff] [blame] | 618 | llvm::StoreInst *Store = |
| 619 | Builder.CreateStore(llvm::Constant::getNullValue(ElTy), Ptr); |
| 620 | Store->setVolatile(true); |
Daniel Dunbar | eb4f81e | 2009-05-27 23:45:33 +0000 | [diff] [blame] | 621 | return RValue::get(0); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 622 | } |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 623 | |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 624 | case Builtin::BI__sync_synchronize: { |
| 625 | Value *C[5]; |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 626 | C[0] = C[1] = C[2] = C[3] = llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 1); |
| 627 | C[4] = llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 628 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::memory_barrier), C, C + 5); |
Daniel Dunbar | eb4f81e | 2009-05-27 23:45:33 +0000 | [diff] [blame] | 629 | return RValue::get(0); |
Chris Lattner | f58cd9b | 2009-05-13 04:46:13 +0000 | [diff] [blame] | 630 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | |
Tanya Lattner | 0b57164 | 2010-01-16 01:21:14 +0000 | [diff] [blame] | 632 | case Builtin::BI__builtin_llvm_memory_barrier: { |
| 633 | Value *C[5] = { |
| 634 | EmitScalarExpr(E->getArg(0)), |
| 635 | EmitScalarExpr(E->getArg(1)), |
| 636 | EmitScalarExpr(E->getArg(2)), |
| 637 | EmitScalarExpr(E->getArg(3)), |
| 638 | EmitScalarExpr(E->getArg(4)) |
| 639 | }; |
| 640 | Builder.CreateCall(CGM.getIntrinsic(Intrinsic::memory_barrier), C, C + 5); |
| 641 | return RValue::get(0); |
| 642 | } |
| 643 | |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 644 | // Library functions with special handling. |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 645 | case Builtin::BIsqrt: |
| 646 | case Builtin::BIsqrtf: |
| 647 | case Builtin::BIsqrtl: { |
| 648 | // Rewrite sqrt to intrinsic if allowed. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 649 | if (!FD->hasAttr<ConstAttr>()) |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 650 | break; |
| 651 | Value *Arg0 = EmitScalarExpr(E->getArg(0)); |
| 652 | const llvm::Type *ArgType = Arg0->getType(); |
| 653 | Value *F = CGM.getIntrinsic(Intrinsic::sqrt, &ArgType, 1); |
| 654 | return RValue::get(Builder.CreateCall(F, Arg0, "tmp")); |
| 655 | } |
| 656 | |
| 657 | case Builtin::BIpow: |
| 658 | case Builtin::BIpowf: |
| 659 | case Builtin::BIpowl: { |
| 660 | // Rewrite sqrt to intrinsic if allowed. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 661 | if (!FD->hasAttr<ConstAttr>()) |
Daniel Dunbar | ef2abfe | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 662 | break; |
| 663 | Value *Base = EmitScalarExpr(E->getArg(0)); |
| 664 | Value *Exponent = EmitScalarExpr(E->getArg(1)); |
| 665 | const llvm::Type *ArgType = Base->getType(); |
| 666 | Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1); |
| 667 | return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); |
| 668 | } |
Nate Begeman | 7ea2e3f | 2008-05-15 07:38:03 +0000 | [diff] [blame] | 669 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 670 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 671 | // If this is an alias for a libm function (e.g. __builtin_sin) turn it into |
| 672 | // that function. |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 673 | if (getContext().BuiltinInfo.isLibFunction(BuiltinID) || |
| 674 | getContext().BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 675 | return EmitCall(E->getCallee()->getType(), |
| 676 | CGM.getBuiltinLibFunction(FD, BuiltinID), |
Anders Carlsson | d2490a9 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 677 | ReturnValueSlot(), |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 678 | E->arg_begin(), E->arg_end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 680 | // See if we have a target specific intrinsic. |
Dale Johannesen | a6f80ef | 2009-02-05 01:50:47 +0000 | [diff] [blame] | 681 | const char *Name = getContext().BuiltinInfo.GetName(BuiltinID); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 682 | Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic; |
| 683 | if (const char *Prefix = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | llvm::Triple::getArchTypePrefix(Target.getTriple().getArch())) |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 685 | IntrinsicID = Intrinsic::getIntrinsicForGCCBuiltin(Prefix, Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 686 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 687 | if (IntrinsicID != Intrinsic::not_intrinsic) { |
| 688 | SmallVector<Value*, 16> Args; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 690 | Function *F = CGM.getIntrinsic(IntrinsicID); |
| 691 | const llvm::FunctionType *FTy = F->getFunctionType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 692 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 693 | for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { |
| 694 | Value *ArgValue = EmitScalarExpr(E->getArg(i)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 696 | // If the intrinsic arg type is different from the builtin arg type |
| 697 | // we need to do a bit cast. |
| 698 | const llvm::Type *PTy = FTy->getParamType(i); |
| 699 | if (PTy != ArgValue->getType()) { |
| 700 | assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) && |
| 701 | "Must be able to losslessly bit cast to param"); |
| 702 | ArgValue = Builder.CreateBitCast(ArgValue, PTy); |
| 703 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 705 | Args.push_back(ArgValue); |
| 706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 708 | Value *V = Builder.CreateCall(F, Args.data(), Args.data() + Args.size()); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 709 | QualType BuiltinRetType = E->getType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 711 | const llvm::Type *RetTy = llvm::Type::getVoidTy(VMContext); |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 712 | if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 714 | if (RetTy != V->getType()) { |
| 715 | assert(V->getType()->canLosslesslyBitCastTo(RetTy) && |
| 716 | "Must be able to losslessly bit cast result type"); |
| 717 | V = Builder.CreateBitCast(V, RetTy); |
| 718 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 719 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 720 | return RValue::get(V); |
| 721 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 723 | // See if we have a target specific builtin that needs to be lowered. |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 724 | if (Value *V = EmitTargetBuiltinExpr(BuiltinID, E)) |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 725 | return RValue::get(V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 726 | |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 727 | ErrorUnsupported(E, "builtin function"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | |
Chris Lattner | b7cfe88 | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 729 | // Unknown builtin, for now just dump it out and return undef. |
| 730 | if (hasAggregateLLVMType(E->getType())) |
Daniel Dunbar | 195337d | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 731 | return RValue::getAggregate(CreateMemTemp(E->getType())); |
Owen Anderson | 03e2050 | 2009-07-30 23:11:26 +0000 | [diff] [blame] | 732 | return RValue::get(llvm::UndefValue::get(ConvertType(E->getType()))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 734 | |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 735 | Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID, |
| 736 | const CallExpr *E) { |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 737 | switch (Target.getTriple().getArch()) { |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 738 | case llvm::Triple::arm: |
| 739 | case llvm::Triple::thumb: |
| 740 | return EmitARMBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 741 | case llvm::Triple::x86: |
| 742 | case llvm::Triple::x86_64: |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 743 | return EmitX86BuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 744 | case llvm::Triple::ppc: |
| 745 | case llvm::Triple::ppc64: |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 746 | return EmitPPCBuiltinExpr(BuiltinID, E); |
Daniel Dunbar | 55cc2ed | 2009-08-24 09:54:37 +0000 | [diff] [blame] | 747 | default: |
| 748 | return 0; |
| 749 | } |
Daniel Dunbar | f02e9dd | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Chris Lattner | 2752c01 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 752 | Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID, |
| 753 | const CallExpr *E) { |
| 754 | switch (BuiltinID) { |
| 755 | default: return 0; |
| 756 | |
| 757 | case ARM::BI__builtin_thread_pointer: { |
| 758 | Value *AtomF = CGM.getIntrinsic(Intrinsic::arm_thread_pointer, 0, 0); |
| 759 | return Builder.CreateCall(AtomF); |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 765 | const CallExpr *E) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 767 | llvm::SmallVector<Value*, 4> Ops; |
| 768 | |
| 769 | for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) |
| 770 | Ops.push_back(EmitScalarExpr(E->getArg(i))); |
| 771 | |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 772 | switch (BuiltinID) { |
Anders Carlsson | 46a26b0 | 2007-12-09 23:39:18 +0000 | [diff] [blame] | 773 | default: return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 774 | case X86::BI__builtin_ia32_pslldi128: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 775 | case X86::BI__builtin_ia32_psllqi128: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | case X86::BI__builtin_ia32_psllwi128: |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 777 | case X86::BI__builtin_ia32_psradi128: |
| 778 | case X86::BI__builtin_ia32_psrawi128: |
| 779 | case X86::BI__builtin_ia32_psrldi128: |
| 780 | case X86::BI__builtin_ia32_psrlqi128: |
| 781 | case X86::BI__builtin_ia32_psrlwi128: { |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 782 | Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::getInt64Ty(VMContext), "zext"); |
| 783 | const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::getInt64Ty(VMContext), 2); |
| 784 | llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0); |
Owen Anderson | 03e2050 | 2009-07-30 23:11:26 +0000 | [diff] [blame] | 785 | Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 786 | Ops[1], Zero, "insert"); |
| 787 | Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); |
| 788 | const char *name = 0; |
| 789 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 791 | switch (BuiltinID) { |
| 792 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 793 | case X86::BI__builtin_ia32_pslldi128: |
| 794 | name = "pslldi"; |
| 795 | ID = Intrinsic::x86_sse2_psll_d; |
| 796 | break; |
| 797 | case X86::BI__builtin_ia32_psllqi128: |
| 798 | name = "psllqi"; |
| 799 | ID = Intrinsic::x86_sse2_psll_q; |
| 800 | break; |
| 801 | case X86::BI__builtin_ia32_psllwi128: |
| 802 | name = "psllwi"; |
| 803 | ID = Intrinsic::x86_sse2_psll_w; |
| 804 | break; |
| 805 | case X86::BI__builtin_ia32_psradi128: |
| 806 | name = "psradi"; |
| 807 | ID = Intrinsic::x86_sse2_psra_d; |
| 808 | break; |
| 809 | case X86::BI__builtin_ia32_psrawi128: |
| 810 | name = "psrawi"; |
| 811 | ID = Intrinsic::x86_sse2_psra_w; |
| 812 | break; |
| 813 | case X86::BI__builtin_ia32_psrldi128: |
| 814 | name = "psrldi"; |
| 815 | ID = Intrinsic::x86_sse2_psrl_d; |
| 816 | break; |
| 817 | case X86::BI__builtin_ia32_psrlqi128: |
| 818 | name = "psrlqi"; |
| 819 | ID = Intrinsic::x86_sse2_psrl_q; |
| 820 | break; |
| 821 | case X86::BI__builtin_ia32_psrlwi128: |
| 822 | name = "psrlwi"; |
| 823 | ID = Intrinsic::x86_sse2_psrl_w; |
| 824 | break; |
| 825 | } |
| 826 | llvm::Function *F = CGM.getIntrinsic(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 828 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | case X86::BI__builtin_ia32_pslldi: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 830 | case X86::BI__builtin_ia32_psllqi: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 831 | case X86::BI__builtin_ia32_psllwi: |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 832 | case X86::BI__builtin_ia32_psradi: |
| 833 | case X86::BI__builtin_ia32_psrawi: |
| 834 | case X86::BI__builtin_ia32_psrldi: |
| 835 | case X86::BI__builtin_ia32_psrlqi: |
| 836 | case X86::BI__builtin_ia32_psrlwi: { |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 837 | Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::getInt64Ty(VMContext), "zext"); |
| 838 | const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::getInt64Ty(VMContext), 1); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 839 | Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 840 | const char *name = 0; |
| 841 | Intrinsic::ID ID = Intrinsic::not_intrinsic; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 843 | switch (BuiltinID) { |
| 844 | default: assert(0 && "Unsupported shift intrinsic!"); |
| 845 | case X86::BI__builtin_ia32_pslldi: |
| 846 | name = "pslldi"; |
| 847 | ID = Intrinsic::x86_mmx_psll_d; |
| 848 | break; |
| 849 | case X86::BI__builtin_ia32_psllqi: |
| 850 | name = "psllqi"; |
| 851 | ID = Intrinsic::x86_mmx_psll_q; |
| 852 | break; |
| 853 | case X86::BI__builtin_ia32_psllwi: |
| 854 | name = "psllwi"; |
| 855 | ID = Intrinsic::x86_mmx_psll_w; |
| 856 | break; |
| 857 | case X86::BI__builtin_ia32_psradi: |
| 858 | name = "psradi"; |
| 859 | ID = Intrinsic::x86_mmx_psra_d; |
| 860 | break; |
| 861 | case X86::BI__builtin_ia32_psrawi: |
| 862 | name = "psrawi"; |
| 863 | ID = Intrinsic::x86_mmx_psra_w; |
| 864 | break; |
| 865 | case X86::BI__builtin_ia32_psrldi: |
| 866 | name = "psrldi"; |
| 867 | ID = Intrinsic::x86_mmx_psrl_d; |
| 868 | break; |
| 869 | case X86::BI__builtin_ia32_psrlqi: |
| 870 | name = "psrlqi"; |
| 871 | ID = Intrinsic::x86_mmx_psrl_q; |
| 872 | break; |
| 873 | case X86::BI__builtin_ia32_psrlwi: |
| 874 | name = "psrlwi"; |
| 875 | ID = Intrinsic::x86_mmx_psrl_w; |
| 876 | break; |
| 877 | } |
Chris Lattner | 7acda7c | 2007-12-18 00:25:38 +0000 | [diff] [blame] | 878 | llvm::Function *F = CGM.getIntrinsic(ID); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name); |
Anders Carlsson | 2929cfa | 2007-12-14 17:48:24 +0000 | [diff] [blame] | 880 | } |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 881 | case X86::BI__builtin_ia32_cmpps: { |
| 882 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps); |
| 883 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpps"); |
| 884 | } |
| 885 | case X86::BI__builtin_ia32_cmpss: { |
| 886 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss); |
| 887 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpss"); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 888 | } |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 889 | case X86::BI__builtin_ia32_ldmxcsr: { |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 890 | const llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(VMContext); |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 891 | Value *One = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1); |
| 892 | Value *Tmp = Builder.CreateAlloca(llvm::Type::getInt32Ty(VMContext), One, "tmp"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 893 | Builder.CreateStore(Ops[0], Tmp); |
| 894 | return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame] | 895 | Builder.CreateBitCast(Tmp, PtrTy)); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 896 | } |
| 897 | case X86::BI__builtin_ia32_stmxcsr: { |
Benjamin Kramer | 3c0ef8c | 2009-10-13 10:07:13 +0000 | [diff] [blame] | 898 | const llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(VMContext); |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 899 | Value *One = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1); |
| 900 | Value *Tmp = Builder.CreateAlloca(llvm::Type::getInt32Ty(VMContext), One, "tmp"); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 901 | One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), |
Chris Lattner | 3eae03e | 2008-05-06 00:56:42 +0000 | [diff] [blame] | 902 | Builder.CreateBitCast(Tmp, PtrTy)); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 903 | return Builder.CreateLoad(Tmp, "stmxcsr"); |
| 904 | } |
Anders Carlsson | 79dcf5f | 2009-05-18 19:16:46 +0000 | [diff] [blame] | 905 | case X86::BI__builtin_ia32_cmppd: { |
| 906 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd); |
| 907 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmppd"); |
| 908 | } |
| 909 | case X86::BI__builtin_ia32_cmpsd: { |
| 910 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd); |
| 911 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpsd"); |
Anders Carlsson | cc8b7f9 | 2007-12-16 22:33:50 +0000 | [diff] [blame] | 912 | } |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 913 | case X86::BI__builtin_ia32_storehps: |
| 914 | case X86::BI__builtin_ia32_storelps: { |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 915 | const llvm::Type *EltTy = llvm::Type::getInt64Ty(VMContext); |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 916 | llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); |
| 917 | llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 918 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 919 | // cast val v2i64 |
| 920 | Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 921 | |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 922 | // extract (0, 1) |
| 923 | unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 924 | llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), Index); |
Nate Begeman | e772210 | 2008-04-14 04:49:57 +0000 | [diff] [blame] | 925 | Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); |
| 926 | |
| 927 | // cast pointer to i64 & store |
| 928 | Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy); |
| 929 | return Builder.CreateStore(Ops[1], Ops[0]); |
| 930 | } |
Eric Christopher | 91b5927 | 2009-12-01 05:00:51 +0000 | [diff] [blame] | 931 | case X86::BI__builtin_ia32_palignr: { |
Nate Begeman | c3420ff | 2009-12-14 05:15:02 +0000 | [diff] [blame] | 932 | Function *F = CGM.getIntrinsic(Intrinsic::x86_ssse3_palign_r); |
| 933 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size()); |
| 934 | } |
| 935 | case X86::BI__builtin_ia32_palignr128: { |
Nate Begeman | ce5818a | 2009-12-14 04:57:03 +0000 | [diff] [blame] | 936 | unsigned shiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue(); |
| 937 | |
| 938 | // If palignr is shifting the pair of input vectors less than 17 bytes, |
| 939 | // emit a shuffle instruction. |
| 940 | if (shiftVal <= 16) { |
| 941 | const llvm::Type *IntTy = llvm::Type::getInt32Ty(VMContext); |
| 942 | |
| 943 | llvm::SmallVector<llvm::Constant*, 16> Indices; |
| 944 | for (unsigned i = 0; i != 16; ++i) |
| 945 | Indices.push_back(llvm::ConstantInt::get(IntTy, shiftVal + i)); |
| 946 | |
| 947 | Value* SV = llvm::ConstantVector::get(Indices.begin(), Indices.size()); |
| 948 | return Builder.CreateShuffleVector(Ops[1], Ops[0], SV, "palignr"); |
| 949 | } |
| 950 | |
| 951 | // If palignr is shifting the pair of input vectors more than 16 but less |
| 952 | // than 32 bytes, emit a logical right shift of the destination. |
| 953 | if (shiftVal < 32) { |
| 954 | const llvm::Type *EltTy = llvm::Type::getInt64Ty(VMContext); |
| 955 | const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); |
| 956 | const llvm::Type *IntTy = llvm::Type::getInt32Ty(VMContext); |
| 957 | |
| 958 | Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast"); |
| 959 | Ops[1] = llvm::ConstantInt::get(IntTy, (shiftVal-16) * 8); |
| 960 | |
| 961 | // create i32 constant |
| 962 | llvm::Function *F = CGM.getIntrinsic(Intrinsic::x86_sse2_psrl_dq); |
| 963 | return Builder.CreateCall(F, &Ops[0], &Ops[0] + 2, "palignr"); |
| 964 | } |
| 965 | |
| 966 | // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. |
| 967 | return llvm::Constant::getNullValue(ConvertType(E->getType())); |
Eric Christopher | 91b5927 | 2009-12-01 05:00:51 +0000 | [diff] [blame] | 968 | } |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 972 | Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, |
Chris Lattner | 1feedd8 | 2007-12-13 07:34:23 +0000 | [diff] [blame] | 973 | const CallExpr *E) { |
Daniel Dunbar | b0b8438 | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 974 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | } |