51 cl::desc(
"Enable unsafe double to float "
52 "shrinking for math lib calls"));
59 cl::desc(
"Enable hot/cold operator new library calls"));
63 "Enable optimization of existing hot/cold operator new library calls"));
66 cl::desc(
"Enable transformation of nobuiltin operator new library calls"));
73struct HotColdHintParser :
public cl::parser<unsigned> {
76 bool parse(cl::Option &O, StringRef ArgName, StringRef Arg,
unsigned &
Value) {
78 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
81 return O.error(
"'" + Arg +
"' value must be in the range [0, 255]!");
95 cl::desc(
"Value to pass to hot/cold operator new for cold allocation"));
98 cl::desc(
"Value to pass to hot/cold operator new for "
99 "notcold (warm) allocation"));
102 cl::desc(
"Value to pass to hot/cold operator new for hot allocation"));
106 "Value to pass to hot/cold operator new for ambiguous allocation"));
113 return Func == LibFunc_abs || Func == LibFunc_labs ||
114 Func == LibFunc_llabs || Func == LibFunc_strlen;
121 if (IC->isEquality() && IC->getOperand(1) == With)
131 return OI->getType()->isFloatingPointTy();
137 return OI->getType()->isFP128Ty();
170 bool Negate = Str[0] ==
'-';
171 if (Str[0] ==
'-' || Str[0] ==
'+') {
172 Str = Str.drop_front();
183 uint64_t Max = AsSigned && Negate ? 1 : 0;
187 if (Str.size() > 1) {
189 if (
toUpper((
unsigned char)Str[1]) ==
'X') {
190 if (Str.size() == 2 || (
Base &&
Base != 16))
195 Str = Str.drop_front(2);
201 }
else if (
Base == 0)
211 for (
unsigned i = 0; i != Str.size(); ++i) {
212 unsigned char DigVal = Str[i];
214 DigVal = DigVal -
'0';
218 DigVal = DigVal -
'A' + 10;
231 if (VFlow || Result > Max)
239 Value *StrEnd =
B.CreateInBoundsGEP(
B.getInt8Ty(), StrBeg, Off,
"endptr");
240 B.CreateStore(StrEnd, EndPtr);
251 return ConstantInt::get(RetTy, Result, AsSigned);
258 if (
C->isNullValue())
286 for (
unsigned ArgNo : ArgNos) {
287 uint64_t DerefBytes = DereferenceableBytes;
292 DereferenceableBytes);
311 for (
unsigned ArgNo : ArgNos) {
337 DerefMin = std::min(
X,
Y);
358 NewCI->
getContext(), {NewCI->getAttributes(), Old.getAttributes()}));
371 return Len >= Str.size() ? Str : Str.substr(0, Len);
396 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, Len,
B));
399Value *LibCallSimplifier::emitStrLenMemCpy(
Value *Src,
Value *Dst, uint64_t Len,
410 Value *CpyDst =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, DstLen,
"endptr");
415 TLI->getAsSizeT(Len + 1, *
B.GetInsertBlock()->getModule()));
459 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, SrcLen,
B));
472 Type *CharTy =
B.getInt8Ty();
473 Value *Char0 =
B.CreateLoad(CharTy, Src);
474 CharVal =
B.CreateTrunc(CharVal, CharTy);
475 Value *Cmp =
B.CreateICmpEQ(Char0, CharVal,
"char0cmp");
479 Value *
And =
B.CreateICmpNE(NBytes, Zero);
480 Cmp =
B.CreateLogicalAnd(
And, Cmp);
484 return B.CreateSelect(Cmp, Src, NullPtr);
506 FunctionType *FT =
Callee->getFunctionType();
507 unsigned IntBits = TLI->getIntSize();
508 if (!FT->getParamType(1)->isIntegerTy(IntBits))
511 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
515 ConstantInt::get(SizeTTy, Len),
B,
524 return B.CreateIntToPtr(
B.getTrue(), CI->
getType());
533 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, StrLen,
"strchr");
546 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(
I),
"strchr");
558 if (CharC && CharC->
isZero())
563 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
568 uint64_t NBytes = Str.size() + 1;
569 Value *
Size = ConstantInt::get(SizeTTy, NBytes);
576 return ConstantInt::get(CI->
getType(), 0);
578 StringRef Str1, Str2;
583 if (HasStr1 && HasStr2)
585 std::clamp(Str1.
compare(Str2), -1, 1));
587 if (HasStr1 && Str1.
empty())
588 return B.CreateNeg(
B.CreateZExt(
589 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
591 if (HasStr2 && Str2.
empty())
592 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
606 TLI->getAsSizeT(std::min(Len1, Len2), *CI->
getModule()),
611 SimplifyQuery SQ(DL, TLI, DT, AC, CI);
612 if (!HasStr1 && HasStr2) {
617 }
else if (HasStr1 && !HasStr2) {
639 return ConstantInt::get(CI->
getType(), 0);
651 return ConstantInt::get(CI->
getType(), 0);
656 StringRef Str1, Str2;
661 if (HasStr1 && HasStr2) {
666 std::clamp(SubStr1.
compare(SubStr2), -1, 1));
669 if (HasStr1 && Str1.
empty())
670 return B.CreateNeg(
B.CreateZExt(
671 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
673 if (HasStr2 && Str2.
empty())
674 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
685 if (!HasStr1 && HasStr2) {
686 Len2 = std::min(Len2,
Length);
691 }
else if (HasStr1 && !HasStr2) {
692 Len1 = std::min(Len1,
Length);
706 if (SrcLen &&
Size) {
708 if (SrcLen <= Size->getZExtValue() + 1)
730 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
745 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
756 Value *DstEnd =
B.CreateInBoundsGEP(
757 B.getInt8Ty(), Dst, TLI->getAsSizeT(Len - 1, *CI->
getModule()));
761 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1), LenV);
780 NBytes = SizeC->getZExtValue();
789 B.CreateStore(
B.getInt8(0), Dst);
802 uint64_t SrcLen = Str.find(
'\0');
805 bool NulTerm = SrcLen < NBytes;
814 SrcLen = std::min(SrcLen, uint64_t(Str.size()));
815 NBytes = std::min(NBytes - 1, SrcLen);
820 B.CreateStore(
B.getInt8(0), Dst);
821 return ConstantInt::get(CI->
getType(), 0);
827 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
828 TLI->getAsSizeT(NBytes, *CI->
getModule()));
832 Value *EndOff = ConstantInt::get(CI->
getType(), NBytes);
833 Value *EndPtr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, EndOff);
834 B.CreateStore(
B.getInt8(0), EndPtr);
840 return ConstantInt::get(CI->
getType(), SrcLen);
845Value *LibCallSimplifier::optimizeStringNCpy(
CallInst *CI,
bool RetEnd,
862 N = SizeC->getZExtValue();
869 Type *CharTy =
B.getInt8Ty();
870 Value *CharVal =
B.CreateLoad(CharTy, Src,
"stxncpy.char0");
871 B.CreateStore(CharVal, Dst);
877 Value *ZeroChar = ConstantInt::get(CharTy, 0);
878 Value *
Cmp =
B.CreateICmpEQ(CharVal, ZeroChar,
"stpncpy.char0cmp");
880 Value *Off1 =
B.getInt32(1);
881 Value *EndPtr =
B.CreateInBoundsGEP(CharTy, Dst, Off1,
"stpncpy.end");
882 return B.CreateSelect(Cmp, Dst, EndPtr,
"stpncpy.sel");
897 CI->
getAttributes().getParamAttrs(0).getAlignment().valueOrOne();
898 CallInst *NewCI =
B.CreateMemSet(Dst,
B.getInt8(
'\0'),
Size, MemSetAlign);
906 if (
N > SrcLen + 1) {
915 std::string SrcStr = Str.str();
918 SrcStr.resize(
N,
'\0');
919 Src =
B.CreateGlobalString(SrcStr,
"str", 0,
925 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
934 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, Off,
"endptr");
951 return B.CreateZExt(
B.CreateLoad(CharTy, Src,
"char0"),
957 if (BoundCst->isZero())
959 return ConstantInt::get(CI->
getType(), 0);
961 if (BoundCst->isOne()) {
963 Value *CharVal =
B.CreateLoad(CharTy, Src,
"strnlen.char0");
964 Value *ZeroChar = ConstantInt::get(CharTy, 0);
965 Value *
Cmp =
B.CreateICmpNE(CharVal, ZeroChar,
"strnlen.char0cmp");
966 return B.CreateZExt(Cmp, CI->
getType());
976 return B.CreateBinaryIntrinsic(Intrinsic::umin, LenC, Bound);
993 unsigned BW = DL.getIndexTypeSizeInBits(
GEP->getType());
994 SmallMapVector<Value *, APInt, 4> VarOffsets;
995 APInt ConstOffset(BW, 0);
996 assert(CharSize % 8 == 0 &&
"Expected a multiple of 8 sized CharSize");
998 if (!
GEP->collectOffset(DL, BW, VarOffsets, ConstOffset) ||
999 VarOffsets.
size() != 1 || ConstOffset != 0 ||
1000 VarOffsets.
begin()->second != CharSize / 8)
1003 ConstantDataArraySlice Slice;
1005 uint64_t NullTermIdx;
1006 if (Slice.
Array ==
nullptr) {
1009 NullTermIdx = ~((uint64_t)0);
1010 for (uint64_t
I = 0,
E = Slice.
Length;
I <
E; ++
I) {
1018 if (NullTermIdx == ~((uint64_t)0))
1029 if ((
Known.isNonNegative() &&
Known.getMaxValue().ule(NullTermIdx)) ||
1031 NullTermIdx == Slice.
Length - 1)) {
1033 return B.CreateSub(ConstantInt::get(CI->
getType(), NullTermIdx),
1043 if (LenTrue && LenFalse) {
1045 return OptimizationRemark(
"instcombine",
"simplify-libcalls", CI)
1046 <<
"folded strlen(select) to select of constants";
1048 return B.CreateSelect(
SI->getCondition(),
1049 ConstantInt::get(CI->
getType(), LenTrue - 1),
1050 ConstantInt::get(CI->
getType(), LenFalse - 1));
1058 if (
Value *V = optimizeStringLength(CI,
B, 8))
1066 if (
Value *V = optimizeStringLength(CI,
B, 8, Bound))
1076 unsigned WCharSize = TLI->getWCharSize(M) * 8;
1081 return optimizeStringLength(CI,
B, WCharSize);
1091 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1095 if (HasS1 && HasS2) {
1096 size_t I =
S1.find_first_of(S2);
1101 B.getInt64(
I),
"strpbrk");
1105 if (HasS2 && S2.
size() == 1)
1130 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1134 if (HasS1 && HasS2) {
1135 size_t Pos =
S1.find_first_not_of(S2);
1138 return ConstantInt::get(CI->
getType(), Pos);
1150 if (HasS1 &&
S1.empty())
1154 if (HasS1 && HasS2) {
1155 size_t Pos =
S1.find_first_of(S2);
1158 return ConstantInt::get(CI->
getType(), Pos);
1162 if (HasS2 && S2.
empty())
1179 StrLen,
B, DL, TLI);
1187 replaceAllUsesWith(Old, Cmp);
1193 StringRef SearchStr, ToFindStr;
1198 if (HasStr2 && ToFindStr.
empty())
1202 if (HasStr1 && HasStr2) {
1209 return B.CreateConstInBoundsGEP1_64(
B.getInt8Ty(), CI->
getArgOperand(0),
1214 if (HasStr2 && ToFindStr.
size() == 1) {
1235 if (LenC->
isOne()) {
1238 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memrchr.char0");
1240 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1241 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memrchr.char0cmp");
1242 return B.CreateSelect(Cmp, SrcStr, NullPtr,
"memrchr.sel");
1250 if (Str.size() == 0)
1259 if (Str.size() < EndOff)
1274 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos));
1276 if (Str.find(Str[Pos]) == Pos) {
1283 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
1284 B.getInt64(Pos),
"memrchr.ptr_plus");
1285 return B.CreateSelect(Cmp, NullPtr, SrcPlus,
"memrchr.sel");
1290 Str = Str.substr(0, EndOff);
1298 Type *Int8Ty =
B.getInt8Ty();
1299 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1301 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1302 Value *CEqS0 =
B.CreateICmpEQ(ConstantInt::get(Int8Ty, Str[0]), CharVal);
1303 Value *
And =
B.CreateLogicalAnd(NNeZ, CEqS0);
1304 Value *SizeM1 =
B.CreateSub(
Size, ConstantInt::get(SizeTy, 1));
1306 B.CreateInBoundsGEP(Int8Ty, SrcStr, SizeM1,
"memrchr.ptr_plus");
1307 return B.CreateSelect(
And, SrcPlus, NullPtr,
"memrchr.sel");
1330 if (LenC->
isOne()) {
1333 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memchr.char0");
1335 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1336 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memchr.char0cmp");
1337 return B.CreateSelect(Cmp, SrcStr, NullPtr,
"memchr.sel");
1357 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos),
1359 return B.CreateSelect(Cmp, NullPtr, SrcPlus);
1362 if (Str.size() == 0)
1371 size_t Pos = Str.find_first_not_of(Str[0]);
1387 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1389 Value *Sel1 = NullPtr;
1392 Value *PosVal = ConstantInt::get(SizeTy, Pos);
1393 Value *StrPos = ConstantInt::get(Int8Ty, Str[Pos]);
1394 Value *CEqSPos =
B.CreateICmpEQ(CharVal, StrPos);
1396 Value *
And =
B.CreateAnd(CEqSPos, NGtPos);
1397 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, PosVal);
1398 Sel1 =
B.CreateSelect(
And, SrcPlus, NullPtr,
"memchr.sel1");
1401 Value *Str0 = ConstantInt::get(Int8Ty, Str[0]);
1402 Value *CEqS0 =
B.CreateICmpEQ(Str0, CharVal);
1403 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1405 return B.CreateSelect(
And, SrcStr, Sel1,
"memchr.sel2");
1436 *std::max_element(
reinterpret_cast<const unsigned char *
>(Str.begin()),
1437 reinterpret_cast<const unsigned char *
>(Str.end()));
1444 if (!DL.fitsInLegalInteger(Max + 1)) {
1450 std::string SortedStr = Str.str();
1453 unsigned NonContRanges = 1;
1454 for (
size_t i = 1; i < SortedStr.size(); ++i) {
1455 if (SortedStr[i] > SortedStr[i - 1] + 1) {
1462 if (NonContRanges > 2)
1466 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1469 for (
unsigned char C : SortedStr)
1470 CharCompares.
push_back(
B.CreateICmpEQ(CharVal,
B.getInt8(
C)));
1472 return B.CreateIntToPtr(
B.CreateOr(CharCompares), CI->
getType());
1477 unsigned char Width =
NextPowerOf2(std::max((
unsigned char)7, Max));
1483 Value *BitfieldC =
B.getInt(Bitfield);
1487 C =
B.CreateAnd(
C,
B.getIntN(Width, 0xFF));
1494 Value *Shl =
B.CreateShl(
B.getIntN(Width, 1ULL),
C);
1495 Value *
Bits =
B.CreateIsNotNull(
B.CreateAnd(Shl, BitfieldC),
"memchr.bits");
1499 return B.CreateIntToPtr(
B.CreateLogicalAnd(Bounds, Bits,
"memchr"),
1524 if (Pos == MinSize ||
1525 (StrNCmp && (LStr[Pos] ==
'\0' && RStr[Pos] ==
'\0'))) {
1533 if (LStr[Pos] != RStr[Pos])
1538 typedef unsigned char UChar;
1539 int IRes = UChar(LStr[Pos]) < UChar(RStr[Pos]) ? -1 : 1;
1540 Value *MaxSize = ConstantInt::get(
Size->getType(), Pos);
1543 return B.CreateSelect(Cmp, Zero, Res);
1555 Value *LHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
LHS,
"lhsc"),
1557 Value *RHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
RHS,
"rhsc"),
1559 return B.CreateSub(LHSV, RHSV,
"chardiff");
1567 Align PrefAlignment =
DL.getPrefTypeAlign(IntType);
1570 Value *LHSV =
nullptr;
1574 Value *RHSV =
nullptr;
1583 LHSV =
B.CreateLoad(IntType,
LHS,
"lhsv");
1585 RHSV =
B.CreateLoad(IntType,
RHS,
"rhsv");
1586 return B.CreateZExt(
B.CreateICmpNE(LHSV, RHSV), CI->
getType(),
"memcmp");
1594Value *LibCallSimplifier::optimizeMemCmpBCmpCommon(
CallInst *CI,
1614 if (
Value *V = optimizeMemCmpBCmpCommon(CI,
B))
1632 return optimizeMemCmpBCmpCommon(CI,
B);
1658 if (
N->isNullValue())
1671 if (
N->getZExtValue() <= SrcStr.
size()) {
1680 ConstantInt::get(
N->getType(), std::min(uint64_t(Pos + 1),
N->getZExtValue()));
1683 return Pos + 1 <=
N->getZExtValue()
1684 ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, NewN)
1698 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
N);
1731 if (MDNode *MD = CI->
getMetadata(LLVMContext::MD_alloc_token))
1732 MallocCI->setMetadata(LLVMContext::MD_alloc_token, MD);
1741Value *LibCallSimplifier::maybeOptimizeNoBuiltinOperatorNew(
CallInst *CI,
1749 if (!TLI->getLibFunc(*Callee, Func))
1753 case LibFunc_ZnwmRKSt9nothrow_t:
1754 case LibFunc_ZnwmSt11align_val_t:
1755 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1757 case LibFunc_ZnamRKSt9nothrow_t:
1758 case LibFunc_ZnamSt11align_val_t:
1759 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1760 case LibFunc_size_returning_new:
1761 case LibFunc_size_returning_new_aligned:
1768 case LibFunc_Znwm12__hot_cold_t:
1769 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1770 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1771 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1772 case LibFunc_Znam12__hot_cold_t:
1773 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1774 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1775 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1776 case LibFunc_size_returning_new_hot_cold:
1777 case LibFunc_size_returning_new_aligned_hot_cold:
1786 return optimizeNew(CI,
B, Func);
1799 if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"cold")
1801 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1804 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"hot")
1806 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1819 Value *NewCall =
nullptr;
1821 case LibFunc_Znwm12__hot_cold_t:
1824 LibFunc_Znwm12__hot_cold_t, HotCold);
1828 LibFunc_Znwm12__hot_cold_t, HotCold);
1830 case LibFunc_Znam12__hot_cold_t:
1833 LibFunc_Znam12__hot_cold_t, HotCold);
1837 LibFunc_Znam12__hot_cold_t, HotCold);
1839 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1843 LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
1845 case LibFunc_ZnwmRKSt9nothrow_t:
1848 LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotCold);
1850 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1854 LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
1856 case LibFunc_ZnamRKSt9nothrow_t:
1859 LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotCold);
1861 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1865 LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
1867 case LibFunc_ZnwmSt11align_val_t:
1870 LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotCold);
1872 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1876 LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
1878 case LibFunc_ZnamSt11align_val_t:
1881 LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotCold);
1883 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1887 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1890 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1893 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
1895 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1899 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1902 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1905 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t, HotCold);
1907 case LibFunc_size_returning_new:
1909 LibFunc_size_returning_new_hot_cold,
1912 case LibFunc_size_returning_new_hot_cold:
1915 LibFunc_size_returning_new_hot_cold,
1918 case LibFunc_size_returning_new_aligned:
1921 LibFunc_size_returning_new_aligned_hot_cold, HotCold);
1923 case LibFunc_size_returning_new_aligned_hot_cold:
1927 LibFunc_size_returning_new_aligned_hot_cold, HotCold);
1966 Value *
Op = Cast->getOperand(0);
1967 if (
Op->getType()->isFloatTy())
1976 return ConstantFP::get(Const->getContext(),
F);
1984 bool isPrecise =
false) {
2016 CallerName.
size() == (CalleeName.
size() + 1) &&
2029 R =
isBinary ?
B.CreateIntrinsic(IID,
B.getFloatTy(), V)
2030 :
B.CreateIntrinsic(IID,
B.getFloatTy(), V[0]);
2038 return B.CreateFPExt(R,
B.getDoubleTy());
2044 bool isPrecise =
false) {
2051 bool isPrecise =
false) {
2065 assert(
Op->getType()->isArrayTy() &&
"Unexpected signature for cabs!");
2067 Real =
B.CreateExtractValue(
Op, 0,
"real");
2068 Imag =
B.CreateExtractValue(
Op, 1,
"imag");
2078 Value *AbsOp =
nullptr;
2080 if (ConstReal->isZero())
2084 if (ConstImag->isZero())
2089 return copyFlags(*CI,
B.CreateFAbs(AbsOp, CI,
"cabs"));
2096 Value *RealReal =
B.CreateFMulFMF(Real, Real, CI);
2097 Value *ImagImag =
B.CreateFMulFMF(Imag, Imag, CI);
2099 *CI,
B.CreateUnaryIntrinsic(Intrinsic::sqrt,
2100 B.CreateFAddFMF(RealReal, ImagImag, CI), CI,
2111 unsigned BitWidth =
Op->getType()->getScalarSizeInBits();
2113 Type *IntTy =
Op->getType()->getWithNewBitWidth(DstWidth);
2115 :
B.CreateZExt(
Op, IntTy);
2151 if (CalleeFn && TLI->getLibFunc(CalleeFn->
getName(), LibFn) &&
2156 LibFunc LibFnFloat, LibFnDouble, LibFnLongDouble;
2164 ExpName = TLI->getName(LibFunc_exp);
2165 ID = Intrinsic::exp;
2166 LibFnFloat = LibFunc_expf;
2167 LibFnDouble = LibFunc_exp;
2168 LibFnLongDouble = LibFunc_expl;
2173 ExpName = TLI->getName(LibFunc_exp2);
2174 ID = Intrinsic::exp2;
2175 LibFnFloat = LibFunc_exp2f;
2176 LibFnDouble = LibFunc_exp2;
2177 LibFnLongDouble = LibFunc_exp2l;
2184 ?
B.CreateUnaryIntrinsic(ID,
FMul,
nullptr, ExpName)
2193 substituteInParent(BaseFn, ExpFn);
2204 AttributeList NoAttrs;
2206 const bool UseIntrinsic =
Pow->doesNotAccessMemory();
2212 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2217 Constant *One = ConstantFP::get(Ty, 1.0);
2221 {Ty, ExpoI->getType()},
2222 {One, ExpoI},
Pow,
"exp2"));
2226 One, ExpoI, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2227 LibFunc_ldexpl,
B, NoAttrs));
2232 if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f, LibFunc_exp2l)) {
2235 BaseR = BaseR / *BaseF;
2237 const APFloat *NF = IsReciprocal ? &BaseR : BaseF;
2239 if ((IsInteger || IsReciprocal) &&
2242 NI > 1 && NI.isPowerOf2()) {
2243 double N = NI.logBase2() * (IsReciprocal ? -1.0 : 1.0);
2244 Value *
FMul =
B.CreateFMul(Expo, ConstantFP::get(Ty,
N),
"mul");
2245 if (
Pow->doesNotAccessMemory())
2251 LibFunc_exp2l,
B, NoAttrs));
2257 hasFloatFn(M, TLI, Ty, LibFunc_exp10, LibFunc_exp10f, LibFunc_exp10l)) {
2259 if (
Pow->doesNotAccessMemory()) {
2260 return B.CreateIntrinsic(Intrinsic::exp10, {Ty}, {Expo},
Pow,
"exp10", {},
2265 LibFunc_exp10f, LibFunc_exp10l,
2275 "pow(1.0, y) should have been simplified earlier!");
2284 Value *
FMul =
B.CreateFMul(Log, Expo,
"mul");
2285 if (
Pow->doesNotAccessMemory())
2288 else if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f,
2292 LibFunc_exp2l,
B, NoAttrs));
2304 return B.CreateUnaryIntrinsic(Intrinsic::sqrt, V,
nullptr,
"sqrt");
2307 if (
hasFloatFn(M, TLI, V->getType(), LibFunc_sqrt, LibFunc_sqrtf,
2313 LibFunc_sqrtl,
B, Attrs);
2320 Value *Sqrt, *
Base =
Pow->getArgOperand(0), *Expo =
Pow->getArgOperand(1);
2331 if (ExpoF->
isNegative() && (!
Pow->hasApproxFunc() && !
Pow->hasAllowReassoc()))
2338 if (!
Pow->doesNotAccessMemory() && !
Pow->hasNoInfs() &&
2340 Base, SimplifyQuery(DL, TLI, DT, AC,
Pow,
true,
true, DC)))
2349 if (!
Pow->hasNoSignedZeros())
2350 Sqrt =
B.CreateFAbs(Sqrt,
nullptr,
"abs");
2356 if (!
Pow->hasNoInfs()) {
2359 Value *FCmp =
B.CreateFCmpOEQ(
Base, NegInf,
"isinf");
2360 Sqrt =
B.CreateSelect(FCmp, PosInf, Sqrt);
2365 Sqrt =
B.CreateFDiv(ConstantFP::get(Ty, 1.0), Sqrt,
"reciprocal");
2374 return B.CreateIntrinsic(Intrinsic::powi, Types, Args);
2379 Value *Expo =
Pow->getArgOperand(1);
2384 bool AllowApprox =
Pow->hasApproxFunc();
2388 IRBuilderBase::FastMathFlagGuard Guard(
B);
2389 B.setFastMathFlags(
Pow->getFastMathFlags());
2396 if (
Value *Exp = replacePowWithExp(
Pow,
B))
2403 return B.CreateFDiv(ConstantFP::get(Ty, 1.0),
Base,
"reciprocal");
2407 return ConstantFP::get(Ty, 1.0);
2415 return B.CreateFMul(
Base,
Base,
"square");
2417 if (
Value *Sqrt = replacePowWithSqrt(
Pow,
B))
2428 Value *Sqrt =
nullptr;
2429 if (!ExpoA.isInteger()) {
2443 if (!ExpoI.isInteger())
2455 APSInt IntExpo(TLI->getIntSize(),
false);
2462 Base, ConstantInt::get(
B.getIntNTy(TLI->getIntSize()), IntExpo),
2466 return B.CreateFMul(PowI, Sqrt);
2480 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) &&
2481 hasFloatVersion(M, Name)) {
2493 Value *Ret =
nullptr;
2494 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_exp2) &&
2495 hasFloatVersion(M, Name))
2504 const bool UseIntrinsic =
Callee->isIntrinsic();
2515 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2517 Constant *One = ConstantFP::get(Ty, 1.0);
2520 return copyFlags(*CI,
B.CreateIntrinsic(Intrinsic::ldexp,
2521 {Ty, Exp->getType()},
2525 IRBuilderBase::FastMathFlagGuard Guard(
B);
2528 One, Exp, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2529 LibFunc_ldexpl,
B, AttributeList()));
2553 StringRef LogNm = LogFn->
getName();
2558 if (UnsafeFPShrink && hasFloatVersion(
Mod, LogNm))
2562 LibFunc LogLb, ExpLb, Exp2Lb, Exp10Lb, PowLb;
2565 if (TLI->getLibFunc(LogNm, LogLb)) {
2568 LogID = Intrinsic::log;
2569 ExpLb = LibFunc_expf;
2570 Exp2Lb = LibFunc_exp2f;
2571 Exp10Lb = LibFunc_exp10f;
2572 PowLb = LibFunc_powf;
2575 LogID = Intrinsic::log;
2576 ExpLb = LibFunc_exp;
2577 Exp2Lb = LibFunc_exp2;
2578 Exp10Lb = LibFunc_exp10;
2579 PowLb = LibFunc_pow;
2582 LogID = Intrinsic::log;
2583 ExpLb = LibFunc_expl;
2584 Exp2Lb = LibFunc_exp2l;
2585 Exp10Lb = LibFunc_exp10l;
2586 PowLb = LibFunc_powl;
2589 LogID = Intrinsic::log2;
2590 ExpLb = LibFunc_expf;
2591 Exp2Lb = LibFunc_exp2f;
2592 Exp10Lb = LibFunc_exp10f;
2593 PowLb = LibFunc_powf;
2596 LogID = Intrinsic::log2;
2597 ExpLb = LibFunc_exp;
2598 Exp2Lb = LibFunc_exp2;
2599 Exp10Lb = LibFunc_exp10;
2600 PowLb = LibFunc_pow;
2603 LogID = Intrinsic::log2;
2604 ExpLb = LibFunc_expl;
2605 Exp2Lb = LibFunc_exp2l;
2606 Exp10Lb = LibFunc_exp10l;
2607 PowLb = LibFunc_powl;
2609 case LibFunc_log10f:
2610 LogID = Intrinsic::log10;
2611 ExpLb = LibFunc_expf;
2612 Exp2Lb = LibFunc_exp2f;
2613 Exp10Lb = LibFunc_exp10f;
2614 PowLb = LibFunc_powf;
2617 LogID = Intrinsic::log10;
2618 ExpLb = LibFunc_exp;
2619 Exp2Lb = LibFunc_exp2;
2620 Exp10Lb = LibFunc_exp10;
2621 PowLb = LibFunc_pow;
2623 case LibFunc_log10l:
2624 LogID = Intrinsic::log10;
2625 ExpLb = LibFunc_expl;
2626 Exp2Lb = LibFunc_exp2l;
2627 Exp10Lb = LibFunc_exp10l;
2628 PowLb = LibFunc_powl;
2635 bool IsKnownNoErrno =
Log->hasNoNaNs() &&
Log->hasNoInfs();
2636 if (!IsKnownNoErrno) {
2637 SimplifyQuery SQ(DL, TLI, DT, AC, Log,
true,
true, DC);
2644 Known.cannotBeOrderedLessThanZero() &&
2645 Known.isKnownNeverLogicalZero(
F->getDenormalMode(FltSem));
2647 if (IsKnownNoErrno) {
2648 Value *NewLog =
B.CreateUnaryIntrinsic(LogID,
Log->getArgOperand(0), Log);
2650 I->copyMetadata(*Log);
2655 }
else if (LogID == Intrinsic::log || LogID == Intrinsic::log2 ||
2656 LogID == Intrinsic::log10) {
2658 ExpLb = LibFunc_expf;
2659 Exp2Lb = LibFunc_exp2f;
2660 Exp10Lb = LibFunc_exp10f;
2661 PowLb = LibFunc_powf;
2663 ExpLb = LibFunc_exp;
2664 Exp2Lb = LibFunc_exp2;
2665 Exp10Lb = LibFunc_exp10;
2666 PowLb = LibFunc_pow;
2677 IRBuilderBase::FastMathFlagGuard Guard(
B);
2681 LibFunc ArgLb = NotLibFunc;
2682 TLI->getLibFunc(*Arg, ArgLb);
2685 AttributeList NoAttrs;
2686 if (ArgLb == PowLb || ArgID == Intrinsic::pow || ArgID == Intrinsic::powi) {
2688 Log->doesNotAccessMemory()
2689 ?
B.CreateUnaryIntrinsic(LogID, Arg->
getOperand(0),
nullptr,
"log")
2693 if (ArgID == Intrinsic::powi)
2694 Y =
B.CreateSIToFP(
Y, Ty,
"cast");
2695 Value *MulY =
B.CreateFMul(
Y, LogX,
"mul");
2698 substituteInParent(Arg, MulY);
2704 if (ArgLb == ExpLb || ArgLb == Exp2Lb || ArgLb == Exp10Lb ||
2705 ArgID == Intrinsic::exp || ArgID == Intrinsic::exp2) {
2707 if (ArgLb == ExpLb || ArgID == Intrinsic::exp)
2710 else if (ArgLb == Exp2Lb || ArgID == Intrinsic::exp2)
2711 Eul = ConstantFP::get(
Log->getType(), 2.0);
2713 Eul = ConstantFP::get(
Log->getType(), 10.0);
2714 Value *LogE =
Log->doesNotAccessMemory()
2715 ?
B.CreateUnaryIntrinsic(LogID, Eul,
nullptr,
"log")
2720 substituteInParent(Arg, MulY);
2737 LibFunc ArgLb = NotLibFunc;
2738 TLI->getLibFunc(*Arg, ArgLb);
2740 LibFunc SqrtLb, ExpLb, Exp2Lb, Exp10Lb;
2742 if (TLI->getLibFunc(SqrtFn->
getName(), SqrtLb))
2745 ExpLb = LibFunc_expf;
2746 Exp2Lb = LibFunc_exp2f;
2747 Exp10Lb = LibFunc_exp10f;
2750 ExpLb = LibFunc_exp;
2751 Exp2Lb = LibFunc_exp2;
2752 Exp10Lb = LibFunc_exp10;
2755 ExpLb = LibFunc_expl;
2756 Exp2Lb = LibFunc_exp2l;
2757 Exp10Lb = LibFunc_exp10l;
2764 ExpLb = LibFunc_expf;
2765 Exp2Lb = LibFunc_exp2f;
2766 Exp10Lb = LibFunc_exp10f;
2768 ExpLb = LibFunc_exp;
2769 Exp2Lb = LibFunc_exp2;
2770 Exp10Lb = LibFunc_exp10;
2776 if (ArgLb != ExpLb && ArgLb != Exp2Lb && ArgLb != Exp10Lb &&
2777 ArgID != Intrinsic::exp && ArgID != Intrinsic::exp2)
2780 IRBuilderBase::InsertPointGuard Guard(
B);
2781 B.SetInsertPoint(Arg);
2784 B.CreateFMulFMF(ExpOperand, ConstantFP::get(ExpOperand->getType(), 0.5),
2794 Value *Ret =
nullptr;
2799 (
Callee->getName() ==
"sqrt" ||
2800 Callee->getIntrinsicID() == Intrinsic::sqrt))
2803 if (
Value *Opt = mergeSqrtToExp(CI,
B))
2810 if (!
I ||
I->getOpcode() != Instruction::FMul || !
I->isFast())
2816 Value *Op0 =
I->getOperand(0);
2817 Value *Op1 =
I->getOperand(1);
2818 Value *RepeatOp =
nullptr;
2819 Value *OtherOp =
nullptr;
2850 Value *FabsCall =
B.CreateFAbs(RepeatOp,
I,
"fabs");
2856 B.CreateUnaryIntrinsic(Intrinsic::sqrt, OtherOp,
I,
"sqrt");
2857 return copyFlags(*CI,
B.CreateFMulFMF(FabsCall, SqrtCall,
I));
2868 SimplifyQuery SQ(DL, TLI, DT, AC, CI,
true,
true, DC);
2871 KnownFPClass Known1 =
2874 const fltSemantics &FltSem =
2885Value *LibCallSimplifier::optimizeTrigInversionPairs(
CallInst *CI,
2889 Value *Ret =
nullptr;
2891 if (UnsafeFPShrink &&
2892 (Name ==
"tan" || Name ==
"atanh" || Name ==
"sinh" || Name ==
"cosh" ||
2894 hasFloatVersion(M, Name))
2903 if (!CI->
isFast() || !OpC->isFast())
2913 if (
F && TLI->getLibFunc(
F->getName(), Func) &&
2915 LibFunc inverseFunc = llvm::StringSwitch<LibFunc>(
Callee->getName())
2916 .Case(
"tan", LibFunc_atan)
2917 .Case(
"atanh", LibFunc_tanh)
2918 .Case(
"sinh", LibFunc_asinh)
2919 .Case(
"cosh", LibFunc_acosh)
2920 .Case(
"tanf", LibFunc_atanf)
2921 .Case(
"atanhf", LibFunc_tanhf)
2922 .Case(
"sinhf", LibFunc_asinhf)
2923 .Case(
"coshf", LibFunc_acoshf)
2924 .Case(
"tanl", LibFunc_atanl)
2925 .Case(
"atanhl", LibFunc_tanhl)
2926 .Case(
"sinhl", LibFunc_asinhl)
2927 .Case(
"coshl", LibFunc_acoshl)
2928 .Case(
"asinh", LibFunc_sinh)
2929 .Case(
"asinhf", LibFunc_sinhf)
2930 .Case(
"asinhl", LibFunc_sinhl)
2931 .Default(NotLibFunc);
2932 if (Func == inverseFunc)
2933 Ret = OpC->getArgOperand(0);
2955 Name =
"__sincospif_stret";
2964 Name =
"__sincospi_stret";
2973 M, *TLI, TheLibFunc, OrigCallee->
getAttributes(), ResTy, ArgTy);
2978 B.SetInsertPoint(ArgInst->getParent(), ++ArgInst->getIterator());
2982 BasicBlock &EntryBB =
B.GetInsertBlock()->getParent()->getEntryBlock();
2983 B.SetInsertPoint(&EntryBB, EntryBB.
begin());
2986 SinCos =
B.CreateCall(Callee, Arg,
"sincospi");
2989 Sin =
B.CreateExtractValue(SinCos, 0,
"sinpi");
2990 Cos =
B.CreateExtractValue(SinCos, 1,
"cospi");
2992 Sin =
B.CreateExtractElement(SinCos,
uint64_t{0},
"sinpi");
2993 Cos =
B.CreateExtractElement(SinCos,
uint64_t{1},
"cospi");
3025Value *LibCallSimplifier::optimizeSymmetric(
CallInst *CI, LibFunc Func,
3083 for (User *U : Arg->
users())
3084 classifyArgUse(U,
F, IsFloat, SinCalls, CosCalls, SinCosCalls);
3090 Value *Sin, *Cos, *SinCos;
3095 auto replaceTrigInsts = [
this](SmallVectorImpl<CallInst *> &Calls,
3097 for (CallInst *
C : Calls)
3098 replaceAllUsesWith(
C, Res);
3101 replaceTrigInsts(SinCalls, Sin);
3102 replaceTrigInsts(CosCalls, Cos);
3103 replaceTrigInsts(SinCosCalls, SinCos);
3105 return IsSin ? Sin : Cos;
3108void LibCallSimplifier::classifyArgUse(
3124 if (!Callee || !TLI->getLibFunc(*Callee, Func) ||
3130 if (Func == LibFunc_sinpif)
3132 else if (Func == LibFunc_cospif)
3134 else if (Func == LibFunc_sincospif_stret)
3137 if (Func == LibFunc_sinpi)
3139 else if (Func == LibFunc_cospi)
3141 else if (Func == LibFunc_sincospi_stret)
3163 unsigned IntBW = TLI->getIntSize();
3164 APSInt QuotInt(IntBW,
false);
3171 B.CreateAlignedStore(
3174 return ConstantFP::get(CI->
getType(), Rem);
3201 return ConstantFP::get(CI->
getType(), Difference);
3213 Type *ArgType =
Op->getType();
3214 Value *
V =
B.CreateIntrinsic(Intrinsic::cttz, {ArgType}, {
Op,
B.getTrue()},
3216 V =
B.CreateAdd(V, ConstantInt::get(
V->getType(), 1));
3217 V =
B.CreateIntCast(V, RetType,
false);
3220 return B.CreateSelect(
Cond, V, ConstantInt::get(RetType, 0));
3227 Type *ArgType =
Op->getType();
3228 Value *
V =
B.CreateIntrinsic(Intrinsic::ctlz, {ArgType}, {
Op,
B.getFalse()},
3232 return B.CreateIntCast(V, CI->
getType(),
false);
3239 Value *IsNeg =
B.CreateIsNeg(
X);
3240 Value *NegX =
B.CreateNSWNeg(
X,
"neg");
3241 return B.CreateSelect(IsNeg, NegX,
X);
3247 Type *ArgType =
Op->getType();
3248 Op =
B.CreateSub(
Op, ConstantInt::get(ArgType,
'0'),
"isdigittmp");
3249 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 10),
"isdigit");
3256 Type *ArgType =
Op->getType();
3257 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 128),
"isascii");
3264 ConstantInt::get(CI->
getType(), 0x7F));
3294 return convertStrToInt(CI, Str, EndPtr, CInt->getSExtValue(), AsSigned,
B);
3326 if (!Callee || !Callee->isDeclaration())
3335 if (StreamArg >= (
int)CI->
arg_size())
3343 return GV->
getName() ==
"stderr";
3348 StringRef FormatStr;
3353 if (FormatStr.
empty())
3364 if (FormatStr.
size() == 1 || FormatStr ==
"%%") {
3368 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)FormatStr[0]);
3369 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3373 if (FormatStr ==
"%s" && CI->
arg_size() > 1) {
3374 StringRef OperandStr;
3375 if (!getConstantStringInfo(CI->getOperand(1), OperandStr))
3378 if (OperandStr.empty())
3381 if (OperandStr.size() == 1) {
3385 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)OperandStr[0]);
3386 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3389 if (OperandStr.back() ==
'\n') {
3390 if (!isLibFuncEmittable(CI->getModule(), TLI, LibFunc_puts))
3392 OperandStr = OperandStr.drop_back();
3393 Value *GV = B.CreateGlobalString(OperandStr,
"str");
3394 return copyFlags(*CI, emitPutS(GV, B, TLI));
3400 if (FormatStr.
back() ==
'\n' &&
3402 if (!isLibFuncEmittable(CI->getModule(), TLI, LibFunc_puts))
3406 FormatStr = FormatStr.drop_back();
3407 Value *GV = B.CreateGlobalString(FormatStr,
"str");
3408 return copyFlags(*CI, emitPutS(GV, B, TLI));
3413 if (FormatStr ==
"%c" && CI->
arg_size() > 1 &&
3417 Value *IntChar = B.CreateIntCast(CI->getArgOperand(1), IntTy, false);
3418 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3422 if (FormatStr ==
"%s\n" && CI->
arg_size() > 1 &&
3432 FunctionType *FT =
Callee->getFunctionType();
3433 if (
Value *V = optimizePrintFString(CI,
B)) {
3444 Callee->getAttributes());
3446 New->setCalledFunction(IPrintFFn);
3456 Callee->getAttributes());
3458 New->setCalledFunction(SmallPrintFFn);
3466Value *LibCallSimplifier::optimizeSPrintFString(
CallInst *CI,
3469 StringRef FormatStr;
3485 return ConstantInt::get(CI->
getType(), FormatStr.
size());
3490 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3494 if (FormatStr[1] ==
'c') {
3500 B.CreateStore(V, Ptr);
3501 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Ptr,
B.getInt32(1),
"nul");
3502 B.CreateStore(
B.getInt8(0), Ptr);
3504 return ConstantInt::get(CI->
getType(), 1);
3507 if (FormatStr[1] ==
's') {
3520 TLI->getAsSizeT(SrcLen, *CI->
getModule()));
3522 return ConstantInt::get(CI->
getType(), SrcLen - 1);
3525 Value *PtrDiff =
B.CreatePtrDiff(V, Dest);
3526 return B.CreateIntCast(PtrDiff, CI->
getType(),
false);
3537 B.CreateAdd(Len, ConstantInt::get(
Len->getType(), 1),
"leninc");
3541 return B.CreateIntCast(Len, CI->
getType(),
false);
3549 FunctionType *FT =
Callee->getFunctionType();
3550 if (
Value *V = optimizeSPrintFString(CI,
B)) {
3561 FT,
Callee->getAttributes());
3563 New->setCalledFunction(SIPrintFFn);
3573 Callee->getAttributes());
3575 New->setCalledFunction(SmallSPrintFFn);
3591 assert(StrArg || (
N < 2 && Str.size() == 1));
3593 unsigned IntBits = TLI->getIntSize();
3594 uint64_t IntMax =
maxIntN(IntBits);
3595 if (Str.size() > IntMax)
3601 Value *StrLen = ConstantInt::get(CI->
getType(), Str.size());
3611 NCopy = Str.size() + 1;
3616 if (NCopy && StrArg)
3619 TLI->getAsSizeT(NCopy, *CI->
getModule())));
3628 Value *NulOff =
B.getIntN(IntBits, NCopy);
3629 Value *DstEnd =
B.CreateInBoundsGEP(Int8Ty, DstArg, NulOff,
"endptr");
3630 B.CreateStore(ConstantInt::get(Int8Ty, 0), DstEnd);
3634Value *LibCallSimplifier::optimizeSnPrintFString(
CallInst *CI,
3641 uint64_t
N =
Size->getZExtValue();
3642 uint64_t IntMax =
maxIntN(TLI->getIntSize());
3652 StringRef FormatStr;
3663 return emitSnPrintfMemCpy(CI, FmtArg, FormatStr,
N,
B);
3668 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() != 4)
3672 if (FormatStr[1] ==
'c') {
3677 StringRef CharStr(
"*");
3678 return emitSnPrintfMemCpy(CI,
nullptr, CharStr,
N,
B);
3685 Value *Ptr = DstArg;
3686 B.CreateStore(V, Ptr);
3687 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Ptr,
B.getInt32(1),
"nul");
3688 B.CreateStore(
B.getInt8(0), Ptr);
3689 return ConstantInt::get(CI->
getType(), 1);
3692 if (FormatStr[1] !=
's')
3701 return emitSnPrintfMemCpy(CI, StrArg, Str,
N,
B);
3705 if (
Value *V = optimizeSnPrintFString(CI,
B)) {
3714Value *LibCallSimplifier::optimizeFPrintFString(
CallInst *CI,
3716 optimizeErrorReporting(CI,
B, 0);
3719 StringRef FormatStr;
3743 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3747 if (FormatStr[1] ==
'c') {
3751 Type *IntTy =
B.getIntNTy(TLI->getIntSize());
3757 if (FormatStr[1] ==
's') {
3770 FunctionType *FT =
Callee->getFunctionType();
3771 if (
Value *V = optimizeFPrintFString(CI,
B)) {
3780 FT,
Callee->getAttributes());
3782 New->setCalledFunction(FIPrintFFn);
3791 auto SmallFPrintFFn =
3793 Callee->getAttributes());
3795 New->setCalledFunction(SmallFPrintFFn);
3804 optimizeErrorReporting(CI,
B, 3);
3809 if (SizeC && CountC) {
3814 return ConstantInt::get(CI->
getType(), 0);
3821 Value *Cast =
B.CreateIntCast(Char, IntTy,
true,
"chari");
3823 return NewCI ? ConstantInt::get(CI->
getType(), 1) : nullptr;
3831 optimizeErrorReporting(CI,
B, 1);
3849 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
3854 ConstantInt::get(SizeTTy, Len - 1),
3894bool LibCallSimplifier::hasFloatVersion(
const Module *M,
StringRef FuncName) {
3895 SmallString<20> FloatFuncName = FuncName;
3896 FloatFuncName +=
'f';
3900Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
3912 "Optimizing string/memory libcall would change the calling convention");
3914 case LibFunc_strcat:
3915 return optimizeStrCat(CI, Builder);
3916 case LibFunc_strncat:
3917 return optimizeStrNCat(CI, Builder);
3918 case LibFunc_strchr:
3919 return optimizeStrChr(CI, Builder);
3920 case LibFunc_strrchr:
3921 return optimizeStrRChr(CI, Builder);
3922 case LibFunc_strcmp:
3923 return optimizeStrCmp(CI, Builder);
3924 case LibFunc_strncmp:
3925 return optimizeStrNCmp(CI, Builder);
3926 case LibFunc_strcpy:
3927 return optimizeStrCpy(CI, Builder);
3928 case LibFunc_stpcpy:
3929 return optimizeStpCpy(CI, Builder);
3930 case LibFunc_strlcpy:
3931 return optimizeStrLCpy(CI, Builder);
3932 case LibFunc_stpncpy:
3933 return optimizeStringNCpy(CI,
true, Builder);
3934 case LibFunc_strncpy:
3935 return optimizeStringNCpy(CI,
false, Builder);
3936 case LibFunc_strlen:
3937 return optimizeStrLen(CI, Builder);
3938 case LibFunc_strnlen:
3939 return optimizeStrNLen(CI, Builder);
3940 case LibFunc_strpbrk:
3941 return optimizeStrPBrk(CI, Builder);
3942 case LibFunc_strndup:
3943 return optimizeStrNDup(CI, Builder);
3944 case LibFunc_strtol:
3945 case LibFunc_strtod:
3946 case LibFunc_strtof:
3947 case LibFunc_strtoul:
3948 case LibFunc_strtoll:
3949 case LibFunc_strtold:
3950 case LibFunc_strtoull:
3951 return optimizeStrTo(CI, Builder);
3952 case LibFunc_strspn:
3953 return optimizeStrSpn(CI, Builder);
3954 case LibFunc_strcspn:
3955 return optimizeStrCSpn(CI, Builder);
3956 case LibFunc_strstr:
3957 return optimizeStrStr(CI, Builder);
3958 case LibFunc_memchr:
3959 return optimizeMemChr(CI, Builder);
3960 case LibFunc_memrchr:
3961 return optimizeMemRChr(CI, Builder);
3963 return optimizeBCmp(CI, Builder);
3964 case LibFunc_memcmp:
3965 return optimizeMemCmp(CI, Builder);
3966 case LibFunc_memcpy:
3967 return optimizeMemCpy(CI, Builder);
3968 case LibFunc_memccpy:
3969 return optimizeMemCCpy(CI, Builder);
3970 case LibFunc_mempcpy:
3971 return optimizeMemPCpy(CI, Builder);
3972 case LibFunc_memmove:
3973 return optimizeMemMove(CI, Builder);
3974 case LibFunc_memset:
3975 return optimizeMemSet(CI, Builder);
3976 case LibFunc_realloc:
3977 return optimizeRealloc(CI, Builder);
3978 case LibFunc_wcslen:
3979 return optimizeWcslen(CI, Builder);
3981 return optimizeBCopy(CI, Builder);
3983 case LibFunc_ZnwmRKSt9nothrow_t:
3984 case LibFunc_ZnwmSt11align_val_t:
3985 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
3987 case LibFunc_ZnamRKSt9nothrow_t:
3988 case LibFunc_ZnamSt11align_val_t:
3989 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
3990 case LibFunc_Znwm12__hot_cold_t:
3991 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
3992 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
3993 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
3994 case LibFunc_Znam12__hot_cold_t:
3995 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
3996 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
3997 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
3998 case LibFunc_size_returning_new:
3999 case LibFunc_size_returning_new_hot_cold:
4000 case LibFunc_size_returning_new_aligned:
4001 case LibFunc_size_returning_new_aligned_hot_cold:
4002 return optimizeNew(CI, Builder, Func);
4018 if (CharSeq.
empty())
4019 Fill =
APInt(32, 0);
4026Value *LibCallSimplifier::optimizeFloatingPointLibCall(
CallInst *CI,
4035 if (
Value *V = optimizeSymmetric(CI, Func, Builder))
4039 case LibFunc_sinpif:
4041 return optimizeSinCosPi(CI,
true, Builder);
4042 case LibFunc_cospif:
4044 return optimizeSinCosPi(CI,
false, Builder);
4058 return optimizePow(CI, Builder);
4062 return optimizeExp2(CI, Builder);
4070 return optimizeSqrt(CI, Builder);
4074 return optimizeFMod(CI, Builder);
4078 case LibFunc_log10f:
4080 case LibFunc_log10l:
4081 case LibFunc_log1pf:
4083 case LibFunc_log1pl:
4090 return optimizeLog(CI, Builder);
4098 case LibFunc_asinhf:
4099 case LibFunc_asinhl:
4104 case LibFunc_atanhf:
4105 case LibFunc_atanhl:
4106 return optimizeTrigInversionPairs(CI, Builder);
4113 case LibFunc_roundeven:
4115 case LibFunc_nearbyint:
4123 if (UnsafeFPShrink &&
4129 CI, Builder, Func == LibFunc_sin ? Intrinsic::sin : Intrinsic::cos);
4143 case LibFunc_copysign:
4150 return optimizeFdim(CI, Builder);
4154 return optimizeFMinFMax(CI, Builder, Intrinsic::minnum);
4158 return optimizeFMinFMax(CI, Builder, Intrinsic::maxnum);
4159 case LibFunc_fminimum_numf:
4160 case LibFunc_fminimum_num:
4161 case LibFunc_fminimum_numl:
4163 case LibFunc_fmaximum_numf:
4164 case LibFunc_fmaximum_num:
4165 case LibFunc_fmaximum_numl:
4170 return optimizeCAbs(CI, Builder);
4171 case LibFunc_remquo:
4172 case LibFunc_remquof:
4173 case LibFunc_remquol:
4174 return optimizeRemquo(CI, Builder);
4193 return maybeOptimizeNoBuiltinOperatorNew(CI, Builder);
4204 Builder.setDefaultOperandBundles(OpBundles);
4212 UnsafeFPShrink =
true;
4216 if (!IsCallingConvC)
4220 switch (
II->getIntrinsicID()) {
4221 case Intrinsic::pow:
4222 return optimizePow(CI, Builder);
4223 case Intrinsic::exp2:
4224 return optimizeExp2(CI, Builder);
4225 case Intrinsic::log:
4226 case Intrinsic::log2:
4227 case Intrinsic::log10:
4228 return optimizeLog(CI, Builder);
4229 case Intrinsic::sqrt:
4230 return optimizeSqrt(CI, Builder);
4231 case Intrinsic::memset:
4232 return optimizeMemSet(CI, Builder);
4233 case Intrinsic::memcpy:
4234 return optimizeMemCpy(CI, Builder);
4235 case Intrinsic::memmove:
4236 return optimizeMemMove(CI, Builder);
4237 case Intrinsic::sin:
4238 case Intrinsic::cos:
4248 if (
Value *SimplifiedFortifiedCI =
4249 FortifiedSimplifier.optimizeCall(CI, Builder))
4250 return SimplifiedFortifiedCI;
4257 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
4259 if (
Value *V = optimizeFloatingPointLibCall(CI, Func, Builder))
4265 return optimizeFFS(CI, Builder);
4269 return optimizeFls(CI, Builder);
4273 return optimizeAbs(CI, Builder);
4274 case LibFunc_isdigit:
4275 return optimizeIsDigit(CI, Builder);
4276 case LibFunc_isascii:
4277 return optimizeIsAscii(CI, Builder);
4278 case LibFunc_toascii:
4279 return optimizeToAscii(CI, Builder);
4283 return optimizeAtoi(CI, Builder);
4284 case LibFunc_strtol:
4285 case LibFunc_strtoll:
4286 return optimizeStrToInt(CI, Builder,
true);
4287 case LibFunc_strtoul:
4288 case LibFunc_strtoull:
4289 return optimizeStrToInt(CI, Builder,
false);
4290 case LibFunc_printf:
4291 return optimizePrintF(CI, Builder);
4292 case LibFunc_sprintf:
4293 return optimizeSPrintF(CI, Builder);
4294 case LibFunc_snprintf:
4295 return optimizeSnPrintF(CI, Builder);
4296 case LibFunc_fprintf:
4297 return optimizeFPrintF(CI, Builder);
4298 case LibFunc_fwrite:
4299 return optimizeFWrite(CI, Builder);
4301 return optimizeFPuts(CI, Builder);
4303 return optimizePuts(CI, Builder);
4304 case LibFunc_perror:
4305 return optimizeErrorReporting(CI, Builder);
4306 case LibFunc_vfprintf:
4307 case LibFunc_fiprintf:
4308 return optimizeErrorReporting(CI, Builder, 0);
4311 return optimizeExit(CI);
4325 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), DT(DT), DC(DC), AC(AC),
4326 ORE(ORE), BFI(BFI), PSI(PSI), Replacer(Replacer), Eraser(Eraser) {}
4333void LibCallSimplifier::eraseFromParent(
Instruction *
I) {
4372bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
4373 CallInst *CI,
unsigned ObjSizeOp, std::optional<unsigned> SizeOp,
4374 std::optional<unsigned> StrOp, std::optional<unsigned> FlagOp) {
4379 if (!Flag || !
Flag->isZero())
4386 if (ConstantInt *ObjSizeCI =
4388 if (ObjSizeCI->isMinusOne())
4391 if (OnlyLowerUnknownSize)
4401 return ObjSizeCI->getZExtValue() >=
Len;
4405 if (ConstantInt *SizeCI =
4407 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
4413Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
4415 if (isFortifiedCallFoldable(CI, 3, 2)) {
4425Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
4427 if (isFortifiedCallFoldable(CI, 3, 2)) {
4437Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
4439 if (isFortifiedCallFoldable(CI, 3, 2)) {
4449Value *FortifiedLibCallSimplifier::optimizeMemPCpyChk(
CallInst *CI,
4452 if (isFortifiedCallFoldable(CI, 3, 2))
4460Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
4468 if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
4470 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
4478 if (isFortifiedCallFoldable(CI, 2, std::nullopt, 1)) {
4479 if (Func == LibFunc_strcpy_chk)
4485 if (OnlyLowerUnknownSize)
4495 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
4497 Value *LenV = ConstantInt::get(SizeTTy, Len);
4501 if (Ret && Func == LibFunc_stpcpy_chk)
4502 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
4503 ConstantInt::get(SizeTTy, Len - 1));
4507Value *FortifiedLibCallSimplifier::optimizeStrLenChk(
CallInst *CI,
4509 if (isFortifiedCallFoldable(CI, 1, std::nullopt, 0))
4515Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
4518 if (isFortifiedCallFoldable(CI, 3, 2)) {
4519 if (Func == LibFunc_strncpy_chk)
4532Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(
CallInst *CI,
4534 if (isFortifiedCallFoldable(CI, 4, 3))
4542Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(
CallInst *CI,
4544 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2)) {
4554Value *FortifiedLibCallSimplifier::optimizeSPrintfChk(
CallInst *CI,
4556 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1)) {
4560 VariadicArgs,
B, TLI));
4566Value *FortifiedLibCallSimplifier::optimizeStrCatChk(
CallInst *CI,
4568 if (isFortifiedCallFoldable(CI, 2))
4575Value *FortifiedLibCallSimplifier::optimizeStrLCat(
CallInst *CI,
4577 if (isFortifiedCallFoldable(CI, 3))
4585Value *FortifiedLibCallSimplifier::optimizeStrNCatChk(
CallInst *CI,
4587 if (isFortifiedCallFoldable(CI, 3))
4595Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(
CallInst *CI,
4597 if (isFortifiedCallFoldable(CI, 3))
4605Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(
CallInst *CI,
4607 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2))
4615Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(
CallInst *CI,
4617 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1))
4648 Builder.setDefaultOperandBundles(OpBundles);
4652 if (!TLI->getLibFunc(*Callee, Func))
4660 case LibFunc_memcpy_chk:
4661 return optimizeMemCpyChk(CI, Builder);
4662 case LibFunc_mempcpy_chk:
4663 return optimizeMemPCpyChk(CI, Builder);
4664 case LibFunc_memmove_chk:
4665 return optimizeMemMoveChk(CI, Builder);
4666 case LibFunc_memset_chk:
4667 return optimizeMemSetChk(CI, Builder);
4668 case LibFunc_stpcpy_chk:
4669 case LibFunc_strcpy_chk:
4670 return optimizeStrpCpyChk(CI, Builder, Func);
4671 case LibFunc_strlen_chk:
4672 return optimizeStrLenChk(CI, Builder);
4673 case LibFunc_stpncpy_chk:
4674 case LibFunc_strncpy_chk:
4675 return optimizeStrpNCpyChk(CI, Builder, Func);
4676 case LibFunc_memccpy_chk:
4677 return optimizeMemCCpyChk(CI, Builder);
4678 case LibFunc_snprintf_chk:
4679 return optimizeSNPrintfChk(CI, Builder);
4680 case LibFunc_sprintf_chk:
4681 return optimizeSPrintfChk(CI, Builder);
4682 case LibFunc_strcat_chk:
4683 return optimizeStrCatChk(CI, Builder);
4684 case LibFunc_strlcat_chk:
4685 return optimizeStrLCat(CI, Builder);
4686 case LibFunc_strncat_chk:
4687 return optimizeStrNCatChk(CI, Builder);
4688 case LibFunc_strlcpy_chk:
4689 return optimizeStrLCpyChk(CI, Builder);
4690 case LibFunc_vsnprintf_chk:
4691 return optimizeVSNPrintfChk(CI, Builder);
4692 case LibFunc_vsprintf_chk:
4693 return optimizeVSPrintfChk(CI, Builder);
4702 : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< 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")
Module.h This file contains the declarations for the Module class.
static llvm::Error parse(GsymDataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
Machine Check Debug Module
uint64_t IntrinsicInst * II
static bool isBinary(MachineInstr &MI)
const SmallVectorImpl< MachineOperand > & Cond
static bool isOnlyUsedInEqualityComparison(Value *V, Value *With)
Return true if it is only used in equality comparisons with With.
static void annotateNonNullAndDereferenceable(CallInst *CI, ArrayRef< unsigned > ArgNos, Value *Size, const DataLayout &DL)
static cl::opt< unsigned, false, HotColdHintParser > ColdNewHintValue("cold-new-hint-value", cl::Hidden, cl::init(1), cl::desc("Value to pass to hot/cold operator new for cold allocation"))
static bool insertSinCosCall(IRBuilderBase &B, Function *OrigCallee, Value *Arg, bool UseFloat, Value *&Sin, Value *&Cos, Value *&SinCos, const TargetLibraryInfo *TLI)
static Value * mergeAttributesAndFlags(CallInst *NewCI, const CallInst &Old)
static cl::opt< bool > OptimizeHotColdNew("optimize-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable hot/cold operator new library calls"))
static Value * optimizeBinaryDoubleFP(CallInst *CI, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool isPrecise=false)
Shrink double -> float for binary functions.
static bool ignoreCallingConv(LibFunc Func)
static cl::opt< bool > OptimizeExistingHotColdNew("optimize-existing-hot-cold-new", cl::Hidden, cl::init(false), cl::desc("Enable optimization of existing hot/cold operator new library calls"))
static void annotateDereferenceableBytes(CallInst *CI, ArrayRef< unsigned > ArgNos, uint64_t DereferenceableBytes)
static bool isReportingError(Function *Callee, CallInst *CI, int StreamArg)
static Value * optimizeDoubleFP(CallInst *CI, IRBuilderBase &B, bool isBinary, const TargetLibraryInfo *TLI, bool isPrecise=false)
Shrink double -> float functions.
static Value * optimizeSymmetricCall(CallInst *CI, bool IsEven, IRBuilderBase &B)
static Value * getSqrtCall(Value *V, AttributeList Attrs, bool NoErrno, Module *M, IRBuilderBase &B, const TargetLibraryInfo *TLI)
static Value * replaceBinaryCall(CallInst *CI, IRBuilderBase &B, Intrinsic::ID IID)
static Value * valueHasFloatPrecision(Value *Val)
Return a variant of Val with float type.
static Value * optimizeMemCmpConstantSize(CallInst *CI, Value *LHS, Value *RHS, uint64_t Len, IRBuilderBase &B, const DataLayout &DL)
static Value * createPowWithIntegerExponent(Value *Base, Value *Expo, Module *M, IRBuilderBase &B)
static Value * convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, uint64_t Base, bool AsSigned, IRBuilderBase &B)
static Value * memChrToCharCompare(CallInst *CI, Value *NBytes, IRBuilderBase &B, const DataLayout &DL)
static Value * copyFlags(const CallInst &Old, Value *New)
static 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 void annotateNonNullNoUndefBasedOnAccess(CallInst *CI, ArrayRef< unsigned > ArgNos)
static Value * optimizeMemCmpVarSize(CallInst *CI, Value *LHS, Value *RHS, Value *Size, bool StrNCmp, IRBuilderBase &B, const DataLayout &DL)
static Value * getIntToFPVal(Value *I2F, IRBuilderBase &B, unsigned DstWidth)
static cl::opt< bool > EnableUnsafeFPShrink("enable-double-float-shrink", cl::Hidden, cl::init(false), cl::desc("Enable unsafe double to float " "shrinking for math lib calls"))
static cl::opt< unsigned, false, HotColdHintParser > NotColdNewHintValue("notcold-new-hint-value", cl::Hidden, cl::init(128), cl::desc("Value to pass to hot/cold operator new for " "notcold (warm) allocation"))
This file defines the SmallString class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static 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.".
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Module * getParent()
Get the module that this global value is contained inside of...
This instruction compares its operands according to the predicate given to the constructor.
Common base class shared among various IRBuilders.
LLVM_ABI Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
LLVM_ABI bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
LLVM_ABI 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.
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.
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()
A Module instance is used to store all the information related to an LLVM module.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Analysis providing profile information.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isStructTy() const
True if this is an instance of StructType.
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
LLVM_ABI const fltSemantics & getFltSemantics() const
A Use represents the edge between a Value definition and its users.
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
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.
auto m_FAbs(const Opnd0 &Op0)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
This namespace contains all of the command line option processing machinery.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
LLVM_ABI Value * emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth=0)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
LLVM_ABI Value * emitStrChr(Value *Ptr, char C, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
constexpr uint64_t maxUIntN(uint64_t N)
Gets the maximum value for a N-bit unsigned integer.
LLVM_ABI Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
LLVM_ABI Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
LLVM_ABI Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI bool isKnownNeverInfinity(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the floating-point scalar value is not an infinity or if the floating-point vector val...
LLVM_ABI bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
@ Known
Known to have no common set bits.
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
LLVM_ABI bool getConstantStringInfo(const Value *V, StringRef &Str, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
LLVM_ABI 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 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.
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 Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
auto dyn_cast_or_null(const Y &Val)
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
LLVM_ABI Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
LLVM_ABI Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
bool isAlpha(char C)
Checks if character C is a valid letter as classified by "C" locale.
LLVM_ABI Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
LLVM_ABI Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
LLVM_ABI uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'.
LLVM_ABI FunctionCallee getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI, LibFunc TheLibFunc, FunctionType *T, AttributeList AttributeList)
Calls getOrInsertFunction() and then makes sure to add mandatory argument attributes.
LLVM_ABI Value * emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
LLVM_ABI Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
LLVM_ABI Value * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
LLVM_ABI Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
LLVM_ABI Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value * > Args, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
@ Mod
The access may modify the value stored in memory.
LLVM_ABI Value * emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
@ And
Bitwise or logical AND of integers.
char toUpper(char x)
Returns the corresponding uppercase character if x is lowercase.
DWARFExpression::Operation Op
@ NearestTiesToEven
roundTiesToEven.
constexpr int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Value * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
LLVM_ABI Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
LLVM_ABI Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
LLVM_ABI Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_ABI Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
LLVM_ABI Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
LLVM_ABI 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 * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
LLVM_ABI Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t Length
Length of the slice.
uint64_t Offset
Slice starts at this Offset.
const ConstantDataArray * Array
ConstantDataArray pointer.
bool 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.