32#define DEBUG_TYPE "build-libcalls"
36STATISTIC(NumReadNone,
"Number of functions inferred as readnone");
38 "Number of functions inferred as inaccessiblememonly");
39STATISTIC(NumReadOnly,
"Number of functions inferred as readonly");
40STATISTIC(NumWriteOnly,
"Number of functions inferred as writeonly");
41STATISTIC(NumArgMemOnly,
"Number of functions inferred as argmemonly");
43 "Number of functions inferred as memory(errnomem: write)");
45 "Number of functions inferred as inaccessiblemem_or_argmemonly");
47 NumWriteArgumentMemOrErrnoMemOnly,
48 "Number of functions inferred as memory(argmem: write, errnomem: write)");
49STATISTIC(NumNoUnwind,
"Number of functions inferred as nounwind");
50STATISTIC(NumNoCallback,
"Number of functions inferred as nocallback");
51STATISTIC(NumNoCapture,
"Number of arguments inferred as nocapture");
52STATISTIC(NumWriteOnlyArg,
"Number of arguments inferred as writeonly");
53STATISTIC(NumReadOnlyArg,
"Number of arguments inferred as readonly");
54STATISTIC(NumNoAlias,
"Number of function returns inferred as noalias");
55STATISTIC(NumNoUndef,
"Number of function returns inferred as noundef returns");
56STATISTIC(NumReturnedArg,
"Number of arguments inferred as returned");
57STATISTIC(NumWillReturn,
"Number of functions inferred as willreturn");
58STATISTIC(NumCold,
"Number of functions inferred as cold");
59STATISTIC(NumNoReturn,
"Number of functions inferred as no return");
62 if (
F.doesNotAccessMemory())
64 F.setDoesNotAccessMemory();
70 if (
F.hasFnAttribute(Attribute::Cold))
72 F.addFnAttr(Attribute::Cold);
78 if (
F.hasFnAttribute(Attribute::NoReturn))
80 F.addFnAttr(Attribute::NoReturn);
90 F.setMemoryEffects(NewME);
97 ++NumInaccessibleMemOnly;
125 ++NumInaccessibleMemOrArgMemOnly;
132 ++NumWriteErrnoMemOnly;
138 ModRefInfo::Mod, ModRefInfo::Mod)))
140 ++NumWriteArgumentMemOrErrnoMemOnly;
145 if (
F.doesNotThrow())
153 if (
F.hasFnAttribute(Attribute::NoCallback))
155 F.addFnAttr(Attribute::NoCallback);
161 if (
F.hasRetAttribute(Attribute::NoAlias))
163 F.addRetAttr(Attribute::NoAlias);
169 if (
F.hasParamAttribute(ArgNo, Attribute::Captures))
178 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
180 F.addParamAttr(ArgNo, Attribute::NoAlias);
186 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
188 F.addParamAttr(ArgNo, Attribute::ReadOnly);
194 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
196 F.addParamAttr(ArgNo, Attribute::WriteOnly);
202 if (!
F.getReturnType()->isVoidTy() &&
203 !
F.hasRetAttribute(Attribute::NoUndef)) {
204 F.addRetAttr(Attribute::NoUndef);
212 bool Changed =
false;
213 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
214 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
215 F.addParamAttr(ArgNo, Attribute::NoUndef);
224 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
226 F.addParamAttr(ArgNo, Attribute::NoUndef);
232 bool UndefAdded =
false;
239 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
241 F.addParamAttr(ArgNo, Attribute::Returned);
247 if (
F.hasFnAttribute(Attribute::NonLazyBind))
249 F.addFnAttr(Attribute::NonLazyBind);
254 if (
F.hasFnAttribute(Attribute::NoFree))
256 F.addFnAttr(Attribute::NoFree);
261 if (
F.hasFnAttribute(Attribute::WillReturn))
263 F.addFnAttr(Attribute::WillReturn);
269 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
271 F.addParamAttr(ArgNo, Attribute::AllocAlign);
276 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
278 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
283 std::optional<unsigned> NumElemsArg) {
284 if (
F.hasFnAttribute(Attribute::AllocSize))
292 if (
F.hasFnAttribute(
"alloc-family"))
294 F.addFnAttr(
"alloc-family", Family);
299 if (
F.hasFnAttribute(Attribute::AllocKind))
320 bool Changed =
false;
322 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
325 switch (TheLibFunc) {
330 case LibFunc_strnlen:
340 case LibFunc_strrchr:
350 case LibFunc_strtoul:
351 case LibFunc_strtoll:
352 case LibFunc_strtold:
353 case LibFunc_strtoull:
361 case LibFunc_strncat:
373 case LibFunc_strncpy:
377 case LibFunc_stpncpy:
388 case LibFunc_strxfrm:
398 case LibFunc_strncmp:
399 case LibFunc_strcspn:
408 case LibFunc_strcoll:
409 case LibFunc_strcasecmp:
410 case LibFunc_strncasecmp:
421 case LibFunc_strpbrk:
430 case LibFunc_strtok_r:
444 case LibFunc_setvbuf:
449 case LibFunc_strndup:
462 case LibFunc_statvfs:
477 case LibFunc_sprintf:
486 case LibFunc_snprintf:
495 case LibFunc_setitimer:
509 case LibFunc_aligned_alloc:
512 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
516 case LibFunc_vec_malloc:
519 case LibFunc_pvalloc:
520 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_malloc ?
"vec_malloc"
522 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
539 case LibFunc_memrchr:
568 case LibFunc_memmove:
578 case LibFunc_mempcpy:
579 case LibFunc_memccpy:
582 case LibFunc_memcpy_chk:
592 case LibFunc_memalign:
594 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
595 AllocFnKind::Uninitialized);
616 case LibFunc_realloc:
617 case LibFunc_reallocf:
618 case LibFunc_vec_realloc:
620 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
632 case LibFunc_reallocarray:
658 case LibFunc_realpath:
672 case LibFunc_readlink:
713 case LibFunc_vec_calloc:
714 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
716 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
731 case LibFunc_ctermid:
732 case LibFunc_clearerr:
733 case LibFunc_closedir:
776 case LibFunc_vec_free:
777 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
790 case LibFunc_fgetc_unlocked:
796 case LibFunc_fsetpos:
797 case LibFunc_flockfile:
798 case LibFunc_funlockfile:
799 case LibFunc_ftrylockfile:
811 case LibFunc_fputc_unlocked:
827 case LibFunc_fstatvfs:
833 case LibFunc_fgets_unlocked:
840 case LibFunc_fread_unlocked:
848 case LibFunc_fwrite_unlocked:
856 case LibFunc_fputs_unlocked:
864 case LibFunc_fprintf:
871 case LibFunc_fgetpos:
882 case LibFunc_getlogin_r:
887 case LibFunc_getc_unlocked:
899 case LibFunc_getchar:
900 case LibFunc_getchar_unlocked:
904 case LibFunc_getitimer:
909 case LibFunc_getpwnam:
931 case LibFunc_unsetenv:
947 case LibFunc_putc_unlocked:
971 case LibFunc_putchar:
972 case LibFunc_putchar_unlocked:
996 case LibFunc_vsscanf:
1004 case LibFunc_vfscanf:
1011 case LibFunc_vprintf:
1017 case LibFunc_vfprintf:
1018 case LibFunc_vsprintf:
1025 case LibFunc_vsnprintf:
1038 case LibFunc_opendir:
1045 case LibFunc_tmpfile:
1070 case LibFunc_lchown:
1082 case LibFunc_dunder_strndup:
1085 case LibFunc_dunder_strdup:
1092 case LibFunc_dunder_strtok_r:
1098 case LibFunc_under_IO_getc:
1103 case LibFunc_under_IO_putc:
1108 case LibFunc_dunder_isoc99_scanf:
1114 case LibFunc_stat64:
1115 case LibFunc_lstat64:
1116 case LibFunc_statvfs64:
1123 case LibFunc_dunder_isoc99_sscanf:
1131 case LibFunc_fopen64:
1140 case LibFunc_fseeko64:
1141 case LibFunc_ftello64:
1146 case LibFunc_tmpfile64:
1151 case LibFunc_fstat64:
1152 case LibFunc_fstatvfs64:
1157 case LibFunc_open64:
1163 case LibFunc_gettimeofday:
1172 case LibFunc_memset_pattern4:
1173 case LibFunc_memset_pattern8:
1174 case LibFunc_memset_pattern16:
1179 case LibFunc_memset:
1182 case LibFunc_memset_chk:
1193 case LibFunc_terminate:
1198 case LibFunc_cxa_throw:
1204 case LibFunc_nvvm_reflect:
1212 case LibFunc_acoshf:
1213 case LibFunc_acoshl:
1218 case LibFunc_asinhf:
1219 case LibFunc_asinhl:
1223 case LibFunc_atan2f:
1224 case LibFunc_atan2l:
1227 case LibFunc_atanhf:
1228 case LibFunc_atanhl:
1240 case LibFunc_cospif:
1244 case LibFunc_tgamma:
1245 case LibFunc_tgammaf:
1246 case LibFunc_tgammal:
1254 case LibFunc_expm1f:
1255 case LibFunc_expm1l:
1263 case LibFunc_hypotf:
1264 case LibFunc_hypotl:
1266 case LibFunc_ldexpf:
1267 case LibFunc_ldexpl:
1270 case LibFunc_log10f:
1271 case LibFunc_log10l:
1273 case LibFunc_log1pf:
1274 case LibFunc_log1pl:
1282 case LibFunc_ilogbf:
1283 case LibFunc_ilogbl:
1289 case LibFunc_remainder:
1290 case LibFunc_remainderf:
1291 case LibFunc_remainderl:
1296 case LibFunc_roundf:
1297 case LibFunc_roundl:
1298 case LibFunc_scalbln:
1299 case LibFunc_scalblnf:
1300 case LibFunc_scalblnl:
1301 case LibFunc_scalbn:
1302 case LibFunc_scalbnf:
1303 case LibFunc_scalbnl:
1305 case LibFunc_sincospif_stret:
1312 case LibFunc_sinpif:
1332 case LibFunc_copysign:
1333 case LibFunc_copysignf:
1334 case LibFunc_copysignl:
1342 case LibFunc_floorf:
1343 case LibFunc_floorl:
1355 case LibFunc_nearbyint:
1356 case LibFunc_nearbyintf:
1357 case LibFunc_nearbyintl:
1358 case LibFunc_toascii:
1360 case LibFunc_truncf:
1361 case LibFunc_truncl:
1364 case LibFunc_isascii:
1365 case LibFunc_isdigit:
1371 case LibFunc_sincos:
1372 case LibFunc_sincosf:
1373 case LibFunc_sincosl:
1377 case LibFunc_remquo:
1378 case LibFunc_remquof:
1379 case LibFunc_remquol:
1404 F.addParamAttr(ArgNo, ExtAttr);
1411 F.addRetAttr(ExtAttr);
1416 if (!
F->arg_size() ||
F->isVarArg())
1423 const Module *M =
F->getParent();
1424 unsigned N = M->getNumberRegisterParameters();
1432 if (!
T->isIntOrPtrTy())
1439 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1440 const unsigned NumRegs = TS > 4 ? 2 : 1;
1445 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1453 "Creating call to non-existing library function.");
1467 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1468 switch (TheLibFunc) {
1470 case LibFunc_putchar:
1474 case LibFunc_ldexpf:
1475 case LibFunc_ldexpl:
1476 case LibFunc_memchr:
1477 case LibFunc_memrchr:
1478 case LibFunc_strchr:
1481 case LibFunc_memccpy:
1491 case LibFunc_calloc:
1492 case LibFunc_fwrite:
1493 case LibFunc_malloc:
1494 case LibFunc_memcmp:
1495 case LibFunc_memcpy_chk:
1496 case LibFunc_mempcpy:
1497 case LibFunc_memset_pattern16:
1498 case LibFunc_snprintf:
1499 case LibFunc_stpncpy:
1500 case LibFunc_strlcat:
1501 case LibFunc_strlcpy:
1502 case LibFunc_strncat:
1503 case LibFunc_strncmp:
1504 case LibFunc_strncpy:
1505 case LibFunc_vsnprintf:
1510 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1511 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1512 "Unhandled integer argument.");
1530 if (!TLI->
has(TheLibFunc))
1535 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1536 if (
auto *
F = dyn_cast<Function>(GV))
1569 "Cannot get name for unavailable function!");
1575 TheLibFunc = FloatFn;
1578 TheLibFunc = DoubleFn;
1579 return TLI->
getName(DoubleFn);
1581 TheLibFunc = LongDoubleFn;
1582 return TLI->
getName(LongDoubleFn);
1593 const Module *M =
B.GetInsertBlock()->getModule();
1601 bool IsVaArgs =
false) {
1602 Module *M =
B.GetInsertBlock()->getModule();
1607 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1612 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1619 Type *CharPtrTy =
B.getPtrTy();
1627 "Argument to wcslen intrinsic must be a pointer.");
1628 Type *PtrTy =
B.getPtrTy();
1635 Type *CharPtrTy =
B.getPtrTy();
1636 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy,
Ptr,
B, TLI);
1641 Type *CharPtrTy =
B.getPtrTy();
1643 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1644 {
Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1649 Type *CharPtrTy =
B.getPtrTy();
1653 LibFunc_strncmp, IntTy,
1654 {CharPtrTy, CharPtrTy, SizeTTy},
1655 {Ptr1, Ptr2, Len},
B, TLI);
1660 Type *CharPtrTy = Dst->getType();
1661 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1662 {Dst, Src},
B, TLI);
1667 Type *CharPtrTy =
B.getPtrTy();
1668 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1669 {Dst, Src},
B, TLI);
1674 Type *CharPtrTy =
B.getPtrTy();
1676 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1677 {Dst, Src, Len},
B, TLI);
1682 Type *CharPtrTy =
B.getPtrTy();
1684 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1685 {Dst, Src, Len},
B, TLI);
1691 Module *M =
B.GetInsertBlock()->getModule();
1697 Attribute::NoUnwind);
1698 Type *VoidPtrTy =
B.getPtrTy();
1702 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1703 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1712 Type *VoidPtrTy =
B.getPtrTy();
1715 {VoidPtrTy, VoidPtrTy, SizeTTy},
1716 {Dst, Src, Len},
B, TLI);
1721 Type *VoidPtrTy =
B.getPtrTy();
1725 {VoidPtrTy, IntTy, SizeTTy},
1726 {
Ptr, Val, Len},
B, TLI);
1731 Type *VoidPtrTy =
B.getPtrTy();
1735 {VoidPtrTy, IntTy, SizeTTy},
1736 {
Ptr, Val, Len},
B, TLI);
1741 Type *VoidPtrTy =
B.getPtrTy();
1745 {VoidPtrTy, VoidPtrTy, SizeTTy},
1746 {Ptr1, Ptr2, Len},
B, TLI);
1751 Type *VoidPtrTy =
B.getPtrTy();
1755 {VoidPtrTy, VoidPtrTy, SizeTTy},
1756 {Ptr1, Ptr2, Len},
B, TLI);
1761 Type *VoidPtrTy =
B.getPtrTy();
1765 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1766 {Ptr1, Ptr2, Val, Len},
B, TLI);
1772 Type *CharPtrTy =
B.getPtrTy();
1778 {CharPtrTy, SizeTTy, CharPtrTy},
1779 Args,
B, TLI,
true);
1785 Type *CharPtrTy =
B.getPtrTy();
1790 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1796 Type *CharPtrTy =
B.getPtrTy();
1798 {CharPtrTy, CharPtrTy},
1799 {Dest, Src},
B, TLI);
1804 Type *CharPtrTy =
B.getPtrTy();
1807 {CharPtrTy, CharPtrTy, SizeTTy},
1808 {Dest, Src,
Size},
B, TLI);
1813 Type *CharPtrTy =
B.getPtrTy();
1816 {CharPtrTy, CharPtrTy, SizeTTy},
1817 {Dest, Src,
Size},
B, TLI);
1822 Type *CharPtrTy =
B.getPtrTy();
1825 {CharPtrTy, CharPtrTy, SizeTTy},
1826 {Dest, Src,
Size},
B, TLI);
1831 Type *CharPtrTy =
B.getPtrTy();
1835 LibFunc_vsnprintf, IntTy,
1836 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1837 {Dest,
Size, Fmt, VAList},
B, TLI);
1842 Type *CharPtrTy =
B.getPtrTy();
1845 {CharPtrTy, CharPtrTy, VAList->
getType()},
1846 {Dest, Fmt, VAList},
B, TLI);
1852 if (!
Op->getType()->isDoubleTy()) {
1855 if (
Op->getType()->isFloatTy())
1868 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1870 Module *M =
B.GetInsertBlock()->getModule();
1879 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1881 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1904 Module *M =
B.GetInsertBlock()->getModule();
1907 LongDoubleFn, TheLibFunc);
1917 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1919 Module *M =
B.GetInsertBlock()->getModule();
1929 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1931 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1941 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1958 Module *M =
B.GetInsertBlock()->getModule();
1961 LongDoubleFn, TheLibFunc);
1970 Module *M =
B.GetInsertBlock()->getModule();
1979 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1989 Module *M =
B.GetInsertBlock()->getModule();
1998 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
2007 Module *M =
B.GetInsertBlock()->getModule();
2014 IntTy, File->getType());
2015 if (File->getType()->isPointerTy())
2017 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
2020 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
2027 Module *M =
B.GetInsertBlock()->getModule();
2034 B.getPtrTy(), File->getType());
2035 if (File->getType()->isPointerTy())
2037 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
2040 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
2047 Module *M =
B.GetInsertBlock()->getModule();
2055 SizeTTy, SizeTTy, File->getType());
2057 if (File->getType()->isPointerTy())
2061 ConstantInt::get(SizeTTy, 1), File});
2064 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
2071 Module *M =
B.GetInsertBlock()->getModule();
2083 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
2091 Module *M =
B.GetInsertBlock()->getModule();
2098 M, TLI, LibFunc_calloc,
B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2100 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
2113 Module *M =
B.GetInsertBlock()->getModule();
2123 M->getOrInsertFunction(
Name, SizedPtrT, Num->
getType(),
B.getInt8Ty());
2125 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
"sized_ptr");
2127 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2138 Module *M =
B.GetInsertBlock()->getModule();
2148 Align->getType(),
B.getInt8Ty());
2151 B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)},
"sized_ptr");
2153 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2162 Module *M =
B.GetInsertBlock()->getModule();
2168 M->getOrInsertFunction(
Name,
B.getPtrTy(), Num->
getType(),
B.getInt8Ty());
2170 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
Name);
2173 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2182 Module *M =
B.GetInsertBlock()->getModule();
2190 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
2193 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2202 Module *M =
B.GetInsertBlock()->getModule();
2213 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2223 Module *M =
B.GetInsertBlock()->getModule();
2233 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2236 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool setRetNoUndef(Function &F)
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of 'Op'.
static bool setDoesNotAlias(Function &F, unsigned ArgNo)
static bool setDoesNotAccessMemory(Function &F)
static bool setOnlyWritesArgMemOrErrnoMem(Function &F)
static bool setArgsNoUndef(Function &F)
static IntegerType * getSizeTTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
static Value * emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
static bool setAllocatedPointerParam(Function &F, unsigned ArgNo)
static void setRetExtAttr(Function &F, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setMemoryEffects(Function &F, MemoryEffects ME)
static Value * emitLibCall(LibFunc TheLibFunc, Type *ReturnType, ArrayRef< Type * > ParamTypes, ArrayRef< Value * > Operands, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool IsVaArgs=false)
static bool setNonLazyBind(Function &F)
static bool setIsCold(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
static bool setAllocSize(Function &F, unsigned ElemSizeArg, std::optional< unsigned > NumElemsArg)
static bool setAlignedAllocParam(Function &F, unsigned ArgNo)
static bool setRetAndArgsNoUndef(Function &F)
static bool setRetDoesNotAlias(Function &F)
static bool setReturnedArg(Function &F, unsigned ArgNo)
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
static bool setOnlyWritesErrnoMemory(Function &F)
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
static bool setDoesNotThrow(Function &F)
static bool setWillReturn(Function &F)
static bool setAllocKind(Function &F, AllocFnKind K)
static bool setNoReturn(Function &F)
static bool setOnlyAccessesInaccessibleMemory(Function &F)
static IntegerType * getIntTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
static bool setAllocFamily(Function &F, StringRef Family)
static bool setArgNoUndef(Function &F, unsigned ArgNo)
static bool setDoesNotCallback(Function &F)
static void setArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setOnlyAccessesArgMemory(Function &F)
static bool setOnlyWritesMemory(Function &F)
static bool setOnlyReadsMemory(Function &F)
static bool setDoesNotFreeMemory(Function &F)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
mir Rename Register Operands
This file defines the SmallString class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
void setCallingConv(CallingConv::ID CC)
void setAttributes(AttributeList A)
Set the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
Common base class shared among various IRBuilders.
Class to represent integer types.
static MemoryEffectsBase readOnly()
Create MemoryEffectsBase that can read any memory.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access argument memory.
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible memory.
static MemoryEffectsBase errnoMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access errno memory.
static MemoryEffectsBase writeOnly()
Create MemoryEffectsBase that can write any memory.
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible or argument memory.
static MemoryEffectsBase argumentOrErrnoMemOnly(ModRefInfo ArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access argument or errno memory.
A Module instance is used to store all the information related to an LLVM module.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Class to represent struct types.
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.
Provides information about what library functions are available for the current target.
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F, const Module &M) const
Return true if the function type FTy is valid for the library function F, regardless of whether the f...
bool has(LibFunc F) const
Tests whether a library function is available.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
StringRef getName(LibFunc F) const
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
The instances of the Type class are immutable: once they are created, they are never changed.
@ HalfTyID
16-bit floating point type
@ FloatTyID
32-bit floating point type
@ DoubleTyID
64-bit floating point type
TypeID getTypeID() const
Return the type id for the type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ X86_StdCall
stdcall is mostly used by the Win32 API.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
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 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.
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 Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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 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.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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 bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
LLVM_ABI bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
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.
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.
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.
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.
LLVM_ABI void markRegisterParameterAttributes(Function *F)
LLVM_ABI StringRef getFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn, LibFunc &TheLibFunc)
Get the name of the overloaded floating point function corresponding to Ty.
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.
LLVM_ABI Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI, unsigned AddrSpace)
Emit a call to the calloc function.
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 isReallocLikeFn(const Function *F)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
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.
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.
LLVM_ABI Value * emitWcsLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the wcslen function to the builder, for the specified pointer.
LLVM_ABI Value * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
LLVM_ABI Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
LLVM_ABI Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_ABI Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
LLVM_ABI Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
LLVM_ABI Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
LLVM_ABI Value * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
LLVM_ABI Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.
This struct is a compact representation of a valid (non-zero power of two) alignment.