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");
66 if (
F.doesNotAccessMemory())
68 F.setDoesNotAccessMemory();
74 if (
F.hasFnAttribute(Attribute::Cold))
76 F.addFnAttr(Attribute::Cold);
82 if (
F.hasFnAttribute(Attribute::NoReturn))
84 F.addFnAttr(Attribute::NoReturn);
94 F.setMemoryEffects(NewME);
122 ++NumInaccessibleMemOrArgMemOnly;
130 ++NumInaccessibleMemOrErrnoMemOnly;
138 ++NumInaccessibleMemOrArgMemOrErrnoMemOnly;
145 ++NumWriteErrnoMemOnly;
153 ++NumWriteArgumentMemOrErrnoMemOnly;
158 if (
F.doesNotThrow())
166 if (
F.hasFnAttribute(Attribute::NoCallback))
168 F.addFnAttr(Attribute::NoCallback);
174 if (
F.hasRetAttribute(Attribute::NoAlias))
176 F.addRetAttr(Attribute::NoAlias);
182 if (
F.hasParamAttribute(ArgNo, Attribute::Captures))
191 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
193 F.addParamAttr(ArgNo, Attribute::NoAlias);
199 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
201 F.addParamAttr(ArgNo, Attribute::ReadOnly);
207 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
209 F.addParamAttr(ArgNo, Attribute::WriteOnly);
215 if (!
F.getReturnType()->isVoidTy() &&
216 !
F.hasRetAttribute(Attribute::NoUndef)) {
217 F.addRetAttr(Attribute::NoUndef);
226 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
227 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
228 F.addParamAttr(ArgNo, Attribute::NoUndef);
237 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
239 F.addParamAttr(ArgNo, Attribute::NoUndef);
245 bool UndefAdded =
false;
252 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
254 F.addParamAttr(ArgNo, Attribute::Returned);
260 if (
F.hasFnAttribute(Attribute::NonLazyBind))
262 F.addFnAttr(Attribute::NonLazyBind);
267 if (
F.hasFnAttribute(Attribute::NoFree))
269 F.addFnAttr(Attribute::NoFree);
274 if (
F.hasFnAttribute(Attribute::WillReturn))
276 F.addFnAttr(Attribute::WillReturn);
282 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
284 F.addParamAttr(ArgNo, Attribute::AllocAlign);
289 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
291 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
296 std::optional<unsigned> NumElemsArg) {
297 if (
F.hasFnAttribute(Attribute::AllocSize))
305 if (
F.hasFnAttribute(
"alloc-family"))
307 F.addFnAttr(
"alloc-family", Family);
312 if (
F.hasFnAttribute(Attribute::AllocKind))
335 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
338 switch (TheLibFunc) {
343 case LibFunc_strnlen:
353 case LibFunc_strrchr:
363 case LibFunc_strtoul:
364 case LibFunc_strtoll:
365 case LibFunc_strtold:
366 case LibFunc_strtoull:
374 case LibFunc_strncat:
386 case LibFunc_strncpy:
390 case LibFunc_stpncpy:
401 case LibFunc_strxfrm:
411 case LibFunc_strncmp:
412 case LibFunc_strcspn:
421 case LibFunc_strcoll:
422 case LibFunc_strcasecmp:
423 case LibFunc_strncasecmp:
434 case LibFunc_strpbrk:
443 case LibFunc_strtok_r:
457 case LibFunc_setvbuf:
462 case LibFunc_strndup:
475 case LibFunc_statvfs:
490 case LibFunc_sprintf:
499 case LibFunc_snprintf:
508 case LibFunc_setitimer:
522 case LibFunc_aligned_alloc:
529 case LibFunc_vec_malloc:
532 case LibFunc_pvalloc:
552 case LibFunc_memrchr:
581 case LibFunc_memmove:
591 case LibFunc_mempcpy:
592 case LibFunc_memccpy:
595 case LibFunc_memcpy_chk:
605 case LibFunc_memalign:
629 case LibFunc_realloc:
630 case LibFunc_reallocf:
631 case LibFunc_vec_realloc:
633 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
645 case LibFunc_reallocarray:
671 case LibFunc_realpath:
685 case LibFunc_readlink:
726 case LibFunc_vec_calloc:
744 case LibFunc_ctermid:
745 case LibFunc_clearerr:
746 case LibFunc_closedir:
789 case LibFunc_vec_free:
803 case LibFunc_fgetc_unlocked:
809 case LibFunc_fsetpos:
810 case LibFunc_flockfile:
811 case LibFunc_funlockfile:
812 case LibFunc_ftrylockfile:
824 case LibFunc_fputc_unlocked:
840 case LibFunc_fstatvfs:
846 case LibFunc_fgets_unlocked:
853 case LibFunc_fread_unlocked:
861 case LibFunc_fwrite_unlocked:
869 case LibFunc_fputs_unlocked:
877 case LibFunc_fprintf:
884 case LibFunc_fgetpos:
895 case LibFunc_getlogin_r:
900 case LibFunc_getc_unlocked:
912 case LibFunc_getchar:
913 case LibFunc_getchar_unlocked:
917 case LibFunc_getitimer:
922 case LibFunc_getpwnam:
944 case LibFunc_unsetenv:
960 case LibFunc_putc_unlocked:
984 case LibFunc_putchar:
985 case LibFunc_putchar_unlocked:
1003 case LibFunc_vscanf:
1009 case LibFunc_vsscanf:
1017 case LibFunc_vfscanf:
1024 case LibFunc_vprintf:
1030 case LibFunc_vfprintf:
1031 case LibFunc_vsprintf:
1038 case LibFunc_vsnprintf:
1051 case LibFunc_opendir:
1058 case LibFunc_tmpfile:
1083 case LibFunc_lchown:
1095 case LibFunc_dunder_strndup:
1098 case LibFunc_dunder_strdup:
1105 case LibFunc_dunder_strtok_r:
1111 case LibFunc_under_IO_getc:
1116 case LibFunc_under_IO_putc:
1121 case LibFunc_dunder_isoc99_scanf:
1127 case LibFunc_stat64:
1128 case LibFunc_lstat64:
1129 case LibFunc_statvfs64:
1136 case LibFunc_dunder_isoc99_sscanf:
1144 case LibFunc_fopen64:
1153 case LibFunc_fseeko64:
1154 case LibFunc_ftello64:
1159 case LibFunc_tmpfile64:
1164 case LibFunc_fstat64:
1165 case LibFunc_fstatvfs64:
1170 case LibFunc_open64:
1176 case LibFunc_gettimeofday:
1185 case LibFunc_memset_pattern4:
1186 case LibFunc_memset_pattern8:
1187 case LibFunc_memset_pattern16:
1192 case LibFunc_memset:
1195 case LibFunc_memset_chk:
1206 case LibFunc_terminate:
1211 case LibFunc_cxa_throw:
1217 case LibFunc_nvvm_reflect:
1225 case LibFunc_acoshf:
1226 case LibFunc_acoshl:
1231 case LibFunc_asinhf:
1232 case LibFunc_asinhl:
1236 case LibFunc_atan2f:
1237 case LibFunc_atan2l:
1240 case LibFunc_atanhf:
1241 case LibFunc_atanhl:
1250 case LibFunc_cospif:
1254 case LibFunc_tgamma:
1255 case LibFunc_tgammaf:
1256 case LibFunc_tgammal:
1264 case LibFunc_expm1f:
1265 case LibFunc_expm1l:
1273 case LibFunc_hypotf:
1274 case LibFunc_hypotl:
1276 case LibFunc_ldexpf:
1277 case LibFunc_ldexpl:
1280 case LibFunc_log10f:
1281 case LibFunc_log10l:
1283 case LibFunc_log1pf:
1284 case LibFunc_log1pl:
1292 case LibFunc_ilogbf:
1293 case LibFunc_ilogbl:
1296 case LibFunc_nextafter:
1297 case LibFunc_nextafterf:
1298 case LibFunc_nextafterl:
1299 case LibFunc_nexttoward:
1300 case LibFunc_nexttowardf:
1301 case LibFunc_nexttowardl:
1305 case LibFunc_remainder:
1306 case LibFunc_remainderf:
1307 case LibFunc_remainderl:
1311 case LibFunc_scalbln:
1312 case LibFunc_scalblnf:
1313 case LibFunc_scalblnl:
1314 case LibFunc_scalbn:
1315 case LibFunc_scalbnf:
1316 case LibFunc_scalbnl:
1318 case LibFunc_sincospif_stret:
1325 case LibFunc_sinpif:
1345 case LibFunc_copysign:
1346 case LibFunc_copysignf:
1347 case LibFunc_copysignl:
1358 case LibFunc_floorf:
1359 case LibFunc_floorl:
1369 case LibFunc_fmaximum_num:
1370 case LibFunc_fmaximum_numf:
1371 case LibFunc_fmaximum_numl:
1372 case LibFunc_fminimum_num:
1373 case LibFunc_fminimum_numf:
1374 case LibFunc_fminimum_numl:
1377 case LibFunc_nearbyint:
1378 case LibFunc_nearbyintf:
1379 case LibFunc_nearbyintl:
1381 case LibFunc_roundf:
1382 case LibFunc_roundl:
1383 case LibFunc_roundeven:
1384 case LibFunc_roundevenf:
1385 case LibFunc_roundevenl:
1386 case LibFunc_toascii:
1388 case LibFunc_truncf:
1389 case LibFunc_truncl:
1392 case LibFunc_isascii:
1393 case LibFunc_isdigit:
1399 case LibFunc_sincos:
1400 case LibFunc_sincosf:
1401 case LibFunc_sincosl:
1405 case LibFunc_remquo:
1406 case LibFunc_remquof:
1407 case LibFunc_remquol:
1432 F.addParamAttr(ArgNo, ExtAttr);
1439 F.addRetAttr(ExtAttr);
1444 if (!
F->arg_size() ||
F->isVarArg())
1451 const Module *M =
F->getParent();
1452 unsigned N = M->getNumberRegisterParameters();
1460 if (!
T->isIntOrPtrTy())
1467 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1468 const unsigned NumRegs = TS > 4 ? 2 : 1;
1473 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1479 AttributeList AttributeList) {
1481 "Creating call to non-existing library function.");
1495 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1496 switch (TheLibFunc) {
1498 case LibFunc_putchar:
1502 case LibFunc_ldexpf:
1503 case LibFunc_ldexpl:
1504 case LibFunc_memchr:
1505 case LibFunc_memrchr:
1506 case LibFunc_strchr:
1509 case LibFunc_memccpy:
1519 case LibFunc_calloc:
1520 case LibFunc_fwrite:
1521 case LibFunc_malloc:
1522 case LibFunc_memcmp:
1523 case LibFunc_memcpy_chk:
1524 case LibFunc_mempcpy:
1525 case LibFunc_memset_pattern16:
1526 case LibFunc_snprintf:
1527 case LibFunc_stpncpy:
1528 case LibFunc_strlcat:
1529 case LibFunc_strlcpy:
1530 case LibFunc_strncat:
1531 case LibFunc_strncmp:
1532 case LibFunc_strncpy:
1533 case LibFunc_vsnprintf:
1538 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1540 "Unhandled integer argument.");
1556 LibFunc TheLibFunc) {
1558 if (!TLI->
has(TheLibFunc))
1563 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1580 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1581 switch (Ty->getTypeID()) {
1594 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1595 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1597 "Cannot get name for unavailable function!");
1599 switch (Ty->getTypeID()) {
1603 TheLibFunc = FloatFn;
1606 TheLibFunc = DoubleFn;
1607 return TLI->
getName(DoubleFn);
1609 TheLibFunc = LongDoubleFn;
1610 return TLI->
getName(LongDoubleFn);
1621 const Module *M =
B.GetInsertBlock()->getModule();
1629 bool IsVaArgs =
false) {
1630 Module *M =
B.GetInsertBlock()->getModule();
1638 CallInst *CI =
B.CreateCall(Callee, Operands, FuncName);
1647 Type *CharPtrTy =
B.getPtrTy();
1649 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr,
B, TLI);
1655 "Argument to wcslen intrinsic must be a pointer.");
1656 Type *PtrTy =
B.getPtrTy();
1658 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr,
B, TLI);
1663 Type *CharPtrTy =
B.getPtrTy();
1664 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr,
B, TLI);
1669 Type *CharPtrTy =
B.getPtrTy();
1671 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1672 {Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1677 Type *CharPtrTy =
B.getPtrTy();
1681 LibFunc_strncmp, IntTy,
1682 {CharPtrTy, CharPtrTy, SizeTTy},
1683 {Ptr1, Ptr2, Len},
B, TLI);
1688 Type *CharPtrTy = Dst->getType();
1689 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1690 {Dst, Src},
B, TLI);
1695 Type *CharPtrTy =
B.getPtrTy();
1696 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1697 {Dst, Src},
B, TLI);
1702 Type *CharPtrTy =
B.getPtrTy();
1704 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1705 {Dst, Src, Len},
B, TLI);
1710 Type *CharPtrTy =
B.getPtrTy();
1712 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1713 {Dst, Src, Len},
B, TLI);
1719 Module *M =
B.GetInsertBlock()->getModule();
1724 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1725 Attribute::NoUnwind);
1726 Type *VoidPtrTy =
B.getPtrTy();
1729 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1730 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1731 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1740 Type *VoidPtrTy =
B.getPtrTy();
1743 {VoidPtrTy, VoidPtrTy, SizeTTy},
1744 {Dst, Src, Len},
B, TLI);
1749 Type *VoidPtrTy =
B.getPtrTy();
1753 {VoidPtrTy, IntTy, SizeTTy},
1754 {Ptr, Val, Len},
B, TLI);
1759 Type *VoidPtrTy =
B.getPtrTy();
1763 {VoidPtrTy, IntTy, SizeTTy},
1764 {Ptr, Val, Len},
B, TLI);
1769 Type *VoidPtrTy =
B.getPtrTy();
1773 {VoidPtrTy, VoidPtrTy, SizeTTy},
1774 {Ptr1, Ptr2, Len},
B, TLI);
1779 Type *VoidPtrTy =
B.getPtrTy();
1783 {VoidPtrTy, VoidPtrTy, SizeTTy},
1784 {Ptr1, Ptr2, Len},
B, TLI);
1789 Type *VoidPtrTy =
B.getPtrTy();
1793 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1794 {Ptr1, Ptr2, Val, Len},
B, TLI);
1800 Type *CharPtrTy =
B.getPtrTy();
1806 {CharPtrTy, SizeTTy, CharPtrTy},
1807 Args,
B, TLI,
true);
1813 Type *CharPtrTy =
B.getPtrTy();
1818 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1824 Type *CharPtrTy =
B.getPtrTy();
1826 {CharPtrTy, CharPtrTy},
1827 {Dest, Src},
B, TLI);
1832 Type *CharPtrTy =
B.getPtrTy();
1835 {CharPtrTy, CharPtrTy, SizeTTy},
1836 {Dest, Src,
Size},
B, TLI);
1841 Type *CharPtrTy =
B.getPtrTy();
1844 {CharPtrTy, CharPtrTy, SizeTTy},
1845 {Dest, Src,
Size},
B, TLI);
1850 Type *CharPtrTy =
B.getPtrTy();
1853 {CharPtrTy, CharPtrTy, SizeTTy},
1854 {Dest, Src,
Size},
B, TLI);
1859 Type *CharPtrTy =
B.getPtrTy();
1863 LibFunc_vsnprintf, IntTy,
1864 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1865 {Dest,
Size, Fmt, VAList},
B, TLI);
1870 Type *CharPtrTy =
B.getPtrTy();
1873 {CharPtrTy, CharPtrTy, VAList->
getType()},
1874 {Dest, Fmt, VAList},
B, TLI);
1880 if (!
Op->getType()->isDoubleTy()) {
1883 if (
Op->getType()->isFloatTy())
1894 const AttributeList &Attrs,
1896 assert((Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1898 Module *M =
B.GetInsertBlock()->getModule();
1907 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1917 const AttributeList &Attrs) {
1928 LibFunc DoubleFn, LibFunc FloatFn,
1930 const AttributeList &Attrs) {
1932 Module *M =
B.GetInsertBlock()->getModule();
1935 LongDoubleFn, TheLibFunc);
1943 const AttributeList &Attrs,
1945 assert((Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1947 Module *M =
B.GetInsertBlock()->getModule();
1951 CallInst *CI =
B.CreateCall(Callee, { Op1, Op2 }, Name);
1957 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1968 const AttributeList &Attrs) {
1969 assert((Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1982 LibFunc DoubleFn, LibFunc FloatFn,
1984 const AttributeList &Attrs) {
1986 Module *M =
B.GetInsertBlock()->getModule();
1989 LongDoubleFn, TheLibFunc);
1998 Module *M =
B.GetInsertBlock()->getModule();
2007 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
2017 Module *M =
B.GetInsertBlock()->getModule();
2026 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
2035 Module *M =
B.GetInsertBlock()->getModule();
2042 IntTy, File->getType());
2043 if (File->getType()->isPointerTy())
2045 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
2055 Module *M =
B.GetInsertBlock()->getModule();
2062 B.getPtrTy(), File->getType());
2063 if (File->getType()->isPointerTy())
2065 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
2075 Module *M =
B.GetInsertBlock()->getModule();
2083 SizeTTy, SizeTTy, File->getType());
2085 if (File->getType()->isPointerTy())
2088 B.CreateCall(
F, {Ptr,
Size,
2089 ConstantInt::get(SizeTTy, 1), File});
2099 Module *M =
B.GetInsertBlock()->getModule();
2119 Module *M =
B.GetInsertBlock()->getModule();
2126 M, TLI, LibFunc_calloc,
B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2128 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
2139 LibFunc SizeFeedbackNewFunc,
2141 Module *M =
B.GetInsertBlock()->getModule();
2151 M->getOrInsertFunction(Name, SizedPtrT, Num->
getType(),
B.getInt8Ty());
2153 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
"sized_ptr");
2164 LibFunc SizeFeedbackNewFunc,
2166 Module *M =
B.GetInsertBlock()->getModule();
2176 Align->getType(),
B.getInt8Ty());
2179 B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)},
"sized_ptr");
2190 Module *M =
B.GetInsertBlock()->getModule();
2196 M->getOrInsertFunction(Name,
B.getPtrTy(), Num->
getType(),
B.getInt8Ty());
2198 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)}, Name);
2209 LibFunc NewFunc,
uint8_t HotCold) {
2210 Module *M =
B.GetInsertBlock()->getModule();
2218 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)}, Name);
2229 LibFunc NewFunc,
uint8_t HotCold) {
2230 Module *M =
B.GetInsertBlock()->getModule();
2236 Name,
B.getPtrTy(), Num->
getType(),
Align->getType(),
B.getInt8Ty());
2238 CallInst *CI =
B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)}, Name);
2250 LibFunc NewFunc,
uint8_t HotCold) {
2251 Module *M =
B.GetInsertBlock()->getModule();
2261 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(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 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< 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.
ArrayRef - 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.
StringRef - Represent a constant reference to a string, i.e.
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Provides information about what library functions are available for the current target.
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F, const Module &M) const
Return true if the function type FTy is valid for the library function F, regardless of whether the f...
bool has(LibFunc F) const
Tests whether a library function is available.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
StringRef getName(LibFunc F) const
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
The instances of the Type class are immutable: once they are created, they are never changed.
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 * emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
LLVM_ABI Value * emitStrChr(Value *Ptr, char C, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
LLVM_ABI Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
LLVM_ABI Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
LLVM_ABI Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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 * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
LLVM_ABI bool isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI, LibFunc TheLibFunc)
Check whether the library function is available on target and also that it in the current Module is a...
LLVM_ABI Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
LLVM_ABI Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
LLVM_ABI Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
LLVM_ABI Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
LLVM_ABI Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
LLVM_ABI Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
LLVM_ABI Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
LLVM_ABI void markRegisterParameterAttributes(Function *F)
LLVM_ABI StringRef getFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn, LibFunc &TheLibFunc)
Get the name of the overloaded floating point function corresponding to Ty.
LLVM_ABI FunctionCallee getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI, LibFunc TheLibFunc, FunctionType *T, AttributeList AttributeList)
Calls getOrInsertFunction() and then makes sure to add mandatory argument attributes.
LLVM_ABI Value * emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
LLVM_ABI Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
LLVM_ABI Value * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
LLVM_ABI Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI, unsigned AddrSpace)
Emit a call to the calloc function.
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 * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
LLVM_ABI Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
LLVM_ABI Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_ABI Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
LLVM_ABI Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
LLVM_ABI Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
LLVM_ABI Value * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
LLVM_ABI Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.
This struct is a compact representation of a valid (non-zero power of two) alignment.