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");
592 case LibFunc_realpath:
606 case LibFunc_readlink:
644 case LibFunc_vec_calloc:
645 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
647 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
662 case LibFunc_ctermid:
663 case LibFunc_clearerr:
664 case LibFunc_closedir:
706 case LibFunc_vec_free:
707 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
720 case LibFunc_fgetc_unlocked:
726 case LibFunc_fsetpos:
727 case LibFunc_flockfile:
728 case LibFunc_funlockfile:
729 case LibFunc_ftrylockfile:
741 case LibFunc_fputc_unlocked:
756 case LibFunc_fstatvfs:
762 case LibFunc_fgets_unlocked:
768 case LibFunc_fread_unlocked:
775 case LibFunc_fwrite_unlocked:
783 case LibFunc_fputs_unlocked:
791 case LibFunc_fprintf:
798 case LibFunc_fgetpos:
809 case LibFunc_getlogin_r:
814 case LibFunc_getc_unlocked:
826 case LibFunc_getchar:
827 case LibFunc_getchar_unlocked:
831 case LibFunc_getitimer:
836 case LibFunc_getpwnam:
858 case LibFunc_unsetenv:
874 case LibFunc_putc_unlocked:
898 case LibFunc_putchar:
899 case LibFunc_putchar_unlocked:
923 case LibFunc_vsscanf:
931 case LibFunc_vfscanf:
938 case LibFunc_vprintf:
944 case LibFunc_vfprintf:
945 case LibFunc_vsprintf:
952 case LibFunc_vsnprintf:
965 case LibFunc_opendir:
972 case LibFunc_tmpfile:
1008 case LibFunc_dunder_strndup:
1011 case LibFunc_dunder_strdup:
1018 case LibFunc_dunder_strtok_r:
1023 case LibFunc_under_IO_getc:
1028 case LibFunc_under_IO_putc:
1033 case LibFunc_dunder_isoc99_scanf:
1039 case LibFunc_stat64:
1040 case LibFunc_lstat64:
1041 case LibFunc_statvfs64:
1048 case LibFunc_dunder_isoc99_sscanf:
1056 case LibFunc_fopen64:
1065 case LibFunc_fseeko64:
1066 case LibFunc_ftello64:
1071 case LibFunc_tmpfile64:
1076 case LibFunc_fstat64:
1077 case LibFunc_fstatvfs64:
1082 case LibFunc_open64:
1088 case LibFunc_gettimeofday:
1097 case LibFunc_memset_pattern4:
1098 case LibFunc_memset_pattern8:
1099 case LibFunc_memset_pattern16:
1104 case LibFunc_memset:
1107 case LibFunc_memset_chk:
1115 case LibFunc_terminate:
1119 case LibFunc_cxa_throw:
1125 case LibFunc_nvvm_reflect:
1131 case LibFunc_ldexpf:
1132 case LibFunc_ldexpl:
1135 case LibFunc_remquo:
1136 case LibFunc_remquof:
1137 case LibFunc_remquol:
1144 case LibFunc_acoshf:
1145 case LibFunc_acoshl:
1150 case LibFunc_asinhf:
1151 case LibFunc_asinhl:
1155 case LibFunc_atan2f:
1156 case LibFunc_atan2l:
1159 case LibFunc_atanhf:
1160 case LibFunc_atanhl:
1168 case LibFunc_copysign:
1169 case LibFunc_copysignf:
1170 case LibFunc_copysignl:
1178 case LibFunc_cospif:
1189 case LibFunc_expm1f:
1190 case LibFunc_expm1l:
1198 case LibFunc_floorf:
1199 case LibFunc_floorl:
1212 case LibFunc_isascii:
1213 case LibFunc_isdigit:
1218 case LibFunc_log10f:
1219 case LibFunc_log10l:
1221 case LibFunc_log1pf:
1222 case LibFunc_log1pl:
1231 case LibFunc_nearbyint:
1232 case LibFunc_nearbyintf:
1233 case LibFunc_nearbyintl:
1237 case LibFunc_remainder:
1238 case LibFunc_remainderf:
1239 case LibFunc_remainderl:
1244 case LibFunc_roundf:
1245 case LibFunc_roundl:
1247 case LibFunc_sincospif_stret:
1254 case LibFunc_sinpif:
1264 case LibFunc_toascii:
1266 case LibFunc_truncf:
1267 case LibFunc_truncl:
1289 F.addParamAttr(ArgNo, ExtAttr);
1296 F.addRetAttr(ExtAttr);
1301 if (!
F->arg_size() ||
F->isVarArg())
1308 const Module *M =
F->getParent();
1309 unsigned N = M->getNumberRegisterParameters();
1317 if (!
T->isIntOrPtrTy())
1324 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1325 const unsigned NumRegs = TS > 4 ? 2 : 1;
1330 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1338 "Creating call to non-existing library function.");
1352 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1353 switch (TheLibFunc) {
1355 case LibFunc_putchar:
1359 case LibFunc_ldexpf:
1360 case LibFunc_ldexpl:
1361 case LibFunc_memchr:
1362 case LibFunc_memrchr:
1363 case LibFunc_strchr:
1366 case LibFunc_memccpy:
1376 case LibFunc_calloc:
1377 case LibFunc_fwrite:
1378 case LibFunc_malloc:
1379 case LibFunc_memcmp:
1380 case LibFunc_memcpy_chk:
1381 case LibFunc_mempcpy:
1382 case LibFunc_memset_pattern16:
1383 case LibFunc_snprintf:
1384 case LibFunc_stpncpy:
1385 case LibFunc_strlcat:
1386 case LibFunc_strlcpy:
1387 case LibFunc_strncat:
1388 case LibFunc_strncmp:
1389 case LibFunc_strncpy:
1390 case LibFunc_vsnprintf:
1395 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1396 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1397 "Unhandled integer argument.");
1415 if (!TLI->
has(TheLibFunc))
1420 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1421 if (
auto *
F = dyn_cast<Function>(GV))
1454 "Cannot get name for unavailable function!");
1460 TheLibFunc = FloatFn;
1463 TheLibFunc = DoubleFn;
1464 return TLI->
getName(DoubleFn);
1466 TheLibFunc = LongDoubleFn;
1467 return TLI->
getName(LongDoubleFn);
1478 const Module *M =
B.GetInsertBlock()->getModule();
1486 bool IsVaArgs =
false) {
1487 Module *M =
B.GetInsertBlock()->getModule();
1492 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1497 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1504 Type *CharPtrTy =
B.getPtrTy();
1511 Type *CharPtrTy =
B.getPtrTy();
1512 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy,
Ptr,
B, TLI);
1517 Type *CharPtrTy =
B.getPtrTy();
1519 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1520 {
Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1525 Type *CharPtrTy =
B.getPtrTy();
1529 LibFunc_strncmp, IntTy,
1530 {CharPtrTy, CharPtrTy, SizeTTy},
1531 {Ptr1, Ptr2, Len},
B, TLI);
1536 Type *CharPtrTy = Dst->getType();
1537 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1538 {Dst, Src},
B, TLI);
1543 Type *CharPtrTy =
B.getPtrTy();
1544 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1545 {Dst, Src},
B, TLI);
1550 Type *CharPtrTy =
B.getPtrTy();
1552 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1553 {Dst, Src, Len},
B, TLI);
1558 Type *CharPtrTy =
B.getPtrTy();
1560 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1561 {Dst, Src, Len},
B, TLI);
1567 Module *M =
B.GetInsertBlock()->getModule();
1573 Attribute::NoUnwind);
1574 Type *VoidPtrTy =
B.getPtrTy();
1578 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1579 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1588 Type *VoidPtrTy =
B.getPtrTy();
1591 {VoidPtrTy, VoidPtrTy, SizeTTy},
1592 {Dst, Src, Len},
B, TLI);
1597 Type *VoidPtrTy =
B.getPtrTy();
1601 {VoidPtrTy, IntTy, SizeTTy},
1602 {
Ptr, Val, Len},
B, TLI);
1607 Type *VoidPtrTy =
B.getPtrTy();
1611 {VoidPtrTy, IntTy, SizeTTy},
1612 {
Ptr, Val, Len},
B, TLI);
1617 Type *VoidPtrTy =
B.getPtrTy();
1621 {VoidPtrTy, VoidPtrTy, SizeTTy},
1622 {Ptr1, Ptr2, Len},
B, TLI);
1627 Type *VoidPtrTy =
B.getPtrTy();
1631 {VoidPtrTy, VoidPtrTy, SizeTTy},
1632 {Ptr1, Ptr2, Len},
B, TLI);
1637 Type *VoidPtrTy =
B.getPtrTy();
1641 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1642 {Ptr1, Ptr2, Val, Len},
B, TLI);
1648 Type *CharPtrTy =
B.getPtrTy();
1654 {CharPtrTy, SizeTTy, CharPtrTy},
1655 Args,
B, TLI,
true);
1661 Type *CharPtrTy =
B.getPtrTy();
1666 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1672 Type *CharPtrTy =
B.getPtrTy();
1674 {CharPtrTy, CharPtrTy},
1675 {Dest, Src},
B, TLI);
1680 Type *CharPtrTy =
B.getPtrTy();
1683 {CharPtrTy, CharPtrTy, SizeTTy},
1684 {Dest, Src,
Size},
B, TLI);
1689 Type *CharPtrTy =
B.getPtrTy();
1692 {CharPtrTy, CharPtrTy, SizeTTy},
1693 {Dest, Src,
Size},
B, TLI);
1698 Type *CharPtrTy =
B.getPtrTy();
1701 {CharPtrTy, CharPtrTy, SizeTTy},
1702 {Dest, Src,
Size},
B, TLI);
1707 Type *CharPtrTy =
B.getPtrTy();
1711 LibFunc_vsnprintf, IntTy,
1712 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1713 {Dest,
Size, Fmt, VAList},
B, TLI);
1718 Type *CharPtrTy =
B.getPtrTy();
1721 {CharPtrTy, CharPtrTy, VAList->
getType()},
1722 {Dest, Fmt, VAList},
B, TLI);
1728 if (!
Op->getType()->isDoubleTy()) {
1731 if (
Op->getType()->isFloatTy())
1744 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1746 Module *M =
B.GetInsertBlock()->getModule();
1755 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1757 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1780 Module *M =
B.GetInsertBlock()->getModule();
1783 LongDoubleFn, TheLibFunc);
1793 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1795 Module *M =
B.GetInsertBlock()->getModule();
1805 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1807 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1817 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1834 Module *M =
B.GetInsertBlock()->getModule();
1837 LongDoubleFn, TheLibFunc);
1846 Module *M =
B.GetInsertBlock()->getModule();
1855 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1865 Module *M =
B.GetInsertBlock()->getModule();
1874 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
1883 Module *M =
B.GetInsertBlock()->getModule();
1890 IntTy, File->getType());
1891 if (File->getType()->isPointerTy())
1893 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1896 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1903 Module *M =
B.GetInsertBlock()->getModule();
1910 B.getPtrTy(), File->getType());
1911 if (File->getType()->isPointerTy())
1913 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
1916 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1923 Module *M =
B.GetInsertBlock()->getModule();
1930 SizeTTy,
B.getPtrTy(), SizeTTy,
1931 SizeTTy, File->getType());
1933 if (File->getType()->isPointerTy())
1937 ConstantInt::get(SizeTTy, 1), File});
1940 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1947 Module *M =
B.GetInsertBlock()->getModule();
1954 B.getPtrTy(), SizeTTy);
1959 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
1967 Module *M =
B.GetInsertBlock()->getModule();
1974 B.getPtrTy(), SizeTTy, SizeTTy);
1976 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
1989 Module *M =
B.GetInsertBlock()->getModule();
1999 M->getOrInsertFunction(
Name, SizedPtrT, Num->
getType(),
B.getInt8Ty());
2001 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
"sized_ptr");
2003 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2014 Module *M =
B.GetInsertBlock()->getModule();
2024 Align->getType(),
B.getInt8Ty());
2027 B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)},
"sized_ptr");
2029 if (
const Function *
F = dyn_cast<Function>(Func.getCallee()))
2038 Module *M =
B.GetInsertBlock()->getModule();
2046 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
Name);
2049 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2057 LibFunc NewFunc, uint8_t HotCold) {
2058 Module *M =
B.GetInsertBlock()->getModule();
2064 M->getOrInsertFunction(
Name,
B.getPtrTy(), Num->
getType(),
2065 NoThrow->
getType(),
B.getInt8Ty());
2067 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
2070 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2078 LibFunc NewFunc, uint8_t HotCold) {
2079 Module *M =
B.GetInsertBlock()->getModule();
2090 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2099 LibFunc NewFunc, uint8_t HotCold) {
2100 Module *M =
B.GetInsertBlock()->getModule();
2107 NoThrow->
getType(),
B.getInt8Ty());
2110 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2113 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...
mir Rename Register Operands
Module.h This file contains the declarations for the Module class.
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 parameter 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 * 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 * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
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 * 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.