31#define DEBUG_TYPE "build-libcalls"
35STATISTIC(NumReadNone,
"Number of functions inferred as readnone");
37 "Number of functions inferred as inaccessiblememonly");
38STATISTIC(NumReadOnly,
"Number of functions inferred as readonly");
39STATISTIC(NumWriteOnly,
"Number of functions inferred as writeonly");
40STATISTIC(NumArgMemOnly,
"Number of functions inferred as argmemonly");
42 "Number of functions inferred as inaccessiblemem_or_argmemonly");
43STATISTIC(NumNoUnwind,
"Number of functions inferred as nounwind");
44STATISTIC(NumNoCapture,
"Number of arguments inferred as nocapture");
45STATISTIC(NumWriteOnlyArg,
"Number of arguments inferred as writeonly");
46STATISTIC(NumReadOnlyArg,
"Number of arguments inferred as readonly");
47STATISTIC(NumNoAlias,
"Number of function returns inferred as noalias");
48STATISTIC(NumNoUndef,
"Number of function returns inferred as noundef returns");
49STATISTIC(NumReturnedArg,
"Number of arguments inferred as returned");
50STATISTIC(NumWillReturn,
"Number of functions inferred as willreturn");
51STATISTIC(NumCold,
"Number of functions inferred as cold");
54 if (
F.doesNotAccessMemory())
56 F.setDoesNotAccessMemory();
62 if (
F.hasFnAttribute(Attribute::Cold))
64 F.addFnAttr(Attribute::Cold);
70 if (
F.onlyAccessesInaccessibleMemory())
72 F.setOnlyAccessesInaccessibleMemory();
73 ++NumInaccessibleMemOnly;
78 if (
F.onlyReadsMemory())
80 F.setOnlyReadsMemory();
86 if (
F.onlyWritesMemory())
89 F.setOnlyWritesMemory();
94 if (
F.onlyAccessesArgMemory())
96 F.setOnlyAccessesArgMemory();
102 if (
F.onlyAccessesInaccessibleMemOrArgMem())
104 F.setOnlyAccessesInaccessibleMemOrArgMem();
105 ++NumInaccessibleMemOrArgMemOnly;
110 if (
F.doesNotThrow())
118 if (
F.hasRetAttribute(Attribute::NoAlias))
120 F.addRetAttr(Attribute::NoAlias);
126 if (
F.hasParamAttribute(ArgNo, Attribute::NoCapture))
128 F.addParamAttr(ArgNo, Attribute::NoCapture);
134 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
136 F.addParamAttr(ArgNo, Attribute::NoAlias);
142 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
144 F.addParamAttr(ArgNo, Attribute::ReadOnly);
150 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
152 F.addParamAttr(ArgNo, Attribute::WriteOnly);
158 if (!
F.getReturnType()->isVoidTy() &&
159 !
F.hasRetAttribute(Attribute::NoUndef)) {
160 F.addRetAttr(Attribute::NoUndef);
168 bool Changed =
false;
169 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
170 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
171 F.addParamAttr(ArgNo, Attribute::NoUndef);
180 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
182 F.addParamAttr(ArgNo, Attribute::NoUndef);
188 bool UndefAdded =
false;
195 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
197 F.addParamAttr(ArgNo, Attribute::Returned);
203 if (
F.hasFnAttribute(Attribute::NonLazyBind))
205 F.addFnAttr(Attribute::NonLazyBind);
210 if (
F.hasFnAttribute(Attribute::NoFree))
212 F.addFnAttr(Attribute::NoFree);
217 if (
F.hasFnAttribute(Attribute::WillReturn))
219 F.addFnAttr(Attribute::WillReturn);
225 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
227 F.addParamAttr(ArgNo, Attribute::AllocAlign);
232 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
234 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
239 std::optional<unsigned> NumElemsArg) {
240 if (
F.hasFnAttribute(Attribute::AllocSize))
248 if (
F.hasFnAttribute(
"alloc-family"))
250 F.addFnAttr(
"alloc-family", Family);
255 if (
F.hasFnAttribute(Attribute::AllocKind))
276 bool Changed =
false;
278 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
281 switch (TheLibFunc) {
286 case LibFunc_strnlen:
295 case LibFunc_strrchr:
304 case LibFunc_strtoul:
305 case LibFunc_strtoll:
306 case LibFunc_strtold:
307 case LibFunc_strtoull:
314 case LibFunc_strncat:
325 case LibFunc_strncpy:
329 case LibFunc_stpncpy:
339 case LibFunc_strxfrm:
348 case LibFunc_strncmp:
349 case LibFunc_strcspn:
357 case LibFunc_strcoll:
358 case LibFunc_strcasecmp:
359 case LibFunc_strncasecmp:
369 case LibFunc_strpbrk:
377 case LibFunc_strtok_r:
390 case LibFunc_setvbuf:
395 case LibFunc_strndup:
408 case LibFunc_statvfs:
423 case LibFunc_sprintf:
432 case LibFunc_snprintf:
441 case LibFunc_setitimer:
455 case LibFunc_aligned_alloc:
458 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
462 case LibFunc_vec_malloc:
463 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_malloc ?
"vec_malloc"
465 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
482 case LibFunc_memrchr:
508 case LibFunc_memmove:
517 case LibFunc_mempcpy:
518 case LibFunc_memccpy:
521 case LibFunc_memcpy_chk:
530 case LibFunc_memalign:
532 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
533 AllocFnKind::Uninitialized);
554 case LibFunc_realloc:
555 case LibFunc_reallocf:
556 case LibFunc_vec_realloc:
558 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
582 case LibFunc_realpath:
596 case LibFunc_readlink:
634 case LibFunc_vec_calloc:
635 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
637 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
652 case LibFunc_ctermid:
653 case LibFunc_clearerr:
654 case LibFunc_closedir:
696 case LibFunc_vec_free:
697 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
710 case LibFunc_fgetc_unlocked:
716 case LibFunc_fsetpos:
717 case LibFunc_flockfile:
718 case LibFunc_funlockfile:
719 case LibFunc_ftrylockfile:
731 case LibFunc_fputc_unlocked:
746 case LibFunc_fstatvfs:
752 case LibFunc_fgets_unlocked:
758 case LibFunc_fread_unlocked:
765 case LibFunc_fwrite_unlocked:
773 case LibFunc_fputs_unlocked:
781 case LibFunc_fprintf:
788 case LibFunc_fgetpos:
799 case LibFunc_getlogin_r:
804 case LibFunc_getc_unlocked:
816 case LibFunc_getchar:
817 case LibFunc_getchar_unlocked:
821 case LibFunc_getitimer:
826 case LibFunc_getpwnam:
848 case LibFunc_unsetenv:
864 case LibFunc_putc_unlocked:
888 case LibFunc_putchar:
889 case LibFunc_putchar_unlocked:
913 case LibFunc_vsscanf:
921 case LibFunc_vfscanf:
928 case LibFunc_vprintf:
934 case LibFunc_vfprintf:
935 case LibFunc_vsprintf:
942 case LibFunc_vsnprintf:
955 case LibFunc_opendir:
962 case LibFunc_tmpfile:
998 case LibFunc_dunder_strndup:
1001 case LibFunc_dunder_strdup:
1008 case LibFunc_dunder_strtok_r:
1013 case LibFunc_under_IO_getc:
1018 case LibFunc_under_IO_putc:
1023 case LibFunc_dunder_isoc99_scanf:
1029 case LibFunc_stat64:
1030 case LibFunc_lstat64:
1031 case LibFunc_statvfs64:
1038 case LibFunc_dunder_isoc99_sscanf:
1046 case LibFunc_fopen64:
1055 case LibFunc_fseeko64:
1056 case LibFunc_ftello64:
1061 case LibFunc_tmpfile64:
1066 case LibFunc_fstat64:
1067 case LibFunc_fstatvfs64:
1072 case LibFunc_open64:
1078 case LibFunc_gettimeofday:
1087 case LibFunc_memset_pattern4:
1088 case LibFunc_memset_pattern8:
1089 case LibFunc_memset_pattern16:
1094 case LibFunc_memset:
1097 case LibFunc_memset_chk:
1106 case LibFunc_nvvm_reflect:
1112 case LibFunc_ldexpf:
1113 case LibFunc_ldexpl:
1116 case LibFunc_remquo:
1117 case LibFunc_remquof:
1118 case LibFunc_remquol:
1125 case LibFunc_acoshf:
1126 case LibFunc_acoshl:
1131 case LibFunc_asinhf:
1132 case LibFunc_asinhl:
1136 case LibFunc_atan2f:
1137 case LibFunc_atan2l:
1140 case LibFunc_atanhf:
1141 case LibFunc_atanhl:
1149 case LibFunc_copysign:
1150 case LibFunc_copysignf:
1151 case LibFunc_copysignl:
1159 case LibFunc_cospif:
1170 case LibFunc_expm1f:
1171 case LibFunc_expm1l:
1179 case LibFunc_floorf:
1180 case LibFunc_floorl:
1193 case LibFunc_isascii:
1194 case LibFunc_isdigit:
1199 case LibFunc_log10f:
1200 case LibFunc_log10l:
1202 case LibFunc_log1pf:
1203 case LibFunc_log1pl:
1212 case LibFunc_nearbyint:
1213 case LibFunc_nearbyintf:
1214 case LibFunc_nearbyintl:
1218 case LibFunc_remainder:
1219 case LibFunc_remainderf:
1220 case LibFunc_remainderl:
1225 case LibFunc_roundf:
1226 case LibFunc_roundl:
1228 case LibFunc_sincospif_stret:
1235 case LibFunc_sinpif:
1245 case LibFunc_toascii:
1247 case LibFunc_truncf:
1248 case LibFunc_truncl:
1270 F.addParamAttr(ArgNo, ExtAttr);
1277 F.addRetAttr(ExtAttr);
1282 if (!
F->arg_size() ||
F->isVarArg())
1289 const Module *M =
F->getParent();
1290 unsigned N = M->getNumberRegisterParameters();
1298 if (!
T->isIntOrPtrTy())
1305 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1306 const unsigned NumRegs = TS > 4 ? 2 : 1;
1311 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1319 "Creating call to non-existing library function.");
1333 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1334 switch (TheLibFunc) {
1336 case LibFunc_putchar:
1340 case LibFunc_ldexpf:
1341 case LibFunc_ldexpl:
1342 case LibFunc_memchr:
1343 case LibFunc_memrchr:
1344 case LibFunc_strchr:
1347 case LibFunc_memccpy:
1357 case LibFunc_calloc:
1358 case LibFunc_fwrite:
1359 case LibFunc_malloc:
1360 case LibFunc_memcmp:
1361 case LibFunc_memcpy_chk:
1362 case LibFunc_mempcpy:
1363 case LibFunc_memset_pattern16:
1364 case LibFunc_snprintf:
1365 case LibFunc_stpncpy:
1366 case LibFunc_strlcat:
1367 case LibFunc_strlcpy:
1368 case LibFunc_strncat:
1369 case LibFunc_strncmp:
1370 case LibFunc_strncpy:
1371 case LibFunc_vsnprintf:
1376 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1377 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1378 "Unhandled integer argument.");
1396 if (!TLI->
has(TheLibFunc))
1401 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1402 if (
auto *
F = dyn_cast<Function>(GV))
1435 "Cannot get name for unavailable function!");
1441 TheLibFunc = FloatFn;
1444 TheLibFunc = DoubleFn;
1445 return TLI->
getName(DoubleFn);
1447 TheLibFunc = LongDoubleFn;
1448 return TLI->
getName(LongDoubleFn);
1459 const Module *M =
B.GetInsertBlock()->getModule();
1467 bool IsVaArgs =
false) {
1468 Module *M =
B.GetInsertBlock()->getModule();
1473 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1478 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1485 Type *CharPtrTy =
B.getPtrTy();
1492 Type *CharPtrTy =
B.getPtrTy();
1493 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy,
Ptr,
B, TLI);
1498 Type *CharPtrTy =
B.getPtrTy();
1500 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1501 {
Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1506 Type *CharPtrTy =
B.getPtrTy();
1510 LibFunc_strncmp, IntTy,
1511 {CharPtrTy, CharPtrTy, SizeTTy},
1512 {Ptr1, Ptr2, Len},
B, TLI);
1517 Type *CharPtrTy = Dst->getType();
1518 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1519 {Dst, Src},
B, TLI);
1524 Type *CharPtrTy =
B.getPtrTy();
1525 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1526 {Dst, Src},
B, TLI);
1531 Type *CharPtrTy =
B.getPtrTy();
1533 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1534 {Dst, Src, Len},
B, TLI);
1539 Type *CharPtrTy =
B.getPtrTy();
1541 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1542 {Dst, Src, Len},
B, TLI);
1548 Module *M =
B.GetInsertBlock()->getModule();
1554 Attribute::NoUnwind);
1555 Type *VoidPtrTy =
B.getPtrTy();
1559 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1560 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1569 Type *VoidPtrTy =
B.getPtrTy();
1572 {VoidPtrTy, VoidPtrTy, SizeTTy},
1573 {Dst, Src, Len},
B, TLI);
1578 Type *VoidPtrTy =
B.getPtrTy();
1582 {VoidPtrTy, IntTy, SizeTTy},
1583 {
Ptr, Val, Len},
B, TLI);
1588 Type *VoidPtrTy =
B.getPtrTy();
1592 {VoidPtrTy, IntTy, SizeTTy},
1593 {
Ptr, Val, Len},
B, TLI);
1598 Type *VoidPtrTy =
B.getPtrTy();
1602 {VoidPtrTy, VoidPtrTy, SizeTTy},
1603 {Ptr1, Ptr2, Len},
B, TLI);
1608 Type *VoidPtrTy =
B.getPtrTy();
1612 {VoidPtrTy, VoidPtrTy, SizeTTy},
1613 {Ptr1, Ptr2, Len},
B, TLI);
1618 Type *VoidPtrTy =
B.getPtrTy();
1622 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1623 {Ptr1, Ptr2, Val, Len},
B, TLI);
1629 Type *CharPtrTy =
B.getPtrTy();
1635 {CharPtrTy, SizeTTy, CharPtrTy},
1636 Args,
B, TLI,
true);
1642 Type *CharPtrTy =
B.getPtrTy();
1647 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1653 Type *CharPtrTy =
B.getPtrTy();
1655 {CharPtrTy, CharPtrTy},
1656 {Dest, Src},
B, TLI);
1661 Type *CharPtrTy =
B.getPtrTy();
1664 {CharPtrTy, CharPtrTy, SizeTTy},
1665 {Dest, Src,
Size},
B, TLI);
1670 Type *CharPtrTy =
B.getPtrTy();
1673 {CharPtrTy, CharPtrTy, SizeTTy},
1674 {Dest, Src,
Size},
B, TLI);
1679 Type *CharPtrTy =
B.getPtrTy();
1682 {CharPtrTy, CharPtrTy, SizeTTy},
1683 {Dest, Src,
Size},
B, TLI);
1688 Type *CharPtrTy =
B.getPtrTy();
1692 LibFunc_vsnprintf, IntTy,
1693 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1694 {Dest,
Size, Fmt, VAList},
B, TLI);
1699 Type *CharPtrTy =
B.getPtrTy();
1702 {CharPtrTy, CharPtrTy, VAList->
getType()},
1703 {Dest, Fmt, VAList},
B, TLI);
1709 if (!
Op->getType()->isDoubleTy()) {
1712 if (
Op->getType()->isFloatTy())
1725 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1727 Module *M =
B.GetInsertBlock()->getModule();
1736 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1738 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1761 Module *M =
B.GetInsertBlock()->getModule();
1764 LongDoubleFn, TheLibFunc);
1774 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1776 Module *M =
B.GetInsertBlock()->getModule();
1786 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1788 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1798 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1815 Module *M =
B.GetInsertBlock()->getModule();
1818 LongDoubleFn, TheLibFunc);
1827 Module *M =
B.GetInsertBlock()->getModule();
1836 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1846 Module *M =
B.GetInsertBlock()->getModule();
1855 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
1864 Module *M =
B.GetInsertBlock()->getModule();
1871 IntTy, File->getType());
1872 if (File->getType()->isPointerTy())
1874 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1877 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1884 Module *M =
B.GetInsertBlock()->getModule();
1891 B.getPtrTy(), File->getType());
1892 if (File->getType()->isPointerTy())
1894 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
1897 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1904 Module *M =
B.GetInsertBlock()->getModule();
1911 SizeTTy,
B.getPtrTy(), SizeTTy,
1912 SizeTTy, File->getType());
1914 if (File->getType()->isPointerTy())
1918 ConstantInt::get(SizeTTy, 1), File});
1921 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1928 Module *M =
B.GetInsertBlock()->getModule();
1935 B.getPtrTy(), SizeTTy);
1940 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
1948 Module *M =
B.GetInsertBlock()->getModule();
1955 B.getPtrTy(), SizeTTy, SizeTTy);
1957 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
1969 Module *M =
B.GetInsertBlock()->getModule();
1977 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
Name);
1980 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
1988 LibFunc NewFunc, uint8_t HotCold) {
1989 Module *M =
B.GetInsertBlock()->getModule();
1995 M->getOrInsertFunction(
Name,
B.getPtrTy(), Num->
getType(),
1996 NoThrow->
getType(),
B.getInt8Ty());
1998 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
2001 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2009 LibFunc NewFunc, uint8_t HotCold) {
2010 Module *M =
B.GetInsertBlock()->getModule();
2021 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2030 LibFunc NewFunc, uint8_t HotCold) {
2031 Module *M =
B.GetInsertBlock()->getModule();
2038 NoThrow->
getType(),
B.getInt8Ty());
2041 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2044 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 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.
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 * 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 * 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.