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 inaccessiblemem_or_argmemonly");
44STATISTIC(NumNoUnwind,
"Number of functions inferred as nounwind");
45STATISTIC(NumNoCapture,
"Number of arguments inferred as nocapture");
46STATISTIC(NumWriteOnlyArg,
"Number of arguments inferred as writeonly");
47STATISTIC(NumReadOnlyArg,
"Number of arguments inferred as readonly");
48STATISTIC(NumNoAlias,
"Number of function returns inferred as noalias");
49STATISTIC(NumNoUndef,
"Number of function returns inferred as noundef returns");
50STATISTIC(NumReturnedArg,
"Number of arguments inferred as returned");
51STATISTIC(NumWillReturn,
"Number of functions inferred as willreturn");
52STATISTIC(NumCold,
"Number of functions inferred as cold");
53STATISTIC(NumNoReturn,
"Number of functions inferred as no return");
56 if (
F.doesNotAccessMemory())
58 F.setDoesNotAccessMemory();
64 if (
F.hasFnAttribute(Attribute::Cold))
66 F.addFnAttr(Attribute::Cold);
72 if (
F.hasFnAttribute(Attribute::NoReturn))
74 F.addFnAttr(Attribute::NoReturn);
80 if (
F.onlyAccessesInaccessibleMemory())
82 F.setOnlyAccessesInaccessibleMemory();
83 ++NumInaccessibleMemOnly;
88 if (
F.onlyReadsMemory())
90 F.setOnlyReadsMemory();
96 if (
F.onlyWritesMemory())
99 F.setOnlyWritesMemory();
104 if (
F.onlyAccessesArgMemory())
106 F.setOnlyAccessesArgMemory();
112 if (
F.onlyAccessesInaccessibleMemOrArgMem())
114 F.setOnlyAccessesInaccessibleMemOrArgMem();
115 ++NumInaccessibleMemOrArgMemOnly;
120 if (
F.doesNotThrow())
128 if (
F.hasRetAttribute(Attribute::NoAlias))
130 F.addRetAttr(Attribute::NoAlias);
136 if (
F.hasParamAttribute(ArgNo, Attribute::Captures))
145 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
147 F.addParamAttr(ArgNo, Attribute::NoAlias);
153 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
155 F.addParamAttr(ArgNo, Attribute::ReadOnly);
161 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
163 F.addParamAttr(ArgNo, Attribute::WriteOnly);
169 if (!
F.getReturnType()->isVoidTy() &&
170 !
F.hasRetAttribute(Attribute::NoUndef)) {
171 F.addRetAttr(Attribute::NoUndef);
179 bool Changed =
false;
180 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
181 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
182 F.addParamAttr(ArgNo, Attribute::NoUndef);
191 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
193 F.addParamAttr(ArgNo, Attribute::NoUndef);
199 bool UndefAdded =
false;
206 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
208 F.addParamAttr(ArgNo, Attribute::Returned);
214 if (
F.hasFnAttribute(Attribute::NonLazyBind))
216 F.addFnAttr(Attribute::NonLazyBind);
221 if (
F.hasFnAttribute(Attribute::NoFree))
223 F.addFnAttr(Attribute::NoFree);
228 if (
F.hasFnAttribute(Attribute::WillReturn))
230 F.addFnAttr(Attribute::WillReturn);
236 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
238 F.addParamAttr(ArgNo, Attribute::AllocAlign);
243 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
245 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
250 std::optional<unsigned> NumElemsArg) {
251 if (
F.hasFnAttribute(Attribute::AllocSize))
259 if (
F.hasFnAttribute(
"alloc-family"))
261 F.addFnAttr(
"alloc-family", Family);
266 if (
F.hasFnAttribute(Attribute::AllocKind))
287 bool Changed =
false;
289 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
292 switch (TheLibFunc) {
297 case LibFunc_strnlen:
306 case LibFunc_strrchr:
315 case LibFunc_strtoul:
316 case LibFunc_strtoll:
317 case LibFunc_strtold:
318 case LibFunc_strtoull:
325 case LibFunc_strncat:
336 case LibFunc_strncpy:
340 case LibFunc_stpncpy:
350 case LibFunc_strxfrm:
359 case LibFunc_strncmp:
360 case LibFunc_strcspn:
368 case LibFunc_strcoll:
369 case LibFunc_strcasecmp:
370 case LibFunc_strncasecmp:
380 case LibFunc_strpbrk:
388 case LibFunc_strtok_r:
401 case LibFunc_setvbuf:
406 case LibFunc_strndup:
419 case LibFunc_statvfs:
434 case LibFunc_sprintf:
443 case LibFunc_snprintf:
452 case LibFunc_setitimer:
466 case LibFunc_aligned_alloc:
469 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
473 case LibFunc_vec_malloc:
474 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_malloc ?
"vec_malloc"
476 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
493 case LibFunc_memrchr:
519 case LibFunc_memmove:
528 case LibFunc_mempcpy:
529 case LibFunc_memccpy:
532 case LibFunc_memcpy_chk:
541 case LibFunc_memalign:
543 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
544 AllocFnKind::Uninitialized);
565 case LibFunc_realloc:
566 case LibFunc_reallocf:
567 case LibFunc_vec_realloc:
569 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
581 case LibFunc_reallocarray:
607 case LibFunc_realpath:
621 case LibFunc_readlink:
659 case LibFunc_vec_calloc:
660 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
662 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
677 case LibFunc_ctermid:
678 case LibFunc_clearerr:
679 case LibFunc_closedir:
721 case LibFunc_vec_free:
722 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
735 case LibFunc_fgetc_unlocked:
741 case LibFunc_fsetpos:
742 case LibFunc_flockfile:
743 case LibFunc_funlockfile:
744 case LibFunc_ftrylockfile:
756 case LibFunc_fputc_unlocked:
771 case LibFunc_fstatvfs:
777 case LibFunc_fgets_unlocked:
783 case LibFunc_fread_unlocked:
790 case LibFunc_fwrite_unlocked:
798 case LibFunc_fputs_unlocked:
806 case LibFunc_fprintf:
813 case LibFunc_fgetpos:
824 case LibFunc_getlogin_r:
829 case LibFunc_getc_unlocked:
841 case LibFunc_getchar:
842 case LibFunc_getchar_unlocked:
846 case LibFunc_getitimer:
851 case LibFunc_getpwnam:
873 case LibFunc_unsetenv:
889 case LibFunc_putc_unlocked:
913 case LibFunc_putchar:
914 case LibFunc_putchar_unlocked:
938 case LibFunc_vsscanf:
946 case LibFunc_vfscanf:
953 case LibFunc_vprintf:
959 case LibFunc_vfprintf:
960 case LibFunc_vsprintf:
967 case LibFunc_vsnprintf:
980 case LibFunc_opendir:
987 case LibFunc_tmpfile:
1011 case LibFunc_lchown:
1023 case LibFunc_dunder_strndup:
1026 case LibFunc_dunder_strdup:
1033 case LibFunc_dunder_strtok_r:
1038 case LibFunc_under_IO_getc:
1043 case LibFunc_under_IO_putc:
1048 case LibFunc_dunder_isoc99_scanf:
1054 case LibFunc_stat64:
1055 case LibFunc_lstat64:
1056 case LibFunc_statvfs64:
1063 case LibFunc_dunder_isoc99_sscanf:
1071 case LibFunc_fopen64:
1080 case LibFunc_fseeko64:
1081 case LibFunc_ftello64:
1086 case LibFunc_tmpfile64:
1091 case LibFunc_fstat64:
1092 case LibFunc_fstatvfs64:
1097 case LibFunc_open64:
1103 case LibFunc_gettimeofday:
1112 case LibFunc_memset_pattern4:
1113 case LibFunc_memset_pattern8:
1114 case LibFunc_memset_pattern16:
1119 case LibFunc_memset:
1122 case LibFunc_memset_chk:
1130 case LibFunc_terminate:
1134 case LibFunc_cxa_throw:
1140 case LibFunc_nvvm_reflect:
1146 case LibFunc_ldexpf:
1147 case LibFunc_ldexpl:
1150 case LibFunc_remquo:
1151 case LibFunc_remquof:
1152 case LibFunc_remquol:
1159 case LibFunc_acoshf:
1160 case LibFunc_acoshl:
1165 case LibFunc_asinhf:
1166 case LibFunc_asinhl:
1170 case LibFunc_atan2f:
1171 case LibFunc_atan2l:
1174 case LibFunc_atanhf:
1175 case LibFunc_atanhl:
1183 case LibFunc_copysign:
1184 case LibFunc_copysignf:
1185 case LibFunc_copysignl:
1193 case LibFunc_cospif:
1197 case LibFunc_tgamma:
1198 case LibFunc_tgammaf:
1199 case LibFunc_tgammal:
1207 case LibFunc_expm1f:
1208 case LibFunc_expm1l:
1219 case LibFunc_floorf:
1220 case LibFunc_floorl:
1234 case LibFunc_hypotf:
1235 case LibFunc_hypotl:
1236 case LibFunc_isascii:
1237 case LibFunc_isdigit:
1242 case LibFunc_log10f:
1243 case LibFunc_log10l:
1245 case LibFunc_log1pf:
1246 case LibFunc_log1pl:
1254 case LibFunc_ilogbf:
1255 case LibFunc_ilogbl:
1258 case LibFunc_nearbyint:
1259 case LibFunc_nearbyintf:
1260 case LibFunc_nearbyintl:
1264 case LibFunc_remainder:
1265 case LibFunc_remainderf:
1266 case LibFunc_remainderl:
1271 case LibFunc_roundf:
1272 case LibFunc_roundl:
1273 case LibFunc_scalbln:
1274 case LibFunc_scalblnf:
1275 case LibFunc_scalblnl:
1276 case LibFunc_scalbn:
1277 case LibFunc_scalbnf:
1278 case LibFunc_scalbnl:
1280 case LibFunc_sincospif_stret:
1287 case LibFunc_sinpif:
1297 case LibFunc_toascii:
1299 case LibFunc_truncf:
1300 case LibFunc_truncl:
1306 case LibFunc_sincos:
1307 case LibFunc_sincosf:
1308 case LibFunc_sincosl:
1334 F.addParamAttr(ArgNo, ExtAttr);
1341 F.addRetAttr(ExtAttr);
1346 if (!
F->arg_size() ||
F->isVarArg())
1353 const Module *M =
F->getParent();
1354 unsigned N = M->getNumberRegisterParameters();
1362 if (!
T->isIntOrPtrTy())
1369 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1370 const unsigned NumRegs = TS > 4 ? 2 : 1;
1375 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1383 "Creating call to non-existing library function.");
1397 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1398 switch (TheLibFunc) {
1400 case LibFunc_putchar:
1404 case LibFunc_ldexpf:
1405 case LibFunc_ldexpl:
1406 case LibFunc_memchr:
1407 case LibFunc_memrchr:
1408 case LibFunc_strchr:
1411 case LibFunc_memccpy:
1421 case LibFunc_calloc:
1422 case LibFunc_fwrite:
1423 case LibFunc_malloc:
1424 case LibFunc_memcmp:
1425 case LibFunc_memcpy_chk:
1426 case LibFunc_mempcpy:
1427 case LibFunc_memset_pattern16:
1428 case LibFunc_snprintf:
1429 case LibFunc_stpncpy:
1430 case LibFunc_strlcat:
1431 case LibFunc_strlcpy:
1432 case LibFunc_strncat:
1433 case LibFunc_strncmp:
1434 case LibFunc_strncpy:
1435 case LibFunc_vsnprintf:
1440 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1441 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1442 "Unhandled integer argument.");
1460 if (!TLI->
has(TheLibFunc))
1465 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1466 if (
auto *
F = dyn_cast<Function>(GV))
1499 "Cannot get name for unavailable function!");
1505 TheLibFunc = FloatFn;
1508 TheLibFunc = DoubleFn;
1509 return TLI->
getName(DoubleFn);
1511 TheLibFunc = LongDoubleFn;
1512 return TLI->
getName(LongDoubleFn);
1523 const Module *M =
B.GetInsertBlock()->getModule();
1531 bool IsVaArgs =
false) {
1532 Module *M =
B.GetInsertBlock()->getModule();
1537 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1542 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1549 Type *CharPtrTy =
B.getPtrTy();
1556 Type *CharPtrTy =
B.getPtrTy();
1557 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy,
Ptr,
B, TLI);
1562 Type *CharPtrTy =
B.getPtrTy();
1564 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1565 {
Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1570 Type *CharPtrTy =
B.getPtrTy();
1574 LibFunc_strncmp, IntTy,
1575 {CharPtrTy, CharPtrTy, SizeTTy},
1576 {Ptr1, Ptr2, Len},
B, TLI);
1581 Type *CharPtrTy = Dst->getType();
1582 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1583 {Dst, Src},
B, TLI);
1588 Type *CharPtrTy =
B.getPtrTy();
1589 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1590 {Dst, Src},
B, TLI);
1595 Type *CharPtrTy =
B.getPtrTy();
1597 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1598 {Dst, Src, Len},
B, TLI);
1603 Type *CharPtrTy =
B.getPtrTy();
1605 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1606 {Dst, Src, Len},
B, TLI);
1612 Module *M =
B.GetInsertBlock()->getModule();
1618 Attribute::NoUnwind);
1619 Type *VoidPtrTy =
B.getPtrTy();
1623 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1624 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1633 Type *VoidPtrTy =
B.getPtrTy();
1636 {VoidPtrTy, VoidPtrTy, SizeTTy},
1637 {Dst, Src, Len},
B, TLI);
1642 Type *VoidPtrTy =
B.getPtrTy();
1646 {VoidPtrTy, IntTy, SizeTTy},
1647 {
Ptr, Val, Len},
B, TLI);
1652 Type *VoidPtrTy =
B.getPtrTy();
1656 {VoidPtrTy, IntTy, SizeTTy},
1657 {
Ptr, Val, Len},
B, TLI);
1662 Type *VoidPtrTy =
B.getPtrTy();
1666 {VoidPtrTy, VoidPtrTy, SizeTTy},
1667 {Ptr1, Ptr2, Len},
B, TLI);
1672 Type *VoidPtrTy =
B.getPtrTy();
1676 {VoidPtrTy, VoidPtrTy, SizeTTy},
1677 {Ptr1, Ptr2, Len},
B, TLI);
1682 Type *VoidPtrTy =
B.getPtrTy();
1686 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1687 {Ptr1, Ptr2, Val, Len},
B, TLI);
1693 Type *CharPtrTy =
B.getPtrTy();
1699 {CharPtrTy, SizeTTy, CharPtrTy},
1700 Args,
B, TLI,
true);
1706 Type *CharPtrTy =
B.getPtrTy();
1711 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1717 Type *CharPtrTy =
B.getPtrTy();
1719 {CharPtrTy, CharPtrTy},
1720 {Dest, Src},
B, TLI);
1725 Type *CharPtrTy =
B.getPtrTy();
1728 {CharPtrTy, CharPtrTy, SizeTTy},
1729 {Dest, Src,
Size},
B, TLI);
1734 Type *CharPtrTy =
B.getPtrTy();
1737 {CharPtrTy, CharPtrTy, SizeTTy},
1738 {Dest, Src,
Size},
B, TLI);
1743 Type *CharPtrTy =
B.getPtrTy();
1746 {CharPtrTy, CharPtrTy, SizeTTy},
1747 {Dest, Src,
Size},
B, TLI);
1752 Type *CharPtrTy =
B.getPtrTy();
1756 LibFunc_vsnprintf, IntTy,
1757 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1758 {Dest,
Size, Fmt, VAList},
B, TLI);
1763 Type *CharPtrTy =
B.getPtrTy();
1766 {CharPtrTy, CharPtrTy, VAList->
getType()},
1767 {Dest, Fmt, VAList},
B, TLI);
1773 if (!
Op->getType()->isDoubleTy()) {
1776 if (
Op->getType()->isFloatTy())
1789 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1791 Module *M =
B.GetInsertBlock()->getModule();
1800 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1802 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1825 Module *M =
B.GetInsertBlock()->getModule();
1828 LongDoubleFn, TheLibFunc);
1838 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1840 Module *M =
B.GetInsertBlock()->getModule();
1850 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1852 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1862 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1879 Module *M =
B.GetInsertBlock()->getModule();
1882 LongDoubleFn, TheLibFunc);
1891 Module *M =
B.GetInsertBlock()->getModule();
1900 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1910 Module *M =
B.GetInsertBlock()->getModule();
1919 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
1928 Module *M =
B.GetInsertBlock()->getModule();
1935 IntTy, File->getType());
1936 if (File->getType()->isPointerTy())
1938 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1941 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1948 Module *M =
B.GetInsertBlock()->getModule();
1955 B.getPtrTy(), File->getType());
1956 if (File->getType()->isPointerTy())
1958 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
1961 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1968 Module *M =
B.GetInsertBlock()->getModule();
1976 SizeTTy, SizeTTy, File->getType());
1978 if (File->getType()->isPointerTy())
1982 ConstantInt::get(SizeTTy, 1), File});
1985 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1992 Module *M =
B.GetInsertBlock()->getModule();
2004 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
2012 Module *M =
B.GetInsertBlock()->getModule();
2019 M, TLI, LibFunc_calloc,
B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2021 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
2034 Module *M =
B.GetInsertBlock()->getModule();
2044 M->getOrInsertFunction(
Name, SizedPtrT, Num->
getType(),
B.getInt8Ty());
2046 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
"sized_ptr");
2048 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2059 Module *M =
B.GetInsertBlock()->getModule();
2069 Align->getType(),
B.getInt8Ty());
2072 B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)},
"sized_ptr");
2074 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2083 Module *M =
B.GetInsertBlock()->getModule();
2089 M->getOrInsertFunction(
Name,
B.getPtrTy(), Num->
getType(),
B.getInt8Ty());
2091 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
Name);
2094 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2103 Module *M =
B.GetInsertBlock()->getModule();
2111 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
2114 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2123 Module *M =
B.GetInsertBlock()->getModule();
2134 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2144 Module *M =
B.GetInsertBlock()->getModule();
2154 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2157 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
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 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 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 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 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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static 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 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.
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 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.
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.
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.
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.
Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
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.
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.
Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value * > VariadicArgs, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
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.
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.
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.
bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
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...
Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
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.
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
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.
Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
void markRegisterParameterAttributes(Function *F)
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.
FunctionCallee getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI, LibFunc TheLibFunc, FunctionType *T, AttributeList AttributeList)
Calls getOrInsertFunction() and then makes sure to add mandatory argument attributes.
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.
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
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.
Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI, unsigned AddrSpace)
Emit a call to the calloc function.
Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
bool isReallocLikeFn(const Function *F)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value * > Args, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
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.
Value * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
Value * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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.
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.