llvm.org GIT mirror llvm / b41b5e0
Get rid of these cache variables, which are a holdover from the days when we had multiple type planes and these lookups were expensive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74319 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
2 changed file(s) with 30 addition(s) and 76 deletion(s). Raw diff Collapse all Expand all
2424
2525 class IntrinsicLowering {
2626 const TargetData& TD;
27
28 Constant *SetjmpFCache;
29 Constant *LongjmpFCache;
30 Constant *AbortFCache;
31 Constant *MemcpyFCache;
32 Constant *MemmoveFCache;
33 Constant *MemsetFCache;
34 Constant *sqrtFCache;
35 Constant *sqrtDCache;
36 Constant *sqrtLDCache;
37 Constant *logFCache;
38 Constant *logDCache;
39 Constant *logLDCache;
40 Constant *log2FCache;
41 Constant *log2DCache;
42 Constant *log2LDCache;
43 Constant *log10FCache;
44 Constant *log10DCache;
45 Constant *log10LDCache;
46 Constant *expFCache;
47 Constant *expDCache;
48 Constant *expLDCache;
49 Constant *exp2FCache;
50 Constant *exp2DCache;
51 Constant *exp2LDCache;
52 Constant *powFCache;
53 Constant *powDCache;
54 Constant *powLDCache;
27
5528
5629 bool Warned;
5730 public:
5831 explicit IntrinsicLowering(const TargetData &td) :
59 TD(td), SetjmpFCache(0), LongjmpFCache(0), AbortFCache(0),
60 MemcpyFCache(0), MemmoveFCache(0), MemsetFCache(0), sqrtFCache(0),
61 sqrtDCache(0), sqrtLDCache(0), logFCache(0), logDCache(0), logLDCache(0),
62 log2FCache(0), log2DCache(0), log2LDCache(0), log10FCache(0),
63 log10DCache(0), log10LDCache(0), expFCache(0), expDCache(0),
64 expLDCache(0), exp2FCache(0), exp2DCache(0), exp2LDCache(0), powFCache(0),
65 powDCache(0), powLDCache(0), Warned(false) {}
32 TD(td), Warned(false) {}
6633
6734 /// AddPrototypes - This method, if called, causes all of the prototypes
6835 /// that might be needed by an intrinsic lowering implementation to be
6060 template
6161 static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
6262 ArgIt ArgBegin, ArgIt ArgEnd,
63 const Type *RetTy, Constant *&FCache) {
64 if (!FCache) {
65 // If we haven't already looked up this function, check to see if the
66 // program already contains a function with this name.
67 Module *M = CI->getParent()->getParent()->getParent();
68 // Get or insert the definition now.
69 std::vector ParamTys;
70 for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
71 ParamTys.push_back((*I)->getType());
72 FCache = M->getOrInsertFunction(NewFn,
73 FunctionType::get(RetTy, ParamTys, false));
74 }
63 const Type *RetTy) {
64 // If we haven't already looked up this function, check to see if the
65 // program already contains a function with this name.
66 Module *M = CI->getParent()->getParent()->getParent();
67 // Get or insert the definition now.
68 std::vector ParamTys;
69 for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
70 ParamTys.push_back((*I)->getType());
71 Constant* FCache = M->getOrInsertFunction(NewFn,
72 FunctionType::get(RetTy, ParamTys, false));
7573
7674 IRBuilder<> Builder(CI->getParent(), CI);
7775 SmallVector Args(ArgBegin, ArgEnd);
623621 return NewCI;
624622 }
625623
626 static void ReplaceFPIntrinsicWithCall(CallInst *CI, Constant *FCache,
627 Constant *DCache, Constant *LDCache,
628 const char *Fname, const char *Dname,
624 static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname,
625 const char *Dname,
629626 const char *LDname) {
630627 switch (CI->getOperand(1)->getType()->getTypeID()) {
631628 default: assert(0 && "Invalid type in intrinsic"); abort();
632629 case Type::FloatTyID:
633630 ReplaceCallWith(Fname, CI, CI->op_begin() + 1, CI->op_end(),
634 Type::FloatTy, FCache);
631 Type::FloatTy);
635632 break;
636633 case Type::DoubleTyID:
637634 ReplaceCallWith(Dname, CI, CI->op_begin() + 1, CI->op_end(),
638 Type::DoubleTy, DCache);
635 Type::DoubleTy);
639636 break;
640637 case Type::X86_FP80TyID:
641638 case Type::FP128TyID:
642639 case Type::PPC_FP128TyID:
643640 ReplaceCallWith(LDname, CI, CI->op_begin() + 1, CI->op_end(),
644 CI->getOperand(1)->getType(), LDCache);
641 CI->getOperand(1)->getType());
645642 break;
646643 }
647644 }
668665 // convert the call to an explicit setjmp or longjmp call.
669666 case Intrinsic::setjmp: {
670667 Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin() + 1, CI->op_end(),
671 Type::Int32Ty, SetjmpFCache);
668 Type::Int32Ty);
672669 if (CI->getType() != Type::VoidTy)
673670 CI->replaceAllUsesWith(V);
674671 break;
680677
681678 case Intrinsic::longjmp: {
682679 ReplaceCallWith("longjmp", CI, CI->op_begin() + 1, CI->op_end(),
683 Type::VoidTy, LongjmpFCache);
680 Type::VoidTy);
684681 break;
685682 }
686683
687684 case Intrinsic::siglongjmp: {
688685 // Insert the call to abort
689686 ReplaceCallWith("abort", CI, CI->op_end(), CI->op_end(),
690 Type::VoidTy, AbortFCache);
687 Type::VoidTy);
691688 break;
692689 }
693690 case Intrinsic::ctpop:
785782 Ops[0] = CI->getOperand(1);
786783 Ops[1] = CI->getOperand(2);
787784 Ops[2] = Size;
788 ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getOperand(1)->getType(),
789 MemcpyFCache);
785 ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getOperand(1)->getType());
790786 break;
791787 }
792788 case Intrinsic::memmove: {
797793 Ops[0] = CI->getOperand(1);
798794 Ops[1] = CI->getOperand(2);
799795 Ops[2] = Size;
800 ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getOperand(1)->getType(),
801 MemmoveFCache);
796 ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getOperand(1)->getType());
802797 break;
803798 }
804799 case Intrinsic::memset: {
811806 Ops[1] = Builder.CreateIntCast(CI->getOperand(2), Type::Int32Ty,
812807 /* isSigned */ false);
813808 Ops[2] = Size;
814 ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(1)->getType(),
815 MemsetFCache);
809 ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(1)->getType());
816810 break;
817811 }
818812 case Intrinsic::sqrt: {
819 ReplaceFPIntrinsicWithCall(CI, sqrtFCache, sqrtDCache, sqrtLDCache,
820 "sqrtf", "sqrt", "sqrtl");
813 ReplaceFPIntrinsicWithCall(CI, "sqrtf", "sqrt", "sqrtl");
821814 break;
822815 }
823816 case Intrinsic::log: {
824 ReplaceFPIntrinsicWithCall(CI, logFCache, logDCache, logLDCache,
825 "logf", "log", "logl");
817 ReplaceFPIntrinsicWithCall(CI, "logf", "log", "logl");
826818 break;
827819 }
828820 case Intrinsic::log2: {
829 ReplaceFPIntrinsicWithCall(CI, log2FCache, log2DCache, log2LDCache,
830 "log2f", "log2", "log2l");
821 ReplaceFPIntrinsicWithCall(CI, "log2f", "log2", "log2l");
831822 break;
832823 }
833824 case Intrinsic::log10: {
834 ReplaceFPIntrinsicWithCall(CI, log10FCache, log10DCache, log10LDCache,
835 "log10f", "log10", "log10l");
825 ReplaceFPIntrinsicWithCall(CI, "log10f", "log10", "log10l");
836826 break;
837827 }
838828 case Intrinsic::exp: {
839 ReplaceFPIntrinsicWithCall(CI, expFCache, expDCache, expLDCache,
840 "expf", "exp", "expl");
829 ReplaceFPIntrinsicWithCall(CI, "expf", "exp", "expl");
841830 break;
842831 }
843832 case Intrinsic::exp2: {
844 ReplaceFPIntrinsicWithCall(CI, exp2FCache, exp2DCache, exp2LDCache,
845 "exp2f", "exp2", "exp2l");
833 ReplaceFPIntrinsicWithCall(CI, "exp2f", "exp2", "exp2l");
846834 break;
847835 }
848836 case Intrinsic::pow: {
849 ReplaceFPIntrinsicWithCall(CI, powFCache, powDCache, powLDCache,
850 "powf", "pow", "powl");
837 ReplaceFPIntrinsicWithCall(CI, "powf", "pow", "powl");
851838 break;
852839 }
853840 case Intrinsic::flt_rounds: