32#define DEBUG_TYPE "build-libcalls"
36STATISTIC(NumReadNone,
"Number of functions inferred as readnone");
37STATISTIC(NumReadOnly,
"Number of functions inferred as readonly");
38STATISTIC(NumWriteOnly,
"Number of functions inferred as writeonly");
39STATISTIC(NumArgMemOnly,
"Number of functions inferred as argmemonly");
41 "Number of functions inferred as memory(errnomem: write)");
43 "Number of functions inferred as inaccessiblemem_or_argmemonly");
45 "Number of functions inferred as memory(inaccessiblemem: readwrite, "
48 "Number of functions inferred as memory(argmem: readwrite, "
49 "inaccessiblemem: readwrite, errnomem: write)");
51 NumWriteArgumentMemOrErrnoMemOnly,
52 "Number of functions inferred as memory(argmem: write, errnomem: write)");
53STATISTIC(NumNoUnwind,
"Number of functions inferred as nounwind");
54STATISTIC(NumNoCallback,
"Number of functions inferred as nocallback");
55STATISTIC(NumNoCapture,
"Number of arguments inferred as nocapture");
56STATISTIC(NumWriteOnlyArg,
"Number of arguments inferred as writeonly");
57STATISTIC(NumReadOnlyArg,
"Number of arguments inferred as readonly");
58STATISTIC(NumNoAlias,
"Number of function returns inferred as noalias");
59STATISTIC(NumNoUndef,
"Number of function returns inferred as noundef returns");
60STATISTIC(NumReturnedArg,
"Number of arguments inferred as returned");
61STATISTIC(NumWillReturn,
"Number of functions inferred as willreturn");
62STATISTIC(NumCold,
"Number of functions inferred as cold");
63STATISTIC(NumNoReturn,
"Number of functions inferred as no return");
64STATISTIC(NumNoSync,
"Number of functions inferred as nosync");
67 if (
F.doesNotAccessMemory())
69 F.setDoesNotAccessMemory();
75 if (
F.hasFnAttribute(Attribute::Cold))
77 F.addFnAttr(Attribute::Cold);
83 if (
F.hasFnAttribute(Attribute::NoReturn))
85 F.addFnAttr(Attribute::NoReturn);
95 F.setMemoryEffects(NewME);
123 ++NumInaccessibleMemOrArgMemOnly;
131 ++NumInaccessibleMemOrErrnoMemOnly;
139 ++NumInaccessibleMemOrArgMemOrErrnoMemOnly;
146 ++NumWriteErrnoMemOnly;
154 ++NumWriteArgumentMemOrErrnoMemOnly;
159 if (
F.doesNotThrow())
167 if (
F.hasFnAttribute(Attribute::NoCallback))
169 F.addFnAttr(Attribute::NoCallback);
175 if (
F.hasRetAttribute(Attribute::NoAlias))
177 F.addRetAttr(Attribute::NoAlias);
183 if (
F.hasParamAttribute(ArgNo, Attribute::Captures))
192 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
194 F.addParamAttr(ArgNo, Attribute::NoAlias);
200 if (
F.hasFnAttribute(Attribute::NoSync))
202 F.addFnAttr(Attribute::NoSync);
208 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
210 F.addParamAttr(ArgNo, Attribute::ReadOnly);
216 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
218 F.addParamAttr(ArgNo, Attribute::WriteOnly);
224 if (!
F.getReturnType()->isVoidTy() &&
225 !
F.hasRetAttribute(Attribute::NoUndef)) {
226 F.addRetAttr(Attribute::NoUndef);
235 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
236 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
237 F.addParamAttr(ArgNo, Attribute::NoUndef);
246 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
248 F.addParamAttr(ArgNo, Attribute::NoUndef);
254 bool UndefAdded =
false;
261 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
263 F.addParamAttr(ArgNo, Attribute::Returned);
269 if (
F.hasFnAttribute(Attribute::NonLazyBind))
271 F.addFnAttr(Attribute::NonLazyBind);
276 if (
F.hasFnAttribute(Attribute::NoFree))
278 F.addFnAttr(Attribute::NoFree);
283 if (
F.hasFnAttribute(Attribute::WillReturn))
285 F.addFnAttr(Attribute::WillReturn);
291 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
293 F.addParamAttr(ArgNo, Attribute::AllocAlign);
298 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
300 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
305 std::optional<unsigned> NumElemsArg) {
306 if (
F.hasFnAttribute(Attribute::AllocSize))
314 if (
F.hasFnAttribute(
"alloc-family"))
316 F.addFnAttr(
"alloc-family", Family);
321 if (
F.hasFnAttribute(Attribute::AllocKind))
339 if (!TLI.
has(TheLibFunc))
344 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
347 switch (TheLibFunc) {
352 case LibFunc_strnlen:
363 case LibFunc_strrchr:
374 case LibFunc_strtoul:
375 case LibFunc_strtoll:
376 case LibFunc_strtold:
377 case LibFunc_strtoull:
385 case LibFunc_strncat:
398 case LibFunc_strncpy:
402 case LibFunc_stpncpy:
414 case LibFunc_strxfrm:
424 case LibFunc_strncmp:
425 case LibFunc_strcspn:
435 case LibFunc_strcoll:
436 case LibFunc_strcasecmp:
437 case LibFunc_strncasecmp:
448 case LibFunc_strpbrk:
458 case LibFunc_strtok_r:
472 case LibFunc_setvbuf:
477 case LibFunc_strndup:
490 case LibFunc_statvfs:
505 case LibFunc_sprintf:
514 case LibFunc_snprintf:
523 case LibFunc_setitimer:
537 case LibFunc_posix_memalign:
545 case LibFunc_aligned_alloc:
552 case LibFunc_vec_malloc:
555 case LibFunc_pvalloc:
576 case LibFunc_memrchr:
608 case LibFunc_memmove:
619 case LibFunc_mempcpy:
620 case LibFunc_memccpy:
623 case LibFunc_memcpy_chk:
634 case LibFunc_memalign:
658 case LibFunc_realloc:
659 case LibFunc_reallocf:
660 case LibFunc_vec_realloc:
662 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
674 case LibFunc_reallocarray:
700 case LibFunc_realpath:
714 case LibFunc_readlink:
758 case LibFunc_vec_calloc:
776 case LibFunc_ctermid:
777 case LibFunc_clearerr:
778 case LibFunc_closedir:
822 case LibFunc_vec_free:
836 case LibFunc_fgetc_unlocked:
842 case LibFunc_fsetpos:
843 case LibFunc_flockfile:
844 case LibFunc_funlockfile:
845 case LibFunc_ftrylockfile:
857 case LibFunc_fputc_unlocked:
874 case LibFunc_fstatvfs:
880 case LibFunc_fgets_unlocked:
887 case LibFunc_fread_unlocked:
895 case LibFunc_fwrite_unlocked:
903 case LibFunc_fputs_unlocked:
911 case LibFunc_fprintf:
918 case LibFunc_fgetpos:
929 case LibFunc_getlogin_r:
934 case LibFunc_getc_unlocked:
946 case LibFunc_getchar:
947 case LibFunc_getchar_unlocked:
951 case LibFunc_getitimer:
956 case LibFunc_getpwnam:
978 case LibFunc_unsetenv:
994 case LibFunc_putc_unlocked:
1000 case LibFunc_printf:
1001 case LibFunc_perror:
1012 case LibFunc_pwrite:
1018 case LibFunc_putchar:
1019 case LibFunc_putchar_unlocked:
1032 case LibFunc_pclose:
1037 case LibFunc_vscanf:
1043 case LibFunc_vsscanf:
1051 case LibFunc_vfscanf:
1058 case LibFunc_vprintf:
1064 case LibFunc_vfprintf:
1065 case LibFunc_vsprintf:
1072 case LibFunc_vsnprintf:
1085 case LibFunc_opendir:
1092 case LibFunc_tmpfile:
1117 case LibFunc_lchown:
1129 case LibFunc_dunder_strndup:
1132 case LibFunc_dunder_strdup:
1139 case LibFunc_dunder_strtok_r:
1145 case LibFunc_under_IO_getc:
1150 case LibFunc_under_IO_putc:
1155 case LibFunc_dunder_isoc99_scanf:
1161 case LibFunc_stat64:
1162 case LibFunc_lstat64:
1163 case LibFunc_statvfs64:
1170 case LibFunc_dunder_isoc99_sscanf:
1178 case LibFunc_fopen64:
1187 case LibFunc_fseeko64:
1188 case LibFunc_ftello64:
1193 case LibFunc_tmpfile64:
1198 case LibFunc_fstat64:
1199 case LibFunc_fstatvfs64:
1204 case LibFunc_open64:
1210 case LibFunc_gettimeofday:
1219 case LibFunc_memset_pattern4:
1220 case LibFunc_memset_pattern8:
1221 case LibFunc_memset_pattern16:
1226 case LibFunc_memset:
1229 case LibFunc_memset_chk:
1241 case LibFunc_terminate:
1246 case LibFunc_cxa_throw:
1252 case LibFunc_nvvm_reflect:
1260 case LibFunc_acoshf:
1261 case LibFunc_acoshl:
1266 case LibFunc_asinhf:
1267 case LibFunc_asinhl:
1271 case LibFunc_atan2f:
1272 case LibFunc_atan2l:
1275 case LibFunc_atanhf:
1276 case LibFunc_atanhl:
1285 case LibFunc_cospif:
1289 case LibFunc_tgamma:
1290 case LibFunc_tgammaf:
1291 case LibFunc_tgammal:
1299 case LibFunc_expm1f:
1300 case LibFunc_expm1l:
1308 case LibFunc_hypotf:
1309 case LibFunc_hypotl:
1311 case LibFunc_ldexpf:
1312 case LibFunc_ldexpl:
1315 case LibFunc_log10f:
1316 case LibFunc_log10l:
1318 case LibFunc_log1pf:
1319 case LibFunc_log1pl:
1327 case LibFunc_ilogbf:
1328 case LibFunc_ilogbl:
1331 case LibFunc_nextafter:
1332 case LibFunc_nextafterf:
1333 case LibFunc_nextafterl:
1334 case LibFunc_nexttoward:
1335 case LibFunc_nexttowardf:
1336 case LibFunc_nexttowardl:
1340 case LibFunc_remainder:
1341 case LibFunc_remainderf:
1342 case LibFunc_remainderl:
1346 case LibFunc_scalbln:
1347 case LibFunc_scalblnf:
1348 case LibFunc_scalblnl:
1349 case LibFunc_scalbn:
1350 case LibFunc_scalbnf:
1351 case LibFunc_scalbnl:
1359 case LibFunc_sinpif:
1380 case LibFunc_copysign:
1381 case LibFunc_copysignf:
1382 case LibFunc_copysignl:
1393 case LibFunc_floorf:
1394 case LibFunc_floorl:
1404 case LibFunc_fmaximum_num:
1405 case LibFunc_fmaximum_numf:
1406 case LibFunc_fmaximum_numl:
1407 case LibFunc_fminimum_num:
1408 case LibFunc_fminimum_numf:
1409 case LibFunc_fminimum_numl:
1412 case LibFunc_nearbyint:
1413 case LibFunc_nearbyintf:
1414 case LibFunc_nearbyintl:
1416 case LibFunc_roundf:
1417 case LibFunc_roundl:
1418 case LibFunc_roundeven:
1419 case LibFunc_roundevenf:
1420 case LibFunc_roundevenl:
1421 case LibFunc_sincos_stret:
1422 case LibFunc_sincosf_stret:
1423 case LibFunc_sincospi_stret:
1424 case LibFunc_sincospif_stret:
1425 case LibFunc_toascii:
1427 case LibFunc_truncf:
1428 case LibFunc_truncl:
1431 case LibFunc_isascii:
1432 case LibFunc_isdigit:
1438 case LibFunc_sincos:
1439 case LibFunc_sincosf:
1440 case LibFunc_sincosl:
1444 case LibFunc_remquo:
1445 case LibFunc_remquof:
1446 case LibFunc_remquol:
1472 F.addParamAttr(ArgNo, ExtAttr);
1479 F.addParamAttr(ArgNo, ExtAttr);
1486 F.addRetAttr(ExtAttr);
1491 if (!
F->arg_size() ||
F->isVarArg())
1498 const Module *M =
F->getParent();
1499 unsigned N = M->getNumberRegisterParameters();
1507 if (!
T->isIntOrPtrTy())
1514 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1515 const unsigned NumRegs = TS > 4 ? 2 : 1;
1520 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1528 "Creating call to non-existing library function.");
1542 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1543 switch (TheLibFunc) {
1545 case LibFunc_putchar:
1549 case LibFunc_ldexpf:
1550 case LibFunc_ldexpl:
1551 case LibFunc_memchr:
1552 case LibFunc_memrchr:
1553 case LibFunc_strchr:
1556 case LibFunc_memccpy:
1562 case LibFunc_Znwm12__hot_cold_t:
1563 case LibFunc_Znam12__hot_cold_t:
1564 case LibFunc_size_returning_new_hot_cold:
1567 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1568 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1569 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1570 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1571 case LibFunc_size_returning_new_aligned_hot_cold:
1574 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1575 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1585 case LibFunc_calloc:
1586 case LibFunc_fwrite:
1587 case LibFunc_malloc:
1588 case LibFunc_memcmp:
1589 case LibFunc_memcpy_chk:
1590 case LibFunc_mempcpy:
1591 case LibFunc_memset_pattern16:
1592 case LibFunc_snprintf:
1593 case LibFunc_stpncpy:
1594 case LibFunc_strlcat:
1595 case LibFunc_strlcpy:
1596 case LibFunc_strncat:
1597 case LibFunc_strncmp:
1598 case LibFunc_strncpy:
1599 case LibFunc_vsnprintf:
1604 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1606 "Unhandled integer argument.");
1622 LibFunc TheLibFunc) {
1624 if (!TLI->
has(TheLibFunc))
1629 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1644 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1645 switch (Ty->getTypeID()) {
1658 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1659 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1661 "Cannot get name for unavailable function!");
1663 switch (Ty->getTypeID()) {
1667 TheLibFunc = FloatFn;
1670 TheLibFunc = DoubleFn;
1671 return TLI->
getName(DoubleFn);
1673 TheLibFunc = LongDoubleFn;
1674 return TLI->
getName(LongDoubleFn);
1685 const Module *M =
B.getModule();
1693 bool IsVaArgs =
false) {
1711 Type *CharPtrTy =
B.getPtrTy();
1713 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr,
B, TLI);
1719 "Argument to wcslen intrinsic must be a pointer.");
1720 Type *PtrTy =
B.getPtrTy();
1722 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr,
B, TLI);
1727 Type *CharPtrTy =
B.getPtrTy();
1728 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr,
B, TLI);
1733 Type *CharPtrTy =
B.getPtrTy();
1735 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1736 {Ptr, ConstantInt::get(IntTy, (
unsigned char)
C)},
B, TLI);
1741 Type *CharPtrTy =
B.getPtrTy();
1745 LibFunc_strncmp, IntTy,
1746 {CharPtrTy, CharPtrTy, SizeTTy},
1747 {Ptr1, Ptr2, Len},
B, TLI);
1752 Type *CharPtrTy = Dst->getType();
1753 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1754 {Dst, Src},
B, TLI);
1759 Type *CharPtrTy =
B.getPtrTy();
1760 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1761 {Dst, Src},
B, TLI);
1766 Type *CharPtrTy =
B.getPtrTy();
1768 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1769 {Dst, Src, Len},
B, TLI);
1774 Type *CharPtrTy =
B.getPtrTy();
1776 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1777 {Dst, Src, Len},
B, TLI);
1788 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1789 Attribute::NoUnwind);
1790 Type *VoidPtrTy =
B.getPtrTy();
1793 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1794 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1795 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1804 Type *VoidPtrTy =
B.getPtrTy();
1807 {VoidPtrTy, VoidPtrTy, SizeTTy},
1808 {Dst, Src, Len},
B, TLI);
1813 Type *VoidPtrTy =
B.getPtrTy();
1817 {VoidPtrTy, IntTy, SizeTTy},
1818 {Ptr, Val, Len},
B, TLI);
1823 Type *VoidPtrTy =
B.getPtrTy();
1827 {VoidPtrTy, IntTy, SizeTTy},
1828 {Ptr, Val, Len},
B, TLI);
1833 Type *VoidPtrTy =
B.getPtrTy();
1837 {VoidPtrTy, VoidPtrTy, SizeTTy},
1838 {Ptr1, Ptr2, Len},
B, TLI);
1843 Type *VoidPtrTy =
B.getPtrTy();
1847 {VoidPtrTy, VoidPtrTy, SizeTTy},
1848 {Ptr1, Ptr2, Len},
B, TLI);
1853 Type *VoidPtrTy =
B.getPtrTy();
1857 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1858 {Ptr1, Ptr2, Val, Len},
B, TLI);
1864 Type *CharPtrTy =
B.getPtrTy();
1870 {CharPtrTy, SizeTTy, CharPtrTy},
1871 Args,
B, TLI,
true);
1877 Type *CharPtrTy =
B.getPtrTy();
1882 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1888 Type *CharPtrTy =
B.getPtrTy();
1890 {CharPtrTy, CharPtrTy},
1891 {Dest, Src},
B, TLI);
1896 Type *CharPtrTy =
B.getPtrTy();
1899 {CharPtrTy, CharPtrTy, SizeTTy},
1900 {Dest, Src,
Size},
B, TLI);
1905 Type *CharPtrTy =
B.getPtrTy();
1908 {CharPtrTy, CharPtrTy, SizeTTy},
1909 {Dest, Src,
Size},
B, TLI);
1914 Type *CharPtrTy =
B.getPtrTy();
1917 {CharPtrTy, CharPtrTy, SizeTTy},
1918 {Dest, Src,
Size},
B, TLI);
1923 Type *CharPtrTy =
B.getPtrTy();
1927 LibFunc_vsnprintf, IntTy,
1928 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1929 {Dest,
Size, Fmt, VAList},
B, TLI);
1934 Type *CharPtrTy =
B.getPtrTy();
1937 {CharPtrTy, CharPtrTy, VAList->
getType()},
1938 {Dest, Fmt, VAList},
B, TLI);
1944 if (!
Op->getType()->isDoubleTy()) {
1947 if (
Op->getType()->isFloatTy())
1960 assert((Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1971 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1990 LibFunc DoubleFn, LibFunc FloatFn,
1997 LongDoubleFn, TheLibFunc);
2007 assert((Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
2013 CallInst *CI =
B.CreateCall(Callee, { Op1, Op2 }, Name);
2019 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
2031 assert((Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
2042 LibFunc DoubleFn, LibFunc FloatFn,
2049 LongDoubleFn, TheLibFunc);
2059 return emitLibCall(LibFunc_putchar, IntTy, IntTy, Char,
B, TLI);
2065 return emitLibCall(LibFunc_puts, IntTy,
B.getPtrTy(), Str,
B, TLI);
2071 return emitLibCall(LibFunc_fputc, IntTy, {IntTy, File->getType()},
2072 {Char, File},
B, TLI);
2078 return emitLibCall(LibFunc_fputs, IntTy, {
B.getPtrTy(), File->getType()},
2079 {Str, File},
B, TLI);
2086 {
B.getPtrTy(), SizeTTy, SizeTTy, File->getType()},
2087 {Ptr,
Size, ConstantInt::get(SizeTTy, 1), File},
B, TLI);
2093 return emitLibCall(LibFunc_malloc,
B.getPtrTy(), SizeTTy, Num,
B, TLI);
2099 return emitLibCall(LibFunc_calloc,
B.getPtrTy(AddrSpace), {SizeTTy, SizeTTy},
2100 {Num, Size},
B, &TLI);
2105 LibFunc SizeFeedbackNewFunc,
2112 if (
const Function *
F = M->getFunction(Name);
2113 F &&
F->getReturnType() != RetTy)
2119 CallInst *CI =
B.CreateCall(Func, {Num, HotCold},
"sized_ptr");
2130 LibFunc SizeFeedbackNewFunc,
2137 if (
const Function *
F = M->getFunction(Name);
2138 F &&
F->getReturnType() != RetTy)
2143 Align->getType(),
B.getInt8Ty());
2145 CallInst *CI =
B.CreateCall(Func, {Num,
Align, HotCold},
"sized_ptr");
2164 CallInst *CI =
B.CreateCall(Func, {Num, HotCold}, Name);
2175 LibFunc NewFunc,
Value *HotCold) {
2183 NoThrow->
getType(),
B.getInt8Ty());
2185 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow, HotCold}, Name);
2196 LibFunc NewFunc,
Value *HotCold) {
2204 Align->getType(),
B.getInt8Ty());
2218 LibFunc NewFunc,
Value *HotCold) {
2228 CallInst *CI =
B.CreateCall(Func, {Num,
Align, NoThrow, HotCold}, Name);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool setRetNoUndef(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMemOrErrnoMem(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 setDoesNotSync(Function &F)
static void setI8ArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setDoesNotAlias(Function &F, unsigned ArgNo)
static bool setDoesNotAccessMemory(Function &F)
static bool setOnlyAccessesInaccessibleMemOrErrnoMem(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 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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
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.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Common base class shared among various IRBuilders.
Class to represent integer types.
static MemoryEffectsBase readOnly()
static MemoryEffectsBase inaccessibleOrArgOrErrnoMemOnly(ModRefInfo InaccessibleOrArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase errnoMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase writeOnly()
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase argumentOrErrnoMemOnly(ModRefInfo ArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
static MemoryEffectsBase inaccessibleOrErrnoMemOnly(ModRefInfo InaccessibleMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
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.
Represent a constant reference to a string, i.e.
Provides information about what library functions are available for the current target.
static Attribute::AttrKind getExtAttrForI8Param(bool Signed=true)
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.
StringRef getName(LibFunc F) const
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
@ HalfTyID
16-bit floating point type
@ FloatTyID
32-bit floating point type
@ DoubleTyID
64-bit floating point 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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ 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 * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold, Type *RetTy)
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
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 * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
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 * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI 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.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
LLVM_ABI bool 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.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
LLVM_ABI Value * emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
DWARFExpression::Operation Op
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.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
LLVM_ABI Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
LLVM_ABI Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_ABI Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
Emit a call to the hot/cold operator new function.
LLVM_ABI Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold, Type *RetTy)
LLVM_ABI Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
LLVM_ABI Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
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.