51 cl::desc(
"Enable unsafe double to float "
52 "shrinking for math lib calls"));
59 cl::desc(
"Enable hot/cold operator new library calls"));
68 "Enable optimization of existing hot/cold operator new library calls"),
72 "Do not optimize existing hot/cold operator new library calls"),
74 "Only optimize existing hot/cold operator new library calls "
75 "if determined to be cold"),
78 "Always optimize existing hot/cold operator new library calls"),
81 "Always optimize existing hot/cold operator new library calls")),
85 cl::desc(
"Enable transformation of nobuiltin operator new library calls"));
88 cl::desc(
"Take the minimum of compiler hint and existing hint when "
89 "optimizing existing hot/cold operator new library calls"));
96struct HotColdHintParser :
public cl::parser<unsigned> {
99 bool parse(cl::Option &O, StringRef ArgName, StringRef Arg,
unsigned &
Value) {
101 return O.error(
"'" + Arg +
"' value invalid for uint argument!");
104 return O.error(
"'" + Arg +
"' value must be in the range [0, 255]!");
118 cl::desc(
"Value to pass to hot/cold operator new for cold allocation"));
121 cl::desc(
"Value to pass to hot/cold operator new for "
122 "notcold (warm) allocation"));
125 cl::desc(
"Value to pass to hot/cold operator new for hot allocation"));
129 "Value to pass to hot/cold operator new for ambiguous allocation"));
136 return Func == LibFunc_abs || Func == LibFunc_labs ||
137 Func == LibFunc_llabs || Func == LibFunc_strlen;
144 if (IC->isEquality() && IC->getOperand(1) == With)
154 return OI->getType()->isFloatingPointTy();
160 return OI->getType()->isFP128Ty();
193 bool Negate = Str[0] ==
'-';
194 if (Str[0] ==
'-' || Str[0] ==
'+') {
195 Str = Str.drop_front();
206 uint64_t Max = AsSigned && Negate ? 1 : 0;
210 if (Str.size() > 1) {
212 if (
toUpper((
unsigned char)Str[1]) ==
'X') {
213 if (Str.size() == 2 || (
Base &&
Base != 16))
218 Str = Str.drop_front(2);
224 }
else if (
Base == 0)
234 for (
unsigned i = 0; i != Str.size(); ++i) {
235 unsigned char DigVal = Str[i];
237 DigVal = DigVal -
'0';
241 DigVal = DigVal -
'A' + 10;
254 if (VFlow || Result > Max)
262 Value *StrEnd =
B.CreateInBoundsGEP(
B.getInt8Ty(), StrBeg, Off,
"endptr");
263 B.CreateStore(StrEnd, EndPtr);
274 return ConstantInt::get(RetTy, Result, AsSigned);
281 if (
C->isNullValue())
309 for (
unsigned ArgNo : ArgNos) {
310 uint64_t DerefBytes = DereferenceableBytes;
315 DereferenceableBytes);
334 for (
unsigned ArgNo : ArgNos) {
360 DerefMin = std::min(
X,
Y);
381 NewCI->
getContext(), {NewCI->getAttributes(), Old.getAttributes()}));
394 return Len >= Str.size() ? Str : Str.substr(0, Len);
419 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, Len,
B));
433 Value *CpyDst =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, DstLen,
"endptr");
438 TLI->getAsSizeT(Len + 1, *
B.GetInsertBlock()->getModule()));
482 return copyFlags(*CI, emitStrLenMemCpy(Src, Dst, SrcLen,
B));
495 Type *CharTy =
B.getInt8Ty();
496 Value *Char0 =
B.CreateLoad(CharTy, Src);
497 CharVal =
B.CreateTrunc(CharVal, CharTy);
498 Value *Cmp =
B.CreateICmpEQ(Char0, CharVal,
"char0cmp");
502 Value *
And =
B.CreateICmpNE(NBytes, Zero);
503 Cmp =
B.CreateLogicalAnd(
And, Cmp);
507 return B.CreateSelect(Cmp, Src, NullPtr);
529 FunctionType *FT =
Callee->getFunctionType();
530 unsigned IntBits = TLI->getIntSize();
531 if (!FT->getParamType(1)->isIntegerTy(IntBits))
534 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
538 ConstantInt::get(SizeTTy, Len),
B,
547 return B.CreateIntToPtr(
B.getTrue(), CI->
getType());
556 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, StrLen,
"strchr");
569 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(
I),
"strchr");
581 if (CharC && CharC->
isZero())
586 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
592 Value *
Size = ConstantInt::get(SizeTTy, NBytes);
599 return ConstantInt::get(CI->
getType(), 0);
601 StringRef Str1, Str2;
606 if (HasStr1 && HasStr2)
608 std::clamp(Str1.
compare(Str2), -1, 1));
610 if (HasStr1 && Str1.
empty())
611 return B.CreateNeg(
B.CreateZExt(
612 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
614 if (HasStr2 && Str2.
empty())
615 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
629 TLI->getAsSizeT(std::min(Len1, Len2), *CI->
getModule()),
634 SimplifyQuery SQ(DL, TLI, DT, AC, CI);
635 if (!HasStr1 && HasStr2) {
640 }
else if (HasStr1 && !HasStr2) {
662 return ConstantInt::get(CI->
getType(), 0);
674 return ConstantInt::get(CI->
getType(), 0);
679 StringRef Str1, Str2;
684 if (HasStr1 && HasStr2) {
689 std::clamp(SubStr1.
compare(SubStr2), -1, 1));
692 if (HasStr1 && Str1.
empty())
693 return B.CreateNeg(
B.CreateZExt(
694 B.CreateLoad(
B.getInt8Ty(), Str2P,
"strcmpload"), CI->
getType()));
696 if (HasStr2 && Str2.
empty())
697 return B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(), Str1P,
"strcmpload"),
708 if (!HasStr1 && HasStr2) {
709 Len2 = std::min(Len2,
Length);
714 }
else if (HasStr1 && !HasStr2) {
715 Len1 = std::min(Len1,
Length);
729 if (SrcLen &&
Size) {
731 if (SrcLen <= Size->getZExtValue() + 1)
753 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
768 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
779 Value *DstEnd =
B.CreateInBoundsGEP(
780 B.getInt8Ty(), Dst, TLI->getAsSizeT(Len - 1, *CI->
getModule()));
784 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1), LenV);
803 NBytes = SizeC->getZExtValue();
812 B.CreateStore(
B.getInt8(0), Dst);
828 bool NulTerm = SrcLen < NBytes;
837 SrcLen = std::min(SrcLen,
uint64_t(Str.size()));
838 NBytes = std::min(NBytes - 1, SrcLen);
843 B.CreateStore(
B.getInt8(0), Dst);
844 return ConstantInt::get(CI->
getType(), 0);
850 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
851 TLI->getAsSizeT(NBytes, *CI->
getModule()));
855 Value *EndOff = ConstantInt::get(CI->
getType(), NBytes);
856 Value *EndPtr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, EndOff);
857 B.CreateStore(
B.getInt8(0), EndPtr);
863 return ConstantInt::get(CI->
getType(), SrcLen);
868Value *LibCallSimplifier::optimizeStringNCpy(
CallInst *CI,
bool RetEnd,
885 N = SizeC->getZExtValue();
892 Type *CharTy =
B.getInt8Ty();
893 Value *CharVal =
B.CreateLoad(CharTy, Src,
"stxncpy.char0");
894 B.CreateStore(CharVal, Dst);
900 Value *ZeroChar = ConstantInt::get(CharTy, 0);
901 Value *
Cmp =
B.CreateICmpEQ(CharVal, ZeroChar,
"stpncpy.char0cmp");
903 Value *Off1 =
B.getInt32(1);
904 Value *EndPtr =
B.CreateInBoundsGEP(CharTy, Dst, Off1,
"stpncpy.end");
905 return B.CreateSelect(Cmp, Dst, EndPtr,
"stpncpy.sel");
920 CI->
getAttributes().getParamAttrs(0).getAlignment().valueOrOne();
921 CallInst *NewCI =
B.CreateMemSet(Dst,
B.getInt8(
'\0'),
Size, MemSetAlign);
929 if (
N > SrcLen + 1) {
938 std::string SrcStr = Str.str();
941 SrcStr.resize(
N,
'\0');
942 Src =
B.CreateGlobalString(SrcStr,
"str", 0,
948 CallInst *NewCI =
B.CreateMemCpy(Dst,
Align(1), Src,
Align(1),
957 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, Off,
"endptr");
974 return B.CreateZExt(
B.CreateLoad(CharTy, Src,
"char0"),
980 if (BoundCst->isZero())
982 return ConstantInt::get(CI->
getType(), 0);
984 if (BoundCst->isOne()) {
986 Value *CharVal =
B.CreateLoad(CharTy, Src,
"strnlen.char0");
987 Value *ZeroChar = ConstantInt::get(CharTy, 0);
988 Value *
Cmp =
B.CreateICmpNE(CharVal, ZeroChar,
"strnlen.char0cmp");
989 return B.CreateZExt(Cmp, CI->
getType());
999 return B.CreateBinaryIntrinsic(Intrinsic::umin, LenC, Bound);
1016 unsigned BW = DL.getIndexTypeSizeInBits(
GEP->getType());
1017 SmallMapVector<Value *, APInt, 4> VarOffsets;
1018 APInt ConstOffset(BW, 0);
1019 assert(CharSize % 8 == 0 &&
"Expected a multiple of 8 sized CharSize");
1021 if (!
GEP->collectOffset(DL, BW, VarOffsets, ConstOffset) ||
1022 VarOffsets.
size() != 1 || ConstOffset != 0 ||
1023 VarOffsets.
begin()->second != CharSize / 8)
1026 ConstantDataArraySlice Slice;
1029 if (Slice.
Array ==
nullptr) {
1052 if ((
Known.isNonNegative() &&
Known.getMaxValue().ule(NullTermIdx)) ||
1054 NullTermIdx == Slice.
Length - 1)) {
1056 return B.CreateSub(ConstantInt::get(CI->
getType(), NullTermIdx),
1066 if (LenTrue && LenFalse) {
1068 return OptimizationRemark(
"instcombine",
"simplify-libcalls", CI)
1069 <<
"folded strlen(select) to select of constants";
1071 return B.CreateSelect(
SI->getCondition(),
1072 ConstantInt::get(CI->
getType(), LenTrue - 1),
1073 ConstantInt::get(CI->
getType(), LenFalse - 1));
1081 if (
Value *V = optimizeStringLength(CI,
B, 8))
1089 if (
Value *V = optimizeStringLength(CI,
B, 8, Bound))
1099 unsigned WCharSize = TLI->getWCharSize(M) * 8;
1104 return optimizeStringLength(CI,
B, WCharSize);
1114 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1118 if (HasS1 && HasS2) {
1119 size_t I =
S1.find_first_of(S2);
1124 B.getInt64(
I),
"strpbrk");
1128 if (HasS2 && S2.
size() == 1)
1153 if ((HasS1 &&
S1.empty()) || (HasS2 && S2.
empty()))
1157 if (HasS1 && HasS2) {
1158 size_t Pos =
S1.find_first_not_of(S2);
1161 return ConstantInt::get(CI->
getType(), Pos);
1173 if (HasS1 &&
S1.empty())
1177 if (HasS1 && HasS2) {
1178 size_t Pos =
S1.find_first_of(S2);
1181 return ConstantInt::get(CI->
getType(), Pos);
1185 if (HasS2 && S2.
empty())
1202 StrLen,
B, DL, TLI);
1210 replaceAllUsesWith(Old, Cmp);
1216 StringRef SearchStr, ToFindStr;
1221 if (HasStr2 && ToFindStr.
empty())
1225 if (HasStr1 && HasStr2) {
1232 return B.CreateConstInBoundsGEP1_64(
B.getInt8Ty(), CI->
getArgOperand(0),
1237 if (HasStr2 && ToFindStr.
size() == 1) {
1258 if (LenC->
isOne()) {
1261 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memrchr.char0");
1263 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1264 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memrchr.char0cmp");
1265 return B.CreateSelect(Cmp, SrcStr, NullPtr,
"memrchr.sel");
1273 if (Str.size() == 0)
1282 if (Str.size() < EndOff)
1297 return B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos));
1299 if (Str.find(Str[Pos]) == Pos) {
1306 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
1307 B.getInt64(Pos),
"memrchr.ptr_plus");
1308 return B.CreateSelect(Cmp, NullPtr, SrcPlus,
"memrchr.sel");
1313 Str = Str.substr(0, EndOff);
1321 Type *Int8Ty =
B.getInt8Ty();
1322 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1324 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1325 Value *CEqS0 =
B.CreateICmpEQ(ConstantInt::get(Int8Ty, Str[0]), CharVal);
1326 Value *
And =
B.CreateLogicalAnd(NNeZ, CEqS0);
1327 Value *SizeM1 =
B.CreateSub(
Size, ConstantInt::get(SizeTy, 1));
1329 B.CreateInBoundsGEP(Int8Ty, SrcStr, SizeM1,
"memrchr.ptr_plus");
1330 return B.CreateSelect(
And, SrcPlus, NullPtr,
"memrchr.sel");
1353 if (LenC->
isOne()) {
1356 Value *Val =
B.CreateLoad(
B.getInt8Ty(), SrcStr,
"memchr.char0");
1358 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1359 Value *
Cmp =
B.CreateICmpEQ(Val, CharVal,
"memchr.char0cmp");
1360 return B.CreateSelect(Cmp, SrcStr, NullPtr,
"memchr.sel");
1380 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr,
B.getInt64(Pos),
1382 return B.CreateSelect(Cmp, NullPtr, SrcPlus);
1385 if (Str.size() == 0)
1394 size_t Pos = Str.find_first_not_of(Str[0]);
1410 CharVal =
B.CreateTrunc(CharVal, Int8Ty);
1412 Value *Sel1 = NullPtr;
1415 Value *PosVal = ConstantInt::get(SizeTy, Pos);
1416 Value *StrPos = ConstantInt::get(Int8Ty, Str[Pos]);
1417 Value *CEqSPos =
B.CreateICmpEQ(CharVal, StrPos);
1419 Value *
And =
B.CreateAnd(CEqSPos, NGtPos);
1420 Value *SrcPlus =
B.CreateInBoundsGEP(
B.getInt8Ty(), SrcStr, PosVal);
1421 Sel1 =
B.CreateSelect(
And, SrcPlus, NullPtr,
"memchr.sel1");
1424 Value *Str0 = ConstantInt::get(Int8Ty, Str[0]);
1425 Value *CEqS0 =
B.CreateICmpEQ(Str0, CharVal);
1426 Value *NNeZ =
B.CreateICmpNE(
Size, ConstantInt::get(SizeTy, 0));
1428 return B.CreateSelect(
And, SrcStr, Sel1,
"memchr.sel2");
1459 *std::max_element(
reinterpret_cast<const unsigned char *
>(Str.begin()),
1460 reinterpret_cast<const unsigned char *
>(Str.end()));
1467 if (!DL.fitsInLegalInteger(Max + 1)) {
1473 std::string SortedStr = Str.str();
1476 unsigned NonContRanges = 1;
1477 for (
size_t i = 1; i < SortedStr.size(); ++i) {
1478 if (SortedStr[i] > SortedStr[i - 1] + 1) {
1485 if (NonContRanges > 2)
1489 CharVal =
B.CreateTrunc(CharVal,
B.getInt8Ty());
1492 for (
unsigned char C : SortedStr)
1493 CharCompares.
push_back(
B.CreateICmpEQ(CharVal,
B.getInt8(
C)));
1495 return B.CreateIntToPtr(
B.CreateOr(CharCompares), CI->
getType());
1500 unsigned char Width =
NextPowerOf2(std::max((
unsigned char)7, Max));
1506 Value *BitfieldC =
B.getInt(Bitfield);
1510 C =
B.CreateAnd(
C,
B.getIntN(Width, 0xFF));
1517 Value *Shl =
B.CreateShl(
B.getIntN(Width, 1ULL),
C);
1518 Value *
Bits =
B.CreateIsNotNull(
B.CreateAnd(Shl, BitfieldC),
"memchr.bits");
1522 return B.CreateIntToPtr(
B.CreateLogicalAnd(Bounds, Bits,
"memchr"),
1547 if (Pos == MinSize ||
1548 (StrNCmp && (LStr[Pos] ==
'\0' && RStr[Pos] ==
'\0'))) {
1556 if (LStr[Pos] != RStr[Pos])
1561 typedef unsigned char UChar;
1562 int IRes = UChar(LStr[Pos]) < UChar(RStr[Pos]) ? -1 : 1;
1563 Value *MaxSize = ConstantInt::get(
Size->getType(), Pos);
1566 return B.CreateSelect(Cmp, Zero, Res);
1578 Value *LHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
LHS,
"lhsc"),
1580 Value *RHSV =
B.CreateZExt(
B.CreateLoad(
B.getInt8Ty(),
RHS,
"rhsc"),
1582 return B.CreateSub(LHSV, RHSV,
"chardiff");
1590 Align PrefAlignment =
DL.getPrefTypeAlign(IntType);
1593 Value *LHSV =
nullptr;
1597 Value *RHSV =
nullptr;
1606 LHSV =
B.CreateLoad(IntType,
LHS,
"lhsv");
1608 RHSV =
B.CreateLoad(IntType,
RHS,
"rhsv");
1609 return B.CreateZExt(
B.CreateICmpNE(LHSV, RHSV), CI->
getType(),
"memcmp");
1617Value *LibCallSimplifier::optimizeMemCmpBCmpCommon(
CallInst *CI,
1637 if (
Value *V = optimizeMemCmpBCmpCommon(CI,
B))
1655 return optimizeMemCmpBCmpCommon(CI,
B);
1681 if (
N->isNullValue())
1694 if (
N->getZExtValue() <= SrcStr.
size()) {
1703 ConstantInt::get(
N->getType(), std::min(
uint64_t(Pos + 1),
N->getZExtValue()));
1706 return Pos + 1 <=
N->getZExtValue()
1707 ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, NewN)
1721 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
N);
1754 if (MDNode *MD = CI->
getMetadata(LLVMContext::MD_alloc_token))
1755 MallocCI->setMetadata(LLVMContext::MD_alloc_token, MD);
1764Value *LibCallSimplifier::maybeOptimizeNoBuiltinOperatorNew(
CallInst *CI,
1771 LibFunc
Func = TLI->getLibFunc(*Callee);
1772 if (Func == NotLibFunc)
1776 case LibFunc_ZnwmRKSt9nothrow_t:
1777 case LibFunc_ZnwmSt11align_val_t:
1778 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1780 case LibFunc_ZnamRKSt9nothrow_t:
1781 case LibFunc_ZnamSt11align_val_t:
1782 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1783 case LibFunc_size_returning_new:
1784 case LibFunc_size_returning_new_aligned:
1791 case LibFunc_Znwm12__hot_cold_t:
1792 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1793 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1794 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1795 case LibFunc_Znam12__hot_cold_t:
1796 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1797 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1798 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1799 case LibFunc_size_returning_new_hot_cold:
1800 case LibFunc_size_returning_new_aligned_hot_cold:
1809 return optimizeNew(CI,
B, Func);
1822 bool IsCold =
false;
1823 if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"cold") {
1826 }
else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1829 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
"hot")
1831 else if (CI->
getAttributes().getFnAttr(
"memprof").getValueAsString() ==
1837 bool ShouldOptimizeExistingHotColdNew =
1842 Value *HotColdVal =
B.getInt8(HotCold);
1843 auto getHotColdHintForExisting = [&](uint8_t HotCold) ->
Value * {
1849 ExistingHint =
B.CreateTruncOrBitCast(ExistingHint,
B.getInt8Ty());
1853 return B.CreateBinaryIntrinsic(Intrinsic::umin, ExistingHint, HotColdVal);
1863 Value *NewCall =
nullptr;
1865 case LibFunc_Znwm12__hot_cold_t:
1866 if (ShouldOptimizeExistingHotColdNew)
1868 LibFunc_Znwm12__hot_cold_t,
1869 getHotColdHintForExisting(HotCold));
1873 LibFunc_Znwm12__hot_cold_t, HotColdVal);
1875 case LibFunc_Znam12__hot_cold_t:
1876 if (ShouldOptimizeExistingHotColdNew)
1878 LibFunc_Znam12__hot_cold_t,
1879 getHotColdHintForExisting(HotCold));
1883 LibFunc_Znam12__hot_cold_t, HotColdVal);
1885 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1886 if (ShouldOptimizeExistingHotColdNew)
1889 TLI, LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t,
1890 getHotColdHintForExisting(HotCold));
1892 case LibFunc_ZnwmRKSt9nothrow_t:
1895 LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t, HotColdVal);
1897 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1898 if (ShouldOptimizeExistingHotColdNew)
1901 TLI, LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t,
1902 getHotColdHintForExisting(HotCold));
1904 case LibFunc_ZnamRKSt9nothrow_t:
1907 LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t, HotColdVal);
1909 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1910 if (ShouldOptimizeExistingHotColdNew)
1913 TLI, LibFunc_ZnwmSt11align_val_t12__hot_cold_t,
1914 getHotColdHintForExisting(HotCold));
1916 case LibFunc_ZnwmSt11align_val_t:
1919 LibFunc_ZnwmSt11align_val_t12__hot_cold_t, HotColdVal);
1921 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1922 if (ShouldOptimizeExistingHotColdNew)
1925 TLI, LibFunc_ZnamSt11align_val_t12__hot_cold_t,
1926 getHotColdHintForExisting(HotCold));
1928 case LibFunc_ZnamSt11align_val_t:
1931 LibFunc_ZnamSt11align_val_t12__hot_cold_t, HotColdVal);
1933 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1934 if (ShouldOptimizeExistingHotColdNew)
1937 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1938 getHotColdHintForExisting(HotCold));
1940 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1943 TLI, LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1946 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1947 if (ShouldOptimizeExistingHotColdNew)
1950 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1951 getHotColdHintForExisting(HotCold));
1953 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1956 TLI, LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t,
1959 case LibFunc_size_returning_new:
1961 LibFunc_size_returning_new_hot_cold,
1964 case LibFunc_size_returning_new_hot_cold:
1965 if (ShouldOptimizeExistingHotColdNew)
1967 LibFunc_size_returning_new_hot_cold,
1968 getHotColdHintForExisting(HotCold));
1970 case LibFunc_size_returning_new_aligned:
1973 LibFunc_size_returning_new_aligned_hot_cold, HotColdVal);
1975 case LibFunc_size_returning_new_aligned_hot_cold:
1976 if (ShouldOptimizeExistingHotColdNew)
1979 LibFunc_size_returning_new_aligned_hot_cold,
1980 getHotColdHintForExisting(HotCold));
2019 Value *
Op = Cast->getOperand(0);
2020 if (
Op->getType()->isFloatTy())
2029 return ConstantFP::get(Const->getContext(),
F);
2037 bool isPrecise =
false) {
2069 CallerName.
size() == (CalleeName.
size() + 1) &&
2082 R =
isBinary ?
B.CreateIntrinsic(IID,
B.getFloatTy(), V)
2083 :
B.CreateIntrinsic(IID,
B.getFloatTy(), V[0]);
2091 return B.CreateFPExt(R,
B.getDoubleTy());
2097 bool isPrecise =
false) {
2104 bool isPrecise =
false) {
2111 if (!RetTy || RetTy->getNumElements() != 2 ||
2112 !RetTy->getElementType(0)->getScalarType()->isDoubleTy())
2118 if (Ext->getOperand(0)->getType()->getScalarType()->isFloatTy())
2119 X = Ext->getOperand(0);
2129 if (!Cast || !Cast->getType()->getScalarType()->isFloatTy())
2137 Value *NewCall =
B.CreateIntrinsic(Intrinsic::sincos,
X->getType(),
X);
2139 LLVMContext::MD_fpmath, CI->
getMetadata(LLVMContext::MD_fpmath));
2141 for (
unsigned I = 0;
I != 2; ++
I) {
2142 Value *Ext =
B.CreateFPExt(
B.CreateExtractValue(NewCall,
I),
2143 RetTy->getElementType(
I));
2144 Res =
B.CreateInsertValue(Res, Ext,
I);
2159 assert(
Op->getType()->isArrayTy() &&
"Unexpected signature for cabs!");
2161 Real =
B.CreateExtractValue(
Op, 0,
"real");
2162 Imag =
B.CreateExtractValue(
Op, 1,
"imag");
2172 Value *AbsOp =
nullptr;
2174 if (ConstReal->isZero())
2178 if (ConstImag->isZero())
2183 return copyFlags(*CI,
B.CreateFAbs(AbsOp, CI,
"cabs"));
2190 Value *RealReal =
B.CreateFMulFMF(Real, Real, CI);
2191 Value *ImagImag =
B.CreateFMulFMF(Imag, Imag, CI);
2193 *CI,
B.CreateUnaryIntrinsic(Intrinsic::sqrt,
2194 B.CreateFAddFMF(RealReal, ImagImag, CI), CI,
2205 unsigned BitWidth =
Op->getType()->getScalarSizeInBits();
2207 Type *IntTy =
Op->getType()->getWithNewBitWidth(DstWidth);
2209 :
B.CreateZExt(
Op, IntTy);
2244 CalleeFn ? TLI->getLibFunc(CalleeFn->
getName()) : NotLibFunc;
2249 LibFunc LibFnFloat, LibFnDouble, LibFnLongDouble;
2257 ExpName = TLI->getName(LibFunc_exp);
2258 ID = Intrinsic::exp;
2259 LibFnFloat = LibFunc_expf;
2260 LibFnDouble = LibFunc_exp;
2261 LibFnLongDouble = LibFunc_expl;
2266 ExpName = TLI->getName(LibFunc_exp2);
2267 ID = Intrinsic::exp2;
2268 LibFnFloat = LibFunc_exp2f;
2269 LibFnDouble = LibFunc_exp2;
2270 LibFnLongDouble = LibFunc_exp2l;
2277 ?
B.CreateUnaryIntrinsic(ID,
FMul,
nullptr, ExpName)
2286 substituteInParent(BaseFn, ExpFn);
2297 AttributeList NoAttrs;
2299 const bool UseIntrinsic =
Pow->doesNotAccessMemory();
2305 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2310 Constant *One = ConstantFP::get(Ty, 1.0);
2314 {Ty, ExpoI->getType()},
2315 {One, ExpoI},
Pow,
"exp2"));
2319 One, ExpoI, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2320 LibFunc_ldexpl,
B, NoAttrs));
2325 if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f, LibFunc_exp2l)) {
2328 BaseR = BaseR / *BaseF;
2330 const APFloat *NF = IsReciprocal ? &BaseR : BaseF;
2332 if ((IsInteger || IsReciprocal) &&
2335 NI > 1 && NI.isPowerOf2()) {
2336 double N = NI.logBase2() * (IsReciprocal ? -1.0 : 1.0);
2337 Value *
FMul =
B.CreateFMul(Expo, ConstantFP::get(Ty,
N),
"mul");
2338 if (
Pow->doesNotAccessMemory())
2344 LibFunc_exp2l,
B, NoAttrs));
2350 hasFloatFn(M, TLI, Ty, LibFunc_exp10, LibFunc_exp10f, LibFunc_exp10l)) {
2352 if (
Pow->doesNotAccessMemory()) {
2353 return B.CreateIntrinsic(Intrinsic::exp10, {Ty}, {Expo},
Pow,
"exp10", {},
2358 LibFunc_exp10f, LibFunc_exp10l,
2368 "pow(1.0, y) should have been simplified earlier!");
2377 Value *
FMul =
B.CreateFMul(Log, Expo,
"mul");
2378 if (
Pow->doesNotAccessMemory())
2381 else if (
hasFloatFn(M, TLI, Ty, LibFunc_exp2, LibFunc_exp2f,
2385 LibFunc_exp2l,
B, NoAttrs));
2397 return B.CreateUnaryIntrinsic(Intrinsic::sqrt, V,
nullptr,
"sqrt");
2400 if (
hasFloatFn(M, TLI, V->getType(), LibFunc_sqrt, LibFunc_sqrtf,
2406 LibFunc_sqrtl,
B, Attrs);
2413 Value *Sqrt, *
Base =
Pow->getArgOperand(0), *Expo =
Pow->getArgOperand(1);
2424 if (ExpoF->
isNegative() && (!
Pow->hasApproxFunc() && !
Pow->hasAllowReassoc()))
2431 if (!
Pow->doesNotAccessMemory() && !
Pow->hasNoInfs() &&
2433 Base, SimplifyQuery(DL, TLI, DT, AC,
Pow,
true,
true, DC)))
2442 if (!
Pow->hasNoSignedZeros())
2443 Sqrt =
B.CreateFAbs(Sqrt,
nullptr,
"abs");
2449 if (!
Pow->hasNoInfs()) {
2452 Value *FCmp =
B.CreateFCmpOEQ(
Base, NegInf,
"isinf");
2453 Sqrt =
B.CreateSelect(FCmp, PosInf, Sqrt);
2458 Sqrt =
B.CreateFDiv(ConstantFP::get(Ty, 1.0), Sqrt,
"reciprocal");
2467 return B.CreateIntrinsic(Intrinsic::powi, Types, Args);
2472 Value *Expo =
Pow->getArgOperand(1);
2477 bool AllowApprox =
Pow->hasApproxFunc();
2481 IRBuilderBase::FastMathFlagGuard Guard(
B);
2482 B.setFastMathFlags(
Pow->getFastMathFlags());
2489 if (
Value *Exp = replacePowWithExp(
Pow,
B))
2496 return B.CreateFDiv(ConstantFP::get(Ty, 1.0),
Base,
"reciprocal");
2500 return ConstantFP::get(Ty, 1.0);
2508 return B.CreateFMul(
Base,
Base,
"square");
2510 if (
Value *Sqrt = replacePowWithSqrt(
Pow,
B))
2521 Value *Sqrt =
nullptr;
2522 if (!ExpoA.isInteger()) {
2536 if (!ExpoI.isInteger())
2548 APSInt IntExpo(TLI->getIntSize(),
false);
2555 Base, ConstantInt::get(
B.getIntNTy(TLI->getIntSize()), IntExpo),
2559 return B.CreateFMul(PowI, Sqrt);
2575 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_pow) &&
2576 hasFloatVersion(M, Name)) {
2588 Value *Ret =
nullptr;
2589 if (UnsafeFPShrink && Name == TLI->getName(LibFunc_exp2) &&
2590 hasFloatVersion(M, Name))
2599 const bool UseIntrinsic =
Callee->isIntrinsic();
2610 hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2612 Constant *One = ConstantFP::get(Ty, 1.0);
2615 return copyFlags(*CI,
B.CreateIntrinsic(Intrinsic::ldexp,
2616 {Ty, Exp->getType()},
2620 IRBuilderBase::FastMathFlagGuard Guard(
B);
2623 One, Exp, TLI, LibFunc_ldexp, LibFunc_ldexpf,
2624 LibFunc_ldexpl,
B, AttributeList()));
2648 StringRef LogNm = LogFn->
getName();
2653 if (UnsafeFPShrink && hasFloatVersion(
Mod, LogNm))
2657 LibFunc LogLb, ExpLb, Exp2Lb, Exp10Lb, PowLb;
2660 LogLb = TLI->getLibFunc(LogNm);
2661 if (LogLb != NotLibFunc) {
2664 LogID = Intrinsic::log;
2665 ExpLb = LibFunc_expf;
2666 Exp2Lb = LibFunc_exp2f;
2667 Exp10Lb = LibFunc_exp10f;
2668 PowLb = LibFunc_powf;
2671 LogID = Intrinsic::log;
2672 ExpLb = LibFunc_exp;
2673 Exp2Lb = LibFunc_exp2;
2674 Exp10Lb = LibFunc_exp10;
2675 PowLb = LibFunc_pow;
2678 LogID = Intrinsic::log;
2679 ExpLb = LibFunc_expl;
2680 Exp2Lb = LibFunc_exp2l;
2681 Exp10Lb = LibFunc_exp10l;
2682 PowLb = LibFunc_powl;
2685 LogID = Intrinsic::log2;
2686 ExpLb = LibFunc_expf;
2687 Exp2Lb = LibFunc_exp2f;
2688 Exp10Lb = LibFunc_exp10f;
2689 PowLb = LibFunc_powf;
2692 LogID = Intrinsic::log2;
2693 ExpLb = LibFunc_exp;
2694 Exp2Lb = LibFunc_exp2;
2695 Exp10Lb = LibFunc_exp10;
2696 PowLb = LibFunc_pow;
2699 LogID = Intrinsic::log2;
2700 ExpLb = LibFunc_expl;
2701 Exp2Lb = LibFunc_exp2l;
2702 Exp10Lb = LibFunc_exp10l;
2703 PowLb = LibFunc_powl;
2705 case LibFunc_log10f:
2706 LogID = Intrinsic::log10;
2707 ExpLb = LibFunc_expf;
2708 Exp2Lb = LibFunc_exp2f;
2709 Exp10Lb = LibFunc_exp10f;
2710 PowLb = LibFunc_powf;
2713 LogID = Intrinsic::log10;
2714 ExpLb = LibFunc_exp;
2715 Exp2Lb = LibFunc_exp2;
2716 Exp10Lb = LibFunc_exp10;
2717 PowLb = LibFunc_pow;
2719 case LibFunc_log10l:
2720 LogID = Intrinsic::log10;
2721 ExpLb = LibFunc_expl;
2722 Exp2Lb = LibFunc_exp2l;
2723 Exp10Lb = LibFunc_exp10l;
2724 PowLb = LibFunc_powl;
2731 bool IsKnownNoErrno =
Log->hasNoNaNs() &&
Log->hasNoInfs();
2732 if (!IsKnownNoErrno) {
2733 SimplifyQuery SQ(DL, TLI, DT, AC, Log,
true,
true, DC);
2740 Known.cannotBeOrderedLessThanZero() &&
2741 Known.isKnownNeverLogicalZero(
F->getDenormalMode(FltSem));
2743 if (IsKnownNoErrno) {
2744 Value *NewLog =
B.CreateUnaryIntrinsic(LogID,
Log->getArgOperand(0), Log);
2746 I->copyMetadata(*Log);
2751 }
else if (LogID == Intrinsic::log || LogID == Intrinsic::log2 ||
2752 LogID == Intrinsic::log10) {
2754 ExpLb = LibFunc_expf;
2755 Exp2Lb = LibFunc_exp2f;
2756 Exp10Lb = LibFunc_exp10f;
2757 PowLb = LibFunc_powf;
2759 ExpLb = LibFunc_exp;
2760 Exp2Lb = LibFunc_exp2;
2761 Exp10Lb = LibFunc_exp10;
2762 PowLb = LibFunc_pow;
2773 IRBuilderBase::FastMathFlagGuard Guard(
B);
2777 LibFunc ArgLb = TLI->getLibFunc(*Arg);
2780 AttributeList NoAttrs;
2781 if (ArgLb == PowLb || ArgID == Intrinsic::pow || ArgID == Intrinsic::powi) {
2783 Log->doesNotAccessMemory()
2784 ?
B.CreateUnaryIntrinsic(LogID, Arg->
getOperand(0),
nullptr,
"log")
2788 if (ArgID == Intrinsic::powi)
2789 Y =
B.CreateSIToFP(
Y, Ty,
"cast");
2790 Value *MulY =
B.CreateFMul(
Y, LogX,
"mul");
2793 substituteInParent(Arg, MulY);
2799 if (ArgLb == ExpLb || ArgLb == Exp2Lb || ArgLb == Exp10Lb ||
2800 ArgID == Intrinsic::exp || ArgID == Intrinsic::exp2) {
2802 if (ArgLb == ExpLb || ArgID == Intrinsic::exp)
2805 else if (ArgLb == Exp2Lb || ArgID == Intrinsic::exp2)
2806 Eul = ConstantFP::get(
Log->getType(), 2.0);
2808 Eul = ConstantFP::get(
Log->getType(), 10.0);
2809 Value *LogE =
Log->doesNotAccessMemory()
2810 ?
B.CreateUnaryIntrinsic(LogID, Eul,
nullptr,
"log")
2815 substituteInParent(Arg, MulY);
2832 LibFunc ArgLb = TLI->getLibFunc(*Arg);
2834 LibFunc SqrtLb, ExpLb, Exp2Lb, Exp10Lb;
2836 SqrtLb = TLI->getLibFunc(SqrtFn->
getName());
2837 if (SqrtLb != NotLibFunc)
2840 ExpLb = LibFunc_expf;
2841 Exp2Lb = LibFunc_exp2f;
2842 Exp10Lb = LibFunc_exp10f;
2845 ExpLb = LibFunc_exp;
2846 Exp2Lb = LibFunc_exp2;
2847 Exp10Lb = LibFunc_exp10;
2850 ExpLb = LibFunc_expl;
2851 Exp2Lb = LibFunc_exp2l;
2852 Exp10Lb = LibFunc_exp10l;
2859 ExpLb = LibFunc_expf;
2860 Exp2Lb = LibFunc_exp2f;
2861 Exp10Lb = LibFunc_exp10f;
2863 ExpLb = LibFunc_exp;
2864 Exp2Lb = LibFunc_exp2;
2865 Exp10Lb = LibFunc_exp10;
2871 if (ArgLb != ExpLb && ArgLb != Exp2Lb && ArgLb != Exp10Lb &&
2872 ArgID != Intrinsic::exp && ArgID != Intrinsic::exp2)
2875 IRBuilderBase::InsertPointGuard Guard(
B);
2876 B.SetInsertPoint(Arg);
2879 B.CreateFMulFMF(ExpOperand, ConstantFP::get(ExpOperand->getType(), 0.5),
2889 Value *Ret =
nullptr;
2894 (
Callee->getName() ==
"sqrt" ||
2895 Callee->getIntrinsicID() == Intrinsic::sqrt))
2898 if (
Value *Opt = mergeSqrtToExp(CI,
B))
2905 if (!
I ||
I->getOpcode() != Instruction::FMul || !
I->isFast())
2911 Value *Op0 =
I->getOperand(0);
2912 Value *Op1 =
I->getOperand(1);
2913 Value *RepeatOp =
nullptr;
2914 Value *OtherOp =
nullptr;
2945 Value *FabsCall =
B.CreateFAbs(RepeatOp,
I,
"fabs");
2951 B.CreateUnaryIntrinsic(Intrinsic::sqrt, OtherOp,
I,
"sqrt");
2952 return copyFlags(*CI,
B.CreateFMulFMF(FabsCall, SqrtCall,
I));
2963 SimplifyQuery SQ(DL, TLI, DT, AC, CI,
true,
true, DC);
2966 KnownFPClass Known1 =
2969 const fltSemantics &FltSem =
2980Value *LibCallSimplifier::optimizeTrigInversionPairs(
CallInst *CI,
2984 Value *Ret =
nullptr;
2986 if (UnsafeFPShrink &&
2987 (Name ==
"tan" || Name ==
"atanh" || Name ==
"sinh" || Name ==
"cosh" ||
2989 hasFloatVersion(M, Name))
2998 if (!CI->
isFast() || !OpC->isFast())
3007 LibFunc
Func =
F ? TLI->getLibFunc(
F->getName()) : NotLibFunc;
3009 LibFunc inverseFunc = llvm::StringSwitch<LibFunc>(
Callee->getName())
3010 .Case(
"tan", LibFunc_atan)
3011 .Case(
"atanh", LibFunc_tanh)
3012 .Case(
"sinh", LibFunc_asinh)
3013 .Case(
"cosh", LibFunc_acosh)
3014 .Case(
"tanf", LibFunc_atanf)
3015 .Case(
"atanhf", LibFunc_tanhf)
3016 .Case(
"sinhf", LibFunc_asinhf)
3017 .Case(
"coshf", LibFunc_acoshf)
3018 .Case(
"tanl", LibFunc_atanl)
3019 .Case(
"atanhl", LibFunc_tanhl)
3020 .Case(
"sinhl", LibFunc_asinhl)
3021 .Case(
"coshl", LibFunc_acoshl)
3022 .Case(
"asinh", LibFunc_sinh)
3023 .Case(
"asinhf", LibFunc_sinhf)
3024 .Case(
"asinhl", LibFunc_sinhl)
3025 .Default(NotLibFunc);
3026 if (Func == inverseFunc)
3027 Ret = OpC->getArgOperand(0);
3049 Name =
"__sincospif_stret";
3058 Name =
"__sincospi_stret";
3066 M, *TLI, TheLibFunc, OrigCallee->
getAttributes(), ResTy, ArgTy);
3071 B.SetInsertPoint(ArgInst->getParent(), ++ArgInst->getIterator());
3075 BasicBlock &EntryBB =
B.GetInsertBlock()->getParent()->getEntryBlock();
3076 B.SetInsertPoint(&EntryBB, EntryBB.
begin());
3079 SinCos =
B.CreateCall(Callee, Arg,
"sincospi");
3082 Sin =
B.CreateExtractValue(SinCos, 0,
"sinpi");
3083 Cos =
B.CreateExtractValue(SinCos, 1,
"cospi");
3085 Sin =
B.CreateExtractElement(SinCos,
uint64_t{0},
"sinpi");
3086 Cos =
B.CreateExtractElement(SinCos,
uint64_t{1},
"cospi");
3118Value *LibCallSimplifier::optimizeSymmetric(
CallInst *CI, LibFunc Func,
3176 for (User *U : Arg->
users())
3177 classifyArgUse(U,
F, IsFloat, SinCalls, CosCalls, SinCosCalls);
3183 Value *Sin, *Cos, *SinCos;
3188 auto replaceTrigInsts = [
this](SmallVectorImpl<CallInst *> &Calls,
3190 for (CallInst *
C : Calls)
3191 replaceAllUsesWith(
C, Res);
3194 replaceTrigInsts(SinCalls, Sin);
3195 replaceTrigInsts(CosCalls, Cos);
3196 replaceTrigInsts(SinCosCalls, SinCos);
3198 return IsSin ? Sin : Cos;
3201void LibCallSimplifier::classifyArgUse(
3216 LibFunc
Func =
Callee ? TLI->getLibFunc(*Callee) : NotLibFunc;
3221 if (Func == LibFunc_sinpif)
3223 else if (Func == LibFunc_cospif)
3225 else if (Func == LibFunc_sincospif_stret)
3228 if (Func == LibFunc_sinpi)
3230 else if (Func == LibFunc_cospi)
3232 else if (Func == LibFunc_sincospi_stret)
3254 unsigned IntBW = TLI->getIntSize();
3255 APSInt QuotInt(IntBW,
false);
3262 B.CreateAlignedStore(
3265 return ConstantFP::get(CI->
getType(), Rem);
3292 return ConstantFP::get(CI->
getType(), Difference);
3304 Type *ArgType =
Op->getType();
3305 Value *
V =
B.CreateIntrinsic(Intrinsic::cttz, {ArgType}, {
Op,
B.getTrue()},
3307 V =
B.CreateAdd(V, ConstantInt::get(
V->getType(), 1));
3308 V =
B.CreateIntCast(V, RetType,
false);
3311 return B.CreateSelect(
Cond, V, ConstantInt::get(RetType, 0));
3318 Type *ArgType =
Op->getType();
3319 Value *
V =
B.CreateIntrinsic(Intrinsic::ctlz, {ArgType}, {
Op,
B.getFalse()},
3323 return B.CreateIntCast(V, CI->
getType(),
false);
3330 Value *IsNeg =
B.CreateIsNeg(
X);
3331 Value *NegX =
B.CreateNSWNeg(
X,
"neg");
3332 return B.CreateSelect(IsNeg, NegX,
X);
3338 Type *ArgType =
Op->getType();
3339 Op =
B.CreateSub(
Op, ConstantInt::get(ArgType,
'0'),
"isdigittmp");
3340 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 10),
"isdigit");
3347 Type *ArgType =
Op->getType();
3348 Op =
B.CreateICmpULT(
Op, ConstantInt::get(ArgType, 128),
"isascii");
3355 ConstantInt::get(CI->
getType(), 0x7F));
3385 return convertStrToInt(CI, Str, EndPtr, CInt->getSExtValue(), AsSigned,
B);
3417 if (!Callee || !Callee->isDeclaration())
3426 if (StreamArg >= (
int)CI->
arg_size())
3434 return GV->
getName() ==
"stderr";
3439 StringRef FormatStr;
3444 if (FormatStr.
empty())
3455 if (FormatStr.
size() == 1 || FormatStr ==
"%%") {
3459 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)FormatStr[0]);
3460 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3464 if (FormatStr ==
"%s" && CI->
arg_size() > 1) {
3465 StringRef OperandStr;
3466 if (!getConstantStringInfo(CI->getOperand(1), OperandStr))
3469 if (OperandStr.empty())
3472 if (OperandStr.size() == 1) {
3476 Value *IntChar = ConstantInt::get(IntTy, (unsigned char)OperandStr[0]);
3477 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3480 if (OperandStr.back() ==
'\n') {
3481 if (!isLibFuncEmittable(CI->getModule(), TLI, LibFunc_puts))
3483 OperandStr = OperandStr.drop_back();
3484 Value *GV = B.CreateGlobalString(OperandStr,
"str");
3485 return copyFlags(*CI, emitPutS(GV, B, TLI));
3491 if (FormatStr.
back() ==
'\n' &&
3493 if (!isLibFuncEmittable(CI->getModule(), TLI, LibFunc_puts))
3497 FormatStr = FormatStr.drop_back();
3498 Value *GV = B.CreateGlobalString(FormatStr,
"str");
3499 return copyFlags(*CI, emitPutS(GV, B, TLI));
3504 if (FormatStr ==
"%c" && CI->
arg_size() > 1 &&
3508 Value *IntChar = B.CreateIntCast(CI->getArgOperand(1), IntTy, false);
3509 return copyFlags(*CI, emitPutChar(IntChar, B, TLI));
3513 if (FormatStr ==
"%s\n" && CI->
arg_size() > 1 &&
3523 FunctionType *FT =
Callee->getFunctionType();
3524 if (
Value *V = optimizePrintFString(CI,
B)) {
3535 Callee->getAttributes());
3537 New->setCalledFunction(IPrintFFn);
3547 Callee->getAttributes());
3549 New->setCalledFunction(SmallPrintFFn);
3557Value *LibCallSimplifier::optimizeSPrintFString(
CallInst *CI,
3560 StringRef FormatStr;
3576 return ConstantInt::get(CI->
getType(), FormatStr.
size());
3581 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3585 if (FormatStr[1] ==
'c') {
3591 B.CreateStore(V, Ptr);
3592 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Ptr,
B.getInt32(1),
"nul");
3593 B.CreateStore(
B.getInt8(0), Ptr);
3595 return ConstantInt::get(CI->
getType(), 1);
3598 if (FormatStr[1] ==
's') {
3611 TLI->getAsSizeT(SrcLen, *CI->
getModule()));
3613 return ConstantInt::get(CI->
getType(), SrcLen - 1);
3616 Value *PtrDiff =
B.CreatePtrDiff(V, Dest);
3617 return B.CreateIntCast(PtrDiff, CI->
getType(),
false);
3628 B.CreateAdd(Len, ConstantInt::get(
Len->getType(), 1),
"leninc");
3632 return B.CreateIntCast(Len, CI->
getType(),
false);
3640 FunctionType *FT =
Callee->getFunctionType();
3641 if (
Value *V = optimizeSPrintFString(CI,
B)) {
3652 FT,
Callee->getAttributes());
3654 New->setCalledFunction(SIPrintFFn);
3664 Callee->getAttributes());
3666 New->setCalledFunction(SmallSPrintFFn);
3682 assert(StrArg || (
N < 2 && Str.size() == 1));
3684 unsigned IntBits = TLI->getIntSize();
3686 if (Str.size() > IntMax)
3692 Value *StrLen = ConstantInt::get(CI->
getType(), Str.size());
3702 NCopy = Str.size() + 1;
3707 if (NCopy && StrArg)
3710 TLI->getAsSizeT(NCopy, *CI->
getModule())));
3719 Value *NulOff =
B.getIntN(IntBits, NCopy);
3720 Value *DstEnd =
B.CreateInBoundsGEP(Int8Ty, DstArg, NulOff,
"endptr");
3721 B.CreateStore(ConstantInt::get(Int8Ty, 0), DstEnd);
3725Value *LibCallSimplifier::optimizeSnPrintFString(
CallInst *CI,
3743 StringRef FormatStr;
3754 return emitSnPrintfMemCpy(CI, FmtArg, FormatStr,
N,
B);
3759 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() != 4)
3763 if (FormatStr[1] ==
'c') {
3768 StringRef CharStr(
"*");
3769 return emitSnPrintfMemCpy(CI,
nullptr, CharStr,
N,
B);
3776 Value *Ptr = DstArg;
3777 B.CreateStore(V, Ptr);
3778 Ptr =
B.CreateInBoundsGEP(
B.getInt8Ty(), Ptr,
B.getInt32(1),
"nul");
3779 B.CreateStore(
B.getInt8(0), Ptr);
3780 return ConstantInt::get(CI->
getType(), 1);
3783 if (FormatStr[1] !=
's')
3792 return emitSnPrintfMemCpy(CI, StrArg, Str,
N,
B);
3796 if (
Value *V = optimizeSnPrintFString(CI,
B)) {
3805Value *LibCallSimplifier::optimizeFPrintFString(
CallInst *CI,
3807 optimizeErrorReporting(CI,
B, 0);
3810 StringRef FormatStr;
3834 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' || CI->
arg_size() < 3)
3838 if (FormatStr[1] ==
'c') {
3842 Type *IntTy =
B.getIntNTy(TLI->getIntSize());
3848 if (FormatStr[1] ==
's') {
3861 FunctionType *FT =
Callee->getFunctionType();
3862 if (
Value *V = optimizeFPrintFString(CI,
B)) {
3871 FT,
Callee->getAttributes());
3873 New->setCalledFunction(FIPrintFFn);
3882 auto SmallFPrintFFn =
3884 Callee->getAttributes());
3886 New->setCalledFunction(SmallFPrintFFn);
3895 optimizeErrorReporting(CI,
B, 3);
3900 if (SizeC && CountC) {
3905 return ConstantInt::get(CI->
getType(), 0);
3912 Value *Cast =
B.CreateIntCast(Char, IntTy,
true,
"chari");
3914 return NewCI ? ConstantInt::get(CI->
getType(), 1) : nullptr;
3922 optimizeErrorReporting(CI,
B, 1);
3940 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
3945 ConstantInt::get(SizeTTy, Len - 1),
3985bool LibCallSimplifier::hasFloatVersion(
const Module *M,
StringRef FuncName) {
3986 SmallString<20> FloatFuncName = FuncName;
3987 FloatFuncName +=
'f';
3991Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
3995 LibFunc
Func = TLI->getLibFunc(*Callee);
4003 "Optimizing string/memory libcall would change the calling convention");
4005 case LibFunc_strcat:
4006 return optimizeStrCat(CI, Builder);
4007 case LibFunc_strncat:
4008 return optimizeStrNCat(CI, Builder);
4009 case LibFunc_strchr:
4010 return optimizeStrChr(CI, Builder);
4011 case LibFunc_strrchr:
4012 return optimizeStrRChr(CI, Builder);
4013 case LibFunc_strcmp:
4014 return optimizeStrCmp(CI, Builder);
4015 case LibFunc_strncmp:
4016 return optimizeStrNCmp(CI, Builder);
4017 case LibFunc_strcpy:
4018 return optimizeStrCpy(CI, Builder);
4019 case LibFunc_stpcpy:
4020 return optimizeStpCpy(CI, Builder);
4021 case LibFunc_strlcpy:
4022 return optimizeStrLCpy(CI, Builder);
4023 case LibFunc_stpncpy:
4024 return optimizeStringNCpy(CI,
true, Builder);
4025 case LibFunc_strncpy:
4026 return optimizeStringNCpy(CI,
false, Builder);
4027 case LibFunc_strlen:
4028 return optimizeStrLen(CI, Builder);
4029 case LibFunc_strnlen:
4030 return optimizeStrNLen(CI, Builder);
4031 case LibFunc_strpbrk:
4032 return optimizeStrPBrk(CI, Builder);
4033 case LibFunc_strndup:
4034 return optimizeStrNDup(CI, Builder);
4035 case LibFunc_strtol:
4036 case LibFunc_strtod:
4037 case LibFunc_strtof:
4038 case LibFunc_strtoul:
4039 case LibFunc_strtoll:
4040 case LibFunc_strtold:
4041 case LibFunc_strtoull:
4042 return optimizeStrTo(CI, Builder);
4043 case LibFunc_strspn:
4044 return optimizeStrSpn(CI, Builder);
4045 case LibFunc_strcspn:
4046 return optimizeStrCSpn(CI, Builder);
4047 case LibFunc_strstr:
4048 return optimizeStrStr(CI, Builder);
4049 case LibFunc_memchr:
4050 return optimizeMemChr(CI, Builder);
4051 case LibFunc_memrchr:
4052 return optimizeMemRChr(CI, Builder);
4054 return optimizeBCmp(CI, Builder);
4055 case LibFunc_memcmp:
4056 return optimizeMemCmp(CI, Builder);
4057 case LibFunc_memcpy:
4058 return optimizeMemCpy(CI, Builder);
4059 case LibFunc_memccpy:
4060 return optimizeMemCCpy(CI, Builder);
4061 case LibFunc_mempcpy:
4062 return optimizeMemPCpy(CI, Builder);
4063 case LibFunc_memmove:
4064 return optimizeMemMove(CI, Builder);
4065 case LibFunc_memset:
4066 return optimizeMemSet(CI, Builder);
4067 case LibFunc_realloc:
4068 return optimizeRealloc(CI, Builder);
4069 case LibFunc_wcslen:
4070 return optimizeWcslen(CI, Builder);
4072 return optimizeBCopy(CI, Builder);
4074 case LibFunc_ZnwmRKSt9nothrow_t:
4075 case LibFunc_ZnwmSt11align_val_t:
4076 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
4078 case LibFunc_ZnamRKSt9nothrow_t:
4079 case LibFunc_ZnamSt11align_val_t:
4080 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
4081 case LibFunc_Znwm12__hot_cold_t:
4082 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
4083 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
4084 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
4085 case LibFunc_Znam12__hot_cold_t:
4086 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
4087 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
4088 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
4089 case LibFunc_size_returning_new:
4090 case LibFunc_size_returning_new_hot_cold:
4091 case LibFunc_size_returning_new_aligned:
4092 case LibFunc_size_returning_new_aligned_hot_cold:
4093 return optimizeNew(CI, Builder, Func);
4109 if (CharSeq.
empty())
4110 Fill =
APInt(32, 0);
4117Value *LibCallSimplifier::optimizeFloatingPointLibCall(
CallInst *CI,
4126 if (
Value *V = optimizeSymmetric(CI, Func, Builder))
4130 case LibFunc_sinpif:
4132 return optimizeSinCosPi(CI,
true, Builder);
4133 case LibFunc_cospif:
4135 return optimizeSinCosPi(CI,
false, Builder);
4149 return optimizePow(CI, Builder);
4153 return optimizeExp2(CI, Builder);
4161 return optimizeSqrt(CI, Builder);
4165 return optimizeFMod(CI, Builder);
4169 case LibFunc_log10f:
4171 case LibFunc_log10l:
4172 case LibFunc_log1pf:
4174 case LibFunc_log1pl:
4181 return optimizeLog(CI, Builder);
4189 case LibFunc_asinhf:
4190 case LibFunc_asinhl:
4195 case LibFunc_atanhf:
4196 case LibFunc_atanhl:
4197 return optimizeTrigInversionPairs(CI, Builder);
4204 case LibFunc_roundeven:
4206 case LibFunc_nearbyint:
4214 if (UnsafeFPShrink &&
4220 CI, Builder, Func == LibFunc_sin ? Intrinsic::sin : Intrinsic::cos);
4234 case LibFunc_copysign:
4241 return optimizeFdim(CI, Builder);
4245 return optimizeFMinFMax(CI, Builder, Intrinsic::minnum);
4249 return optimizeFMinFMax(CI, Builder, Intrinsic::maxnum);
4250 case LibFunc_fminimum_numf:
4251 case LibFunc_fminimum_num:
4252 case LibFunc_fminimum_numl:
4254 case LibFunc_fmaximum_numf:
4255 case LibFunc_fmaximum_num:
4256 case LibFunc_fmaximum_numl:
4261 return optimizeCAbs(CI, Builder);
4262 case LibFunc_remquo:
4263 case LibFunc_remquof:
4264 case LibFunc_remquol:
4265 return optimizeRemquo(CI, Builder);
4284 return maybeOptimizeNoBuiltinOperatorNew(CI, Builder);
4288 LibFunc Func = TLI->getLibFunc(*Callee);
4295 Builder.setDefaultOperandBundles(OpBundles);
4303 UnsafeFPShrink =
true;
4307 if (!IsCallingConvC)
4311 switch (
II->getIntrinsicID()) {
4312 case Intrinsic::pow:
4313 return optimizePow(CI, Builder);
4314 case Intrinsic::exp2:
4315 return optimizeExp2(CI, Builder);
4316 case Intrinsic::log:
4317 case Intrinsic::log2:
4318 case Intrinsic::log10:
4319 return optimizeLog(CI, Builder);
4320 case Intrinsic::sqrt:
4321 return optimizeSqrt(CI, Builder);
4322 case Intrinsic::memset:
4323 return optimizeMemSet(CI, Builder);
4324 case Intrinsic::memcpy:
4325 return optimizeMemCpy(CI, Builder);
4326 case Intrinsic::memmove:
4327 return optimizeMemMove(CI, Builder);
4328 case Intrinsic::sin:
4329 case Intrinsic::cos:
4333 case Intrinsic::sincos:
4343 if (
Value *SimplifiedFortifiedCI =
4344 FortifiedSimplifier.optimizeCall(CI, Builder))
4345 return SimplifiedFortifiedCI;
4352 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
4354 if (
Value *V = optimizeFloatingPointLibCall(CI, Func, Builder))
4360 return optimizeFFS(CI, Builder);
4364 return optimizeFls(CI, Builder);
4368 return optimizeAbs(CI, Builder);
4369 case LibFunc_isdigit:
4370 return optimizeIsDigit(CI, Builder);
4371 case LibFunc_isascii:
4372 return optimizeIsAscii(CI, Builder);
4373 case LibFunc_toascii:
4374 return optimizeToAscii(CI, Builder);
4378 return optimizeAtoi(CI, Builder);
4379 case LibFunc_strtol:
4380 case LibFunc_strtoll:
4381 return optimizeStrToInt(CI, Builder,
true);
4382 case LibFunc_strtoul:
4383 case LibFunc_strtoull:
4384 return optimizeStrToInt(CI, Builder,
false);
4385 case LibFunc_printf:
4386 return optimizePrintF(CI, Builder);
4387 case LibFunc_sprintf:
4388 return optimizeSPrintF(CI, Builder);
4389 case LibFunc_snprintf:
4390 return optimizeSnPrintF(CI, Builder);
4391 case LibFunc_fprintf:
4392 return optimizeFPrintF(CI, Builder);
4393 case LibFunc_fwrite:
4394 return optimizeFWrite(CI, Builder);
4396 return optimizeFPuts(CI, Builder);
4398 return optimizePuts(CI, Builder);
4399 case LibFunc_perror:
4400 return optimizeErrorReporting(CI, Builder);
4401 case LibFunc_vfprintf:
4402 case LibFunc_fiprintf:
4403 return optimizeErrorReporting(CI, Builder, 0);
4406 return optimizeExit(CI);
4420 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), DT(DT), DC(DC), AC(AC),
4421 ORE(ORE), BFI(BFI), PSI(PSI), Replacer(Replacer), Eraser(Eraser) {}
4428void LibCallSimplifier::eraseFromParent(
Instruction *
I) {
4467bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
4468 CallInst *CI,
unsigned ObjSizeOp, std::optional<unsigned> SizeOp,
4469 std::optional<unsigned> StrOp, std::optional<unsigned> FlagOp) {
4474 if (!Flag || !
Flag->isZero())
4481 if (ConstantInt *ObjSizeCI =
4483 if (ObjSizeCI->isMinusOne())
4486 if (OnlyLowerUnknownSize)
4496 return ObjSizeCI->getZExtValue() >=
Len;
4500 if (ConstantInt *SizeCI =
4502 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
4508Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
4510 if (isFortifiedCallFoldable(CI, 3, 2)) {
4520Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
4522 if (isFortifiedCallFoldable(CI, 3, 2)) {
4532Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
4534 if (isFortifiedCallFoldable(CI, 3, 2)) {
4544Value *FortifiedLibCallSimplifier::optimizeMemPCpyChk(
CallInst *CI,
4547 if (isFortifiedCallFoldable(CI, 3, 2))
4555Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
4563 if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
4565 return StrLen ?
B.CreateInBoundsGEP(
B.getInt8Ty(), Dst, StrLen) :
nullptr;
4573 if (isFortifiedCallFoldable(CI, 2, std::nullopt, 1)) {
4574 if (Func == LibFunc_strcpy_chk)
4580 if (OnlyLowerUnknownSize)
4590 unsigned SizeTBits = TLI->getSizeTSize(*CI->
getModule());
4592 Value *LenV = ConstantInt::get(SizeTTy, Len);
4596 if (Ret && Func == LibFunc_stpcpy_chk)
4597 return B.CreateInBoundsGEP(
B.getInt8Ty(), Dst,
4598 ConstantInt::get(SizeTTy, Len - 1));
4602Value *FortifiedLibCallSimplifier::optimizeStrLenChk(
CallInst *CI,
4604 if (isFortifiedCallFoldable(CI, 1, std::nullopt, 0))
4610Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
4613 if (isFortifiedCallFoldable(CI, 3, 2)) {
4614 if (Func == LibFunc_strncpy_chk)
4627Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(
CallInst *CI,
4629 if (isFortifiedCallFoldable(CI, 4, 3))
4637Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(
CallInst *CI,
4639 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2)) {
4649Value *FortifiedLibCallSimplifier::optimizeSPrintfChk(
CallInst *CI,
4651 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1)) {
4655 VariadicArgs,
B, TLI));
4661Value *FortifiedLibCallSimplifier::optimizeStrCatChk(
CallInst *CI,
4663 if (isFortifiedCallFoldable(CI, 2))
4670Value *FortifiedLibCallSimplifier::optimizeStrLCat(
CallInst *CI,
4672 if (isFortifiedCallFoldable(CI, 3))
4680Value *FortifiedLibCallSimplifier::optimizeStrNCatChk(
CallInst *CI,
4682 if (isFortifiedCallFoldable(CI, 3))
4690Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(
CallInst *CI,
4692 if (isFortifiedCallFoldable(CI, 3))
4700Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(
CallInst *CI,
4702 if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2))
4710Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(
CallInst *CI,
4712 if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1))
4742 Builder.setDefaultOperandBundles(OpBundles);
4746 LibFunc Func = TLI->getLibFunc(*Callee);
4747 if (Func == NotLibFunc)
4755 case LibFunc_memcpy_chk:
4756 return optimizeMemCpyChk(CI, Builder);
4757 case LibFunc_mempcpy_chk:
4758 return optimizeMemPCpyChk(CI, Builder);
4759 case LibFunc_memmove_chk:
4760 return optimizeMemMoveChk(CI, Builder);
4761 case LibFunc_memset_chk:
4762 return optimizeMemSetChk(CI, Builder);
4763 case LibFunc_stpcpy_chk:
4764 case LibFunc_strcpy_chk:
4765 return optimizeStrpCpyChk(CI, Builder, Func);
4766 case LibFunc_strlen_chk:
4767 return optimizeStrLenChk(CI, Builder);
4768 case LibFunc_stpncpy_chk:
4769 case LibFunc_strncpy_chk:
4770 return optimizeStrpNCpyChk(CI, Builder, Func);
4771 case LibFunc_memccpy_chk:
4772 return optimizeMemCCpyChk(CI, Builder);
4773 case LibFunc_snprintf_chk:
4774 return optimizeSNPrintfChk(CI, Builder);
4775 case LibFunc_sprintf_chk:
4776 return optimizeSPrintfChk(CI, Builder);
4777 case LibFunc_strcat_chk:
4778 return optimizeStrCatChk(CI, Builder);
4779 case LibFunc_strlcat_chk:
4780 return optimizeStrLCat(CI, Builder);
4781 case LibFunc_strncat_chk:
4782 return optimizeStrNCatChk(CI, Builder);
4783 case LibFunc_strlcpy_chk:
4784 return optimizeStrLCpyChk(CI, Builder);
4785 case LibFunc_vsnprintf_chk:
4786 return optimizeVSNPrintfChk(CI, Builder);
4787 case LibFunc_vsprintf_chk:
4788 return optimizeVSPrintfChk(CI, Builder);
4797 : 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")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Module.h This file contains the declarations for the Module class.
static llvm::Error parse(GsymDataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
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 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 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"))
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.".
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.
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.
LibFunc getLibFunc(StringRef funcName) 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.
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 * 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.
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 Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
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 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 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 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 * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
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 * 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.
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 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.
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.