1//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file implements some functions that will create standard C libcalls. 11//===----------------------------------------------------------------------===// 32#define DEBUG_TYPE "build-libcalls" 34//- Infer Attributes ---------------------------------------------------------// 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");
56if (
F.doesNotAccessMemory())
58F.setDoesNotAccessMemory();
64if (
F.hasFnAttribute(Attribute::Cold))
66F.addFnAttr(Attribute::Cold);
72if (
F.hasFnAttribute(Attribute::NoReturn))
74F.addFnAttr(Attribute::NoReturn);
80if (
F.onlyAccessesInaccessibleMemory())
82F.setOnlyAccessesInaccessibleMemory();
83 ++NumInaccessibleMemOnly;
88if (
F.onlyReadsMemory())
90F.setOnlyReadsMemory();
96if (
F.onlyWritesMemory())
// writeonly or readnone 99F.setOnlyWritesMemory();
104if (
F.onlyAccessesArgMemory())
106F.setOnlyAccessesArgMemory();
112if (
F.onlyAccessesInaccessibleMemOrArgMem())
114F.setOnlyAccessesInaccessibleMemOrArgMem();
115 ++NumInaccessibleMemOrArgMemOnly;
128if (
F.hasRetAttribute(Attribute::NoAlias))
130F.addRetAttr(Attribute::NoAlias);
136if (
F.hasParamAttribute(ArgNo, Attribute::NoCapture))
138F.addParamAttr(ArgNo, Attribute::NoCapture);
144if (
F.hasParamAttribute(ArgNo, Attribute::NoAlias))
146F.addParamAttr(ArgNo, Attribute::NoAlias);
152if (
F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
154F.addParamAttr(ArgNo, Attribute::ReadOnly);
160if (
F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
162F.addParamAttr(ArgNo, Attribute::WriteOnly);
168if (!
F.getReturnType()->isVoidTy() &&
169 !
F.hasRetAttribute(Attribute::NoUndef)) {
170F.addRetAttr(Attribute::NoUndef);
179for (
unsigned ArgNo = 0; ArgNo <
F.arg_size(); ++ArgNo) {
180if (!
F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
181F.addParamAttr(ArgNo, Attribute::NoUndef);
190if (
F.hasParamAttribute(ArgNo, Attribute::NoUndef))
192F.addParamAttr(ArgNo, Attribute::NoUndef);
198bool UndefAdded =
false;
205if (
F.hasParamAttribute(ArgNo, Attribute::Returned))
207F.addParamAttr(ArgNo, Attribute::Returned);
213if (
F.hasFnAttribute(Attribute::NonLazyBind))
215F.addFnAttr(Attribute::NonLazyBind);
220if (
F.hasFnAttribute(Attribute::NoFree))
222F.addFnAttr(Attribute::NoFree);
227if (
F.hasFnAttribute(Attribute::WillReturn))
229F.addFnAttr(Attribute::WillReturn);
235if (
F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
237F.addParamAttr(ArgNo, Attribute::AllocAlign);
242if (
F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
244F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
249 std::optional<unsigned> NumElemsArg) {
250if (
F.hasFnAttribute(Attribute::AllocSize))
258if (
F.hasFnAttribute(
"alloc-family"))
260F.addFnAttr(
"alloc-family", Family);
265if (
F.hasFnAttribute(Attribute::AllocKind))
288if (
F.getParent() !=
nullptr &&
F.getParent()->getRtLibUseGOT())
317case LibFunc_strtoull:
356case LibFunc_strcmp:
// 0,1 357case LibFunc_strspn:
// 0,1 358case LibFunc_strncmp:
// 0,1 359case LibFunc_strcspn:
// 0,1 368case LibFunc_strcasecmp:
// 0,1 369case LibFunc_strncasecmp:
// 370// Those functions may depend on the locale, which may be accessed through 387case LibFunc_strtok_r:
442case LibFunc_snprintf:
451case LibFunc_setitimer:
460// May throw; "system" is a valid pthread cancellation point. 465case LibFunc_aligned_alloc:
468 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
472case LibFunc_vec_malloc:
473 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_malloc ?
"vec_malloc" 475 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
531case LibFunc_memcpy_chk:
540case LibFunc_memalign:
542 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Aligned |
543 AllocFnKind::Uninitialized);
565case LibFunc_reallocf:
566case LibFunc_vec_realloc:
568F, TheLibFunc == LibFunc_vec_realloc ?
"vec_malloc" :
"malloc");
580case LibFunc_reallocarray:
595// May throw; "read" is a valid pthread cancellation point. 606case LibFunc_realpath:
620case LibFunc_readlink:
628// May throw; "write" is a valid pthread cancellation point. 658case LibFunc_vec_calloc:
659 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_calloc ?
"vec_malloc" 661 Changed |=
setAllocKind(
F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
677case LibFunc_clearerr:
678case LibFunc_closedir:
720case LibFunc_vec_free:
721 Changed |=
setAllocFamily(
F, TheLibFunc == LibFunc_vec_free ?
"vec_malloc" 734case LibFunc_fgetc_unlocked:
741case LibFunc_flockfile:
742case LibFunc_funlockfile:
743case LibFunc_ftrylockfile:
755case LibFunc_fputc_unlocked:
770case LibFunc_fstatvfs:
776case LibFunc_fgets_unlocked:
782case LibFunc_fread_unlocked:
789case LibFunc_fwrite_unlocked:
794// FIXME: readonly #1? 797case LibFunc_fputs_unlocked:
823case LibFunc_getlogin_r:
828case LibFunc_getc_unlocked:
841case LibFunc_getchar_unlocked:
845case LibFunc_getitimer:
850case LibFunc_getpwnam:
872case LibFunc_unsetenv:
888case LibFunc_putc_unlocked:
902// May throw; "pread" is a valid pthread cancellation point. 907// May throw; "pwrite" is a valid pthread cancellation point. 913case LibFunc_putchar_unlocked:
958case LibFunc_vfprintf:
959case LibFunc_vsprintf:
966case LibFunc_vsnprintf:
974// May throw; "open" is a valid pthread cancellation point. 1017// May throw; places call through function pointer. 1018// Cannot give undef pointer/size 1022case LibFunc_dunder_strndup:
1025case LibFunc_dunder_strdup:
1032case LibFunc_dunder_strtok_r:
1037case LibFunc_under_IO_getc:
1042case LibFunc_under_IO_putc:
1047case LibFunc_dunder_isoc99_scanf:
1054case LibFunc_lstat64:
1055case LibFunc_statvfs64:
1062case LibFunc_dunder_isoc99_sscanf:
1070case LibFunc_fopen64:
1079case LibFunc_fseeko64:
1080case LibFunc_ftello64:
1085case LibFunc_tmpfile64:
1090case LibFunc_fstat64:
1091case LibFunc_fstatvfs64:
1097// May throw; "open" is a valid pthread cancellation point. 1102case LibFunc_gettimeofday:
1103// Currently some platforms have the restrict keyword on the arguments to 1104// gettimeofday. To be conservative, do not add noalias to gettimeofday's 1111case LibFunc_memset_pattern4:
1112case LibFunc_memset_pattern8:
1113case LibFunc_memset_pattern16:
1121case LibFunc_memset_chk:
1129case LibFunc_terminate:
1133case LibFunc_cxa_throw:
1136// Don't add `nofree` on `__cxa_throw` 1138// int __nvvm_reflect(const char *) 1139case LibFunc_nvvm_reflect:
1150case LibFunc_remquof:
1151case LibFunc_remquol:
1182case LibFunc_copysign:
1183case LibFunc_copysignf:
1184case LibFunc_copysignl:
1197case LibFunc_tgammaf:
1198case LibFunc_tgammal:
1235case LibFunc_isascii:
1236case LibFunc_isdigit:
1257case LibFunc_nearbyint:
1258case LibFunc_nearbyintf:
1259case LibFunc_nearbyintl:
1263case LibFunc_remainder:
1264case LibFunc_remainderf:
1265case LibFunc_remainderl:
1272case LibFunc_scalbln:
1273case LibFunc_scalblnf:
1274case LibFunc_scalblnl:
1276case LibFunc_scalbnf:
1277case LibFunc_scalbnl:
1279case LibFunc_sincospif_stret:
1296case LibFunc_toascii:
1306case LibFunc_sincosf:
1307case LibFunc_sincosl:
1318// FIXME: It'd be really nice to cover all the library functions we're 1322// We have to do this step after AllocKind has been inferred on functions so 1323// we can reliably identify free-like and realloc-like functions. 1333F.addParamAttr(ArgNo, ExtAttr);
1340F.addRetAttr(ExtAttr);
1343// Modeled after X86TargetLowering::markLibCallAttributes. 1345if (!
F->arg_size() ||
F->isVarArg())
1352constModule *M =
F->getParent();
1353unsignedN = M->getNumberRegisterParameters();
1361if (!
T->isIntOrPtrTy())
1368assert(TS <= 4 &&
"Need to account for parameters larger than word size");
1369constunsigned NumRegs = TS > 4 ? 2 : 1;
1374F->addParamAttr(
A.getArgNo(), Attribute::InReg);
1382"Creating call to non-existing library function.");
1386// Make sure any mandatory argument attributes are added. 1388// Any outgoing i32 argument should be handled with setArgExtAttr() which 1389// will add an extension attribute if the target ABI requires it. Adding 1390// argument extensions is typically done by the front end but when an 1391// optimizer is building a library call on its own it has to take care of 1392// this. Each such generated function must be handled here with sign or 1393// zero extensions as needed. F is retreived with cast<> because we demand 1394// of the caller to have called isLibFuncEmittable() first. 1396assert(
F->getFunctionType() ==
T &&
"Function type does not match.");
1397switch (TheLibFunc) {
1399case LibFunc_putchar:
1406case LibFunc_memrchr:
1410case LibFunc_memccpy:
1414// These are functions that are known to not need any argument extension 1415// on any target: A size_t argument (which may be an i32 on some targets) 1416// should not trigger the assert below. 1424case LibFunc_memcpy_chk:
1425case LibFunc_mempcpy:
1426case LibFunc_memset_pattern16:
1427case LibFunc_snprintf:
1428case LibFunc_stpncpy:
1429case LibFunc_strlcat:
1430case LibFunc_strlcpy:
1431case LibFunc_strncat:
1432case LibFunc_strncmp:
1433case LibFunc_strncpy:
1434case LibFunc_vsnprintf:
1439for (
unsigned i = 0; i <
T->getNumParams(); i++)
1440assert(!isa<IntegerType>(
T->getParamType(i)) &&
1441"Unhandled integer argument.");
1459if (!TLI->
has(TheLibFunc))
1462// Check if the Module already has a GlobalValue with the same name, in 1463// which case it must be a Function with the expected type. 1464if (
GlobalValue *GV = M->getNamedValue(FuncName)) {
1465if (
auto *
F = dyn_cast<Function>(GV))
1498"Cannot get name for unavailable function!");
1504 TheLibFunc = FloatFn;
1507 TheLibFunc = DoubleFn;
1510 TheLibFunc = LongDoubleFn;
1511return TLI->
getName(LongDoubleFn);
1515//- Emit LibCalls ------------------------------------------------------------// 1522constModule *M =
B.GetInsertBlock()->getModule();
1530bool IsVaArgs =
false) {
1531Module *M =
B.GetInsertBlock()->getModule();
1536FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1541 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1548Type *CharPtrTy =
B.getPtrTy();
1555Type *CharPtrTy =
B.getPtrTy();
1561Type *CharPtrTy =
B.getPtrTy();
1563returnemitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1564 {
Ptr, ConstantInt::get(IntTy,
C)},
B, TLI);
1569Type *CharPtrTy =
B.getPtrTy();
1573 LibFunc_strncmp, IntTy,
1574 {CharPtrTy, CharPtrTy, SizeTTy},
1575 {Ptr1, Ptr2, Len},
B, TLI);
1580Type *CharPtrTy = Dst->getType();
1581returnemitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1587Type *CharPtrTy =
B.getPtrTy();
1588returnemitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1594Type *CharPtrTy =
B.getPtrTy();
1596returnemitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1597 {Dst, Src, Len},
B, TLI);
1602Type *CharPtrTy =
B.getPtrTy();
1604returnemitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1605 {Dst, Src, Len},
B, TLI);
1611Module *M =
B.GetInsertBlock()->getModule();
1617 Attribute::NoUnwind);
1618Type *VoidPtrTy =
B.getPtrTy();
1622 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1623CallInst *CI =
B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1632Type *VoidPtrTy =
B.getPtrTy();
1635 {VoidPtrTy, VoidPtrTy, SizeTTy},
1636 {Dst, Src, Len},
B, TLI);
1641Type *VoidPtrTy =
B.getPtrTy();
1645 {VoidPtrTy, IntTy, SizeTTy},
1646 {
Ptr, Val, Len},
B, TLI);
1651Type *VoidPtrTy =
B.getPtrTy();
1655 {VoidPtrTy, IntTy, SizeTTy},
1656 {
Ptr, Val, Len},
B, TLI);
1661Type *VoidPtrTy =
B.getPtrTy();
1665 {VoidPtrTy, VoidPtrTy, SizeTTy},
1666 {Ptr1, Ptr2, Len},
B, TLI);
1671Type *VoidPtrTy =
B.getPtrTy();
1675 {VoidPtrTy, VoidPtrTy, SizeTTy},
1676 {Ptr1, Ptr2, Len},
B, TLI);
1681Type *VoidPtrTy =
B.getPtrTy();
1685 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1686 {Ptr1, Ptr2, Val, Len},
B, TLI);
1692Type *CharPtrTy =
B.getPtrTy();
1698 {CharPtrTy, SizeTTy, CharPtrTy},
1699 Args,
B, TLI,
/*IsVaArgs=*/true);
1705Type *CharPtrTy =
B.getPtrTy();
1710 {CharPtrTy, CharPtrTy}, Args,
B, TLI,
1716Type *CharPtrTy =
B.getPtrTy();
1718 {CharPtrTy, CharPtrTy},
1719 {Dest, Src},
B, TLI);
1724Type *CharPtrTy =
B.getPtrTy();
1727 {CharPtrTy, CharPtrTy, SizeTTy},
1728 {Dest, Src,
Size},
B, TLI);
1733Type *CharPtrTy =
B.getPtrTy();
1736 {CharPtrTy, CharPtrTy, SizeTTy},
1737 {Dest, Src,
Size},
B, TLI);
1742Type *CharPtrTy =
B.getPtrTy();
1745 {CharPtrTy, CharPtrTy, SizeTTy},
1746 {Dest, Src,
Size},
B, TLI);
1751Type *CharPtrTy =
B.getPtrTy();
1755 LibFunc_vsnprintf, IntTy,
1756 {CharPtrTy, SizeTTy, CharPtrTy, VAList->
getType()},
1757 {Dest,
Size, Fmt, VAList},
B, TLI);
1762Type *CharPtrTy =
B.getPtrTy();
1765 {CharPtrTy, CharPtrTy, VAList->
getType()},
1766 {Dest, Fmt, VAList},
B, TLI);
1769/// Append a suffix to the function name according to the type of 'Op'. 1772if (!
Op->getType()->isDoubleTy()) {
1775if (
Op->getType()->isFloatTy())
1788assert((
Name !=
"") &&
"Must specify Name to emitUnaryFloatFnCall");
1790Module *M =
B.GetInsertBlock()->getModule();
1795// The incoming attribute set may have come from a speculatable intrinsic, but 1796// is being replaced with a library call which is not allowed to be 1799 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1801 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1823// Get the name of the function according to TLI. 1824Module *M =
B.GetInsertBlock()->getModule();
1827 LongDoubleFn, TheLibFunc);
1837assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1839Module *M =
B.GetInsertBlock()->getModule();
1845// The incoming attribute set may have come from a speculatable intrinsic, but 1846// is being replaced with a library call which is not allowed to be 1849 Attrs.removeFnAttribute(
B.getContext(), Attribute::Speculatable));
1851 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1861assert((
Name !=
"") &&
"Must specify Name to emitBinaryFloatFnCall");
1877// Get the name of the function according to TLI. 1878Module *M =
B.GetInsertBlock()->getModule();
1881 LongDoubleFn, TheLibFunc);
1886// Emit a call to putchar(int) with Char as the argument. Char must have 1887// the same precision as int, which need not be 32 bits. 1890Module *M =
B.GetInsertBlock()->getModule();
1899CallInst *CI =
B.CreateCall(PutChar, Char, PutCharName);
1909Module *M =
B.GetInsertBlock()->getModule();
1918CallInst *CI =
B.CreateCall(PutS, Str, PutsName);
1927Module *M =
B.GetInsertBlock()->getModule();
1934 IntTy, File->getType());
1935if (File->getType()->isPointerTy())
1937CallInst *CI =
B.CreateCall(
F, {Char, File}, FPutcName);
1940 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1947Module *M =
B.GetInsertBlock()->getModule();
1954B.getPtrTy(), File->getType());
1955if (File->getType()->isPointerTy())
1957CallInst *CI =
B.CreateCall(
F, {Str, File}, FPutsName);
1960 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1967Module *M =
B.GetInsertBlock()->getModule();
1975 SizeTTy, SizeTTy, File->getType());
1977if (File->getType()->isPointerTy())
1981 ConstantInt::get(SizeTTy, 1), File});
1984 dyn_cast<Function>(
F.getCallee()->stripPointerCasts()))
1991Module *M =
B.GetInsertBlock()->getModule();
2003 dyn_cast<Function>(
Malloc.getCallee()->stripPointerCasts()))
2011Module *M =
B.GetInsertBlock()->getModule();
2018 M, TLI, LibFunc_calloc,
B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2033Module *M =
B.GetInsertBlock()->getModule();
2039// __sized_ptr_t struct return type { void*, size_t } 2043 M->getOrInsertFunction(
Name, SizedPtrT, Num->
getType(),
B.getInt8Ty());
2045CallInst *CI =
B.CreateCall(Func, {Num,
B.getInt8(HotCold)},
"sized_ptr");
2047if (
constFunction *
F = dyn_cast<Function>(Func.getCallee()))
2058Module *M =
B.GetInsertBlock()->getModule();
2064// __sized_ptr_t struct return type { void*, size_t } 2068Align->getType(),
B.getInt8Ty());
2071B.CreateCall(Func, {Num,
Align,
B.getInt8(HotCold)},
"sized_ptr");
2073if (
constFunction *
F = dyn_cast<Function>(Func.getCallee()))
2082Module *M =
B.GetInsertBlock()->getModule();
2088 M->getOrInsertFunction(
Name,
B.getPtrTy(), Num->
getType(),
B.getInt8Ty());
2093 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2102Module *M =
B.GetInsertBlock()->getModule();
2110CallInst *CI =
B.CreateCall(Func, {Num, NoThrow,
B.getInt8(HotCold)},
Name);
2113 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2122Module *M =
B.GetInsertBlock()->getModule();
2133 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2143Module *M =
B.GetInsertBlock()->getModule();
2153B.CreateCall(Func, {Num,
Align, NoThrow,
B.getInt8(HotCold)},
Name);
2156 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...
Module.h This file contains the declarations for the Module class.
mir Rename Register Operands
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 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 * 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 * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI, unsigned AddrSpace)
Emit a call to the calloc 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.