37 using namespace PatternMatch;
41 cl::desc(
"Treat error-reporting calls as cold"));
46 cl::desc(
"Enable unsafe double to float "
47 "shrinking for math lib calls"));
56 Func == LibFunc::llabs || Func == LibFunc::strlen;
76 if (!FuncTy->getReturnType()->isPointerTy() &&
77 !FuncTy->getReturnType()->isIntegerTy() &&
78 !FuncTy->getReturnType()->isVoidTy())
81 for (
auto Param : FuncTy->params()) {
82 if (!Param->isPointerTy() && !Param->isIntegerTy())
94 if (
ICmpInst *IC = dyn_cast<ICmpInst>(U))
96 if (
Constant *
C = dyn_cast<Constant>(IC->getOperand(1)))
108 if (
ICmpInst *IC = dyn_cast<ICmpInst>(U))
109 if (IC->isEquality() && IC->getOperand(1) == With)
119 return OI->getType()->isFloatingPointTy();
130 return TLI->
has(FloatFn);
132 return TLI->
has(DoubleFn);
134 return TLI->
has(LongDoubleFn);
157 return emitStrLenMemCpy(Src, Dst, Len, B);
160 Value *LibCallSimplifier::emitStrLenMemCpy(
Value *Src,
Value *Dst, uint64_t Len,
189 Len = LengthArg->getZExtValue();
202 if (SrcLen == 0 || Len == 0)
211 return emitStrLenMemCpy(Src, Dst, SrcLen, B);
291 if (HasStr1 && HasStr2)
294 if (HasStr1 && Str1.empty())
298 if (HasStr2 && Str2.empty())
322 Length = LengthArg->getZExtValue();
337 if (HasStr1 && HasStr2) {
343 if (HasStr1 && Str1.empty())
347 if (HasStr2 && Str2.empty())
413 if (
ConstantInt *LengthArg = dyn_cast<ConstantInt>(LenOp))
414 Len = LengthArg->getZExtValue();
422 if (Len > SrcLen + 1)
453 size_t NullTermIdx = Str.
find(
'\0');
462 APInt KnownZero(BitWidth, 0);
463 APInt KnownOne(BitWidth, 0);
466 KnownZero.flipAllBits();
468 cast<ArrayType>(
GEP->getSourceElementType())->getNumElements();
480 if ((KnownZero.isNonNegative() && KnownZero.ule(NullTermIdx)) ||
481 (
GEP->isInBounds() && isa<GlobalVariable>(
GEP->getOperand(0)) &&
482 NullTermIdx == ArrSize - 1))
491 if (
SelectInst *SI = dyn_cast<SelectInst>(Src)) {
494 if (LenTrue && LenFalse) {
498 "folded strlen(select) to select of constants");
520 if ((HasS1 && S1.
empty()) || (HasS2 && S2.
empty()))
524 if (HasS1 && HasS2) {
534 if (HasS2 && S2.
size() == 1)
542 if (isa<ConstantPointerNull>(EndPtr)) {
558 if ((HasS1 && S1.
empty()) || (HasS2 && S2.
empty()))
562 if (HasS1 && HasS2) {
578 if (HasS1 && S1.
empty())
582 if (HasS1 && HasS2) {
590 if (HasS2 && S2.
empty())
611 ICmpInst *Old = cast<ICmpInst>(*UI++);
615 replaceAllUsesWith(Old, Cmp);
626 if (HasStr2 && ToFindStr.
empty())
630 if (HasStr1 && HasStr2) {
631 size_t Offset = SearchStr.
find(ToFindStr);
638 Result = B.CreateConstInBoundsGEP1_64(Result, Offset,
"strstr");
639 return B.CreateBitCast(Result, CI->
getType());
643 if (HasStr2 && ToFindStr.
size() == 1) {
645 return StrChr ? B.CreateBitCast(StrChr, CI->
getType()) :
nullptr;
656 if (LenC && LenC->isNullValue())
667 Str = Str.
substr(0, LenC->getZExtValue());
680 *std::max_element(reinterpret_cast<const unsigned char *>(Str.
begin()),
681 reinterpret_cast<const unsigned char *>(Str.
end()));
688 if (!DL.fitsInLegalInteger(Max + 1))
693 unsigned char Width =
NextPowerOf2(std::max((
unsigned char)7, Max));
749 return B.
CreateSub(LHSV, RHSV,
"chardiff");
756 unsigned PrefAlignment = DL.getPrefTypeAlignment(IntType);
764 IntType->
getPointerTo(RHS->getType()->getPointerAddressSpace());
780 if (Len > LHSStr.
size() || Len > RHSStr.
size())
785 int Cmp = memcmp(LHSStr.
data(), RHSStr.
data(), Len);
822 PtrType, PtrType,
nullptr);
836 if (!FillValue || FillValue->getZExtValue() != 0)
844 if (!Malloc || !Malloc->hasOneUse())
848 Function *InnerCallee = Malloc->getCalledFunction();
851 Func != LibFunc::malloc)
861 const DataLayout &DL = Malloc->getModule()->getDataLayout();
864 Malloc->getArgOperand(0), Malloc->getAttributes(),
870 Malloc->eraseFromParent();
895 if (
FPExtInst *Cast = dyn_cast<FPExtInst>(Val)) {
896 Value *
Op = Cast->getOperand(0);
900 if (
ConstantFP *Const = dyn_cast<ConstantFP>(Val)) {
981 Value *Ret =
nullptr;
983 if (UnsafeFPShrink && Name ==
"cos" && hasFloatVersion(Name))
999 assert(Exp != 0 &&
"Incorrect exponent 0 not handled");
1001 if (InnerChain[Exp])
1002 return InnerChain[Exp];
1004 static const unsigned AddChain[33][2] = {
1008 {1, 2}, {2, 2}, {2, 3}, {3, 3}, {2, 5}, {4, 4},
1009 {1, 8}, {5, 5}, {1, 10}, {6, 6}, {4, 9}, {7, 7},
1010 {3, 12}, {8, 8}, {8, 9}, {2, 16}, {1, 18}, {10, 10},
1011 {6, 15}, {11, 11}, {3, 20}, {12, 12}, {8, 17}, {13, 13},
1012 {3, 24}, {14, 14}, {4, 25}, {15, 15}, {3, 28}, {16, 16},
1016 getPow(InnerChain, AddChain[Exp][1], B));
1017 return InnerChain[Exp];
1022 Value *Ret =
nullptr;
1024 if (UnsafeFPShrink && Name ==
"pow" && hasFloatVersion(Name))
1041 if (
ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
1043 if (Op1C->isExactlyValue(10.0) &&
1059 Function *OpCCallee = OpC->getCalledFunction();
1060 if (OpCCallee && TLI->getLibFunc(OpCCallee->
getName(),
Func) &&
1061 TLI->has(Func) && (Func == LibFunc::exp || Func == LibFunc::exp2)) {
1147 Value *InnerChain[33] = {
nullptr};
1148 InnerChain[1] = Op1;
1168 Value *Ret =
nullptr;
1170 if (UnsafeFPShrink && Name ==
"exp2" && hasFloatVersion(Name))
1178 LdExp = LibFunc::ldexpf;
1180 LdExp = LibFunc::ldexp;
1182 if (TLI->has(LdExp)) {
1183 Value *LdExpArg =
nullptr;
1184 if (
SIToFPInst *OpC = dyn_cast<SIToFPInst>(Op)) {
1185 if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() <= 32)
1187 }
else if (
UIToFPInst *OpC = dyn_cast<UIToFPInst>(Op)) {
1188 if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() < 32)
1214 if (Name ==
"fabs" && hasFloatVersion(Name))
1225 if ((Name ==
"fmin" || Name ==
"fmax") && hasFloatVersion(Name))
1259 Value *Ret =
nullptr;
1261 if (UnsafeFPShrink && hasFloatVersion(Name))
1270 if (!OpC || !OpC->hasUnsafeAlgebra())
1275 if (Name !=
"log" && Name !=
"log2" && Name !=
"log10")
1285 if (F && ((TLI->getLibFunc(F->
getName(),
Func) && TLI->has(Func) &&
1292 if (F && Name ==
"log" && TLI->getLibFunc(F->
getName(),
Func) &&
1293 TLI->has(Func) && Func == LibFunc::exp2)
1295 OpC->getArgOperand(0),
1304 Value *Ret =
nullptr;
1305 if (TLI->has(LibFunc::sqrtf) && (Callee->
getName() ==
"sqrt" ||
1321 Value *RepeatOp =
nullptr;
1322 Value *OtherOp =
nullptr;
1332 Value *OtherMul0, *OtherMul1;
1335 if (OtherMul0 == OtherMul1 &&
1336 cast<Instruction>(Op0)->hasUnsafeAlgebra()) {
1338 RepeatOp = OtherMul0;
1371 Value *Ret =
nullptr;
1373 if (UnsafeFPShrink && Name ==
"tan" && hasFloatVersion(Name))
1389 Function *F = OpC->getCalledFunction();
1390 if (F && TLI->getLibFunc(F->
getName(),
Func) && TLI->has(Func) &&
1391 ((Func == LibFunc::atan && Callee->
getName() ==
"tan") ||
1392 (Func == LibFunc::atanf && Callee->
getName() ==
"tanf") ||
1393 (Func == LibFunc::atanl && Callee->
getName() ==
"tanl")))
1394 Ret = OpC->getArgOperand(0);
1402 return CI->
hasFnAttr(Attribute::NoUnwind) &&
1415 Name =
"__sincospif_stret";
1424 Name =
"__sincospi_stret";
1430 ResTy, ArgTy,
nullptr);
1432 if (
Instruction *ArgInst = dyn_cast<Instruction>(Arg)) {
1435 B.
SetInsertPoint(ArgInst->getParent(), ++ArgInst->getIterator());
1443 SinCos = B.
CreateCall(Callee, Arg,
"sincospi");
1474 classifyArgUse(U, F, IsFloat, SinCalls, CosCalls, SinCosCalls);
1480 Value *Sin, *Cos, *SinCos;
1486 replaceAllUsesWith(C, Res);
1489 replaceTrigInsts(SinCalls, Sin);
1490 replaceTrigInsts(CosCalls, Cos);
1491 replaceTrigInsts(SinCosCalls, SinCos);
1496 void LibCallSimplifier::classifyArgUse(
1512 if (!Callee || !TLI->getLibFunc(*Callee, Func) || !TLI->has(Func) ||
1517 if (Func == LibFunc::sinpif)
1519 else if (Func == LibFunc::cospif)
1521 else if (Func == LibFunc::sincospif_stret)
1524 if (Func == LibFunc::sinpi)
1526 else if (Func == LibFunc::cospi)
1528 else if (Func == LibFunc::sincospi_stret)
1542 Intrinsic::cttz, ArgType);
1556 Intrinsic::ctlz, ArgType);
1636 return GV->
getName() ==
"stderr";
1646 if (FormatStr.
empty())
1656 if (FormatStr.
size() == 1 || FormatStr ==
"%%")
1664 if (ChrStr.
size() != 1)
1670 if (FormatStr[FormatStr.
size() - 1] ==
'\n' &&
1696 if (
Value *V = optimizePrintFString(CI, B)) {
1724 for (
unsigned i = 0, e = FormatStr.
size();
i != e; ++
i)
1725 if (FormatStr[
i] ==
'%')
1731 FormatStr.
size() + 1),
1738 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' ||
1743 if (FormatStr[1] ==
'c') {
1756 if (FormatStr[1] ==
's') {
1777 if (
Value *V = optimizeSPrintFString(CI, B)) {
1796 optimizeErrorReporting(CI, B, 0);
1811 for (
unsigned i = 0, e = FormatStr.
size();
i != e; ++
i)
1812 if (FormatStr[
i] ==
'%')
1823 if (FormatStr.
size() != 2 || FormatStr[0] !=
'%' ||
1828 if (FormatStr[1] ==
'c') {
1835 if (FormatStr[1] ==
's') {
1847 if (
Value *V = optimizeFPrintFString(CI, B)) {
1866 optimizeErrorReporting(CI, B, 3);
1871 if (!SizeC || !CountC)
1873 uint64_t Bytes = SizeC->
getZExtValue() * CountC->getZExtValue();
1891 optimizeErrorReporting(CI, B, 1);
1931 bool LibCallSimplifier::hasFloatVersion(
StringRef FuncName) {
1934 FloatFuncName +=
'f';
1935 if (TLI->getLibFunc(FloatFuncName, Func))
1936 return TLI->has(Func);
1940 Value *LibCallSimplifier::optimizeStringMemoryLibCall(
CallInst *CI,
1945 if (TLI->getLibFunc(*Callee, Func) && TLI->has(Func)) {
1949 "Optimizing string/memory libcall would change the calling convention");
1951 case LibFunc::strcat:
1952 return optimizeStrCat(CI, Builder);
1953 case LibFunc::strncat:
1954 return optimizeStrNCat(CI, Builder);
1955 case LibFunc::strchr:
1956 return optimizeStrChr(CI, Builder);
1957 case LibFunc::strrchr:
1958 return optimizeStrRChr(CI, Builder);
1960 return optimizeStrCmp(CI, Builder);
1961 case LibFunc::strncmp:
1962 return optimizeStrNCmp(CI, Builder);
1963 case LibFunc::strcpy:
1964 return optimizeStrCpy(CI, Builder);
1965 case LibFunc::stpcpy:
1966 return optimizeStpCpy(CI, Builder);
1967 case LibFunc::strncpy:
1968 return optimizeStrNCpy(CI, Builder);
1969 case LibFunc::strlen:
1970 return optimizeStrLen(CI, Builder);
1971 case LibFunc::strpbrk:
1972 return optimizeStrPBrk(CI, Builder);
1973 case LibFunc::strtol:
1974 case LibFunc::strtod:
1975 case LibFunc::strtof:
1976 case LibFunc::strtoul:
1977 case LibFunc::strtoll:
1978 case LibFunc::strtold:
1979 case LibFunc::strtoull:
1980 return optimizeStrTo(CI, Builder);
1981 case LibFunc::strspn:
1982 return optimizeStrSpn(CI, Builder);
1983 case LibFunc::strcspn:
1984 return optimizeStrCSpn(CI, Builder);
1985 case LibFunc::strstr:
1986 return optimizeStrStr(CI, Builder);
1987 case LibFunc::memchr:
1988 return optimizeMemChr(CI, Builder);
1989 case LibFunc::memcmp:
1990 return optimizeMemCmp(CI, Builder);
1991 case LibFunc::memcpy:
1992 return optimizeMemCpy(CI, Builder);
1993 case LibFunc::memmove:
1994 return optimizeMemMove(CI, Builder);
1995 case LibFunc::memset:
1996 return optimizeMemSet(CI, Builder);
2021 UnsafeFPShrink =
true;
2025 if (!isCallingConvC)
2027 switch (II->getIntrinsicID()) {
2028 case Intrinsic::pow:
2029 return optimizePow(CI, Builder);
2030 case Intrinsic::exp2:
2031 return optimizeExp2(CI, Builder);
2032 case Intrinsic::fabs:
2033 return optimizeFabs(CI, Builder);
2034 case Intrinsic::log:
2035 return optimizeLog(CI, Builder);
2036 case Intrinsic::sqrt:
2037 return optimizeSqrt(CI, Builder);
2045 if (
Value *SimplifiedFortifiedCI = FortifiedSimplifier.optimizeCall(CI)) {
2052 if (
Value *V = optimizeStringMemoryLibCall(SimplifiedCI, TmpBuilder)) {
2059 return SimplifiedFortifiedCI;
2063 if (TLI->getLibFunc(*Callee, Func) && TLI->has(Func)) {
2067 if (
Value *V = optimizeStringMemoryLibCall(CI, Builder))
2073 return optimizeCos(CI, Builder);
2074 case LibFunc::sinpif:
2075 case LibFunc::sinpi:
2076 case LibFunc::cospif:
2077 case LibFunc::cospi:
2078 return optimizeSinCosPi(CI, Builder);
2082 return optimizePow(CI, Builder);
2083 case LibFunc::exp2l:
2085 case LibFunc::exp2f:
2086 return optimizeExp2(CI, Builder);
2087 case LibFunc::fabsf:
2089 case LibFunc::fabsl:
2090 return optimizeFabs(CI, Builder);
2091 case LibFunc::sqrtf:
2093 case LibFunc::sqrtl:
2094 return optimizeSqrt(CI, Builder);
2097 case LibFunc::ffsll:
2098 return optimizeFFS(CI, Builder);
2101 case LibFunc::flsll:
2102 return optimizeFls(CI, Builder);
2105 case LibFunc::llabs:
2106 return optimizeAbs(CI, Builder);
2107 case LibFunc::isdigit:
2108 return optimizeIsDigit(CI, Builder);
2109 case LibFunc::isascii:
2110 return optimizeIsAscii(CI, Builder);
2111 case LibFunc::toascii:
2112 return optimizeToAscii(CI, Builder);
2113 case LibFunc::printf:
2114 return optimizePrintF(CI, Builder);
2115 case LibFunc::sprintf:
2116 return optimizeSPrintF(CI, Builder);
2117 case LibFunc::fprintf:
2118 return optimizeFPrintF(CI, Builder);
2119 case LibFunc::fwrite:
2120 return optimizeFWrite(CI, Builder);
2121 case LibFunc::fputs:
2122 return optimizeFPuts(CI, Builder);
2124 case LibFunc::log10:
2125 case LibFunc::log1p:
2128 return optimizeLog(CI, Builder);
2130 return optimizePuts(CI, Builder);
2134 return optimizeTan(CI, Builder);
2135 case LibFunc::perror:
2136 return optimizeErrorReporting(CI, Builder);
2137 case LibFunc::vfprintf:
2138 case LibFunc::fiprintf:
2139 return optimizeErrorReporting(CI, Builder, 0);
2140 case LibFunc::fputc:
2141 return optimizeErrorReporting(CI, Builder, 1);
2143 case LibFunc::floor:
2146 case LibFunc::nearbyint:
2147 case LibFunc::trunc:
2148 if (hasFloatVersion(FuncName))
2152 case LibFunc::acosh:
2154 case LibFunc::asinh:
2156 case LibFunc::atanh:
2160 case LibFunc::exp10:
2161 case LibFunc::expm1:
2165 if (UnsafeFPShrink && hasFloatVersion(FuncName))
2168 case LibFunc::copysign:
2169 if (hasFloatVersion(FuncName))
2172 case LibFunc::fminf:
2174 case LibFunc::fminl:
2175 case LibFunc::fmaxf:
2177 case LibFunc::fmaxl:
2178 return optimizeFMinFMax(CI, Builder);
2189 : FortifiedSimplifier(TLI), DL(DL), TLI(TLI), UnsafeFPShrink(
false),
2190 Replacer(Replacer) {}
2242 bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
CallInst *CI,
2250 if (ObjSizeCI->isAllOnesValue())
2253 if (OnlyLowerUnknownSize)
2261 return ObjSizeCI->getZExtValue() >= Len;
2264 return ObjSizeCI->getZExtValue() >= SizeCI->getZExtValue();
2269 Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(
CallInst *CI,
2271 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2279 Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(
CallInst *CI,
2281 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2289 Value *FortifiedLibCallSimplifier::optimizeMemSetChk(
CallInst *CI,
2293 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2301 Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(
CallInst *CI,
2311 if (Func == LibFunc::stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) {
2321 if (isFortifiedCallFoldable(CI, 2, 1,
true))
2324 if (OnlyLowerUnknownSize)
2337 if (Ret && Func == LibFunc::stpcpy_chk)
2342 Value *FortifiedLibCallSimplifier::optimizeStrpNCpyChk(
CallInst *CI,
2347 if (isFortifiedCallFoldable(CI, 3, 2,
false)) {
2387 case LibFunc::memcpy_chk:
2388 return optimizeMemCpyChk(CI, Builder);
2389 case LibFunc::memmove_chk:
2390 return optimizeMemMoveChk(CI, Builder);
2391 case LibFunc::memset_chk:
2392 return optimizeMemSetChk(CI, Builder);
2393 case LibFunc::stpcpy_chk:
2394 case LibFunc::strcpy_chk:
2395 return optimizeStrpCpyChk(CI, Builder, Func);
2396 case LibFunc::stpncpy_chk:
2397 case LibFunc::strncpy_chk:
2398 return optimizeStrpNCpyChk(CI, Builder, Func);
2407 : 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 computeKnownBits(const Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
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).
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="")
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
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
uint64_t GetStringLength(const Value *V)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
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.
static bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc::Func DoubleFn, LibFunc::Func FloatFn, LibFunc::Func LongDoubleFn)
Check whether the overloaded unary floating point function corresponding to Ty is available...
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="")
static cl::opt< bool > ColdErrorCalls("error-reporting-is-cold", cl::init(true), cl::Hidden, cl::desc("Treat error-reporting calls as cold"))
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.
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...
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeSet &Attrs)
Emit a call to the unary function named 'Name' (e.g.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
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 strcmp
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName, const Function &Fn, const DebugLoc &DLoc, const Twine &Msg)
Emit an optimization-applied message.
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)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
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.
static bool ignoreCallingConv(LibFunc::Func Func)
bool has(LibFunc::Func F) const
Tests whether a library function is available.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
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...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
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="")
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
Function Alias Analysis false
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)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
const Function * getFunction() const
Return the function this instruction belongs to.
bool isGEPBasedOnPointerToString(const GEPOperator *GEP)
Returns true if the GEP is based on a pointer to a string (array of i8), and is indexing into this st...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static Value * valueHasFloatPrecision(Value *Val)
Return a variant of Val with float type.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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...
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 etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
ConstantInt * getIntN(unsigned N, uint64_t C)
Get a constant N-bit value, zero extended or truncated from a 64-bit value.
static const fltSemantics & IEEEsingle()
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
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)
bool getLibFunc(StringRef funcName, LibFunc::Func &F) const
Searches for a particular function name.
Type * getDoubleTy()
Fetch the type representing a 64-bit floating point value.
Type * getParamType(unsigned i) const
Parameter type accessors.
initializer< Ty > init(const Ty &Val)
Constant * stripPointerCasts()
static Value * emitCalloc(Value *Num, Value *Size, const AttributeSet &Attrs, IRBuilder<> &B, const TargetLibraryInfo &TLI)
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.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
ConstantInt * getTrue()
Get the constant value for i1 true.
C - The default llvm calling convention, compatible with C.
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.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
bool isPointerTy() const
True if this is an instance of PointerType.
uint64_t NextPowerOf2(uint64_t A)
NextPowerOf2 - 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
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.
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.
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
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
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...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
AttributeSet getAttributes() const
Return the attribute list for this Function.
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'.
static const fltSemantics & IEEEdouble()
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...
static bool isOnlyUsedInZeroEqualityComparison(Value *V)
Return true if it only matters that the value is equal or not-equal to zero.
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)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
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.
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeSet &Attrs)
Emit a call to the binary function named 'Name' (e.g.
ConstantInt * getInt(const APInt &AI)
Get a constant integer value.
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)
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
const fltSemantics & getSemantics() const
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
static Value * getPow(Value *InnerChain[33], unsigned Exp, IRBuilder<> &B)
const BasicBlock * getParent() const
A wrapper class for inspecting calls to intrinsic functions.