50#define DEBUG_TYPE "simplify-lib-calls"
55 cl::desc(
"Enable unsafe double to float "
56 "shrinking for math lib calls"));
63 cl::desc(
"Enable hot/cold operator new library calls"));
72 "Enable optimization of existing hot/cold operator new library calls"),
76 "Do not optimize existing hot/cold operator new library calls"),
78 "Only optimize existing hot/cold operator new library calls "
79 "if determined to be cold"),
82 "Always optimize existing hot/cold operator new library calls"),
85 "Always optimize existing hot/cold operator new library calls")),
89 cl::desc(
"Enable transformation of nobuiltin operator new library calls"));
92 cl::desc(
"Take the minimum of compiler hint and existing hint when "
93 "optimizing existing hot/cold operator new library calls"));
104struct HotColdHintParser :
public cl::parser<unsigned> {
105 HotColdHintParser(cl::Option &O) : cl::parser<unsigned>(
O) {}
107 bool parse(cl::Option &O, StringRef ArgName, StringRef Arg,
unsigned &
Value) {
109 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
112 return O.error(
"'" + Arg +
"' value must be in the range [0, 255]!");
126 cl::desc(
"Value to pass to hot/cold operator new for cold allocation"));
129 cl::desc(
"Value to pass to hot/cold operator new for "
130 "notcold (warm) allocation"));
133 cl::desc(
"Value to pass to hot/cold operator new for hot allocation"));
137 "Value to pass to hot/cold operator new for ambiguous allocation"));
144 return Func == LibFunc_abs || Func == LibFunc_labs ||
145 Func == LibFunc_llabs || Func == LibFunc_strlen;
150 for (
User *U :
V->users()) {
152 if (IC->isEquality() && IC->getOperand(1) == With)
162 return OI->getType()->isFloatingPointTy();
168 return OI->getType()->isFP128Ty();
201 bool Negate = Str[0] ==
'-';
202 if (Str[0] ==
'-' || Str[0] ==
'+') {
203 Str = Str.drop_front();
214 uint64_t Max = AsSigned && Negate ? 1 : 0;
218 if (Str.size() > 1) {
220 if (
toUpper((
unsigned char)Str[1]) ==
'X') {
221 if (Str.size() == 2 || (
Base &&
Base != 16))
226 Str = Str.drop_front(2);
232 }
else if (
Base == 0)
242 for (
unsigned i = 0; i != Str.size(); ++i) {
243 unsigned char DigVal = Str[i];
245 DigVal = DigVal -
'0';
249 DigVal = DigVal -
'A' + 10;
262 if (VFlow || Result > Max)
270 Value *StrEnd =
B.CreateInBoundsGEP(
B.getInt8Ty(), StrBeg,
Off,
"endptr");
271 B.CreateStore(StrEnd, EndPtr);
282 return ConstantInt::get(RetTy, Result, AsSigned);
286 for (
User *U :
V->users()) {
289 if (
C->isNullValue())
317 for (
unsigned ArgNo : ArgNos) {
318 uint64_t DerefBytes = DereferenceableBytes;
323 DereferenceableBytes);
343 for (
unsigned ArgNo : ArgNos) {
369 DerefMin = std::min(
X,
Y);
390 NewCI->
getContext(), {NewCI->getAttributes(), Old.getAttributes()}));
407 return Len >= Str.size() ? Str : Str.substr(0, Len);
432 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, Len,
B));
446 Value *CpyDst =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, DstLen,
"endptr");
451 TLI->getAsSizeT(Len + 1, *
B.getModule()));
495 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, SrcLen,
B));
508 Type *CharTy =
B.getInt8Ty();
509 Value *Char0 =
B.CreateLoad(CharTy, Src);
510 CharVal =
B.CreateTrunc(CharVal, CharTy);
511 Value *Cmp =
B.CreateICmpEQ(Char0, CharVal,
"char0cmp");
516 Cmp =
B.CreateLogicalAnd(
And, Cmp);
524 return B.CreateSelect(Cmp, Src, NullPtr);
546 FunctionType *FT =
Callee->getFunctionType();
547 unsigned IntBits = TLI->getIntSize();
548 if (!FT->getParamType(1)->isIntegerTy(IntBits))
551 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
555 ConstantInt::get(SizeTTy, Len),
B,
564 return B.CreateIntToPtr(
B.getTrue(), CI->
getType());
573 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, StrLen,
"strchr");
586 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(
I),
"strchr");
598 if (CharC && CharC->
isZero())
603 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
609 Value *
Size = ConstantInt::get(SizeTTy, NBytes);
616 return ConstantInt::get(CI->
getType(), 0);
618 StringRef Str1, Str2;
623 if (HasStr1 && HasStr2)
625 std::clamp(Str1.
compare(Str2), -1, 1));
627 if (HasStr1 && Str1.
empty())
628 return B.CreateNeg(
B.CreateZExt(
629 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
631 if (HasStr2 && Str2.
empty())
632 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
646 TLI->getAsSizeT(std::min(Len1, Len2), *CI->
getModule()),
651 SimplifyQuery SQ(DL, TLI, DT, AC, CI);
652 if (!HasStr1 && HasStr2) {
657 }
else if (HasStr1 && !HasStr2) {
679 return ConstantInt::get(CI->
getType(), 0);
691 return ConstantInt::get(CI->
getType(), 0);
696 StringRef Str1, Str2;
701 if (HasStr1 && HasStr2) {
706 std::clamp(SubStr1.
compare(SubStr2), -1, 1));
709 if (HasStr1 && Str1.
empty())
710 return B.CreateNeg(
B.CreateZExt(
711 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
713 if (HasStr2 && Str2.
empty())
714 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
725 if (!HasStr1 && HasStr2) {
726 Len2 = std::min(Len2,
Length);
731 }
else if (HasStr1 && !HasStr2) {
732 Len1 = std::min(Len1,
Length);
746 if (SrcLen &&
Size) {
748 if (SrcLen <= Size->getZExtValue() + 1)
770 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
785 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
796 Value *DstEnd =
B.CreateInBoundsGEP(
797 B.getInt8Ty(), Dst, TLI->getAsSizeT(Len - 1, *CI->
getModule()));
801 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1), LenV);
820 NBytes = SizeC->getZExtValue();
829 B.CreateStore(
B.getInt8(0), Dst);
845 bool NulTerm = SrcLen < NBytes;
854 SrcLen = std::min(SrcLen,
uint64_t(Str.size()));
855 NBytes = std::min(NBytes - 1, SrcLen);
860 B.CreateStore(
B.getInt8(0), Dst);
861 return ConstantInt::get(CI->
getType(), 0);
867 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
868 TLI->getAsSizeT(NBytes, *CI->
getModule()));
872 Value *EndOff = ConstantInt::get(CI->
getType(), NBytes);
873 Value *EndPtr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, EndOff);
874 B.CreateStore(
B.getInt8(0), EndPtr);
880 return ConstantInt::get(CI->
getType(), SrcLen);
885Value *LibCallSimplifier::optimizeStringNCpy(
CallInst *CI,
bool RetEnd,
902 N = SizeC->getZExtValue();
909 Type *CharTy =
B.getInt8Ty();
910 Value *CharVal =
B.CreateLoad(CharTy, Src,
"stxncpy.char0");
911 B.CreateStore(CharVal, Dst);
917 Value *ZeroChar = ConstantInt::get(CharTy, 0);
918 Value *
Cmp =
B.CreateICmpEQ(CharVal, ZeroChar,
"stpncpy.char0cmp");
920 Value *Off1 =
B.getInt32(1);
921 Value *EndPtr =
B.CreateInBoundsGEP(CharTy, Dst, Off1,
"stpncpy.end");
922 return B.CreateSelect(Cmp, Dst, EndPtr,
"stpncpy.sel");
937 CI->
getAttributes().getParamAttrs(0).getAlignment().valueOrOne();
938 CallInst *NewCI =
B.CreateMemSet(Dst,
B.getInt8(
'\0'),
Size, MemSetAlign);
946 if (
N > SrcLen + 1) {
955 std::string SrcStr = Str.str();
958 SrcStr.resize(
N,
'\0');
959 Src =
B.CreateGlobalString(SrcStr,
"str", 0,
965 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
974 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
Off,
"endptr");
991 return B.CreateZExt(
B.CreateLoad(CharTy, Src,
"char0"),
997 if (BoundCst->isZero())
999 return ConstantInt::get(CI->
getType(), 0);
1001 if (BoundCst->isOne()) {
1003 Value *CharVal =
B.CreateLoad(CharTy, Src,
"strnlen.char0");
1004 Value *ZeroChar = ConstantInt::get(CharTy, 0);
1005 Value *
Cmp =
B.CreateICmpNE(CharVal, ZeroChar,
"strnlen.char0cmp");
1006 return B.CreateZExt(Cmp, CI->
getType());
1012 Value *LenC = ConstantInt::get(CI->
getType(), Len - 1);
1016 return B.CreateBinaryIntrinsic(Intrinsic::umin, LenC, Bound);
1033 unsigned BW = DL.getIndexTypeSizeInBits(
GEP->getType());
1034 SmallMapVector<Value *, APInt, 4> VarOffsets;
1035 APInt ConstOffset(BW, 0);
1036 assert(CharSize % 8 == 0 &&
"Expected a multiple of 8 sized CharSize");
1038 if (!
GEP->collectOffset(DL, BW, VarOffsets, ConstOffset) ||
1039 VarOffsets.
size() != 1 || ConstOffset != 0 ||
1040 VarOffsets.
begin()->second != CharSize / 8)
1043 ConstantDataArraySlice Slice;
1046 if (Slice.
Array ==
nullptr) {
1069 if ((
Known.isNonNegative() &&
Known.getMaxValue().ule(NullTermIdx)) ||
1071 NullTermIdx == Slice.
Length - 1)) {
1073 return B.CreateSub(ConstantInt::get(CI->
getType(), NullTermIdx),
1083 if (LenTrue && LenFalse) {
1085 return OptimizationRemark(
"instcombine",
"simplify-libcalls", CI)
1086 <<
"folded strlen(select) to select of constants";
1088 return B.CreateSelect(
SI->getCondition(),
1089 ConstantInt::get(CI->
getType(), LenTrue - 1),
1090 ConstantInt::get(CI->
getType(), LenFalse - 1),
"",
1099 if (
Value *
V = optimizeStringLength(CI,
B, 8))
1107 if (
Value *
V = optimizeStringLength(CI,
B, 8, Bound))
1117 unsigned WCharSize =
M.getWCharSize();
1122 if (
Value *
V = optimizeStringLength(CI,
B, WCharSize * 8))
1136 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1140 if (HasS1 && HasS2) {
1141 size_t I =
S1.find_first_of(S2);
1146 B.getInt64(
I),
"strpbrk");
1150 if (HasS2 && S2.
size() == 1)
1175 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1179 if (HasS1 && HasS2) {
1180 size_t Pos =
S1.find_first_not_of(S2);
1183 return ConstantInt::get(CI->
getType(), Pos);
1195 if (HasS1 &&
S1.empty())
1199 if (HasS1 && HasS2) {
1200 size_t Pos =
S1.find_first_of(S2);
1203 return ConstantInt::get(CI->
getType(), Pos);
1207 if (HasS2 && S2.
empty())
1224 StrLen,
B, DL, TLI);
1232 replaceAllUsesWith(Old, Cmp);
1238 StringRef SearchStr, ToFindStr;
1243 if (HasStr2 && ToFindStr.
empty())
1247 if (HasStr1 && HasStr2) {
1254 return B.CreateConstInBoundsGEP1_64(
B.getInt8Ty(), CI->
getArgOperand(0),
1259 if (HasStr2 && ToFindStr.
size() == 1) {
1280 if (LenC->
isOne()) {
1283 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memrchr.char0");
1285 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1286 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memrchr.char0cmp");
1287 return B.CreateSelectWithUnknownProfile(Cmp, SrcStr, NullPtr,
DEBUG_TYPE,
1296 if (Str.size() == 0)
1305 if (Str.size() < EndOff)
1320 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos));
1322 if (Str.find(Str[Pos]) == Pos) {
1329 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
1330 B.getInt64(Pos),
"memrchr.ptr_plus");
1331 return B.CreateSelectWithUnknownProfile(Cmp, NullPtr, SrcPlus,
DEBUG_TYPE,
1337 Str = Str.substr(0, EndOff);
1345 Type *Int8Ty =
B.getInt8Ty();
1346 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1348 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1350 B.CreateICmpEQ(ConstantInt::get(Int8Ty, (
unsigned char)Str[0]), CharVal);
1351 Value *
And =
B.CreateLogicalAnd(NNeZ, CEqS0);
1354 Value *SizeM1 =
B.CreateSub(
Size, ConstantInt::get(SizeTy, 1));
1356 B.CreateInBoundsGEP(Int8Ty, SrcStr, SizeM1,
"memrchr.ptr_plus");
1357 return B.CreateSelectWithUnknownProfile(
And, SrcPlus, NullPtr,
DEBUG_TYPE,
1381 if (LenC->
isOne()) {
1384 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memchr.char0");
1386 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1387 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memchr.char0cmp");
1391 return B.CreateSelectWithUnknownProfile(Cmp, SrcStr, NullPtr,
DEBUG_TYPE,
1412 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos),
1416 return B.CreateSelectWithUnknownProfile(Cmp, NullPtr, SrcPlus,
DEBUG_TYPE);
1419 if (Str.size() == 0)
1428 size_t Pos = Str.find_first_not_of(Str[0]);
1444 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1446 Value *Sel1 = NullPtr;
1449 Value *PosVal = ConstantInt::get(SizeTy, Pos);
1450 Value *StrPos = ConstantInt::get(Int8Ty, (
unsigned char)Str[Pos]);
1451 Value *CEqSPos =
B.CreateICmpEQ(CharVal, StrPos);
1453 Value *
And =
B.CreateAnd(CEqSPos, NGtPos);
1454 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, PosVal);
1457 Sel1 =
B.CreateSelectWithUnknownProfile(
And, SrcPlus, NullPtr,
DEBUG_TYPE,
1461 Value *Str0 = ConstantInt::get(Int8Ty, (
unsigned char)Str[0]);
1462 Value *CEqS0 =
B.CreateICmpEQ(Str0, CharVal);
1463 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1467 return B.CreateSelectWithUnknownProfile(
And, SrcStr, Sel1,
DEBUG_TYPE,
1499 *std::max_element(
reinterpret_cast<const unsigned char *
>(Str.begin()),
1500 reinterpret_cast<const unsigned char *
>(Str.end()));
1507 if (!DL.fitsInLegalInteger(Max + 1)) {
1513 std::string SortedStr = Str.str();
1516 unsigned NonContRanges = 1;
1517 for (
size_t i = 1; i < SortedStr.size(); ++i) {
1518 if (SortedStr[i] > SortedStr[i - 1] + 1) {
1525 if (NonContRanges > 2)
1529 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1532 for (
unsigned char C : SortedStr)
1533 CharCompares.
push_back(
B.CreateICmpEQ(CharVal,
B.getInt8(
C)));
1535 return B.CreateIntToPtr(
B.CreateOr(CharCompares), CI->
getType());
1540 unsigned char Width =
NextPowerOf2(std::max((
unsigned char)7, Max));
1546 Value *BitfieldC =
B.getInt(Bitfield);
1550 C =
B.CreateAnd(
C,
B.getIntN(Width, 0xFF));
1557 Value *Shl =
B.CreateShl(
B.getIntN(Width, 1ULL),
C);
1558 Value *
Bits =
B.CreateIsNotNull(
B.CreateAnd(Shl, BitfieldC),
"memchr.bits");
1562 Value *Memchr =
B.CreateLogicalAnd(Bounds, Bits,
"memchr");
1568 return B.CreateIntToPtr(Memchr, CI->
getType());
1592 if (Pos == MinSize ||
1593 (StrNCmp && (LStr[Pos] ==
'\0' && RStr[Pos] ==
'\0'))) {
1601 if (LStr[Pos] != RStr[Pos])
1606 typedef unsigned char UChar;
1607 int IRes = UChar(LStr[Pos]) < UChar(RStr[Pos]) ? -1 : 1;
1608 Value *MaxSize = ConstantInt::get(
Size->getType(), Pos);
1611 return B.CreateSelect(Cmp,
Zero, Res);
1623 Value *LHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
LHS,
"lhsc"),
1625 Value *RHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
RHS,
"rhsc"),
1627 return B.CreateSub(LHSV, RHSV,
"chardiff");
1635 Align PrefAlignment =
DL.getPrefTypeAlign(IntType);
1638 Value *LHSV =
nullptr;
1642 Value *RHSV =
nullptr;
1651 LHSV =
B.CreateLoad(IntType,
LHS,
"lhsv");
1653 RHSV =
B.CreateLoad(IntType,
RHS,
"rhsv");
1654 return B.CreateZExt(
B.CreateICmpNE(LHSV, RHSV), CI->
getType(),
"memcmp");
1662Value *LibCallSimplifier::optimizeMemCmpBCmpCommon(
CallInst *CI,
1682 if (
Value *
V = optimizeMemCmpBCmpCommon(CI,
B))
1700 return optimizeMemCmpBCmpCommon(CI,
B);
1726 if (
N->isNullValue())
1739 if (
N->getZExtValue() <= SrcStr.
size()) {
1748 ConstantInt::get(
N->getType(), std::min(
uint64_t(Pos + 1),
N->getZExtValue()));
1751 return Pos + 1 <=
N->getZExtValue()
1752 ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, NewN)
1766 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
N);
1799 if (MDNode *MD = CI->
getMetadata(LLVMContext::MD_alloc_token))
1800 MallocCI->setMetadata(LLVMContext::MD_alloc_token, MD);
1809Value *LibCallSimplifier::maybeOptimizeNoBuiltinOperatorNew(
CallInst *CI,
1816 LibFunc
Func = TLI->getLibFunc(*Callee);
1817 if (Func == NotLibFunc)
1821 case LibFunc_ZnwmRKSt9nothrow_t:
1822 case LibFunc_ZnwmSt11align_val_t:
1823 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1825 case LibFunc_ZnamRKSt9nothrow_t:
1826 case LibFunc_ZnamSt11align_val_t:
1827 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1828 case LibFunc_size_returning_new:
1829 case LibFunc_size_returning_new_aligned:
1836 case LibFunc_Znwm12__hot_cold_t:
1837 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1838 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1839 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1840 case LibFunc_Znam12__hot_cold_t:
1841 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1842 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1843 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1844 case LibFunc_size_returning_new_hot_cold:
1845 case LibFunc_size_returning_new_aligned_hot_cold:
1854 return optimizeNew(CI,
B, Func);
1867 bool IsCold =
false;
1868 if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"cold") {
1871 }
else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1874 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"hot")
1876 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1882 bool ShouldOptimizeExistingHotColdNew =
1887 Value *HotColdVal =
B.getInt8(HotCold);
1888 auto getHotColdHintForExisting = [&](uint8_t HotCold) ->
Value * {
1894 ExistingHint =
B.CreateTruncOrBitCast(ExistingHint,
B.getInt8Ty());
1898 return B.CreateBinaryIntrinsic(Intrinsic::umin, ExistingHint, HotColdVal);
1908 Value *NewCall =
nullptr;
1910 case LibFunc_Znwm12__hot_cold_t:
1911 if (ShouldOptimizeExistingHotColdNew)
1913 LibFunc_Znwm12__hot_cold_t,
1914 getHotColdHintForExisting(HotCold));
1918 LibFunc_Znwm12__hot_cold_t, HotColdVal);
1920 case LibFunc_Znam12__hot_cold_t:
1921 if (ShouldOptimizeExistingHotColdNew)
1923 LibFunc_Znam12__hot_cold_t,
1924 getHotColdHintForExisting(HotCold));
1928 LibFunc_Znam12__hot_cold_t, HotColdVal);
1930 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1931 if (ShouldOptimizeExistingHotColdNew)
1934 TLI, LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,
1935 getHotColdHintForExisting(HotCold));
1937 case LibFunc_ZnwmRKSt9nothrow_t:
1940 LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotColdVal);
1942 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1943 if (ShouldOptimizeExistingHotColdNew)
1946 TLI, LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,
1947 getHotColdHintForExisting(HotCold));
1949 case LibFunc_ZnamRKSt9nothrow_t:
1952 LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotColdVal);
1954 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1955 if (ShouldOptimizeExistingHotColdNew)
1958 TLI, LibFunc_ZnwmSt11align_val_t12__hot_cold_t,
1959 getHotColdHintForExisting(HotCold));
1961 case LibFunc_ZnwmSt11align_val_t:
1964 LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotColdVal);
1966 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1967 if (ShouldOptimizeExistingHotColdNew)
1970 TLI, LibFunc_ZnamSt11align_val_t12__hot_cold_t,
1971 getHotColdHintForExisting(HotCold));
1973 case LibFunc_ZnamSt11align_val_t:
1976 LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotColdVal);
1978 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1979 if (ShouldOptimizeExistingHotColdNew)
1982 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1983 getHotColdHintForExisting(HotCold));
1985 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1988 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1991 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1992 if (ShouldOptimizeExistingHotColdNew)
1995 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1996 getHotColdHintForExisting(HotCold));
1998 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
2001 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
2004 case LibFunc_size_returning_new:
2006 LibFunc_size_returning_new_hot_cold,
2009 case LibFunc_size_returning_new_hot_cold:
2010 if (ShouldOptimizeExistingHotColdNew)
2012 CI->
getArgOperand(0),
B, TLI, LibFunc_size_returning_new_hot_cold,
2013 getHotColdHintForExisting(HotCold), CI->
getType());
2015 case LibFunc_size_returning_new_aligned:
2018 LibFunc_size_returning_new_aligned_hot_cold, HotColdVal, CI->
getType());
2020 case LibFunc_size_returning_new_aligned_hot_cold:
2021 if (ShouldOptimizeExistingHotColdNew)
2024 LibFunc_size_returning_new_aligned_hot_cold,
2025 getHotColdHintForExisting(HotCold), CI->
getType());
2073 Value *
Op = Cast->getOperand(0);
2074 if (
Op->getType()->isFloatTy())
2083 return ConstantFP::get(Const->getContext(),
F);
2091 bool isPrecise =
false) {
2123 CallerName.
size() == (CalleeName.
size() + 1) &&
2136 R =
isBinary ?
B.CreateIntrinsic(IID,
B.getFloatTy(),
V)
2137 :
B.CreateIntrinsic(IID,
B.getFloatTy(),
V[0]);
2145 return B.CreateFPExt(R,
B.getDoubleTy());
2151 bool isPrecise =
false) {
2158 bool isPrecise =
false) {
2165 if (!RetTy || RetTy->getNumElements() != 2 ||
2166 !RetTy->getElementType(0)->getScalarType()->isDoubleTy())
2172 if (Ext->getOperand(0)->getType()->getScalarType()->isFloatTy())
2173 X = Ext->getOperand(0);
2183 if (!Cast || !Cast->getType()->getScalarType()->isFloatTy())
2191 Value *NewCall =
B.CreateIntrinsic(Intrinsic::sincos,
X->getType(),
X);
2193 LLVMContext::MD_fpmath, CI->
getMetadata(LLVMContext::MD_fpmath));
2195 for (
unsigned I = 0;
I != 2; ++
I) {
2196 Value *Ext =
B.CreateFPExt(
B.CreateExtractValue(NewCall,
I),
2197 RetTy->getElementType(
I));
2198 Res =
B.CreateInsertValue(Res, Ext,
I);
2213 assert(
Op->getType()->isArrayTy() &&
"Unexpected signature for cabs!");
2215 Real =
B.CreateExtractValue(
Op, 0,
"real");
2216 Imag =
B.CreateExtractValue(
Op, 1,
"imag");
2226 Value *AbsOp =
nullptr;
2228 if (ConstReal->isZero())
2232 if (ConstImag->isZero())
2237 return copyFlags(*CI,
B.CreateFAbs(AbsOp, CI,
"cabs"));
2244 Value *RealReal =
B.CreateFMulFMF(Real, Real, CI);
2245 Value *ImagImag =
B.CreateFMulFMF(Imag, Imag, CI);
2247 *CI,
B.CreateUnaryIntrinsic(Intrinsic::sqrt,
2248 B.CreateFAddFMF(RealReal, ImagImag, CI), CI,
2259 unsigned BitWidth =
Op->getType()->getScalarSizeInBits();
2261 Type *IntTy =
Op->getType()->getWithNewBitWidth(DstWidth);
2263 :
B.CreateZExt(
Op, IntTy);
2298 CalleeFn ? TLI->getLibFunc(CalleeFn->
getName()) : NotLibFunc;
2303 LibFunc LibFnFloat, LibFnDouble, LibFnLongDouble;
2311 ExpName = TLI->getName(LibFunc_exp);
2312 ID = Intrinsic::exp;
2313 LibFnFloat = LibFunc_expf;
2314 LibFnDouble = LibFunc_exp;
2315 LibFnLongDouble = LibFunc_expl;
2320 ExpName = TLI->getName(LibFunc_exp2);
2321 ID = Intrinsic::exp2;
2322 LibFnFloat = LibFunc_exp2f;
2323 LibFnDouble = LibFunc_exp2;
2324 LibFnLongDouble = LibFunc_exp2l;
2331 ?
B.CreateUnaryIntrinsic(ID,
FMul,
nullptr, ExpName)
2340 substituteInParent(BaseFn, ExpFn);
2351 AttributeList NoAttrs;
2353 const bool UseIntrinsic =
Pow->doesNotAccessMemory();
2359 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2364 Constant *One = ConstantFP::get(Ty, 1.0);
2368 {Ty, ExpoI->getType()},
2369 {One, ExpoI},
Pow,
"exp2"));
2373 One, ExpoI, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2374 LibFunc_ldexpl,
B, NoAttrs));
2379 if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f, LibFunc_exp2l)) {
2382 BaseR = BaseR / *BaseF;
2384 const APFloat *NF = IsReciprocal ? &BaseR : BaseF;
2386 if ((IsInteger || IsReciprocal) &&
2389 NI > 1 && NI.isPowerOf2()) {
2390 double N = NI.logBase2() * (IsReciprocal ? -1.0 : 1.0);
2391 Value *
FMul =
B.CreateFMul(Expo, ConstantFP::get(Ty,
N),
"mul");
2392 if (
Pow->doesNotAccessMemory())
2398 LibFunc_exp2l,
B, NoAttrs));
2404 hasFloatFn(M, TLI, Ty, LibFunc_exp10, LibFunc_exp10f, LibFunc_exp10l)) {
2406 if (
Pow->doesNotAccessMemory()) {
2407 return B.CreateIntrinsic(Intrinsic::exp10, {Ty}, {Expo},
Pow,
"exp10", {},
2412 LibFunc_exp10f, LibFunc_exp10l,
2422 "pow(1.0, y) should have been simplified earlier!");
2431 Value *
FMul =
B.CreateFMul(Log, Expo,
"mul");
2432 if (
Pow->doesNotAccessMemory())
2435 else if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f,
2439 LibFunc_exp2l,
B, NoAttrs));
2451 return B.CreateUnaryIntrinsic(Intrinsic::sqrt,
V,
nullptr,
"sqrt");
2454 if (
hasFloatFn(M,
TLI,
V->getType(), LibFunc_sqrt, LibFunc_sqrtf,
2460 LibFunc_sqrtl,
B, Attrs);
2467 Value *Sqrt, *
Base =
Pow->getArgOperand(0), *Expo =
Pow->getArgOperand(1);
2478 if (ExpoF->
isNegative() && (!
Pow->hasApproxFunc() && !
Pow->hasAllowReassoc()))
2485 if (!
Pow->doesNotAccessMemory() && !
Pow->hasNoInfs() &&
2487 Base, SimplifyQuery(DL, TLI, DT, AC,
Pow,
true,
true, DC)))
2496 if (!
Pow->hasNoSignedZeros())
2497 Sqrt =
B.CreateFAbs(Sqrt,
nullptr,
"abs");
2503 if (!
Pow->hasNoInfs()) {
2506 Value *FCmp =
B.CreateFCmpOEQ(
Base, NegInf,
"isinf");
2507 Sqrt =
B.CreateSelect(FCmp, PosInf, Sqrt);
2521 Sqrt =
B.CreateFDiv(ConstantFP::get(Ty, 1.0), Sqrt,
"reciprocal");
2530 return B.CreateIntrinsic(Intrinsic::powi, Types, Args);
2535 Value *Expo =
Pow->getArgOperand(1);
2540 bool AllowApprox =
Pow->hasApproxFunc();
2544 IRBuilderBase::FastMathFlagGuard Guard(
B);
2545 B.setFastMathFlags(
Pow->getFastMathFlags());
2552 if (
Value *Exp = replacePowWithExp(
Pow,
B))
2559 return B.CreateFDiv(ConstantFP::get(Ty, 1.0),
Base,
"reciprocal");
2563 return ConstantFP::get(Ty, 1.0);
2571 return B.CreateFMul(
Base,
Base,
"square");
2573 if (
Value *Sqrt = replacePowWithSqrt(
Pow,
B))
2584 Value *Sqrt =
nullptr;
2585 if (!ExpoA.isInteger()) {
2599 if (!ExpoI.isInteger())
2611 APSInt IntExpo(TLI->getIntSize(),
false);
2618 Base, ConstantInt::get(
B.getIntNTy(TLI->getIntSize()), IntExpo),
2622 return B.CreateFMul(PowI, Sqrt);
2638 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) &&
2639 hasFloatVersion(M, Name)) {
2651 Value *Ret =
nullptr;
2652 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_exp2) &&
2653 hasFloatVersion(M, Name))
2662 const bool UseIntrinsic =
Callee->isIntrinsic();
2673 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2675 Constant *One = ConstantFP::get(Ty, 1.0);
2678 return copyFlags(*CI,
B.CreateIntrinsic(Intrinsic::ldexp,
2679 {Ty, Exp->getType()},
2683 IRBuilderBase::FastMathFlagGuard Guard(
B);
2686 One, Exp, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2687 LibFunc_ldexpl,
B, AttributeList()));
2711 StringRef LogNm = LogFn->
getName();
2716 if (UnsafeFPShrink && (LogFn->
isIntrinsic() || hasFloatVersion(
Mod, LogNm)))
2720 LibFunc LogLb, ExpLb, Exp2Lb, Exp10Lb, PowLb;
2723 LogLb = TLI->getLibFunc(LogNm);
2724 if (LogLb != NotLibFunc) {
2727 LogID = Intrinsic::log;
2728 ExpLb = LibFunc_expf;
2729 Exp2Lb = LibFunc_exp2f;
2730 Exp10Lb = LibFunc_exp10f;
2731 PowLb = LibFunc_powf;
2734 LogID = Intrinsic::log;
2735 ExpLb = LibFunc_exp;
2736 Exp2Lb = LibFunc_exp2;
2737 Exp10Lb = LibFunc_exp10;
2738 PowLb = LibFunc_pow;
2741 LogID = Intrinsic::log;
2742 ExpLb = LibFunc_expl;
2743 Exp2Lb = LibFunc_exp2l;
2744 Exp10Lb = LibFunc_exp10l;
2745 PowLb = LibFunc_powl;
2748 LogID = Intrinsic::log2;
2749 ExpLb = LibFunc_expf;
2750 Exp2Lb = LibFunc_exp2f;
2751 Exp10Lb = LibFunc_exp10f;
2752 PowLb = LibFunc_powf;
2755 LogID = Intrinsic::log2;
2756 ExpLb = LibFunc_exp;
2757 Exp2Lb = LibFunc_exp2;
2758 Exp10Lb = LibFunc_exp10;
2759 PowLb = LibFunc_pow;
2762 LogID = Intrinsic::log2;
2763 ExpLb = LibFunc_expl;
2764 Exp2Lb = LibFunc_exp2l;
2765 Exp10Lb = LibFunc_exp10l;
2766 PowLb = LibFunc_powl;
2768 case LibFunc_log10f:
2769 LogID = Intrinsic::log10;
2770 ExpLb = LibFunc_expf;
2771 Exp2Lb = LibFunc_exp2f;
2772 Exp10Lb = LibFunc_exp10f;
2773 PowLb = LibFunc_powf;
2776 LogID = Intrinsic::log10;
2777 ExpLb = LibFunc_exp;
2778 Exp2Lb = LibFunc_exp2;
2779 Exp10Lb = LibFunc_exp10;
2780 PowLb = LibFunc_pow;
2782 case LibFunc_log10l:
2783 LogID = Intrinsic::log10;
2784 ExpLb = LibFunc_expl;
2785 Exp2Lb = LibFunc_exp2l;
2786 Exp10Lb = LibFunc_exp10l;
2787 PowLb = LibFunc_powl;
2794 bool IsKnownNoErrno =
Log->hasNoNaNs() &&
Log->hasNoInfs();
2795 if (!IsKnownNoErrno) {
2796 SimplifyQuery SQ(DL, TLI, DT, AC, Log,
true,
true, DC);
2803 Known.cannotBeOrderedLessThanZero() &&
2804 Known.isKnownNeverLogicalZero(
F->getDenormalMode(FltSem));
2806 if (IsKnownNoErrno) {
2807 Value *NewLog =
B.CreateUnaryIntrinsic(LogID,
Log->getArgOperand(0), Log);
2809 I->copyMetadata(*Log);
2814 }
else if (LogID == Intrinsic::log || LogID == Intrinsic::log2 ||
2815 LogID == Intrinsic::log10) {
2817 ExpLb = LibFunc_expf;
2818 Exp2Lb = LibFunc_exp2f;
2819 Exp10Lb = LibFunc_exp10f;
2820 PowLb = LibFunc_powf;
2822 ExpLb = LibFunc_exp;
2823 Exp2Lb = LibFunc_exp2;
2824 Exp10Lb = LibFunc_exp10;
2825 PowLb = LibFunc_pow;
2836 IRBuilderBase::FastMathFlagGuard Guard(
B);
2840 LibFunc ArgLb = TLI->getLibFunc(*Arg);
2843 AttributeList NoAttrs;
2844 if (ArgLb == PowLb || ArgID == Intrinsic::pow || ArgID == Intrinsic::powi) {
2846 Log->doesNotAccessMemory()
2847 ?
B.CreateUnaryIntrinsic(LogID, Arg->
getOperand(0),
nullptr,
"log")
2851 if (ArgID == Intrinsic::powi)
2852 Y =
B.CreateSIToFP(
Y, Ty,
"cast");
2853 Value *MulY =
B.CreateFMul(
Y, LogX,
"mul");
2856 substituteInParent(Arg, MulY);
2862 if (ArgLb == ExpLb || ArgLb == Exp2Lb || ArgLb == Exp10Lb ||
2863 ArgID == Intrinsic::exp || ArgID == Intrinsic::exp2) {
2865 if (ArgLb == ExpLb || ArgID == Intrinsic::exp)
2868 else if (ArgLb == Exp2Lb || ArgID == Intrinsic::exp2)
2869 Eul = ConstantFP::get(
Log->getType(), 2.0);
2871 Eul = ConstantFP::get(
Log->getType(), 10.0);
2872 Value *LogE =
Log->doesNotAccessMemory()
2873 ?
B.CreateUnaryIntrinsic(LogID, Eul,
nullptr,
"log")
2878 substituteInParent(Arg, MulY);
2895 LibFunc ArgLb = TLI->getLibFunc(*Arg);
2897 LibFunc SqrtLb, ExpLb, Exp2Lb, Exp10Lb;
2899 SqrtLb = TLI->getLibFunc(SqrtFn->
getName());
2900 if (SqrtLb != NotLibFunc)
2903 ExpLb = LibFunc_expf;
2904 Exp2Lb = LibFunc_exp2f;
2905 Exp10Lb = LibFunc_exp10f;
2908 ExpLb = LibFunc_exp;
2909 Exp2Lb = LibFunc_exp2;
2910 Exp10Lb = LibFunc_exp10;
2913 ExpLb = LibFunc_expl;
2914 Exp2Lb = LibFunc_exp2l;
2915 Exp10Lb = LibFunc_exp10l;
2922 ExpLb = LibFunc_expf;
2923 Exp2Lb = LibFunc_exp2f;
2924 Exp10Lb = LibFunc_exp10f;
2926 ExpLb = LibFunc_exp;
2927 Exp2Lb = LibFunc_exp2;
2928 Exp10Lb = LibFunc_exp10;
2934 if (ArgLb != ExpLb && ArgLb != Exp2Lb && ArgLb != Exp10Lb &&
2935 ArgID != Intrinsic::exp && ArgID != Intrinsic::exp2)
2938 IRBuilderBase::InsertPointGuard Guard(
B);
2939 B.SetInsertPoint(Arg);
2942 B.CreateFMulFMF(ExpOperand, ConstantFP::get(ExpOperand->getType(), 0.5),
2952 Value *Ret =
nullptr;
2957 (
Callee->getName() ==
"sqrt" ||
2958 Callee->getIntrinsicID() == Intrinsic::sqrt))
2961 if (
Value *Opt = mergeSqrtToExp(CI,
B))
2968 if (!
I ||
I->getOpcode() != Instruction::FMul || !
I->isFast())
2974 Value *Op0 =
I->getOperand(0);
2975 Value *Op1 =
I->getOperand(1);
2976 Value *RepeatOp =
nullptr;
2977 Value *OtherOp =
nullptr;
3008 Value *FabsCall =
B.CreateFAbs(RepeatOp,
I,
"fabs");
3014 B.CreateUnaryIntrinsic(Intrinsic::sqrt, OtherOp,
I,
"sqrt");
3015 return copyFlags(*CI,
B.CreateFMulFMF(FabsCall, SqrtCall,
I));
3026 SimplifyQuery SQ(DL, TLI, DT, AC, CI,
true,
true, DC);
3029 KnownFPClass Known1 =
3032 const fltSemantics &FltSem =
3043Value *LibCallSimplifier::optimizeTrigInversionPairs(
CallInst *CI,
3047 Value *Ret =
nullptr;
3049 if (UnsafeFPShrink &&
3050 (Name ==
"tan" || Name ==
"atanh" || Name ==
"sinh" || Name ==
"cosh" ||
3052 hasFloatVersion(M, Name))
3061 if (!CI->
isFast() || !OpC->isFast())
3070 LibFunc
Func =
F ? TLI->getLibFunc(
F->getName()) : NotLibFunc;
3072 LibFunc inverseFunc = llvm::StringSwitch<LibFunc>(
Callee->getName())
3073 .Case(
"tan", LibFunc_atan)
3074 .Case(
"atanh", LibFunc_tanh)
3075 .Case(
"sinh", LibFunc_asinh)
3076 .Case(
"cosh", LibFunc_acosh)
3077 .Case(
"tanf", LibFunc_atanf)
3078 .Case(
"atanhf", LibFunc_tanhf)
3079 .Case(
"sinhf", LibFunc_asinhf)
3080 .Case(
"coshf", LibFunc_acoshf)
3081 .Case(
"tanl", LibFunc_atanl)
3082 .Case(
"atanhl", LibFunc_tanhl)
3083 .Case(
"sinhl", LibFunc_asinhl)
3084 .Case(
"coshl", LibFunc_acoshl)
3085 .Case(
"asinh", LibFunc_sinh)
3086 .Case(
"asinhf", LibFunc_sinhf)
3087 .Case(
"asinhl", LibFunc_sinhl)
3088 .Default(NotLibFunc);
3089 if (Func == inverseFunc)
3090 Ret = OpC->getArgOperand(0);
3112 Name =
"__sincospif_stret";
3121 Name =
"__sincospi_stret";
3127 LibFunc TheLibFunc =
TLI->getLibFunc(Name);
3134 B.SetInsertPoint(++ArgInst->getIterator());
3138 BasicBlock &EntryBB =
B.GetInsertBlock()->getParent()->getEntryBlock();
3139 B.SetInsertPoint(EntryBB.
begin());
3142 SinCos =
B.CreateCall(Callee, Arg,
"sincospi");
3145 Sin =
B.CreateExtractValue(SinCos, 0,
"sinpi");
3146 Cos =
B.CreateExtractValue(SinCos, 1,
"cospi");
3148 Sin =
B.CreateExtractElement(SinCos,
uint64_t{0},
"sinpi");
3149 Cos =
B.CreateExtractElement(SinCos,
uint64_t{1},
"cospi");
3159 return Mode.inputsMayBePositiveZero() ||
Mode.outputsMayBePositiveZero();
3190Value *LibCallSimplifier::optimizeSymmetric(
CallInst *CI, LibFunc Func,
3219 case LibFunc_asinhf:
3220 case LibFunc_asinhl:
3264 for (User *U : Arg->
users())
3265 classifyArgUse(U,
F, IsFloat, SinCalls, CosCalls, SinCosCalls);
3271 Value *Sin, *Cos, *SinCos;
3276 auto replaceTrigInsts = [
this](SmallVectorImpl<CallInst *> &Calls,
3278 for (CallInst *
C : Calls)
3279 replaceAllUsesWith(
C, Res);
3282 replaceTrigInsts(SinCalls, Sin);
3283 replaceTrigInsts(CosCalls, Cos);
3284 replaceTrigInsts(SinCosCalls, SinCos);
3286 return IsSin ? Sin : Cos;
3289void LibCallSimplifier::classifyArgUse(
3304 LibFunc
Func =
Callee ? TLI->getLibFunc(*Callee) : NotLibFunc;
3309 if (Func == LibFunc_sinpif)
3311 else if (Func == LibFunc_cospif)
3313 else if (Func == LibFunc_sincospif_stret)
3316 if (Func == LibFunc_sinpi)
3318 else if (Func == LibFunc_cospi)
3320 else if (Func == LibFunc_sincospi_stret)
3342 unsigned IntBW = TLI->getIntSize();
3343 APSInt QuotInt(IntBW,
false);
3350 B.CreateAlignedStore(
3353 return ConstantFP::get(CI->
getType(), Rem);
3380 return ConstantFP::get(CI->
getType(), Difference);
3392 Type *ArgType =
Op->getType();
3393 Value *
V =
B.CreateIntrinsic(Intrinsic::cttz, {ArgType}, {
Op,
B.getTrue()},
3395 V =
B.CreateAdd(
V, ConstantInt::get(
V->getType(), 1));
3396 V =
B.CreateIntCast(
V, RetType,
false);
3399 Value *S =
B.CreateSelect(
Cond,
V, ConstantInt::get(RetType, 0));
3413 Type *ArgType =
Op->getType();
3414 Value *
V =
B.CreateIntrinsic(Intrinsic::ctlz, {ArgType}, {
Op,
B.getFalse()},
3418 return B.CreateIntCast(
V, CI->
getType(),
false);
3425 Value *IsNeg =
B.CreateIsNeg(
X);
3426 Value *NegX =
B.CreateNSWNeg(
X,
"neg");
3427 return B.CreateSelect(IsNeg, NegX,
X);
3433 Type *ArgType =
Op->getType();
3434 Op =
B.CreateSub(
Op, ConstantInt::get(ArgType,
'0'),
"isdigittmp");
3435 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 10),
"isdigit");
3442 Type *ArgType =
Op->getType();
3443 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 128),
"isascii");
3450 ConstantInt::get(CI->
getType(), 0x7F));
3480 return convertStrToInt(CI, Str, EndPtr, CInt->getSExtValue(), AsSigned,
B);
3512 if (!Callee || !Callee->isDeclaration())
3521 if (StreamArg >= (
int)CI->
arg_size())
3529 return GV->
getName() ==
"stderr";
3534 StringRef FormatStr;
3539 if (FormatStr.
empty())
3550 if (FormatStr.
size() == 1 || FormatStr ==
"%%") {
3554 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)FormatStr[0]);
3555 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3559 if (FormatStr ==
"%s" && CI->
arg_size() > 1) {
3560 StringRef OperandStr;
3561 if (!getConstantStringInfo(CI->getOperand(1), OperandStr))
3564 if (OperandStr.empty())
3567 if (OperandStr.size() == 1) {
3571 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)OperandStr[0]);
3572 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3575 if (OperandStr.back() ==
'\n') {
3576 if (!isLibFuncEmittable(CI->getModule(), TLI, LibFunc_puts))
3578 OperandStr = OperandStr.drop_back();
3579 Value *GV = B.CreateGlobalString(OperandStr,
"str");
3580 return copyFlags(*CI, emitPutS(GV, B, TLI));
3586 if (FormatStr.
back() ==
'\n' &&
3588 if (!isLibFuncEmittable(CI->getModule(), TLI, LibFunc_puts))
3592 FormatStr = FormatStr.drop_back();
3593 Value *GV = B.CreateGlobalString(FormatStr,
"str");
3594 return copyFlags(*CI, emitPutS(GV, B, TLI));
3599 if (FormatStr ==
"%c" && CI->
arg_size() > 1 &&
3603 Value *IntChar = B.CreateIntCast(CI->getArgOperand(1), IntTy, false);
3604 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3608 if (FormatStr ==
"%s\n" && CI->
arg_size() > 1 &&
3618 FunctionType *FT =
Callee->getFunctionType();
3619 if (
Value *
V = optimizePrintFString(CI,
B)) {
3630 Callee->getAttributes());
3632 New->setCalledFunction(IPrintFFn);
3642 Callee->getAttributes());
3644 New->setCalledFunction(SmallPrintFFn);
3652Value *LibCallSimplifier::optimizeSPrintFString(
CallInst *CI,
3655 StringRef FormatStr;
3671 return ConstantInt::get(CI->
getType(), FormatStr.
size());
3676 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3680 if (FormatStr[1] ==
'c') {
3686 B.CreateStore(
V, Ptr);
3687 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Ptr,
B.getInt32(1),
"nul");
3688 B.CreateStore(
B.getInt8(0), Ptr);
3690 return ConstantInt::get(CI->
getType(), 1);
3693 if (FormatStr[1] ==
's') {
3706 TLI->getAsSizeT(SrcLen, *CI->
getModule()));
3708 return ConstantInt::get(CI->
getType(), SrcLen - 1);
3711 Value *PtrDiff =
B.CreatePtrDiff(
V, Dest);
3712 return B.CreateIntCast(PtrDiff, CI->
getType(),
false);
3723 B.CreateAdd(Len, ConstantInt::get(
Len->getType(), 1),
"leninc");
3727 return B.CreateIntCast(Len, CI->
getType(),
false);
3735 FunctionType *FT =
Callee->getFunctionType();
3736 if (
Value *
V = optimizeSPrintFString(CI,
B)) {
3747 FT,
Callee->getAttributes());
3749 New->setCalledFunction(SIPrintFFn);
3759 Callee->getAttributes());
3761 New->setCalledFunction(SmallSPrintFFn);
3777 assert(StrArg || (
N < 2 && Str.size() == 1));
3779 unsigned IntBits = TLI->getIntSize();
3781 if (Str.size() > IntMax)
3787 Value *StrLen = ConstantInt::get(CI->
getType(), Str.size());
3797 NCopy = Str.size() + 1;
3802 if (NCopy && StrArg)
3805 TLI->getAsSizeT(NCopy, *CI->
getModule())));
3814 Value *NulOff =
B.getIntN(IntBits, NCopy);
3815 Value *DstEnd =
B.CreateInBoundsGEP(Int8Ty, DstArg, NulOff,
"endptr");
3816 B.CreateStore(ConstantInt::get(Int8Ty, 0), DstEnd);
3820Value *LibCallSimplifier::optimizeSnPrintFString(
CallInst *CI,
3838 StringRef FormatStr;
3849 return emitSnPrintfMemCpy(CI, FmtArg, FormatStr,
N,
B);
3854 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() != 4)
3858 if (FormatStr[1] ==
'c') {
3863 StringRef CharStr(
"*");
3864 return emitSnPrintfMemCpy(CI,
nullptr, CharStr,
N,
B);
3871 Value *Ptr = DstArg;
3872 B.CreateStore(
V, Ptr);
3873 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Ptr,
B.getInt32(1),
"nul");
3874 B.CreateStore(
B.getInt8(0), Ptr);
3875 return ConstantInt::get(CI->
getType(), 1);
3878 if (FormatStr[1] !=
's')
3887 return emitSnPrintfMemCpy(CI, StrArg, Str,
N,
B);
3891 if (
Value *
V = optimizeSnPrintFString(CI,
B)) {
3900Value *LibCallSimplifier::optimizeFPrintFString(
CallInst *CI,
3902 optimizeErrorReporting(CI,
B, 0);
3905 StringRef FormatStr;
3929 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3933 if (FormatStr[1] ==
'c') {
3937 Type *IntTy =
B.getIntNTy(TLI->getIntSize());
3943 if (FormatStr[1] ==
's') {
3956 FunctionType *FT =
Callee->getFunctionType();
3957 if (
Value *
V = optimizeFPrintFString(CI,
B)) {
3966 FT,
Callee->getAttributes());
3968 New->setCalledFunction(FIPrintFFn);
3977 auto SmallFPrintFFn =
3979 Callee->getAttributes());
3981 New->setCalledFunction(SmallFPrintFFn);
3990 optimizeErrorReporting(CI,
B, 3);
3995 if (SizeC && CountC) {
4000 return ConstantInt::get(CI->
getType(), 0);
4007 Value *Cast =
B.CreateIntCast(Char, IntTy,
true,
"chari");
4009 return NewCI ? ConstantInt::get(CI->
getType(), 1) : nullptr;
4017 optimizeErrorReporting(CI,
B, 1);
4035 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
4040 ConstantInt::get(SizeTTy, Len - 1),
4080bool LibCallSimplifier::hasFloatVersion(
const Module *M,
StringRef FuncName) {
4081 SmallString<20> FloatFuncName = FuncName;
4082 FloatFuncName +=
'f';
4086Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
4090 LibFunc
Func = TLI->getLibFunc(*Callee);
4098 "Optimizing string/memory libcall would change the calling convention");
4100 case LibFunc_strcat:
4101 return optimizeStrCat(CI, Builder);
4102 case LibFunc_strncat:
4103 return optimizeStrNCat(CI, Builder);
4104 case LibFunc_strchr:
4105 return optimizeStrChr(CI, Builder);
4106 case LibFunc_strrchr:
4107 return optimizeStrRChr(CI, Builder);
4108 case LibFunc_strcmp:
4109 return optimizeStrCmp(CI, Builder);
4110 case LibFunc_strncmp:
4111 return optimizeStrNCmp(CI, Builder);
4112 case LibFunc_strcpy:
4113 return optimizeStrCpy(CI, Builder);
4114 case LibFunc_stpcpy:
4115 return optimizeStpCpy(CI, Builder);
4116 case LibFunc_strlcpy:
4117 return optimizeStrLCpy(CI, Builder);
4118 case LibFunc_stpncpy:
4119 return optimizeStringNCpy(CI,
true, Builder);
4120 case LibFunc_strncpy:
4121 return optimizeStringNCpy(CI,
false, Builder);
4122 case LibFunc_strlen:
4123 return optimizeStrLen(CI, Builder);
4124 case LibFunc_strnlen:
4125 return optimizeStrNLen(CI, Builder);
4126 case LibFunc_strpbrk:
4127 return optimizeStrPBrk(CI, Builder);
4128 case LibFunc_strndup:
4129 return optimizeStrNDup(CI, Builder);
4130 case LibFunc_strtol:
4131 case LibFunc_strtod:
4132 case LibFunc_strtof:
4133 case LibFunc_strtoul:
4134 case LibFunc_strtoll:
4135 case LibFunc_strtold:
4136 case LibFunc_strtoull:
4137 return optimizeStrTo(CI, Builder);
4138 case LibFunc_strspn:
4139 return optimizeStrSpn(CI, Builder);
4140 case LibFunc_strcspn:
4141 return optimizeStrCSpn(CI, Builder);
4142 case LibFunc_strstr:
4143 return optimizeStrStr(CI, Builder);
4144 case LibFunc_memchr:
4145 return optimizeMemChr(CI, Builder);
4146 case LibFunc_memrchr:
4147 return optimizeMemRChr(CI, Builder);
4149 return optimizeBCmp(CI, Builder);
4150 case LibFunc_memcmp:
4151 return optimizeMemCmp(CI, Builder);
4152 case LibFunc_memcpy:
4153 return optimizeMemCpy(CI, Builder);
4154 case LibFunc_memccpy:
4155 return optimizeMemCCpy(CI, Builder);
4156 case LibFunc_mempcpy:
4157 return optimizeMemPCpy(CI, Builder);
4158 case LibFunc_memmove:
4159 return optimizeMemMove(CI, Builder);
4160 case LibFunc_memset:
4161 return optimizeMemSet(CI, Builder);
4162 case LibFunc_realloc:
4163 return optimizeRealloc(CI, Builder);
4164 case LibFunc_wcslen:
4165 return optimizeWcslen(CI, Builder);
4167 return optimizeBCopy(CI, Builder);
4169 case LibFunc_ZnwmRKSt9nothrow_t:
4170 case LibFunc_ZnwmSt11align_val_t:
4171 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
4173 case LibFunc_ZnamRKSt9nothrow_t:
4174 case LibFunc_ZnamSt11align_val_t:
4175 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
4176 case LibFunc_Znwm12__hot_cold_t:
4177 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
4178 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
4179 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
4180 case LibFunc_Znam12__hot_cold_t:
4181 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
4182 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
4183 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
4184 case LibFunc_size_returning_new:
4185 case LibFunc_size_returning_new_hot_cold:
4186 case LibFunc_size_returning_new_aligned:
4187 case LibFunc_size_returning_new_aligned_hot_cold:
4188 return optimizeNew(CI, Builder, Func);
4204 if (CharSeq.
empty())
4205 Fill =
APInt(32, 0);
4212Value *LibCallSimplifier::optimizeFloatingPointLibCall(
CallInst *CI,
4221 if (
Value *
V = optimizeSymmetric(CI, Func, Builder))
4225 case LibFunc_sinpif:
4227 return optimizeSinCosPi(CI,
true, Builder);
4228 case LibFunc_cospif:
4230 return optimizeSinCosPi(CI,
false, Builder);
4244 return optimizePow(CI, Builder);
4248 return optimizeExp2(CI, Builder);
4250 case LibFunc_ldexpf:
4251 case LibFunc_ldexpl:
4252 case LibFunc_scalbn:
4253 case LibFunc_scalbnf:
4254 case LibFunc_scalbnl:
4271 if (
Value *
V = optimizeSqrt(CI, Builder))
4279 return optimizeFMod(CI, Builder);
4283 case LibFunc_log10f:
4285 case LibFunc_log10l:
4286 case LibFunc_log1pf:
4288 case LibFunc_log1pl:
4295 return optimizeLog(CI, Builder);
4303 case LibFunc_asinhf:
4304 case LibFunc_asinhl:
4309 case LibFunc_atanhf:
4310 case LibFunc_atanhl:
4311 return optimizeTrigInversionPairs(CI, Builder);
4316 case LibFunc_floorf:
4318 case LibFunc_floorl:
4320 case LibFunc_roundf:
4322 case LibFunc_roundl:
4324 case LibFunc_roundevenf:
4325 case LibFunc_roundeven:
4326 case LibFunc_roundevenl:
4328 case LibFunc_nearbyintf:
4329 case LibFunc_nearbyint:
4330 case LibFunc_nearbyintl:
4336 case LibFunc_truncf:
4338 case LibFunc_truncl:
4342 if (UnsafeFPShrink &&
4348 CI, Builder, Func == LibFunc_sin ? Intrinsic::sin : Intrinsic::cos);
4362 case LibFunc_copysign:
4367 case LibFunc_copysignf:
4368 case LibFunc_copysignl:
4373 return optimizeFdim(CI, Builder);
4377 return optimizeFMinFMax(CI, Builder, Intrinsic::minnum);
4381 return optimizeFMinFMax(CI, Builder, Intrinsic::maxnum);
4382 case LibFunc_fminimum_numf:
4383 case LibFunc_fminimum_num:
4384 case LibFunc_fminimum_numl:
4386 case LibFunc_fmaximum_numf:
4387 case LibFunc_fmaximum_num:
4388 case LibFunc_fmaximum_numl:
4393 return optimizeCAbs(CI, Builder);
4394 case LibFunc_remquo:
4395 case LibFunc_remquof:
4396 case LibFunc_remquol:
4397 return optimizeRemquo(CI, Builder);
4412 LibFunc Func = TLI->getLibFunc(*Callee);
4425 return maybeOptimizeNoBuiltinOperatorNew(CI, Builder);
4434 Builder.setDefaultOperandBundles(OpBundles);
4442 UnsafeFPShrink =
true;
4446 if (!IsCallingConvC)
4450 switch (
II->getIntrinsicID()) {
4451 case Intrinsic::pow:
4452 return optimizePow(CI, Builder);
4453 case Intrinsic::exp2:
4454 return optimizeExp2(CI, Builder);
4455 case Intrinsic::log:
4456 case Intrinsic::log2:
4457 case Intrinsic::log10:
4458 return optimizeLog(CI, Builder);
4459 case Intrinsic::sqrt:
4460 return optimizeSqrt(CI, Builder);
4461 case Intrinsic::memset:
4462 return optimizeMemSet(CI, Builder);
4463 case Intrinsic::memcpy:
4464 return optimizeMemCpy(CI, Builder);
4465 case Intrinsic::memmove:
4466 return optimizeMemMove(CI, Builder);
4467 case Intrinsic::sin:
4468 case Intrinsic::cos:
4472 case Intrinsic::sincos:
4482 if (
Value *SimplifiedFortifiedCI =
4483 FortifiedSimplifier.optimizeCall(CI, Builder))
4484 return SimplifiedFortifiedCI;
4491 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
4493 if (
Value *V = optimizeFloatingPointLibCall(CI, Func, Builder))
4499 return optimizeFFS(CI, Builder);
4503 return optimizeFls(CI, Builder);
4507 return optimizeAbs(CI, Builder);
4508 case LibFunc_isdigit:
4509 return optimizeIsDigit(CI, Builder);
4510 case LibFunc_isascii:
4511 return optimizeIsAscii(CI, Builder);
4512 case LibFunc_toascii:
4513 return optimizeToAscii(CI, Builder);
4517 return optimizeAtoi(CI, Builder);
4518 case LibFunc_strtol:
4519 case LibFunc_strtoll:
4520 return optimizeStrToInt(CI, Builder,
true);
4521 case LibFunc_strtoul:
4522 case LibFunc_strtoull:
4523 return optimizeStrToInt(CI, Builder,
false);
4524 case LibFunc_printf:
4525 return optimizePrintF(CI, Builder);
4526 case LibFunc_sprintf:
4527 return optimizeSPrintF(CI, Builder);
4528 case LibFunc_snprintf:
4529 return optimizeSnPrintF(CI, Builder);
4530 case LibFunc_fprintf:
4531 return optimizeFPrintF(CI, Builder);
4532 case LibFunc_fwrite:
4533 return optimizeFWrite(CI, Builder);
4535 return optimizeFPuts(CI, Builder);
4537 return optimizePuts(CI, Builder);
4538 case LibFunc_perror:
4539 return optimizeErrorReporting(CI, Builder);
4540 case LibFunc_vfprintf:
4541 case LibFunc_fiprintf:
4542 return optimizeErrorReporting(CI, Builder, 0);
4545 return optimizeExit(CI);
4559 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), DT(DT), DC(DC), AC(AC),
4560 ORE(ORE), BFI(BFI), PSI(PSI), Replacer(Replacer), Eraser(Eraser) {}
4567void LibCallSimplifier::eraseFromParent(
Instruction *
I) {
4606bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
4607 CallInst *CI,
unsigned ObjSizeOp, std::optional<unsigned> SizeOp,
4608 std::optional<unsigned> StrOp, std::optional<unsigned> FlagOp) {
4613 if (!Flag || !
Flag->isZero())
4620 if (ConstantInt *ObjSizeCI =
4622 if (ObjSizeCI->isMinusOne())
4625 if (OnlyLowerUnknownSize)
4635 return ObjSizeCI->getZExtValue() >=
Len;
4639 if (ConstantInt *SizeCI =
4641 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
4647Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
4649 if (isFortifiedCallFoldable(CI, 3, 2)) {
4659Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
4661 if (isFortifiedCallFoldable(CI, 3, 2)) {
4671Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
4673 if (isFortifiedCallFoldable(CI, 3, 2)) {
4683Value *FortifiedLibCallSimplifier::optimizeMemPCpyChk(
CallInst *CI,
4686 if (isFortifiedCallFoldable(CI, 3, 2))
4694Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
4702 if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
4704 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
4712 if (isFortifiedCallFoldable(CI, 2, std::nullopt, 1)) {
4713 if (Func == LibFunc_strcpy_chk)
4719 if (OnlyLowerUnknownSize)
4729 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
4731 Value *LenV = ConstantInt::get(SizeTTy, Len);
4735 if (Ret && Func == LibFunc_stpcpy_chk)
4736 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
4737 ConstantInt::get(SizeTTy, Len - 1));
4741Value *FortifiedLibCallSimplifier::optimizeStrLenChk(
CallInst *CI,
4743 if (isFortifiedCallFoldable(CI, 1, std::nullopt, 0))
4749Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
4752 if (isFortifiedCallFoldable(CI, 3, 2)) {
4753 if (Func == LibFunc_strncpy_chk)
4766Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(
CallInst *CI,
4768 if (isFortifiedCallFoldable(CI, 4, 3))
4776Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(
CallInst *CI,
4778 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2)) {
4788Value *FortifiedLibCallSimplifier::optimizeSPrintfChk(
CallInst *CI,
4790 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1)) {
4794 VariadicArgs,
B, TLI));
4800Value *FortifiedLibCallSimplifier::optimizeStrCatChk(
CallInst *CI,
4802 if (isFortifiedCallFoldable(CI, 2))
4809Value *FortifiedLibCallSimplifier::optimizeStrLCat(
CallInst *CI,
4811 if (isFortifiedCallFoldable(CI, 3))
4819Value *FortifiedLibCallSimplifier::optimizeStrNCatChk(
CallInst *CI,
4821 if (isFortifiedCallFoldable(CI, 3))
4829Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(
CallInst *CI,
4831 if (isFortifiedCallFoldable(CI, 3))
4839Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(
CallInst *CI,
4841 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2))
4849Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(
CallInst *CI,
4851 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1))
4881 Builder.setDefaultOperandBundles(OpBundles);
4885 LibFunc Func = TLI->getLibFunc(*Callee);
4886 if (Func == NotLibFunc)
4894 case LibFunc_memcpy_chk:
4895 return optimizeMemCpyChk(CI, Builder);
4896 case LibFunc_mempcpy_chk:
4897 return optimizeMemPCpyChk(CI, Builder);
4898 case LibFunc_memmove_chk:
4899 return optimizeMemMoveChk(CI, Builder);
4900 case LibFunc_memset_chk:
4901 return optimizeMemSetChk(CI, Builder);
4902 case LibFunc_stpcpy_chk:
4903 case LibFunc_strcpy_chk:
4904 return optimizeStrpCpyChk(CI, Builder, Func);
4905 case LibFunc_strlen_chk:
4906 return optimizeStrLenChk(CI, Builder);
4907 case LibFunc_stpncpy_chk:
4908 case LibFunc_strncpy_chk:
4909 return optimizeStrpNCpyChk(CI, Builder, Func);
4910 case LibFunc_memccpy_chk:
4911 return optimizeMemCCpyChk(CI, Builder);
4912 case LibFunc_snprintf_chk:
4913 return optimizeSNPrintfChk(CI, Builder);
4914 case LibFunc_sprintf_chk:
4915 return optimizeSPrintfChk(CI, Builder);
4916 case LibFunc_strcat_chk:
4917 return optimizeStrCatChk(CI, Builder);
4918 case LibFunc_strlcat_chk:
4919 return optimizeStrLCat(CI, Builder);
4920 case LibFunc_strncat_chk:
4921 return optimizeStrNCatChk(CI, Builder);
4922 case LibFunc_strlcpy_chk:
4923 return optimizeStrLCpyChk(CI, Builder);
4924 case LibFunc_vsnprintf_chk:
4925 return optimizeVSNPrintfChk(CI, Builder);
4926 case LibFunc_vsprintf_chk:
4927 return optimizeVSPrintfChk(CI, Builder);
4936 : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
const TargetLowering & TLI
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Module.h This file contains the declarations for the Module class.
static bool mayFlushDenormalsToPositiveZero(const CallInst *CI)
Flushing a denormal to +0.0 breaks f(-x) = -f(x) for odd f.
static llvm::Error parse(GsymDataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
uint64_t IntrinsicInst * II
static bool isBinary(MachineInstr &MI)
This file contains the declarations for profiling metadata utility functions.
SmallVector< MachineOperand, 4 > Cond
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static bool isOnlyUsedInEqualityComparison(Value *V, Value *With)
Return true if it is only used in equality comparisons with With.
static Value * optimizeSinCosDoubleFP(CallInst *CI, IRBuilderBase &B)
Shrink double -> float for llvm.sincos.
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 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 cl::opt< OptimizeExistingHotColdNewKind > OptimizeExistingHotColdNew("optimize-existing-hot-cold-new", cl::Hidden, cl::desc("Enable optimization of existing hot/cold operator new library calls"), cl::values(clEnumValN(OptimizeExistingHotColdNewKind::None, "none", "Do not optimize existing hot/cold operator new library calls"), clEnumValN(OptimizeExistingHotColdNewKind::Cold, "cold", "Only optimize existing hot/cold operator new library calls " "if determined to be cold"), clEnumValN(OptimizeExistingHotColdNewKind::Always, "always", "Always optimize existing hot/cold operator new library calls"), clEnumValN(OptimizeExistingHotColdNewKind::Always, "", "Always optimize existing hot/cold operator new library calls")), cl::init(OptimizeExistingHotColdNewKind::None), cl::ValueOptional)
static cl::opt< bool > MinExistingHotColdNewHint("min-existing-hot-cold-new-hint", cl::Hidden, cl::init(false), cl::desc("Take the minimum of compiler hint and existing hint when " "optimizing existing hot/cold operator new library calls"))
static bool ignoreCallingConv(LibFunc Func)
static void annotateDereferenceableBytes(CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t DereferenceableBytes)
static void copyFPMath(const CallInst &Old, Value *New)
Preserve the accuracy requirement of Old on the replacement New.
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 * replaceBinaryCall(CallInst *CI, IRBuilderBase &B, Intrinsic::ID IID)
static Value * valueHasFloatPrecision(Value *Val)
Return a variant of Val with float type.
static void annotateNonNullNoUndefBasedOnAccess(CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t CharSize=1)
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 bool canTransformToMemCmp(CallInst *CI, Value *Str, uint64_t Len, const SimplifyQuery &SQ)
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< bool > OptimizeNoBuiltinHotColdNew("optimize-nobuiltin-hot-cold-new-new", cl::Hidden, cl::init(false), cl::desc("Enable transformation of nobuiltin operator new library calls"))
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 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"))
OptimizeExistingHotColdNewKind
This file defines the SmallString class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static SymbolRef::Type getType(const Symbol *Sym)
static const fltSemantics & IEEEsingle()
static constexpr roundingMode rmTowardZero
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
opStatus
IEEE-754R 7: Default exception handling.
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
Class for arbitrary precision integers.
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 ConstantFP * getZero(Type *Ty, bool Negative=false)
static LLVM_ABI ConstantFP * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
static LLVM_ABI ConstantFP * getInfinity(Type *Ty, bool Negative=false)
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.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
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)
LLVM_ABI FortifiedLibCallSimplifier(const TargetLibraryInfo *TLI, bool OnlyLowerUnknownSize=false)
LLVM_ABI 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.".
DenormalMode getDenormalMode(const fltSemantics &FPType) const
Returns the denormal handling type for the default rounding mode of the function.
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.
Value * CreateLdexp(Value *Src, Value *Exp, FMFSource FMFSource={}, const Twine &Name="")
Create call to the ldexp intrinsic.
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 void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
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.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
iterator_range< user_iterator > users()
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 void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
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.
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 known this can never be interpreted as a zero.
LLVM_ABI 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)
LLVM_ABI 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()
static constexpr uint32_t kLikelyBranchWeight
The weight for a branch taken with high probability.
static constexpr uint32_t kUnlikelyBranchWeight
The weight for a branch taken with low probability.
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.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
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.
Represent a constant reference to a string, i.e.
static constexpr size_t npos
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
Check if the string is empty.
char back() const
Get the last character in the string.
constexpr size_t size() const
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.
int compare(StringRef RHS) const
Compare two strings; the result is negative, zero, or positive if this string is lexicographically le...
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.
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
bool isVoidTy() const
Return true if this is 'void'.
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.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< user_iterator > users()
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.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
match_deferred< 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()...
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
ap_match< APFloat > m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
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.
auto m_CopySign(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_Value()
Match an arbitrary value and ignore it.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
FNeg_match< OpTy, true > m_FNegOrFSubNegZero(const OpTy &X)
Match fneg X or fsub -0.0, X.
auto m_FAbs(const Opnd0 &Op0)
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
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.
LLVM_ABI Value * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold, Type *RetTy)
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 cl::opt< bool > ProfcheckDisableMetadataFixes
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...
@ Known
Known to have no common set bits.
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName, const Function *F=nullptr)
Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...
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 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_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 void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=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 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 * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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 void setBranchWeights(Instruction &I, ArrayRef< uint32_t > Weights, bool IsExpected, bool ElideAllZero=false)
Create a new branch_weights metadata node and add or overwrite a prof metadata reference to instructi...
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)
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 Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
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.
LLVM_ABI bool isOnlyUsedInZeroEqualityComparison(const Instruction *CtxI)
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 * 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.
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
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 * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *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 * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold, Type *RetTy)
LLVM_ABI bool isDereferenceablePointer(const Value *V, Type *Ty, const SimplifyQuery &Q, bool IgnoreFree=false)
Equivalent to isDereferenceableAndAlignedPointer with an alignment of 1.
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 * 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.
@ Always
Always emit .debug_str_offsets talbes as DWARF64 for testing.
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.
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.
Represent subnormal handling kind for floating point instruction inputs and outputs.