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::NoCapture))
138 F.addParamAttr(ArgNo, Attribute::NoCapture);
144 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
146 F.addParamAttr(ArgNo, Attribute::NoAlias);
152 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
154 F.addParamAttr(ArgNo, Attribute::ReadOnly);
160 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
162 F.addParamAttr(ArgNo, Attribute::WriteOnly);
168 if (!
F.getReturnType()->isVoidTy() &&
169 !
F.hasRetAttribute(Attribute::NoUndef)) {
170 F.addRetAttr(Attribute::NoUndef);
178 bool Changed =
false;
179 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
180 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
181 F.addParamAttr(ArgNo, Attribute::NoUndef);
190 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
192 F.addParamAttr(ArgNo, Attribute::NoUndef);
198 bool UndefAdded =
false;
205 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
207 F.addParamAttr(ArgNo, Attribute::Returned);
213 if (
F.hasFnAttribute(Attribute::NonLazyBind))
215 F.addFnAttr(Attribute::NonLazyBind);
220 if (
F.hasFnAttribute(Attribute::NoFree))
222 F.addFnAttr(Attribute::NoFree);
227 if (
F.hasFnAttribute(Attribute::WillReturn))
229 F.addFnAttr(Attribute::WillReturn);
235 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
237 F.addParamAttr(ArgNo, Attribute::AllocAlign);
242 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
244 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
249 std::optional<unsigned> NumElemsArg) {
250 if (
F.hasFnAttribute(Attribute::AllocSize))
258 if (
F.hasFnAttribute(
"alloc-family"))
260 F.addFnAttr(
"alloc-family", Family);
265 if (
F.hasFnAttribute(Attribute::AllocKind))
286 bool Changed =
false;
288 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
291 switch (TheLibFunc) {
296 case LibFunc_strnlen:
305 case LibFunc_strrchr:
314 case LibFunc_strtoul:
315 case LibFunc_strtoll:
316 case LibFunc_strtold:
317 case LibFunc_strtoull:
324 case LibFunc_strncat:
335 case LibFunc_strncpy:
339 case LibFunc_stpncpy:
349 case LibFunc_strxfrm:
358 case LibFunc_strncmp:
359 case LibFunc_strcspn:
367 case LibFunc_strcoll:
368 case LibFunc_strcasecmp:
369 case LibFunc_strncasecmp:
379 case LibFunc_strpbrk:
387 case LibFunc_strtok_r:
400 case LibFunc_setvbuf:
405 case LibFunc_strndup:
418 case LibFunc_statvfs:
433 case LibFunc_sprintf:
442 case LibFunc_snprintf:
451 case LibFunc_setitimer:
465 case LibFunc_aligned_alloc:
468 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
472 case LibFunc_vec_malloc:
473 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_malloc ?
"vec_malloc"
475 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
492 case LibFunc_memrchr:
518 case LibFunc_memmove:
527 case LibFunc_mempcpy:
528 case LibFunc_memccpy:
531 case LibFunc_memcpy_chk:
540 case LibFunc_memalign:
542 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
543 AllocFnKind::Uninitialized);
564 case LibFunc_realloc:
565 case LibFunc_reallocf:
566 case LibFunc_vec_realloc:
568 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
580 case LibFunc_reallocarray:
606 case LibFunc_realpath:
620 case LibFunc_readlink:
658 case LibFunc_vec_calloc:
659 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
661 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
676 case LibFunc_ctermid:
677 case LibFunc_clearerr:
678 case LibFunc_closedir:
720 case LibFunc_vec_free:
721 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
734 case LibFunc_fgetc_unlocked:
740 case LibFunc_fsetpos:
741 case LibFunc_flockfile:
742 case LibFunc_funlockfile:
743 case LibFunc_ftrylockfile:
755 case LibFunc_fputc_unlocked:
770 case LibFunc_fstatvfs:
776 case LibFunc_fgets_unlocked:
782 case LibFunc_fread_unlocked:
789 case LibFunc_fwrite_unlocked:
797 case LibFunc_fputs_unlocked:
805 case LibFunc_fprintf:
812 case LibFunc_fgetpos:
823 case LibFunc_getlogin_r:
828 case LibFunc_getc_unlocked:
840 case LibFunc_getchar:
841 case LibFunc_getchar_unlocked:
845 case LibFunc_getitimer:
850 case LibFunc_getpwnam:
872 case LibFunc_unsetenv:
888 case LibFunc_putc_unlocked:
912 case LibFunc_putchar:
913 case LibFunc_putchar_unlocked:
937 case LibFunc_vsscanf:
945 case LibFunc_vfscanf:
952 case LibFunc_vprintf:
958 case LibFunc_vfprintf:
959 case LibFunc_vsprintf:
966 case LibFunc_vsnprintf:
979 case LibFunc_opendir:
986 case LibFunc_tmpfile:
1010 case LibFunc_lchown:
1022 case LibFunc_dunder_strndup:
1025 case LibFunc_dunder_strdup:
1032 case LibFunc_dunder_strtok_r:
1037 case LibFunc_under_IO_getc:
1042 case LibFunc_under_IO_putc:
1047 case LibFunc_dunder_isoc99_scanf:
1053 case LibFunc_stat64:
1054 case LibFunc_lstat64:
1055 case LibFunc_statvfs64:
1062 case LibFunc_dunder_isoc99_sscanf:
1070 case LibFunc_fopen64:
1079 case LibFunc_fseeko64:
1080 case LibFunc_ftello64:
1085 case LibFunc_tmpfile64:
1090 case LibFunc_fstat64:
1091 case LibFunc_fstatvfs64:
1096 case LibFunc_open64:
1102 case LibFunc_gettimeofday:
1111 case LibFunc_memset_pattern4:
1112 case LibFunc_memset_pattern8:
1113 case LibFunc_memset_pattern16:
1118 case LibFunc_memset:
1121 case LibFunc_memset_chk:
1129 case LibFunc_terminate:
1133 case LibFunc_cxa_throw:
1139 case LibFunc_nvvm_reflect:
1145 case LibFunc_ldexpf:
1146 case LibFunc_ldexpl:
1149 case LibFunc_remquo:
1150 case LibFunc_remquof:
1151 case LibFunc_remquol:
1158 case LibFunc_acoshf:
1159 case LibFunc_acoshl:
1164 case LibFunc_asinhf:
1165 case LibFunc_asinhl:
1169 case LibFunc_atan2f:
1170 case LibFunc_atan2l:
1173 case LibFunc_atanhf:
1174 case LibFunc_atanhl:
1182 case LibFunc_copysign:
1183 case LibFunc_copysignf:
1184 case LibFunc_copysignl:
1192 case LibFunc_cospif:
1196 case LibFunc_tgamma:
1197 case LibFunc_tgammaf:
1198 case LibFunc_tgammal:
1206 case LibFunc_expm1f:
1207 case LibFunc_expm1l:
1218 case LibFunc_floorf:
1219 case LibFunc_floorl:
1233 case LibFunc_hypotf:
1234 case LibFunc_hypotl:
1235 case LibFunc_isascii:
1236 case LibFunc_isdigit:
1241 case LibFunc_log10f:
1242 case LibFunc_log10l:
1244 case LibFunc_log1pf:
1245 case LibFunc_log1pl:
1253 case LibFunc_ilogbf:
1254 case LibFunc_ilogbl:
1257 case LibFunc_nearbyint:
1258 case LibFunc_nearbyintf:
1259 case LibFunc_nearbyintl:
1263 case LibFunc_remainder:
1264 case LibFunc_remainderf:
1265 case LibFunc_remainderl:
1270 case LibFunc_roundf:
1271 case LibFunc_roundl:
1272 case LibFunc_scalbln:
1273 case LibFunc_scalblnf:
1274 case LibFunc_scalblnl:
1275 case LibFunc_scalbn:
1276 case LibFunc_scalbnf:
1277 case LibFunc_scalbnl:
1279 case LibFunc_sincospif_stret:
1286 case LibFunc_sinpif:
1296 case LibFunc_toascii:
1298 case LibFunc_truncf:
1299 case LibFunc_truncl:
1305 case LibFunc_sincos:
1306 case LibFunc_sincosf:
1307 case LibFunc_sincosl:
1333 F.addParamAttr(ArgNo, ExtAttr);
1340 F.addRetAttr(ExtAttr);
1345 if (!
F->arg_size() ||
F->isVarArg())
1352 const Module *M =
F->getParent();
1353 unsigned N = M->getNumberRegisterParameters();
1361 if (!
T->isIntOrPtrTy())
1368 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1369 const unsigned NumRegs = TS > 4 ? 2 : 1;
1374 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1382 "Creating call to non-existing library function.");
1396 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1397 switch (TheLibFunc) {
1399 case LibFunc_putchar:
1403 case LibFunc_ldexpf:
1404 case LibFunc_ldexpl:
1405 case LibFunc_memchr:
1406 case LibFunc_memrchr:
1407 case LibFunc_strchr:
1410 case LibFunc_memccpy:
1420 case LibFunc_calloc:
1421 case LibFunc_fwrite:
1422 case LibFunc_malloc:
1423 case LibFunc_memcmp:
1424 case LibFunc_memcpy_chk:
1425 case LibFunc_mempcpy:
1426 case LibFunc_memset_pattern16:
1427 case LibFunc_snprintf:
1428 case LibFunc_stpncpy:
1429 case LibFunc_strlcat:
1430 case LibFunc_strlcpy:
1431 case LibFunc_strncat:
1432 case LibFunc_strncmp:
1433 case LibFunc_strncpy:
1434 case LibFunc_vsnprintf:
1439 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1440 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1441 "Unhandled integer argument.");
1459 if (!TLI->
has(TheLibFunc))
1464 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1465 if (
auto *
F = dyn_cast<Function>(GV))
1498 "Cannot get name for unavailable function!");
1504 TheLibFunc = FloatFn;
1507 TheLibFunc = DoubleFn;
1508 return TLI->
getName(DoubleFn);
1510 TheLibFunc = LongDoubleFn;
1511 return TLI->
getName(LongDoubleFn);
1522 const Module *M =
B.GetInsertBlock()->getModule();
1530 bool IsVaArgs =
false) {
1531 Module *M =
B.GetInsertBlock()->getModule();
1536 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1541 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1548 Type *CharPtrTy =
Ptr->getType();
1555 Type *CharPtrTy =
Ptr->getType();
1556 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy,
Ptr,
B, TLI);
1561 Type *CharPtrTy =
Ptr->getType();
1563 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1564 {
Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1574 LibFunc_strncmp, IntTy,
1575 {CharPtrTy, CharPtrTy, SizeTTy},
1576 {Ptr1, Ptr2, Len},
B, TLI);
1581 Type *CharPtrTy = Dst->getType();
1582 assert(CharPtrTy == Src->getType());
1583 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1584 {Dst, Src},
B, TLI);
1589 Type *CharPtrTy = Dst->getType();
1590 assert(CharPtrTy == Src->getType());
1591 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1592 {Dst, Src},
B, TLI);
1597 Type *CharPtrTy = Dst->getType();
1598 assert(CharPtrTy == Src->getType());
1600 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1601 {Dst, Src, Len},
B, TLI);
1606 Type *CharPtrTy = Dst->getType();
1607 assert(CharPtrTy == Src->getType());
1609 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1610 {Dst, Src, Len},
B, TLI);
1616 Module *M =
B.GetInsertBlock()->getModule();
1622 Attribute::NoUnwind);
1623 Type *VoidPtrTy = Dst->getType();
1624 assert(VoidPtrTy == Src->getType());
1628 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1629 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1638 Type *VoidPtrTy = Dst->getType();
1639 assert(VoidPtrTy == Src->getType());
1642 {VoidPtrTy, VoidPtrTy, SizeTTy},
1643 {Dst, Src, Len},
B, TLI);
1648 Type *VoidPtrTy =
Ptr->getType();
1652 {VoidPtrTy, IntTy, SizeTTy},
1653 {
Ptr, Val, Len},
B, TLI);
1658 Type *VoidPtrTy =
Ptr->getType();
1662 {VoidPtrTy, IntTy, SizeTTy},
1663 {
Ptr, Val, Len},
B, TLI);
1673 {VoidPtrTy, VoidPtrTy, SizeTTy},
1674 {Ptr1, Ptr2, Len},
B, TLI);
1684 {VoidPtrTy, VoidPtrTy, SizeTTy},
1685 {Ptr1, Ptr2, Len},
B, TLI);
1695 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1696 {Ptr1, Ptr2, Val, Len},
B, TLI);
1709 {CharPtrTy, SizeTTy, CharPtrTy},
1710 Args,
B, TLI,
true);
1721 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1728 assert(CharPtrTy == Src->getType());
1730 {CharPtrTy, CharPtrTy},
1731 {Dest, Src},
B, TLI);
1737 assert(CharPtrTy == Src->getType());
1740 {CharPtrTy, CharPtrTy, SizeTTy},
1741 {Dest, Src,
Size},
B, TLI);
1747 assert(CharPtrTy == Src->getType());
1750 {CharPtrTy, CharPtrTy, SizeTTy},
1751 {Dest, Src,
Size},
B, TLI);
1757 assert(CharPtrTy == Src->getType());
1760 {CharPtrTy, CharPtrTy, SizeTTy},
1761 {Dest, Src,
Size},
B, TLI);
1771 LibFunc_vsnprintf, IntTy,
1772 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1773 {Dest,
Size, Fmt, VAList},
B, TLI);
1782 {CharPtrTy, CharPtrTy, VAList->
getType()},
1783 {Dest, Fmt, VAList},
B, TLI);
1789 if (!
Op->getType()->isDoubleTy()) {
1792 if (
Op->getType()->isFloatTy())
1805 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1807 Module *M =
B.GetInsertBlock()->getModule();
1816 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1818 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1841 Module *M =
B.GetInsertBlock()->getModule();
1844 LongDoubleFn, TheLibFunc);
1854 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1856 Module *M =
B.GetInsertBlock()->getModule();
1866 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1868 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1878 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1895 Module *M =
B.GetInsertBlock()->getModule();
1898 LongDoubleFn, TheLibFunc);
1907 Module *M =
B.GetInsertBlock()->getModule();
1916 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1926 Module *M =
B.GetInsertBlock()->getModule();
1935 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
1944 Module *M =
B.GetInsertBlock()->getModule();
1951 IntTy, File->getType());
1952 if (File->getType()->isPointerTy())
1954 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1957 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1964 Module *M =
B.GetInsertBlock()->getModule();
1971 Str->getType(), File->getType());
1972 if (File->getType()->isPointerTy())
1974 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
1977 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1984 Module *M =
B.GetInsertBlock()->getModule();
1992 SizeTTy, SizeTTy, File->getType());
1994 if (File->getType()->isPointerTy())
1998 ConstantInt::get(SizeTTy, 1), File});
2001 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
2008 Module *M =
B.GetInsertBlock()->getModule();
2020 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
2028 Module *M =
B.GetInsertBlock()->getModule();
2037 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
2051 Module *M =
B.GetInsertBlock()->getModule();
2061 M->getOrInsertFunction(
Name, SizedPtrT, Num->
getType(),
B.getInt8Ty());
2063 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
"sized_ptr");
2065 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2076 Module *M =
B.GetInsertBlock()->getModule();
2086 Align->getType(),
B.getInt8Ty());
2089 B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)},
"sized_ptr");
2091 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2100 Module *M =
B.GetInsertBlock()->getModule();
2108 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
Name);
2111 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2121 Module *M =
B.GetInsertBlock()->getModule();
2129 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
2132 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2142 Module *M =
B.GetInsertBlock()->getModule();
2148 Align->getType(),
B.getInt8Ty());
2153 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2163 Module *M =
B.GetInsertBlock()->getModule();
2170 NoThrow->
getType(),
B.getInt8Ty());
2173 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2176 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.
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.
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 * emitHotColdNewNoThrow(Type *RetTy, Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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 * emitMalloc(Type *RetTy, Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Value * emitHotColdSizeReturningNew(Type *RetTy, Value *Num, 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 * emitHotColdNew(Type *RetTy, Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
Value * emitHotColdNewAlignedNoThrow(Type *RetTy, Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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 * emitHotColdSizeReturningNewAligned(Type *RetTy, Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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)
Value * emitCalloc(Type *RetTy, Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
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 * 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 * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
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 * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
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.
Value * emitHotColdNewAligned(Type *RetTy, Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
This struct is a compact representation of a valid (non-zero power of two) alignment.