Revision: 127735 Author: clattner Date: 2007-05-27 08:51:11 -0700 (Sun, 27 May 2007)
Log Message: ----------- simplify this code through the use of Intrinsic::getDeclaration Modified Paths: -------------- apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp Modified: apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp =================================================================== --- apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp 2007-05-27 15:33:17 UTC (rev 127734) +++ apple-local/branches/llvm/gcc/config/rs6000/llvm-rs6000.cpp 2007-05-27 15:51:11 UTC (rev 127735) @@ -34,30 +34,19 @@ #include "toplev.h" } -/* MergeIntPtrOperand - This merges the int and pointer operands of a GCC - * intrinsic into a single operand for the LLVM intrinsic. For example, this - * turns LVX(4, p) -> llvm.lvx(gep P, 4). OPNUM specifies the operand number - * of the integer to contract with its following pointer and NAME specifies the - * name of the resultant intrinsic. - */ -static void MergeIntPtrOperand(TreeToLLVM *TTL, Constant *&Cache, - unsigned OpNum, const char *Name, +// MergeIntPtrOperand - This merges the int and pointer operands of a GCC +// intrinsic into a single operand for the LLVM intrinsic. For example, this +// turns LVX(4, p) -> llvm.lvx(gep P, 4). OPNUM specifies the operand number +// of the integer to contract with its following pointer and NAME specifies the +// name of the resultant intrinsic. +static void MergeIntPtrOperand(TreeToLLVM *TTL, + unsigned OpNum, Intrinsic::ID IID, const Type *ResultType, std::vector<Value*> &Ops, LLVMBuilder &Builder, Value *&Result) { const Type *VoidPtrTy = PointerType::get(Type::Int8Ty); - if (!Cache) { - std::vector<const Type*> ArgTys; - for (unsigned i = 0, e = Ops.size(); i != e; ++i) - ArgTys.push_back(Ops[i]->getType()); - - ArgTys.erase(ArgTys.begin() + OpNum); - ArgTys[OpNum] = VoidPtrTy; - FunctionType *FT = FunctionType::get(ResultType, ArgTys, false); - Module *M = Builder.GetInsertBlock()->getParent()->getParent(); - Cache = M->getOrInsertFunction(Name, FT); - } + Function *IntFn = Intrinsic::getDeclaration(TheModule, IID); Value *Offset = Ops[OpNum]; Value *Ptr = Ops[OpNum + 1]; @@ -68,7 +57,7 @@ Ops.erase(Ops.begin() + OpNum); Ops[OpNum] = Ptr; - Value *V = Builder.CreateCall(Cache, &Ops[0], Ops.size()); + Value *V = Builder.CreateCall(IntFn, &Ops[0], Ops.size()); if (V->getType() != Type::VoidTy) { V->setName("tmp"); @@ -76,9 +65,8 @@ } } -/* GetAltivecTypeNumFromType - Given an LLVM type, return a unique ID for - * the type in the range 0-3. - */ +// GetAltivecTypeNumFromType - Given an LLVM type, return a unique ID for +// the type in the range 0-3. static int GetAltivecTypeNumFromType(const Type *Ty) { return ((Ty == Type::Int32Ty) ? 0 : \ ((Ty == Type::Int16Ty) ? 1 : \ @@ -86,20 +74,10 @@ ((Ty == Type::FloatTy) ? 3 : -1)))); } -/* GetAltivecLetterFromType - Given an LLVM type, return the altivec letter - * for the type, e.g. int -> w. - */ -static char GetAltivecLetterFromType(const Type *Ty) { - return ((Ty == Type::Int32Ty) ? 'w' : - ((Ty == Type::Int16Ty) ? 'h' : - ((Ty == Type::Int8Ty) ? 'b' : - ((Ty == Type::FloatTy) ? 'f' : 'x')))); -} - -/* TargetIntrinsicLower - To handle builtins, we want to expand the - * invocation into normal LLVM code. If the target can handle the builtin, this - * function should emit the expanded code and return true. - */ +// TargetIntrinsicLower - To handle builtins, we want to expand the +//invocation into normal LLVM code. If the target can handle the builtin, this +//function should emit the expanded code and return true. +// bool TreeToLLVM::TargetIntrinsicLower(tree exp, unsigned FnCode, Value *DestLoc, @@ -137,77 +115,53 @@ case ALTIVEC_BUILTIN_VXOR: Result = Builder.CreateXor(Ops[0], Ops[1], "tmp"); return true; - case ALTIVEC_BUILTIN_LVSL: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvsl", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_LVSL: + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvsl, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_LVSR: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvsr", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_LVSR: + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvsr, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_LVX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvx", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_LVX: + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvx, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_LVXL: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvxl", + case ALTIVEC_BUILTIN_LVXL: + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvxl, ResultType, Ops, Builder, Result); - } return true; - case ALTIVEC_BUILTIN_LVEBX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvebx", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_LVEBX: + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvebx, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_LVEHX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvehx", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_LVEHX: + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvehx, + ResultType, Ops, Builder, Result); return true; case ALTIVEC_BUILTIN_LVEWX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 0, "llvm.ppc.altivec.lvewx", - ResultType, Ops, Builder, Result); - } + MergeIntPtrOperand(this, 0, Intrinsic::ppc_altivec_lvewx, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_STVX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvx", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_STVX: + MergeIntPtrOperand(this, 1, Intrinsic::ppc_altivec_stvx, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_STVEBX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvebx", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_STVEBX: + MergeIntPtrOperand(this, 1, Intrinsic::ppc_altivec_stvebx, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_STVEHX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvehx", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_STVEHX: + MergeIntPtrOperand(this, 1, Intrinsic::ppc_altivec_stvehx, + ResultType, Ops, Builder, Result); return true; case ALTIVEC_BUILTIN_STVEWX: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvewx", - ResultType, Ops, Builder, Result); - } + MergeIntPtrOperand(this, 1, Intrinsic::ppc_altivec_stvewx, + ResultType, Ops, Builder, Result); return true; - case ALTIVEC_BUILTIN_STVXL: { - static Constant *Cache = NULL; - MergeIntPtrOperand(this, Cache, 1, "llvm.ppc.altivec.stvxl", - ResultType, Ops, Builder, Result); - } + case ALTIVEC_BUILTIN_STVXL: + MergeIntPtrOperand(this, 1, Intrinsic::ppc_altivec_stvxl, + ResultType, Ops, Builder, Result); return true; case ALTIVEC_BUILTIN_VSPLTISB: if (Constant *Elt = dyn_cast<ConstantInt>(Ops[0])) { @@ -327,7 +281,7 @@ Result = BuildVectorShuffle(Ops[0], Ops[1], 2, 6, 3, 7); return true; case ALTIVEC_BUILTIN_ABS_V4SF: { - /* and out sign bits */ + // and out sign bits VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4); Ops[0] = Builder.CreateBitCast(Ops[0], v4i32, "tmp"); Constant *C = ConstantInt::get(Type::Int32Ty, 0x7FFFFFFF); @@ -338,44 +292,45 @@ } case ALTIVEC_BUILTIN_ABS_V4SI: case ALTIVEC_BUILTIN_ABS_V8HI: - case ALTIVEC_BUILTIN_ABS_V16QI: { /* iabs(x) -> smax(x, 0-x) */ + case ALTIVEC_BUILTIN_ABS_V16QI: { // iabs(x) -> smax(x, 0-x) Result = Builder.CreateNeg(Ops[0], "tmp"); - /* get the right smax intrinsic. */ - static Constant *smax[3]; + // get the right smax intrinsic. + static const unsigned smax_iid[3] = { + Intrinsic::ppc_altivec_vmaxsw, + Intrinsic::ppc_altivec_vmaxsh, + Intrinsic::ppc_altivec_vmaxsb + }; const VectorType *PTy = cast<VectorType>(ResultType); unsigned N = GetAltivecTypeNumFromType(PTy->getElementType()); - if (smax[N] == 0) { - Module *M = Builder.GetInsertBlock()->getParent()->getParent(); - smax[N] = M->getOrInsertFunction(std::string ("llvm.ppc.altivec.vmaxs")+ - GetAltivecLetterFromType(PTy->getElementType ()), - ResultType, ResultType, ResultType, NULL); - } - Result = Builder.CreateCall(smax[N], Ops[0], Result, "tmp"); + Function *smax = Intrinsic::getDeclaration(TheModule, smax_iid[N]); + Result = Builder.CreateCall(smax, Ops[0], Result, "tmp"); return true; } case ALTIVEC_BUILTIN_ABSS_V4SI: case ALTIVEC_BUILTIN_ABSS_V8HI: - case ALTIVEC_BUILTIN_ABSS_V16QI: { /* iabss(x) -> smax(x, satsub (0,x)) */ + case ALTIVEC_BUILTIN_ABSS_V16QI: { // iabss(x) -> smax(x, satsub (0,x)) + // get the right smax/subs intrinsics. + static const unsigned smax_iid[3] = { + Intrinsic::ppc_altivec_vmaxsw, + Intrinsic::ppc_altivec_vmaxsh, + Intrinsic::ppc_altivec_vmaxsb + }; + static const unsigned subss_iid[3] = { + Intrinsic::ppc_altivec_vsubsws, + Intrinsic::ppc_altivec_vsubshs, + Intrinsic::ppc_altivec_vsubsbs + }; + static Constant *sxs[3], *smax[3]; - /* get the right satsub intrinsic. */ + // get the right satsub intrinsic. const VectorType *PTy = cast<VectorType>(ResultType); unsigned N = GetAltivecTypeNumFromType(PTy->getElementType()); - if (sxs[N] == 0) { - Module *M = Builder.GetInsertBlock()->getParent()->getParent(); - sxs[N] = M->getOrInsertFunction(std::string ("llvm.ppc.altivec.vsubs")+ - GetAltivecLetterFromType(PTy->getElementType()) +"s", - ResultType, ResultType, ResultType, NULL); - } - Result = Constant::getNullValue(ResultType); - Result = Builder.CreateCall(sxs[N], Result, Ops[0], "tmp"); - /* get the right smax intrinsic. */ - if (smax[N] == 0) { - Module *M = Builder.GetInsertBlock()->getParent()->getParent(); - smax[N] = M->getOrInsertFunction(std::string ("llvm.ppc.altivec.vmaxs")+ - GetAltivecLetterFromType(PTy->getElementType ()), - ResultType, ResultType, ResultType, NULL); - } - Result = Builder.CreateCall(smax[N], Ops[0], Result, "tmp"); + Function *smax = Intrinsic::getDeclaration(TheModule, smax_iid[N]); + Function *subss = Intrinsic::getDeclaration(TheModule, subss_iid [N]); + + Result = Builder.CreateCall(subss, Constant::getNullValue (ResultType), + Ops[0], "tmp"); + Result = Builder.CreateCall(smax, Ops[0], Result, "tmp"); return true; } } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits