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");
53 if (
F.doesNotAccessMemory())
55 F.setDoesNotAccessMemory();
61 if (
F.onlyAccessesInaccessibleMemory())
63 F.setOnlyAccessesInaccessibleMemory();
64 ++NumInaccessibleMemOnly;
69 if (
F.onlyReadsMemory())
71 F.setOnlyReadsMemory();
77 if (
F.onlyWritesMemory())
80 F.setOnlyWritesMemory();
85 if (
F.onlyAccessesArgMemory())
87 F.setOnlyAccessesArgMemory();
93 if (
F.onlyAccessesInaccessibleMemOrArgMem())
95 F.setOnlyAccessesInaccessibleMemOrArgMem();
96 ++NumInaccessibleMemOrArgMemOnly;
101 if (
F.doesNotThrow())
109 if (
F.hasRetAttribute(Attribute::NoAlias))
111 F.addRetAttr(Attribute::NoAlias);
117 if (
F.hasParamAttribute(ArgNo, Attribute::NoCapture))
119 F.addParamAttr(ArgNo, Attribute::NoCapture);
125 if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
127 F.addParamAttr(ArgNo, Attribute::NoAlias);
133 if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
135 F.addParamAttr(ArgNo, Attribute::ReadOnly);
141 if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
143 F.addParamAttr(ArgNo, Attribute::WriteOnly);
149 if (!
F.getReturnType()->isVoidTy() &&
150 !
F.hasRetAttribute(Attribute::NoUndef)) {
151 F.addRetAttr(Attribute::NoUndef);
159 bool Changed =
false;
160 for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
161 if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
162 F.addParamAttr(ArgNo, Attribute::NoUndef);
171 if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
173 F.addParamAttr(ArgNo, Attribute::NoUndef);
179 bool UndefAdded =
false;
186 if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
188 F.addParamAttr(ArgNo, Attribute::Returned);
194 if (
F.hasFnAttribute(Attribute::NonLazyBind))
196 F.addFnAttr(Attribute::NonLazyBind);
201 if (
F.hasFnAttribute(Attribute::NoFree))
203 F.addFnAttr(Attribute::NoFree);
208 if (
F.hasFnAttribute(Attribute::WillReturn))
210 F.addFnAttr(Attribute::WillReturn);
216 if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
218 F.addParamAttr(ArgNo, Attribute::AllocAlign);
223 if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
225 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
230 std::optional<unsigned> NumElemsArg) {
231 if (
F.hasFnAttribute(Attribute::AllocSize))
239 if (
F.hasFnAttribute(
"alloc-family"))
241 F.addFnAttr(
"alloc-family", Family);
246 if (
F.hasFnAttribute(Attribute::AllocKind))
267 bool Changed =
false;
269 if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
272 switch (TheLibFunc) {
274 case LibFunc_strnlen:
283 case LibFunc_strrchr:
292 case LibFunc_strtoul:
293 case LibFunc_strtoll:
294 case LibFunc_strtold:
295 case LibFunc_strtoull:
302 case LibFunc_strncat:
313 case LibFunc_strncpy:
317 case LibFunc_stpncpy:
327 case LibFunc_strxfrm:
336 case LibFunc_strncmp:
337 case LibFunc_strcspn:
345 case LibFunc_strcoll:
346 case LibFunc_strcasecmp:
347 case LibFunc_strncasecmp:
357 case LibFunc_strpbrk:
365 case LibFunc_strtok_r:
378 case LibFunc_setvbuf:
383 case LibFunc_strndup:
396 case LibFunc_statvfs:
411 case LibFunc_sprintf:
420 case LibFunc_snprintf:
429 case LibFunc_setitimer:
443 case LibFunc_aligned_alloc:
446 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
450 case LibFunc_vec_malloc:
451 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_malloc ?
"vec_malloc"
453 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
470 case LibFunc_memrchr:
496 case LibFunc_memmove:
505 case LibFunc_mempcpy:
506 case LibFunc_memccpy:
509 case LibFunc_memcpy_chk:
518 case LibFunc_memalign:
520 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
521 AllocFnKind::Uninitialized);
542 case LibFunc_realloc:
543 case LibFunc_reallocf:
544 case LibFunc_vec_realloc:
546 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
570 case LibFunc_realpath:
584 case LibFunc_readlink:
622 case LibFunc_vec_calloc:
623 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
625 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
640 case LibFunc_ctermid:
641 case LibFunc_clearerr:
642 case LibFunc_closedir:
684 case LibFunc_vec_free:
685 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
698 case LibFunc_fgetc_unlocked:
704 case LibFunc_fsetpos:
705 case LibFunc_flockfile:
706 case LibFunc_funlockfile:
707 case LibFunc_ftrylockfile:
719 case LibFunc_fputc_unlocked:
734 case LibFunc_fstatvfs:
740 case LibFunc_fgets_unlocked:
746 case LibFunc_fread_unlocked:
753 case LibFunc_fwrite_unlocked:
761 case LibFunc_fputs_unlocked:
769 case LibFunc_fprintf:
776 case LibFunc_fgetpos:
787 case LibFunc_getlogin_r:
792 case LibFunc_getc_unlocked:
804 case LibFunc_getchar:
805 case LibFunc_getchar_unlocked:
809 case LibFunc_getitimer:
814 case LibFunc_getpwnam:
836 case LibFunc_unsetenv:
852 case LibFunc_putc_unlocked:
876 case LibFunc_putchar:
877 case LibFunc_putchar_unlocked:
901 case LibFunc_vsscanf:
909 case LibFunc_vfscanf:
916 case LibFunc_vprintf:
922 case LibFunc_vfprintf:
923 case LibFunc_vsprintf:
930 case LibFunc_vsnprintf:
943 case LibFunc_opendir:
950 case LibFunc_tmpfile:
986 case LibFunc_dunder_strndup:
989 case LibFunc_dunder_strdup:
996 case LibFunc_dunder_strtok_r:
1001 case LibFunc_under_IO_getc:
1006 case LibFunc_under_IO_putc:
1011 case LibFunc_dunder_isoc99_scanf:
1017 case LibFunc_stat64:
1018 case LibFunc_lstat64:
1019 case LibFunc_statvfs64:
1026 case LibFunc_dunder_isoc99_sscanf:
1034 case LibFunc_fopen64:
1043 case LibFunc_fseeko64:
1044 case LibFunc_ftello64:
1049 case LibFunc_tmpfile64:
1054 case LibFunc_fstat64:
1055 case LibFunc_fstatvfs64:
1060 case LibFunc_open64:
1066 case LibFunc_gettimeofday:
1075 case LibFunc_memset_pattern4:
1076 case LibFunc_memset_pattern8:
1077 case LibFunc_memset_pattern16:
1082 case LibFunc_memset:
1085 case LibFunc_memset_chk:
1091 case LibFunc_nvvm_reflect:
1097 case LibFunc_ldexpf:
1098 case LibFunc_ldexpl:
1105 case LibFunc_acoshf:
1106 case LibFunc_acoshl:
1111 case LibFunc_asinhf:
1112 case LibFunc_asinhl:
1116 case LibFunc_atan2f:
1117 case LibFunc_atan2l:
1120 case LibFunc_atanhf:
1121 case LibFunc_atanhl:
1129 case LibFunc_copysign:
1130 case LibFunc_copysignf:
1131 case LibFunc_copysignl:
1139 case LibFunc_cospif:
1147 case LibFunc_expm1f:
1148 case LibFunc_expm1l:
1156 case LibFunc_floorf:
1157 case LibFunc_floorl:
1170 case LibFunc_isascii:
1171 case LibFunc_isdigit:
1176 case LibFunc_log10f:
1177 case LibFunc_log10l:
1179 case LibFunc_log1pf:
1180 case LibFunc_log1pl:
1189 case LibFunc_nearbyint:
1190 case LibFunc_nearbyintf:
1191 case LibFunc_nearbyintl:
1199 case LibFunc_roundf:
1200 case LibFunc_roundl:
1202 case LibFunc_sincospif_stret:
1209 case LibFunc_sinpif:
1219 case LibFunc_toascii:
1221 case LibFunc_truncf:
1222 case LibFunc_truncl:
1244 F.addParamAttr(ArgNo, ExtAttr);
1251 F.addRetAttr(ExtAttr);
1256 if (!
F->arg_size() ||
F->isVarArg())
1263 const Module *M =
F->getParent();
1264 unsigned N = M->getNumberRegisterParameters();
1272 if (!
T->isIntOrPtrTy())
1279 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1280 const unsigned NumRegs = TS > 4 ? 2 : 1;
1285 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1293 "Creating call to non-existing library function.");
1307 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1308 switch (TheLibFunc) {
1310 case LibFunc_putchar:
1314 case LibFunc_ldexpf:
1315 case LibFunc_ldexpl:
1316 case LibFunc_memchr:
1317 case LibFunc_memrchr:
1318 case LibFunc_strchr:
1321 case LibFunc_memccpy:
1331 case LibFunc_calloc:
1332 case LibFunc_fwrite:
1333 case LibFunc_malloc:
1334 case LibFunc_memcmp:
1335 case LibFunc_memcpy_chk:
1336 case LibFunc_mempcpy:
1337 case LibFunc_memset_pattern16:
1338 case LibFunc_snprintf:
1339 case LibFunc_stpncpy:
1340 case LibFunc_strlcat:
1341 case LibFunc_strlcpy:
1342 case LibFunc_strncat:
1343 case LibFunc_strncmp:
1344 case LibFunc_strncpy:
1345 case LibFunc_vsnprintf:
1350 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1351 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1352 "Unhandled integer argument.");
1370 if (!TLI->
has(TheLibFunc))
1375 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1376 if (
auto *
F = dyn_cast<Function>(GV))
1409 "Cannot get name for unavailable function!");
1415 TheLibFunc = FloatFn;
1418 TheLibFunc = DoubleFn;
1419 return TLI->
getName(DoubleFn);
1421 TheLibFunc = LongDoubleFn;
1422 return TLI->
getName(LongDoubleFn);
1433 const Module *M =
B.GetInsertBlock()->getModule();
1441 bool IsVaArgs =
false) {
1442 Module *M =
B.GetInsertBlock()->getModule();
1447 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1452 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1459 Type *CharPtrTy =
B.getPtrTy();
1466 Type *CharPtrTy =
B.getPtrTy();
1467 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy,
Ptr,
B, TLI);
1472 Type *CharPtrTy =
B.getPtrTy();
1474 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1480 Type *CharPtrTy =
B.getPtrTy();
1484 LibFunc_strncmp, IntTy,
1485 {CharPtrTy, CharPtrTy, SizeTTy},
1486 {Ptr1, Ptr2, Len},
B, TLI);
1491 Type *CharPtrTy = Dst->getType();
1492 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1493 {Dst, Src},
B, TLI);
1498 Type *CharPtrTy =
B.getPtrTy();
1499 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1500 {Dst, Src},
B, TLI);
1505 Type *CharPtrTy =
B.getPtrTy();
1507 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1508 {Dst, Src, Len},
B, TLI);
1513 Type *CharPtrTy =
B.getPtrTy();
1515 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1516 {Dst, Src, Len},
B, TLI);
1522 Module *M =
B.GetInsertBlock()->getModule();
1528 Attribute::NoUnwind);
1529 Type *VoidPtrTy =
B.getPtrTy();
1533 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1534 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1543 Type *VoidPtrTy =
B.getPtrTy();
1546 {VoidPtrTy, VoidPtrTy, SizeTTy},
1547 {Dst, Src, Len},
B, TLI);
1552 Type *VoidPtrTy =
B.getPtrTy();
1556 {VoidPtrTy, IntTy, SizeTTy},
1557 {
Ptr, Val, Len},
B, TLI);
1562 Type *VoidPtrTy =
B.getPtrTy();
1566 {VoidPtrTy, IntTy, SizeTTy},
1567 {
Ptr, Val, Len},
B, TLI);
1572 Type *VoidPtrTy =
B.getPtrTy();
1576 {VoidPtrTy, VoidPtrTy, SizeTTy},
1577 {Ptr1, Ptr2, Len},
B, TLI);
1582 Type *VoidPtrTy =
B.getPtrTy();
1586 {VoidPtrTy, VoidPtrTy, SizeTTy},
1587 {Ptr1, Ptr2, Len},
B, TLI);
1592 Type *VoidPtrTy =
B.getPtrTy();
1596 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1597 {Ptr1, Ptr2, Val, Len},
B, TLI);
1603 Type *CharPtrTy =
B.getPtrTy();
1609 {CharPtrTy, SizeTTy, CharPtrTy},
1610 Args,
B, TLI,
true);
1616 Type *CharPtrTy =
B.getPtrTy();
1621 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1627 Type *CharPtrTy =
B.getPtrTy();
1629 {CharPtrTy, CharPtrTy},
1630 {Dest, Src},
B, TLI);
1635 Type *CharPtrTy =
B.getPtrTy();
1638 {CharPtrTy, CharPtrTy, SizeTTy},
1639 {Dest, Src,
Size},
B, TLI);
1644 Type *CharPtrTy =
B.getPtrTy();
1647 {CharPtrTy, CharPtrTy, SizeTTy},
1648 {Dest, Src,
Size},
B, TLI);
1653 Type *CharPtrTy =
B.getPtrTy();
1656 {CharPtrTy, CharPtrTy, SizeTTy},
1657 {Dest, Src,
Size},
B, TLI);
1662 Type *CharPtrTy =
B.getPtrTy();
1666 LibFunc_vsnprintf, IntTy,
1667 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1668 {Dest,
Size, Fmt, VAList},
B, TLI);
1673 Type *CharPtrTy =
B.getPtrTy();
1676 {CharPtrTy, CharPtrTy, VAList->
getType()},
1677 {Dest, Fmt, VAList},
B, TLI);
1683 if (!
Op->getType()->isDoubleTy()) {
1686 if (
Op->getType()->isFloatTy())
1699 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1701 Module *M =
B.GetInsertBlock()->getModule();
1710 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1712 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1735 Module *M =
B.GetInsertBlock()->getModule();
1738 LongDoubleFn, TheLibFunc);
1748 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1750 Module *M =
B.GetInsertBlock()->getModule();
1760 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1762 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1772 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1789 Module *M =
B.GetInsertBlock()->getModule();
1792 LongDoubleFn, TheLibFunc);
1801 Module *M =
B.GetInsertBlock()->getModule();
1810 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1820 Module *M =
B.GetInsertBlock()->getModule();
1829 CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
1838 Module *M =
B.GetInsertBlock()->getModule();
1845 IntTy, File->getType());
1846 if (File->getType()->isPointerTy())
1848 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1851 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1858 Module *M =
B.GetInsertBlock()->getModule();
1865 B.getPtrTy(), File->getType());
1866 if (File->getType()->isPointerTy())
1868 CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
1871 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1878 Module *M =
B.GetInsertBlock()->getModule();
1885 SizeTTy,
B.getPtrTy(), SizeTTy,
1886 SizeTTy, File->getType());
1888 if (File->getType()->isPointerTy())
1895 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1902 Module *M =
B.GetInsertBlock()->getModule();
1909 B.getPtrTy(), SizeTTy);
1914 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
1922 Module *M =
B.GetInsertBlock()->getModule();
1929 B.getPtrTy(), SizeTTy, SizeTTy);
1931 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
1943 Module *M =
B.GetInsertBlock()->getModule();
1951 CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
Name);
1954 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
1962 LibFunc NewFunc, uint8_t HotCold) {
1963 Module *M =
B.GetInsertBlock()->getModule();
1969 M->getOrInsertFunction(
Name,
B.getPtrTy(), Num->
getType(),
1970 NoThrow->
getType(),
B.getInt8Ty());
1972 CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
1975 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
1983 LibFunc NewFunc, uint8_t HotCold) {
1984 Module *M =
B.GetInsertBlock()->getModule();
1995 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2004 LibFunc NewFunc, uint8_t HotCold) {
2005 Module *M =
B.GetInsertBlock()->getModule();
2012 NoThrow->
getType(),
B.getInt8Ty());
2015 B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2018 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 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 void markRegisterParameterAttributes(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.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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.
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.