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:
494 case LibFunc_memmove:
503 case LibFunc_mempcpy:
504 case LibFunc_memccpy:
507 case LibFunc_memcpy_chk:
516 case LibFunc_memalign:
518 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
519 AllocFnKind::Uninitialized);
540 case LibFunc_realloc:
541 case LibFunc_reallocf:
542 case LibFunc_vec_realloc:
544 F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
568 case LibFunc_realpath:
582 case LibFunc_readlink:
620 case LibFunc_vec_calloc:
621 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc"
623 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
638 case LibFunc_ctermid:
639 case LibFunc_clearerr:
640 case LibFunc_closedir:
682 case LibFunc_vec_free:
683 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc"
696 case LibFunc_fgetc_unlocked:
702 case LibFunc_fsetpos:
703 case LibFunc_flockfile:
704 case LibFunc_funlockfile:
705 case LibFunc_ftrylockfile:
717 case LibFunc_fputc_unlocked:
730 case LibFunc_fstatvfs:
736 case LibFunc_fgets_unlocked:
742 case LibFunc_fread_unlocked:
749 case LibFunc_fwrite_unlocked:
757 case LibFunc_fputs_unlocked:
765 case LibFunc_fprintf:
772 case LibFunc_fgetpos:
783 case LibFunc_getlogin_r:
788 case LibFunc_getc_unlocked:
800 case LibFunc_getchar:
801 case LibFunc_getchar_unlocked:
805 case LibFunc_getitimer:
810 case LibFunc_getpwnam:
832 case LibFunc_unsetenv:
848 case LibFunc_putc_unlocked:
872 case LibFunc_putchar:
873 case LibFunc_putchar_unlocked:
897 case LibFunc_vsscanf:
905 case LibFunc_vfscanf:
912 case LibFunc_vprintf:
918 case LibFunc_vfprintf:
919 case LibFunc_vsprintf:
926 case LibFunc_vsnprintf:
939 case LibFunc_opendir:
946 case LibFunc_tmpfile:
982 case LibFunc_dunder_strndup:
985 case LibFunc_dunder_strdup:
992 case LibFunc_dunder_strtok_r:
997 case LibFunc_under_IO_getc:
1002 case LibFunc_under_IO_putc:
1007 case LibFunc_dunder_isoc99_scanf:
1013 case LibFunc_stat64:
1014 case LibFunc_lstat64:
1015 case LibFunc_statvfs64:
1022 case LibFunc_dunder_isoc99_sscanf:
1030 case LibFunc_fopen64:
1039 case LibFunc_fseeko64:
1040 case LibFunc_ftello64:
1045 case LibFunc_tmpfile64:
1050 case LibFunc_fstat64:
1051 case LibFunc_fstatvfs64:
1056 case LibFunc_open64:
1062 case LibFunc_gettimeofday:
1071 case LibFunc_memset_pattern4:
1072 case LibFunc_memset_pattern8:
1073 case LibFunc_memset_pattern16:
1078 case LibFunc_memset:
1081 case LibFunc_memset_chk:
1087 case LibFunc_nvvm_reflect:
1093 case LibFunc_ldexpf:
1094 case LibFunc_ldexpl:
1101 case LibFunc_acoshf:
1102 case LibFunc_acoshl:
1107 case LibFunc_asinhf:
1108 case LibFunc_asinhl:
1112 case LibFunc_atan2f:
1113 case LibFunc_atan2l:
1116 case LibFunc_atanhf:
1117 case LibFunc_atanhl:
1125 case LibFunc_copysign:
1126 case LibFunc_copysignf:
1127 case LibFunc_copysignl:
1135 case LibFunc_cospif:
1143 case LibFunc_expm1f:
1144 case LibFunc_expm1l:
1152 case LibFunc_floorf:
1153 case LibFunc_floorl:
1166 case LibFunc_isascii:
1167 case LibFunc_isdigit:
1172 case LibFunc_log10f:
1173 case LibFunc_log10l:
1175 case LibFunc_log1pf:
1176 case LibFunc_log1pl:
1185 case LibFunc_nearbyint:
1186 case LibFunc_nearbyintf:
1187 case LibFunc_nearbyintl:
1195 case LibFunc_roundf:
1196 case LibFunc_roundl:
1198 case LibFunc_sincospif_stret:
1205 case LibFunc_sinpif:
1215 case LibFunc_toascii:
1217 case LibFunc_truncf:
1218 case LibFunc_truncl:
1240 F.addParamAttr(ArgNo, ExtAttr);
1247 F.addRetAttr(ExtAttr);
1252 if (!
F->arg_size() ||
F->isVarArg())
1259 const Module *M =
F->getParent();
1260 unsigned N = M->getNumberRegisterParameters();
1268 if (!
T->isIntOrPtrTy())
1275 assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1276 const unsigned NumRegs = TS > 4 ? 2 : 1;
1281 F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1289 "Creating call to non-existing library function.");
1303 assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1304 switch (TheLibFunc) {
1306 case LibFunc_putchar:
1310 case LibFunc_ldexpf:
1311 case LibFunc_ldexpl:
1312 case LibFunc_memchr:
1313 case LibFunc_memrchr:
1314 case LibFunc_strchr:
1317 case LibFunc_memccpy:
1327 case LibFunc_calloc:
1328 case LibFunc_fwrite:
1329 case LibFunc_malloc:
1330 case LibFunc_memcmp:
1331 case LibFunc_memcpy_chk:
1332 case LibFunc_mempcpy:
1333 case LibFunc_memset_pattern16:
1334 case LibFunc_snprintf:
1335 case LibFunc_stpncpy:
1336 case LibFunc_strlcat:
1337 case LibFunc_strlcpy:
1338 case LibFunc_strncat:
1339 case LibFunc_strncmp:
1340 case LibFunc_strncpy:
1341 case LibFunc_vsnprintf:
1346 for (
unsigned i = 0; i <
T->getNumParams(); i++)
1347 assert(!isa<IntegerType>(
T->getParamType(i)) &&
1348 "Unhandled integer argument.");
1366 if (!TLI->
has(TheLibFunc))
1371 if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1372 if (
auto *
F = dyn_cast<Function>(GV))
1405 "Cannot get name for unavailable function!");
1411 TheLibFunc = FloatFn;
1414 TheLibFunc = DoubleFn;
1415 return TLI->
getName(DoubleFn);
1417 TheLibFunc = LongDoubleFn;
1418 return TLI->
getName(LongDoubleFn);
1426 return B.CreateBitCast(V,
B.getInt8PtrTy(AS),
"cstr");
1434 const Module *M =
B.GetInsertBlock()->getModule();
1442 bool IsVaArgs =
false) {
1443 Module *M =
B.GetInsertBlock()->getModule();
1448 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1467 return emitLibCall(LibFunc_strdup,
B.getInt8PtrTy(),
B.getInt8PtrTy(),
1473 Type *I8Ptr =
B.getInt8PtrTy();
1475 return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, IntTy},
1484 LibFunc_strncmp, IntTy,
1485 {
B.getInt8PtrTy(),
B.getInt8PtrTy(), SizeTTy},
1491 Type *I8Ptr = Dst->getType();
1492 return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
1498 Type *I8Ptr =
B.getInt8PtrTy();
1499 return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
1505 Type *I8Ptr =
B.getInt8PtrTy();
1507 return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
1513 Type *I8Ptr =
B.getInt8PtrTy();
1515 return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
1522 Module *M =
B.GetInsertBlock()->getModule();
1528 Attribute::NoUnwind);
1529 Type *I8Ptr =
B.getInt8PtrTy();
1533 I8Ptr, I8Ptr, SizeTTy, SizeTTy);
1536 CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1545 Type *I8Ptr =
B.getInt8PtrTy();
1548 {I8Ptr, I8Ptr, SizeTTy},
1549 {Dst, Src, Len},
B, TLI);
1554 Type *I8Ptr =
B.getInt8PtrTy();
1558 {I8Ptr, IntTy, SizeTTy},
1564 Type *I8Ptr =
B.getInt8PtrTy();
1568 {I8Ptr, IntTy, SizeTTy},
1574 Type *I8Ptr =
B.getInt8PtrTy();
1578 {I8Ptr, I8Ptr, SizeTTy},
1584 Type *I8Ptr =
B.getInt8PtrTy();
1588 {I8Ptr, I8Ptr, SizeTTy},
1594 Type *I8Ptr =
B.getInt8PtrTy();
1598 {I8Ptr, I8Ptr, IntTy, SizeTTy},
1599 {Ptr1, Ptr2, Val, Len},
B, TLI);
1605 Type *I8Ptr =
B.getInt8PtrTy();
1611 {I8Ptr, SizeTTy, I8Ptr},
1612 Args,
B, TLI,
true);
1618 Type *I8Ptr =
B.getInt8PtrTy();
1623 {I8Ptr, I8Ptr}, Args,
B, TLI,
1630 {B.getInt8PtrTy(), B.getInt8PtrTy()},
1631 {castToCStr(Dest, B), castToCStr(Src, B)},
B, TLI);
1636 Type *I8Ptr =
B.getInt8PtrTy();
1639 {I8Ptr, I8Ptr, SizeTTy},
1645 Type *I8Ptr =
B.getInt8PtrTy();
1648 {I8Ptr, I8Ptr, SizeTTy},
1654 Type *I8Ptr =
B.getInt8PtrTy();
1657 {I8Ptr, I8Ptr, SizeTTy},
1663 Type *I8Ptr =
B.getInt8PtrTy();
1667 LibFunc_vsnprintf, IntTy,
1668 {I8Ptr, SizeTTy, I8Ptr, VAList->
getType()},
1674 Type *I8Ptr =
B.getInt8PtrTy();
1677 {I8Ptr, I8Ptr, VAList->
getType()},
1684 if (!Op->getType()->isDoubleTy()) {
1687 if (Op->getType()->isFloatTy())
1700 assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1702 Module *M =
B.GetInsertBlock()->getModule();
1711 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1736 Module *M =
B.GetInsertBlock()->getModule();
1739 LongDoubleFn, TheLibFunc);
1749 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1751 Module *M =
B.GetInsertBlock()->getModule();
1761 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1773 assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1790 Module *M =
B.GetInsertBlock()->getModule();
1793 LongDoubleFn, TheLibFunc);
1802 Module *M =
B.GetInsertBlock()->getModule();
1811 CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1821 Module *M =
B.GetInsertBlock()->getModule();
1839 Module *M =
B.GetInsertBlock()->getModule();
1846 IntTy, File->getType());
1847 if (File->getType()->isPointerTy())
1849 CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1852 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1859 Module *M =
B.GetInsertBlock()->getModule();
1866 B.getInt8PtrTy(), File->getType());
1867 if (File->getType()->isPointerTy())
1872 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1879 Module *M =
B.GetInsertBlock()->getModule();
1886 SizeTTy,
B.getInt8PtrTy(), SizeTTy,
1887 SizeTTy, File->getType());
1889 if (File->getType()->isPointerTy())
1896 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1903 Module *M =
B.GetInsertBlock()->getModule();
1910 B.getInt8PtrTy(), SizeTTy);
1915 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
1923 Module *M =
B.GetInsertBlock()->getModule();
1930 B.getInt8PtrTy(), SizeTTy, SizeTTy);
1932 CallInst *CI =
B.CreateCall(Calloc, {Num,
Size}, CallocName);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu Simplify well known AMD library false FunctionCallee Callee
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.
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.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ 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 * castToCStr(Value *V, IRBuilderBase &B)
Return V if it is an i8*, otherwise cast it to i8*.
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 a range to a container.
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 * 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 * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.