51 cl::desc(
"Enable unsafe double to float "
52 "shrinking for math lib calls"));
59 cl::desc(
"Enable hot/cold operator new library calls"));
63 "Enable optimization of existing hot/cold operator new library calls"));
70struct HotColdHintParser :
public cl::parser<unsigned> {
73 bool parse(cl::Option &O, StringRef ArgName, StringRef Arg,
unsigned &
Value) {
75 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
78 return O.error(
"'" + Arg +
"' value must be in the range [0, 255]!");
92 cl::desc(
"Value to pass to hot/cold operator new for cold allocation"));
95 cl::desc(
"Value to pass to hot/cold operator new for "
96 "notcold (warm) allocation"));
99 cl::desc(
"Value to pass to hot/cold operator new for hot allocation"));
103 "Value to pass to hot/cold operator new for ambiguous allocation"));
110 return Func == LibFunc_abs || Func == LibFunc_labs ||
111 Func == LibFunc_llabs || Func == LibFunc_strlen;
118 if (IC->isEquality() && IC->getOperand(1) == With)
128 return OI->getType()->isFloatingPointTy();
134 return OI->getType()->isFP128Ty();
167 bool Negate = Str[0] ==
'-';
168 if (Str[0] ==
'-' || Str[0] ==
'+') {
169 Str = Str.drop_front();
180 uint64_t Max = AsSigned && Negate ? 1 : 0;
184 if (Str.size() > 1) {
186 if (
toUpper((
unsigned char)Str[1]) ==
'X') {
187 if (Str.size() == 2 || (
Base &&
Base != 16))
192 Str = Str.drop_front(2);
198 }
else if (
Base == 0)
208 for (
unsigned i = 0; i != Str.size(); ++i) {
209 unsigned char DigVal = Str[i];
211 DigVal = DigVal -
'0';
215 DigVal = DigVal -
'A' + 10;
228 if (VFlow || Result > Max)
236 Value *StrEnd =
B.CreateInBoundsGEP(
B.getInt8Ty(), StrBeg, Off,
"endptr");
237 B.CreateStore(StrEnd, EndPtr);
244 return ConstantInt::get(RetTy, Result);
251 if (
C->isNullValue())
279 for (
unsigned ArgNo : ArgNos) {
280 uint64_t DerefBytes = DereferenceableBytes;
285 DereferenceableBytes);
304 for (
unsigned ArgNo : ArgNos) {
330 DerefMin = std::min(
X,
Y);
351 NewCI->
getContext(), {NewCI->getAttributes(), Old.getAttributes()}));
364 return Len >= Str.size() ? Str : Str.substr(0, Len);
389 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, Len,
B));
392Value *LibCallSimplifier::emitStrLenMemCpy(
Value *Src,
Value *Dst, uint64_t Len,
403 Value *CpyDst =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, DstLen,
"endptr");
408 TLI->getAsSizeT(Len + 1, *
B.GetInsertBlock()->getModule()));
452 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, SrcLen,
B));
465 Type *CharTy =
B.getInt8Ty();
466 Value *Char0 =
B.CreateLoad(CharTy, Src);
467 CharVal =
B.CreateTrunc(CharVal, CharTy);
468 Value *Cmp =
B.CreateICmpEQ(Char0, CharVal,
"char0cmp");
472 Value *
And =
B.CreateICmpNE(NBytes, Zero);
473 Cmp =
B.CreateLogicalAnd(
And, Cmp);
477 return B.CreateSelect(Cmp, Src, NullPtr);
499 FunctionType *FT =
Callee->getFunctionType();
500 unsigned IntBits = TLI->getIntSize();
501 if (!FT->getParamType(1)->isIntegerTy(IntBits))
504 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
508 ConstantInt::get(SizeTTy, Len),
B,
517 return B.CreateIntToPtr(
B.getTrue(), CI->
getType());
526 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, StrLen,
"strchr");
539 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(
I),
"strchr");
551 if (CharC && CharC->
isZero())
556 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
561 uint64_t NBytes = Str.size() + 1;
562 Value *
Size = ConstantInt::get(SizeTTy, NBytes);
569 return ConstantInt::get(CI->
getType(), 0);
571 StringRef Str1, Str2;
576 if (HasStr1 && HasStr2)
577 return ConstantInt::get(CI->
getType(),
578 std::clamp(Str1.
compare(Str2), -1, 1));
580 if (HasStr1 && Str1.
empty())
581 return B.CreateNeg(
B.CreateZExt(
582 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
584 if (HasStr2 && Str2.
empty())
585 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
599 TLI->getAsSizeT(std::min(Len1, Len2), *CI->
getModule()),
604 if (!HasStr1 && HasStr2) {
609 }
else if (HasStr1 && !HasStr2) {
631 return ConstantInt::get(CI->
getType(), 0);
643 return ConstantInt::get(CI->
getType(), 0);
648 StringRef Str1, Str2;
653 if (HasStr1 && HasStr2) {
657 return ConstantInt::get(CI->
getType(),
658 std::clamp(SubStr1.
compare(SubStr2), -1, 1));
661 if (HasStr1 && Str1.
empty())
662 return B.CreateNeg(
B.CreateZExt(
663 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
665 if (HasStr2 && Str2.
empty())
666 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
677 if (!HasStr1 && HasStr2) {
678 Len2 = std::min(Len2,
Length);
683 }
else if (HasStr1 && !HasStr2) {
684 Len1 = std::min(Len1,
Length);
698 if (SrcLen &&
Size) {
700 if (SrcLen <= Size->getZExtValue() + 1)
722 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
737 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
748 Value *DstEnd =
B.CreateInBoundsGEP(
749 B.getInt8Ty(), Dst, TLI->getAsSizeT(Len - 1, *CI->
getModule()));
753 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1), LenV);
772 NBytes = SizeC->getZExtValue();
781 B.CreateStore(
B.getInt8(0), Dst);
794 uint64_t SrcLen = Str.find(
'\0');
797 bool NulTerm = SrcLen < NBytes;
806 SrcLen = std::min(SrcLen, uint64_t(Str.size()));
807 NBytes = std::min(NBytes - 1, SrcLen);
812 B.CreateStore(
B.getInt8(0), Dst);
813 return ConstantInt::get(CI->
getType(), 0);
819 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
820 TLI->getAsSizeT(NBytes, *CI->
getModule()));
824 Value *EndOff = ConstantInt::get(CI->
getType(), NBytes);
825 Value *EndPtr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, EndOff);
826 B.CreateStore(
B.getInt8(0), EndPtr);
832 return ConstantInt::get(CI->
getType(), SrcLen);
837Value *LibCallSimplifier::optimizeStringNCpy(
CallInst *CI,
bool RetEnd,
854 N = SizeC->getZExtValue();
861 Type *CharTy =
B.getInt8Ty();
862 Value *CharVal =
B.CreateLoad(CharTy, Src,
"stxncpy.char0");
863 B.CreateStore(CharVal, Dst);
869 Value *ZeroChar = ConstantInt::get(CharTy, 0);
870 Value *
Cmp =
B.CreateICmpEQ(CharVal, ZeroChar,
"stpncpy.char0cmp");
872 Value *Off1 =
B.getInt32(1);
873 Value *EndPtr =
B.CreateInBoundsGEP(CharTy, Dst, Off1,
"stpncpy.end");
874 return B.CreateSelect(Cmp, Dst, EndPtr,
"stpncpy.sel");
889 CI->
getAttributes().getParamAttrs(0).getAlignment().valueOrOne();
890 CallInst *NewCI =
B.CreateMemSet(Dst,
B.getInt8(
'\0'),
Size, MemSetAlign);
898 if (
N > SrcLen + 1) {
907 std::string SrcStr = Str.str();
910 SrcStr.resize(
N,
'\0');
911 Src =
B.CreateGlobalString(SrcStr,
"str", 0,
917 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
926 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, Off,
"endptr");
943 return B.CreateZExt(
B.CreateLoad(CharTy, Src,
"char0"),
949 if (BoundCst->isZero())
951 return ConstantInt::get(CI->
getType(), 0);
953 if (BoundCst->isOne()) {
955 Value *CharVal =
B.CreateLoad(CharTy, Src,
"strnlen.char0");
956 Value *ZeroChar = ConstantInt::get(CharTy, 0);
957 Value *
Cmp =
B.CreateICmpNE(CharVal, ZeroChar,
"strnlen.char0cmp");
958 return B.CreateZExt(Cmp, CI->
getType());
968 return B.CreateBinaryIntrinsic(Intrinsic::umin, LenC, Bound);
985 unsigned BW = DL.getIndexTypeSizeInBits(
GEP->getType());
986 SmallMapVector<Value *, APInt, 4> VarOffsets;
987 APInt ConstOffset(BW, 0);
988 assert(CharSize % 8 == 0 &&
"Expected a multiple of 8 sized CharSize");
990 if (!
GEP->collectOffset(DL, BW, VarOffsets, ConstOffset) ||
991 VarOffsets.
size() != 1 || ConstOffset != 0 ||
992 VarOffsets.
begin()->second != CharSize / 8)
995 ConstantDataArraySlice Slice;
997 uint64_t NullTermIdx;
998 if (Slice.
Array ==
nullptr) {
1001 NullTermIdx = ~((uint64_t)0);
1002 for (uint64_t
I = 0,
E = Slice.
Length;
I <
E; ++
I) {
1010 if (NullTermIdx == ~((uint64_t)0))
1023 NullTermIdx == Slice.
Length - 1)) {
1025 return B.CreateSub(ConstantInt::get(CI->
getType(), NullTermIdx),
1035 if (LenTrue && LenFalse) {
1037 return OptimizationRemark(
"instcombine",
"simplify-libcalls", CI)
1038 <<
"folded strlen(select) to select of constants";
1040 return B.CreateSelect(
SI->getCondition(),
1041 ConstantInt::get(CI->
getType(), LenTrue - 1),
1042 ConstantInt::get(CI->
getType(), LenFalse - 1));
1050 if (
Value *V = optimizeStringLength(CI,
B, 8))
1058 if (
Value *V = optimizeStringLength(CI,
B, 8, Bound))
1068 unsigned WCharSize = TLI->getWCharSize(M) * 8;
1073 return optimizeStringLength(CI,
B, WCharSize);
1083 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1087 if (HasS1 && HasS2) {
1088 size_t I =
S1.find_first_of(S2);
1093 B.getInt64(
I),
"strpbrk");
1097 if (HasS2 && S2.
size() == 1)
1122 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1126 if (HasS1 && HasS2) {
1127 size_t Pos =
S1.find_first_not_of(S2);
1130 return ConstantInt::get(CI->
getType(), Pos);
1142 if (HasS1 &&
S1.empty())
1146 if (HasS1 && HasS2) {
1147 size_t Pos =
S1.find_first_of(S2);
1150 return ConstantInt::get(CI->
getType(), Pos);
1154 if (HasS2 && S2.
empty())
1171 StrLen,
B, DL, TLI);
1179 replaceAllUsesWith(Old, Cmp);
1185 StringRef SearchStr, ToFindStr;
1190 if (HasStr2 && ToFindStr.
empty())
1194 if (HasStr1 && HasStr2) {
1201 return B.CreateConstInBoundsGEP1_64(
B.getInt8Ty(), CI->
getArgOperand(0),
1206 if (HasStr2 && ToFindStr.
size() == 1) {
1227 if (LenC->
isOne()) {
1230 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memrchr.char0");
1232 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1233 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memrchr.char0cmp");
1234 return B.CreateSelect(Cmp, SrcStr, NullPtr,
"memrchr.sel");
1242 if (Str.size() == 0)
1251 if (Str.size() < EndOff)
1266 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos));
1268 if (Str.find(Str[Pos]) == Pos) {
1275 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
1276 B.getInt64(Pos),
"memrchr.ptr_plus");
1277 return B.CreateSelect(Cmp, NullPtr, SrcPlus,
"memrchr.sel");
1282 Str = Str.substr(0, EndOff);
1290 Type *Int8Ty =
B.getInt8Ty();
1291 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1293 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1294 Value *CEqS0 =
B.CreateICmpEQ(ConstantInt::get(Int8Ty, Str[0]), CharVal);
1295 Value *
And =
B.CreateLogicalAnd(NNeZ, CEqS0);
1296 Value *SizeM1 =
B.CreateSub(
Size, ConstantInt::get(SizeTy, 1));
1298 B.CreateInBoundsGEP(Int8Ty, SrcStr, SizeM1,
"memrchr.ptr_plus");
1299 return B.CreateSelect(
And, SrcPlus, NullPtr,
"memrchr.sel");
1322 if (LenC->
isOne()) {
1325 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memchr.char0");
1327 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1328 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memchr.char0cmp");
1329 return B.CreateSelect(Cmp, SrcStr, NullPtr,
"memchr.sel");
1349 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos),
1351 return B.CreateSelect(Cmp, NullPtr, SrcPlus);
1354 if (Str.size() == 0)
1363 size_t Pos = Str.find_first_not_of(Str[0]);
1379 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1381 Value *Sel1 = NullPtr;
1384 Value *PosVal = ConstantInt::get(SizeTy, Pos);
1385 Value *StrPos = ConstantInt::get(Int8Ty, Str[Pos]);
1386 Value *CEqSPos =
B.CreateICmpEQ(CharVal, StrPos);
1388 Value *
And =
B.CreateAnd(CEqSPos, NGtPos);
1389 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, PosVal);
1390 Sel1 =
B.CreateSelect(
And, SrcPlus, NullPtr,
"memchr.sel1");
1393 Value *Str0 = ConstantInt::get(Int8Ty, Str[0]);
1394 Value *CEqS0 =
B.CreateICmpEQ(Str0, CharVal);
1395 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1397 return B.CreateSelect(
And, SrcStr, Sel1,
"memchr.sel2");
1428 *std::max_element(
reinterpret_cast<const unsigned char *
>(Str.begin()),
1429 reinterpret_cast<const unsigned char *
>(Str.end()));
1436 if (!DL.fitsInLegalInteger(Max + 1)) {
1442 std::string SortedStr = Str.str();
1445 unsigned NonContRanges = 1;
1446 for (
size_t i = 1; i < SortedStr.size(); ++i) {
1447 if (SortedStr[i] > SortedStr[i - 1] + 1) {
1454 if (NonContRanges > 2)
1458 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1461 for (
unsigned char C : SortedStr)
1462 CharCompares.
push_back(
B.CreateICmpEQ(CharVal,
B.getInt8(
C)));
1464 return B.CreateIntToPtr(
B.CreateOr(CharCompares), CI->
getType());
1469 unsigned char Width =
NextPowerOf2(std::max((
unsigned char)7, Max));
1475 Value *BitfieldC =
B.getInt(Bitfield);
1479 C =
B.CreateAnd(
C,
B.getIntN(Width, 0xFF));
1486 Value *Shl =
B.CreateShl(
B.getIntN(Width, 1ULL),
C);
1487 Value *
Bits =
B.CreateIsNotNull(
B.CreateAnd(Shl, BitfieldC),
"memchr.bits");
1491 return B.CreateIntToPtr(
B.CreateLogicalAnd(Bounds, Bits,
"memchr"),
1516 if (Pos == MinSize ||
1517 (StrNCmp && (LStr[Pos] ==
'\0' && RStr[Pos] ==
'\0'))) {
1525 if (LStr[Pos] != RStr[Pos])
1530 typedef unsigned char UChar;
1531 int IRes = UChar(LStr[Pos]) < UChar(RStr[Pos]) ? -1 : 1;
1532 Value *MaxSize = ConstantInt::get(
Size->getType(), Pos);
1535 return B.CreateSelect(Cmp, Zero, Res);
1547 Value *LHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
LHS,
"lhsc"),
1549 Value *RHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
RHS,
"rhsc"),
1551 return B.CreateSub(LHSV, RHSV,
"chardiff");
1559 Align PrefAlignment =
DL.getPrefTypeAlign(IntType);
1562 Value *LHSV =
nullptr;
1566 Value *RHSV =
nullptr;
1575 LHSV =
B.CreateLoad(IntType,
LHS,
"lhsv");
1577 RHSV =
B.CreateLoad(IntType,
RHS,
"rhsv");
1578 return B.CreateZExt(
B.CreateICmpNE(LHSV, RHSV), CI->
getType(),
"memcmp");
1586Value *LibCallSimplifier::optimizeMemCmpBCmpCommon(
CallInst *CI,
1606 if (
Value *V = optimizeMemCmpBCmpCommon(CI,
B))
1624 return optimizeMemCmpBCmpCommon(CI,
B);
1650 if (
N->isNullValue())
1663 if (
N->getZExtValue() <= SrcStr.
size()) {
1672 ConstantInt::get(
N->getType(), std::min(uint64_t(Pos + 1),
N->getZExtValue()));
1675 return Pos + 1 <=
N->getZExtValue()
1676 ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, NewN)
1690 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
N);
1730Value *LibCallSimplifier::optimizeExistingHotColdNew(
CallInst *CI,
1738 if (!TLI->getLibFunc(*Callee, Func))
1741 case LibFunc_Znwm12__hot_cold_t:
1742 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1743 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1744 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1745 case LibFunc_Znam12__hot_cold_t:
1746 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1747 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1748 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1749 case LibFunc_size_returning_new_hot_cold:
1750 case LibFunc_size_returning_new_aligned_hot_cold:
1751 return optimizeNew(CI,
B, Func);
1767 if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"cold")
1769 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1772 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"hot")
1774 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1788 case LibFunc_Znwm12__hot_cold_t:
1791 LibFunc_Znwm12__hot_cold_t, HotCold);
1795 LibFunc_Znwm12__hot_cold_t, HotCold);
1797 case LibFunc_Znam12__hot_cold_t:
1800 LibFunc_Znam12__hot_cold_t, HotCold);
1804 LibFunc_Znam12__hot_cold_t, HotCold);
1806 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1810 LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
1812 case LibFunc_ZnwmRKSt9nothrow_t:
1814 TLI, LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,
1817 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1821 LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
1823 case LibFunc_ZnamRKSt9nothrow_t:
1825 TLI, LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,
1828 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1832 LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
1834 case LibFunc_ZnwmSt11align_val_t:
1836 TLI, LibFunc_ZnwmSt11align_val_t12__hot_cold_t,
1839 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1843 LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
1845 case LibFunc_ZnamSt11align_val_t:
1847 TLI, LibFunc_ZnamSt11align_val_t12__hot_cold_t,
1850 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1854 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1857 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1860 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
1862 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1866 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1869 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1872 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
1874 case LibFunc_size_returning_new:
1876 LibFunc_size_returning_new_hot_cold,
1879 case LibFunc_size_returning_new_hot_cold:
1882 LibFunc_size_returning_new_hot_cold,
1885 case LibFunc_size_returning_new_aligned:
1888 LibFunc_size_returning_new_aligned_hot_cold, HotCold);
1890 case LibFunc_size_returning_new_aligned_hot_cold:
1894 LibFunc_size_returning_new_aligned_hot_cold, HotCold);
1921 Value *
Op = Cast->getOperand(0);
1922 if (
Op->getType()->isFloatTy())
1931 return ConstantFP::get(Const->getContext(),
F);
1939 bool isPrecise =
false) {
1971 CallerName.
size() == (CalleeName.
size() + 1) &&
1984 R =
isBinary ?
B.CreateIntrinsic(IID,
B.getFloatTy(), V)
1985 :
B.CreateIntrinsic(IID,
B.getFloatTy(), V[0]);
1992 return B.CreateFPExt(R,
B.getDoubleTy());
1998 bool isPrecise =
false) {
2005 bool isPrecise =
false) {
2019 assert(
Op->getType()->isArrayTy() &&
"Unexpected signature for cabs!");
2021 Real =
B.CreateExtractValue(
Op, 0,
"real");
2022 Imag =
B.CreateExtractValue(
Op, 1,
"imag");
2032 Value *AbsOp =
nullptr;
2034 if (ConstReal->isZero())
2038 if (ConstImag->isZero())
2044 *CI,
B.CreateUnaryIntrinsic(Intrinsic::fabs, AbsOp, CI,
"cabs"));
2051 Value *RealReal =
B.CreateFMulFMF(Real, Real, CI);
2052 Value *ImagImag =
B.CreateFMulFMF(Imag, Imag, CI);
2054 *CI,
B.CreateUnaryIntrinsic(Intrinsic::sqrt,
2055 B.CreateFAddFMF(RealReal, ImagImag, CI), CI,
2066 unsigned BitWidth =
Op->getType()->getScalarSizeInBits();
2068 Type *IntTy =
Op->getType()->getWithNewBitWidth(DstWidth);
2070 :
B.CreateZExt(
Op, IntTy);
2106 if (CalleeFn && TLI->getLibFunc(CalleeFn->
getName(), LibFn) &&
2111 LibFunc LibFnFloat, LibFnDouble, LibFnLongDouble;
2119 ExpName = TLI->getName(LibFunc_exp);
2120 ID = Intrinsic::exp;
2121 LibFnFloat = LibFunc_expf;
2122 LibFnDouble = LibFunc_exp;
2123 LibFnLongDouble = LibFunc_expl;
2128 ExpName = TLI->getName(LibFunc_exp2);
2129 ID = Intrinsic::exp2;
2130 LibFnFloat = LibFunc_exp2f;
2131 LibFnDouble = LibFunc_exp2;
2132 LibFnLongDouble = LibFunc_exp2l;
2139 ?
B.CreateUnaryIntrinsic(
ID,
FMul,
nullptr, ExpName)
2148 substituteInParent(BaseFn, ExpFn);
2159 AttributeList NoAttrs;
2167 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2172 Constant *One = ConstantFP::get(Ty, 1.0);
2175 return copyFlags(*Pow,
B.CreateIntrinsic(Intrinsic::ldexp,
2176 {Ty, ExpoI->getType()},
2177 {One, ExpoI}, Pow,
"exp2"));
2181 One, ExpoI, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2182 LibFunc_ldexpl,
B, NoAttrs));
2187 if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f, LibFunc_exp2l)) {
2190 BaseR = BaseR / *BaseF;
2192 const APFloat *NF = IsReciprocal ? &BaseR : BaseF;
2194 if ((IsInteger || IsReciprocal) &&
2197 NI > 1 && NI.isPowerOf2()) {
2198 double N = NI.logBase2() * (IsReciprocal ? -1.0 : 1.0);
2199 Value *
FMul =
B.CreateFMul(Expo, ConstantFP::get(Ty,
N),
"mul");
2201 return copyFlags(*Pow,
B.CreateUnaryIntrinsic(Intrinsic::exp2,
FMul,
2206 LibFunc_exp2l,
B, NoAttrs));
2212 hasFloatFn(M, TLI, Ty, LibFunc_exp10, LibFunc_exp10f, LibFunc_exp10l)) {
2215 CallInst *NewExp10 =
2216 B.CreateIntrinsic(Intrinsic::exp10, {Ty}, {Expo}, Pow,
"exp10");
2221 LibFunc_exp10f, LibFunc_exp10l,
2231 "pow(1.0, y) should have been simplified earlier!");
2233 Value *Log =
nullptr;
2240 Value *
FMul =
B.CreateFMul(Log, Expo,
"mul");
2242 return copyFlags(*Pow,
B.CreateUnaryIntrinsic(Intrinsic::exp2,
FMul,
2244 else if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f,
2248 LibFunc_exp2l,
B, NoAttrs));
2260 return B.CreateUnaryIntrinsic(Intrinsic::sqrt, V,
nullptr,
"sqrt");
2263 if (
hasFloatFn(M, TLI, V->getType(), LibFunc_sqrt, LibFunc_sqrtf,
2269 LibFunc_sqrtl,
B, Attrs);
2296 Base, SimplifyQuery(DL, TLI, DT, AC, Pow,
true,
true, DC)))
2306 Sqrt =
B.CreateUnaryIntrinsic(Intrinsic::fabs, Sqrt,
nullptr,
"abs");
2315 Value *FCmp =
B.CreateFCmpOEQ(
Base, NegInf,
"isinf");
2316 Sqrt =
B.CreateSelect(FCmp, PosInf, Sqrt);
2321 Sqrt =
B.CreateFDiv(ConstantFP::get(Ty, 1.0), Sqrt,
"reciprocal");
2330 return B.CreateIntrinsic(Intrinsic::powi, Types, Args);
2344 IRBuilderBase::FastMathFlagGuard Guard(
B);
2352 if (
Value *Exp = replacePowWithExp(Pow,
B))
2359 return B.CreateFDiv(ConstantFP::get(Ty, 1.0),
Base,
"reciprocal");
2363 return ConstantFP::get(Ty, 1.0);
2371 return B.CreateFMul(
Base,
Base,
"square");
2373 if (
Value *Sqrt = replacePowWithSqrt(Pow,
B))
2384 Value *Sqrt =
nullptr;
2385 if (!ExpoA.isInteger()) {
2399 if (!ExpoI.isInteger())
2411 APSInt IntExpo(TLI->getIntSize(),
false);
2418 Base, ConstantInt::get(
B.getIntNTy(TLI->getIntSize()), IntExpo),
2422 return B.CreateFMul(PowI, Sqrt);
2436 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) &&
2437 hasFloatVersion(M, Name)) {
2450 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_exp2) &&
2451 hasFloatVersion(M, Name))
2460 const bool UseIntrinsic =
Callee->isIntrinsic();
2471 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2473 Constant *One = ConstantFP::get(Ty, 1.0);
2476 return copyFlags(*CI,
B.CreateIntrinsic(Intrinsic::ldexp,
2477 {Ty, Exp->getType()},
2481 IRBuilderBase::FastMathFlagGuard Guard(
B);
2484 One, Exp, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2485 LibFunc_ldexpl,
B, AttributeList()));
2499 if ((Name ==
"fmin" || Name ==
"fmax") && hasFloatVersion(M, Name))
2514 : Intrinsic::maxnum;
2521 StringRef LogNm = LogFn->
getName();
2526 if (UnsafeFPShrink && hasFloatVersion(
Mod, LogNm))
2530 LibFunc LogLb, ExpLb, Exp2Lb, Exp10Lb, PowLb;
2533 if (TLI->getLibFunc(LogNm, LogLb)) {
2536 LogID = Intrinsic::log;
2537 ExpLb = LibFunc_expf;
2538 Exp2Lb = LibFunc_exp2f;
2539 Exp10Lb = LibFunc_exp10f;
2540 PowLb = LibFunc_powf;
2543 LogID = Intrinsic::log;
2544 ExpLb = LibFunc_exp;
2545 Exp2Lb = LibFunc_exp2;
2546 Exp10Lb = LibFunc_exp10;
2547 PowLb = LibFunc_pow;
2550 LogID = Intrinsic::log;
2551 ExpLb = LibFunc_expl;
2552 Exp2Lb = LibFunc_exp2l;
2553 Exp10Lb = LibFunc_exp10l;
2554 PowLb = LibFunc_powl;
2557 LogID = Intrinsic::log2;
2558 ExpLb = LibFunc_expf;
2559 Exp2Lb = LibFunc_exp2f;
2560 Exp10Lb = LibFunc_exp10f;
2561 PowLb = LibFunc_powf;
2564 LogID = Intrinsic::log2;
2565 ExpLb = LibFunc_exp;
2566 Exp2Lb = LibFunc_exp2;
2567 Exp10Lb = LibFunc_exp10;
2568 PowLb = LibFunc_pow;
2571 LogID = Intrinsic::log2;
2572 ExpLb = LibFunc_expl;
2573 Exp2Lb = LibFunc_exp2l;
2574 Exp10Lb = LibFunc_exp10l;
2575 PowLb = LibFunc_powl;
2577 case LibFunc_log10f:
2578 LogID = Intrinsic::log10;
2579 ExpLb = LibFunc_expf;
2580 Exp2Lb = LibFunc_exp2f;
2581 Exp10Lb = LibFunc_exp10f;
2582 PowLb = LibFunc_powf;
2585 LogID = Intrinsic::log10;
2586 ExpLb = LibFunc_exp;
2587 Exp2Lb = LibFunc_exp2;
2588 Exp10Lb = LibFunc_exp10;
2589 PowLb = LibFunc_pow;
2591 case LibFunc_log10l:
2592 LogID = Intrinsic::log10;
2593 ExpLb = LibFunc_expl;
2594 Exp2Lb = LibFunc_exp2l;
2595 Exp10Lb = LibFunc_exp10l;
2596 PowLb = LibFunc_powl;
2604 if (!IsKnownNoErrno) {
2605 SimplifyQuery SQ(DL, TLI, DT, AC, Log,
true,
true, DC);
2615 if (IsKnownNoErrno) {
2616 auto *NewLog =
B.CreateUnaryIntrinsic(LogID, Log->
getArgOperand(0), Log);
2617 NewLog->copyMetadata(*Log);
2620 }
else if (LogID == Intrinsic::log || LogID == Intrinsic::log2 ||
2621 LogID == Intrinsic::log10) {
2623 ExpLb = LibFunc_expf;
2624 Exp2Lb = LibFunc_exp2f;
2625 Exp10Lb = LibFunc_exp10f;
2626 PowLb = LibFunc_powf;
2628 ExpLb = LibFunc_exp;
2629 Exp2Lb = LibFunc_exp2;
2630 Exp10Lb = LibFunc_exp10;
2631 PowLb = LibFunc_pow;
2642 IRBuilderBase::FastMathFlagGuard Guard(
B);
2647 TLI->getLibFunc(*Arg, ArgLb);
2650 AttributeList NoAttrs;
2651 if (ArgLb == PowLb || ArgID == Intrinsic::pow || ArgID == Intrinsic::powi) {
2654 ?
B.CreateUnaryIntrinsic(LogID, Arg->
getOperand(0),
nullptr,
"log")
2658 if (ArgID == Intrinsic::powi)
2659 Y =
B.CreateSIToFP(
Y, Ty,
"cast");
2660 Value *MulY =
B.CreateFMul(
Y, LogX,
"mul");
2663 substituteInParent(Arg, MulY);
2669 if (ArgLb == ExpLb || ArgLb == Exp2Lb || ArgLb == Exp10Lb ||
2670 ArgID == Intrinsic::exp || ArgID == Intrinsic::exp2) {
2672 if (ArgLb == ExpLb || ArgID == Intrinsic::exp)
2675 else if (ArgLb == Exp2Lb || ArgID == Intrinsic::exp2)
2676 Eul = ConstantFP::get(Log->
getType(), 2.0);
2678 Eul = ConstantFP::get(Log->
getType(), 10.0);
2680 ?
B.CreateUnaryIntrinsic(LogID, Eul,
nullptr,
"log")
2685 substituteInParent(Arg, MulY);
2703 TLI->getLibFunc(*Arg, ArgLb);
2705 LibFunc SqrtLb, ExpLb, Exp2Lb, Exp10Lb;
2707 if (TLI->getLibFunc(SqrtFn->
getName(), SqrtLb))
2710 ExpLb = LibFunc_expf;
2711 Exp2Lb = LibFunc_exp2f;
2712 Exp10Lb = LibFunc_exp10f;
2715 ExpLb = LibFunc_exp;
2716 Exp2Lb = LibFunc_exp2;
2717 Exp10Lb = LibFunc_exp10;
2720 ExpLb = LibFunc_expl;
2721 Exp2Lb = LibFunc_exp2l;
2722 Exp10Lb = LibFunc_exp10l;
2729 ExpLb = LibFunc_expf;
2730 Exp2Lb = LibFunc_exp2f;
2731 Exp10Lb = LibFunc_exp10f;
2733 ExpLb = LibFunc_exp;
2734 Exp2Lb = LibFunc_exp2;
2735 Exp10Lb = LibFunc_exp10;
2741 if (ArgLb != ExpLb && ArgLb != Exp2Lb && ArgLb != Exp10Lb &&
2742 ArgID != Intrinsic::exp && ArgID != Intrinsic::exp2)
2745 IRBuilderBase::InsertPointGuard Guard(
B);
2746 B.SetInsertPoint(Arg);
2749 B.CreateFMulFMF(ExpOperand, ConstantFP::get(ExpOperand->getType(), 0.5),
2764 (
Callee->getName() ==
"sqrt" ||
2765 Callee->getIntrinsicID() == Intrinsic::sqrt))
2768 if (
Value *Opt = mergeSqrtToExp(CI,
B))
2775 if (!
I ||
I->getOpcode() != Instruction::FMul || !
I->isFast())
2781 Value *Op0 =
I->getOperand(0);
2782 Value *Op1 =
I->getOperand(1);
2783 Value *RepeatOp =
nullptr;
2784 Value *OtherOp =
nullptr;
2816 B.CreateUnaryIntrinsic(Intrinsic::fabs, RepeatOp,
I,
"fabs");
2822 B.CreateUnaryIntrinsic(Intrinsic::sqrt, OtherOp,
I,
"sqrt");
2823 return copyFlags(*CI,
B.CreateFMulFMF(FabsCall, SqrtCall,
I));
2835 SimplifyQuery SQ(DL, TLI, DT, AC, CI,
true,
true, DC);
2838 KnownFPClass Known1 =
2841 const fltSemantics &FltSem =
2850 FRemI->setHasNoNaNs(
true);
2856Value *LibCallSimplifier::optimizeTrigInversionPairs(
CallInst *CI,
2862 if (UnsafeFPShrink &&
2863 (Name ==
"tan" || Name ==
"atanh" || Name ==
"sinh" || Name ==
"cosh" ||
2865 hasFloatVersion(M, Name))
2874 if (!CI->
isFast() || !OpC->isFast())
2884 if (
F && TLI->getLibFunc(
F->getName(), Func) &&
2886 LibFunc inverseFunc = llvm::StringSwitch<LibFunc>(
Callee->getName())
2887 .Case(
"tan", LibFunc_atan)
2888 .Case(
"atanh", LibFunc_tanh)
2889 .Case(
"sinh", LibFunc_asinh)
2890 .Case(
"cosh", LibFunc_acosh)
2891 .Case(
"tanf", LibFunc_atanf)
2892 .Case(
"atanhf", LibFunc_tanhf)
2893 .Case(
"sinhf", LibFunc_asinhf)
2894 .Case(
"coshf", LibFunc_acoshf)
2895 .Case(
"tanl", LibFunc_atanl)
2896 .Case(
"atanhl", LibFunc_tanhl)
2897 .Case(
"sinhl", LibFunc_asinhl)
2898 .Case(
"coshl", LibFunc_acoshl)
2899 .Case(
"asinh", LibFunc_sinh)
2900 .Case(
"asinhf", LibFunc_sinhf)
2901 .Case(
"asinhl", LibFunc_sinhl)
2903 if (Func == inverseFunc)
2904 Ret = OpC->getArgOperand(0);
2926 Name =
"__sincospif_stret";
2935 Name =
"__sincospi_stret";
2944 M, *TLI, TheLibFunc, OrigCallee->
getAttributes(), ResTy, ArgTy);
2949 B.SetInsertPoint(ArgInst->getParent(), ++ArgInst->getIterator());
2953 BasicBlock &EntryBB =
B.GetInsertBlock()->getParent()->getEntryBlock();
2954 B.SetInsertPoint(&EntryBB, EntryBB.
begin());
2957 SinCos =
B.CreateCall(Callee, Arg,
"sincospi");
2960 Sin =
B.CreateExtractValue(SinCos, 0,
"sinpi");
2961 Cos =
B.CreateExtractValue(SinCos, 1,
"cospi");
2963 Sin =
B.CreateExtractElement(SinCos, ConstantInt::get(
B.getInt32Ty(), 0),
2965 Cos =
B.CreateExtractElement(SinCos, ConstantInt::get(
B.getInt32Ty(), 1),
2979 Call->copyFastMathFlags(CI);
2993 Call->copyFastMathFlags(CI);
3046 for (User *U : Arg->
users())
3047 classifyArgUse(U,
F, IsFloat, SinCalls, CosCalls, SinCosCalls);
3053 Value *Sin, *Cos, *SinCos;
3058 auto replaceTrigInsts = [
this](SmallVectorImpl<CallInst *> &Calls,
3060 for (CallInst *
C : Calls)
3061 replaceAllUsesWith(
C, Res);
3064 replaceTrigInsts(SinCalls, Sin);
3065 replaceTrigInsts(CosCalls, Cos);
3066 replaceTrigInsts(SinCosCalls, SinCos);
3068 return IsSin ? Sin : Cos;
3071void LibCallSimplifier::classifyArgUse(
3087 if (!Callee || !TLI->getLibFunc(*Callee, Func) ||
3093 if (Func == LibFunc_sinpif)
3095 else if (Func == LibFunc_cospif)
3097 else if (Func == LibFunc_sincospif_stret)
3100 if (Func == LibFunc_sinpi)
3102 else if (Func == LibFunc_cospi)
3104 else if (Func == LibFunc_sincospi_stret)
3126 unsigned IntBW = TLI->getIntSize();
3127 APSInt QuotInt(IntBW,
false);
3134 B.CreateAlignedStore(
3135 ConstantInt::get(
B.getIntNTy(IntBW), QuotInt.getExtValue()),
3137 return ConstantFP::get(CI->
getType(), Rem);
3164 return ConstantFP::get(CI->
getType(), MaxVal);
3176 Type *ArgType =
Op->getType();
3177 Value *
V =
B.CreateIntrinsic(Intrinsic::cttz, {ArgType}, {
Op,
B.getTrue()},
3179 V =
B.CreateAdd(V, ConstantInt::get(
V->getType(), 1));
3180 V =
B.CreateIntCast(V, RetType,
false);
3183 return B.CreateSelect(
Cond, V, ConstantInt::get(RetType, 0));
3190 Type *ArgType =
Op->getType();
3191 Value *
V =
B.CreateIntrinsic(Intrinsic::ctlz, {ArgType}, {
Op,
B.getFalse()},
3195 return B.CreateIntCast(V, CI->
getType(),
false);
3202 Value *IsNeg =
B.CreateIsNeg(
X);
3203 Value *NegX =
B.CreateNSWNeg(
X,
"neg");
3204 return B.CreateSelect(IsNeg, NegX,
X);
3210 Type *ArgType =
Op->getType();
3211 Op =
B.CreateSub(
Op, ConstantInt::get(ArgType,
'0'),
"isdigittmp");
3212 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 10),
"isdigit");
3219 Type *ArgType =
Op->getType();
3220 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 128),
"isascii");
3227 ConstantInt::get(CI->
getType(), 0x7F));
3257 return convertStrToInt(CI, Str, EndPtr, CInt->getSExtValue(), AsSigned,
B);
3289 if (!Callee || !Callee->isDeclaration())
3298 if (StreamArg >= (
int)CI->
arg_size())
3306 return GV->
getName() ==
"stderr";
3311 StringRef FormatStr;
3316 if (FormatStr.
empty())
3327 if (FormatStr.
size() == 1 || FormatStr ==
"%%") {
3331 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)FormatStr[0]);
3332 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3336 if (FormatStr ==
"%s" && CI->
arg_size() > 1) {
3337 StringRef OperandStr;
3338 if (!getConstantStringInfo(CI->getOperand(1), OperandStr))
3341 if (OperandStr.empty())
3344 if (OperandStr.size() == 1) {
3348 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)OperandStr[0]);
3349 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3352 if (OperandStr.back() ==
'\n') {
3353 OperandStr = OperandStr.drop_back();
3354 Value *GV = B.CreateGlobalString(OperandStr,
"str");
3355 return copyFlags(*CI, emitPutS(GV, B, TLI));
3361 if (FormatStr.
back() ==
'\n' &&
3365 FormatStr = FormatStr.drop_back();
3366 Value *GV = B.CreateGlobalString(FormatStr,
"str");
3367 return copyFlags(*CI, emitPutS(GV, B, TLI));
3372 if (FormatStr ==
"%c" && CI->
arg_size() > 1 &&
3376 Value *IntChar = B.CreateIntCast(CI->getArgOperand(1), IntTy, false);
3377 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3381 if (FormatStr ==
"%s\n" && CI->
arg_size() > 1 &&
3391 FunctionType *FT =
Callee->getFunctionType();
3392 if (
Value *V = optimizePrintFString(CI,
B)) {
3403 Callee->getAttributes());
3405 New->setCalledFunction(IPrintFFn);
3415 Callee->getAttributes());
3417 New->setCalledFunction(SmallPrintFFn);
3425Value *LibCallSimplifier::optimizeSPrintFString(
CallInst *CI,
3428 StringRef FormatStr;
3444 return ConstantInt::get(CI->
getType(), FormatStr.
size());
3449 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3453 if (FormatStr[1] ==
'c') {
3459 B.CreateStore(V,
Ptr);
3460 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(),
Ptr,
B.getInt32(1),
"nul");
3461 B.CreateStore(
B.getInt8(0),
Ptr);
3463 return ConstantInt::get(CI->
getType(), 1);
3466 if (FormatStr[1] ==
's') {
3479 TLI->getAsSizeT(SrcLen, *CI->
getModule()));
3481 return ConstantInt::get(CI->
getType(), SrcLen - 1);
3484 Value *PtrDiff =
B.CreatePtrDiff(
B.getInt8Ty(), V, Dest);
3485 return B.CreateIntCast(PtrDiff, CI->
getType(),
false);
3496 B.CreateAdd(Len, ConstantInt::get(
Len->getType(), 1),
"leninc");
3500 return B.CreateIntCast(Len, CI->
getType(),
false);
3508 FunctionType *FT =
Callee->getFunctionType();
3509 if (
Value *V = optimizeSPrintFString(CI,
B)) {
3520 FT,
Callee->getAttributes());
3522 New->setCalledFunction(SIPrintFFn);
3532 Callee->getAttributes());
3534 New->setCalledFunction(SmallSPrintFFn);
3550 assert(StrArg || (
N < 2 && Str.size() == 1));
3552 unsigned IntBits = TLI->getIntSize();
3553 uint64_t IntMax =
maxIntN(IntBits);
3554 if (Str.size() > IntMax)
3560 Value *StrLen = ConstantInt::get(CI->
getType(), Str.size());
3570 NCopy = Str.size() + 1;
3575 if (NCopy && StrArg)
3578 TLI->getAsSizeT(NCopy, *CI->
getModule())));
3587 Value *NulOff =
B.getIntN(IntBits, NCopy);
3588 Value *DstEnd =
B.CreateInBoundsGEP(Int8Ty, DstArg, NulOff,
"endptr");
3589 B.CreateStore(ConstantInt::get(Int8Ty, 0), DstEnd);
3593Value *LibCallSimplifier::optimizeSnPrintFString(
CallInst *CI,
3600 uint64_t
N =
Size->getZExtValue();
3601 uint64_t IntMax =
maxIntN(TLI->getIntSize());
3611 StringRef FormatStr;
3622 return emitSnPrintfMemCpy(CI, FmtArg, FormatStr,
N,
B);
3627 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() != 4)
3631 if (FormatStr[1] ==
'c') {
3636 StringRef CharStr(
"*");
3637 return emitSnPrintfMemCpy(CI,
nullptr, CharStr,
N,
B);
3645 B.CreateStore(V,
Ptr);
3646 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(),
Ptr,
B.getInt32(1),
"nul");
3647 B.CreateStore(
B.getInt8(0),
Ptr);
3648 return ConstantInt::get(CI->
getType(), 1);
3651 if (FormatStr[1] !=
's')
3660 return emitSnPrintfMemCpy(CI, StrArg, Str,
N,
B);
3664 if (
Value *V = optimizeSnPrintFString(CI,
B)) {
3673Value *LibCallSimplifier::optimizeFPrintFString(
CallInst *CI,
3675 optimizeErrorReporting(CI,
B, 0);
3678 StringRef FormatStr;
3702 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3706 if (FormatStr[1] ==
'c') {
3710 Type *IntTy =
B.getIntNTy(TLI->getIntSize());
3716 if (FormatStr[1] ==
's') {
3729 FunctionType *FT =
Callee->getFunctionType();
3730 if (
Value *V = optimizeFPrintFString(CI,
B)) {
3739 FT,
Callee->getAttributes());
3741 New->setCalledFunction(FIPrintFFn);
3750 auto SmallFPrintFFn =
3752 Callee->getAttributes());
3754 New->setCalledFunction(SmallFPrintFFn);
3763 optimizeErrorReporting(CI,
B, 3);
3768 if (SizeC && CountC) {
3773 return ConstantInt::get(CI->
getType(), 0);
3780 Value *Cast =
B.CreateIntCast(Char, IntTy,
true,
"chari");
3782 return NewCI ? ConstantInt::get(CI->
getType(), 1) : nullptr;
3790 optimizeErrorReporting(CI,
B, 1);
3808 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
3813 ConstantInt::get(SizeTTy, Len - 1),
3853bool LibCallSimplifier::hasFloatVersion(
const Module *M,
StringRef FuncName) {
3854 SmallString<20> FloatFuncName = FuncName;
3855 FloatFuncName +=
'f';
3859Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
3871 "Optimizing string/memory libcall would change the calling convention");
3873 case LibFunc_strcat:
3874 return optimizeStrCat(CI, Builder);
3875 case LibFunc_strncat:
3876 return optimizeStrNCat(CI, Builder);
3877 case LibFunc_strchr:
3878 return optimizeStrChr(CI, Builder);
3879 case LibFunc_strrchr:
3880 return optimizeStrRChr(CI, Builder);
3881 case LibFunc_strcmp:
3882 return optimizeStrCmp(CI, Builder);
3883 case LibFunc_strncmp:
3884 return optimizeStrNCmp(CI, Builder);
3885 case LibFunc_strcpy:
3886 return optimizeStrCpy(CI, Builder);
3887 case LibFunc_stpcpy:
3888 return optimizeStpCpy(CI, Builder);
3889 case LibFunc_strlcpy:
3890 return optimizeStrLCpy(CI, Builder);
3891 case LibFunc_stpncpy:
3892 return optimizeStringNCpy(CI,
true, Builder);
3893 case LibFunc_strncpy:
3894 return optimizeStringNCpy(CI,
false, Builder);
3895 case LibFunc_strlen:
3896 return optimizeStrLen(CI, Builder);
3897 case LibFunc_strnlen:
3898 return optimizeStrNLen(CI, Builder);
3899 case LibFunc_strpbrk:
3900 return optimizeStrPBrk(CI, Builder);
3901 case LibFunc_strndup:
3902 return optimizeStrNDup(CI, Builder);
3903 case LibFunc_strtol:
3904 case LibFunc_strtod:
3905 case LibFunc_strtof:
3906 case LibFunc_strtoul:
3907 case LibFunc_strtoll:
3908 case LibFunc_strtold:
3909 case LibFunc_strtoull:
3910 return optimizeStrTo(CI, Builder);
3911 case LibFunc_strspn:
3912 return optimizeStrSpn(CI, Builder);
3913 case LibFunc_strcspn:
3914 return optimizeStrCSpn(CI, Builder);
3915 case LibFunc_strstr:
3916 return optimizeStrStr(CI, Builder);
3917 case LibFunc_memchr:
3918 return optimizeMemChr(CI, Builder);
3919 case LibFunc_memrchr:
3920 return optimizeMemRChr(CI, Builder);
3922 return optimizeBCmp(CI, Builder);
3923 case LibFunc_memcmp:
3924 return optimizeMemCmp(CI, Builder);
3925 case LibFunc_memcpy:
3926 return optimizeMemCpy(CI, Builder);
3927 case LibFunc_memccpy:
3928 return optimizeMemCCpy(CI, Builder);
3929 case LibFunc_mempcpy:
3930 return optimizeMemPCpy(CI, Builder);
3931 case LibFunc_memmove:
3932 return optimizeMemMove(CI, Builder);
3933 case LibFunc_memset:
3934 return optimizeMemSet(CI, Builder);
3935 case LibFunc_realloc:
3936 return optimizeRealloc(CI, Builder);
3937 case LibFunc_wcslen:
3938 return optimizeWcslen(CI, Builder);
3940 return optimizeBCopy(CI, Builder);
3942 case LibFunc_ZnwmRKSt9nothrow_t:
3943 case LibFunc_ZnwmSt11align_val_t:
3944 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
3946 case LibFunc_ZnamRKSt9nothrow_t:
3947 case LibFunc_ZnamSt11align_val_t:
3948 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
3949 case LibFunc_Znwm12__hot_cold_t:
3950 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
3951 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
3952 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
3953 case LibFunc_Znam12__hot_cold_t:
3954 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
3955 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
3956 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
3957 case LibFunc_size_returning_new:
3958 case LibFunc_size_returning_new_hot_cold:
3959 case LibFunc_size_returning_new_aligned:
3960 case LibFunc_size_returning_new_aligned_hot_cold:
3961 return optimizeNew(CI, Builder, Func);
3977 if (CharSeq.
empty())
3978 Fill =
APInt(32, 0);
3985Value *LibCallSimplifier::optimizeFloatingPointLibCall(
CallInst *CI,
3994 if (
Value *V = optimizeSymmetric(CI, Func, Builder))
3998 case LibFunc_sinpif:
4000 return optimizeSinCosPi(CI,
true, Builder);
4001 case LibFunc_cospif:
4003 return optimizeSinCosPi(CI,
false, Builder);
4007 return optimizePow(CI, Builder);
4011 return optimizeExp2(CI, Builder);
4019 return optimizeSqrt(CI, Builder);
4023 return optimizeFMod(CI, Builder);
4027 case LibFunc_log10f:
4029 case LibFunc_log10l:
4030 case LibFunc_log1pf:
4032 case LibFunc_log1pl:
4039 return optimizeLog(CI, Builder);
4047 case LibFunc_asinhf:
4048 case LibFunc_asinhl:
4053 case LibFunc_atanhf:
4054 case LibFunc_atanhl:
4055 return optimizeTrigInversionPairs(CI, Builder);
4062 case LibFunc_roundeven:
4064 case LibFunc_nearbyint:
4084 case LibFunc_copysign:
4091 return optimizeFdim(CI, Builder);
4098 return optimizeFMinFMax(CI, Builder);
4102 return optimizeCAbs(CI, Builder);
4103 case LibFunc_remquo:
4104 case LibFunc_remquof:
4105 case LibFunc_remquol:
4106 return optimizeRemquo(CI, Builder);
4126 return optimizeExistingHotColdNew(CI, Builder);
4137 Builder.setDefaultOperandBundles(OpBundles);
4145 UnsafeFPShrink =
true;
4149 if (!IsCallingConvC)
4153 switch (
II->getIntrinsicID()) {
4154 case Intrinsic::pow:
4155 return optimizePow(CI, Builder);
4156 case Intrinsic::exp2:
4157 return optimizeExp2(CI, Builder);
4158 case Intrinsic::log:
4159 case Intrinsic::log2:
4160 case Intrinsic::log10:
4161 return optimizeLog(CI, Builder);
4162 case Intrinsic::sqrt:
4163 return optimizeSqrt(CI, Builder);
4164 case Intrinsic::memset:
4165 return optimizeMemSet(CI, Builder);
4166 case Intrinsic::memcpy:
4167 return optimizeMemCpy(CI, Builder);
4168 case Intrinsic::memmove:
4169 return optimizeMemMove(CI, Builder);
4170 case Intrinsic::sin:
4171 case Intrinsic::cos:
4181 if (
Value *SimplifiedFortifiedCI =
4182 FortifiedSimplifier.optimizeCall(CI, Builder))
4183 return SimplifiedFortifiedCI;
4190 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
4192 if (
Value *V = optimizeFloatingPointLibCall(CI, Func, Builder))
4198 return optimizeFFS(CI, Builder);
4202 return optimizeFls(CI, Builder);
4206 return optimizeAbs(CI, Builder);
4207 case LibFunc_isdigit:
4208 return optimizeIsDigit(CI, Builder);
4209 case LibFunc_isascii:
4210 return optimizeIsAscii(CI, Builder);
4211 case LibFunc_toascii:
4212 return optimizeToAscii(CI, Builder);
4216 return optimizeAtoi(CI, Builder);
4217 case LibFunc_strtol:
4218 case LibFunc_strtoll:
4219 return optimizeStrToInt(CI, Builder,
true);
4220 case LibFunc_strtoul:
4221 case LibFunc_strtoull:
4222 return optimizeStrToInt(CI, Builder,
false);
4223 case LibFunc_printf:
4224 return optimizePrintF(CI, Builder);
4225 case LibFunc_sprintf:
4226 return optimizeSPrintF(CI, Builder);
4227 case LibFunc_snprintf:
4228 return optimizeSnPrintF(CI, Builder);
4229 case LibFunc_fprintf:
4230 return optimizeFPrintF(CI, Builder);
4231 case LibFunc_fwrite:
4232 return optimizeFWrite(CI, Builder);
4234 return optimizeFPuts(CI, Builder);
4236 return optimizePuts(CI, Builder);
4237 case LibFunc_perror:
4238 return optimizeErrorReporting(CI, Builder);
4239 case LibFunc_vfprintf:
4240 case LibFunc_fiprintf:
4241 return optimizeErrorReporting(CI, Builder, 0);
4244 return optimizeExit(CI);
4258 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), DT(DT), DC(DC), AC(AC),
4259 ORE(ORE), BFI(BFI), PSI(PSI), Replacer(Replacer), Eraser(Eraser) {}
4266void LibCallSimplifier::eraseFromParent(
Instruction *
I) {
4305bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
4306 CallInst *CI,
unsigned ObjSizeOp, std::optional<unsigned> SizeOp,
4307 std::optional<unsigned> StrOp, std::optional<unsigned> FlagOp) {
4312 if (!Flag || !
Flag->isZero())
4319 if (ConstantInt *ObjSizeCI =
4321 if (ObjSizeCI->isMinusOne())
4324 if (OnlyLowerUnknownSize)
4334 return ObjSizeCI->getZExtValue() >=
Len;
4338 if (ConstantInt *SizeCI =
4340 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
4346Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
4348 if (isFortifiedCallFoldable(CI, 3, 2)) {
4358Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
4360 if (isFortifiedCallFoldable(CI, 3, 2)) {
4370Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
4372 if (isFortifiedCallFoldable(CI, 3, 2)) {
4382Value *FortifiedLibCallSimplifier::optimizeMemPCpyChk(
CallInst *CI,
4385 if (isFortifiedCallFoldable(CI, 3, 2))
4393Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
4401 if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
4403 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
4411 if (isFortifiedCallFoldable(CI, 2, std::nullopt, 1)) {
4412 if (Func == LibFunc_strcpy_chk)
4418 if (OnlyLowerUnknownSize)
4428 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
4430 Value *LenV = ConstantInt::get(SizeTTy, Len);
4434 if (Ret && Func == LibFunc_stpcpy_chk)
4435 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
4436 ConstantInt::get(SizeTTy, Len - 1));
4440Value *FortifiedLibCallSimplifier::optimizeStrLenChk(
CallInst *CI,
4442 if (isFortifiedCallFoldable(CI, 1, std::nullopt, 0))
4448Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
4451 if (isFortifiedCallFoldable(CI, 3, 2)) {
4452 if (Func == LibFunc_strncpy_chk)
4465Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(
CallInst *CI,
4467 if (isFortifiedCallFoldable(CI, 4, 3))
4475Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(
CallInst *CI,
4477 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2)) {
4487Value *FortifiedLibCallSimplifier::optimizeSPrintfChk(
CallInst *CI,
4489 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1)) {
4493 VariadicArgs,
B, TLI));
4499Value *FortifiedLibCallSimplifier::optimizeStrCatChk(
CallInst *CI,
4501 if (isFortifiedCallFoldable(CI, 2))
4508Value *FortifiedLibCallSimplifier::optimizeStrLCat(
CallInst *CI,
4510 if (isFortifiedCallFoldable(CI, 3))
4518Value *FortifiedLibCallSimplifier::optimizeStrNCatChk(
CallInst *CI,
4520 if (isFortifiedCallFoldable(CI, 3))
4528Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(
CallInst *CI,
4530 if (isFortifiedCallFoldable(CI, 3))
4538Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(
CallInst *CI,
4540 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2))
4548Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(
CallInst *CI,
4550 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1))
4581 Builder.setDefaultOperandBundles(OpBundles);
4585 if (!TLI->getLibFunc(*Callee, Func))
4593 case LibFunc_memcpy_chk:
4594 return optimizeMemCpyChk(CI, Builder);
4595 case LibFunc_mempcpy_chk:
4596 return optimizeMemPCpyChk(CI, Builder);
4597 case LibFunc_memmove_chk:
4598 return optimizeMemMoveChk(CI, Builder);
4599 case LibFunc_memset_chk:
4600 return optimizeMemSetChk(CI, Builder);
4601 case LibFunc_stpcpy_chk:
4602 case LibFunc_strcpy_chk:
4603 return optimizeStrpCpyChk(CI, Builder, Func);
4604 case LibFunc_strlen_chk:
4605 return optimizeStrLenChk(CI, Builder);
4606 case LibFunc_stpncpy_chk:
4607 case LibFunc_strncpy_chk:
4608 return optimizeStrpNCpyChk(CI, Builder, Func);
4609 case LibFunc_memccpy_chk:
4610 return optimizeMemCCpyChk(CI, Builder);
4611 case LibFunc_snprintf_chk:
4612 return optimizeSNPrintfChk(CI, Builder);
4613 case LibFunc_sprintf_chk:
4614 return optimizeSPrintfChk(CI, Builder);
4615 case LibFunc_strcat_chk:
4616 return optimizeStrCatChk(CI, Builder);
4617 case LibFunc_strlcat_chk:
4618 return optimizeStrLCat(CI, Builder);
4619 case LibFunc_strncat_chk:
4620 return optimizeStrNCatChk(CI, Builder);
4621 case LibFunc_strlcpy_chk:
4622 return optimizeStrLCpyChk(CI, Builder);
4623 case LibFunc_vsnprintf_chk:
4624 return optimizeVSNPrintfChk(CI, Builder);
4625 case LibFunc_vsprintf_chk:
4626 return optimizeVSPrintfChk(CI, Builder);
4635 : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
static llvm::Error parse(DataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
Machine Check Debug Module
uint64_t IntrinsicInst * II
static bool isBinary(MachineInstr &MI)
const SmallVectorImpl< MachineOperand > & Cond
static bool isOnlyUsedInEqualityComparison(Value *V, Value *With)
Return true if it is only used in equality comparisons with With.
static void annotateNonNullAndDereferenceable(CallInst *CI, ArrayRef< unsigned > ArgNos, Value *Size, const DataLayout &DL)
static cl::opt< unsigned, false, HotColdHintParser > ColdNewHintValue("cold-new-hint-value", cl::Hidden, cl::init(1), cl::desc("Value to pass to hot/cold operator new for cold allocation"))
static bool insertSinCosCall(IRBuilderBase &B, Function *OrigCallee, Value *Arg, bool UseFloat, Value *&Sin, Value *&Cos, Value *&SinCos, const TargetLibraryInfo *TLI)
static bool canTransformToMemCmp(CallInst *CI, Value *Str, uint64_t Len, const DataLayout &DL)
static Value * mergeAttributesAndFlags(CallInst *NewCI, const CallInst &Old)
static cl::opt< bool > OptimizeHotColdNew("optimize-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable hot/cold operator new library calls"))
static Value * optimizeBinaryDoubleFP(CallInst *CI, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool isPrecise=false)
Shrink double -> float for binary functions.
static bool ignoreCallingConv(LibFunc Func)
static cl::opt< bool > OptimizeExistingHotColdNew("optimize-existing-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable optimization of existing hot/cold operator new library calls"))
static void annotateDereferenceableBytes(CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t DereferenceableBytes)
static bool isReportingError(Function *Callee, CallInst *CI, int StreamArg)
static Value * optimizeDoubleFP(CallInst *CI, IRBuilderBase &B, bool isBinary, const TargetLibraryInfo *TLI, bool isPrecise=false)
Shrink double -> float functions.
static Value * optimizeSymmetricCall(CallInst *CI, bool IsEven, IRBuilderBase &B)
static Value * getSqrtCall(Value *V, AttributeList Attrs, bool NoErrno, Module *M, IRBuilderBase &B, const TargetLibraryInfo *TLI)
static Value * valueHasFloatPrecision(Value *Val)
Return a variant of Val with float type.
static Value * optimizeMemCmpConstantSize(CallInst *CI, Value *LHS, Value *RHS, uint64_t Len, IRBuilderBase &B, const DataLayout &DL)
static Value * createPowWithIntegerExponent(Value *Base, Value *Expo, Module *M, IRBuilderBase &B)
static Value * convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, uint64_t Base, bool AsSigned, IRBuilderBase &B)
static Value * memChrToCharCompare(CallInst *CI, Value *NBytes, IRBuilderBase &B, const DataLayout &DL)
static Value * copyFlags(const CallInst &Old, Value *New)
static StringRef substr(StringRef Str, uint64_t Len)
static cl::opt< unsigned, false, HotColdHintParser > HotNewHintValue("hot-new-hint-value", cl::Hidden, cl::init(254), cl::desc("Value to pass to hot/cold operator new for hot allocation"))
static bool isTrigLibCall(CallInst *CI)
static Value * optimizeNaN(CallInst *CI)
Constant folding nan/nanf/nanl.
static bool isOnlyUsedInComparisonWithZero(Value *V)
static Value * replaceUnaryCall(CallInst *CI, IRBuilderBase &B, Intrinsic::ID IID)
static bool callHasFloatingPointArgument(const CallInst *CI)
static Value * optimizeUnaryDoubleFP(CallInst *CI, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool isPrecise=false)
Shrink double -> float for unary functions.
static bool callHasFP128Argument(const CallInst *CI)
static cl::opt< unsigned, false, HotColdHintParser > AmbiguousNewHintValue("ambiguous-new-hint-value", cl::Hidden, cl::init(222), cl::desc("Value to pass to hot/cold operator new for ambiguous allocation"))
static void annotateNonNullNoUndefBasedOnAccess(CallInst *CI, ArrayRef< unsigned > ArgNos)
static Value * optimizeMemCmpVarSize(CallInst *CI, Value *LHS, Value *RHS, Value *Size, bool StrNCmp, IRBuilderBase &B, const DataLayout &DL)
static Value * getIntToFPVal(Value *I2F, IRBuilderBase &B, unsigned DstWidth)
static cl::opt< bool > EnableUnsafeFPShrink("enable-double-float-shrink", cl::Hidden, cl::init(false), cl::desc("Enable unsafe double to float " "shrinking for math lib calls"))
static cl::opt< unsigned, false, HotColdHintParser > NotColdNewHintValue("notcold-new-hint-value", cl::Hidden, cl::init(128), cl::desc("Value to pass to hot/cold operator new for " "notcold (warm) allocation"))
This file defines the SmallString class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static SymbolRef::Type getType(const Symbol *Sym)
opStatus divide(const APFloat &RHS, roundingMode RM)
bool isFiniteNonZero() const
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
opStatus subtract(const APFloat &RHS, roundingMode RM)
LLVM_ABI double convertToDouble() const
Converts this APFloat to host double value.
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
opStatus add(const APFloat &RHS, roundingMode RM)
const fltSemantics & getSemantics() const
LLVM_ABI float convertToFloat() const
Converts this APFloat to host float value.
opStatus remainder(const APFloat &RHS)
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A cache of @llvm.assume calls within a function.
static LLVM_ABI Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
void removeParamAttrs(unsigned ArgNo, const AttributeMask &AttrsToRemove)
Removes the attributes from the given argument.
LLVM_ABI void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool doesNotAccessMemory(unsigned OpNo) const
void removeRetAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the return value.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
bool isStrictFP() const
Determine if the call requires strict floating point semantics.
AttributeSet getParamAttributes(unsigned ArgNo) const
Return the param attributes for this call.
uint64_t getParamDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
AttributeSet getRetAttributes() const
Return the return attributes for this call.
void setAttributes(AttributeList A)
Set the attributes for this call.
bool doesNotThrow() const
Determine if the call cannot unwind.
Value * getArgOperand(unsigned i) const
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a parameter (0=unknown).
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
TailCallKind getTailCallKind() const
bool isMustTailCall() const
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
@ ICMP_UGT
unsigned greater than
@ ICMP_ULT
unsigned less than
@ ICMP_ULE
unsigned less or equal
Predicate getPredicate() const
Return the predicate for this instruction.
LLVM_ABI uint64_t getElementAsInteger(uint64_t i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
ConstantFP - Floating Point Values [float, double].
static LLVM_ABI Constant * getInfinity(Type *Ty, bool Negative=false)
static LLVM_ABI Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
This is an important base class in LLVM.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
This class represents an extension of floating point types.
This class represents a truncation of floating point types.
void setNoSignedZeros(bool B=true)
static FastMathFlags getFast()
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
FortifiedLibCallSimplifier(const TargetLibraryInfo *TLI, bool OnlyLowerUnknownSize=false)
Value * optimizeCall(CallInst *CI, IRBuilderBase &B)
Take the given call instruction and return a more optimal value to replace the instruction with or 0 ...
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
AttributeList getAttributes() const
Return the attribute list for this Function.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Module * getParent()
Get the module that this global value is contained inside of...
This instruction compares its operands according to the predicate given to the constructor.
Common base class shared among various IRBuilders.
LLVM_ABI Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
LLVM_ABI bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
LLVM_ABI bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
LLVM_ABI bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI bool isFast() const LLVM_READONLY
Determine whether all fast-math-flags are set.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
LLVM_ABI bool hasApproxFunc() const LLVM_READONLY
Determine whether the approximate-math-functions flag is set.
LLVM_ABI bool hasAllowReassoc() const LLVM_READONLY
Determine whether the allow-reassociation flag is set.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
LibCallSimplifier(const DataLayout &DL, const TargetLibraryInfo *TLI, DominatorTree *DT, DomConditionCache *DC, AssumptionCache *AC, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, function_ref< void(Instruction *, Value *)> Replacer=&replaceAllUsesWithDefault, function_ref< void(Instruction *)> Eraser=&eraseFromParentDefault)
Value * optimizeCall(CallInst *CI, IRBuilderBase &B)
optimizeCall - Take the given call instruction and return a more optimal value to replace the instruc...
An instruction for reading from memory.
Value * getPointerOperand()
A Module instance is used to store all the information related to an LLVM module.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Analysis providing profile information.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
char back() const
back - Get the last character in the string.
constexpr size_t size() const
size - Get the string size.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
static constexpr size_t npos
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static LLVM_ABI bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
Provides information about what library functions are available for the current target.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isStructTy() const
True if this is an instance of StructType.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
LLVM_ABI const fltSemantics & getFltSemantics() const
A Use represents the edge between a Value definition and its users.
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
iterator_range< user_iterator > users()
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
deferredval_ty< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
This namespace contains all of the command line option processing machinery.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionAddr VTableAddr Value
LLVM_ABI Value * emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth=0)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
LLVM_ABI Value * emitStrChr(Value *Ptr, char C, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
constexpr uint64_t maxUIntN(uint64_t N)
Gets the maximum value for a N-bit unsigned integer.
LLVM_ABI Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
LLVM_ABI Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
LLVM_ABI Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI bool isKnownNeverInfinity(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the floating-point scalar value is not an infinity or if the floating-point vector val...
LLVM_ABI bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
LLVM_ABI bool getConstantStringInfo(const Value *V, StringRef &Str, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
LLVM_ABI bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, Align Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested.
LLVM_ABI Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value * > VariadicArgs, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
LLVM_ABI bool getConstantDataArrayInfo(const Value *V, ConstantDataArraySlice &Slice, unsigned ElementSize, uint64_t Offset=0)
Returns true if the value V is a pointer into a ConstantDataArray.
LLVM_ABI Value * emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memrchr function, analogously to emitMemChr.
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2019 maximum semantics.
LLVM_ABI Value * emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcat function.
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI bool hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
LLVM_ABI Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
LLVM_ABI bool isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI, LibFunc TheLibFunc)
Check whether the library function is available on target and also that it in the current Module is a...
LLVM_ABI Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
auto dyn_cast_or_null(const Y &Val)
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
LLVM_ABI Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
LLVM_ABI Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
bool isAlpha(char C)
Checks if character C is a valid letter as classified by "C" locale.
LLVM_ABI Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
LLVM_ABI Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
LLVM_ABI uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'.
LLVM_ABI FunctionCallee getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI, LibFunc TheLibFunc, FunctionType *T, AttributeList AttributeList)
Calls getOrInsertFunction() and then makes sure to add mandatory argument attributes.
LLVM_ABI Value * emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
LLVM_ABI Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
LLVM_ABI Value * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
LLVM_ABI Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
LLVM_ABI Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value * > Args, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
@ Mod
The access may modify the value stored in memory.
LLVM_ABI Value * emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
@ And
Bitwise or logical AND of integers.
char toUpper(char x)
Returns the corresponding uppercase character if x is lowercase.
DWARFExpression::Operation Op
@ NearestTiesToEven
roundTiesToEven.
constexpr int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Value * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
LLVM_ABI Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
LLVM_ABI Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
LLVM_ABI Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_ABI Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
LLVM_ABI Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
LLVM_ABI Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
LLVM_ABI Value * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
LLVM_ABI Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
static LLVM_ABI const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
static constexpr roundingMode rmTowardZero
opStatus
IEEE-754R 7: Default exception handling.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t Length
Length of the slice.
uint64_t Offset
Slice starts at this Offset.
const ConstantDataArray * Array
ConstantDataArray pointer.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
bool isKnownNeverInfinity() const
Return true if it's known this can never be an infinity.
static constexpr FPClassTest OrderedLessThanZeroMask
LLVM_ABI bool isKnownNeverLogicalZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a zero.
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...