2007-08-21 02:05:56 +08:00
|
|
|
//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-08-21 02:05:56 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This contains code to emit Builtin calls as LLVM code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "CodeGenModule.h"
|
2007-12-10 05:20:04 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2007-08-31 12:31:45 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2007-08-21 02:05:56 +08:00
|
|
|
#include "clang/AST/Builtins.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
2007-12-10 07:17:02 +08:00
|
|
|
#include "clang/AST/TargetBuiltins.h"
|
2007-08-26 12:17:05 +08:00
|
|
|
#include "llvm/Constants.h"
|
2007-08-31 12:44:06 +08:00
|
|
|
#include "llvm/Function.h"
|
2007-10-13 07:56:29 +08:00
|
|
|
#include "llvm/Intrinsics.h"
|
2007-08-21 02:05:56 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
2007-12-10 05:20:04 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2008-05-10 06:40:52 +08:00
|
|
|
/// Utility to insert an atomic instruction based Instrinsic::ID and
|
|
|
|
// the expression node
|
|
|
|
static RValue EmitBinaryAtomic(CodeGenFunction& CFG,
|
|
|
|
Intrinsic::ID Id, const CallExpr *E) {
|
|
|
|
const llvm::Type *ResType = CFG.ConvertType(E->getType());
|
|
|
|
Value *AtomF = CFG.CGM.getIntrinsic(Id, &ResType, 1);
|
|
|
|
return RValue::get(CFG.Builder.CreateCall2(AtomF,
|
|
|
|
CFG.EmitScalarExpr(E->getArg(0)),
|
|
|
|
CFG.EmitScalarExpr(E->getArg(1))));
|
|
|
|
}
|
|
|
|
|
2007-08-26 12:17:05 +08:00
|
|
|
RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
|
|
|
|
switch (BuiltinID) {
|
2007-12-10 05:20:04 +08:00
|
|
|
default: {
|
2007-08-31 12:44:06 +08:00
|
|
|
if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
|
2008-01-18 02:06:09 +08:00
|
|
|
return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID),
|
2008-01-30 09:32:06 +08:00
|
|
|
E->getCallee()->getType(), E->arg_begin(),
|
|
|
|
E->getNumArgs());
|
2007-12-10 05:20:04 +08:00
|
|
|
|
|
|
|
// See if we have a target specific intrinsic.
|
2007-12-13 15:34:23 +08:00
|
|
|
Intrinsic::ID IntrinsicID;
|
2007-12-10 05:20:04 +08:00
|
|
|
const char *TargetPrefix = Target.getTargetPrefix();
|
|
|
|
const char *BuiltinName = getContext().BuiltinInfo.GetName(BuiltinID);
|
|
|
|
#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
|
|
|
#include "llvm/Intrinsics.gen"
|
|
|
|
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
|
|
|
|
|
|
|
|
if (IntrinsicID != Intrinsic::not_intrinsic) {
|
2007-12-13 15:34:23 +08:00
|
|
|
SmallVector<Value*, 16> Args;
|
2007-12-10 05:20:04 +08:00
|
|
|
|
2007-12-18 08:25:38 +08:00
|
|
|
Function *F = CGM.getIntrinsic(IntrinsicID);
|
2007-12-10 05:20:04 +08:00
|
|
|
const llvm::FunctionType *FTy = F->getFunctionType();
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *ArgValue = EmitScalarExpr(E->getArg(i));
|
2007-12-10 05:20:04 +08:00
|
|
|
|
|
|
|
// If the intrinsic arg type is different from the builtin arg type
|
|
|
|
// we need to do a bit cast.
|
|
|
|
const llvm::Type *PTy = FTy->getParamType(i);
|
|
|
|
if (PTy != ArgValue->getType()) {
|
|
|
|
assert(PTy->canLosslesslyBitCastTo(FTy->getParamType(i)) &&
|
|
|
|
"Must be able to losslessly bit cast to param");
|
|
|
|
ArgValue = Builder.CreateBitCast(ArgValue, PTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
Args.push_back(ArgValue);
|
|
|
|
}
|
|
|
|
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *V = Builder.CreateCall(F, &Args[0], &Args[0] + Args.size());
|
2007-12-10 05:20:04 +08:00
|
|
|
QualType BuiltinRetType = E->getType();
|
|
|
|
|
2007-12-13 15:34:23 +08:00
|
|
|
const llvm::Type *RetTy = llvm::Type::VoidTy;
|
|
|
|
if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType);
|
2007-12-10 05:20:04 +08:00
|
|
|
|
|
|
|
if (RetTy != V->getType()) {
|
|
|
|
assert(V->getType()->canLosslesslyBitCastTo(RetTy) &&
|
|
|
|
"Must be able to losslessly bit cast result type");
|
|
|
|
V = Builder.CreateBitCast(V, RetTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return RValue::get(V);
|
|
|
|
}
|
2007-12-10 07:17:02 +08:00
|
|
|
|
|
|
|
// See if we have a target specific builtin that needs to be lowered.
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *V = 0;
|
2007-12-10 07:17:02 +08:00
|
|
|
|
|
|
|
if (strcmp(TargetPrefix, "x86") == 0)
|
|
|
|
V = EmitX86BuiltinExpr(BuiltinID, E);
|
|
|
|
else if (strcmp(TargetPrefix, "ppc") == 0)
|
|
|
|
V = EmitPPCBuiltinExpr(BuiltinID, E);
|
|
|
|
|
|
|
|
if (V)
|
|
|
|
return RValue::get(V);
|
2007-08-31 12:44:06 +08:00
|
|
|
|
2007-12-02 09:49:16 +08:00
|
|
|
WarnUnsupported(E, "builtin function");
|
2007-08-26 12:17:05 +08:00
|
|
|
|
|
|
|
// Unknown builtin, for now just dump it out and return undef.
|
|
|
|
if (hasAggregateLLVMType(E->getType()))
|
|
|
|
return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType())));
|
2007-12-13 15:34:23 +08:00
|
|
|
return RValue::get(UndefValue::get(ConvertType(E->getType())));
|
2007-12-10 05:20:04 +08:00
|
|
|
}
|
2007-08-26 12:17:05 +08:00
|
|
|
case Builtin::BI__builtin___CFStringMakeConstantString: {
|
|
|
|
const Expr *Arg = E->getArg(0);
|
|
|
|
|
2007-11-01 08:39:26 +08:00
|
|
|
while (1) {
|
|
|
|
if (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
|
|
|
|
Arg = PE->getSubExpr();
|
|
|
|
else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Arg))
|
|
|
|
Arg = CE->getSubExpr();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2007-08-26 12:17:05 +08:00
|
|
|
|
|
|
|
const StringLiteral *Literal = cast<StringLiteral>(Arg);
|
|
|
|
std::string S(Literal->getStrData(), Literal->getByteLength());
|
|
|
|
|
|
|
|
return RValue::get(CGM.GetAddrOfConstantCFString(S));
|
2007-10-13 07:56:29 +08:00
|
|
|
}
|
|
|
|
case Builtin::BI__builtin_va_start:
|
|
|
|
case Builtin::BI__builtin_va_end: {
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *ArgValue = EmitScalarExpr(E->getArg(0));
|
2007-12-17 09:11:20 +08:00
|
|
|
const llvm::Type *DestType =
|
|
|
|
llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
2007-10-13 07:56:29 +08:00
|
|
|
if (ArgValue->getType() != DestType)
|
|
|
|
ArgValue = Builder.CreateBitCast(ArgValue, DestType,
|
|
|
|
ArgValue->getNameStart());
|
|
|
|
|
2007-12-13 15:34:23 +08:00
|
|
|
Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_start) ?
|
|
|
|
Intrinsic::vastart : Intrinsic::vaend;
|
2007-12-18 08:25:38 +08:00
|
|
|
return RValue::get(Builder.CreateCall(CGM.getIntrinsic(inst), ArgValue));
|
2007-10-13 07:56:29 +08:00
|
|
|
}
|
2008-02-10 04:26:43 +08:00
|
|
|
case Builtin::BI__builtin_va_copy: {
|
|
|
|
// FIXME: This does not yet handle architectures where va_list is a struct.
|
|
|
|
Value *DstPtr = EmitScalarExpr(E->getArg(0));
|
|
|
|
Value *SrcValue = EmitScalarExpr(E->getArg(1));
|
|
|
|
|
|
|
|
Value *SrcPtr = CreateTempAlloca(SrcValue->getType(), "dst_ptr");
|
|
|
|
|
|
|
|
// FIXME: Volatile
|
|
|
|
Builder.CreateStore(SrcValue, SrcPtr, false);
|
|
|
|
|
|
|
|
const llvm::Type *Type =
|
|
|
|
llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
|
|
|
|
|
|
|
DstPtr = Builder.CreateBitCast(DstPtr, Type);
|
|
|
|
SrcPtr = Builder.CreateBitCast(SrcPtr, Type);
|
2008-05-06 08:56:42 +08:00
|
|
|
return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy),
|
|
|
|
DstPtr, SrcPtr));
|
2008-02-10 04:26:43 +08:00
|
|
|
}
|
2007-10-29 10:59:40 +08:00
|
|
|
case Builtin::BI__builtin_classify_type: {
|
2007-12-13 15:34:23 +08:00
|
|
|
APSInt Result(32);
|
2007-10-29 10:59:40 +08:00
|
|
|
if (!E->isBuiltinClassifyType(Result))
|
|
|
|
assert(0 && "Expr not __builtin_classify_type!");
|
2007-12-13 15:34:23 +08:00
|
|
|
return RValue::get(ConstantInt::get(Result));
|
2007-10-29 10:59:40 +08:00
|
|
|
}
|
2007-11-01 08:39:26 +08:00
|
|
|
case Builtin::BI__builtin_constant_p: {
|
2007-12-13 15:34:23 +08:00
|
|
|
APSInt Result(32);
|
2007-11-01 08:39:26 +08:00
|
|
|
// FIXME: Analyze the parameter and check if it is a constant.
|
|
|
|
Result = 0;
|
2007-12-13 15:34:23 +08:00
|
|
|
return RValue::get(ConstantInt::get(Result));
|
2007-11-01 08:39:26 +08:00
|
|
|
}
|
2007-11-21 03:05:17 +08:00
|
|
|
case Builtin::BI__builtin_abs: {
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *ArgValue = EmitScalarExpr(E->getArg(0));
|
2007-11-21 03:05:17 +08:00
|
|
|
|
|
|
|
llvm::BinaryOperator *NegOp =
|
|
|
|
Builder.CreateNeg(ArgValue, (ArgValue->getName() + "neg").c_str());
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *CmpResult =
|
2007-11-21 03:05:17 +08:00
|
|
|
Builder.CreateICmpSGE(ArgValue, NegOp->getOperand(0), "abscond");
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *Result =
|
2007-11-21 03:05:17 +08:00
|
|
|
Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs");
|
|
|
|
|
|
|
|
return RValue::get(Result);
|
|
|
|
}
|
2008-02-06 15:19:27 +08:00
|
|
|
case Builtin::BI__builtin_ctz:
|
|
|
|
case Builtin::BI__builtin_ctzl:
|
|
|
|
case Builtin::BI__builtin_ctzll: {
|
|
|
|
Value *ArgValue = EmitScalarExpr(E->getArg(0));
|
|
|
|
|
|
|
|
const llvm::Type *ArgType = ArgValue->getType();
|
|
|
|
Value *F = CGM.getIntrinsic(Intrinsic::cttz, &ArgType, 1);
|
|
|
|
|
|
|
|
const llvm::Type *ResultType = ConvertType(E->getType());
|
|
|
|
Value *Result = Builder.CreateCall(F, ArgValue, "tmp");
|
|
|
|
if (Result->getType() != ResultType)
|
|
|
|
Result = Builder.CreateIntCast(Result, ResultType, "cast");
|
|
|
|
return RValue::get(Result);
|
|
|
|
}
|
2007-12-13 15:34:23 +08:00
|
|
|
case Builtin::BI__builtin_expect:
|
|
|
|
return RValue::get(EmitScalarExpr(E->getArg(0)));
|
2007-12-03 05:58:10 +08:00
|
|
|
case Builtin::BI__builtin_bswap32:
|
|
|
|
case Builtin::BI__builtin_bswap64: {
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *ArgValue = EmitScalarExpr(E->getArg(0));
|
2007-12-03 05:58:10 +08:00
|
|
|
const llvm::Type *ArgType = ArgValue->getType();
|
2007-12-18 08:25:38 +08:00
|
|
|
Value *F = CGM.getIntrinsic(Intrinsic::bswap, &ArgType, 1);
|
2007-12-13 15:34:23 +08:00
|
|
|
return RValue::get(Builder.CreateCall(F, ArgValue, "tmp"));
|
2007-12-03 05:58:10 +08:00
|
|
|
}
|
2007-12-05 15:22:48 +08:00
|
|
|
case Builtin::BI__builtin_inff: {
|
2007-12-13 15:34:23 +08:00
|
|
|
APFloat f(APFloat::IEEEsingle, APFloat::fcInfinity, false);
|
2008-05-05 02:23:51 +08:00
|
|
|
return RValue::get(ConstantFP::get(f));
|
2007-12-05 15:22:48 +08:00
|
|
|
}
|
2008-02-02 00:06:34 +08:00
|
|
|
case Builtin::BI__builtin_huge_val:
|
2007-12-05 15:22:48 +08:00
|
|
|
case Builtin::BI__builtin_inf:
|
|
|
|
// FIXME: mapping long double onto double.
|
|
|
|
case Builtin::BI__builtin_infl: {
|
2007-12-13 15:34:23 +08:00
|
|
|
APFloat f(APFloat::IEEEdouble, APFloat::fcInfinity, false);
|
2008-05-05 02:23:51 +08:00
|
|
|
return RValue::get(ConstantFP::get(f));
|
2007-12-05 15:22:48 +08:00
|
|
|
}
|
2007-12-20 08:44:32 +08:00
|
|
|
case Builtin::BI__builtin_isgreater:
|
|
|
|
case Builtin::BI__builtin_isgreaterequal:
|
|
|
|
case Builtin::BI__builtin_isless:
|
|
|
|
case Builtin::BI__builtin_islessequal:
|
|
|
|
case Builtin::BI__builtin_islessgreater:
|
|
|
|
case Builtin::BI__builtin_isunordered: {
|
|
|
|
// Ordered comparisons: we know the arguments to these are matching scalar
|
|
|
|
// floating point values.
|
|
|
|
Value *LHS = EmitScalarExpr(E->getArg(0));
|
|
|
|
Value *RHS = EmitScalarExpr(E->getArg(1));
|
|
|
|
|
|
|
|
switch (BuiltinID) {
|
|
|
|
default: assert(0 && "Unknown ordered comparison");
|
|
|
|
case Builtin::BI__builtin_isgreater:
|
|
|
|
LHS = Builder.CreateFCmpOGT(LHS, RHS, "cmp");
|
|
|
|
break;
|
|
|
|
case Builtin::BI__builtin_isgreaterequal:
|
|
|
|
LHS = Builder.CreateFCmpOGE(LHS, RHS, "cmp");
|
|
|
|
break;
|
|
|
|
case Builtin::BI__builtin_isless:
|
|
|
|
LHS = Builder.CreateFCmpOLT(LHS, RHS, "cmp");
|
|
|
|
break;
|
|
|
|
case Builtin::BI__builtin_islessequal:
|
|
|
|
LHS = Builder.CreateFCmpOLE(LHS, RHS, "cmp");
|
|
|
|
break;
|
|
|
|
case Builtin::BI__builtin_islessgreater:
|
|
|
|
LHS = Builder.CreateFCmpONE(LHS, RHS, "cmp");
|
|
|
|
break;
|
|
|
|
case Builtin::BI__builtin_isunordered:
|
|
|
|
LHS = Builder.CreateFCmpUNO(LHS, RHS, "cmp");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// ZExt bool to int type.
|
|
|
|
return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType()),
|
|
|
|
"tmp"));
|
|
|
|
}
|
2008-02-06 08:02:50 +08:00
|
|
|
case Builtin::BI__builtin_alloca:
|
|
|
|
return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty,
|
|
|
|
EmitScalarExpr(E->getArg(0)),
|
|
|
|
"tmp"));
|
2008-05-10 06:40:52 +08:00
|
|
|
case Builtin::BI__sync_fetch_and_add:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_las, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_sub:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_lss, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_min:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_min, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_max:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_max, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_umin:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umin, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_umax:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_umax, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_and:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_and, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_or:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_or, E);
|
|
|
|
case Builtin::BI__sync_fetch_and_xor:
|
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_load_xor, E);
|
|
|
|
case Builtin::BI__sync_val_compare_and_swap: {
|
|
|
|
Value *Args[3];
|
|
|
|
Args[0]= EmitScalarExpr(E->getArg(0));
|
|
|
|
Args[1] = EmitScalarExpr(E->getArg(1));
|
|
|
|
Args[2] = EmitScalarExpr(E->getArg(2));
|
|
|
|
const llvm::Type *ResType = ConvertType(E->getType());
|
|
|
|
Value *AtomF = CGM.getIntrinsic(Intrinsic::atomic_lcs, &ResType, 1);
|
|
|
|
return RValue::get(Builder.CreateCall(AtomF, &Args[0], &Args[1]+2));
|
2007-08-21 02:05:56 +08:00
|
|
|
}
|
2008-05-10 06:40:52 +08:00
|
|
|
case Builtin::BI__sync_lock_test_and_set:
|
2008-05-15 15:38:03 +08:00
|
|
|
return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E);
|
|
|
|
}
|
2007-08-21 02:05:56 +08:00
|
|
|
return RValue::get(0);
|
|
|
|
}
|
2007-12-10 07:17:02 +08:00
|
|
|
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
|
|
|
|
const CallExpr *E) {
|
2007-12-15 01:48:24 +08:00
|
|
|
|
|
|
|
llvm::SmallVector<Value*, 4> Ops;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = E->getNumArgs(); i != e; i++)
|
|
|
|
Ops.push_back(EmitScalarExpr(E->getArg(i)));
|
|
|
|
|
2007-12-10 07:17:02 +08:00
|
|
|
switch (BuiltinID) {
|
2007-12-10 07:39:18 +08:00
|
|
|
default: return 0;
|
|
|
|
case X86::BI__builtin_ia32_mulps:
|
2007-12-15 01:48:24 +08:00
|
|
|
return Builder.CreateMul(Ops[0], Ops[1], "mulps");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_mulpd:
|
|
|
|
return Builder.CreateMul(Ops[0], Ops[1], "mulpd");
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_pand:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_pand128:
|
2007-12-15 01:48:24 +08:00
|
|
|
return Builder.CreateAnd(Ops[0], Ops[1], "pand");
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_por:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_por128:
|
|
|
|
return Builder.CreateOr(Ops[0], Ops[1], "por");
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_pxor:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_pxor128:
|
|
|
|
return Builder.CreateXor(Ops[0], Ops[1], "pxor");
|
|
|
|
case X86::BI__builtin_ia32_pandn:
|
|
|
|
case X86::BI__builtin_ia32_pandn128:
|
2007-12-15 01:48:24 +08:00
|
|
|
Ops[0] = Builder.CreateNot(Ops[0], "tmp");
|
|
|
|
return Builder.CreateAnd(Ops[0], Ops[1], "pandn");
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_paddb:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_paddb128:
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_paddd:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_paddd128:
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_paddq:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_paddq128:
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_paddw:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_paddw128:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_addps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_addpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
return Builder.CreateAdd(Ops[0], Ops[1], "add");
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_psubb:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_psubb128:
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_psubd:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_psubd128:
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_psubq:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_psubq128:
|
2007-12-11 10:25:54 +08:00
|
|
|
case X86::BI__builtin_ia32_psubw:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_psubw128:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_subps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_subpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
return Builder.CreateSub(Ops[0], Ops[1], "sub");
|
|
|
|
case X86::BI__builtin_ia32_divps:
|
|
|
|
return Builder.CreateFDiv(Ops[0], Ops[1], "divps");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_divpd:
|
|
|
|
return Builder.CreateFDiv(Ops[0], Ops[1], "divpd");
|
2007-12-11 11:09:22 +08:00
|
|
|
case X86::BI__builtin_ia32_pmullw:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_pmullw128:
|
2007-12-15 01:48:24 +08:00
|
|
|
return Builder.CreateMul(Ops[0], Ops[1], "pmul");
|
2007-12-11 11:09:22 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckhbw:
|
2007-12-18 08:25:38 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15,
|
2007-12-11 11:09:22 +08:00
|
|
|
"punpckhbw");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckhbw128:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 8, 24, 9, 25, 10, 26, 11, 27,
|
|
|
|
12, 28, 13, 29, 14, 30, 15, 31,
|
|
|
|
"punpckhbw");
|
2007-12-11 11:09:22 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckhwd:
|
2007-12-18 08:25:38 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhwd");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckhwd128:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 4, 12, 5, 13, 6, 14, 7, 15,
|
|
|
|
"punpckhwd");
|
2007-12-11 11:09:22 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckhdq:
|
2007-12-18 08:25:38 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 1, 3, "punpckhdq");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckhdq128:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "punpckhdq");
|
2007-12-11 11:09:22 +08:00
|
|
|
case X86::BI__builtin_ia32_punpcklbw:
|
2007-12-18 08:25:38 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11,
|
2007-12-11 11:09:22 +08:00
|
|
|
"punpcklbw");
|
|
|
|
case X86::BI__builtin_ia32_punpcklwd:
|
2007-12-18 08:25:38 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpcklwd");
|
2007-12-11 11:09:22 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckldq:
|
2007-12-18 08:25:38 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 2, "punpckldq");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_punpckldq128:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "punpckldq");
|
|
|
|
case X86::BI__builtin_ia32_pslldi128:
|
|
|
|
case X86::BI__builtin_ia32_psllqi128:
|
|
|
|
case X86::BI__builtin_ia32_psllwi128:
|
|
|
|
case X86::BI__builtin_ia32_psradi128:
|
|
|
|
case X86::BI__builtin_ia32_psrawi128:
|
|
|
|
case X86::BI__builtin_ia32_psrldi128:
|
|
|
|
case X86::BI__builtin_ia32_psrlqi128:
|
|
|
|
case X86::BI__builtin_ia32_psrlwi128: {
|
|
|
|
Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext");
|
|
|
|
const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2);
|
|
|
|
llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
|
|
|
|
Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty),
|
|
|
|
Ops[1], Zero, "insert");
|
|
|
|
Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast");
|
|
|
|
const char *name = 0;
|
|
|
|
Intrinsic::ID ID = Intrinsic::not_intrinsic;
|
|
|
|
|
|
|
|
switch (BuiltinID) {
|
|
|
|
default: assert(0 && "Unsupported shift intrinsic!");
|
|
|
|
case X86::BI__builtin_ia32_pslldi128:
|
|
|
|
name = "pslldi";
|
|
|
|
ID = Intrinsic::x86_sse2_psll_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psllqi128:
|
|
|
|
name = "psllqi";
|
|
|
|
ID = Intrinsic::x86_sse2_psll_q;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psllwi128:
|
|
|
|
name = "psllwi";
|
|
|
|
ID = Intrinsic::x86_sse2_psll_w;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psradi128:
|
|
|
|
name = "psradi";
|
|
|
|
ID = Intrinsic::x86_sse2_psra_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrawi128:
|
|
|
|
name = "psrawi";
|
|
|
|
ID = Intrinsic::x86_sse2_psra_w;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrldi128:
|
|
|
|
name = "psrldi";
|
|
|
|
ID = Intrinsic::x86_sse2_psrl_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrlqi128:
|
|
|
|
name = "psrlqi";
|
|
|
|
ID = Intrinsic::x86_sse2_psrl_q;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrlwi128:
|
|
|
|
name = "psrlwi";
|
|
|
|
ID = Intrinsic::x86_sse2_psrl_w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
llvm::Function *F = CGM.getIntrinsic(ID);
|
|
|
|
return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
|
|
|
|
}
|
2007-12-15 01:48:24 +08:00
|
|
|
case X86::BI__builtin_ia32_pslldi:
|
|
|
|
case X86::BI__builtin_ia32_psllqi:
|
|
|
|
case X86::BI__builtin_ia32_psllwi:
|
|
|
|
case X86::BI__builtin_ia32_psradi:
|
|
|
|
case X86::BI__builtin_ia32_psrawi:
|
|
|
|
case X86::BI__builtin_ia32_psrldi:
|
|
|
|
case X86::BI__builtin_ia32_psrlqi:
|
|
|
|
case X86::BI__builtin_ia32_psrlwi: {
|
|
|
|
Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext");
|
|
|
|
const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1);
|
|
|
|
Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast");
|
|
|
|
const char *name = 0;
|
|
|
|
Intrinsic::ID ID = Intrinsic::not_intrinsic;
|
2007-12-11 10:25:54 +08:00
|
|
|
|
2007-12-15 01:48:24 +08:00
|
|
|
switch (BuiltinID) {
|
|
|
|
default: assert(0 && "Unsupported shift intrinsic!");
|
|
|
|
case X86::BI__builtin_ia32_pslldi:
|
|
|
|
name = "pslldi";
|
|
|
|
ID = Intrinsic::x86_mmx_psll_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psllqi:
|
|
|
|
name = "psllqi";
|
|
|
|
ID = Intrinsic::x86_mmx_psll_q;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psllwi:
|
|
|
|
name = "psllwi";
|
|
|
|
ID = Intrinsic::x86_mmx_psll_w;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psradi:
|
|
|
|
name = "psradi";
|
|
|
|
ID = Intrinsic::x86_mmx_psra_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrawi:
|
|
|
|
name = "psrawi";
|
|
|
|
ID = Intrinsic::x86_mmx_psra_w;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrldi:
|
|
|
|
name = "psrldi";
|
|
|
|
ID = Intrinsic::x86_mmx_psrl_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrlqi:
|
|
|
|
name = "psrlqi";
|
|
|
|
ID = Intrinsic::x86_mmx_psrl_q;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrlwi:
|
|
|
|
name = "psrlwi";
|
|
|
|
ID = Intrinsic::x86_mmx_psrl_w;
|
|
|
|
break;
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_pslldi128:
|
|
|
|
name = "pslldi";
|
|
|
|
ID = Intrinsic::x86_sse2_psll_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psllqi128:
|
|
|
|
name = "psllqi";
|
|
|
|
ID = Intrinsic::x86_sse2_psll_q;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psllwi128:
|
|
|
|
name = "psllwi";
|
|
|
|
ID = Intrinsic::x86_sse2_psll_w;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psradi128:
|
|
|
|
name = "psradi";
|
|
|
|
ID = Intrinsic::x86_sse2_psra_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrawi128:
|
|
|
|
name = "psrawi";
|
|
|
|
ID = Intrinsic::x86_sse2_psra_w;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrldi128:
|
|
|
|
name = "psrldi";
|
|
|
|
ID = Intrinsic::x86_sse2_psrl_d;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrlqi128:
|
|
|
|
name = "psrlqi";
|
|
|
|
ID = Intrinsic::x86_sse2_psrl_q;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_psrlwi128:
|
|
|
|
name = "psrlwi";
|
|
|
|
ID = Intrinsic::x86_sse2_psrl_w;
|
|
|
|
break;
|
2007-12-15 01:48:24 +08:00
|
|
|
}
|
2007-12-18 08:25:38 +08:00
|
|
|
llvm::Function *F = CGM.getIntrinsic(ID);
|
2007-12-15 01:48:24 +08:00
|
|
|
return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
|
|
|
|
}
|
2008-05-15 15:38:03 +08:00
|
|
|
case X86::BI__builtin_ia32_pshuflw: {
|
|
|
|
unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[0],
|
|
|
|
i & 0x3, (i & 0xc) >> 2,
|
|
|
|
(i & 0x30) >> 4, (i & 0xc0) >> 6, 4, 5, 6, 7,
|
|
|
|
"pshuflw");
|
|
|
|
}
|
|
|
|
case X86::BI__builtin_ia32_pshufhw: {
|
|
|
|
unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[0], 0, 1, 2, 3,
|
|
|
|
4 + (i & 0x3), 4 + ((i & 0xc) >> 2),
|
|
|
|
4 + ((i & 0x30) >> 4), 4 + ((i & 0xc0) >> 6),
|
|
|
|
"pshufhw");
|
|
|
|
}
|
2007-12-15 01:48:24 +08:00
|
|
|
case X86::BI__builtin_ia32_pshufd: {
|
2007-12-18 08:25:38 +08:00
|
|
|
unsigned i = cast<ConstantInt>(Ops[1])->getZExtValue();
|
2007-12-15 01:48:24 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[0],
|
2007-12-11 10:25:54 +08:00
|
|
|
i & 0x3, (i & 0xc) >> 2,
|
|
|
|
(i & 0x30) >> 4, (i & 0xc0) >> 6,
|
|
|
|
"pshufd");
|
|
|
|
}
|
2007-12-16 05:23:30 +08:00
|
|
|
case X86::BI__builtin_ia32_vec_init_v4hi:
|
|
|
|
case X86::BI__builtin_ia32_vec_init_v8qi:
|
|
|
|
case X86::BI__builtin_ia32_vec_init_v2si:
|
|
|
|
return EmitVector(&Ops[0], Ops.size());
|
|
|
|
case X86::BI__builtin_ia32_vec_ext_v2si:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_vec_ext_v2di:
|
|
|
|
case X86::BI__builtin_ia32_vec_ext_v4sf:
|
|
|
|
case X86::BI__builtin_ia32_vec_ext_v4si:
|
|
|
|
case X86::BI__builtin_ia32_vec_ext_v2df:
|
2007-12-16 05:23:30 +08:00
|
|
|
return Builder.CreateExtractElement(Ops[0], Ops[1], "result");
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpordss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpordsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpunordss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpunordsd:
|
|
|
|
case X86::BI__builtin_ia32_cmpeqss:
|
|
|
|
case X86::BI__builtin_ia32_cmpeqsd:
|
|
|
|
case X86::BI__builtin_ia32_cmpltss:
|
|
|
|
case X86::BI__builtin_ia32_cmpltsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpless:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmplesd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpneqss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpneqsd:
|
|
|
|
case X86::BI__builtin_ia32_cmpnltss:
|
|
|
|
case X86::BI__builtin_ia32_cmpnltsd:
|
|
|
|
case X86::BI__builtin_ia32_cmpnless:
|
|
|
|
case X86::BI__builtin_ia32_cmpnlesd: {
|
2007-12-18 08:25:38 +08:00
|
|
|
unsigned i = 0;
|
2007-12-17 06:33:50 +08:00
|
|
|
const char *name = 0;
|
|
|
|
switch (BuiltinID) {
|
|
|
|
default: assert(0 && "Unknown compare builtin!");
|
|
|
|
case X86::BI__builtin_ia32_cmpeqss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpeqsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 0;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpeq";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpltss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpltsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 1;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmplt";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpless:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmplesd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 2;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmple";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpunordss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpunordsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 3;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpunord";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpneqss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpneqsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 4;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpneq";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpnltss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpnltsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 5;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpntl";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpnless:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpnlesd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 6;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpnle";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpordss:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpordsd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 7;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpord";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-14 12:49:57 +08:00
|
|
|
llvm::Function *F;
|
|
|
|
if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() ==
|
|
|
|
llvm::Type::FloatTy)
|
|
|
|
F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ss);
|
|
|
|
else
|
|
|
|
F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_sd);
|
|
|
|
|
2007-12-17 06:33:50 +08:00
|
|
|
Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i));
|
|
|
|
return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
|
|
|
|
}
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_ldmxcsr: {
|
|
|
|
llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
|
|
|
Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
|
|
|
|
Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp");
|
|
|
|
Builder.CreateStore(Ops[0], Tmp);
|
|
|
|
return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr),
|
2008-05-06 08:56:42 +08:00
|
|
|
Builder.CreateBitCast(Tmp, PtrTy));
|
2008-04-14 12:49:57 +08:00
|
|
|
}
|
|
|
|
case X86::BI__builtin_ia32_stmxcsr: {
|
|
|
|
llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
|
|
|
Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1);
|
|
|
|
Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp");
|
|
|
|
One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr),
|
2008-05-06 08:56:42 +08:00
|
|
|
Builder.CreateBitCast(Tmp, PtrTy));
|
2008-04-14 12:49:57 +08:00
|
|
|
return Builder.CreateLoad(Tmp, "stmxcsr");
|
|
|
|
}
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpordps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpordpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpunordps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpunordpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpeqps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpeqpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpltps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpltpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpleps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmplepd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpneqps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpneqpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpngtps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpngtpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpnltps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpnltpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgtps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgtpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgeps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgepd:
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpngeps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpngepd:
|
|
|
|
case X86::BI__builtin_ia32_cmpnleps:
|
|
|
|
case X86::BI__builtin_ia32_cmpnlepd: {
|
2007-12-18 08:25:38 +08:00
|
|
|
unsigned i = 0;
|
2007-12-17 06:33:50 +08:00
|
|
|
const char *name = 0;
|
|
|
|
bool ShouldSwap = false;
|
|
|
|
switch (BuiltinID) {
|
|
|
|
default: assert(0 && "Unknown compare builtin!");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpeqps:
|
|
|
|
case X86::BI__builtin_ia32_cmpeqpd: i = 0; name = "cmpeq"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpltps:
|
|
|
|
case X86::BI__builtin_ia32_cmpltpd: i = 1; name = "cmplt"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpleps:
|
|
|
|
case X86::BI__builtin_ia32_cmplepd: i = 2; name = "cmple"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpunordps:
|
|
|
|
case X86::BI__builtin_ia32_cmpunordpd: i = 3; name = "cmpunord"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpneqps:
|
|
|
|
case X86::BI__builtin_ia32_cmpneqpd: i = 4; name = "cmpneq"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpnltps:
|
|
|
|
case X86::BI__builtin_ia32_cmpnltpd: i = 5; name = "cmpntl"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpnleps:
|
|
|
|
case X86::BI__builtin_ia32_cmpnlepd: i = 6; name = "cmpnle"; break;
|
|
|
|
case X86::BI__builtin_ia32_cmpordps:
|
|
|
|
case X86::BI__builtin_ia32_cmpordpd: i = 7; name = "cmpord"; break;
|
2007-12-17 06:33:50 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgtps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgtpd:
|
2007-12-18 08:25:38 +08:00
|
|
|
ShouldSwap = true;
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 1;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpgt";
|
2007-12-17 06:33:50 +08:00
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpgeps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpgepd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 2;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpge";
|
2007-12-17 06:33:50 +08:00
|
|
|
ShouldSwap = true;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpngtps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpngtpd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 5;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpngt";
|
2007-12-17 06:33:50 +08:00
|
|
|
ShouldSwap = true;
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_cmpngeps:
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_cmpngepd:
|
2007-12-17 06:33:50 +08:00
|
|
|
i = 6;
|
2008-04-14 12:49:57 +08:00
|
|
|
name = "cmpnge";
|
2007-12-17 06:33:50 +08:00
|
|
|
ShouldSwap = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldSwap)
|
|
|
|
std::swap(Ops[0], Ops[1]);
|
2008-04-14 12:49:57 +08:00
|
|
|
|
|
|
|
llvm::Function *F;
|
|
|
|
if (cast<llvm::VectorType>(Ops[0]->getType())->getElementType() ==
|
|
|
|
llvm::Type::FloatTy)
|
|
|
|
F = CGM.getIntrinsic(Intrinsic::x86_sse_cmp_ps);
|
|
|
|
else
|
|
|
|
F = CGM.getIntrinsic(Intrinsic::x86_sse2_cmp_pd);
|
2007-12-17 06:33:50 +08:00
|
|
|
|
|
|
|
Ops.push_back(llvm::ConstantInt::get(llvm::Type::Int8Ty, i));
|
|
|
|
return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), name);
|
|
|
|
}
|
|
|
|
case X86::BI__builtin_ia32_movss:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 4, 1, 2, 3, "movss");
|
2008-04-04 14:16:25 +08:00
|
|
|
case X86::BI__builtin_ia32_shufps: {
|
2007-12-18 08:25:38 +08:00
|
|
|
unsigned i = cast<ConstantInt>(Ops[2])->getZExtValue();
|
2007-12-17 06:33:50 +08:00
|
|
|
return EmitShuffleVector(Ops[0], Ops[1],
|
|
|
|
i & 0x3, (i & 0xc) >> 2,
|
|
|
|
((i & 0x30) >> 4) + 4,
|
|
|
|
((i & 0x60) >> 6) + 4, "shufps");
|
2008-04-04 14:16:25 +08:00
|
|
|
}
|
2008-04-04 03:58:06 +08:00
|
|
|
case X86::BI__builtin_ia32_punpcklbw128:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 16, 1, 17, 2, 18, 3, 19,
|
|
|
|
4, 20, 5, 21, 6, 22, 7, 23,
|
|
|
|
"punpcklbw");
|
|
|
|
case X86::BI__builtin_ia32_punpcklwd128:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 8, 1, 9, 2, 10, 3, 11,
|
|
|
|
"punpcklwd");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_movlhps:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 1, 4, 5, "movlhps");
|
|
|
|
case X86::BI__builtin_ia32_movhlps:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 6, 7, 2, 3, "movhlps");
|
|
|
|
case X86::BI__builtin_ia32_unpckhps:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 2, 6, 3, 7, "unpckhps");
|
|
|
|
case X86::BI__builtin_ia32_unpcklps:
|
|
|
|
return EmitShuffleVector(Ops[0], Ops[1], 0, 4, 1, 5, "unpcklps");
|
|
|
|
case X86::BI__builtin_ia32_movqv4si: {
|
|
|
|
llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2);
|
|
|
|
return Builder.CreateBitCast(Ops[0], Ty);
|
|
|
|
}
|
|
|
|
case X86::BI__builtin_ia32_loadlps:
|
|
|
|
case X86::BI__builtin_ia32_loadhps: {
|
|
|
|
// FIXME: This should probably be represented as
|
|
|
|
// shuffle (dst, (v4f32 (insert undef, (load i64), 0)), shuf mask hi/lo)
|
|
|
|
const llvm::Type *EltTy = llvm::Type::DoubleTy;
|
|
|
|
const llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
|
|
|
|
const llvm::Type *OrigTy = Ops[0]->getType();
|
|
|
|
unsigned Index = BuiltinID == X86::BI__builtin_ia32_loadlps ? 0 : 1;
|
|
|
|
llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index);
|
|
|
|
Ops[1] = Builder.CreateBitCast(Ops[1], llvm::PointerType::getUnqual(EltTy));
|
|
|
|
Ops[1] = Builder.CreateLoad(Ops[1], "tmp");
|
|
|
|
Ops[0] = Builder.CreateBitCast(Ops[0], VecTy, "cast");
|
|
|
|
Ops[0] = Builder.CreateInsertElement(Ops[0], Ops[1], Idx, "loadps");
|
|
|
|
return Builder.CreateBitCast(Ops[0], OrigTy, "loadps");
|
|
|
|
}
|
|
|
|
case X86::BI__builtin_ia32_storehps:
|
|
|
|
case X86::BI__builtin_ia32_storelps: {
|
|
|
|
const llvm::Type *EltTy = llvm::Type::Int64Ty;
|
|
|
|
llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy);
|
|
|
|
llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
|
|
|
|
|
|
|
|
// cast val v2i64
|
|
|
|
Ops[1] = Builder.CreateBitCast(Ops[1], VecTy, "cast");
|
|
|
|
|
|
|
|
// extract (0, 1)
|
|
|
|
unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1;
|
|
|
|
llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index);
|
|
|
|
Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract");
|
|
|
|
|
|
|
|
// cast pointer to i64 & store
|
|
|
|
Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy);
|
|
|
|
return Builder.CreateStore(Ops[1], Ops[0]);
|
|
|
|
}
|
|
|
|
case X86::BI__builtin_ia32_loadlv4si: {
|
|
|
|
// load i64
|
|
|
|
const llvm::Type *EltTy = llvm::Type::Int64Ty;
|
|
|
|
llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy);
|
|
|
|
Ops[0] = Builder.CreateBitCast(Ops[0], PtrTy);
|
|
|
|
Ops[0] = Builder.CreateLoad(Ops[0], "load");
|
|
|
|
|
|
|
|
// scalar to vector: insert i64 into 2 x i64 undef
|
|
|
|
llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
|
|
|
|
llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0);
|
|
|
|
Ops[0] = Builder.CreateInsertElement(llvm::UndefValue::get(VecTy),
|
|
|
|
Ops[0], Zero, "s2v");
|
|
|
|
|
|
|
|
// shuffle into zero vector.
|
|
|
|
std::vector<llvm::Constant *>Elts;
|
|
|
|
Elts.resize(2, llvm::ConstantInt::get(EltTy, 0));
|
|
|
|
llvm::Value *ZV = ConstantVector::get(Elts);
|
|
|
|
Ops[0] = EmitShuffleVector(ZV, Ops[0], 2, 1, "loadl");
|
|
|
|
|
|
|
|
// bitcast to result.
|
|
|
|
return Builder.CreateBitCast(Ops[0],
|
|
|
|
llvm::VectorType::get(llvm::Type::Int32Ty, 4));
|
|
|
|
}
|
2008-05-17 02:59:42 +08:00
|
|
|
case X86::BI__builtin_ia32_vec_set_v4hi:
|
|
|
|
case X86::BI__builtin_ia32_vec_set_v8hi:
|
|
|
|
return Builder.CreateInsertElement(Ops[0], Ops[1], Ops[2], "pinsrw");
|
2008-04-14 12:49:57 +08:00
|
|
|
case X86::BI__builtin_ia32_andps:
|
|
|
|
case X86::BI__builtin_ia32_andpd:
|
|
|
|
case X86::BI__builtin_ia32_andnps:
|
|
|
|
case X86::BI__builtin_ia32_andnpd:
|
|
|
|
case X86::BI__builtin_ia32_orps:
|
|
|
|
case X86::BI__builtin_ia32_orpd:
|
|
|
|
case X86::BI__builtin_ia32_xorpd:
|
|
|
|
case X86::BI__builtin_ia32_xorps: {
|
|
|
|
const llvm::Type *ITy = llvm::VectorType::get(llvm::Type::Int32Ty, 4);
|
|
|
|
const llvm::Type *FTy = Ops[0]->getType();
|
|
|
|
Ops[0] = Builder.CreateBitCast(Ops[0], ITy, "bitcast");
|
|
|
|
Ops[1] = Builder.CreateBitCast(Ops[1], ITy, "bitcast");
|
|
|
|
switch (BuiltinID) {
|
|
|
|
case X86::BI__builtin_ia32_andps:
|
|
|
|
Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andps");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_andpd:
|
|
|
|
Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andpd");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_andnps:
|
|
|
|
Ops[0] = Builder.CreateNot(Ops[0], "not");
|
|
|
|
Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnps");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_andnpd:
|
|
|
|
Ops[0] = Builder.CreateNot(Ops[0], "not");
|
|
|
|
Ops[0] = Builder.CreateAnd(Ops[0], Ops[1], "andnpd");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_orps:
|
|
|
|
Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orps");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_orpd:
|
|
|
|
Ops[0] = Builder.CreateOr(Ops[0], Ops[1], "orpd");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_xorps:
|
|
|
|
Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorps");
|
|
|
|
break;
|
|
|
|
case X86::BI__builtin_ia32_xorpd:
|
|
|
|
Ops[0] = Builder.CreateXor(Ops[0], Ops[1], "xorpd");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Builder.CreateBitCast(Ops[0], FTy, "bitcast");
|
|
|
|
}
|
2007-12-10 07:17:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-13 15:34:23 +08:00
|
|
|
Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID,
|
|
|
|
const CallExpr *E) {
|
2007-12-10 07:17:02 +08:00
|
|
|
switch (BuiltinID) {
|
2007-12-10 07:39:18 +08:00
|
|
|
default: return 0;
|
2007-12-10 07:17:02 +08:00
|
|
|
}
|
|
|
|
}
|