162d4215bSChandler Carruth //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
262d4215bSChandler Carruth //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
662d4215bSChandler Carruth //
762d4215bSChandler Carruth //===----------------------------------------------------------------------===//
862d4215bSChandler Carruth //
962d4215bSChandler Carruth // This file implements the TargetLibraryInfo class.
1062d4215bSChandler Carruth //
1162d4215bSChandler Carruth //===----------------------------------------------------------------------===//
1262d4215bSChandler Carruth 
1362d4215bSChandler Carruth #include "llvm/Analysis/TargetLibraryInfo.h"
1462d4215bSChandler Carruth #include "llvm/ADT/Triple.h"
1550ec0b5dSMatthias Braun #include "llvm/IR/Constants.h"
1605da2fe5SReid Kleckner #include "llvm/InitializePasses.h"
176d8a2aa9SMichael Zolotukhin #include "llvm/Support/CommandLine.h"
1862d4215bSChandler Carruth using namespace llvm;
1962d4215bSChandler Carruth 
206d8a2aa9SMichael Zolotukhin static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
216d8a2aa9SMichael Zolotukhin     "vector-library", cl::Hidden, cl::desc("Vector functions library"),
226d8a2aa9SMichael Zolotukhin     cl::init(TargetLibraryInfoImpl::NoLibrary),
236d8a2aa9SMichael Zolotukhin     cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
246d8a2aa9SMichael Zolotukhin                           "No vector functions library"),
256d8a2aa9SMichael Zolotukhin                clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
266d8a2aa9SMichael Zolotukhin                           "Accelerate framework"),
2793a9a8a8SFlorian Hahn                clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM,
2893a9a8a8SFlorian Hahn                           "Darwin_libsystem_m", "Darwin libsystem_m"),
2957cdc52cSVenkataramanan Kumar                clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86",
3057cdc52cSVenkataramanan Kumar                           "GLIBC Vector Math library"),
31fe97754aSNemanja Ivanovic                clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
32fe97754aSNemanja Ivanovic                           "IBM MASS vector library"),
33a6669a1eSMatt Masten                clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
347459398aSJoel Jones                           "Intel SVML library")));
356d8a2aa9SMichael Zolotukhin 
3670434770SBenjamin Kramer StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
3770434770SBenjamin Kramer     {
38cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING
39cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def"
4062d4215bSChandler Carruth };
4162d4215bSChandler Carruth 
4262d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) {
4362d4215bSChandler Carruth   // Only Darwin variants have _stret versions of combined trig functions.
4462d4215bSChandler Carruth   if (!T.isOSDarwin())
4562d4215bSChandler Carruth     return false;
4662d4215bSChandler Carruth 
4762d4215bSChandler Carruth   // The ABI is rather complicated on x86, so don't do anything special there.
4862d4215bSChandler Carruth   if (T.getArch() == Triple::x86)
4962d4215bSChandler Carruth     return false;
5062d4215bSChandler Carruth 
5162d4215bSChandler Carruth   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
5262d4215bSChandler Carruth     return false;
5362d4215bSChandler Carruth 
5462d4215bSChandler Carruth   if (T.isiOS() && T.isOSVersionLT(7, 0))
5562d4215bSChandler Carruth     return false;
5662d4215bSChandler Carruth 
5762d4215bSChandler Carruth   return true;
5862d4215bSChandler Carruth }
5962d4215bSChandler Carruth 
608e16d733SClement Courbet static bool hasBcmp(const Triple &TT) {
618e16d733SClement Courbet   // Posix removed support from bcmp() in 2001, but the glibc and several
628e16d733SClement Courbet   // implementations of the libc still have it.
638e16d733SClement Courbet   if (TT.isOSLinux())
648e16d733SClement Courbet     return TT.isGNUEnvironment() || TT.isMusl();
658e16d733SClement Courbet   // Both NetBSD and OpenBSD are planning to remove the function. Windows does
668e16d733SClement Courbet   // not have it.
678d5c2803SAlex Lorenz   return TT.isOSFreeBSD() || TT.isOSSolaris();
688e16d733SClement Courbet }
698e16d733SClement Courbet 
70c5fda0e6SYuanfang Chen static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT,
71c5fda0e6SYuanfang Chen                                      FunctionType *FuncTy) {
72c5fda0e6SYuanfang Chen   switch (CC) {
73c5fda0e6SYuanfang Chen   default:
74c5fda0e6SYuanfang Chen     return false;
75c5fda0e6SYuanfang Chen   case llvm::CallingConv::C:
76c5fda0e6SYuanfang Chen     return true;
77c5fda0e6SYuanfang Chen   case llvm::CallingConv::ARM_APCS:
78c5fda0e6SYuanfang Chen   case llvm::CallingConv::ARM_AAPCS:
79c5fda0e6SYuanfang Chen   case llvm::CallingConv::ARM_AAPCS_VFP: {
80c5fda0e6SYuanfang Chen 
81c5fda0e6SYuanfang Chen     // The iOS ABI diverges from the standard in some cases, so for now don't
82c5fda0e6SYuanfang Chen     // try to simplify those calls.
83c5fda0e6SYuanfang Chen     if (Triple(TT).isiOS())
84c5fda0e6SYuanfang Chen       return false;
85c5fda0e6SYuanfang Chen 
86c5fda0e6SYuanfang Chen     if (!FuncTy->getReturnType()->isPointerTy() &&
87c5fda0e6SYuanfang Chen         !FuncTy->getReturnType()->isIntegerTy() &&
88c5fda0e6SYuanfang Chen         !FuncTy->getReturnType()->isVoidTy())
89c5fda0e6SYuanfang Chen       return false;
90c5fda0e6SYuanfang Chen 
91c5fda0e6SYuanfang Chen     for (auto *Param : FuncTy->params()) {
92c5fda0e6SYuanfang Chen       if (!Param->isPointerTy() && !Param->isIntegerTy())
93c5fda0e6SYuanfang Chen         return false;
94c5fda0e6SYuanfang Chen     }
95c5fda0e6SYuanfang Chen     return true;
96c5fda0e6SYuanfang Chen   }
97c5fda0e6SYuanfang Chen   }
98c5fda0e6SYuanfang Chen   return false;
99c5fda0e6SYuanfang Chen }
100c5fda0e6SYuanfang Chen 
101c5fda0e6SYuanfang Chen bool TargetLibraryInfoImpl::isCallingConvCCompatible(CallBase *CI) {
102c5fda0e6SYuanfang Chen   return ::isCallingConvCCompatible(CI->getCallingConv(),
103c5fda0e6SYuanfang Chen                                     CI->getModule()->getTargetTriple(),
104c5fda0e6SYuanfang Chen                                     CI->getFunctionType());
105c5fda0e6SYuanfang Chen }
106c5fda0e6SYuanfang Chen 
107c5fda0e6SYuanfang Chen bool TargetLibraryInfoImpl::isCallingConvCCompatible(Function *F) {
108c5fda0e6SYuanfang Chen   return ::isCallingConvCCompatible(F->getCallingConv(),
109c5fda0e6SYuanfang Chen                                     F->getParent()->getTargetTriple(),
110c5fda0e6SYuanfang Chen                                     F->getFunctionType());
111c5fda0e6SYuanfang Chen }
112c5fda0e6SYuanfang Chen 
113600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified
114600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target
115600d24b4SSanjay Patel /// triple gets a sane set of defaults.
116c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
11770434770SBenjamin Kramer                        ArrayRef<StringLiteral> StandardNames) {
11862d4215bSChandler Carruth   // Verify that the StandardNames array is in alphabetical order.
1191647ff6eSGeorgii Rymar   assert(
1201647ff6eSGeorgii Rymar       llvm::is_sorted(StandardNames,
1211647ff6eSGeorgii Rymar                       [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) &&
122e30b8ca1SCraig Topper       "TargetLibraryInfoImpl function names must be sorted");
12362d4215bSChandler Carruth 
124ca22d427SDavid Bolvansky   // Set IO unlocked variants as unavailable
125ca22d427SDavid Bolvansky   // Set them as available per system below
126ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_getchar_unlocked);
127ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_putc_unlocked);
128ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_putchar_unlocked);
129ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fputc_unlocked);
130ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fgetc_unlocked);
131ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fread_unlocked);
132ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fwrite_unlocked);
133ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fputs_unlocked);
134ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fgets_unlocked);
135ca22d427SDavid Bolvansky 
1366af8e6c3SMarcin Koscielnicki   bool ShouldExtI32Param = false, ShouldExtI32Return = false,
1376af8e6c3SMarcin Koscielnicki        ShouldSignExtI32Param = false;
1386af8e6c3SMarcin Koscielnicki   // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
1396af8e6c3SMarcin Koscielnicki   // returns corresponding to C-level ints and unsigned ints.
1403e92df3eSFangrui Song   if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
1413e92df3eSFangrui Song       T.getArch() == Triple::systemz) {
1426af8e6c3SMarcin Koscielnicki     ShouldExtI32Param = true;
1436af8e6c3SMarcin Koscielnicki     ShouldExtI32Return = true;
1446af8e6c3SMarcin Koscielnicki   }
1456af8e6c3SMarcin Koscielnicki   // Mips, on the other hand, needs signext on i32 parameters corresponding
1466af8e6c3SMarcin Koscielnicki   // to both signed and unsigned ints.
14785e200e9SAlexander Richardson   if (T.isMIPS()) {
1486af8e6c3SMarcin Koscielnicki     ShouldSignExtI32Param = true;
1496af8e6c3SMarcin Koscielnicki   }
1506af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Param(ShouldExtI32Param);
1516af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Return(ShouldExtI32Return);
1526af8e6c3SMarcin Koscielnicki   TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
1536af8e6c3SMarcin Koscielnicki 
1549c54ee43SBjorn Pettersson   // Let's assume by default that the size of int is 32 bits, unless the target
1559c54ee43SBjorn Pettersson   // is a 16-bit architecture because then it most likely is 16 bits. If that
1569c54ee43SBjorn Pettersson   // isn't true for a target those defaults should be overridden below.
1579c54ee43SBjorn Pettersson   TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
1589c54ee43SBjorn Pettersson 
159314deab9SYaxun (Sam) Liu   if (T.isAMDGPU())
160c26b3940STim Renouf     TLI.disableAllFunctions();
16178fd4f08SNicolai Hahnle 
162ef72cdedSDavid Bolvansky   // There are no library implementations of memcpy and memset for AMD gpus and
16362d4215bSChandler Carruth   // these can be difficult to lower in the backend.
164314deab9SYaxun (Sam) Liu   if (T.isAMDGPU()) {
165d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memcpy);
166d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset);
167d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
1682662351eSJoseph Huber     TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
1692662351eSJoseph Huber     TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
17062d4215bSChandler Carruth     return;
17162d4215bSChandler Carruth   }
17262d4215bSChandler Carruth 
17362d4215bSChandler Carruth   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
1748b40366bSTim Northover   // All versions of watchOS support it.
17562d4215bSChandler Carruth   if (T.isMacOSX()) {
176ca22d427SDavid Bolvansky     // available IO unlocked variants on Mac OS X
177ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getc_unlocked);
178ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getchar_unlocked);
179ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putc_unlocked);
180ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putchar_unlocked);
181ca22d427SDavid Bolvansky 
18262d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 5))
183d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
18462d4215bSChandler Carruth   } else if (T.isiOS()) {
18562d4215bSChandler Carruth     if (T.isOSVersionLT(3, 0))
186d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
1878b40366bSTim Northover   } else if (!T.isWatchOS()) {
188d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
18962d4215bSChandler Carruth   }
19062d4215bSChandler Carruth 
19162d4215bSChandler Carruth   if (!hasSinCosPiStret(T)) {
192d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpi);
193d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpif);
194d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospi);
195d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospif);
196d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospi_stret);
197d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospif_stret);
19862d4215bSChandler Carruth   }
19962d4215bSChandler Carruth 
2008e16d733SClement Courbet   if (!hasBcmp(T))
2018e16d733SClement Courbet     TLI.setUnavailable(LibFunc_bcmp);
2028e16d733SClement Courbet 
20362d4215bSChandler Carruth   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
20462d4215bSChandler Carruth       !T.isMacOSXVersionLT(10, 7)) {
20562d4215bSChandler Carruth     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
20662d4215bSChandler Carruth     // we don't care about) have two versions; on recent OSX, the one we want
20762d4215bSChandler Carruth     // has a $UNIX2003 suffix. The two implementations are identical except
20862d4215bSChandler Carruth     // for the return value in some edge cases.  However, we don't want to
20962d4215bSChandler Carruth     // generate code that depends on the old symbols.
210d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
211d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
21262d4215bSChandler Carruth   }
21362d4215bSChandler Carruth 
214b4f9991fSAlon Zakai   // iprintf and friends are only available on XCore, TCE, and Emscripten.
215b4f9991fSAlon Zakai   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
216b4f9991fSAlon Zakai       T.getOS() != Triple::Emscripten) {
217d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_iprintf);
218d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_siprintf);
219d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fiprintf);
22062d4215bSChandler Carruth   }
22162d4215bSChandler Carruth 
222b4f9991fSAlon Zakai   // __small_printf and friends are only available on Emscripten.
223b4f9991fSAlon Zakai   if (T.getOS() != Triple::Emscripten) {
224b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_printf);
225b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_sprintf);
226b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_fprintf);
227b4f9991fSAlon Zakai   }
228b4f9991fSAlon Zakai 
22962d4215bSChandler Carruth   if (T.isOSWindows() && !T.isOSCygMing()) {
2304b86c474SEvandro Menezes     // XXX: The earliest documentation available at the moment is for VS2015/VC19:
2314b86c474SEvandro Menezes     // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
2324b86c474SEvandro Menezes     // XXX: In order to use an MSVCRT older than VC19,
2334b86c474SEvandro Menezes     // the specific library version must be explicit in the target triple,
2344b86c474SEvandro Menezes     // e.g., x86_64-pc-windows-msvc18.
2354b86c474SEvandro Menezes     bool hasPartialC99 = true;
2364b86c474SEvandro Menezes     if (T.isKnownWindowsMSVCEnvironment()) {
2374b86c474SEvandro Menezes       unsigned Major, Minor, Micro;
2384b86c474SEvandro Menezes       T.getEnvironmentVersion(Major, Minor, Micro);
2394b86c474SEvandro Menezes       hasPartialC99 = (Major == 0 || Major >= 19);
2404b86c474SEvandro Menezes     }
2414b86c474SEvandro Menezes 
242f4a36959SEvandro Menezes     // Latest targets support C89 math functions, in part.
243f4a36959SEvandro Menezes     bool isARM = (T.getArch() == Triple::aarch64 ||
244f4a36959SEvandro Menezes                   T.getArch() == Triple::arm);
245f4a36959SEvandro Menezes     bool hasPartialFloat = (isARM ||
2464b86c474SEvandro Menezes                             T.getArch() == Triple::x86_64);
2474b86c474SEvandro Menezes 
248f4a36959SEvandro Menezes     // Win32 does not support float C89 math functions, in general.
2494b86c474SEvandro Menezes     if (!hasPartialFloat) {
250e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_acosf);
251e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_asinf);
252e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_atan2f);
253f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_atanf);
254e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_ceilf);
255e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_cosf);
256e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_coshf);
257e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_expf);
258e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_floorf);
259e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_fmodf);
260e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_log10f);
261f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_logf);
262e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_modff);
263e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_powf);
2642470d298SEhud Katz       TLI.setUnavailable(LibFunc_remainderf);
265e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sinf);
266e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sinhf);
267e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sqrtf);
268e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_tanf);
269e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_tanhf);
270e5bb58b1SEvandro Menezes     }
271f4a36959SEvandro Menezes     if (!isARM)
2724b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_fabsf);
273e5bb58b1SEvandro Menezes     TLI.setUnavailable(LibFunc_frexpf);
274e5bb58b1SEvandro Menezes     TLI.setUnavailable(LibFunc_ldexpf);
275e5bb58b1SEvandro Menezes 
276f4a36959SEvandro Menezes     // Win32 does not support long double C89 math functions.
27798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_acosl);
27898f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_asinl);
27998f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_atan2l);
280f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_atanl);
28198f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_ceill);
28298f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_cosl);
28398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_coshl);
28498f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_expl);
28598f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_fabsl);
28698f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_floorl);
28798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_fmodl);
28898f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_frexpl);
28998f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_ldexpl);
2904b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log10l);
291f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_logl);
29298f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_modfl);
29398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_powl);
2942470d298SEhud Katz     TLI.setUnavailable(LibFunc_remainderl);
29598f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sinl);
29698f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sinhl);
29798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sqrtl);
29898f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_tanl);
29998f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_tanhl);
30062d4215bSChandler Carruth 
301e5bb58b1SEvandro Menezes     // Win32 does not fully support C99 math functions.
3024b86c474SEvandro Menezes     if (!hasPartialC99) {
30398f356cdSEvandro Menezes       TLI.setUnavailable(LibFunc_acosh);
3044b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_acoshf);
305f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_asinh);
3064b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_asinhf);
307f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_atanh);
3084b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_atanhf);
309f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
3104b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_cabsf);
311f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_cbrt);
3124b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_cbrtf);
313f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
314f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
315f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_exp2);
3164b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_exp2f);
317f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_expm1);
3184b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_expm1f);
319f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmax);
320f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmaxf);
321f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmin);
322f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fminf);
323f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_log1p);
3244b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_log1pf);
325f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_log2);
3264b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_log2f);
327f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_logb, "_logb");
328f4a36959SEvandro Menezes       if (hasPartialFloat)
329f4a36959SEvandro Menezes         TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
330f4a36959SEvandro Menezes       else
3314b86c474SEvandro Menezes         TLI.setUnavailable(LibFunc_logbf);
332f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_rint);
3334b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_rintf);
334f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_round);
3354b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_roundf);
336f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_trunc);
33798f356cdSEvandro Menezes       TLI.setUnavailable(LibFunc_truncf);
338f4a36959SEvandro Menezes     }
3394b86c474SEvandro Menezes 
3404b86c474SEvandro Menezes     // Win32 does not support long double C99 math functions.
3414b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_acoshl);
3424b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_asinhl);
3434b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_atanhl);
3444b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_cabsl);
3454b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_cbrtl);
346f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_copysignl);
3474b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_exp2l);
3484b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_expm1l);
349f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_fmaxl);
350f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_fminl);
3514b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log1pl);
3524b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log2l);
3534b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_logbl);
3544b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_nearbyintl);
3554b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_rintl);
3564b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_roundl);
35798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_truncl);
35898f356cdSEvandro Menezes 
359e5bb58b1SEvandro Menezes     // Win32 does not support these functions, but
360e5bb58b1SEvandro Menezes     // they are generally available on POSIX-compliant systems.
361d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_access);
362c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_chmod);
363c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_closedir);
364c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_fdopen);
365c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_fileno);
366c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_fseeko);
367c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_fstat);
368c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_ftello);
369c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_gettimeofday);
370c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_memccpy);
371c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_mkdir);
372c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_open);
373c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_opendir);
374c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_pclose);
375c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_popen);
376c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_read);
377c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_rmdir);
378c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_stat);
379c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_strcasecmp);
380c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_strncasecmp);
381c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_unlink);
382c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_utime);
383c5638a71SMartin Storsjö     TLI.setUnavailable(LibFunc_write);
384c5638a71SMartin Storsjö   }
385c5638a71SMartin Storsjö 
386c5638a71SMartin Storsjö   if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) {
387c5638a71SMartin Storsjö     // These functions aren't available in either MSVC or MinGW environments.
388d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcmp);
389d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcopy);
390d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bzero);
391d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chown);
392d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ctermid);
393d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffs);
394d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flockfile);
395d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs);
396d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftrylockfile);
397d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_funlockfile);
398d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getitimer);
399d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getlogin_r);
400d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getpwnam);
401d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htonl);
402d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htons);
403d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lchown);
404d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat);
405d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohl);
406d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohs);
407d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pread);
408d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pwrite);
409d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_readlink);
410d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_realpath);
411d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_setitimer);
412d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs);
413d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpcpy);
414d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpncpy);
415d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_times);
416d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_uname);
417d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unsetenv);
418d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utimes);
41962d4215bSChandler Carruth   }
42062d4215bSChandler Carruth 
42162d4215bSChandler Carruth   switch (T.getOS()) {
42262d4215bSChandler Carruth   case Triple::MacOSX:
42362d4215bSChandler Carruth     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
42462d4215bSChandler Carruth     // and their names are __exp10 and __exp10f. exp10l is not available on
42562d4215bSChandler Carruth     // OS X or iOS.
426d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
42762d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 9)) {
428d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
429d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
43062d4215bSChandler Carruth     } else {
431d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
432d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
43362d4215bSChandler Carruth     }
43462d4215bSChandler Carruth     break;
43562d4215bSChandler Carruth   case Triple::IOS:
43689a6eefeSTim Northover   case Triple::TvOS:
4378b40366bSTim Northover   case Triple::WatchOS:
438d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
439ab1bcda8SJim Lin     if (!T.isWatchOS() &&
440ab1bcda8SJim Lin         (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
441d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
442d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
44362d4215bSChandler Carruth     } else {
444d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
445d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
44662d4215bSChandler Carruth     }
44762d4215bSChandler Carruth     break;
44862d4215bSChandler Carruth   case Triple::Linux:
44962d4215bSChandler Carruth     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
45062d4215bSChandler Carruth     // buggy prior to glibc version 2.18. Until this version is widely deployed
45162d4215bSChandler Carruth     // or we have a reasonable detection strategy, we cannot use exp10 reliably
45262d4215bSChandler Carruth     // on Linux.
45362d4215bSChandler Carruth     //
45462d4215bSChandler Carruth     // Fall through to disable all of them.
455cd1d5aafSJustin Bogner     LLVM_FALLTHROUGH;
45662d4215bSChandler Carruth   default:
457d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10);
458d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10f);
459d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
46062d4215bSChandler Carruth   }
46162d4215bSChandler Carruth 
46262d4215bSChandler Carruth   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
46362d4215bSChandler Carruth   // Linux (GLIBC):
46462d4215bSChandler Carruth   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
46583b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
46662d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
46762d4215bSChandler Carruth   switch (T.getOS()) {
46862d4215bSChandler Carruth   case Triple::Darwin:
46962d4215bSChandler Carruth   case Triple::MacOSX:
47062d4215bSChandler Carruth   case Triple::IOS:
47189a6eefeSTim Northover   case Triple::TvOS:
4728b40366bSTim Northover   case Triple::WatchOS:
47362d4215bSChandler Carruth   case Triple::FreeBSD:
47462d4215bSChandler Carruth   case Triple::Linux:
47562d4215bSChandler Carruth     break;
47662d4215bSChandler Carruth   default:
477d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsl);
47862d4215bSChandler Carruth   }
47962d4215bSChandler Carruth 
48062d4215bSChandler Carruth   // ffsll is available on at least FreeBSD and Linux (GLIBC):
48183b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
48262d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
48362d4215bSChandler Carruth   switch (T.getOS()) {
48489a6eefeSTim Northover   case Triple::Darwin:
48589a6eefeSTim Northover   case Triple::MacOSX:
48689a6eefeSTim Northover   case Triple::IOS:
48789a6eefeSTim Northover   case Triple::TvOS:
48889a6eefeSTim Northover   case Triple::WatchOS:
48962d4215bSChandler Carruth   case Triple::FreeBSD:
49062d4215bSChandler Carruth   case Triple::Linux:
49162d4215bSChandler Carruth     break;
49262d4215bSChandler Carruth   default:
493d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsll);
49462d4215bSChandler Carruth   }
49562d4215bSChandler Carruth 
496bfd3082eSDavide Italiano   // The following functions are available on at least FreeBSD:
497bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
498bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
499bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
500bfd3082eSDavide Italiano   if (!T.isOSFreeBSD()) {
501d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fls);
502d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsl);
503d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsll);
504bfd3082eSDavide Italiano   }
505bfd3082eSDavide Italiano 
506e3a5fc6dSEli Friedman   // The following functions are only available on GNU/Linux (using glibc).
507e3a5fc6dSEli Friedman   // Linux variants without glibc (eg: bionic, musl) may have some subset.
508e3a5fc6dSEli Friedman   if (!T.isOSLinux() || !T.isGNUEnvironment()) {
509d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strdup);
510d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strtok_r);
511d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
512d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
513d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_getc);
514d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_putc);
515e3a5fc6dSEli Friedman     // But, Android and musl have memalign.
516e3a5fc6dSEli Friedman     if (!T.isAndroid() && !T.isMusl())
517d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memalign);
518d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fopen64);
519d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko64);
520d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat64);
521d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs64);
522d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello64);
523d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat64);
524d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open64);
525d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat64);
526d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs64);
527d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_tmpfile64);
52852149f03SSanjay Patel 
52952149f03SSanjay Patel     // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
5306d15c4deSserge-sans-paille     // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
5316d15c4deSserge-sans-paille     // so we keep these functions around just so that they're recognized by
5326d15c4deSserge-sans-paille     // the ConstantFolder.
53352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acos_finite);
53452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosf_finite);
53552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosl_finite);
53652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosh_finite);
53752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshf_finite);
53852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshl_finite);
53952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asin_finite);
54052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinf_finite);
54152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinl_finite);
54252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2_finite);
54352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2f_finite);
54452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2l_finite);
54552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanh_finite);
54652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhf_finite);
54752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhl_finite);
54852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_cosh_finite);
54952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshf_finite);
55052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshl_finite);
55152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10_finite);
55252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10f_finite);
55352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10l_finite);
55452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2_finite);
55552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2f_finite);
55652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2l_finite);
55752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp_finite);
55852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expf_finite);
55952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expl_finite);
56052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10_finite);
56152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10f_finite);
56252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10l_finite);
56352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2_finite);
56452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2f_finite);
56552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2l_finite);
56652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log_finite);
56752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logf_finite);
56852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logl_finite);
56952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_pow_finite);
57052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powf_finite);
57152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powl_finite);
57252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinh_finite);
57352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhf_finite);
57452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhl_finite);
57562d4215bSChandler Carruth   }
5766d8a2aa9SMichael Zolotukhin 
577c1078872SMartin Storsjo   if ((T.isOSLinux() && T.isGNUEnvironment()) ||
578c1078872SMartin Storsjo       (T.isAndroid() && !T.isAndroidVersionLT(28))) {
579ca22d427SDavid Bolvansky     // available IO unlocked variants on GNU/Linux and Android P or later
580ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getc_unlocked);
581ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getchar_unlocked);
582ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putc_unlocked);
583ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putchar_unlocked);
584ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fputc_unlocked);
585ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fgetc_unlocked);
586ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fread_unlocked);
587ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fwrite_unlocked);
588ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fputs_unlocked);
589ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fgets_unlocked);
590ca22d427SDavid Bolvansky   }
591ca22d427SDavid Bolvansky 
592*58481663SNathan Lanza   if (T.isAndroid() && T.isAndroidVersionLT(21)) {
593*58481663SNathan Lanza     TLI.setUnavailable(LibFunc_stpcpy);
594*58481663SNathan Lanza     TLI.setUnavailable(LibFunc_stpncpy);
595*58481663SNathan Lanza   }
596*58481663SNathan Lanza 
59751132881SJustin Lebar   // As currently implemented in clang, NVPTX code has no standard library to
59851132881SJustin Lebar   // speak of.  Headers provide a standard-ish library implementation, but many
59951132881SJustin Lebar   // of the signatures are wrong -- for example, many libm functions are not
60051132881SJustin Lebar   // extern "C".
60151132881SJustin Lebar   //
60251132881SJustin Lebar   // libdevice, an IR library provided by nvidia, is linked in by the front-end,
60351132881SJustin Lebar   // but only used functions are provided to llvm.  Moreover, most of the
60451132881SJustin Lebar   // functions in libdevice don't map precisely to standard library functions.
60551132881SJustin Lebar   //
60651132881SJustin Lebar   // FIXME: Having no standard library prevents e.g. many fastmath
60751132881SJustin Lebar   // optimizations, so this situation should be fixed.
608ae272d71SDavid Majnemer   if (T.isNVPTX()) {
60951132881SJustin Lebar     TLI.disableAllFunctions();
610d21529faSDavid L. Jones     TLI.setAvailable(LibFunc_nvvm_reflect);
611f40a2c3bSJohannes Doerfert     TLI.setAvailable(llvm::LibFunc_malloc);
612f40a2c3bSJohannes Doerfert     TLI.setAvailable(llvm::LibFunc_free);
613f40a2c3bSJohannes Doerfert 
614f40a2c3bSJohannes Doerfert     // TODO: We could enable the following two according to [0] but we haven't
615f40a2c3bSJohannes Doerfert     //       done an evaluation wrt. the performance implications.
616f40a2c3bSJohannes Doerfert     // [0]
617f40a2c3bSJohannes Doerfert     // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations
618f40a2c3bSJohannes Doerfert     //
619f40a2c3bSJohannes Doerfert     //    TLI.setAvailable(llvm::LibFunc_memcpy);
620f40a2c3bSJohannes Doerfert     //    TLI.setAvailable(llvm::LibFunc_memset);
621f40a2c3bSJohannes Doerfert 
6222662351eSJoseph Huber     TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
6232662351eSJoseph Huber     TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
624ae272d71SDavid Majnemer   } else {
625d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nvvm_reflect);
626ae272d71SDavid Majnemer   }
62751132881SJustin Lebar 
62899a0aa07SShimin Cui   // These vec_malloc/free routines are only available on AIX.
62999a0aa07SShimin Cui   if (!T.isOSAIX()) {
63099a0aa07SShimin Cui     TLI.setUnavailable(LibFunc_vec_calloc);
63199a0aa07SShimin Cui     TLI.setUnavailable(LibFunc_vec_malloc);
63299a0aa07SShimin Cui     TLI.setUnavailable(LibFunc_vec_realloc);
63399a0aa07SShimin Cui     TLI.setUnavailable(LibFunc_vec_free);
63499a0aa07SShimin Cui   }
63599a0aa07SShimin Cui 
636ed03d948SMehdi Amini   TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
63762d4215bSChandler Carruth }
63862d4215bSChandler Carruth 
639c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
64062d4215bSChandler Carruth   // Default to everything being available.
64162d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
64262d4215bSChandler Carruth 
64362d4215bSChandler Carruth   initialize(*this, Triple(), StandardNames);
64462d4215bSChandler Carruth }
64562d4215bSChandler Carruth 
6467459398aSJoel Jones TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
64762d4215bSChandler Carruth   // Default to everything being available.
64862d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
64962d4215bSChandler Carruth 
65062d4215bSChandler Carruth   initialize(*this, T, StandardNames);
65162d4215bSChandler Carruth }
65262d4215bSChandler Carruth 
653c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
6547459398aSJoel Jones     : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
6555ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
6569c54ee43SBjorn Pettersson       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
6579c54ee43SBjorn Pettersson       SizeOfInt(TLI.SizeOfInt) {
65862d4215bSChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
659ed03d948SMehdi Amini   VectorDescs = TLI.VectorDescs;
660ed03d948SMehdi Amini   ScalarDescs = TLI.ScalarDescs;
6618ca43224SChandler Carruth }
6628ca43224SChandler Carruth 
663c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
6647459398aSJoel Jones     : CustomNames(std::move(TLI.CustomNames)),
6655ae2c526SMarcin Koscielnicki       ShouldExtI32Param(TLI.ShouldExtI32Param),
6665ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
6679c54ee43SBjorn Pettersson       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
6689c54ee43SBjorn Pettersson       SizeOfInt(TLI.SizeOfInt) {
6698ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
6708ca43224SChandler Carruth             AvailableArray);
671ed03d948SMehdi Amini   VectorDescs = TLI.VectorDescs;
672ed03d948SMehdi Amini   ScalarDescs = TLI.ScalarDescs;
6738ca43224SChandler Carruth }
6748ca43224SChandler Carruth 
675c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
67662d4215bSChandler Carruth   CustomNames = TLI.CustomNames;
6775ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
6785ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
6795ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
6809c54ee43SBjorn Pettersson   SizeOfInt = TLI.SizeOfInt;
6818ca43224SChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
6828ca43224SChandler Carruth   return *this;
6838ca43224SChandler Carruth }
6848ca43224SChandler Carruth 
685c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
6868ca43224SChandler Carruth   CustomNames = std::move(TLI.CustomNames);
6875ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
6885ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
6895ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
6909c54ee43SBjorn Pettersson   SizeOfInt = TLI.SizeOfInt;
6918ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
6928ca43224SChandler Carruth             AvailableArray);
6938ca43224SChandler Carruth   return *this;
69462d4215bSChandler Carruth }
69562d4215bSChandler Carruth 
69621abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) {
69762d4215bSChandler Carruth   // Filter out empty names and names containing null bytes, those can't be in
69862d4215bSChandler Carruth   // our table.
69962d4215bSChandler Carruth   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
70021abdf98SMichael Zolotukhin     return StringRef();
70162d4215bSChandler Carruth 
70262d4215bSChandler Carruth   // Check for \01 prefix that is used to mangle __asm declarations and
70362d4215bSChandler Carruth   // strip it if present.
7046f0ecca3SPeter Collingbourne   return GlobalValue::dropLLVMManglingEscape(funcName);
70521abdf98SMichael Zolotukhin }
70621abdf98SMichael Zolotukhin 
707d5e60669SBenjamin Kramer bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
70821abdf98SMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
70921abdf98SMichael Zolotukhin   if (funcName.empty())
71021abdf98SMichael Zolotukhin     return false;
71121abdf98SMichael Zolotukhin 
712d5e60669SBenjamin Kramer   const auto *Start = std::begin(StandardNames);
713d5e60669SBenjamin Kramer   const auto *End = std::end(StandardNames);
714d5e60669SBenjamin Kramer   const auto *I = std::lower_bound(Start, End, funcName);
71562d4215bSChandler Carruth   if (I != End && *I == funcName) {
716d21529faSDavid L. Jones     F = (LibFunc)(I - Start);
71762d4215bSChandler Carruth     return true;
71862d4215bSChandler Carruth   }
71962d4215bSChandler Carruth   return false;
72062d4215bSChandler Carruth }
72162d4215bSChandler Carruth 
722d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
723d21529faSDavid L. Jones                                                    LibFunc F,
724d765a82bSAhmed Bougacha                                                    const DataLayout *DL) const {
725d765a82bSAhmed Bougacha   LLVMContext &Ctx = FTy.getContext();
7266913812aSFangrui Song   Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AddressSpace=*/0) : nullptr;
727d765a82bSAhmed Bougacha   auto IsSizeTTy = [SizeTTy](Type *Ty) {
728d765a82bSAhmed Bougacha     return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
729d765a82bSAhmed Bougacha   };
730d765a82bSAhmed Bougacha   unsigned NumParams = FTy.getNumParams();
731d765a82bSAhmed Bougacha 
732d765a82bSAhmed Bougacha   switch (F) {
733c3bed1e8SCalixte Denizet   case LibFunc_execl:
734c3bed1e8SCalixte Denizet   case LibFunc_execlp:
7358f07efc7SCalixte Denizet   case LibFunc_execle:
736c3bed1e8SCalixte Denizet     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
737c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
738c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
739c3bed1e8SCalixte Denizet   case LibFunc_execv:
740c3bed1e8SCalixte Denizet   case LibFunc_execvp:
741c3bed1e8SCalixte Denizet     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
742c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
743c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
744c3bed1e8SCalixte Denizet   case LibFunc_execvP:
745c3bed1e8SCalixte Denizet   case LibFunc_execvpe:
746c3bed1e8SCalixte Denizet   case LibFunc_execve:
747c3bed1e8SCalixte Denizet     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
748c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
749c3bed1e8SCalixte Denizet             FTy.getParamType(2)->isPointerTy() &&
750c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
751f8c9ceb1SGeorge Burgess IV   case LibFunc_strlen_chk:
752f8c9ceb1SGeorge Burgess IV     --NumParams;
753f8c9ceb1SGeorge Burgess IV     if (!IsSizeTTy(FTy.getParamType(NumParams)))
754f8c9ceb1SGeorge Burgess IV       return false;
755f8c9ceb1SGeorge Burgess IV     LLVM_FALLTHROUGH;
756d21529faSDavid L. Jones   case LibFunc_strlen:
757d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
758d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
759d765a82bSAhmed Bougacha 
760d21529faSDavid L. Jones   case LibFunc_strchr:
761d21529faSDavid L. Jones   case LibFunc_strrchr:
762d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
763d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
764d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy());
765d765a82bSAhmed Bougacha 
766d21529faSDavid L. Jones   case LibFunc_strtol:
767d21529faSDavid L. Jones   case LibFunc_strtod:
768d21529faSDavid L. Jones   case LibFunc_strtof:
769d21529faSDavid L. Jones   case LibFunc_strtoul:
770d21529faSDavid L. Jones   case LibFunc_strtoll:
771d21529faSDavid L. Jones   case LibFunc_strtold:
772d21529faSDavid L. Jones   case LibFunc_strtoull:
773d765a82bSAhmed Bougacha     return ((NumParams == 2 || NumParams == 3) &&
774d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
775d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
776abb2a93cSErik Pilkington   case LibFunc_strcat_chk:
777abb2a93cSErik Pilkington     --NumParams;
778abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
779abb2a93cSErik Pilkington       return false;
780abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
781d21529faSDavid L. Jones   case LibFunc_strcat:
782d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
783d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
784d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType());
785d765a82bSAhmed Bougacha 
786abb2a93cSErik Pilkington   case LibFunc_strncat_chk:
787abb2a93cSErik Pilkington     --NumParams;
788abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
789abb2a93cSErik Pilkington       return false;
790abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
791d21529faSDavid L. Jones   case LibFunc_strncat:
792d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
793d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
794d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType() &&
7957bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
796d765a82bSAhmed Bougacha 
797d21529faSDavid L. Jones   case LibFunc_strcpy_chk:
798d21529faSDavid L. Jones   case LibFunc_stpcpy_chk:
799d765a82bSAhmed Bougacha     --NumParams;
800d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
801d765a82bSAhmed Bougacha       return false;
802b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
803d21529faSDavid L. Jones   case LibFunc_strcpy:
804d21529faSDavid L. Jones   case LibFunc_stpcpy:
805d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
806d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
807b26d6758SAlex Richardson             FTy.getParamType(0)->isPointerTy());
808d765a82bSAhmed Bougacha 
809abb2a93cSErik Pilkington   case LibFunc_strlcat_chk:
810abb2a93cSErik Pilkington   case LibFunc_strlcpy_chk:
811abb2a93cSErik Pilkington     --NumParams;
812abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
813abb2a93cSErik Pilkington       return false;
814abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
815abb2a93cSErik Pilkington   case LibFunc_strlcat:
816abb2a93cSErik Pilkington   case LibFunc_strlcpy:
817abb2a93cSErik Pilkington     return NumParams == 3 && IsSizeTTy(FTy.getReturnType()) &&
818abb2a93cSErik Pilkington            FTy.getParamType(0)->isPointerTy() &&
819abb2a93cSErik Pilkington            FTy.getParamType(1)->isPointerTy() &&
820abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2));
821abb2a93cSErik Pilkington 
822d21529faSDavid L. Jones   case LibFunc_strncpy_chk:
823d21529faSDavid L. Jones   case LibFunc_stpncpy_chk:
824d765a82bSAhmed Bougacha     --NumParams;
825d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
826d765a82bSAhmed Bougacha       return false;
827b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
828d21529faSDavid L. Jones   case LibFunc_strncpy:
829d21529faSDavid L. Jones   case LibFunc_stpncpy:
830d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
831d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
832b26d6758SAlex Richardson             FTy.getParamType(0)->isPointerTy() &&
8337bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
834d765a82bSAhmed Bougacha 
835d21529faSDavid L. Jones   case LibFunc_strxfrm:
836d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
837d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
838d765a82bSAhmed Bougacha 
839d21529faSDavid L. Jones   case LibFunc_strcmp:
840d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
841d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
842d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
843d765a82bSAhmed Bougacha 
844d21529faSDavid L. Jones   case LibFunc_strncmp:
845d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
846d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
847d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
8487bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
849d765a82bSAhmed Bougacha 
850d21529faSDavid L. Jones   case LibFunc_strspn:
851d21529faSDavid L. Jones   case LibFunc_strcspn:
852d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
853d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
854d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
855d765a82bSAhmed Bougacha 
856d21529faSDavid L. Jones   case LibFunc_strcoll:
857d21529faSDavid L. Jones   case LibFunc_strcasecmp:
858d21529faSDavid L. Jones   case LibFunc_strncasecmp:
859d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
860d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
861d765a82bSAhmed Bougacha 
862d21529faSDavid L. Jones   case LibFunc_strstr:
863d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
864d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
865d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
866d765a82bSAhmed Bougacha 
867d21529faSDavid L. Jones   case LibFunc_strpbrk:
868d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
869d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
870d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
871d765a82bSAhmed Bougacha 
872d21529faSDavid L. Jones   case LibFunc_strtok:
873d21529faSDavid L. Jones   case LibFunc_strtok_r:
874d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
875d21529faSDavid L. Jones   case LibFunc_scanf:
876d21529faSDavid L. Jones   case LibFunc_setbuf:
877d21529faSDavid L. Jones   case LibFunc_setvbuf:
878d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
879d21529faSDavid L. Jones   case LibFunc_strdup:
880d21529faSDavid L. Jones   case LibFunc_strndup:
881d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
882d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
883d21529faSDavid L. Jones   case LibFunc_sscanf:
884d21529faSDavid L. Jones   case LibFunc_stat:
885d21529faSDavid L. Jones   case LibFunc_statvfs:
886d21529faSDavid L. Jones   case LibFunc_siprintf:
887b4f9991fSAlon Zakai   case LibFunc_small_sprintf:
888d21529faSDavid L. Jones   case LibFunc_sprintf:
889d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
8900d7c3775SMartin Storsjo             FTy.getParamType(1)->isPointerTy() &&
8910d7c3775SMartin Storsjo             FTy.getReturnType()->isIntegerTy(32));
892abb2a93cSErik Pilkington 
893abb2a93cSErik Pilkington   case LibFunc_sprintf_chk:
894abb2a93cSErik Pilkington     return NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
895abb2a93cSErik Pilkington            FTy.getParamType(1)->isIntegerTy(32) &&
896abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2)) &&
897abb2a93cSErik Pilkington            FTy.getParamType(3)->isPointerTy() &&
898abb2a93cSErik Pilkington            FTy.getReturnType()->isIntegerTy(32);
899abb2a93cSErik Pilkington 
900d21529faSDavid L. Jones   case LibFunc_snprintf:
9017f555577SSanjay Patel     return NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
9027f555577SSanjay Patel            IsSizeTTy(FTy.getParamType(1)) &&
9030d7c3775SMartin Storsjo            FTy.getParamType(2)->isPointerTy() &&
9047f555577SSanjay Patel            FTy.getReturnType()->isIntegerTy(32);
905abb2a93cSErik Pilkington 
906abb2a93cSErik Pilkington   case LibFunc_snprintf_chk:
907abb2a93cSErik Pilkington     return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
908abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(1)) &&
909abb2a93cSErik Pilkington            FTy.getParamType(2)->isIntegerTy(32) &&
910abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(3)) &&
911abb2a93cSErik Pilkington            FTy.getParamType(4)->isPointerTy() &&
912abb2a93cSErik Pilkington            FTy.getReturnType()->isIntegerTy(32);
913abb2a93cSErik Pilkington 
914d21529faSDavid L. Jones   case LibFunc_setitimer:
915d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
916d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
917d21529faSDavid L. Jones   case LibFunc_system:
918d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
9192662351eSJoseph Huber   case LibFunc___kmpc_alloc_shared:
920d21529faSDavid L. Jones   case LibFunc_malloc:
92199a0aa07SShimin Cui   case LibFunc_vec_malloc:
922d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
923d21529faSDavid L. Jones   case LibFunc_memcmp:
9246b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
9256b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
9266b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
927d765a82bSAhmed Bougacha 
928d21529faSDavid L. Jones   case LibFunc_memchr:
929d21529faSDavid L. Jones   case LibFunc_memrchr:
9306b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
9316b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
932d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32) &&
9336b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
934d21529faSDavid L. Jones   case LibFunc_modf:
935d21529faSDavid L. Jones   case LibFunc_modff:
936d21529faSDavid L. Jones   case LibFunc_modfl:
937d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
938d765a82bSAhmed Bougacha 
939d21529faSDavid L. Jones   case LibFunc_memcpy_chk:
94086429c4eSDávid Bolvanský   case LibFunc_mempcpy_chk:
941d21529faSDavid L. Jones   case LibFunc_memmove_chk:
942d765a82bSAhmed Bougacha     --NumParams;
943d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
944d765a82bSAhmed Bougacha       return false;
945b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
946d21529faSDavid L. Jones   case LibFunc_memcpy:
947d21529faSDavid L. Jones   case LibFunc_mempcpy:
948d21529faSDavid L. Jones   case LibFunc_memmove:
949d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
950d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
951d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
952d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
953d765a82bSAhmed Bougacha 
954d21529faSDavid L. Jones   case LibFunc_memset_chk:
955d765a82bSAhmed Bougacha     --NumParams;
956d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
957d765a82bSAhmed Bougacha       return false;
958b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
959d21529faSDavid L. Jones   case LibFunc_memset:
960d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
961d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
962d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
963d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
964d765a82bSAhmed Bougacha 
965abb2a93cSErik Pilkington   case LibFunc_memccpy_chk:
966abb2a93cSErik Pilkington       --NumParams;
967abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
968abb2a93cSErik Pilkington       return false;
969abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
970d21529faSDavid L. Jones   case LibFunc_memccpy:
971d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
972d21529faSDavid L. Jones   case LibFunc_memalign:
973d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
974d21529faSDavid L. Jones   case LibFunc_realloc:
975d21529faSDavid L. Jones   case LibFunc_reallocf:
97699a0aa07SShimin Cui   case LibFunc_vec_realloc:
977b26d6758SAlex Richardson     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
9786b9be1dbSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
9796b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(1)));
980d21529faSDavid L. Jones   case LibFunc_read:
981d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
982d21529faSDavid L. Jones   case LibFunc_rewind:
983d21529faSDavid L. Jones   case LibFunc_rmdir:
984d21529faSDavid L. Jones   case LibFunc_remove:
985d21529faSDavid L. Jones   case LibFunc_realpath:
986d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
987d21529faSDavid L. Jones   case LibFunc_rename:
988d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
989d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
990d21529faSDavid L. Jones   case LibFunc_readlink:
991d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
992d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
993d21529faSDavid L. Jones   case LibFunc_write:
994d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
995c0955edfSUday Bondhugula   case LibFunc_aligned_alloc:
996c0955edfSUday Bondhugula     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
997d21529faSDavid L. Jones   case LibFunc_bcopy:
998d21529faSDavid L. Jones   case LibFunc_bcmp:
999d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1000d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1001d21529faSDavid L. Jones   case LibFunc_bzero:
1002d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1003d21529faSDavid L. Jones   case LibFunc_calloc:
100499a0aa07SShimin Cui   case LibFunc_vec_calloc:
10057414bbebSSanjay Patel     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
10067414bbebSSanjay Patel             FTy.getParamType(0) == FTy.getParamType(1));
10071fe3f1caSAhmed Bougacha 
1008d21529faSDavid L. Jones   case LibFunc_atof:
1009d21529faSDavid L. Jones   case LibFunc_atoi:
1010d21529faSDavid L. Jones   case LibFunc_atol:
1011d21529faSDavid L. Jones   case LibFunc_atoll:
1012d21529faSDavid L. Jones   case LibFunc_ferror:
1013d21529faSDavid L. Jones   case LibFunc_getenv:
1014d21529faSDavid L. Jones   case LibFunc_getpwnam:
1015d21529faSDavid L. Jones   case LibFunc_iprintf:
1016b4f9991fSAlon Zakai   case LibFunc_small_printf:
1017d21529faSDavid L. Jones   case LibFunc_pclose:
1018d21529faSDavid L. Jones   case LibFunc_perror:
1019d21529faSDavid L. Jones   case LibFunc_printf:
1020d21529faSDavid L. Jones   case LibFunc_puts:
1021d21529faSDavid L. Jones   case LibFunc_uname:
1022d21529faSDavid L. Jones   case LibFunc_under_IO_getc:
1023d21529faSDavid L. Jones   case LibFunc_unlink:
1024d21529faSDavid L. Jones   case LibFunc_unsetenv:
1025d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
10261fe3f1caSAhmed Bougacha 
1027d21529faSDavid L. Jones   case LibFunc_access:
1028d21529faSDavid L. Jones   case LibFunc_chmod:
1029d21529faSDavid L. Jones   case LibFunc_chown:
1030d21529faSDavid L. Jones   case LibFunc_clearerr:
1031d21529faSDavid L. Jones   case LibFunc_closedir:
1032d21529faSDavid L. Jones   case LibFunc_ctermid:
1033d21529faSDavid L. Jones   case LibFunc_fclose:
1034d21529faSDavid L. Jones   case LibFunc_feof:
1035d21529faSDavid L. Jones   case LibFunc_fflush:
1036d21529faSDavid L. Jones   case LibFunc_fgetc:
1037ca22d427SDavid Bolvansky   case LibFunc_fgetc_unlocked:
1038d21529faSDavid L. Jones   case LibFunc_fileno:
1039d21529faSDavid L. Jones   case LibFunc_flockfile:
1040d21529faSDavid L. Jones   case LibFunc_free:
1041d21529faSDavid L. Jones   case LibFunc_fseek:
1042d21529faSDavid L. Jones   case LibFunc_fseeko64:
1043d21529faSDavid L. Jones   case LibFunc_fseeko:
1044d21529faSDavid L. Jones   case LibFunc_fsetpos:
1045d21529faSDavid L. Jones   case LibFunc_ftell:
1046d21529faSDavid L. Jones   case LibFunc_ftello64:
1047d21529faSDavid L. Jones   case LibFunc_ftello:
1048d21529faSDavid L. Jones   case LibFunc_ftrylockfile:
1049d21529faSDavid L. Jones   case LibFunc_funlockfile:
1050d21529faSDavid L. Jones   case LibFunc_getc:
1051d21529faSDavid L. Jones   case LibFunc_getc_unlocked:
1052d21529faSDavid L. Jones   case LibFunc_getlogin_r:
1053d21529faSDavid L. Jones   case LibFunc_mkdir:
1054d21529faSDavid L. Jones   case LibFunc_mktime:
1055d21529faSDavid L. Jones   case LibFunc_times:
105699a0aa07SShimin Cui   case LibFunc_vec_free:
10571fe3f1caSAhmed Bougacha     return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
1058754eb1c2SJoseph Huber   case LibFunc___kmpc_free_shared:
1059754eb1c2SJoseph Huber     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1060754eb1c2SJoseph Huber             IsSizeTTy(FTy.getParamType(1)));
10611fe3f1caSAhmed Bougacha 
1062d21529faSDavid L. Jones   case LibFunc_fopen:
1063d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1064d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1065d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1066c3bed1e8SCalixte Denizet   case LibFunc_fork:
1067c3bed1e8SCalixte Denizet     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
1068d21529faSDavid L. Jones   case LibFunc_fdopen:
1069d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1070d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1071d21529faSDavid L. Jones   case LibFunc_fputc:
1072ca22d427SDavid Bolvansky   case LibFunc_fputc_unlocked:
1073d21529faSDavid L. Jones   case LibFunc_fstat:
1074d21529faSDavid L. Jones   case LibFunc_frexp:
1075d21529faSDavid L. Jones   case LibFunc_frexpf:
1076d21529faSDavid L. Jones   case LibFunc_frexpl:
1077d21529faSDavid L. Jones   case LibFunc_fstatvfs:
1078d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1079d21529faSDavid L. Jones   case LibFunc_fgets:
1080ca22d427SDavid Bolvansky   case LibFunc_fgets_unlocked:
1081d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1082d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1083d21529faSDavid L. Jones   case LibFunc_fread:
1084ca22d427SDavid Bolvansky   case LibFunc_fread_unlocked:
1085d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1086d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
1087d21529faSDavid L. Jones   case LibFunc_fwrite:
1088ca22d427SDavid Bolvansky   case LibFunc_fwrite_unlocked:
1089d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
1090d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1091d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
1092d765a82bSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy() &&
1093d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
1094d21529faSDavid L. Jones   case LibFunc_fputs:
1095ca22d427SDavid Bolvansky   case LibFunc_fputs_unlocked:
1096d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1097d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1098d21529faSDavid L. Jones   case LibFunc_fscanf:
1099d21529faSDavid L. Jones   case LibFunc_fiprintf:
1100b4f9991fSAlon Zakai   case LibFunc_small_fprintf:
1101d21529faSDavid L. Jones   case LibFunc_fprintf:
11026b9be1dbSAhmed Bougacha     return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
11036b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1104d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1105d21529faSDavid L. Jones   case LibFunc_fgetpos:
1106d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1107d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1108d21529faSDavid L. Jones   case LibFunc_getchar:
1109ca22d427SDavid Bolvansky   case LibFunc_getchar_unlocked:
11106b9be1dbSAhmed Bougacha     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
1111d21529faSDavid L. Jones   case LibFunc_gets:
1112b26d6758SAlex Richardson     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1113d21529faSDavid L. Jones   case LibFunc_getitimer:
1114d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1115d21529faSDavid L. Jones   case LibFunc_ungetc:
1116d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1117d21529faSDavid L. Jones   case LibFunc_utime:
1118d21529faSDavid L. Jones   case LibFunc_utimes:
1119d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1120d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1121d21529faSDavid L. Jones   case LibFunc_putc:
1122ca22d427SDavid Bolvansky   case LibFunc_putc_unlocked:
1123d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1124d21529faSDavid L. Jones   case LibFunc_pread:
1125d21529faSDavid L. Jones   case LibFunc_pwrite:
1126d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
1127d21529faSDavid L. Jones   case LibFunc_popen:
1128d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1129d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1130d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1131d21529faSDavid L. Jones   case LibFunc_vscanf:
1132d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1133d21529faSDavid L. Jones   case LibFunc_vsscanf:
1134d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1135d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1136d21529faSDavid L. Jones   case LibFunc_vfscanf:
1137d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1138d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1139d21529faSDavid L. Jones   case LibFunc_valloc:
1140d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1141d21529faSDavid L. Jones   case LibFunc_vprintf:
1142d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1143d21529faSDavid L. Jones   case LibFunc_vfprintf:
1144d21529faSDavid L. Jones   case LibFunc_vsprintf:
1145d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1146d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1147abb2a93cSErik Pilkington   case LibFunc_vsprintf_chk:
1148abb2a93cSErik Pilkington     return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
1149abb2a93cSErik Pilkington            FTy.getParamType(1)->isIntegerTy(32) &&
1150abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2)) && FTy.getParamType(3)->isPointerTy();
1151d21529faSDavid L. Jones   case LibFunc_vsnprintf:
1152d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1153d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1154abb2a93cSErik Pilkington   case LibFunc_vsnprintf_chk:
1155abb2a93cSErik Pilkington     return NumParams == 6 && FTy.getParamType(0)->isPointerTy() &&
1156abb2a93cSErik Pilkington            FTy.getParamType(2)->isIntegerTy(32) &&
1157abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(3)) && FTy.getParamType(4)->isPointerTy();
1158d21529faSDavid L. Jones   case LibFunc_open:
1159d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1160d21529faSDavid L. Jones   case LibFunc_opendir:
1161d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
1162d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
1163d21529faSDavid L. Jones   case LibFunc_tmpfile:
1164d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1165d21529faSDavid L. Jones   case LibFunc_htonl:
1166d21529faSDavid L. Jones   case LibFunc_ntohl:
11676b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
11686b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1169d21529faSDavid L. Jones   case LibFunc_htons:
1170d21529faSDavid L. Jones   case LibFunc_ntohs:
11716b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
11726b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1173d21529faSDavid L. Jones   case LibFunc_lstat:
1174d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1175d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1176d21529faSDavid L. Jones   case LibFunc_lchown:
1177d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1178d21529faSDavid L. Jones   case LibFunc_qsort:
1179d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
1180d21529faSDavid L. Jones   case LibFunc_dunder_strdup:
1181d21529faSDavid L. Jones   case LibFunc_dunder_strndup:
1182d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
1183d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
1184d21529faSDavid L. Jones   case LibFunc_dunder_strtok_r:
1185d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1186d21529faSDavid L. Jones   case LibFunc_under_IO_putc:
1187d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1188d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_scanf:
1189d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1190d21529faSDavid L. Jones   case LibFunc_stat64:
1191d21529faSDavid L. Jones   case LibFunc_lstat64:
1192d21529faSDavid L. Jones   case LibFunc_statvfs64:
119379dcc274SMichael Kuperstein     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1194d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1195d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_sscanf:
119679dcc274SMichael Kuperstein     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1197d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1198d21529faSDavid L. Jones   case LibFunc_fopen64:
1199d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1200d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1201d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1202d21529faSDavid L. Jones   case LibFunc_tmpfile64:
1203d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1204d21529faSDavid L. Jones   case LibFunc_fstat64:
1205d21529faSDavid L. Jones   case LibFunc_fstatvfs64:
1206d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1207d21529faSDavid L. Jones   case LibFunc_open64:
1208d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1209d21529faSDavid L. Jones   case LibFunc_gettimeofday:
1210d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1211d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1212d765a82bSAhmed Bougacha 
12136b9be1dbSAhmed Bougacha   // new(unsigned int);
1214d21529faSDavid L. Jones   case LibFunc_Znwj:
12156b9be1dbSAhmed Bougacha   // new(unsigned long);
1216d21529faSDavid L. Jones   case LibFunc_Znwm:
12176b9be1dbSAhmed Bougacha   // new[](unsigned int);
1218d21529faSDavid L. Jones   case LibFunc_Znaj:
12196b9be1dbSAhmed Bougacha   // new[](unsigned long);
1220d21529faSDavid L. Jones   case LibFunc_Znam:
12216b9be1dbSAhmed Bougacha   // new(unsigned int);
1222d21529faSDavid L. Jones   case LibFunc_msvc_new_int:
12236b9be1dbSAhmed Bougacha   // new(unsigned long long);
1224d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong:
12256b9be1dbSAhmed Bougacha   // new[](unsigned int);
1226d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int:
12276b9be1dbSAhmed Bougacha   // new[](unsigned long long);
1228d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong:
12296b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
12306b9be1dbSAhmed Bougacha 
12316b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
1232d21529faSDavid L. Jones   case LibFunc_ZnwjRKSt9nothrow_t:
12336b9be1dbSAhmed Bougacha   // new(unsigned long, nothrow);
1234d21529faSDavid L. Jones   case LibFunc_ZnwmRKSt9nothrow_t:
12356b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
1236d21529faSDavid L. Jones   case LibFunc_ZnajRKSt9nothrow_t:
12376b9be1dbSAhmed Bougacha   // new[](unsigned long, nothrow);
1238d21529faSDavid L. Jones   case LibFunc_ZnamRKSt9nothrow_t:
12396b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
1240d21529faSDavid L. Jones   case LibFunc_msvc_new_int_nothrow:
12416b9be1dbSAhmed Bougacha   // new(unsigned long long, nothrow);
1242d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong_nothrow:
12436b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
1244d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int_nothrow:
12456b9be1dbSAhmed Bougacha   // new[](unsigned long long, nothrow);
1246d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong_nothrow:
124796bbec79SEric Fiselier   // new(unsigned int, align_val_t)
124896bbec79SEric Fiselier   case LibFunc_ZnwjSt11align_val_t:
124996bbec79SEric Fiselier   // new(unsigned long, align_val_t)
125096bbec79SEric Fiselier   case LibFunc_ZnwmSt11align_val_t:
125196bbec79SEric Fiselier   // new[](unsigned int, align_val_t)
125296bbec79SEric Fiselier   case LibFunc_ZnajSt11align_val_t:
125396bbec79SEric Fiselier   // new[](unsigned long, align_val_t)
125496bbec79SEric Fiselier   case LibFunc_ZnamSt11align_val_t:
12556b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
12566b9be1dbSAhmed Bougacha 
125796bbec79SEric Fiselier   // new(unsigned int, align_val_t, nothrow)
125896bbec79SEric Fiselier   case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
125996bbec79SEric Fiselier   // new(unsigned long, align_val_t, nothrow)
126096bbec79SEric Fiselier   case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
126196bbec79SEric Fiselier   // new[](unsigned int, align_val_t, nothrow)
126296bbec79SEric Fiselier   case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
126396bbec79SEric Fiselier   // new[](unsigned long, align_val_t, nothrow)
126496bbec79SEric Fiselier   case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
126596bbec79SEric Fiselier     return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
126696bbec79SEric Fiselier 
12676b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1268d21529faSDavid L. Jones   case LibFunc_ZdaPv:
12696b9be1dbSAhmed Bougacha   // void operator delete(void*);
1270d21529faSDavid L. Jones   case LibFunc_ZdlPv:
12716b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1272d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32:
12736b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1274d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64:
12756b9be1dbSAhmed Bougacha   // void operator delete(void*);
1276d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32:
12776b9be1dbSAhmed Bougacha   // void operator delete(void*);
1278d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64:
12796b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
12806b9be1dbSAhmed Bougacha 
12816b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1282d21529faSDavid L. Jones   case LibFunc_ZdaPvRKSt9nothrow_t:
12836b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1284d21529faSDavid L. Jones   case LibFunc_ZdaPvj:
12856b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long);
1286d21529faSDavid L. Jones   case LibFunc_ZdaPvm:
12876b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1288d21529faSDavid L. Jones   case LibFunc_ZdlPvRKSt9nothrow_t:
12896b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1290d21529faSDavid L. Jones   case LibFunc_ZdlPvj:
12916b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long);
1292d21529faSDavid L. Jones   case LibFunc_ZdlPvm:
129396bbec79SEric Fiselier   // void operator delete(void*, align_val_t)
129496bbec79SEric Fiselier   case LibFunc_ZdlPvSt11align_val_t:
129596bbec79SEric Fiselier   // void operator delete[](void*, align_val_t)
129696bbec79SEric Fiselier   case LibFunc_ZdaPvSt11align_val_t:
12976b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1298d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_int:
12996b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1300d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_nothrow:
13016b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long long);
1302d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_longlong:
13036b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1304d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_nothrow:
13056b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1306d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_int:
13076b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1308d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_nothrow:
13096b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long long);
1310d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_longlong:
13116b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1312d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_nothrow:
13136b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1314d765a82bSAhmed Bougacha 
131596bbec79SEric Fiselier   // void operator delete(void*, align_val_t, nothrow)
131696bbec79SEric Fiselier   case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
131796bbec79SEric Fiselier   // void operator delete[](void*, align_val_t, nothrow)
131896bbec79SEric Fiselier   case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
13196bc2b042SHiroshi Yamauchi   // void operator delete(void*, unsigned int, align_val_t)
13206bc2b042SHiroshi Yamauchi   case LibFunc_ZdlPvjSt11align_val_t:
13216bc2b042SHiroshi Yamauchi   // void operator delete(void*, unsigned long, align_val_t)
13226bc2b042SHiroshi Yamauchi   case LibFunc_ZdlPvmSt11align_val_t:
13236bc2b042SHiroshi Yamauchi   // void operator delete[](void*, unsigned int, align_val_t);
13246bc2b042SHiroshi Yamauchi   case LibFunc_ZdaPvjSt11align_val_t:
13256bc2b042SHiroshi Yamauchi   // void operator delete[](void*, unsigned long, align_val_t);
13266bc2b042SHiroshi Yamauchi   case LibFunc_ZdaPvmSt11align_val_t:
132796bbec79SEric Fiselier     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
132896bbec79SEric Fiselier 
1329c4250941SGui Andrade   // void __atomic_load(size_t, void *, void *, int)
1330c4250941SGui Andrade   case LibFunc_atomic_load:
1331c4250941SGui Andrade   // void __atomic_store(size_t, void *, void *, int)
1332c4250941SGui Andrade   case LibFunc_atomic_store:
1333c4250941SGui Andrade     return (NumParams == 4 && FTy.getParamType(0)->isIntegerTy() &&
1334c4250941SGui Andrade             FTy.getParamType(1)->isPointerTy() &&
1335c4250941SGui Andrade             FTy.getParamType(2)->isPointerTy() &&
1336c4250941SGui Andrade             FTy.getParamType(3)->isIntegerTy());
1337c4250941SGui Andrade 
1338d21529faSDavid L. Jones   case LibFunc_memset_pattern16:
1339d765a82bSAhmed Bougacha     return (!FTy.isVarArg() && NumParams == 3 &&
13406b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
13416b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
13426b9be1dbSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy());
1343d765a82bSAhmed Bougacha 
1344d21529faSDavid L. Jones   case LibFunc_cxa_guard_abort:
1345d21529faSDavid L. Jones   case LibFunc_cxa_guard_acquire:
1346d21529faSDavid L. Jones   case LibFunc_cxa_guard_release:
1347d21529faSDavid L. Jones   case LibFunc_nvvm_reflect:
13486b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1349d765a82bSAhmed Bougacha 
1350d21529faSDavid L. Jones   case LibFunc_sincospi_stret:
1351d21529faSDavid L. Jones   case LibFunc_sincospif_stret:
13526b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
13536b9be1dbSAhmed Bougacha 
1354d21529faSDavid L. Jones   case LibFunc_acos:
13553cd8c16dSAndrew Kaylor   case LibFunc_acos_finite:
1356d21529faSDavid L. Jones   case LibFunc_acosf:
13573cd8c16dSAndrew Kaylor   case LibFunc_acosf_finite:
1358d21529faSDavid L. Jones   case LibFunc_acosh:
13593cd8c16dSAndrew Kaylor   case LibFunc_acosh_finite:
1360d21529faSDavid L. Jones   case LibFunc_acoshf:
13613cd8c16dSAndrew Kaylor   case LibFunc_acoshf_finite:
1362d21529faSDavid L. Jones   case LibFunc_acoshl:
13633cd8c16dSAndrew Kaylor   case LibFunc_acoshl_finite:
1364d21529faSDavid L. Jones   case LibFunc_acosl:
13653cd8c16dSAndrew Kaylor   case LibFunc_acosl_finite:
1366d21529faSDavid L. Jones   case LibFunc_asin:
13673cd8c16dSAndrew Kaylor   case LibFunc_asin_finite:
1368d21529faSDavid L. Jones   case LibFunc_asinf:
13693cd8c16dSAndrew Kaylor   case LibFunc_asinf_finite:
1370d21529faSDavid L. Jones   case LibFunc_asinh:
1371d21529faSDavid L. Jones   case LibFunc_asinhf:
1372d21529faSDavid L. Jones   case LibFunc_asinhl:
1373d21529faSDavid L. Jones   case LibFunc_asinl:
13743cd8c16dSAndrew Kaylor   case LibFunc_asinl_finite:
1375d21529faSDavid L. Jones   case LibFunc_atan:
1376d21529faSDavid L. Jones   case LibFunc_atanf:
1377d21529faSDavid L. Jones   case LibFunc_atanh:
13783cd8c16dSAndrew Kaylor   case LibFunc_atanh_finite:
1379d21529faSDavid L. Jones   case LibFunc_atanhf:
13803cd8c16dSAndrew Kaylor   case LibFunc_atanhf_finite:
1381d21529faSDavid L. Jones   case LibFunc_atanhl:
13823cd8c16dSAndrew Kaylor   case LibFunc_atanhl_finite:
1383d21529faSDavid L. Jones   case LibFunc_atanl:
1384d21529faSDavid L. Jones   case LibFunc_cbrt:
1385d21529faSDavid L. Jones   case LibFunc_cbrtf:
1386d21529faSDavid L. Jones   case LibFunc_cbrtl:
1387d21529faSDavid L. Jones   case LibFunc_ceil:
1388d21529faSDavid L. Jones   case LibFunc_ceilf:
1389d21529faSDavid L. Jones   case LibFunc_ceill:
1390d21529faSDavid L. Jones   case LibFunc_cos:
1391d21529faSDavid L. Jones   case LibFunc_cosf:
1392d21529faSDavid L. Jones   case LibFunc_cosh:
13933cd8c16dSAndrew Kaylor   case LibFunc_cosh_finite:
1394d21529faSDavid L. Jones   case LibFunc_coshf:
13953cd8c16dSAndrew Kaylor   case LibFunc_coshf_finite:
1396d21529faSDavid L. Jones   case LibFunc_coshl:
13973cd8c16dSAndrew Kaylor   case LibFunc_coshl_finite:
1398d21529faSDavid L. Jones   case LibFunc_cosl:
1399d21529faSDavid L. Jones   case LibFunc_exp10:
14003cd8c16dSAndrew Kaylor   case LibFunc_exp10_finite:
1401d21529faSDavid L. Jones   case LibFunc_exp10f:
14023cd8c16dSAndrew Kaylor   case LibFunc_exp10f_finite:
1403d21529faSDavid L. Jones   case LibFunc_exp10l:
14043cd8c16dSAndrew Kaylor   case LibFunc_exp10l_finite:
1405d21529faSDavid L. Jones   case LibFunc_exp2:
14063cd8c16dSAndrew Kaylor   case LibFunc_exp2_finite:
1407d21529faSDavid L. Jones   case LibFunc_exp2f:
14083cd8c16dSAndrew Kaylor   case LibFunc_exp2f_finite:
1409d21529faSDavid L. Jones   case LibFunc_exp2l:
14103cd8c16dSAndrew Kaylor   case LibFunc_exp2l_finite:
1411d21529faSDavid L. Jones   case LibFunc_exp:
14123cd8c16dSAndrew Kaylor   case LibFunc_exp_finite:
1413d21529faSDavid L. Jones   case LibFunc_expf:
14143cd8c16dSAndrew Kaylor   case LibFunc_expf_finite:
1415d21529faSDavid L. Jones   case LibFunc_expl:
14163cd8c16dSAndrew Kaylor   case LibFunc_expl_finite:
1417d21529faSDavid L. Jones   case LibFunc_expm1:
1418d21529faSDavid L. Jones   case LibFunc_expm1f:
1419d21529faSDavid L. Jones   case LibFunc_expm1l:
1420d21529faSDavid L. Jones   case LibFunc_fabs:
1421d21529faSDavid L. Jones   case LibFunc_fabsf:
1422d21529faSDavid L. Jones   case LibFunc_fabsl:
1423d21529faSDavid L. Jones   case LibFunc_floor:
1424d21529faSDavid L. Jones   case LibFunc_floorf:
1425d21529faSDavid L. Jones   case LibFunc_floorl:
1426d21529faSDavid L. Jones   case LibFunc_log10:
14273cd8c16dSAndrew Kaylor   case LibFunc_log10_finite:
1428d21529faSDavid L. Jones   case LibFunc_log10f:
14293cd8c16dSAndrew Kaylor   case LibFunc_log10f_finite:
1430d21529faSDavid L. Jones   case LibFunc_log10l:
14313cd8c16dSAndrew Kaylor   case LibFunc_log10l_finite:
1432d21529faSDavid L. Jones   case LibFunc_log1p:
1433d21529faSDavid L. Jones   case LibFunc_log1pf:
1434d21529faSDavid L. Jones   case LibFunc_log1pl:
1435d21529faSDavid L. Jones   case LibFunc_log2:
14363cd8c16dSAndrew Kaylor   case LibFunc_log2_finite:
1437d21529faSDavid L. Jones   case LibFunc_log2f:
14383cd8c16dSAndrew Kaylor   case LibFunc_log2f_finite:
1439d21529faSDavid L. Jones   case LibFunc_log2l:
14403cd8c16dSAndrew Kaylor   case LibFunc_log2l_finite:
1441d21529faSDavid L. Jones   case LibFunc_log:
14423cd8c16dSAndrew Kaylor   case LibFunc_log_finite:
1443d21529faSDavid L. Jones   case LibFunc_logb:
1444d21529faSDavid L. Jones   case LibFunc_logbf:
1445d21529faSDavid L. Jones   case LibFunc_logbl:
1446d21529faSDavid L. Jones   case LibFunc_logf:
14473cd8c16dSAndrew Kaylor   case LibFunc_logf_finite:
1448d21529faSDavid L. Jones   case LibFunc_logl:
14493cd8c16dSAndrew Kaylor   case LibFunc_logl_finite:
1450d21529faSDavid L. Jones   case LibFunc_nearbyint:
1451d21529faSDavid L. Jones   case LibFunc_nearbyintf:
1452d21529faSDavid L. Jones   case LibFunc_nearbyintl:
1453d21529faSDavid L. Jones   case LibFunc_rint:
1454d21529faSDavid L. Jones   case LibFunc_rintf:
1455d21529faSDavid L. Jones   case LibFunc_rintl:
1456d21529faSDavid L. Jones   case LibFunc_round:
1457d21529faSDavid L. Jones   case LibFunc_roundf:
1458d21529faSDavid L. Jones   case LibFunc_roundl:
14594d20e31fSSerge Pavlov   case LibFunc_roundeven:
14604d20e31fSSerge Pavlov   case LibFunc_roundevenf:
14614d20e31fSSerge Pavlov   case LibFunc_roundevenl:
1462d21529faSDavid L. Jones   case LibFunc_sin:
1463d21529faSDavid L. Jones   case LibFunc_sinf:
1464d21529faSDavid L. Jones   case LibFunc_sinh:
14653cd8c16dSAndrew Kaylor   case LibFunc_sinh_finite:
1466d21529faSDavid L. Jones   case LibFunc_sinhf:
14673cd8c16dSAndrew Kaylor   case LibFunc_sinhf_finite:
1468d21529faSDavid L. Jones   case LibFunc_sinhl:
14693cd8c16dSAndrew Kaylor   case LibFunc_sinhl_finite:
1470d21529faSDavid L. Jones   case LibFunc_sinl:
1471d21529faSDavid L. Jones   case LibFunc_sqrt:
1472d21529faSDavid L. Jones   case LibFunc_sqrt_finite:
1473d21529faSDavid L. Jones   case LibFunc_sqrtf:
1474d21529faSDavid L. Jones   case LibFunc_sqrtf_finite:
1475d21529faSDavid L. Jones   case LibFunc_sqrtl:
1476d21529faSDavid L. Jones   case LibFunc_sqrtl_finite:
1477d21529faSDavid L. Jones   case LibFunc_tan:
1478d21529faSDavid L. Jones   case LibFunc_tanf:
1479d21529faSDavid L. Jones   case LibFunc_tanh:
1480d21529faSDavid L. Jones   case LibFunc_tanhf:
1481d21529faSDavid L. Jones   case LibFunc_tanhl:
1482d21529faSDavid L. Jones   case LibFunc_tanl:
1483d21529faSDavid L. Jones   case LibFunc_trunc:
1484d21529faSDavid L. Jones   case LibFunc_truncf:
1485d21529faSDavid L. Jones   case LibFunc_truncl:
1486d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1487d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1488d765a82bSAhmed Bougacha 
1489d21529faSDavid L. Jones   case LibFunc_atan2:
14903cd8c16dSAndrew Kaylor   case LibFunc_atan2_finite:
1491d21529faSDavid L. Jones   case LibFunc_atan2f:
14923cd8c16dSAndrew Kaylor   case LibFunc_atan2f_finite:
1493d21529faSDavid L. Jones   case LibFunc_atan2l:
14943cd8c16dSAndrew Kaylor   case LibFunc_atan2l_finite:
1495d21529faSDavid L. Jones   case LibFunc_fmin:
1496d21529faSDavid L. Jones   case LibFunc_fminf:
1497d21529faSDavid L. Jones   case LibFunc_fminl:
1498d21529faSDavid L. Jones   case LibFunc_fmax:
1499d21529faSDavid L. Jones   case LibFunc_fmaxf:
1500d21529faSDavid L. Jones   case LibFunc_fmaxl:
1501d21529faSDavid L. Jones   case LibFunc_fmod:
1502d21529faSDavid L. Jones   case LibFunc_fmodf:
1503d21529faSDavid L. Jones   case LibFunc_fmodl:
15042470d298SEhud Katz   case LibFunc_remainder:
15052470d298SEhud Katz   case LibFunc_remainderf:
15062470d298SEhud Katz   case LibFunc_remainderl:
1507d21529faSDavid L. Jones   case LibFunc_copysign:
1508d21529faSDavid L. Jones   case LibFunc_copysignf:
1509d21529faSDavid L. Jones   case LibFunc_copysignl:
1510d21529faSDavid L. Jones   case LibFunc_pow:
15113cd8c16dSAndrew Kaylor   case LibFunc_pow_finite:
1512d21529faSDavid L. Jones   case LibFunc_powf:
15133cd8c16dSAndrew Kaylor   case LibFunc_powf_finite:
1514d21529faSDavid L. Jones   case LibFunc_powl:
15153cd8c16dSAndrew Kaylor   case LibFunc_powl_finite:
1516d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1517d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
1518d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(1));
1519d765a82bSAhmed Bougacha 
1520d21529faSDavid L. Jones   case LibFunc_ldexp:
1521d21529faSDavid L. Jones   case LibFunc_ldexpf:
1522d21529faSDavid L. Jones   case LibFunc_ldexpl:
15236b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
15246b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
15259c54ee43SBjorn Pettersson             FTy.getParamType(1)->isIntegerTy(getIntSize()));
15266b9be1dbSAhmed Bougacha 
1527d21529faSDavid L. Jones   case LibFunc_ffs:
1528d21529faSDavid L. Jones   case LibFunc_ffsl:
1529d21529faSDavid L. Jones   case LibFunc_ffsll:
1530d21529faSDavid L. Jones   case LibFunc_fls:
1531d21529faSDavid L. Jones   case LibFunc_flsl:
1532d21529faSDavid L. Jones   case LibFunc_flsll:
153304949fafSSanjay Patel     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
153404949fafSSanjay Patel             FTy.getParamType(0)->isIntegerTy());
153504949fafSSanjay Patel 
1536d21529faSDavid L. Jones   case LibFunc_isdigit:
1537d21529faSDavid L. Jones   case LibFunc_isascii:
1538d21529faSDavid L. Jones   case LibFunc_toascii:
1539d21529faSDavid L. Jones   case LibFunc_putchar:
1540ca22d427SDavid Bolvansky   case LibFunc_putchar_unlocked:
1541d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
154204949fafSSanjay Patel             FTy.getReturnType() == FTy.getParamType(0));
1543d765a82bSAhmed Bougacha 
1544d21529faSDavid L. Jones   case LibFunc_abs:
1545d21529faSDavid L. Jones   case LibFunc_labs:
1546d21529faSDavid L. Jones   case LibFunc_llabs:
1547d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1548d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1549d765a82bSAhmed Bougacha 
1550d21529faSDavid L. Jones   case LibFunc_cxa_atexit:
1551d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1552d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1553d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
1554d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1555d765a82bSAhmed Bougacha 
1556d21529faSDavid L. Jones   case LibFunc_sinpi:
1557d21529faSDavid L. Jones   case LibFunc_cospi:
1558d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1559d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1560d765a82bSAhmed Bougacha 
1561d21529faSDavid L. Jones   case LibFunc_sinpif:
1562d21529faSDavid L. Jones   case LibFunc_cospif:
1563d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1564d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1565d765a82bSAhmed Bougacha 
1566d21529faSDavid L. Jones   case LibFunc_strnlen:
15676b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1568b26d6758SAlex Richardson             FTy.getParamType(0)->isPointerTy() &&
1569b26d6758SAlex Richardson             IsSizeTTy(FTy.getParamType(1)));
15706b9be1dbSAhmed Bougacha 
1571d21529faSDavid L. Jones   case LibFunc_posix_memalign:
15726b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
15736b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1574b26d6758SAlex Richardson             IsSizeTTy(FTy.getParamType(1)) && IsSizeTTy(FTy.getParamType(2)));
15756b9be1dbSAhmed Bougacha 
157660b40b8fSMatthias Braun   case LibFunc_wcslen:
157760b40b8fSMatthias Braun     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
157860b40b8fSMatthias Braun             FTy.getReturnType()->isIntegerTy());
157960b40b8fSMatthias Braun 
15802ff24731SHal Finkel   case LibFunc_cabs:
15812ff24731SHal Finkel   case LibFunc_cabsf:
15822ff24731SHal Finkel   case LibFunc_cabsl: {
15832ff24731SHal Finkel     Type* RetTy = FTy.getReturnType();
15842ff24731SHal Finkel     if (!RetTy->isFloatingPointTy())
15852ff24731SHal Finkel       return false;
15862ff24731SHal Finkel 
15872ff24731SHal Finkel     // NOTE: These prototypes are target specific and currently support
15882ff24731SHal Finkel     // "complex" passed as an array or discrete real & imaginary parameters.
15892ff24731SHal Finkel     // Add other calling conventions to enable libcall optimizations.
15902ff24731SHal Finkel     if (NumParams == 1)
15912ff24731SHal Finkel       return (FTy.getParamType(0)->isArrayTy() &&
15922ff24731SHal Finkel               FTy.getParamType(0)->getArrayNumElements() == 2 &&
15932ff24731SHal Finkel               FTy.getParamType(0)->getArrayElementType() == RetTy);
15942ff24731SHal Finkel     else if (NumParams == 2)
15952ff24731SHal Finkel       return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
15962ff24731SHal Finkel     else
15972ff24731SHal Finkel       return false;
15982ff24731SHal Finkel   }
15996b9be1dbSAhmed Bougacha   case LibFunc::NumLibFuncs:
16003b705ef7SEvandro Menezes   case LibFunc::NotLibFunc:
160186b680a3SAhmed Bougacha     break;
1602d765a82bSAhmed Bougacha   }
16036b9be1dbSAhmed Bougacha 
160486b680a3SAhmed Bougacha   llvm_unreachable("Invalid libfunc");
1605d765a82bSAhmed Bougacha }
1606d765a82bSAhmed Bougacha 
1607d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1608d21529faSDavid L. Jones                                        LibFunc &F) const {
160976ea748dSPhilip Reames   // Intrinsics don't overlap w/libcalls; if our module has a large number of
161076ea748dSPhilip Reames   // intrinsics, this ends up being an interesting compile time win since we
161176ea748dSPhilip Reames   // avoid string normalization and comparison.
161276ea748dSPhilip Reames   if (FDecl.isIntrinsic()) return false;
161376ea748dSPhilip Reames 
1614d765a82bSAhmed Bougacha   const DataLayout *DL =
1615d765a82bSAhmed Bougacha       FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1616d765a82bSAhmed Bougacha   return getLibFunc(FDecl.getName(), F) &&
1617d765a82bSAhmed Bougacha          isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1618d765a82bSAhmed Bougacha }
1619d765a82bSAhmed Bougacha 
1620c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() {
162162d4215bSChandler Carruth   memset(AvailableArray, 0, sizeof(AvailableArray));
162262d4215bSChandler Carruth }
1623b98f63dbSChandler Carruth 
1624e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
16259a72cd7bSMehdi Amini   return LHS.ScalarFnName < RHS.ScalarFnName;
1626e8f2551fSMichael Zolotukhin }
1627e8f2551fSMichael Zolotukhin 
1628e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
16299a72cd7bSMehdi Amini   return LHS.VectorFnName < RHS.VectorFnName;
1630e8f2551fSMichael Zolotukhin }
1631e8f2551fSMichael Zolotukhin 
1632e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
16339a72cd7bSMehdi Amini   return LHS.ScalarFnName < S;
1634e8f2551fSMichael Zolotukhin }
1635e8f2551fSMichael Zolotukhin 
1636ed03d948SMehdi Amini void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1637f76e83bfSKazu Hirata   llvm::append_range(VectorDescs, Fns);
16380cac726aSFangrui Song   llvm::sort(VectorDescs, compareByScalarFnName);
1639e8f2551fSMichael Zolotukhin 
1640f76e83bfSKazu Hirata   llvm::append_range(ScalarDescs, Fns);
16410cac726aSFangrui Song   llvm::sort(ScalarDescs, compareByVectorFnName);
1642e8f2551fSMichael Zolotukhin }
1643e8f2551fSMichael Zolotukhin 
16446d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1645ed03d948SMehdi Amini     enum VectorLibrary VecLib) {
16466d8a2aa9SMichael Zolotukhin   switch (VecLib) {
16476d8a2aa9SMichael Zolotukhin   case Accelerate: {
16486d8a2aa9SMichael Zolotukhin     const VecDesc VecFuncs[] = {
1649820b9031SNemanja Ivanovic     #define TLI_DEFINE_ACCELERATE_VECFUNCS
1650820b9031SNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
16516d8a2aa9SMichael Zolotukhin     };
1652ed03d948SMehdi Amini     addVectorizableFunctions(VecFuncs);
16536d8a2aa9SMichael Zolotukhin     break;
16546d8a2aa9SMichael Zolotukhin   }
165593a9a8a8SFlorian Hahn   case DarwinLibSystemM: {
165693a9a8a8SFlorian Hahn     const VecDesc VecFuncs[] = {
165793a9a8a8SFlorian Hahn     #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
165893a9a8a8SFlorian Hahn     #include "llvm/Analysis/VecFuncs.def"
165993a9a8a8SFlorian Hahn     };
166093a9a8a8SFlorian Hahn     addVectorizableFunctions(VecFuncs);
166193a9a8a8SFlorian Hahn     break;
166293a9a8a8SFlorian Hahn   }
166357cdc52cSVenkataramanan Kumar   case LIBMVEC_X86: {
166457cdc52cSVenkataramanan Kumar     const VecDesc VecFuncs[] = {
166557cdc52cSVenkataramanan Kumar     #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
166657cdc52cSVenkataramanan Kumar     #include "llvm/Analysis/VecFuncs.def"
166757cdc52cSVenkataramanan Kumar     };
166857cdc52cSVenkataramanan Kumar     addVectorizableFunctions(VecFuncs);
166957cdc52cSVenkataramanan Kumar     break;
167057cdc52cSVenkataramanan Kumar   }
1671fe97754aSNemanja Ivanovic   case MASSV: {
1672fe97754aSNemanja Ivanovic     const VecDesc VecFuncs[] = {
1673fe97754aSNemanja Ivanovic     #define TLI_DEFINE_MASSV_VECFUNCS
1674fe97754aSNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
1675fe97754aSNemanja Ivanovic     };
1676ed03d948SMehdi Amini     addVectorizableFunctions(VecFuncs);
1677fe97754aSNemanja Ivanovic     break;
1678fe97754aSNemanja Ivanovic   }
1679a6669a1eSMatt Masten   case SVML: {
1680a6669a1eSMatt Masten     const VecDesc VecFuncs[] = {
1681820b9031SNemanja Ivanovic     #define TLI_DEFINE_SVML_VECFUNCS
1682820b9031SNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
1683a6669a1eSMatt Masten     };
1684ed03d948SMehdi Amini     addVectorizableFunctions(VecFuncs);
1685a6669a1eSMatt Masten     break;
1686a6669a1eSMatt Masten   }
1687ed03d948SMehdi Amini   case NoLibrary:
16886d8a2aa9SMichael Zolotukhin     break;
16896d8a2aa9SMichael Zolotukhin   }
16906d8a2aa9SMichael Zolotukhin }
16916d8a2aa9SMichael Zolotukhin 
1692ed03d948SMehdi Amini bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1693e8f2551fSMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
1694ed03d948SMehdi Amini   if (funcName.empty())
1695e8f2551fSMichael Zolotukhin     return false;
1696e8f2551fSMichael Zolotukhin 
1697cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1698cecc4352SFangrui Song       llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1699e8f2551fSMichael Zolotukhin   return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1700e8f2551fSMichael Zolotukhin }
1701e8f2551fSMichael Zolotukhin 
170201b87444SDavid Sherwood StringRef
170301b87444SDavid Sherwood TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
170401b87444SDavid Sherwood                                              const ElementCount &VF) const {
1705e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1706ed03d948SMehdi Amini   if (F.empty())
1707e8f2551fSMichael Zolotukhin     return F;
1708cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1709cecc4352SFangrui Song       llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
1710e8f2551fSMichael Zolotukhin   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1711e8f2551fSMichael Zolotukhin     if (I->VectorizationFactor == VF)
1712e8f2551fSMichael Zolotukhin       return I->VectorFnName;
1713e8f2551fSMichael Zolotukhin     ++I;
1714e8f2551fSMichael Zolotukhin   }
1715e8f2551fSMichael Zolotukhin   return StringRef();
1716e8f2551fSMichael Zolotukhin }
1717e8f2551fSMichael Zolotukhin 
1718878ab6dfSTeresa Johnson TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
1719164a2aa6SChandler Carruth                                              FunctionAnalysisManager &) {
1720878ab6dfSTeresa Johnson   if (!BaselineInfoImpl)
1721878ab6dfSTeresa Johnson     BaselineInfoImpl =
1722878ab6dfSTeresa Johnson         TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
1723878ab6dfSTeresa Johnson   return TargetLibraryInfo(*BaselineInfoImpl, &F);
1724c0291865SChandler Carruth }
1725c0291865SChandler Carruth 
172650ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
172750ec0b5dSMatthias Braun   if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
172850ec0b5dSMatthias Braun       M.getModuleFlag("wchar_size")))
172950ec0b5dSMatthias Braun     return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1730cc603ee3SMatthias Braun   return 0;
173150ec0b5dSMatthias Braun }
1732c0291865SChandler Carruth 
1733b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1734878ab6dfSTeresa Johnson     : ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
1735b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1736b98f63dbSChandler Carruth }
1737b98f63dbSChandler Carruth 
1738b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
1739878ab6dfSTeresa Johnson     : ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) {
1740b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1741b98f63dbSChandler Carruth }
1742b98f63dbSChandler Carruth 
1743b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1744c0291865SChandler Carruth     const TargetLibraryInfoImpl &TLIImpl)
1745878ab6dfSTeresa Johnson     : ImmutablePass(ID), TLA(TLIImpl) {
1746b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1747b98f63dbSChandler Carruth }
1748b98f63dbSChandler Carruth 
1749dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key;
1750df0cd726SNAKAMURA Takumi 
1751b98f63dbSChandler Carruth // Register the basic pass.
1752b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1753b98f63dbSChandler Carruth                 "Target Library Information", false, true)
1754b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0;
1755b98f63dbSChandler Carruth 
1756b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {}
1757d6de5f12SFrancesco Petrogalli 
175801b87444SDavid Sherwood void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF,
175901b87444SDavid Sherwood                                         ElementCount &FixedVF,
176001b87444SDavid Sherwood                                         ElementCount &ScalableVF) const {
1761d6de5f12SFrancesco Petrogalli   ScalarF = sanitizeFunctionName(ScalarF);
176201b87444SDavid Sherwood   // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the
176301b87444SDavid Sherwood   // same as a scalar.
176401b87444SDavid Sherwood   ScalableVF = ElementCount::getScalable(0);
176501b87444SDavid Sherwood   FixedVF = ElementCount::getFixed(1);
1766ed03d948SMehdi Amini   if (ScalarF.empty())
176701b87444SDavid Sherwood     return;
1768d6de5f12SFrancesco Petrogalli 
1769d6de5f12SFrancesco Petrogalli   std::vector<VecDesc>::const_iterator I =
1770d6de5f12SFrancesco Petrogalli       llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
1771d6de5f12SFrancesco Petrogalli   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) {
177201b87444SDavid Sherwood     ElementCount *VF =
177301b87444SDavid Sherwood         I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF;
177401b87444SDavid Sherwood     if (ElementCount::isKnownGT(I->VectorizationFactor, *VF))
177501b87444SDavid Sherwood       *VF = I->VectorizationFactor;
1776d6de5f12SFrancesco Petrogalli     ++I;
1777d6de5f12SFrancesco Petrogalli   }
1778d6de5f12SFrancesco Petrogalli }
1779