48 cl::desc(
"Enable unsafe double to float " 49 "shrinking for math lib calls"));
56 return Func == LibFunc_abs || Func == LibFunc_labs ||
57 Func == LibFunc_llabs || Func == LibFunc_strlen;
77 if (!FuncTy->getReturnType()->isPointerTy() &&
78 !FuncTy->getReturnType()->isIntegerTy() &&
79 !FuncTy->getReturnType()->isVoidTy())
82 for (
auto Param : FuncTy->params()) {
83 if (!Param->isPointerTy() && !Param->isIntegerTy())
95 if (
ICmpInst *IC = dyn_cast<ICmpInst>(U))
96 if (IC->isEquality() && IC->getOperand(1) == With)
106 return OI->getType()->isFloatingPointTy();
112 return OI->getType()->isFP128Ty();
123 std::string nptr = Str.
str();
125 long long int Result = strtoll(nptr.c_str(), &End, Base);
152 if (!TLI->
getLibFunc(*InnerCallee, Func) || !TLI->
has(Func) ||
153 Func != LibFunc_fopen)
165 if (
ICmpInst *IC = dyn_cast<ICmpInst>(U))
166 if (
Constant *
C = dyn_cast<Constant>(IC->getOperand(1)))
167 if (
C->isNullValue())
192 uint64_t DereferenceableBytes) {
196 for (
unsigned ArgNo : ArgNos) {
197 uint64_t DerefBytes = DereferenceableBytes;
203 DereferenceableBytes);
223 for (
unsigned ArgNo : ArgNos) {
237 if (
ConstantInt *LenC = dyn_cast<ConstantInt>(Size)) {
243 uint64_t DerefMin = 1;
273 return emitStrLenMemCpy(Src, Dst, Len, B);
276 Value *LibCallSimplifier::emitStrLenMemCpy(
Value *Src,
Value *Dst, uint64_t Len,
337 return emitStrLenMemCpy(Src, Dst, SrcLen, B);
423 if (HasStr1 && HasStr2)
426 if (HasStr1 && Str1.empty())
430 if (HasStr2 && Str2.empty())
445 std::min(Len1, Len2)),
450 if (!HasStr1 && HasStr2) {
456 }
else if (HasStr1 && !HasStr2) {
479 if (
ConstantInt *LengthArg = dyn_cast<ConstantInt>(Size))
480 Length = LengthArg->getZExtValue();
488 return emitMemCmp(Str1P, Str2P, Size, B, DL, TLI);
495 if (HasStr1 && HasStr2) {
501 if (HasStr1 && Str1.
empty())
505 if (HasStr2 && Str2.
empty())
517 if (!HasStr1 && HasStr2) {
518 Len2 = std::min(Len2, Length);
524 }
else if (HasStr1 && !HasStr2) {
525 Len1 = std::min(Len1, Length);
540 if (SrcLen && Size) {
542 if (SrcLen <= Size->getZExtValue() + 1)
609 if (
ConstantInt *LengthArg = dyn_cast<ConstantInt>(Size))
610 Len = LengthArg->getZExtValue();
637 if (Len > SrcLen + 1)
670 uint64_t NullTermIdx;
671 if (Slice.
Array ==
nullptr) {
674 NullTermIdx = ~((uint64_t)0);
675 for (uint64_t
I = 0,
E = Slice.
Length;
I <
E; ++
I) {
683 if (NullTermIdx == ~((uint64_t)0))
691 cast<ArrayType>(
GEP->getSourceElementType())->getNumElements();
704 (
GEP->isInBounds() && isa<GlobalVariable>(
GEP->getOperand(0)) &&
705 NullTermIdx == ArrSize - 1)) {
719 if (LenTrue && LenFalse) {
722 <<
"folded strlen(select) to select of constants";
740 if (
Value *V = optimizeStringLength(CI, B, 8))
748 unsigned WCharSize = TLI->getWCharSize(M) * 8;
753 return optimizeStringLength(CI, B, WCharSize);
763 if ((HasS1 && S1.
empty()) || (HasS2 && S2.
empty()))
767 if (HasS1 && HasS2) {
777 if (HasS2 && S2.
size() == 1)
785 if (isa<ConstantPointerNull>(EndPtr)) {
801 if ((HasS1 && S1.
empty()) || (HasS2 && S2.
empty()))
805 if (HasS1 && HasS2) {
821 if (HasS1 && S1.
empty())
825 if (HasS1 && HasS2) {
833 if (HasS2 && S2.
empty())
854 ICmpInst *Old = cast<ICmpInst>(*UI++);
858 replaceAllUsesWith(Old, Cmp);
869 if (HasStr2 && ToFindStr.
empty())
873 if (HasStr1 && HasStr2) {
887 if (HasStr2 && ToFindStr.
size() == 1) {
889 return StrChr ? B.CreateBitCast(StrChr, CI->
getType()) :
nullptr;
925 Str = Str.
substr(0, LenC->getZExtValue());
939 *std::max_element(reinterpret_cast<const unsigned char *>(Str.
begin()),
940 reinterpret_cast<const unsigned char *>(Str.
end()));
947 if (!DL.fitsInLegalInteger(Max + 1))
955 APInt Bitfield(Width, 0);
957 Bitfield.
setBit((
unsigned char)
C);
1004 return B.
CreateSub(LHSV, RHSV,
"chardiff");
1015 Value *LHSV =
nullptr;
1016 if (
auto *LHSC = dyn_cast<Constant>(LHS)) {
1020 Value *RHSV =
nullptr;
1021 if (
auto *RHSC = dyn_cast<Constant>(RHS)) {
1050 if (Len > LHSStr.
size() || Len > RHSStr.
size())
1067 Value *LibCallSimplifier::optimizeMemCmpBCmpCommon(
CallInst *CI,
1082 if (LenC->getZExtValue() == 0)
1092 if (
Value *V = optimizeMemCmpBCmpCommon(CI, B))
1102 return emitBCmp(LHS, RHS, Size, B, DL, TLI);
1109 return optimizeMemCmpBCmpCommon(CI, B);
1115 if (isa<IntrinsicInst>(CI))
1135 if (N->isNullValue())
1146 size_t Pos = SrcStr.find(StopChar->
getSExtValue() & 0xFF);
1148 if (N->getZExtValue() <= SrcStr.size()) {
1157 ConstantInt::get(N->getType(), std::min(uint64_t(Pos + 1), N->getZExtValue()));
1160 return Pos + 1 <= N->getZExtValue()
1178 if (isa<IntrinsicInst>(CI))
1192 if (!FillValue || FillValue->getZExtValue() != 0)
1200 if (!Malloc || !Malloc->hasOneUse())
1204 Function *InnerCallee = Malloc->getCalledFunction();
1209 if (!TLI->getLibFunc(*InnerCallee, Func) || !TLI->has(Func) ||
1210 Func != LibFunc_malloc)
1220 const DataLayout &DL = Malloc->getModule()->getDataLayout();
1223 Malloc->getArgOperand(0),
1224 Malloc->getAttributes(),
B, *TLI)) {
1225 substituteInParent(Malloc, Calloc);
1235 if (isa<IntrinsicInst>(CI))
1238 if (
auto *Calloc = foldMallocMemset(CI, B))
1280 if (
FPExtInst *Cast = dyn_cast<FPExtInst>(Val)) {
1281 Value *
Op = Cast->getOperand(0);
1285 if (
ConstantFP *Const = dyn_cast<ConstantFP>(Val)) {
1298 bool isBinary,
bool isPrecise =
false) {
1317 if (!V[0] || (isBinary && !V[1]))
1329 if (!CallerName.
empty() && CallerName.
back() ==
'f' &&
1330 CallerName.
size() == (CalleeName.
size() + 1) &&
1356 bool isPrecise =
false) {
1362 bool isPrecise =
false) {
1397 if (!isa<FPMathOperator>(Call))
1434 assert(Exp != 0 &&
"Incorrect exponent 0 not handled");
1436 if (InnerChain[Exp])
1437 return InnerChain[Exp];
1439 static const unsigned AddChain[33][2] = {
1443 {1, 2}, {2, 2}, {2, 3}, {3, 3}, {2, 5}, {4, 4},
1444 {1, 8}, {5, 5}, {1, 10}, {6, 6}, {4, 9}, {7, 7},
1445 {3, 12}, {8, 8}, {8, 9}, {2, 16}, {1, 18}, {10, 10},
1446 {6, 15}, {11, 11}, {3, 20}, {12, 12}, {8, 17}, {13, 13},
1447 {3, 24}, {14, 14}, {4, 25}, {15, 15}, {3, 28}, {16, 16},
1451 getPow(InnerChain, AddChain[Exp][1], B));
1452 return InnerChain[Exp];
1457 if (isa<SIToFPInst>(I2F) || isa<UIToFPInst>(I2F)) {
1458 Value *
Op = cast<Instruction>(I2F)->getOperand(0);
1462 if (BitWidth < 32 ||
1463 (BitWidth == 32 && isa<SIToFPInst>(I2F)))
1502 TLI->getLibFunc(CalleeFn->
getName(), LibFn) && TLI->has(LibFn)) {
1506 LibFunc LibFnFloat, LibFnDouble, LibFnLongDouble;
1511 case LibFunc_expf:
case LibFunc_exp:
case LibFunc_expl:
1512 ExpName = TLI->getName(LibFunc_exp);
1513 ID = Intrinsic::exp;
1514 LibFnFloat = LibFunc_expf;
1515 LibFnDouble = LibFunc_exp;
1516 LibFnLongDouble = LibFunc_expl;
1518 case LibFunc_exp2f:
case LibFunc_exp2:
case LibFunc_exp2l:
1519 ExpName = TLI->getName(LibFunc_exp2);
1520 ID = Intrinsic::exp2;
1521 LibFnFloat = LibFunc_exp2f;
1522 LibFnDouble = LibFunc_exp2;
1523 LibFnLongDouble = LibFunc_exp2l;
1540 substituteInParent(BaseFn, ExpFn);
1553 (isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo)) &&
1554 hasFloatFn(TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) {
1557 LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl,
1562 if (
hasFloatFn(TLI, Ty, LibFunc_exp2, LibFunc_exp2f, LibFunc_exp2l)) {
1565 BaseR = BaseR / *BaseF;
1567 const APFloat *NF = IsReciprocal ? &BaseR : BaseF;
1569 if ((IsInteger || IsReciprocal) &&
1573 double N = NI.
logBase2() * (IsReciprocal ? -1.0 : 1.0);
1580 LibFunc_exp2l, B, Attrs);
1587 hasFloatFn(TLI, Ty, LibFunc_exp10, LibFunc_exp10f, LibFunc_exp10l))
1589 LibFunc_exp10l, B, Attrs);
1594 Value *Log =
nullptr;
1605 else if (
hasFloatFn(TLI, Ty, LibFunc_exp2, LibFunc_exp2f, LibFunc_exp2l))
1607 LibFunc_exp2l, B, Attrs);
1630 LibFunc_sqrtl, B, Attrs);
1659 Sqrt = B.CreateCall(FAbsFn, Sqrt,
"abs");
1667 Value *FCmp = B.CreateFCmpOEQ(Base, NegInf,
"isinf");
1668 Sqrt = B.CreateSelect(FCmp, PosInf, Sqrt);
1692 Value *Shrunk =
nullptr;
1697 if (!
hasFloatFn(TLI, Ty, LibFunc_pow, LibFunc_powf, LibFunc_powl))
1706 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) &&
1707 hasFloatVersion(Name))
1716 if (
Value *Exp = replacePowWithExp(Pow, B))
1737 if (
Value *Sqrt = replacePowWithSqrt(Pow, B))
1754 Value *Sqrt =
nullptr;
1755 if (!ExpoA.isInteger()) {
1771 Value *InnerChain[33] = {
nullptr};
1772 InnerChain[1] = Base;
1773 InnerChain[2] = B.
CreateFMul(Base, Base,
"square");
1778 Value *FMul =
getPow(InnerChain, ExpoA.convertToDouble(),
B);
1791 APSInt IntExpo(32,
false);
1802 if (AllowApprox && (isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo))) {
1814 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_exp2) &&
1815 hasFloatVersion(Name))
1823 if ((isa<SIToFPInst>(Op) || isa<UIToFPInst>(Op)) &&
1824 hasFloatFn(TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) {
1827 LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl,
1839 if ((Name ==
"fmin" || Name ==
"fmax") && hasFloatVersion(Name))
1870 if (UnsafeFPShrink && hasFloatVersion(LogNm))
1878 LibFunc LogLb, ExpLb, Exp2Lb, Exp10Lb, PowLb;
1881 if (TLI->getLibFunc(LogNm, LogLb))
1884 LogID = Intrinsic::log;
1885 ExpLb = LibFunc_expf;
1886 Exp2Lb = LibFunc_exp2f;
1887 Exp10Lb = LibFunc_exp10f;
1888 PowLb = LibFunc_powf;
1891 LogID = Intrinsic::log;
1892 ExpLb = LibFunc_exp;
1893 Exp2Lb = LibFunc_exp2;
1894 Exp10Lb = LibFunc_exp10;
1895 PowLb = LibFunc_pow;
1898 LogID = Intrinsic::log;
1899 ExpLb = LibFunc_expl;
1900 Exp2Lb = LibFunc_exp2l;
1901 Exp10Lb = LibFunc_exp10l;
1902 PowLb = LibFunc_powl;
1906 ExpLb = LibFunc_expf;
1907 Exp2Lb = LibFunc_exp2f;
1908 Exp10Lb = LibFunc_exp10f;
1909 PowLb = LibFunc_powf;
1913 ExpLb = LibFunc_exp;
1914 Exp2Lb = LibFunc_exp2;
1915 Exp10Lb = LibFunc_exp10;
1916 PowLb = LibFunc_pow;
1920 ExpLb = LibFunc_expl;
1921 Exp2Lb = LibFunc_exp2l;
1922 Exp10Lb = LibFunc_exp10l;
1923 PowLb = LibFunc_powl;
1925 case LibFunc_log10f:
1926 LogID = Intrinsic::log10;
1927 ExpLb = LibFunc_expf;
1928 Exp2Lb = LibFunc_exp2f;
1929 Exp10Lb = LibFunc_exp10f;
1930 PowLb = LibFunc_powf;
1933 LogID = Intrinsic::log10;
1934 ExpLb = LibFunc_exp;
1935 Exp2Lb = LibFunc_exp2;
1936 Exp10Lb = LibFunc_exp10;
1937 PowLb = LibFunc_pow;
1939 case LibFunc_log10l:
1940 LogID = Intrinsic::log10;
1941 ExpLb = LibFunc_expl;
1942 Exp2Lb = LibFunc_exp2l;
1943 Exp10Lb = LibFunc_exp10l;
1944 PowLb = LibFunc_powl;
1950 LogID == Intrinsic::log10) {
1952 ExpLb = LibFunc_expf;
1953 Exp2Lb = LibFunc_exp2f;
1954 Exp10Lb = LibFunc_exp10f;
1955 PowLb = LibFunc_powf;
1957 ExpLb = LibFunc_exp;
1958 Exp2Lb = LibFunc_exp2;
1959 Exp10Lb = LibFunc_exp10;
1960 PowLb = LibFunc_pow;
1971 TLI->getLibFunc(Arg, ArgLb);
1974 if (ArgLb == PowLb || ArgID == Intrinsic::pow) {
1983 substituteInParent(Arg, MulY);
1989 if (ArgLb == ExpLb || ArgLb == Exp2Lb || ArgLb == Exp10Lb ||
1990 ArgID == Intrinsic::exp || ArgID == Intrinsic::exp2) {
1992 if (ArgLb == ExpLb || ArgID == Intrinsic::exp)
1995 else if (ArgLb == Exp2Lb || ArgID == Intrinsic::exp2)
2006 substituteInParent(Arg, MulY);
2019 if (TLI->has(LibFunc_sqrtf) && (Callee->
getName() ==
"sqrt" ||
2035 Value *RepeatOp =
nullptr;
2036 Value *OtherOp =
nullptr;
2046 Value *OtherMul0, *OtherMul1;
2049 if (OtherMul0 == OtherMul1 && cast<Instruction>(Op0)->isFast()) {
2051 RepeatOp = OtherMul0;
2086 if (UnsafeFPShrink && Name ==
"tan" && hasFloatVersion(Name))
2095 if (!CI->
isFast() || !OpC->isFast())
2103 if (F && TLI->getLibFunc(F->
getName(), Func) && TLI->has(Func) &&
2104 ((Func == LibFunc_atan && Callee->
getName() ==
"tan") ||
2105 (Func == LibFunc_atanf && Callee->
getName() ==
"tanf") ||
2106 (Func == LibFunc_atanl && Callee->
getName() ==
"tanl")))
2107 Ret = OpC->getArgOperand(0);
2115 return CI->
hasFnAttr(Attribute::NoUnwind) &&
2128 Name =
"__sincospif_stret";
2137 Name =
"__sincospi_stret";
2145 if (
Instruction *ArgInst = dyn_cast<Instruction>(Arg)) {
2148 B.
SetInsertPoint(ArgInst->getParent(), ++ArgInst->getIterator());
2156 SinCos = B.
CreateCall(Callee, Arg,
"sincospi");
2187 classifyArgUse(U, F, IsFloat, SinCalls, CosCalls, SinCosCalls);
2193 Value *Sin, *Cos, *SinCos;
2199 replaceAllUsesWith(
C, Res);
2202 replaceTrigInsts(SinCalls, Sin);
2203 replaceTrigInsts(CosCalls, Cos);
2204 replaceTrigInsts(SinCosCalls, SinCos);
2209 void LibCallSimplifier::classifyArgUse(
2225 if (!Callee || !TLI->getLibFunc(*Callee, Func) || !TLI->has(Func) ||
2230 if (Func == LibFunc_sinpif)
2232 else if (Func == LibFunc_cospif)
2234 else if (Func == LibFunc_sincospif_stret)
2237 if (Func == LibFunc_sinpi)
2239 else if (Func == LibFunc_cospi)
2241 else if (Func == LibFunc_sincospi_stret)
2255 Intrinsic::cttz, ArgType);
2269 Intrinsic::ctlz, ArgType);
2372 return GV->
getName() ==
"stderr";
2382 if (FormatStr.
empty())
2392 if (FormatStr.
size() == 1 || FormatStr ==
"%%")
2400 if (ChrStr.
size() != 1)
2406 if (FormatStr[FormatStr.
size() - 1] ==
'\n' &&
2432 if (
Value *V = optimizePrintFString(CI, B)) {
2452 auto SmallPrintFFn =
2483 FormatStr.
size() + 1));
2489 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' ||
2494 if (FormatStr[1] ==
'c') {
2507 if (FormatStr[1] ==
's') {
2530 if (
Value *V = optimizeSPrintFString(CI, B)) {
2550 auto SmallSPrintFFn =
2584 else if (N < FormatStr.
size() + 1)
2593 FormatStr.
size() + 1));
2599 if (FormatStr.
size() == 2 && FormatStr[0] ==
'%' &&
2603 if (FormatStr[1] ==
'c') {
2621 if (FormatStr[1] ==
's') {
2629 else if (N < Str.
size() + 1)
2644 if (
Value *V = optimizeSnPrintFString(CI, B)) {
2654 optimizeErrorReporting(CI, B, 0);
2681 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' ||
2686 if (FormatStr[1] ==
'c') {
2693 if (FormatStr[1] ==
's') {
2705 if (
Value *V = optimizeFPrintFString(CI, B)) {
2725 auto SmallFPrintFFn =
2738 optimizeErrorReporting(CI, B, 3);
2743 if (SizeC && CountC) {
2744 uint64_t Bytes = SizeC->
getZExtValue() * CountC->getZExtValue();
2769 optimizeErrorReporting(CI, B, 1);
2802 optimizeErrorReporting(CI, B, 1);
2856 bool LibCallSimplifier::hasFloatVersion(
StringRef FuncName) {
2859 FloatFuncName +=
'f';
2860 if (TLI->getLibFunc(FloatFuncName, Func))
2861 return TLI->has(Func);
2865 Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
2870 if (TLI->getLibFunc(*Callee, Func) && TLI->has(Func)) {
2874 "Optimizing string/memory libcall would change the calling convention");
2876 case LibFunc_strcat:
2877 return optimizeStrCat(CI, Builder);
2878 case LibFunc_strncat:
2879 return optimizeStrNCat(CI, Builder);
2880 case LibFunc_strchr:
2881 return optimizeStrChr(CI, Builder);
2882 case LibFunc_strrchr:
2883 return optimizeStrRChr(CI, Builder);
2884 case LibFunc_strcmp:
2885 return optimizeStrCmp(CI, Builder);
2886 case LibFunc_strncmp:
2887 return optimizeStrNCmp(CI, Builder);
2888 case LibFunc_strcpy:
2889 return optimizeStrCpy(CI, Builder);
2890 case LibFunc_stpcpy:
2891 return optimizeStpCpy(CI, Builder);
2892 case LibFunc_strncpy:
2893 return optimizeStrNCpy(CI, Builder);
2894 case LibFunc_strlen:
2895 return optimizeStrLen(CI, Builder);
2896 case LibFunc_strpbrk:
2897 return optimizeStrPBrk(CI, Builder);
2898 case LibFunc_strndup:
2899 return optimizeStrNDup(CI, Builder);
2900 case LibFunc_strtol:
2901 case LibFunc_strtod:
2902 case LibFunc_strtof:
2903 case LibFunc_strtoul:
2904 case LibFunc_strtoll:
2905 case LibFunc_strtold:
2906 case LibFunc_strtoull:
2907 return optimizeStrTo(CI, Builder);
2908 case LibFunc_strspn:
2909 return optimizeStrSpn(CI, Builder);
2910 case LibFunc_strcspn:
2911 return optimizeStrCSpn(CI, Builder);
2912 case LibFunc_strstr:
2913 return optimizeStrStr(CI, Builder);
2914 case LibFunc_memchr:
2915 return optimizeMemChr(CI, Builder);
2916 case LibFunc_memrchr:
2917 return optimizeMemRChr(CI, Builder);
2919 return optimizeBCmp(CI, Builder);
2920 case LibFunc_memcmp:
2921 return optimizeMemCmp(CI, Builder);
2922 case LibFunc_memcpy:
2923 return optimizeMemCpy(CI, Builder);
2924 case LibFunc_memccpy:
2925 return optimizeMemCCpy(CI, Builder);
2926 case LibFunc_mempcpy:
2927 return optimizeMemPCpy(CI, Builder);
2928 case LibFunc_memmove:
2929 return optimizeMemMove(CI, Builder);
2930 case LibFunc_memset:
2931 return optimizeMemSet(CI, Builder);
2932 case LibFunc_realloc:
2933 return optimizeRealloc(CI, Builder);
2934 case LibFunc_wcslen:
2935 return optimizeWcslen(CI, Builder);
2937 return optimizeBCopy(CI, Builder);
2945 Value *LibCallSimplifier::optimizeFloatingPointLibCall(
CallInst *CI,
2956 case LibFunc_sinpif:
2958 case LibFunc_cospif:
2960 return optimizeSinCosPi(CI, Builder);
2964 return optimizePow(CI, Builder);
2968 return optimizeExp2(CI, Builder);
2976 return optimizeSqrt(CI, Builder);
2980 case LibFunc_log10f:
2982 case LibFunc_log10l:
2983 case LibFunc_log1pf:
2985 case LibFunc_log1pl:
2992 return optimizeLog(CI, Builder);
2996 return optimizeTan(CI, Builder);
3003 case LibFunc_nearbyint:
3027 case LibFunc_copysign:
3037 return optimizeFMinFMax(CI, Builder);
3041 return optimizeCAbs(CI, Builder);
3067 else if (isa<FPMathOperator>(CI) && CI->
isFast())
3068 UnsafeFPShrink =
true;
3072 if (!isCallingConvC)
3076 switch (II->getIntrinsicID()) {
3077 case Intrinsic::pow:
3078 return optimizePow(CI, Builder);
3079 case Intrinsic::exp2:
3080 return optimizeExp2(CI, Builder);
3081 case Intrinsic::log:
3083 case Intrinsic::log10:
3084 return optimizeLog(CI, Builder);
3085 case Intrinsic::sqrt:
3086 return optimizeSqrt(CI, Builder);
3088 case Intrinsic::memset:
3089 return optimizeMemSet(CI, Builder);
3090 case Intrinsic::memcpy:
3091 return optimizeMemCpy(CI, Builder);
3092 case Intrinsic::memmove:
3093 return optimizeMemMove(CI, Builder);
3100 if (
Value *SimplifiedFortifiedCI = FortifiedSimplifier.optimizeCall(CI)) {
3107 if (
Value *V = optimizeStringMemoryLibCall(SimplifiedCI, TmpBuilder)) {
3109 substituteInParent(SimplifiedCI, V);
3113 return SimplifiedFortifiedCI;
3117 if (TLI->getLibFunc(*Callee, Func) && TLI->has(Func)) {
3121 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
3123 if (
Value *V = optimizeFloatingPointLibCall(CI, Func, Builder))
3129 return optimizeFFS(CI, Builder);
3133 return optimizeFls(CI, Builder);
3137 return optimizeAbs(CI, Builder);
3138 case LibFunc_isdigit:
3139 return optimizeIsDigit(CI, Builder);
3140 case LibFunc_isascii:
3141 return optimizeIsAscii(CI, Builder);
3142 case LibFunc_toascii:
3143 return optimizeToAscii(CI, Builder);
3147 return optimizeAtoi(CI, Builder);
3148 case LibFunc_strtol:
3149 case LibFunc_strtoll:
3150 return optimizeStrtol(CI, Builder);
3151 case LibFunc_printf:
3152 return optimizePrintF(CI, Builder);
3153 case LibFunc_sprintf:
3154 return optimizeSPrintF(CI, Builder);
3155 case LibFunc_snprintf:
3156 return optimizeSnPrintF(CI, Builder);
3157 case LibFunc_fprintf:
3158 return optimizeFPrintF(CI, Builder);
3159 case LibFunc_fwrite:
3160 return optimizeFWrite(CI, Builder);
3162 return optimizeFRead(CI, Builder);
3164 return optimizeFPuts(CI, Builder);
3166 return optimizeFGets(CI, Builder);
3168 return optimizeFPutc(CI, Builder);
3170 return optimizeFGetc(CI, Builder);
3172 return optimizePuts(CI, Builder);
3173 case LibFunc_perror:
3174 return optimizeErrorReporting(CI, Builder);
3175 case LibFunc_vfprintf:
3176 case LibFunc_fiprintf:
3177 return optimizeErrorReporting(CI, Builder, 0);
3191 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), ORE(ORE), BFI(BFI), PSI(PSI),
3192 UnsafeFPShrink(
false), Replacer(Replacer), Eraser(Eraser) {}
3199 void LibCallSimplifier::eraseFromParent(
Instruction *I) {
3239 FortifiedLibCallSimplifier::isFortifiedCallFoldable(
CallInst *CI,
3248 if (!Flag || !Flag->
isZero())
3257 if (ObjSizeCI->isMinusOne())
3260 if (OnlyLowerUnknownSize)
3270 return ObjSizeCI->getZExtValue() >= Len;
3276 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
3282 Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
3284 if (isFortifiedCallFoldable(CI, 3, 2)) {
3294 Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
3296 if (isFortifiedCallFoldable(CI, 3, 2)) {
3306 Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
3310 if (isFortifiedCallFoldable(CI, 3, 2)) {
3320 Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
3328 if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
3338 if (isFortifiedCallFoldable(CI, 2,
None, 1)) {
3339 if (Func == LibFunc_strcpy_chk)
3345 if (OnlyLowerUnknownSize)
3360 if (Ret && Func == LibFunc_stpcpy_chk)
3365 Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
3368 if (isFortifiedCallFoldable(CI, 3, 2)) {
3369 if (Func == LibFunc_strncpy_chk)
3380 Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(
CallInst *CI,
3382 if (isFortifiedCallFoldable(CI, 4, 3))
3389 Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(
CallInst *CI,
3391 if (isFortifiedCallFoldable(CI, 3, 1,
None, 2)) {
3400 Value *FortifiedLibCallSimplifier::optimizeSPrintfChk(
CallInst *CI,
3402 if (isFortifiedCallFoldable(CI, 2,
None,
None, 1)) {
3411 Value *FortifiedLibCallSimplifier::optimizeStrCatChk(
CallInst *CI,
3413 if (isFortifiedCallFoldable(CI, 2))
3419 Value *FortifiedLibCallSimplifier::optimizeStrLCat(
CallInst *CI,
3421 if (isFortifiedCallFoldable(CI, 3))
3428 Value *FortifiedLibCallSimplifier::optimizeStrNCatChk(
CallInst *CI,
3430 if (isFortifiedCallFoldable(CI, 3))
3437 Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(
CallInst *CI,
3439 if (isFortifiedCallFoldable(CI, 3))
3446 Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(
CallInst *CI,
3448 if (isFortifiedCallFoldable(CI, 3, 1,
None, 2))
3455 Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(
CallInst *CI,
3457 if (isFortifiedCallFoldable(CI, 2,
None,
None, 1))
3496 case LibFunc_memcpy_chk:
3497 return optimizeMemCpyChk(CI, Builder);
3498 case LibFunc_memmove_chk:
3499 return optimizeMemMoveChk(CI, Builder);
3500 case LibFunc_memset_chk:
3501 return optimizeMemSetChk(CI, Builder);
3502 case LibFunc_stpcpy_chk:
3503 case LibFunc_strcpy_chk:
3504 return optimizeStrpCpyChk(CI, Builder, Func);
3505 case LibFunc_stpncpy_chk:
3506 case LibFunc_strncpy_chk:
3507 return optimizeStrpNCpyChk(CI, Builder, Func);
3508 case LibFunc_memccpy_chk:
3509 return optimizeMemCCpyChk(CI, Builder);
3510 case LibFunc_snprintf_chk:
3511 return optimizeSNPrintfChk(CI, Builder);
3512 case LibFunc_sprintf_chk:
3513 return optimizeSPrintfChk(CI, Builder);
3514 case LibFunc_strcat_chk:
3515 return optimizeStrCatChk(CI, Builder);
3516 case LibFunc_strlcat_chk:
3517 return optimizeStrLCat(CI, Builder);
3518 case LibFunc_strncat_chk:
3519 return optimizeStrNCatChk(CI, Builder);
3520 case LibFunc_strlcpy_chk:
3521 return optimizeStrLCpyChk(CI, Builder);
3522 case LibFunc_vsnprintf_chk:
3523 return optimizeVSNPrintfChk(CI, Builder);
3524 case LibFunc_vsprintf_chk:
3525 return optimizeVSPrintfChk(CI, Builder);
3534 : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
Value * CreateNSWNeg(Value *V, const Twine &Name="")
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
bool hasNoInfs() const
Determine whether the no-infs flag is set.
Value * emitStpCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
A parsed version of the target data layout string in and methods for querying it. ...
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool hasNoSignedZeros() const
Determine whether the no-signed-zeros flag is set.
void flipAllBits()
Toggle every bit to its opposite value.
uint64_t getZExtValue() const
Get zero extended value.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
bool doesNotAccessMemory(unsigned OpNo) const
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
This class represents lattice values for constants.
static bool callHasFloatingPointArgument(const CallInst *CI)
Type * getParamType(unsigned i) const
Parameter type accessors.
Value * emitStrDup(Value *Ptr, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * optimizeCall(CallInst *CI)
Take the given call instruction and return a more optimal value to replace the instruction with or 0 ...
A Module instance is used to store all the information related to an LLVM module. ...
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
static Constant * getInfinity(Type *Ty, bool Negative=false)
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Function * getCaller()
Helper to get the caller (the parent function).
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
void push_back(const T &Elt)
Analysis providing profile information.
LLVM_NODISCARD int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
This class represents a function call, abstracting a target machine's calling convention.
static uint64_t round(uint64_t Acc, uint64_t Input)
Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value *> Args, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
An efficient, type-erasing, non-owning reference to a callable.
float convertToFloat() const
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, MaybeAlign Alignment, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
LLVMContext & getContext() const
All values hold a context through their type.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
C - The default llvm calling convention, compatible with C.
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
const fltSemantics & getSemantics() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
static bool isTrigLibCall(CallInst *CI)
bool isGEPBasedOnPointerToString(const GEPOperator *GEP, unsigned CharSize=8)
Returns true if the GEP is based on a pointer to a string (array of.
Value * emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs_unlocked function.
uint64_t Offset
Slice starts at this Offset.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
LLVMContext & getContext() const
Get the context in which this basic block lives.
Value * emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
static bool isReportingError(Function *Callee, CallInst *CI, int StreamArg)
static void annotateDereferenceableBytes(CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t DereferenceableBytes)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
iterator begin()
Instruction iterator methods.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
static Value * replaceUnaryCall(CallInst *CI, IRBuilder<> &B, Intrinsic::ID IID)
Value * getArgOperand(unsigned i) const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
static void annotateNonNullBasedOnAccess(CallInst *CI, ArrayRef< unsigned > ArgNos)
static FastMathFlags getFast()
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
void setBit(unsigned BitPosition)
Set a given bit to 1.
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
FortifiedLibCallSimplifier(const TargetLibraryInfo *TLI, bool OnlyLowerUnknownSize=false)
A Use represents the edge between a Value definition and its users.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Value * emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an integer.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool hasApproxFunc() const
Determine whether the approximate-math-functions flag is set.
Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
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"))
Value * emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc_unlocked function.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
static Value * convertStrToNumber(CallInst *CI, StringRef &Str, int64_t Base)
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
Class to represent function types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Type * getType() const
All values are typed, get the type of this value.
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
const ConstantDataArray * Array
ConstantDataArray pointer.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LibCallSimplifier(const DataLayout &DL, const TargetLibraryInfo *TLI, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, function_ref< void(Instruction *, Value *)> Replacer=&replaceAllUsesWithDefault, function_ref< void(Instruction *)> Eraser=&eraseFromParentDefault)
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
BasicBlock * GetInsertBlock() const
Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
bool has(LibFunc F) const
Tests whether a library function is available.
Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
LLVM_NODISCARD size_t size() const
size - Get the string size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
AttributeList getAttributes() const
Return the attribute list for this Function.
static const fltSemantics & IEEEdouble() LLVM_READNONE
static Value * valueHasFloatPrecision(Value *Val)
Return a variant of Val with float type.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
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'...
void takeName(Value *V)
Transfer the name from V to this value.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static Value * getIntToFPVal(Value *I2F, IRBuilder<> &B)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Value * getOperand(unsigned i) const
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static bool isOnlyUsedInComparisonWithZero(Value *V)
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.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
const BasicBlock & getEntryBlock() const
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
OneUse_match< T > m_OneUse(const T &SubPattern)
initializer< Ty > init(const Ty &Val)
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
static bool isLocallyOpenedFile(Value *File, CallInst *CI, IRBuilder<> &B, const TargetLibraryInfo *TLI)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
void setNoSignedZeros(bool B=true)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
Value * CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
ConstantInt * getTrue()
Get the constant value for i1 true.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Instrumentation for Order File
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
bool isPointerTy() const
True if this is an instance of PointerType.
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
FunctionType * getFunctionType() const
ConstantFP - Floating Point Values [float, double].
double convertToDouble() const
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
LLVM_NODISCARD AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
bool isFast() const
Determine whether all fast-math-flags are set.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This instruction compares its operands according to the predicate given to the constructor.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Value * getPointerOperand()
static bool isCallingConvCCompatible(CallInst *CI)
Class to represent integer types.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
static Value * createPowWithIntegerExponent(Value *Base, Value *Expo, Module *M, IRBuilder<> &B)
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
Represents offset+length into a ConstantDataArray.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
const Function * getFunction() const
Return the function this instruction belongs to.
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
static double log2(double V)
static Value * optimizeMemCmpConstantSize(CallInst *CI, Value *LHS, Value *RHS, uint64_t Len, IRBuilder<> &B, const DataLayout &DL)
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
Value * emitStrChr(Value *Ptr, char C, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
LLVM_NODISCARD char back() const
back - Get the last character in the string.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
static bool isBinary(MachineInstr &MI)
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Triple - Helper class for working with autoconf configuration names.
Value * emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite_unlocked function.
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
Value * emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
static const fltSemantics & IEEEsingle() LLVM_READNONE
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
static Value * optimizeDoubleFP(CallInst *CI, IRBuilder<> &B, bool isBinary, bool isPrecise=false)
Shrink double -> float functions.
Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length...
Value * emitFGetCUnlocked(Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgetc_unlocked function. File is a pointer to FILE.
This is the shared class of boolean and integer constants.
Align max(MaybeAlign Lhs, Align Rhs)
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0)
Make a new global variable with initializer type i8*.
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
Value * emitStrCat(Value *Dest, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Module.h This file contains the declarations for the Module class.
uint64_t Length
Length of the slice.
Provides information about what library functions are available for the current target.
bool isLegalInteger(uint64_t Width) const
Returns true if the specified type is known to be a native integer type supported by the CPU...
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
AttributeList getAttributes() const
Return the parameter attributes for this call.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
unsigned logBase2() const
The access may modify the value stored in memory.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
amdgpu Simplify well known AMD library false FunctionCallee Callee
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
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< user_iterator > users()
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
ConstantInt * getFalse()
Get the constant value for i1 false.
Value * emitFGetSUnlocked(Value *Str, Value *Size, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgets_unlocked function.
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
CallInst * CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
opStatus add(const APFloat &RHS, roundingMode RM)
Predicate getPredicate() const
Return the predicate for this instruction.
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
unsigned getNumArgOperands() const
Merge contiguous icmps into a memcmp
unsigned getIntegerBitWidth() const
LLVM_NODISCARD bool empty() const
static Value * optimizeUnaryDoubleFP(CallInst *CI, IRBuilder<> &B, bool isPrecise=false)
Shrink double -> float for unary functions.
Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
CallingConv::ID getCallingConv() const
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
StringRef getName() const
Return a constant reference to the value's name.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
static Value * optimizeBinaryDoubleFP(CallInst *CI, IRBuilder<> &B, bool isPrecise=false)
Shrink double -> float for binary functions.
Value * optimizeCall(CallInst *CI)
optimizeCall - Take the given call instruction and return a more optimal value to replace the instruc...
Value * emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcat function.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
unsigned 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.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static void insertSinCosCall(IRBuilder<> &B, Function *OrigCallee, Value *Arg, bool UseFloat, Value *&Sin, Value *&Cos, Value *&SinCos)
Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value *> VariadicArgs, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
bool isStrictFP() const
Determine if the call requires strict floating point semantics.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static bool isOnlyUsedInEqualityComparison(Value *V, Value *With)
Return true if it is only used in equality comparisons with With.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
This class represents a truncation of floating point types.
Value * emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fread_unlocked function.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Value * emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_NODISCARD StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Value * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length...
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
static bool canTransformToMemCmp(CallInst *CI, Value *Str, uint64_t Len, const DataLayout &DL)
Value * emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, IRBuilder<> &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
static bool callHasFP128Argument(const CallInst *CI)
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
static Value * optimizeTrigReflections(CallInst *Call, LibFunc Func, IRBuilder<> &B)
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
bool hasOneUse() const
Return true if there is exactly one user of this value.
static Value * getSqrtCall(Value *V, AttributeList Attrs, bool NoErrno, Module *M, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
static void annotateNonNullAndDereferenceable(CallInst *CI, ArrayRef< unsigned > ArgNos, Value *Size, const DataLayout &DL)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
static bool ignoreCallingConv(LibFunc Func)
This class represents an extension of floating point types.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
bool hasFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
static Value * getPow(Value *InnerChain[33], unsigned Exp, IRBuilder<> &B)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
bool isStructTy() const
True if this is an instance of StructType.
bool isArrayTy() const
True if this is an instance of ArrayType.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, MaybeAlign Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...