Lines Matching refs:CI

56   /// performed.  If it returns CI, then it transformed the call and CI is to be
57 /// deleted. If it returns something else, replace CI with the new value and
58 /// delete CI.
59 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)
66 Value *optimizeCall(CallInst *CI, const DataLayout *TD,
69 Caller = CI->getParent()->getParent();
73 if (CI->getCalledFunction())
74 Context = &CI->getCalledFunction()->getContext();
77 if (!ignoreCallingConv() && CI->getCallingConv() != llvm::CallingConv::C)
80 return callOptimizer(CI->getCalledFunction(), CI, B);
118 static bool callHasFloatingPointArgument(const CallInst *CI) {
119 for (CallInst::const_op_iterator it = CI->op_begin(), e = CI->op_end();
153 CallInst *CI;
156 if (CI->getArgOperand(SizeCIOp) == CI->getArgOperand(SizeArgOp))
159 dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
163 uint64_t Len = GetStringLength(CI->getArgOperand(SizeArgOp));
170 CI->getArgOperand(SizeArgOp)))
178 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
179 this->CI = CI;
181 LLVMContext &Context = CI->getParent()->getContext();
192 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
193 CI->getArgOperand(2), 1);
194 return CI->getArgOperand(0);
201 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
202 this->CI = CI;
204 LLVMContext &Context = CI->getParent()->getContext();
215 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
216 CI->getArgOperand(2), 1);
217 return CI->getArgOperand(0);
224 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
225 this->CI = CI;
227 LLVMContext &Context = CI->getParent()->getContext();
238 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
240 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
241 return CI->getArgOperand(0);
248 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
249 this->CI = CI;
252 LLVMContext &Context = CI->getParent()->getContext();
262 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
285 CI->getArgOperand(2), B, TD, TLI);
293 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
294 this->CI = CI;
297 LLVMContext &Context = CI->getParent()->getContext();
307 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
334 if (!EmitMemCpyChk(Dst, Src, LenV, CI->getArgOperand(2), B, TD, TLI))
343 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
344 this->CI = CI;
347 LLVMContext &Context = CI->getParent()->getContext();
358 Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
359 CI->getArgOperand(2), B, TD, TLI,
372 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
382 Value *Dst = CI->getArgOperand(0);
383 Value *Src = CI->getArgOperand(1);
422 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
433 Value *Dst = CI->getArgOperand(0);
434 Value *Src = CI->getArgOperand(1);
438 if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
466 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
475 Value *SrcStr = CI->getArgOperand(0);
479 ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
488 return EmitMemChr(SrcStr, CI->getArgOperand(1), // include nul.
504 return Constant::getNullValue(CI->getType());
512 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
521 Value *SrcStr = CI->getArgOperand(0);
522 ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
540 return Constant::getNullValue(CI->getType());
548 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
557 Value *Str1P = CI->getArgOperand(0), *Str2P = CI->getArgOperand(1);
559 return ConstantInt::get(CI->getType(), 0);
567 return ConstantInt::get(CI->getType(), Str1.compare(Str2));
571 CI->getType()));
574 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
593 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
603 Value *Str1P = CI->getArgOperand(0), *Str2P = CI->getArgOperand(1);
605 return ConstantInt::get(CI->getType(), 0);
609 if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
615 return ConstantInt::get(CI->getType(), 0);
618 return EmitMemCmp(Str1P, Str2P, CI->getArgOperand(2), B, TD, TLI);
628 return ConstantInt::get(CI->getType(), SubStr1.compare(SubStr2));
633 CI->getType()));
636 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
643 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
652 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
672 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
684 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
708 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
716 Value *Dst = CI->getArgOperand(0);
717 Value *Src = CI->getArgOperand(1);
718 Value *LenOp = CI->getArgOperand(2);
756 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
763 Value *Src = CI->getArgOperand(0);
767 return ConstantInt::get(CI->getType(), Len-1);
771 if (isOnlyUsedInZeroEqualityComparison(CI))
772 return B.CreateZExt(B.CreateLoad(Src, "strlenfirst"), CI->getType());
778 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
787 bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);
788 bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);
793 return Constant::getNullValue(CI->getType());
799 return Constant::getNullValue(CI->getType());
801 return B.CreateGEP(CI->getArgOperand(0), B.getInt64(I), "strpbrk");
806 return EmitStrChr(CI->getArgOperand(0), S2[0], B, TD, TLI);
813 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
820 Value *EndPtr = CI->getArgOperand(1);
824 CI->addAttribute(1, Attribute::NoCapture);
832 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
841 bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);
842 bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);
847 return Constant::getNullValue(CI->getType());
853 return ConstantInt::get(CI->getType(), Pos);
861 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
870 bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);
871 bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);
875 return Constant::getNullValue(CI->getType());
881 return ConstantInt::get(CI->getType(), Pos);
886 return EmitStrLen(CI->getArgOperand(0), B, TD, TLI);
893 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
902 if (CI->getArgOperand(0) == CI->getArgOperand(1))
903 return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
906 if (TD && isOnlyUsedInEqualityComparison(CI, CI->getArgOperand(0))) {
907 Value *StrLen = EmitStrLen(CI->getArgOperand(1), B, TD, TLI);
910 Value *StrNCmp = EmitStrNCmp(CI->getArgOperand(0), CI->getArgOperand(1),
914 for (Value::use_iterator UI = CI->use_begin(), UE = CI->use_end();
922 return CI;
927 bool HasStr1 = getConstantStringInfo(CI->getArgOperand(0), SearchStr);
928 bool HasStr2 = getConstantStringInfo(CI->getArgOperand(1), ToFindStr);
932 return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
939 return Constant::getNullValue(CI->getType());
942 Value *Result = CastToCStr(CI->getArgOperand(0), B);
944 return B.CreateBitCast(Result, CI->getType());
949 Value *StrChr= EmitStrChr(CI->getArgOperand(0), ToFindStr[0], B, TD, TLI);
950 return StrChr ? B.CreateBitCast(StrChr, CI->getType()) : 0;
957 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
964 Value *LHS = CI->getArgOperand(0), *RHS = CI->getArgOperand(1);
967 return Constant::getNullValue(CI->getType());
970 ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getArgOperand(2));
975 return Constant::getNullValue(CI->getType());
980 CI->getType(), "lhsv");
982 CI->getType(), "rhsv");
1001 return ConstantInt::get(CI->getType(), Ret);
1009 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1021 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
1022 CI->getArgOperand(2), 1);
1023 return CI->getArgOperand(0);
1028 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1040 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
1041 CI->getArgOperand(2), 1);
1042 return CI->getArgOperand(0);
1047 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1059 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
1060 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
1061 return CI->getArgOperand(0);
1075 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1083 for (Value::use_iterator UseI = CI->use_begin(); UseI != CI->use_end();
1092 FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getArgOperand(0));
1112 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1117 Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);
1128 Value *Op1 = CI->getArgOperand(0);
1139 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1144 Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);
1155 Value *Op1 = CI->getArgOperand(0), *Op2 = CI->getArgOperand(1);
1171 return ConstantFP::get(CI->getType(), 1.0);
1183 Value *Inf = ConstantFP::getInfinity(CI->getType());
1184 Value *NegInf = ConstantFP::getInfinity(CI->getType(), true);
1199 return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0),
1207 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1212 Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);
1222 Value *Op = CI->getArgOperand(0);
1251 CallInst *CI = B.CreateCall2(Callee, One, LdExpArg);
1253 CI->setCallingConv(F->getCallingConv());
1255 return CI;
1264 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1267 if (!isTrigLibCall(CI))
1270 Value *Arg = CI->getArgOperand(0);
1282 classifyArgUse(*UI, CI->getParent(), IsFloat, SinCalls, CosCalls,
1290 insertSinCosCall(B, CI->getCalledFunction(), Arg, IsFloat, Sin, Cos,
1300 bool isTrigLibCall(CallInst *CI) {
1301 Function *Callee = CI->getCalledFunction();
1306 bool AttributesSafe = CI->hasFnAttr(Attribute::NoUnwind) &&
1307 CI->hasFnAttr(Attribute::ReadNone);
1320 CallInst *CI = dyn_cast<CallInst>(Val);
1322 if (!CI)
1325 Function *Callee = CI->getCalledFunction();
1329 !isTrigLibCall(CI))
1334 SinCalls.push_back(CI);
1336 CosCalls.push_back(CI);
1338 SinCosCalls.push_back(CI);
1341 SinCalls.push_back(CI);
1343 CosCalls.push_back(CI);
1345 SinCosCalls.push_back(CI);
1415 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1424 Value *Op = CI->getArgOperand(0);
1427 if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
1428 if (CI->isZero()) // ffs(0) -> 0.
1431 return B.getInt32(CI->getValue().countTrailingZeros() + 1);
1449 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1457 Value *Op = CI->getArgOperand(0);
1466 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1474 Value *Op = CI->getArgOperand(0);
1477 return B.CreateZExt(Op, CI->getType());
1482 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1490 Value *Op = CI->getArgOperand(0);
1492 return B.CreateZExt(Op, CI->getType());
1497 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1505 return B.CreateAnd(CI->getArgOperand(0),
1506 ConstantInt::get(CI->getType(),0x7F));
1517 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &) {
1527 if (!CI->hasFnAttr(Attribute::Cold) && isReportingError(Callee, CI)) {
1528 CI->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
1535 bool isReportingError(Function *Callee, CallInst *CI) {
1548 if (StreamArg >= (int) CI->getNumArgOperands())
1550 LoadInst *LI = dyn_cast<LoadInst>(CI->getArgOperand(StreamArg));
1563 Value *optimizeFixedFormatString(Function *Callee, CallInst *CI,
1567 if (!getConstantStringInfo(CI->getArgOperand(0), FormatStr))
1572 return CI->use_empty() ? (Value*)CI :
1573 ConstantInt::get(CI->getType(), 0);
1578 if (!CI->use_empty())
1584 if (CI->use_empty() || !Res) return Res;
1585 return B.CreateIntCast(Res, CI->getType(), true);
1596 return (CI->use_empty() || !NewCI) ?
1598 ConstantInt::get(CI->getType(), FormatStr.size()+1);
1603 if (FormatStr == "%c" && CI->getNumArgOperands() > 1 &&
1604 CI->getArgOperand(1)->getType()->isIntegerTy()) {
1605 Value *Res = EmitPutChar(CI->getArgOperand(1), B, TD, TLI);
1607 if (CI->use_empty() || !Res) return Res;
1608 return B.CreateIntCast(Res, CI->getType(), true);
1612 if (FormatStr == "%s\n" && CI->getNumArgOperands() > 1 &&
1613 CI->getArgOperand(1)->getType()->isPointerTy()) {
1614 return EmitPutS(CI->getArgOperand(1), B, TD, TLI);
1619 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1627 if (Value *V = optimizeFixedFormatString(Callee, CI, B)) {
1633 if (TLI->has(LibFunc::iprintf) && !callHasFloatingPointArgument(CI)) {
1637 CallInst *New = cast<CallInst>(CI->clone());
1647 Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,
1651 if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))
1655 if (CI->getNumArgOperands() == 2) {
1666 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
1669 return ConstantInt::get(CI->getType(), FormatStr.size());
1675 CI->getNumArgOperands() < 3)
1681 if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return 0;
1682 Value *V = B.CreateTrunc(CI->getArgOperand(2), B.getInt8Ty(), "char");
1683 Value *Ptr = CastToCStr(CI->getArgOperand(0), B);
1688 return ConstantInt::get(CI->getType(), 1);
1696 if (!CI->getArgOperand(2)->getType()->isPointerTy()) return 0;
1698 Value *Len = EmitStrLen(CI->getArgOperand(2), B, TD, TLI);
1704 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), IncLen, 1);
1707 return B.CreateIntCast(Len, CI->getType(), false);
1712 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1720 if (Value *V = OptimizeFixedFormatString(Callee, CI, B)) {
1726 if (TLI->has(LibFunc::siprintf) && !callHasFloatingPointArgument(CI)) {
1730 CallInst *New = cast<CallInst>(CI->clone());
1740 Value *optimizeFixedFormatString(Function *Callee, CallInst *CI,
1743 (void) ER.callOptimizer(Callee, CI, B);
1747 if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))
1753 if (!CI->use_empty())
1757 if (CI->getNumArgOperands() == 2) {
1765 return EmitFWrite(CI->getArgOperand(1),
1768 CI->getArgOperand(0), B, TD, TLI);
1774 CI->getNumArgOperands() < 3)
1780 if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return 0;
1781 return EmitFPutC(CI->getArgOperand(2), CI->getArgOperand(0), B, TD, TLI);
1786 if (!CI->getArgOperand(2)->getType()->isPointerTy())
1788 return EmitFPutS(CI->getArgOperand(2), CI->getArgOperand(0), B, TD, TLI);
1793 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1801 if (Value *V = optimizeFixedFormatString(Callee, CI, B)) {
1807 if (TLI->has(LibFunc::fiprintf) && !callHasFloatingPointArgument(CI)) {
1811 CallInst *New = cast<CallInst>(CI->clone());
1821 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1823 (void) ER.callOptimizer(Callee, CI, B);
1835 ConstantInt *SizeC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
1836 ConstantInt *CountC = dyn_cast<ConstantInt>(CI->getArgOperand(2));
1842 return ConstantInt::get(CI->getType(), 0);
1846 if (Bytes == 1 && CI->use_empty()) { // fwrite(S,1,1,F) -> fputc(S[0],F)
1847 Value *Char = B.CreateLoad(CastToCStr(CI->getArgOperand(0), B), "char");
1848 Value *NewCI = EmitFPutC(Char, CI->getArgOperand(3), B, TD, TLI);
1849 return NewCI ? ConstantInt::get(CI->getType(), 1) : 0;
1857 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1859 (void) ER.callOptimizer(Callee, CI, B);
1868 !CI->use_empty())
1872 uint64_t Len = GetStringLength(CI->getArgOperand(0));
1875 return EmitFWrite(CI->getArgOperand(0),
1877 CI->getArgOperand(1), B, TD, TLI);
1882 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1892 if (!getConstantStringInfo(CI->getArgOperand(0), Str))
1895 if (Str.empty() && CI->use_empty()) {
1898 if (CI->use_empty() || !Res) return Res;
1899 return B.CreateIntCast(Res, CI->getType(), true);
1931 Value *optimizeCall(CallInst *CI);
1932 LibCallOptimization *lookupOptimization(CallInst *CI);
1999 LibCallOptimization *LibCallSimplifierImpl::lookupOptimization(CallInst *CI) {
2001 Function *Callee = CI->getCalledFunction();
2005 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI)) {
2174 Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {
2175 LibCallOptimization *LCO = lookupOptimization(CI);
2177 IRBuilder<> Builder(CI);
2178 return LCO->optimizeCall(CI, TD, TLI, LCS, Builder);
2193 Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
2194 if (CI->isNoBuiltin()) return 0;
2195 return Impl->optimizeCall(CI);