Home | History | Annotate | Download | only in Scalar

Lines Matching refs:CI

60   /// performed.  If it returns CI, then it transformed the call and CI is to be
61 /// deleted. If it returns something else, replace CI with the new value and
62 /// delete CI.
63 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)
66 Value *OptimizeCall(CallInst *CI, const TargetData *TD,
68 Caller = CI->getParent()->getParent();
71 if (CI->getCalledFunction())
72 Context = &CI->getCalledFunction()->getContext();
75 if (CI->getCallingConv() != llvm::CallingConv::C)
78 return CallOptimizer(CI->getCalledFunction(), CI, B);
104 static bool CallHasFloatingPointArgument(const CallInst *CI) {
105 for (CallInst::const_op_iterator it = CI->op_begin(), e = CI->op_end();
135 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
145 Value *Dst = CI->getArgOperand(0);
146 Value *Src = CI->getArgOperand(1);
185 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
196 Value *Dst = CI->getArgOperand(0);
197 Value *Src = CI->getArgOperand(1);
201 if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
233 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
242 Value *SrcStr = CI->getArgOperand(0);
246 ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
255 return EmitMemChr(SrcStr, CI->getArgOperand(1), // include nul.
272 return Constant::getNullValue(CI->getType());
283 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
292 Value *SrcStr = CI->getArgOperand(0);
293 ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
313 return Constant::getNullValue(CI->getType());
324 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
333 Value *Str1P = CI->getArgOperand(0), *Str2P = CI->getArgOperand(1);
335 return ConstantInt::get(CI->getType(), 0);
343 return ConstantInt::get(CI->getType(),
348 CI->getType()));
351 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
373 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
383 Value *Str1P = CI->getArgOperand(0), *Str2P = CI->getArgOperand(1);
385 return ConstantInt::get(CI->getType(), 0);
389 if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
395 return ConstantInt::get(CI->getType(), 0);
398 return EmitMemCmp(Str1P, Str2P, CI->getArgOperand(2), B, TD);
408 return ConstantInt::get(CI->getType(), SubStr1.compare(SubStr2));
413 CI->getType()));
416 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
431 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
441 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
457 CI->getArgOperand(2), B, TD);
469 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
477 Value *Dst = CI->getArgOperand(0);
478 Value *Src = CI->getArgOperand(1);
479 Value *LenOp = CI->getArgOperand(2);
518 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
525 Value *Src = CI->getArgOperand(0);
529 return ConstantInt::get(CI->getType(), Len-1);
533 if (IsOnlyUsedInZeroEqualityComparison(CI))
534 return B.CreateZExt(B.CreateLoad(Src, "strlenfirst"), CI->getType());
544 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
553 bool HasS1 = GetConstantStringInfo(CI->getArgOperand(0), S1);
554 bool HasS2 = GetConstantStringInfo(CI->getArgOperand(1), S2);
559 return Constant::getNullValue(CI->getType());
565 return Constant::getNullValue(CI->getType());
567 return B.CreateGEP(CI->getArgOperand(0), B.getInt64(I), "strpbrk");
572 return EmitStrChr(CI->getArgOperand(0), S2[0], B, TD);
582 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
589 Value *EndPtr = CI->getArgOperand(1);
593 CI->addAttribute(1, Attribute::NoCapture);
604 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
613 bool HasS1 = GetConstantStringInfo(CI->getArgOperand(0), S1);
614 bool HasS2 = GetConstantStringInfo(CI->getArgOperand(1), S2);
619 return Constant::getNullValue(CI->getType());
623 return ConstantInt::get(CI->getType(), strspn(S1.c_str(), S2.c_str()));
633 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
642 bool HasS1 = GetConstantStringInfo(CI->getArgOperand(0), S1);
643 bool HasS2 = GetConstantStringInfo(CI->getArgOperand(1), S2);
647 return Constant::getNullValue(CI->getType());
651 return ConstantInt::get(CI->getType(), strcspn(S1.c_str(), S2.c_str()));
655 return EmitStrLen(CI->getArgOperand(0), B, TD);
665 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
674 if (CI->getArgOperand(0) == CI->getArgOperand(1))
675 return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
678 if (TD && IsOnlyUsedInEqualityComparison(CI, CI->getArgOperand(0))) {
679 Value *StrLen = EmitStrLen(CI->getArgOperand(1), B, TD);
680 Value *StrNCmp = EmitStrNCmp(CI->getArgOperand(0), CI->getArgOperand(1),
682 for (Value::use_iterator UI = CI->use_begin(), UE = CI->use_end();
691 return CI;
696 bool HasStr1 = GetConstantStringInfo(CI->getArgOperand(0), SearchStr);
697 bool HasStr2 = GetConstantStringInfo(CI->getArgOperand(1), ToFindStr);
701 return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
708 return Constant::getNullValue(CI->getType());
711 Value *Result = CastToCStr(CI->getArgOperand(0), B);
713 return B.CreateBitCast(Result, CI->getType());
718 return B.CreateBitCast(EmitStrChr(CI->getArgOperand(0),
719 ToFindStr[0], B, TD), CI->getType());
729 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
736 Value *LHS = CI->getArgOperand(0), *RHS = CI->getArgOperand(1);
739 return Constant::getNullValue(CI->getType());
742 ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getArgOperand(2));
747 return Constant::getNullValue(CI->getType());
752 CI->getType(), "lhsv");
754 CI->getType(), "rhsv");
766 return ConstantInt::get(CI->getType(), Ret);
777 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
789 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
790 CI->getArgOperand(2), 1);
791 return CI->getArgOperand(0);
799 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
811 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
812 CI->getArgOperand(2), 1);
813 return CI->getArgOperand(0);
821 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
833 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
834 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
835 return CI->getArgOperand(0);
847 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
856 Value *Op1 = CI->getArgOperand(0), *Op2 = CI->getArgOperand(1);
868 return ConstantFP::get(CI->getType(), 1.0);
876 Value *Inf = ConstantFP::getInfinity(CI->getType());
877 Value *NegInf = ConstantFP::getInfinity(CI->getType(), true);
892 return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0),
902 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
910 Value *Op = CI->getArgOperand(0);
939 CallInst *CI = B.CreateCall2(Callee, One, LdExpArg);
941 CI->setCallingConv(F->getCallingConv());
943 return CI;
953 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
960 FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getArgOperand(0));
980 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
989 Value *Op = CI->getArgOperand(0);
992 if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
993 if (CI->getValue() == 0) // ffs(0) -> 0.
994 return Constant::getNullValue(CI->getType());
996 return B.getInt32(CI->getValue().countTrailingZeros() + 1);
1016 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1024 Value *Op = CI->getArgOperand(0);
1027 return B.CreateZExt(Op, CI->getType());
1035 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1043 Value *Op = CI->getArgOperand(0);
1045 return B.CreateZExt(Op, CI->getType());
1053 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1061 Value *Op = CI->getArgOperand(0);
1074 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1082 return B.CreateAnd(CI->getArgOperand(0),
1083 ConstantInt::get(CI->getType(),0x7F));
1095 Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,
1099 if (!GetConstantStringInfo(CI->getArgOperand(0), FormatStr))
1104 return CI->use_empty() ? (Value*)CI :
1105 ConstantInt::get(CI->getType(), 0);
1110 if (!CI->use_empty())
1116 if (CI->use_empty()) return CI;
1117 return B.CreateIntCast(Res, CI->getType(), true);
1130 return CI->use_empty() ? (Value*)CI :
1131 ConstantInt::get(CI->getType(), FormatStr.size()+1);
1136 if (FormatStr == "%c" && CI->getNumArgOperands() > 1 &&
1137 CI->getArgOperand(1)->getType()->isIntegerTy()) {
1138 Value *Res = EmitPutChar(CI->getArgOperand(1), B, TD);
1140 if (CI->use_empty()) return CI;
1141 return B.CreateIntCast(Res, CI->getType(), true);
1145 if (FormatStr == "%s\n" && CI->getNumArgOperands() > 1 &&
1146 CI->getArgOperand(1)->getType()->isPointerTy()) {
1147 EmitPutS(CI->getArgOperand(1), B, TD);
1148 return CI;
1153 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1161 if (Value *V = OptimizeFixedFormatString(Callee, CI, B)) {
1167 if (TLI->has(LibFunc::iprintf) && !CallHasFloatingPointArgument(CI)) {
1171 CallInst *New = cast<CallInst>(CI->clone());
1184 Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,
1188 if (!GetConstantStringInfo(CI->getArgOperand(1), FormatStr))
1192 if (CI->getNumArgOperands() == 2) {
1203 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
1206 return ConstantInt::get(CI->getType(), FormatStr.size());
1212 CI->getNumArgOperands() < 3)
1218 if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return 0;
1219 Value *V = B.CreateTrunc(CI->getArgOperand(2), B.getInt8Ty(), "char");
1220 Value *Ptr = CastToCStr(CI->getArgOperand(0), B);
1225 return ConstantInt::get(CI->getType(), 1);
1233 if (!CI->getArgOperand(2)->getType()->isPointerTy()) return 0;
1235 Value *Len = EmitStrLen(CI->getArgOperand(2), B, TD);
1239 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), IncLen, 1);
1242 return B.CreateIntCast(Len, CI->getType(), false);
1247 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1255 if (Value *V = OptimizeFixedFormatString(Callee, CI, B)) {
1261 if (TLI->has(LibFunc::siprintf) && !CallHasFloatingPointArgument(CI)) {
1265 CallInst *New = cast<CallInst>(CI->clone());
1278 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1289 ConstantInt *SizeC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
1290 ConstantInt *CountC = dyn_cast<ConstantInt>(CI->getArgOperand(2));
1296 return ConstantInt::get(CI->getType(), 0);
1300 Value *Char = B.CreateLoad(CastToCStr(CI->getArgOperand(0), B), "char");
1301 EmitFPutC(Char, CI->getArgOperand(3), B, TD);
1302 return ConstantInt::get(CI->getType(), 1);
1313 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1321 !CI->use_empty())
1325 uint64_t Len = GetStringLength(CI->getArgOperand(0));
1327 EmitFWrite(CI->getArgOperand(0),
1329 CI->getArgOperand(1), B, TD);
1330 return CI; // Known to have no uses (see above).
1338 Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,
1342 if (!GetConstantStringInfo(CI->getArgOperand(1), FormatStr))
1346 if (CI->getNumArgOperands() == 2) {
1354 EmitFWrite(CI->getArgOperand(1),
1357 CI->getArgOperand(0), B, TD);
1358 return ConstantInt::get(CI->getType(), FormatStr.size());
1364 CI->getNumArgOperands() < 3)
1370 if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return 0;
1371 EmitFPutC(CI->getArgOperand(2), CI->getArgOperand(0), B, TD);
1372 return ConstantInt::get(CI->getType(), 1);
1377 if (!CI->getArgOperand(2)->getType()->isPointerTy() || !CI->use_empty())
1379 EmitFPutS(CI->getArgOperand(2), CI->getArgOperand(0), B, TD);
1380 return CI;
1385 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1393 if (Value *V = OptimizeFixedFormatString(Callee, CI, B)) {
1399 if (TLI->has(LibFunc::fiprintf) && !CallHasFloatingPointArgument(CI)) {
1403 CallInst *New = cast<CallInst>(CI->clone());
1416 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
1426 if (!GetConstantStringInfo(CI->getArgOperand(0), Str))
1429 if (Str.empty() && CI->use_empty()) {
1432 if (CI->use_empty()) return CI;
1433 return B.CreateIntCast(Res, CI->getType(), true);
1608 CallInst *CI = dyn_cast<CallInst>(I++);
1609 if (!CI) continue;
1612 Function *Callee = CI->getCalledFunction();
1624 // Use debug location of CI for all new instructions.
1625 Builder.SetCurrentDebugLocation(CI->getDebugLoc());
1628 Value *Result = LCO->OptimizeCall(CI, TD, TLI, Builder);
1631 DEBUG(dbgs() << "SimplifyLibCalls simplified: " << *CI;
1640 I = CI; ++I;
1642 if (CI != Result && !CI->use_empty()) {
1643 CI->replaceAllUsesWith(Result);
1645 Result->takeName(CI);
1647 CI->eraseFromParent();