38 using namespace PatternMatch;
43 cl::desc(
"Enable unsafe double to float "
44 "shrinking for math lib calls"));
52 return Func == LibFunc_abs || Func == LibFunc_labs ||
53 Func == LibFunc_llabs || Func == LibFunc_strlen;
73 if (!FuncTy->getReturnType()->isPointerTy() &&
74 !FuncTy->getReturnType()->isIntegerTy() &&
75 !FuncTy->getReturnType()->isVoidTy())
78 for (
auto Param : FuncTy->params()) {
79 if (!Param->isPointerTy() && !Param->isIntegerTy())
91 if (
ICmpInst *IC = dyn_cast<ICmpInst>(U))
92 if (IC->isEquality() && IC->getOperand(1) == With)
102 return OI->getType()->isFloatingPointTy();
113 return TLI->
has(FloatFn);
115 return TLI->
has(DoubleFn);
117 return TLI->
has(LongDoubleFn);
140 return emitStrLenMemCpy(Src, Dst, Len, B);
143 Value *LibCallSimplifier::emitStrLenMemCpy(
Value *Src,
Value *Dst, uint64_t Len,
172 Len = LengthArg->getZExtValue();
185 if (SrcLen == 0 || Len == 0)
194 return emitStrLenMemCpy(Src, Dst, SrcLen, B);
274 if (HasStr1 && HasStr2)
277 if (HasStr1 && Str1.empty())
281 if (HasStr2 && Str2.empty())
305 Length = LengthArg->getZExtValue();
320 if (HasStr1 && HasStr2) {
326 if (HasStr1 && Str1.empty())
330 if (HasStr2 && Str2.empty())
396 if (
ConstantInt *LengthArg = dyn_cast<ConstantInt>(LenOp))
397 Len = LengthArg->getZExtValue();
405 if (Len > SrcLen + 1)
437 uint64_t NullTermIdx;
438 if (Slice.
Array ==
nullptr) {
441 NullTermIdx = ~((uint64_t)0);
442 for (uint64_t I = 0,
E = Slice.
Length; I <
E; ++I) {
450 if (NullTermIdx == ~((uint64_t)0))
458 cast<ArrayType>(
GEP->getSourceElementType())->getNumElements();
471 (
GEP->isInBounds() && isa<GlobalVariable>(
GEP->getOperand(0)) &&
472 NullTermIdx == ArrSize - 1)) {
483 if (
SelectInst *SI = dyn_cast<SelectInst>(Src)) {
486 if (LenTrue && LenFalse) {
490 "folded strlen(select) to select of constants");
506 return optimizeStringLength(CI, B, 8);
511 unsigned WCharSize = TLI->getWCharSize(M) * 8;
513 return optimizeStringLength(CI, B, WCharSize);
523 if ((HasS1 && S1.
empty()) || (HasS2 && S2.
empty()))
527 if (HasS1 && HasS2) {
537 if (HasS2 && S2.
size() == 1)
545 if (isa<ConstantPointerNull>(EndPtr)) {
561 if ((HasS1 && S1.
empty()) || (HasS2 && S2.
empty()))
565 if (HasS1 && HasS2) {
581 if (HasS1 && S1.
empty())
585 if (HasS1 && HasS2) {
593 if (HasS2 && S2.
empty())
614 ICmpInst *Old = cast<ICmpInst>(*UI++);
618 replaceAllUsesWith(Old, Cmp);
629 if (HasStr2 && ToFindStr.
empty())
633 if (HasStr1 && HasStr2) {
634 size_t Offset = SearchStr.
find(ToFindStr);
641 Result = B.CreateConstInBoundsGEP1_64(Result, Offset,
"strstr");
642 return B.CreateBitCast(Result, CI->
getType());
646 if (HasStr2 && ToFindStr.
size() == 1) {
648 return StrChr ? B.CreateBitCast(StrChr, CI->
getType()) :
nullptr;
659 if (LenC && LenC->isZero())
670 Str = Str.
substr(0, LenC->getZExtValue());
683 *std::max_element(reinterpret_cast<const unsigned char *>(Str.
begin()),
684 reinterpret_cast<const unsigned char *>(Str.
end()));
691 if (!DL.fitsInLegalInteger(Max + 1))
752 return B.
CreateSub(LHSV, RHSV,
"chardiff");
759 unsigned PrefAlignment = DL.getPrefTypeAlignment(IntType);
767 IntType->
getPointerTo(RHS->getType()->getPointerAddressSpace());
783 if (Len > LHSStr.
size() || Len > RHSStr.
size())
788 int Cmp = memcmp(LHSStr.
data(), RHSStr.
data(), Len);
839 if (!FillValue || FillValue->getZExtValue() != 0)
847 if (!Malloc || !Malloc->hasOneUse())
851 Function *InnerCallee = Malloc->getCalledFunction();
857 Func != LibFunc_malloc)
867 const DataLayout &DL = Malloc->getModule()->getDataLayout();
870 Malloc->getArgOperand(0), Malloc->getAttributes(),
876 Malloc->eraseFromParent();
901 if (
FPExtInst *Cast = dyn_cast<FPExtInst>(Val)) {
902 Value *
Op = Cast->getOperand(0);
906 if (
ConstantFP *Const = dyn_cast<ConstantFP>(Val)) {
951 if ((FName.
size() == (CalleeName.
size() + 1)) &&
952 (FName.
back() ==
'f') &&
1019 Value *Ret =
nullptr;
1021 if (UnsafeFPShrink && Name ==
"cos" && hasFloatVersion(Name))
1037 assert(Exp != 0 &&
"Incorrect exponent 0 not handled");
1039 if (InnerChain[Exp])
1040 return InnerChain[Exp];
1042 static const unsigned AddChain[33][2] = {
1046 {1, 2}, {2, 2}, {2, 3}, {3, 3}, {2, 5}, {4, 4},
1047 {1, 8}, {5, 5}, {1, 10}, {6, 6}, {4, 9}, {7, 7},
1048 {3, 12}, {8, 8}, {8, 9}, {2, 16}, {1, 18}, {10, 10},
1049 {6, 15}, {11, 11}, {3, 20}, {12, 12}, {8, 17}, {13, 13},
1050 {3, 24}, {14, 14}, {4, 25}, {15, 15}, {3, 28}, {16, 16},
1054 getPow(InnerChain, AddChain[Exp][1], B));
1055 return InnerChain[Exp];
1060 Value *Ret =
nullptr;
1062 if (UnsafeFPShrink && Name ==
"pow" && hasFloatVersion(Name))
1079 if (
ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
1081 if (Op1C->isExactlyValue(10.0) &&
1097 Function *OpCCallee = OpC->getCalledFunction();
1098 if (OpCCallee && TLI->getLibFunc(OpCCallee->
getName(), Func) &&
1099 TLI->has(Func) && (Func == LibFunc_exp || Func == LibFunc_exp2)) {
1193 Value *InnerChain[33] = {
nullptr};
1194 InnerChain[1] = Op1;
1214 Value *Ret =
nullptr;
1216 if (UnsafeFPShrink && Name ==
"exp2" && hasFloatVersion(Name))
1222 LibFunc LdExp = LibFunc_ldexpl;
1224 LdExp = LibFunc_ldexpf;
1226 LdExp = LibFunc_ldexp;
1228 if (TLI->has(LdExp)) {
1229 Value *LdExpArg =
nullptr;
1230 if (
SIToFPInst *OpC = dyn_cast<SIToFPInst>(Op)) {
1231 if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() <= 32)
1233 }
else if (
UIToFPInst *OpC = dyn_cast<UIToFPInst>(Op)) {
1234 if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() < 32)
1262 if ((Name ==
"fmin" || Name ==
"fmax") && hasFloatVersion(Name))
1296 Value *Ret =
nullptr;
1298 if (UnsafeFPShrink && hasFloatVersion(Name))
1307 if (!OpC || !OpC->hasUnsafeAlgebra())
1312 if (Name !=
"log" && Name !=
"log2" && Name !=
"log10")
1322 if (F && ((TLI->getLibFunc(F->
getName(), Func) && TLI->has(Func) &&
1329 if (F && Name ==
"log" && TLI->getLibFunc(F->
getName(), Func) &&
1330 TLI->has(Func) && Func == LibFunc_exp2)
1332 OpC->getArgOperand(0),
1341 Value *Ret =
nullptr;
1345 if (TLI->has(LibFunc_sqrtf) && (Callee->
getName() ==
"sqrt" ||
1361 Value *RepeatOp =
nullptr;
1362 Value *OtherOp =
nullptr;
1372 Value *OtherMul0, *OtherMul1;
1375 if (OtherMul0 == OtherMul1 &&
1376 cast<Instruction>(Op0)->hasUnsafeAlgebra()) {
1378 RepeatOp = OtherMul0;
1411 Value *Ret =
nullptr;
1413 if (UnsafeFPShrink && Name ==
"tan" && hasFloatVersion(Name))
1429 Function *F = OpC->getCalledFunction();
1430 if (F && TLI->getLibFunc(F->
getName(), Func) && TLI->has(Func) &&
1431 ((Func == LibFunc_atan && Callee->
getName() ==
"tan") ||
1432 (Func == LibFunc_atanf && Callee->
getName() ==
"tanf") ||
1433 (Func == LibFunc_atanl && Callee->
getName() ==
"tanl")))
1434 Ret = OpC->getArgOperand(0);
1442 return CI->
hasFnAttr(Attribute::NoUnwind) &&
1455 Name =
"__sincospif_stret";
1464 Name =
"__sincospi_stret";
1472 if (
Instruction *ArgInst = dyn_cast<Instruction>(Arg)) {
1475 B.
SetInsertPoint(ArgInst->getParent(), ++ArgInst->getIterator());
1483 SinCos = B.
CreateCall(Callee, Arg,
"sincospi");
1514 classifyArgUse(U, F, IsFloat, SinCalls, CosCalls, SinCosCalls);
1520 Value *Sin, *Cos, *SinCos;
1526 replaceAllUsesWith(C, Res);
1529 replaceTrigInsts(SinCalls, Sin);
1530 replaceTrigInsts(CosCalls, Cos);
1531 replaceTrigInsts(SinCosCalls, SinCos);
1536 void LibCallSimplifier::classifyArgUse(
1552 if (!Callee || !TLI->getLibFunc(*Callee, Func) || !TLI->has(Func) ||
1557 if (Func == LibFunc_sinpif)
1559 else if (Func == LibFunc_cospif)
1561 else if (Func == LibFunc_sincospif_stret)
1564 if (Func == LibFunc_sinpi)
1566 else if (Func == LibFunc_cospi)
1568 else if (Func == LibFunc_sincospi_stret)
1582 Intrinsic::cttz, ArgType);
1596 Intrinsic::ctlz, ArgType);
1676 return GV->
getName() ==
"stderr";
1686 if (FormatStr.
empty())
1696 if (FormatStr.
size() == 1 || FormatStr ==
"%%")
1704 if (ChrStr.
size() != 1)
1710 if (FormatStr[FormatStr.
size() - 1] ==
'\n' &&
1736 if (
Value *V = optimizePrintFString(CI, B)) {
1764 for (
unsigned i = 0, e = FormatStr.
size(); i != e; ++i)
1765 if (FormatStr[i] ==
'%')
1771 FormatStr.
size() + 1),
1778 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' ||
1783 if (FormatStr[1] ==
'c') {
1796 if (FormatStr[1] ==
's') {
1817 if (
Value *V = optimizeSPrintFString(CI, B)) {
1836 optimizeErrorReporting(CI, B, 0);
1851 for (
unsigned i = 0, e = FormatStr.
size(); i != e; ++i)
1852 if (FormatStr[i] ==
'%')
1863 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' ||
1868 if (FormatStr[1] ==
'c') {
1875 if (FormatStr[1] ==
's') {
1887 if (
Value *V = optimizeFPrintFString(CI, B)) {
1906 optimizeErrorReporting(CI, B, 3);
1911 if (!SizeC || !CountC)
1913 uint64_t Bytes = SizeC->
getZExtValue() * CountC->getZExtValue();
1931 optimizeErrorReporting(CI, B, 1);
1971 bool LibCallSimplifier::hasFloatVersion(
StringRef FuncName) {
1974 FloatFuncName +=
'f';
1975 if (TLI->getLibFunc(FloatFuncName, Func))
1976 return TLI->has(Func);
1980 Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
1985 if (TLI->getLibFunc(*Callee, Func) && TLI->has(Func)) {
1989 "Optimizing string/memory libcall would change the calling convention");
1991 case LibFunc_strcat:
1992 return optimizeStrCat(CI, Builder);
1993 case LibFunc_strncat:
1994 return optimizeStrNCat(CI, Builder);
1995 case LibFunc_strchr:
1996 return optimizeStrChr(CI, Builder);
1997 case LibFunc_strrchr:
1998 return optimizeStrRChr(CI, Builder);
1999 case LibFunc_strcmp:
2000 return optimizeStrCmp(CI, Builder);
2001 case LibFunc_strncmp:
2002 return optimizeStrNCmp(CI, Builder);
2003 case LibFunc_strcpy:
2004 return optimizeStrCpy(CI, Builder);
2005 case LibFunc_stpcpy:
2006 return optimizeStpCpy(CI, Builder);
2007 case LibFunc_strncpy:
2008 return optimizeStrNCpy(CI, Builder);
2009 case LibFunc_strlen:
2010 return optimizeStrLen(CI, Builder);
2011 case LibFunc_strpbrk:
2012 return optimizeStrPBrk(CI, Builder);
2013 case LibFunc_strtol:
2014 case LibFunc_strtod:
2015 case LibFunc_strtof:
2016 case LibFunc_strtoul:
2017 case LibFunc_strtoll:
2018 case LibFunc_strtold:
2019 case LibFunc_strtoull:
2020 return optimizeStrTo(CI, Builder);
2021 case LibFunc_strspn:
2022 return optimizeStrSpn(CI, Builder);
2023 case LibFunc_strcspn:
2024 return optimizeStrCSpn(CI, Builder);
2025 case LibFunc_strstr:
2026 return optimizeStrStr(CI, Builder);
2027 case LibFunc_memchr:
2028 return optimizeMemChr(CI, Builder);
2029 case LibFunc_memcmp:
2030 return optimizeMemCmp(CI, Builder);
2031 case LibFunc_memcpy:
2032 return optimizeMemCpy(CI, Builder);
2033 case LibFunc_memmove:
2034 return optimizeMemMove(CI, Builder);
2035 case LibFunc_memset:
2036 return optimizeMemSet(CI, Builder);
2037 case LibFunc_wcslen:
2038 return optimizeWcslen(CI, Builder);
2063 UnsafeFPShrink =
true;
2067 if (!isCallingConvC)
2069 switch (II->getIntrinsicID()) {
2070 case Intrinsic::pow:
2071 return optimizePow(CI, Builder);
2072 case Intrinsic::exp2:
2073 return optimizeExp2(CI, Builder);
2074 case Intrinsic::log:
2075 return optimizeLog(CI, Builder);
2076 case Intrinsic::sqrt:
2077 return optimizeSqrt(CI, Builder);
2085 if (
Value *SimplifiedFortifiedCI = FortifiedSimplifier.optimizeCall(CI)) {
2092 if (
Value *V = optimizeStringMemoryLibCall(SimplifiedCI, TmpBuilder)) {
2099 return SimplifiedFortifiedCI;
2103 if (TLI->getLibFunc(*Callee, Func) && TLI->has(Func)) {
2107 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
2113 return optimizeCos(CI, Builder);
2114 case LibFunc_sinpif:
2116 case LibFunc_cospif:
2118 return optimizeSinCosPi(CI, Builder);
2122 return optimizePow(CI, Builder);
2126 return optimizeExp2(CI, Builder);
2134 return optimizeSqrt(CI, Builder);
2138 return optimizeFFS(CI, Builder);
2142 return optimizeFls(CI, Builder);
2146 return optimizeAbs(CI, Builder);
2147 case LibFunc_isdigit:
2148 return optimizeIsDigit(CI, Builder);
2149 case LibFunc_isascii:
2150 return optimizeIsAscii(CI, Builder);
2151 case LibFunc_toascii:
2152 return optimizeToAscii(CI, Builder);
2153 case LibFunc_printf:
2154 return optimizePrintF(CI, Builder);
2155 case LibFunc_sprintf:
2156 return optimizeSPrintF(CI, Builder);
2157 case LibFunc_fprintf:
2158 return optimizeFPrintF(CI, Builder);
2159 case LibFunc_fwrite:
2160 return optimizeFWrite(CI, Builder);
2162 return optimizeFPuts(CI, Builder);
2168 return optimizeLog(CI, Builder);
2170 return optimizePuts(CI, Builder);
2174 return optimizeTan(CI, Builder);
2175 case LibFunc_perror:
2176 return optimizeErrorReporting(CI, Builder);
2177 case LibFunc_vfprintf:
2178 case LibFunc_fiprintf:
2179 return optimizeErrorReporting(CI, Builder, 0);
2181 return optimizeErrorReporting(CI, Builder, 1);
2188 case LibFunc_nearbyint:
2208 if (UnsafeFPShrink && hasFloatVersion(FuncName))
2211 case LibFunc_copysign:
2212 if (hasFloatVersion(FuncName))
2221 return optimizeFMinFMax(CI, Builder);
2232 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), UnsafeFPShrink(
false),
2233 Replacer(Replacer) {}
2275 bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
CallInst *CI,
2283 if (ObjSizeCI->isMinusOne())
2286 if (OnlyLowerUnknownSize)
2294 return ObjSizeCI->getZExtValue() >= Len;
2297 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
2302 Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
2304 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2312 Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
2314 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2322 Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
2326 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2334 Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
2344 if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
2354 if (isFortifiedCallFoldable(CI, 2, 1,
true))
2357 if (OnlyLowerUnknownSize)
2370 if (Ret && Func == LibFunc_stpcpy_chk)
2375 Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
2380 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2420 case LibFunc_memcpy_chk:
2421 return optimizeMemCpyChk(CI, Builder);
2422 case LibFunc_memmove_chk:
2423 return optimizeMemMoveChk(CI, Builder);
2424 case LibFunc_memset_chk:
2425 return optimizeMemSetChk(CI, Builder);
2426 case LibFunc_stpcpy_chk:
2427 case LibFunc_strcpy_chk:
2428 return optimizeStrpCpyChk(CI, Builder, Func);
2429 case LibFunc_stpncpy_chk:
2430 case LibFunc_strncpy_chk:
2431 return optimizeStrpNCpyChk(CI, Builder, Func);
2440 : TLI(TLI), OnlyLowerUnknownSize(OnlyLowerUnknownSize) {}
static Value * optimizeUnaryDoubleFP(CallInst *CI, IRBuilder<> &B, bool CheckRetType)
Shrink double -> float for unary functions like 'floor'.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
static Value * foldMallocMemset(CallInst *Memset, IRBuilder<> &B, const TargetLibraryInfo &TLI)
Fold memset[_chk](malloc(n), 0, n) –> calloc(1, n).
void flipAllBits()
Toggle every bit to its opposite value.
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return an i1 value testing if Arg is not null.
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
static bool callHasFloatingPointArgument(const CallInst *CI)
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Value * optimizeCall(CallInst *CI)
Take the given call instruction and return a more optimal value to replace the instruction with or 0 ...
A Module instance is used to store all the information related to an LLVM module. ...
void setNoNaNs()
Flag setters.
static Constant * getInfinity(Type *Ty, bool Negative=false)
2: 32-bit floating point type
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
static uint64_t round(uint64_t Acc, uint64_t Input)
An efficient, type-erasing, non-owning reference to a callable.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const Function * getParent() const
Return the enclosing method, or null if none.
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
CallInst * CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memset to the specified pointer and the specified value.
An instruction for reading from memory.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
static bool isTrigLibCall(CallInst *CI)
Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI, StringRef Name="strncpy")
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length...
bool isGEPBasedOnPointerToString(const GEPOperator *GEP, unsigned CharSize=8)
Returns true if the GEP is based on a pointer to a string (array of.
LLVM_NODISCARD char back() const
back - Get the last character in the string.
uint64_t Offset
Slice starts at this Offset.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
static Value * emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, IRBuilder<> &B, const TargetLibraryInfo &TLI)
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
static bool isReportingError(Function *Callee, CallInst *CI, int StreamArg)
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 Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
void setCallingConv(CallingConv::ID CC)
AttributeList getAttributes() const
Return the attribute list for this Function.
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
static Value * replaceUnaryCall(CallInst *CI, IRBuilder<> &B, Intrinsic::ID IID)
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="")
This class represents the LLVM 'select' instruction.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
const Constant * stripPointerCasts() const
FortifiedLibCallSimplifier(const TargetLibraryInfo *TLI, bool OnlyLowerUnknownSize=false)
A Use represents the edge between a Value definition and its users.
Value * emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an integer.
unsigned getNumArgOperands() const
Return the number of call arguments.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
Value * CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name="")
LLVM_NODISCARD bool empty() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Class to represent function types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
const ConstantDataArray * Array
ConstantDataArray pointer.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
CallInst * CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memmove between the specified pointers.
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
TypeID getTypeID() const
Return the type id for the type.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI, StringRef Name="strcpy")
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
const Function * getFunction() const
Return the function this instruction belongs to.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static const fltSemantics & IEEEdouble() LLVM_READNONE
static Value * valueHasFloatPrecision(Value *Val)
Return a variant of Val with float type.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
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_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
void takeName(Value *V)
Transfer the name from V to this value.
Value * CreateInBoundsGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Value * CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
static unsigned getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
bool getConstantDataArrayInfo(const Value *V, ConstantDataArraySlice &Slice, unsigned ElementSize, uint64_t Offset=0)
Returns true if the value V is a pointer into a ContantDataArray.
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function.
LoadInst * CreateLoad(Value *Ptr, const char *Name)
static bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded unary floating point function corresponding to Ty is available...
Function Alias Analysis false
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName, const Function &Fn, const DiagnosticLocation &Loc, const Twine &Msg)
Legacy interface to emit an optimization-applied message.
Type * getParamType(unsigned i) const
Parameter type accessors.
initializer< Ty > init(const Ty &Val)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
FunctionType * getFunctionType() const
Returns the FunctionType for me.
ConstantInt * getTrue()
Get the constant value for i1 true.
This is an important base class in LLVM.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
ConstantFP - Floating Point Values [float, double].
Value * CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This instruction compares its operands according to the predicate given to the constructor.
Value * getOperand(unsigned i) const
Value * getPointerOperand()
static bool isCallingConvCCompatible(CallInst *CI)
unsigned getIntegerBitWidth() const
Class to represent integer types.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
Predicate getPredicate() const
Return the predicate for this instruction.
Represents offset+length into a ConstantDataArray.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
bool isPointerTy() const
True if this is an instance of PointerType.
uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Value * emitStrChr(Value *Ptr, char C, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
LLVMContext & getContext() const
All values hold a context through their type.
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
Triple - Helper class for working with autoconf configuration names.
FunctionType * getFunctionType() const
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Value * CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
static const fltSemantics & IEEEsingle() LLVM_READNONE
This is the shared class of boolean and integer constants.
GlobalVariable * CreateGlobalString(StringRef Str, const Twine &Name="", unsigned AddressSpace=0)
Make a new global variable with initializer type i8*.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
uint64_t Length
Length of the slice.
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
BasicBlock * GetInsertBlock() const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
const BasicBlock & getEntryBlock() const
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
C - The default llvm calling convention, compatible with C.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
double convertToDouble() const
static Value * optimizeBinaryDoubleFP(CallInst *CI, IRBuilder<> &B)
Shrink double -> float for binary functions like 'fmin/fmax'.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
ConstantInt * getFalse()
Get the constant value for i1 false.
bool isStructTy() const
True if this is an instance of StructType.
bool isNegative() const
Return true if the sign bit is set.
void setCalledFunction(Value *Fn)
Set the function called.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
CallInst * CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memcpy between the specified pointers.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
APFloat abs(APFloat X)
Returns the absolute value of the argument.
This class represents a cast unsigned integer to floating point.
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * optimizeCall(CallInst *CI)
optimizeCall - Take the given call instruction and return a more optimal value to replace the instruc...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static void insertSinCosCall(IRBuilder<> &B, Function *OrigCallee, Value *Arg, bool UseFloat, Value *&Sin, Value *&Cos, Value *&SinCos)
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
const APFloat & getValueAPF() const
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
3: 64-bit floating point type
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
This class represents a cast from signed integer to floating point.
static bool isOnlyUsedInEqualityComparison(Value *V, Value *With)
Return true if it is only used in equality comparisons with With.
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
LLVMContext & getContext() const
Get the context in which this basic block lives.
This class represents a truncation of floating point types.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Value * emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
void setFastMathFlags(FastMathFlags NewFMF)
Set the fast-math flags to be used with generated fp-math operators.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
cmpResult compare(const APFloat &RHS) const
Value * CreateFDiv(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
static bool ignoreCallingConv(LibFunc Func)
This class represents an extension of floating point types.
LibCallSimplifier(const DataLayout &DL, const TargetLibraryInfo *TLI, function_ref< void(Instruction *, Value *)> Replacer=&replaceAllUsesWithDefault)
Value * CreateFMul(Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
const fltSemantics & getSemantics() const
static Value * getPow(Value *InnerChain[33], unsigned Exp, IRBuilder<> &B)
const BasicBlock * getParent() const
bool has(LibFunc F) const
Tests whether a library function is available.
A wrapper class for inspecting calls to intrinsic functions.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.