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"),
2757cdc52cSVenkataramanan Kumar                clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86",
2857cdc52cSVenkataramanan Kumar                           "GLIBC Vector Math library"),
29fe97754aSNemanja Ivanovic                clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
30fe97754aSNemanja Ivanovic                           "IBM MASS vector library"),
31a6669a1eSMatt Masten                clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
327459398aSJoel Jones                           "Intel SVML library")));
336d8a2aa9SMichael Zolotukhin 
3470434770SBenjamin Kramer StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
3570434770SBenjamin Kramer     {
36cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING
37cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def"
3862d4215bSChandler Carruth };
3962d4215bSChandler Carruth 
4062d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) {
4162d4215bSChandler Carruth   // Only Darwin variants have _stret versions of combined trig functions.
4262d4215bSChandler Carruth   if (!T.isOSDarwin())
4362d4215bSChandler Carruth     return false;
4462d4215bSChandler Carruth 
4562d4215bSChandler Carruth   // The ABI is rather complicated on x86, so don't do anything special there.
4662d4215bSChandler Carruth   if (T.getArch() == Triple::x86)
4762d4215bSChandler Carruth     return false;
4862d4215bSChandler Carruth 
4962d4215bSChandler Carruth   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
5062d4215bSChandler Carruth     return false;
5162d4215bSChandler Carruth 
5262d4215bSChandler Carruth   if (T.isiOS() && T.isOSVersionLT(7, 0))
5362d4215bSChandler Carruth     return false;
5462d4215bSChandler Carruth 
5562d4215bSChandler Carruth   return true;
5662d4215bSChandler Carruth }
5762d4215bSChandler Carruth 
588e16d733SClement Courbet static bool hasBcmp(const Triple &TT) {
598e16d733SClement Courbet   // Posix removed support from bcmp() in 2001, but the glibc and several
608e16d733SClement Courbet   // implementations of the libc still have it.
618e16d733SClement Courbet   if (TT.isOSLinux())
628e16d733SClement Courbet     return TT.isGNUEnvironment() || TT.isMusl();
638e16d733SClement Courbet   // Both NetBSD and OpenBSD are planning to remove the function. Windows does
648e16d733SClement Courbet   // not have it.
658d5c2803SAlex Lorenz   return TT.isOSFreeBSD() || TT.isOSSolaris();
668e16d733SClement Courbet }
678e16d733SClement Courbet 
68600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified
69600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target
70600d24b4SSanjay Patel /// triple gets a sane set of defaults.
71c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
7270434770SBenjamin Kramer                        ArrayRef<StringLiteral> StandardNames) {
7362d4215bSChandler Carruth   // Verify that the StandardNames array is in alphabetical order.
741647ff6eSGeorgii Rymar   assert(
751647ff6eSGeorgii Rymar       llvm::is_sorted(StandardNames,
761647ff6eSGeorgii Rymar                       [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) &&
77e30b8ca1SCraig Topper       "TargetLibraryInfoImpl function names must be sorted");
7862d4215bSChandler Carruth 
79ca22d427SDavid Bolvansky   // Set IO unlocked variants as unavailable
80ca22d427SDavid Bolvansky   // Set them as available per system below
81ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_getchar_unlocked);
82ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_putc_unlocked);
83ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_putchar_unlocked);
84ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fputc_unlocked);
85ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fgetc_unlocked);
86ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fread_unlocked);
87ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fwrite_unlocked);
88ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fputs_unlocked);
89ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fgets_unlocked);
90ca22d427SDavid Bolvansky 
916af8e6c3SMarcin Koscielnicki   bool ShouldExtI32Param = false, ShouldExtI32Return = false,
926af8e6c3SMarcin Koscielnicki        ShouldSignExtI32Param = false;
936af8e6c3SMarcin Koscielnicki   // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
946af8e6c3SMarcin Koscielnicki   // returns corresponding to C-level ints and unsigned ints.
953e92df3eSFangrui Song   if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
963e92df3eSFangrui Song       T.getArch() == Triple::systemz) {
976af8e6c3SMarcin Koscielnicki     ShouldExtI32Param = true;
986af8e6c3SMarcin Koscielnicki     ShouldExtI32Return = true;
996af8e6c3SMarcin Koscielnicki   }
1006af8e6c3SMarcin Koscielnicki   // Mips, on the other hand, needs signext on i32 parameters corresponding
1016af8e6c3SMarcin Koscielnicki   // to both signed and unsigned ints.
10285e200e9SAlexander Richardson   if (T.isMIPS()) {
1036af8e6c3SMarcin Koscielnicki     ShouldSignExtI32Param = true;
1046af8e6c3SMarcin Koscielnicki   }
1056af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Param(ShouldExtI32Param);
1066af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Return(ShouldExtI32Return);
1076af8e6c3SMarcin Koscielnicki   TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
1086af8e6c3SMarcin Koscielnicki 
109314deab9SYaxun (Sam) Liu   if (T.isAMDGPU())
110c26b3940STim Renouf     TLI.disableAllFunctions();
11178fd4f08SNicolai Hahnle 
112ef72cdedSDavid Bolvansky   // There are no library implementations of memcpy and memset for AMD gpus and
11362d4215bSChandler Carruth   // these can be difficult to lower in the backend.
114314deab9SYaxun (Sam) Liu   if (T.isAMDGPU()) {
115d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memcpy);
116d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset);
117d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
11862d4215bSChandler Carruth     return;
11962d4215bSChandler Carruth   }
12062d4215bSChandler Carruth 
12162d4215bSChandler Carruth   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
1228b40366bSTim Northover   // All versions of watchOS support it.
12362d4215bSChandler Carruth   if (T.isMacOSX()) {
124ca22d427SDavid Bolvansky     // available IO unlocked variants on Mac OS X
125ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getc_unlocked);
126ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getchar_unlocked);
127ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putc_unlocked);
128ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putchar_unlocked);
129ca22d427SDavid Bolvansky 
13062d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 5))
131d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
13262d4215bSChandler Carruth   } else if (T.isiOS()) {
13362d4215bSChandler Carruth     if (T.isOSVersionLT(3, 0))
134d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
1358b40366bSTim Northover   } else if (!T.isWatchOS()) {
136d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
13762d4215bSChandler Carruth   }
13862d4215bSChandler Carruth 
13962d4215bSChandler Carruth   if (!hasSinCosPiStret(T)) {
140d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpi);
141d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpif);
142d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospi);
143d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospif);
144d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospi_stret);
145d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospif_stret);
14662d4215bSChandler Carruth   }
14762d4215bSChandler Carruth 
1488e16d733SClement Courbet   if (!hasBcmp(T))
1498e16d733SClement Courbet     TLI.setUnavailable(LibFunc_bcmp);
1508e16d733SClement Courbet 
15162d4215bSChandler Carruth   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
15262d4215bSChandler Carruth       !T.isMacOSXVersionLT(10, 7)) {
15362d4215bSChandler Carruth     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
15462d4215bSChandler Carruth     // we don't care about) have two versions; on recent OSX, the one we want
15562d4215bSChandler Carruth     // has a $UNIX2003 suffix. The two implementations are identical except
15662d4215bSChandler Carruth     // for the return value in some edge cases.  However, we don't want to
15762d4215bSChandler Carruth     // generate code that depends on the old symbols.
158d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
159d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
16062d4215bSChandler Carruth   }
16162d4215bSChandler Carruth 
162b4f9991fSAlon Zakai   // iprintf and friends are only available on XCore, TCE, and Emscripten.
163b4f9991fSAlon Zakai   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
164b4f9991fSAlon Zakai       T.getOS() != Triple::Emscripten) {
165d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_iprintf);
166d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_siprintf);
167d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fiprintf);
16862d4215bSChandler Carruth   }
16962d4215bSChandler Carruth 
170b4f9991fSAlon Zakai   // __small_printf and friends are only available on Emscripten.
171b4f9991fSAlon Zakai   if (T.getOS() != Triple::Emscripten) {
172b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_printf);
173b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_sprintf);
174b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_fprintf);
175b4f9991fSAlon Zakai   }
176b4f9991fSAlon Zakai 
17762d4215bSChandler Carruth   if (T.isOSWindows() && !T.isOSCygMing()) {
1784b86c474SEvandro Menezes     // XXX: The earliest documentation available at the moment is for VS2015/VC19:
1794b86c474SEvandro Menezes     // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
1804b86c474SEvandro Menezes     // XXX: In order to use an MSVCRT older than VC19,
1814b86c474SEvandro Menezes     // the specific library version must be explicit in the target triple,
1824b86c474SEvandro Menezes     // e.g., x86_64-pc-windows-msvc18.
1834b86c474SEvandro Menezes     bool hasPartialC99 = true;
1844b86c474SEvandro Menezes     if (T.isKnownWindowsMSVCEnvironment()) {
1854b86c474SEvandro Menezes       unsigned Major, Minor, Micro;
1864b86c474SEvandro Menezes       T.getEnvironmentVersion(Major, Minor, Micro);
1874b86c474SEvandro Menezes       hasPartialC99 = (Major == 0 || Major >= 19);
1884b86c474SEvandro Menezes     }
1894b86c474SEvandro Menezes 
190f4a36959SEvandro Menezes     // Latest targets support C89 math functions, in part.
191f4a36959SEvandro Menezes     bool isARM = (T.getArch() == Triple::aarch64 ||
192f4a36959SEvandro Menezes                   T.getArch() == Triple::arm);
193f4a36959SEvandro Menezes     bool hasPartialFloat = (isARM ||
1944b86c474SEvandro Menezes                             T.getArch() == Triple::x86_64);
1954b86c474SEvandro Menezes 
196f4a36959SEvandro Menezes     // Win32 does not support float C89 math functions, in general.
1974b86c474SEvandro Menezes     if (!hasPartialFloat) {
198e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_acosf);
199e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_asinf);
200e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_atan2f);
201f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_atanf);
202e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_ceilf);
203e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_cosf);
204e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_coshf);
205e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_expf);
206e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_floorf);
207e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_fmodf);
208e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_log10f);
209f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_logf);
210e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_modff);
211e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_powf);
2122470d298SEhud Katz       TLI.setUnavailable(LibFunc_remainderf);
213e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sinf);
214e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sinhf);
215e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sqrtf);
216e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_tanf);
217e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_tanhf);
218e5bb58b1SEvandro Menezes     }
219f4a36959SEvandro Menezes     if (!isARM)
2204b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_fabsf);
221e5bb58b1SEvandro Menezes     TLI.setUnavailable(LibFunc_frexpf);
222e5bb58b1SEvandro Menezes     TLI.setUnavailable(LibFunc_ldexpf);
223e5bb58b1SEvandro Menezes 
224f4a36959SEvandro Menezes     // Win32 does not support long double C89 math functions.
22598f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_acosl);
22698f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_asinl);
22798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_atan2l);
228f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_atanl);
22998f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_ceill);
23098f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_cosl);
23198f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_coshl);
23298f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_expl);
23398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_fabsl);
23498f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_floorl);
23598f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_fmodl);
23698f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_frexpl);
23798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_ldexpl);
2384b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log10l);
239f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_logl);
24098f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_modfl);
24198f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_powl);
2422470d298SEhud Katz     TLI.setUnavailable(LibFunc_remainderl);
24398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sinl);
24498f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sinhl);
24598f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sqrtl);
24698f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_tanl);
24798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_tanhl);
24862d4215bSChandler Carruth 
249e5bb58b1SEvandro Menezes     // Win32 does not fully support C99 math functions.
2504b86c474SEvandro Menezes     if (!hasPartialC99) {
25198f356cdSEvandro Menezes       TLI.setUnavailable(LibFunc_acosh);
2524b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_acoshf);
253f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_asinh);
2544b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_asinhf);
255f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_atanh);
2564b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_atanhf);
257f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
2584b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_cabsf);
259f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_cbrt);
2604b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_cbrtf);
261f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
262f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
263f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_exp2);
2644b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_exp2f);
265f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_expm1);
2664b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_expm1f);
267f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmax);
268f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmaxf);
269f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmin);
270f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fminf);
271f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_log1p);
2724b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_log1pf);
273f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_log2);
2744b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_log2f);
275f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_logb, "_logb");
276f4a36959SEvandro Menezes       if (hasPartialFloat)
277f4a36959SEvandro Menezes         TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
278f4a36959SEvandro Menezes       else
2794b86c474SEvandro Menezes         TLI.setUnavailable(LibFunc_logbf);
280f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_rint);
2814b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_rintf);
282f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_round);
2834b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_roundf);
284f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_trunc);
28598f356cdSEvandro Menezes       TLI.setUnavailable(LibFunc_truncf);
286f4a36959SEvandro Menezes     }
2874b86c474SEvandro Menezes 
2884b86c474SEvandro Menezes     // Win32 does not support long double C99 math functions.
2894b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_acoshl);
2904b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_asinhl);
2914b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_atanhl);
2924b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_cabsl);
2934b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_cbrtl);
294f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_copysignl);
2954b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_exp2l);
2964b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_expm1l);
297f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_fmaxl);
298f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_fminl);
2994b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log1pl);
3004b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log2l);
3014b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_logbl);
3024b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_nearbyintl);
3034b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_rintl);
3044b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_roundl);
30598f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_truncl);
30698f356cdSEvandro Menezes 
307e5bb58b1SEvandro Menezes     // Win32 does not support these functions, but
308e5bb58b1SEvandro Menezes     // they are generally available on POSIX-compliant systems.
309d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_access);
310d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcmp);
311d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcopy);
312d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bzero);
313d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chmod);
314d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chown);
315d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_closedir);
316d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ctermid);
317d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fdopen);
318d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffs);
319d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fileno);
320d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flockfile);
321d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko);
322d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat);
323d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs);
324d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello);
325d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftrylockfile);
326d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_funlockfile);
327d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getitimer);
328d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getlogin_r);
329d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getpwnam);
330d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_gettimeofday);
331d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htonl);
332d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htons);
333d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lchown);
334d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat);
335d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memccpy);
336d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_mkdir);
337d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohl);
338d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohs);
339d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open);
340d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_opendir);
341d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pclose);
342d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_popen);
343d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pread);
344d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pwrite);
345d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_read);
346d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_readlink);
347d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_realpath);
348d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_rmdir);
349d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_setitimer);
350d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat);
351d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs);
352d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpcpy);
353d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpncpy);
354d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_strcasecmp);
355d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_strncasecmp);
356d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_times);
357d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_uname);
358d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unlink);
359d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unsetenv);
360d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utime);
361d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utimes);
362d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_write);
36362d4215bSChandler Carruth   }
36462d4215bSChandler Carruth 
36562d4215bSChandler Carruth   switch (T.getOS()) {
36662d4215bSChandler Carruth   case Triple::MacOSX:
36762d4215bSChandler Carruth     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
36862d4215bSChandler Carruth     // and their names are __exp10 and __exp10f. exp10l is not available on
36962d4215bSChandler Carruth     // OS X or iOS.
370d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
37162d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 9)) {
372d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
373d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
37462d4215bSChandler Carruth     } else {
375d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
376d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
37762d4215bSChandler Carruth     }
37862d4215bSChandler Carruth     break;
37962d4215bSChandler Carruth   case Triple::IOS:
38089a6eefeSTim Northover   case Triple::TvOS:
3818b40366bSTim Northover   case Triple::WatchOS:
382d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
383ab1bcda8SJim Lin     if (!T.isWatchOS() &&
384ab1bcda8SJim Lin         (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
385d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
386d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
38762d4215bSChandler Carruth     } else {
388d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
389d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
39062d4215bSChandler Carruth     }
39162d4215bSChandler Carruth     break;
39262d4215bSChandler Carruth   case Triple::Linux:
39362d4215bSChandler Carruth     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
39462d4215bSChandler Carruth     // buggy prior to glibc version 2.18. Until this version is widely deployed
39562d4215bSChandler Carruth     // or we have a reasonable detection strategy, we cannot use exp10 reliably
39662d4215bSChandler Carruth     // on Linux.
39762d4215bSChandler Carruth     //
39862d4215bSChandler Carruth     // Fall through to disable all of them.
399cd1d5aafSJustin Bogner     LLVM_FALLTHROUGH;
40062d4215bSChandler Carruth   default:
401d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10);
402d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10f);
403d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
40462d4215bSChandler Carruth   }
40562d4215bSChandler Carruth 
40662d4215bSChandler Carruth   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
40762d4215bSChandler Carruth   // Linux (GLIBC):
40862d4215bSChandler Carruth   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
40983b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
41062d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
41162d4215bSChandler Carruth   switch (T.getOS()) {
41262d4215bSChandler Carruth   case Triple::Darwin:
41362d4215bSChandler Carruth   case Triple::MacOSX:
41462d4215bSChandler Carruth   case Triple::IOS:
41589a6eefeSTim Northover   case Triple::TvOS:
4168b40366bSTim Northover   case Triple::WatchOS:
41762d4215bSChandler Carruth   case Triple::FreeBSD:
41862d4215bSChandler Carruth   case Triple::Linux:
41962d4215bSChandler Carruth     break;
42062d4215bSChandler Carruth   default:
421d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsl);
42262d4215bSChandler Carruth   }
42362d4215bSChandler Carruth 
42462d4215bSChandler Carruth   // ffsll is available on at least FreeBSD and Linux (GLIBC):
42583b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
42662d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
42762d4215bSChandler Carruth   switch (T.getOS()) {
42889a6eefeSTim Northover   case Triple::Darwin:
42989a6eefeSTim Northover   case Triple::MacOSX:
43089a6eefeSTim Northover   case Triple::IOS:
43189a6eefeSTim Northover   case Triple::TvOS:
43289a6eefeSTim Northover   case Triple::WatchOS:
43362d4215bSChandler Carruth   case Triple::FreeBSD:
43462d4215bSChandler Carruth   case Triple::Linux:
43562d4215bSChandler Carruth     break;
43662d4215bSChandler Carruth   default:
437d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsll);
43862d4215bSChandler Carruth   }
43962d4215bSChandler Carruth 
440bfd3082eSDavide Italiano   // The following functions are available on at least FreeBSD:
441bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
442bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
443bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
444bfd3082eSDavide Italiano   if (!T.isOSFreeBSD()) {
445d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fls);
446d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsl);
447d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsll);
448bfd3082eSDavide Italiano   }
449bfd3082eSDavide Italiano 
450e3a5fc6dSEli Friedman   // The following functions are only available on GNU/Linux (using glibc).
451e3a5fc6dSEli Friedman   // Linux variants without glibc (eg: bionic, musl) may have some subset.
452e3a5fc6dSEli Friedman   if (!T.isOSLinux() || !T.isGNUEnvironment()) {
453d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strdup);
454d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strtok_r);
455d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
456d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
457d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_getc);
458d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_putc);
459e3a5fc6dSEli Friedman     // But, Android and musl have memalign.
460e3a5fc6dSEli Friedman     if (!T.isAndroid() && !T.isMusl())
461d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memalign);
462d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fopen64);
463d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko64);
464d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat64);
465d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs64);
466d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello64);
467d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat64);
468d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open64);
469d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat64);
470d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs64);
471d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_tmpfile64);
47252149f03SSanjay Patel 
47352149f03SSanjay Patel     // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
4746d15c4deSserge-sans-paille     // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
4756d15c4deSserge-sans-paille     // so we keep these functions around just so that they're recognized by
4766d15c4deSserge-sans-paille     // the ConstantFolder.
47752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acos_finite);
47852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosf_finite);
47952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosl_finite);
48052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosh_finite);
48152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshf_finite);
48252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshl_finite);
48352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asin_finite);
48452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinf_finite);
48552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinl_finite);
48652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2_finite);
48752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2f_finite);
48852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2l_finite);
48952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanh_finite);
49052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhf_finite);
49152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhl_finite);
49252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_cosh_finite);
49352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshf_finite);
49452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshl_finite);
49552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10_finite);
49652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10f_finite);
49752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10l_finite);
49852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2_finite);
49952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2f_finite);
50052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2l_finite);
50152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp_finite);
50252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expf_finite);
50352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expl_finite);
50452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10_finite);
50552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10f_finite);
50652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10l_finite);
50752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2_finite);
50852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2f_finite);
50952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2l_finite);
51052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log_finite);
51152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logf_finite);
51252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logl_finite);
51352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_pow_finite);
51452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powf_finite);
51552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powl_finite);
51652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinh_finite);
51752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhf_finite);
51852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhl_finite);
51962d4215bSChandler Carruth   }
5206d8a2aa9SMichael Zolotukhin 
521c1078872SMartin Storsjo   if ((T.isOSLinux() && T.isGNUEnvironment()) ||
522c1078872SMartin Storsjo       (T.isAndroid() && !T.isAndroidVersionLT(28))) {
523ca22d427SDavid Bolvansky     // available IO unlocked variants on GNU/Linux and Android P or later
524ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getc_unlocked);
525ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getchar_unlocked);
526ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putc_unlocked);
527ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putchar_unlocked);
528ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fputc_unlocked);
529ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fgetc_unlocked);
530ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fread_unlocked);
531ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fwrite_unlocked);
532ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fputs_unlocked);
533ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fgets_unlocked);
534ca22d427SDavid Bolvansky   }
535ca22d427SDavid Bolvansky 
53651132881SJustin Lebar   // As currently implemented in clang, NVPTX code has no standard library to
53751132881SJustin Lebar   // speak of.  Headers provide a standard-ish library implementation, but many
53851132881SJustin Lebar   // of the signatures are wrong -- for example, many libm functions are not
53951132881SJustin Lebar   // extern "C".
54051132881SJustin Lebar   //
54151132881SJustin Lebar   // libdevice, an IR library provided by nvidia, is linked in by the front-end,
54251132881SJustin Lebar   // but only used functions are provided to llvm.  Moreover, most of the
54351132881SJustin Lebar   // functions in libdevice don't map precisely to standard library functions.
54451132881SJustin Lebar   //
54551132881SJustin Lebar   // FIXME: Having no standard library prevents e.g. many fastmath
54651132881SJustin Lebar   // optimizations, so this situation should be fixed.
547ae272d71SDavid Majnemer   if (T.isNVPTX()) {
54851132881SJustin Lebar     TLI.disableAllFunctions();
549d21529faSDavid L. Jones     TLI.setAvailable(LibFunc_nvvm_reflect);
550ae272d71SDavid Majnemer   } else {
551d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nvvm_reflect);
552ae272d71SDavid Majnemer   }
55351132881SJustin Lebar 
554ed03d948SMehdi Amini   TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
55562d4215bSChandler Carruth }
55662d4215bSChandler Carruth 
557c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
55862d4215bSChandler Carruth   // Default to everything being available.
55962d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
56062d4215bSChandler Carruth 
56162d4215bSChandler Carruth   initialize(*this, Triple(), StandardNames);
56262d4215bSChandler Carruth }
56362d4215bSChandler Carruth 
5647459398aSJoel Jones TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
56562d4215bSChandler Carruth   // Default to everything being available.
56662d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
56762d4215bSChandler Carruth 
56862d4215bSChandler Carruth   initialize(*this, T, StandardNames);
56962d4215bSChandler Carruth }
57062d4215bSChandler Carruth 
571c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
5727459398aSJoel Jones     : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
5735ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
5745ae2c526SMarcin Koscielnicki       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
57562d4215bSChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
576ed03d948SMehdi Amini   VectorDescs = TLI.VectorDescs;
577ed03d948SMehdi Amini   ScalarDescs = TLI.ScalarDescs;
5788ca43224SChandler Carruth }
5798ca43224SChandler Carruth 
580c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
5817459398aSJoel Jones     : CustomNames(std::move(TLI.CustomNames)),
5825ae2c526SMarcin Koscielnicki       ShouldExtI32Param(TLI.ShouldExtI32Param),
5835ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
5845ae2c526SMarcin Koscielnicki       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
5858ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
5868ca43224SChandler Carruth             AvailableArray);
587ed03d948SMehdi Amini   VectorDescs = TLI.VectorDescs;
588ed03d948SMehdi Amini   ScalarDescs = TLI.ScalarDescs;
5898ca43224SChandler Carruth }
5908ca43224SChandler Carruth 
591c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
59262d4215bSChandler Carruth   CustomNames = TLI.CustomNames;
5935ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
5945ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
5955ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
5968ca43224SChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
5978ca43224SChandler Carruth   return *this;
5988ca43224SChandler Carruth }
5998ca43224SChandler Carruth 
600c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
6018ca43224SChandler Carruth   CustomNames = std::move(TLI.CustomNames);
6025ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
6035ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
6045ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
6058ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
6068ca43224SChandler Carruth             AvailableArray);
6078ca43224SChandler Carruth   return *this;
60862d4215bSChandler Carruth }
60962d4215bSChandler Carruth 
61021abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) {
61162d4215bSChandler Carruth   // Filter out empty names and names containing null bytes, those can't be in
61262d4215bSChandler Carruth   // our table.
61362d4215bSChandler Carruth   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
61421abdf98SMichael Zolotukhin     return StringRef();
61562d4215bSChandler Carruth 
61662d4215bSChandler Carruth   // Check for \01 prefix that is used to mangle __asm declarations and
61762d4215bSChandler Carruth   // strip it if present.
6186f0ecca3SPeter Collingbourne   return GlobalValue::dropLLVMManglingEscape(funcName);
61921abdf98SMichael Zolotukhin }
62021abdf98SMichael Zolotukhin 
621d5e60669SBenjamin Kramer bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const {
62221abdf98SMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
62321abdf98SMichael Zolotukhin   if (funcName.empty())
62421abdf98SMichael Zolotukhin     return false;
62521abdf98SMichael Zolotukhin 
626d5e60669SBenjamin Kramer   const auto *Start = std::begin(StandardNames);
627d5e60669SBenjamin Kramer   const auto *End = std::end(StandardNames);
628d5e60669SBenjamin Kramer   const auto *I = std::lower_bound(Start, End, funcName);
62962d4215bSChandler Carruth   if (I != End && *I == funcName) {
630d21529faSDavid L. Jones     F = (LibFunc)(I - Start);
63162d4215bSChandler Carruth     return true;
63262d4215bSChandler Carruth   }
63362d4215bSChandler Carruth   return false;
63462d4215bSChandler Carruth }
63562d4215bSChandler Carruth 
636d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
637d21529faSDavid L. Jones                                                    LibFunc F,
638d765a82bSAhmed Bougacha                                                    const DataLayout *DL) const {
639d765a82bSAhmed Bougacha   LLVMContext &Ctx = FTy.getContext();
640d765a82bSAhmed Bougacha   Type *PCharTy = Type::getInt8PtrTy(Ctx);
6416913812aSFangrui Song   Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AddressSpace=*/0) : nullptr;
642d765a82bSAhmed Bougacha   auto IsSizeTTy = [SizeTTy](Type *Ty) {
643d765a82bSAhmed Bougacha     return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
644d765a82bSAhmed Bougacha   };
645d765a82bSAhmed Bougacha   unsigned NumParams = FTy.getNumParams();
646d765a82bSAhmed Bougacha 
647d765a82bSAhmed Bougacha   switch (F) {
648c3bed1e8SCalixte Denizet   case LibFunc_execl:
649c3bed1e8SCalixte Denizet   case LibFunc_execlp:
6508f07efc7SCalixte Denizet   case LibFunc_execle:
651c3bed1e8SCalixte Denizet     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
652c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
653c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
654c3bed1e8SCalixte Denizet   case LibFunc_execv:
655c3bed1e8SCalixte Denizet   case LibFunc_execvp:
656c3bed1e8SCalixte Denizet     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
657c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
658c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
659c3bed1e8SCalixte Denizet   case LibFunc_execvP:
660c3bed1e8SCalixte Denizet   case LibFunc_execvpe:
661c3bed1e8SCalixte Denizet   case LibFunc_execve:
662c3bed1e8SCalixte Denizet     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
663c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
664c3bed1e8SCalixte Denizet             FTy.getParamType(2)->isPointerTy() &&
665c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
666f8c9ceb1SGeorge Burgess IV   case LibFunc_strlen_chk:
667f8c9ceb1SGeorge Burgess IV     --NumParams;
668f8c9ceb1SGeorge Burgess IV     if (!IsSizeTTy(FTy.getParamType(NumParams)))
669f8c9ceb1SGeorge Burgess IV       return false;
670f8c9ceb1SGeorge Burgess IV     LLVM_FALLTHROUGH;
671d21529faSDavid L. Jones   case LibFunc_strlen:
672d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
673d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
674d765a82bSAhmed Bougacha 
675d21529faSDavid L. Jones   case LibFunc_strchr:
676d21529faSDavid L. Jones   case LibFunc_strrchr:
677d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
678d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
679d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy());
680d765a82bSAhmed Bougacha 
681d21529faSDavid L. Jones   case LibFunc_strtol:
682d21529faSDavid L. Jones   case LibFunc_strtod:
683d21529faSDavid L. Jones   case LibFunc_strtof:
684d21529faSDavid L. Jones   case LibFunc_strtoul:
685d21529faSDavid L. Jones   case LibFunc_strtoll:
686d21529faSDavid L. Jones   case LibFunc_strtold:
687d21529faSDavid L. Jones   case LibFunc_strtoull:
688d765a82bSAhmed Bougacha     return ((NumParams == 2 || NumParams == 3) &&
689d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
690d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
691abb2a93cSErik Pilkington   case LibFunc_strcat_chk:
692abb2a93cSErik Pilkington     --NumParams;
693abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
694abb2a93cSErik Pilkington       return false;
695abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
696d21529faSDavid L. Jones   case LibFunc_strcat:
697d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
698d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
699d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType());
700d765a82bSAhmed Bougacha 
701abb2a93cSErik Pilkington   case LibFunc_strncat_chk:
702abb2a93cSErik Pilkington     --NumParams;
703abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
704abb2a93cSErik Pilkington       return false;
705abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
706d21529faSDavid L. Jones   case LibFunc_strncat:
707d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
708d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
709d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType() &&
7107bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
711d765a82bSAhmed Bougacha 
712d21529faSDavid L. Jones   case LibFunc_strcpy_chk:
713d21529faSDavid L. Jones   case LibFunc_stpcpy_chk:
714d765a82bSAhmed Bougacha     --NumParams;
715d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
716d765a82bSAhmed Bougacha       return false;
717b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
718d21529faSDavid L. Jones   case LibFunc_strcpy:
719d21529faSDavid L. Jones   case LibFunc_stpcpy:
720d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
721d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
722d765a82bSAhmed Bougacha             FTy.getParamType(0) == PCharTy);
723d765a82bSAhmed Bougacha 
724abb2a93cSErik Pilkington   case LibFunc_strlcat_chk:
725abb2a93cSErik Pilkington   case LibFunc_strlcpy_chk:
726abb2a93cSErik Pilkington     --NumParams;
727abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
728abb2a93cSErik Pilkington       return false;
729abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
730abb2a93cSErik Pilkington   case LibFunc_strlcat:
731abb2a93cSErik Pilkington   case LibFunc_strlcpy:
732abb2a93cSErik Pilkington     return NumParams == 3 && IsSizeTTy(FTy.getReturnType()) &&
733abb2a93cSErik Pilkington            FTy.getParamType(0)->isPointerTy() &&
734abb2a93cSErik Pilkington            FTy.getParamType(1)->isPointerTy() &&
735abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2));
736abb2a93cSErik Pilkington 
737d21529faSDavid L. Jones   case LibFunc_strncpy_chk:
738d21529faSDavid L. Jones   case LibFunc_stpncpy_chk:
739d765a82bSAhmed Bougacha     --NumParams;
740d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
741d765a82bSAhmed Bougacha       return false;
742b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
743d21529faSDavid L. Jones   case LibFunc_strncpy:
744d21529faSDavid L. Jones   case LibFunc_stpncpy:
745d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
746d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
747d765a82bSAhmed Bougacha             FTy.getParamType(0) == PCharTy &&
7487bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
749d765a82bSAhmed Bougacha 
750d21529faSDavid L. Jones   case LibFunc_strxfrm:
751d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
752d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
753d765a82bSAhmed Bougacha 
754d21529faSDavid L. Jones   case LibFunc_strcmp:
755d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
756d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
757d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
758d765a82bSAhmed Bougacha 
759d21529faSDavid L. Jones   case LibFunc_strncmp:
760d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
761d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
762d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
7637bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
764d765a82bSAhmed Bougacha 
765d21529faSDavid L. Jones   case LibFunc_strspn:
766d21529faSDavid L. Jones   case LibFunc_strcspn:
767d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
768d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
769d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
770d765a82bSAhmed Bougacha 
771d21529faSDavid L. Jones   case LibFunc_strcoll:
772d21529faSDavid L. Jones   case LibFunc_strcasecmp:
773d21529faSDavid L. Jones   case LibFunc_strncasecmp:
774d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
775d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
776d765a82bSAhmed Bougacha 
777d21529faSDavid L. Jones   case LibFunc_strstr:
778d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
779d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
780d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
781d765a82bSAhmed Bougacha 
782d21529faSDavid L. Jones   case LibFunc_strpbrk:
783d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
784d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
785d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
786d765a82bSAhmed Bougacha 
787d21529faSDavid L. Jones   case LibFunc_strtok:
788d21529faSDavid L. Jones   case LibFunc_strtok_r:
789d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
790d21529faSDavid L. Jones   case LibFunc_scanf:
791d21529faSDavid L. Jones   case LibFunc_setbuf:
792d21529faSDavid L. Jones   case LibFunc_setvbuf:
793d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
794d21529faSDavid L. Jones   case LibFunc_strdup:
795d21529faSDavid L. Jones   case LibFunc_strndup:
796d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
797d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
798d21529faSDavid L. Jones   case LibFunc_sscanf:
799d21529faSDavid L. Jones   case LibFunc_stat:
800d21529faSDavid L. Jones   case LibFunc_statvfs:
801d21529faSDavid L. Jones   case LibFunc_siprintf:
802b4f9991fSAlon Zakai   case LibFunc_small_sprintf:
803d21529faSDavid L. Jones   case LibFunc_sprintf:
804d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
8050d7c3775SMartin Storsjo             FTy.getParamType(1)->isPointerTy() &&
8060d7c3775SMartin Storsjo             FTy.getReturnType()->isIntegerTy(32));
807abb2a93cSErik Pilkington 
808abb2a93cSErik Pilkington   case LibFunc_sprintf_chk:
809abb2a93cSErik Pilkington     return NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
810abb2a93cSErik Pilkington            FTy.getParamType(1)->isIntegerTy(32) &&
811abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2)) &&
812abb2a93cSErik Pilkington            FTy.getParamType(3)->isPointerTy() &&
813abb2a93cSErik Pilkington            FTy.getReturnType()->isIntegerTy(32);
814abb2a93cSErik Pilkington 
815d21529faSDavid L. Jones   case LibFunc_snprintf:
816d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
8170d7c3775SMartin Storsjo             FTy.getParamType(2)->isPointerTy() &&
8180d7c3775SMartin Storsjo             FTy.getReturnType()->isIntegerTy(32));
819abb2a93cSErik Pilkington 
820abb2a93cSErik Pilkington   case LibFunc_snprintf_chk:
821abb2a93cSErik Pilkington     return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
822abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(1)) &&
823abb2a93cSErik Pilkington            FTy.getParamType(2)->isIntegerTy(32) &&
824abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(3)) &&
825abb2a93cSErik Pilkington            FTy.getParamType(4)->isPointerTy() &&
826abb2a93cSErik Pilkington            FTy.getReturnType()->isIntegerTy(32);
827abb2a93cSErik Pilkington 
828d21529faSDavid L. Jones   case LibFunc_setitimer:
829d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
830d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
831d21529faSDavid L. Jones   case LibFunc_system:
832d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
833d21529faSDavid L. Jones   case LibFunc_malloc:
834d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
835d21529faSDavid L. Jones   case LibFunc_memcmp:
8366b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
8376b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
8386b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
839d765a82bSAhmed Bougacha 
840d21529faSDavid L. Jones   case LibFunc_memchr:
841d21529faSDavid L. Jones   case LibFunc_memrchr:
8426b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
8436b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
844d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32) &&
8456b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
846d21529faSDavid L. Jones   case LibFunc_modf:
847d21529faSDavid L. Jones   case LibFunc_modff:
848d21529faSDavid L. Jones   case LibFunc_modfl:
849d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
850d765a82bSAhmed Bougacha 
851d21529faSDavid L. Jones   case LibFunc_memcpy_chk:
85286429c4eSDávid Bolvanský   case LibFunc_mempcpy_chk:
853d21529faSDavid L. Jones   case LibFunc_memmove_chk:
854d765a82bSAhmed Bougacha     --NumParams;
855d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
856d765a82bSAhmed Bougacha       return false;
857b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
858d21529faSDavid L. Jones   case LibFunc_memcpy:
859d21529faSDavid L. Jones   case LibFunc_mempcpy:
860d21529faSDavid L. Jones   case LibFunc_memmove:
861d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
862d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
863d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
864d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
865d765a82bSAhmed Bougacha 
866d21529faSDavid L. Jones   case LibFunc_memset_chk:
867d765a82bSAhmed Bougacha     --NumParams;
868d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
869d765a82bSAhmed Bougacha       return false;
870b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
871d21529faSDavid L. Jones   case LibFunc_memset:
872d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
873d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
874d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
875d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
876d765a82bSAhmed Bougacha 
877abb2a93cSErik Pilkington   case LibFunc_memccpy_chk:
878abb2a93cSErik Pilkington       --NumParams;
879abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
880abb2a93cSErik Pilkington       return false;
881abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
882d21529faSDavid L. Jones   case LibFunc_memccpy:
883d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
884d21529faSDavid L. Jones   case LibFunc_memalign:
885d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
886d21529faSDavid L. Jones   case LibFunc_realloc:
887d21529faSDavid L. Jones   case LibFunc_reallocf:
8886b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
8896b9be1dbSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
8906b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(1)));
891d21529faSDavid L. Jones   case LibFunc_read:
892d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
893d21529faSDavid L. Jones   case LibFunc_rewind:
894d21529faSDavid L. Jones   case LibFunc_rmdir:
895d21529faSDavid L. Jones   case LibFunc_remove:
896d21529faSDavid L. Jones   case LibFunc_realpath:
897d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
898d21529faSDavid L. Jones   case LibFunc_rename:
899d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
900d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
901d21529faSDavid L. Jones   case LibFunc_readlink:
902d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
903d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
904d21529faSDavid L. Jones   case LibFunc_write:
905d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
906c0955edfSUday Bondhugula   case LibFunc_aligned_alloc:
907c0955edfSUday Bondhugula     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
908d21529faSDavid L. Jones   case LibFunc_bcopy:
909d21529faSDavid L. Jones   case LibFunc_bcmp:
910d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
911d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
912d21529faSDavid L. Jones   case LibFunc_bzero:
913d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
914d21529faSDavid L. Jones   case LibFunc_calloc:
915d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
9161fe3f1caSAhmed Bougacha 
917d21529faSDavid L. Jones   case LibFunc_atof:
918d21529faSDavid L. Jones   case LibFunc_atoi:
919d21529faSDavid L. Jones   case LibFunc_atol:
920d21529faSDavid L. Jones   case LibFunc_atoll:
921d21529faSDavid L. Jones   case LibFunc_ferror:
922d21529faSDavid L. Jones   case LibFunc_getenv:
923d21529faSDavid L. Jones   case LibFunc_getpwnam:
924d21529faSDavid L. Jones   case LibFunc_iprintf:
925b4f9991fSAlon Zakai   case LibFunc_small_printf:
926d21529faSDavid L. Jones   case LibFunc_pclose:
927d21529faSDavid L. Jones   case LibFunc_perror:
928d21529faSDavid L. Jones   case LibFunc_printf:
929d21529faSDavid L. Jones   case LibFunc_puts:
930d21529faSDavid L. Jones   case LibFunc_uname:
931d21529faSDavid L. Jones   case LibFunc_under_IO_getc:
932d21529faSDavid L. Jones   case LibFunc_unlink:
933d21529faSDavid L. Jones   case LibFunc_unsetenv:
934d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
9351fe3f1caSAhmed Bougacha 
936d21529faSDavid L. Jones   case LibFunc_access:
937d21529faSDavid L. Jones   case LibFunc_chmod:
938d21529faSDavid L. Jones   case LibFunc_chown:
939d21529faSDavid L. Jones   case LibFunc_clearerr:
940d21529faSDavid L. Jones   case LibFunc_closedir:
941d21529faSDavid L. Jones   case LibFunc_ctermid:
942d21529faSDavid L. Jones   case LibFunc_fclose:
943d21529faSDavid L. Jones   case LibFunc_feof:
944d21529faSDavid L. Jones   case LibFunc_fflush:
945d21529faSDavid L. Jones   case LibFunc_fgetc:
946ca22d427SDavid Bolvansky   case LibFunc_fgetc_unlocked:
947d21529faSDavid L. Jones   case LibFunc_fileno:
948d21529faSDavid L. Jones   case LibFunc_flockfile:
949d21529faSDavid L. Jones   case LibFunc_free:
950d21529faSDavid L. Jones   case LibFunc_fseek:
951d21529faSDavid L. Jones   case LibFunc_fseeko64:
952d21529faSDavid L. Jones   case LibFunc_fseeko:
953d21529faSDavid L. Jones   case LibFunc_fsetpos:
954d21529faSDavid L. Jones   case LibFunc_ftell:
955d21529faSDavid L. Jones   case LibFunc_ftello64:
956d21529faSDavid L. Jones   case LibFunc_ftello:
957d21529faSDavid L. Jones   case LibFunc_ftrylockfile:
958d21529faSDavid L. Jones   case LibFunc_funlockfile:
959d21529faSDavid L. Jones   case LibFunc_getc:
960d21529faSDavid L. Jones   case LibFunc_getc_unlocked:
961d21529faSDavid L. Jones   case LibFunc_getlogin_r:
962d21529faSDavid L. Jones   case LibFunc_mkdir:
963d21529faSDavid L. Jones   case LibFunc_mktime:
964d21529faSDavid L. Jones   case LibFunc_times:
9651fe3f1caSAhmed Bougacha     return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
9661fe3f1caSAhmed Bougacha 
967d21529faSDavid L. Jones   case LibFunc_fopen:
968d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
969d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
970d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
971c3bed1e8SCalixte Denizet   case LibFunc_fork:
972c3bed1e8SCalixte Denizet     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
973d21529faSDavid L. Jones   case LibFunc_fdopen:
974d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
975d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
976d21529faSDavid L. Jones   case LibFunc_fputc:
977ca22d427SDavid Bolvansky   case LibFunc_fputc_unlocked:
978d21529faSDavid L. Jones   case LibFunc_fstat:
979d21529faSDavid L. Jones   case LibFunc_frexp:
980d21529faSDavid L. Jones   case LibFunc_frexpf:
981d21529faSDavid L. Jones   case LibFunc_frexpl:
982d21529faSDavid L. Jones   case LibFunc_fstatvfs:
983d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
984d21529faSDavid L. Jones   case LibFunc_fgets:
985ca22d427SDavid Bolvansky   case LibFunc_fgets_unlocked:
986d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
987d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
988d21529faSDavid L. Jones   case LibFunc_fread:
989ca22d427SDavid Bolvansky   case LibFunc_fread_unlocked:
990d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
991d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
992d21529faSDavid L. Jones   case LibFunc_fwrite:
993ca22d427SDavid Bolvansky   case LibFunc_fwrite_unlocked:
994d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
995d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
996d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
997d765a82bSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy() &&
998d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
999d21529faSDavid L. Jones   case LibFunc_fputs:
1000ca22d427SDavid Bolvansky   case LibFunc_fputs_unlocked:
1001d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1002d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1003d21529faSDavid L. Jones   case LibFunc_fscanf:
1004d21529faSDavid L. Jones   case LibFunc_fiprintf:
1005b4f9991fSAlon Zakai   case LibFunc_small_fprintf:
1006d21529faSDavid L. Jones   case LibFunc_fprintf:
10076b9be1dbSAhmed Bougacha     return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
10086b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1009d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1010d21529faSDavid L. Jones   case LibFunc_fgetpos:
1011d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1012d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1013d21529faSDavid L. Jones   case LibFunc_getchar:
1014ca22d427SDavid Bolvansky   case LibFunc_getchar_unlocked:
10156b9be1dbSAhmed Bougacha     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
1016d21529faSDavid L. Jones   case LibFunc_gets:
10176b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
1018d21529faSDavid L. Jones   case LibFunc_getitimer:
1019d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1020d21529faSDavid L. Jones   case LibFunc_ungetc:
1021d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1022d21529faSDavid L. Jones   case LibFunc_utime:
1023d21529faSDavid L. Jones   case LibFunc_utimes:
1024d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1025d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1026d21529faSDavid L. Jones   case LibFunc_putc:
1027ca22d427SDavid Bolvansky   case LibFunc_putc_unlocked:
1028d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1029d21529faSDavid L. Jones   case LibFunc_pread:
1030d21529faSDavid L. Jones   case LibFunc_pwrite:
1031d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
1032d21529faSDavid L. Jones   case LibFunc_popen:
1033d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1034d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1035d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1036d21529faSDavid L. Jones   case LibFunc_vscanf:
1037d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1038d21529faSDavid L. Jones   case LibFunc_vsscanf:
1039d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1040d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1041d21529faSDavid L. Jones   case LibFunc_vfscanf:
1042d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1043d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1044d21529faSDavid L. Jones   case LibFunc_valloc:
1045d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1046d21529faSDavid L. Jones   case LibFunc_vprintf:
1047d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1048d21529faSDavid L. Jones   case LibFunc_vfprintf:
1049d21529faSDavid L. Jones   case LibFunc_vsprintf:
1050d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1051d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1052abb2a93cSErik Pilkington   case LibFunc_vsprintf_chk:
1053abb2a93cSErik Pilkington     return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
1054abb2a93cSErik Pilkington            FTy.getParamType(1)->isIntegerTy(32) &&
1055abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2)) && FTy.getParamType(3)->isPointerTy();
1056d21529faSDavid L. Jones   case LibFunc_vsnprintf:
1057d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1058d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1059abb2a93cSErik Pilkington   case LibFunc_vsnprintf_chk:
1060abb2a93cSErik Pilkington     return NumParams == 6 && FTy.getParamType(0)->isPointerTy() &&
1061abb2a93cSErik Pilkington            FTy.getParamType(2)->isIntegerTy(32) &&
1062abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(3)) && FTy.getParamType(4)->isPointerTy();
1063d21529faSDavid L. Jones   case LibFunc_open:
1064d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1065d21529faSDavid L. Jones   case LibFunc_opendir:
1066d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
1067d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
1068d21529faSDavid L. Jones   case LibFunc_tmpfile:
1069d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1070d21529faSDavid L. Jones   case LibFunc_htonl:
1071d21529faSDavid L. Jones   case LibFunc_ntohl:
10726b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
10736b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1074d21529faSDavid L. Jones   case LibFunc_htons:
1075d21529faSDavid L. Jones   case LibFunc_ntohs:
10766b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
10776b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1078d21529faSDavid L. Jones   case LibFunc_lstat:
1079d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1080d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1081d21529faSDavid L. Jones   case LibFunc_lchown:
1082d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1083d21529faSDavid L. Jones   case LibFunc_qsort:
1084d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
1085d21529faSDavid L. Jones   case LibFunc_dunder_strdup:
1086d21529faSDavid L. Jones   case LibFunc_dunder_strndup:
1087d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
1088d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
1089d21529faSDavid L. Jones   case LibFunc_dunder_strtok_r:
1090d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1091d21529faSDavid L. Jones   case LibFunc_under_IO_putc:
1092d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1093d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_scanf:
1094d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1095d21529faSDavid L. Jones   case LibFunc_stat64:
1096d21529faSDavid L. Jones   case LibFunc_lstat64:
1097d21529faSDavid L. Jones   case LibFunc_statvfs64:
109879dcc274SMichael Kuperstein     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1099d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1100d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_sscanf:
110179dcc274SMichael Kuperstein     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1102d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1103d21529faSDavid L. Jones   case LibFunc_fopen64:
1104d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1105d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1106d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1107d21529faSDavid L. Jones   case LibFunc_tmpfile64:
1108d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1109d21529faSDavid L. Jones   case LibFunc_fstat64:
1110d21529faSDavid L. Jones   case LibFunc_fstatvfs64:
1111d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1112d21529faSDavid L. Jones   case LibFunc_open64:
1113d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1114d21529faSDavid L. Jones   case LibFunc_gettimeofday:
1115d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1116d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1117d765a82bSAhmed Bougacha 
11186b9be1dbSAhmed Bougacha   // new(unsigned int);
1119d21529faSDavid L. Jones   case LibFunc_Znwj:
11206b9be1dbSAhmed Bougacha   // new(unsigned long);
1121d21529faSDavid L. Jones   case LibFunc_Znwm:
11226b9be1dbSAhmed Bougacha   // new[](unsigned int);
1123d21529faSDavid L. Jones   case LibFunc_Znaj:
11246b9be1dbSAhmed Bougacha   // new[](unsigned long);
1125d21529faSDavid L. Jones   case LibFunc_Znam:
11266b9be1dbSAhmed Bougacha   // new(unsigned int);
1127d21529faSDavid L. Jones   case LibFunc_msvc_new_int:
11286b9be1dbSAhmed Bougacha   // new(unsigned long long);
1129d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong:
11306b9be1dbSAhmed Bougacha   // new[](unsigned int);
1131d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int:
11326b9be1dbSAhmed Bougacha   // new[](unsigned long long);
1133d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong:
11346b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
11356b9be1dbSAhmed Bougacha 
11366b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
1137d21529faSDavid L. Jones   case LibFunc_ZnwjRKSt9nothrow_t:
11386b9be1dbSAhmed Bougacha   // new(unsigned long, nothrow);
1139d21529faSDavid L. Jones   case LibFunc_ZnwmRKSt9nothrow_t:
11406b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
1141d21529faSDavid L. Jones   case LibFunc_ZnajRKSt9nothrow_t:
11426b9be1dbSAhmed Bougacha   // new[](unsigned long, nothrow);
1143d21529faSDavid L. Jones   case LibFunc_ZnamRKSt9nothrow_t:
11446b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
1145d21529faSDavid L. Jones   case LibFunc_msvc_new_int_nothrow:
11466b9be1dbSAhmed Bougacha   // new(unsigned long long, nothrow);
1147d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong_nothrow:
11486b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
1149d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int_nothrow:
11506b9be1dbSAhmed Bougacha   // new[](unsigned long long, nothrow);
1151d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong_nothrow:
115296bbec79SEric Fiselier   // new(unsigned int, align_val_t)
115396bbec79SEric Fiselier   case LibFunc_ZnwjSt11align_val_t:
115496bbec79SEric Fiselier   // new(unsigned long, align_val_t)
115596bbec79SEric Fiselier   case LibFunc_ZnwmSt11align_val_t:
115696bbec79SEric Fiselier   // new[](unsigned int, align_val_t)
115796bbec79SEric Fiselier   case LibFunc_ZnajSt11align_val_t:
115896bbec79SEric Fiselier   // new[](unsigned long, align_val_t)
115996bbec79SEric Fiselier   case LibFunc_ZnamSt11align_val_t:
11606b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
11616b9be1dbSAhmed Bougacha 
116296bbec79SEric Fiselier   // new(unsigned int, align_val_t, nothrow)
116396bbec79SEric Fiselier   case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
116496bbec79SEric Fiselier   // new(unsigned long, align_val_t, nothrow)
116596bbec79SEric Fiselier   case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
116696bbec79SEric Fiselier   // new[](unsigned int, align_val_t, nothrow)
116796bbec79SEric Fiselier   case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
116896bbec79SEric Fiselier   // new[](unsigned long, align_val_t, nothrow)
116996bbec79SEric Fiselier   case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
117096bbec79SEric Fiselier     return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
117196bbec79SEric Fiselier 
11726b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1173d21529faSDavid L. Jones   case LibFunc_ZdaPv:
11746b9be1dbSAhmed Bougacha   // void operator delete(void*);
1175d21529faSDavid L. Jones   case LibFunc_ZdlPv:
11766b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1177d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32:
11786b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1179d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64:
11806b9be1dbSAhmed Bougacha   // void operator delete(void*);
1181d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32:
11826b9be1dbSAhmed Bougacha   // void operator delete(void*);
1183d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64:
11846b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
11856b9be1dbSAhmed Bougacha 
11866b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1187d21529faSDavid L. Jones   case LibFunc_ZdaPvRKSt9nothrow_t:
11886b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1189d21529faSDavid L. Jones   case LibFunc_ZdaPvj:
11906b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long);
1191d21529faSDavid L. Jones   case LibFunc_ZdaPvm:
11926b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1193d21529faSDavid L. Jones   case LibFunc_ZdlPvRKSt9nothrow_t:
11946b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1195d21529faSDavid L. Jones   case LibFunc_ZdlPvj:
11966b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long);
1197d21529faSDavid L. Jones   case LibFunc_ZdlPvm:
119896bbec79SEric Fiselier   // void operator delete(void*, align_val_t)
119996bbec79SEric Fiselier   case LibFunc_ZdlPvSt11align_val_t:
120096bbec79SEric Fiselier   // void operator delete[](void*, align_val_t)
120196bbec79SEric Fiselier   case LibFunc_ZdaPvSt11align_val_t:
12026b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1203d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_int:
12046b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1205d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_nothrow:
12066b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long long);
1207d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_longlong:
12086b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1209d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_nothrow:
12106b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1211d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_int:
12126b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1213d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_nothrow:
12146b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long long);
1215d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_longlong:
12166b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1217d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_nothrow:
12186b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1219d765a82bSAhmed Bougacha 
122096bbec79SEric Fiselier   // void operator delete(void*, align_val_t, nothrow)
122196bbec79SEric Fiselier   case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
122296bbec79SEric Fiselier   // void operator delete[](void*, align_val_t, nothrow)
122396bbec79SEric Fiselier   case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
12246bc2b042SHiroshi Yamauchi   // void operator delete(void*, unsigned int, align_val_t)
12256bc2b042SHiroshi Yamauchi   case LibFunc_ZdlPvjSt11align_val_t:
12266bc2b042SHiroshi Yamauchi   // void operator delete(void*, unsigned long, align_val_t)
12276bc2b042SHiroshi Yamauchi   case LibFunc_ZdlPvmSt11align_val_t:
12286bc2b042SHiroshi Yamauchi   // void operator delete[](void*, unsigned int, align_val_t);
12296bc2b042SHiroshi Yamauchi   case LibFunc_ZdaPvjSt11align_val_t:
12306bc2b042SHiroshi Yamauchi   // void operator delete[](void*, unsigned long, align_val_t);
12316bc2b042SHiroshi Yamauchi   case LibFunc_ZdaPvmSt11align_val_t:
123296bbec79SEric Fiselier     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
123396bbec79SEric Fiselier 
1234c4250941SGui Andrade   // void __atomic_load(size_t, void *, void *, int)
1235c4250941SGui Andrade   case LibFunc_atomic_load:
1236c4250941SGui Andrade   // void __atomic_store(size_t, void *, void *, int)
1237c4250941SGui Andrade   case LibFunc_atomic_store:
1238c4250941SGui Andrade     return (NumParams == 4 && FTy.getParamType(0)->isIntegerTy() &&
1239c4250941SGui Andrade             FTy.getParamType(1)->isPointerTy() &&
1240c4250941SGui Andrade             FTy.getParamType(2)->isPointerTy() &&
1241c4250941SGui Andrade             FTy.getParamType(3)->isIntegerTy());
1242c4250941SGui Andrade 
1243d21529faSDavid L. Jones   case LibFunc_memset_pattern16:
1244d765a82bSAhmed Bougacha     return (!FTy.isVarArg() && NumParams == 3 &&
12456b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
12466b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
12476b9be1dbSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy());
1248d765a82bSAhmed Bougacha 
1249d21529faSDavid L. Jones   case LibFunc_cxa_guard_abort:
1250d21529faSDavid L. Jones   case LibFunc_cxa_guard_acquire:
1251d21529faSDavid L. Jones   case LibFunc_cxa_guard_release:
1252d21529faSDavid L. Jones   case LibFunc_nvvm_reflect:
12536b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1254d765a82bSAhmed Bougacha 
1255d21529faSDavid L. Jones   case LibFunc_sincospi_stret:
1256d21529faSDavid L. Jones   case LibFunc_sincospif_stret:
12576b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
12586b9be1dbSAhmed Bougacha 
1259d21529faSDavid L. Jones   case LibFunc_acos:
12603cd8c16dSAndrew Kaylor   case LibFunc_acos_finite:
1261d21529faSDavid L. Jones   case LibFunc_acosf:
12623cd8c16dSAndrew Kaylor   case LibFunc_acosf_finite:
1263d21529faSDavid L. Jones   case LibFunc_acosh:
12643cd8c16dSAndrew Kaylor   case LibFunc_acosh_finite:
1265d21529faSDavid L. Jones   case LibFunc_acoshf:
12663cd8c16dSAndrew Kaylor   case LibFunc_acoshf_finite:
1267d21529faSDavid L. Jones   case LibFunc_acoshl:
12683cd8c16dSAndrew Kaylor   case LibFunc_acoshl_finite:
1269d21529faSDavid L. Jones   case LibFunc_acosl:
12703cd8c16dSAndrew Kaylor   case LibFunc_acosl_finite:
1271d21529faSDavid L. Jones   case LibFunc_asin:
12723cd8c16dSAndrew Kaylor   case LibFunc_asin_finite:
1273d21529faSDavid L. Jones   case LibFunc_asinf:
12743cd8c16dSAndrew Kaylor   case LibFunc_asinf_finite:
1275d21529faSDavid L. Jones   case LibFunc_asinh:
1276d21529faSDavid L. Jones   case LibFunc_asinhf:
1277d21529faSDavid L. Jones   case LibFunc_asinhl:
1278d21529faSDavid L. Jones   case LibFunc_asinl:
12793cd8c16dSAndrew Kaylor   case LibFunc_asinl_finite:
1280d21529faSDavid L. Jones   case LibFunc_atan:
1281d21529faSDavid L. Jones   case LibFunc_atanf:
1282d21529faSDavid L. Jones   case LibFunc_atanh:
12833cd8c16dSAndrew Kaylor   case LibFunc_atanh_finite:
1284d21529faSDavid L. Jones   case LibFunc_atanhf:
12853cd8c16dSAndrew Kaylor   case LibFunc_atanhf_finite:
1286d21529faSDavid L. Jones   case LibFunc_atanhl:
12873cd8c16dSAndrew Kaylor   case LibFunc_atanhl_finite:
1288d21529faSDavid L. Jones   case LibFunc_atanl:
1289d21529faSDavid L. Jones   case LibFunc_cbrt:
1290d21529faSDavid L. Jones   case LibFunc_cbrtf:
1291d21529faSDavid L. Jones   case LibFunc_cbrtl:
1292d21529faSDavid L. Jones   case LibFunc_ceil:
1293d21529faSDavid L. Jones   case LibFunc_ceilf:
1294d21529faSDavid L. Jones   case LibFunc_ceill:
1295d21529faSDavid L. Jones   case LibFunc_cos:
1296d21529faSDavid L. Jones   case LibFunc_cosf:
1297d21529faSDavid L. Jones   case LibFunc_cosh:
12983cd8c16dSAndrew Kaylor   case LibFunc_cosh_finite:
1299d21529faSDavid L. Jones   case LibFunc_coshf:
13003cd8c16dSAndrew Kaylor   case LibFunc_coshf_finite:
1301d21529faSDavid L. Jones   case LibFunc_coshl:
13023cd8c16dSAndrew Kaylor   case LibFunc_coshl_finite:
1303d21529faSDavid L. Jones   case LibFunc_cosl:
1304d21529faSDavid L. Jones   case LibFunc_exp10:
13053cd8c16dSAndrew Kaylor   case LibFunc_exp10_finite:
1306d21529faSDavid L. Jones   case LibFunc_exp10f:
13073cd8c16dSAndrew Kaylor   case LibFunc_exp10f_finite:
1308d21529faSDavid L. Jones   case LibFunc_exp10l:
13093cd8c16dSAndrew Kaylor   case LibFunc_exp10l_finite:
1310d21529faSDavid L. Jones   case LibFunc_exp2:
13113cd8c16dSAndrew Kaylor   case LibFunc_exp2_finite:
1312d21529faSDavid L. Jones   case LibFunc_exp2f:
13133cd8c16dSAndrew Kaylor   case LibFunc_exp2f_finite:
1314d21529faSDavid L. Jones   case LibFunc_exp2l:
13153cd8c16dSAndrew Kaylor   case LibFunc_exp2l_finite:
1316d21529faSDavid L. Jones   case LibFunc_exp:
13173cd8c16dSAndrew Kaylor   case LibFunc_exp_finite:
1318d21529faSDavid L. Jones   case LibFunc_expf:
13193cd8c16dSAndrew Kaylor   case LibFunc_expf_finite:
1320d21529faSDavid L. Jones   case LibFunc_expl:
13213cd8c16dSAndrew Kaylor   case LibFunc_expl_finite:
1322d21529faSDavid L. Jones   case LibFunc_expm1:
1323d21529faSDavid L. Jones   case LibFunc_expm1f:
1324d21529faSDavid L. Jones   case LibFunc_expm1l:
1325d21529faSDavid L. Jones   case LibFunc_fabs:
1326d21529faSDavid L. Jones   case LibFunc_fabsf:
1327d21529faSDavid L. Jones   case LibFunc_fabsl:
1328d21529faSDavid L. Jones   case LibFunc_floor:
1329d21529faSDavid L. Jones   case LibFunc_floorf:
1330d21529faSDavid L. Jones   case LibFunc_floorl:
1331d21529faSDavid L. Jones   case LibFunc_log10:
13323cd8c16dSAndrew Kaylor   case LibFunc_log10_finite:
1333d21529faSDavid L. Jones   case LibFunc_log10f:
13343cd8c16dSAndrew Kaylor   case LibFunc_log10f_finite:
1335d21529faSDavid L. Jones   case LibFunc_log10l:
13363cd8c16dSAndrew Kaylor   case LibFunc_log10l_finite:
1337d21529faSDavid L. Jones   case LibFunc_log1p:
1338d21529faSDavid L. Jones   case LibFunc_log1pf:
1339d21529faSDavid L. Jones   case LibFunc_log1pl:
1340d21529faSDavid L. Jones   case LibFunc_log2:
13413cd8c16dSAndrew Kaylor   case LibFunc_log2_finite:
1342d21529faSDavid L. Jones   case LibFunc_log2f:
13433cd8c16dSAndrew Kaylor   case LibFunc_log2f_finite:
1344d21529faSDavid L. Jones   case LibFunc_log2l:
13453cd8c16dSAndrew Kaylor   case LibFunc_log2l_finite:
1346d21529faSDavid L. Jones   case LibFunc_log:
13473cd8c16dSAndrew Kaylor   case LibFunc_log_finite:
1348d21529faSDavid L. Jones   case LibFunc_logb:
1349d21529faSDavid L. Jones   case LibFunc_logbf:
1350d21529faSDavid L. Jones   case LibFunc_logbl:
1351d21529faSDavid L. Jones   case LibFunc_logf:
13523cd8c16dSAndrew Kaylor   case LibFunc_logf_finite:
1353d21529faSDavid L. Jones   case LibFunc_logl:
13543cd8c16dSAndrew Kaylor   case LibFunc_logl_finite:
1355d21529faSDavid L. Jones   case LibFunc_nearbyint:
1356d21529faSDavid L. Jones   case LibFunc_nearbyintf:
1357d21529faSDavid L. Jones   case LibFunc_nearbyintl:
1358d21529faSDavid L. Jones   case LibFunc_rint:
1359d21529faSDavid L. Jones   case LibFunc_rintf:
1360d21529faSDavid L. Jones   case LibFunc_rintl:
1361d21529faSDavid L. Jones   case LibFunc_round:
1362d21529faSDavid L. Jones   case LibFunc_roundf:
1363d21529faSDavid L. Jones   case LibFunc_roundl:
13644d20e31fSSerge Pavlov   case LibFunc_roundeven:
13654d20e31fSSerge Pavlov   case LibFunc_roundevenf:
13664d20e31fSSerge Pavlov   case LibFunc_roundevenl:
1367d21529faSDavid L. Jones   case LibFunc_sin:
1368d21529faSDavid L. Jones   case LibFunc_sinf:
1369d21529faSDavid L. Jones   case LibFunc_sinh:
13703cd8c16dSAndrew Kaylor   case LibFunc_sinh_finite:
1371d21529faSDavid L. Jones   case LibFunc_sinhf:
13723cd8c16dSAndrew Kaylor   case LibFunc_sinhf_finite:
1373d21529faSDavid L. Jones   case LibFunc_sinhl:
13743cd8c16dSAndrew Kaylor   case LibFunc_sinhl_finite:
1375d21529faSDavid L. Jones   case LibFunc_sinl:
1376d21529faSDavid L. Jones   case LibFunc_sqrt:
1377d21529faSDavid L. Jones   case LibFunc_sqrt_finite:
1378d21529faSDavid L. Jones   case LibFunc_sqrtf:
1379d21529faSDavid L. Jones   case LibFunc_sqrtf_finite:
1380d21529faSDavid L. Jones   case LibFunc_sqrtl:
1381d21529faSDavid L. Jones   case LibFunc_sqrtl_finite:
1382d21529faSDavid L. Jones   case LibFunc_tan:
1383d21529faSDavid L. Jones   case LibFunc_tanf:
1384d21529faSDavid L. Jones   case LibFunc_tanh:
1385d21529faSDavid L. Jones   case LibFunc_tanhf:
1386d21529faSDavid L. Jones   case LibFunc_tanhl:
1387d21529faSDavid L. Jones   case LibFunc_tanl:
1388d21529faSDavid L. Jones   case LibFunc_trunc:
1389d21529faSDavid L. Jones   case LibFunc_truncf:
1390d21529faSDavid L. Jones   case LibFunc_truncl:
1391d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1392d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1393d765a82bSAhmed Bougacha 
1394d21529faSDavid L. Jones   case LibFunc_atan2:
13953cd8c16dSAndrew Kaylor   case LibFunc_atan2_finite:
1396d21529faSDavid L. Jones   case LibFunc_atan2f:
13973cd8c16dSAndrew Kaylor   case LibFunc_atan2f_finite:
1398d21529faSDavid L. Jones   case LibFunc_atan2l:
13993cd8c16dSAndrew Kaylor   case LibFunc_atan2l_finite:
1400d21529faSDavid L. Jones   case LibFunc_fmin:
1401d21529faSDavid L. Jones   case LibFunc_fminf:
1402d21529faSDavid L. Jones   case LibFunc_fminl:
1403d21529faSDavid L. Jones   case LibFunc_fmax:
1404d21529faSDavid L. Jones   case LibFunc_fmaxf:
1405d21529faSDavid L. Jones   case LibFunc_fmaxl:
1406d21529faSDavid L. Jones   case LibFunc_fmod:
1407d21529faSDavid L. Jones   case LibFunc_fmodf:
1408d21529faSDavid L. Jones   case LibFunc_fmodl:
14092470d298SEhud Katz   case LibFunc_remainder:
14102470d298SEhud Katz   case LibFunc_remainderf:
14112470d298SEhud Katz   case LibFunc_remainderl:
1412d21529faSDavid L. Jones   case LibFunc_copysign:
1413d21529faSDavid L. Jones   case LibFunc_copysignf:
1414d21529faSDavid L. Jones   case LibFunc_copysignl:
1415d21529faSDavid L. Jones   case LibFunc_pow:
14163cd8c16dSAndrew Kaylor   case LibFunc_pow_finite:
1417d21529faSDavid L. Jones   case LibFunc_powf:
14183cd8c16dSAndrew Kaylor   case LibFunc_powf_finite:
1419d21529faSDavid L. Jones   case LibFunc_powl:
14203cd8c16dSAndrew Kaylor   case LibFunc_powl_finite:
1421d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1422d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
1423d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(1));
1424d765a82bSAhmed Bougacha 
1425d21529faSDavid L. Jones   case LibFunc_ldexp:
1426d21529faSDavid L. Jones   case LibFunc_ldexpf:
1427d21529faSDavid L. Jones   case LibFunc_ldexpl:
14286b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
14296b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
14306b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32));
14316b9be1dbSAhmed Bougacha 
1432d21529faSDavid L. Jones   case LibFunc_ffs:
1433d21529faSDavid L. Jones   case LibFunc_ffsl:
1434d21529faSDavid L. Jones   case LibFunc_ffsll:
1435d21529faSDavid L. Jones   case LibFunc_fls:
1436d21529faSDavid L. Jones   case LibFunc_flsl:
1437d21529faSDavid L. Jones   case LibFunc_flsll:
143804949fafSSanjay Patel     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
143904949fafSSanjay Patel             FTy.getParamType(0)->isIntegerTy());
144004949fafSSanjay Patel 
1441d21529faSDavid L. Jones   case LibFunc_isdigit:
1442d21529faSDavid L. Jones   case LibFunc_isascii:
1443d21529faSDavid L. Jones   case LibFunc_toascii:
1444d21529faSDavid L. Jones   case LibFunc_putchar:
1445ca22d427SDavid Bolvansky   case LibFunc_putchar_unlocked:
1446d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
144704949fafSSanjay Patel             FTy.getReturnType() == FTy.getParamType(0));
1448d765a82bSAhmed Bougacha 
1449d21529faSDavid L. Jones   case LibFunc_abs:
1450d21529faSDavid L. Jones   case LibFunc_labs:
1451d21529faSDavid L. Jones   case LibFunc_llabs:
1452d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1453d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1454d765a82bSAhmed Bougacha 
1455d21529faSDavid L. Jones   case LibFunc_cxa_atexit:
1456d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1457d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1458d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
1459d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1460d765a82bSAhmed Bougacha 
1461d21529faSDavid L. Jones   case LibFunc_sinpi:
1462d21529faSDavid L. Jones   case LibFunc_cospi:
1463d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1464d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1465d765a82bSAhmed Bougacha 
1466d21529faSDavid L. Jones   case LibFunc_sinpif:
1467d21529faSDavid L. Jones   case LibFunc_cospif:
1468d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1469d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1470d765a82bSAhmed Bougacha 
1471d21529faSDavid L. Jones   case LibFunc_strnlen:
14726b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
14736b9be1dbSAhmed Bougacha             FTy.getParamType(0) == PCharTy &&
14746b9be1dbSAhmed Bougacha             FTy.getParamType(1) == SizeTTy);
14756b9be1dbSAhmed Bougacha 
1476d21529faSDavid L. Jones   case LibFunc_posix_memalign:
14776b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
14786b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
14796b9be1dbSAhmed Bougacha             FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
14806b9be1dbSAhmed Bougacha 
148160b40b8fSMatthias Braun   case LibFunc_wcslen:
148260b40b8fSMatthias Braun     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
148360b40b8fSMatthias Braun             FTy.getReturnType()->isIntegerTy());
148460b40b8fSMatthias Braun 
14852ff24731SHal Finkel   case LibFunc_cabs:
14862ff24731SHal Finkel   case LibFunc_cabsf:
14872ff24731SHal Finkel   case LibFunc_cabsl: {
14882ff24731SHal Finkel     Type* RetTy = FTy.getReturnType();
14892ff24731SHal Finkel     if (!RetTy->isFloatingPointTy())
14902ff24731SHal Finkel       return false;
14912ff24731SHal Finkel 
14922ff24731SHal Finkel     // NOTE: These prototypes are target specific and currently support
14932ff24731SHal Finkel     // "complex" passed as an array or discrete real & imaginary parameters.
14942ff24731SHal Finkel     // Add other calling conventions to enable libcall optimizations.
14952ff24731SHal Finkel     if (NumParams == 1)
14962ff24731SHal Finkel       return (FTy.getParamType(0)->isArrayTy() &&
14972ff24731SHal Finkel               FTy.getParamType(0)->getArrayNumElements() == 2 &&
14982ff24731SHal Finkel               FTy.getParamType(0)->getArrayElementType() == RetTy);
14992ff24731SHal Finkel     else if (NumParams == 2)
15002ff24731SHal Finkel       return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
15012ff24731SHal Finkel     else
15022ff24731SHal Finkel       return false;
15032ff24731SHal Finkel   }
15046b9be1dbSAhmed Bougacha   case LibFunc::NumLibFuncs:
15053b705ef7SEvandro Menezes   case LibFunc::NotLibFunc:
150686b680a3SAhmed Bougacha     break;
1507d765a82bSAhmed Bougacha   }
15086b9be1dbSAhmed Bougacha 
150986b680a3SAhmed Bougacha   llvm_unreachable("Invalid libfunc");
1510d765a82bSAhmed Bougacha }
1511d765a82bSAhmed Bougacha 
1512d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1513d21529faSDavid L. Jones                                        LibFunc &F) const {
151476ea748dSPhilip Reames   // Intrinsics don't overlap w/libcalls; if our module has a large number of
151576ea748dSPhilip Reames   // intrinsics, this ends up being an interesting compile time win since we
151676ea748dSPhilip Reames   // avoid string normalization and comparison.
151776ea748dSPhilip Reames   if (FDecl.isIntrinsic()) return false;
151876ea748dSPhilip Reames 
1519d765a82bSAhmed Bougacha   const DataLayout *DL =
1520d765a82bSAhmed Bougacha       FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1521d765a82bSAhmed Bougacha   return getLibFunc(FDecl.getName(), F) &&
1522d765a82bSAhmed Bougacha          isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1523d765a82bSAhmed Bougacha }
1524d765a82bSAhmed Bougacha 
1525c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() {
152662d4215bSChandler Carruth   memset(AvailableArray, 0, sizeof(AvailableArray));
152762d4215bSChandler Carruth }
1528b98f63dbSChandler Carruth 
1529e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
15309a72cd7bSMehdi Amini   return LHS.ScalarFnName < RHS.ScalarFnName;
1531e8f2551fSMichael Zolotukhin }
1532e8f2551fSMichael Zolotukhin 
1533e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
15349a72cd7bSMehdi Amini   return LHS.VectorFnName < RHS.VectorFnName;
1535e8f2551fSMichael Zolotukhin }
1536e8f2551fSMichael Zolotukhin 
1537e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
15389a72cd7bSMehdi Amini   return LHS.ScalarFnName < S;
1539e8f2551fSMichael Zolotukhin }
1540e8f2551fSMichael Zolotukhin 
1541e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
15429a72cd7bSMehdi Amini   return LHS.VectorFnName < S;
1543e8f2551fSMichael Zolotukhin }
1544e8f2551fSMichael Zolotukhin 
1545ed03d948SMehdi Amini void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1546*f76e83bfSKazu Hirata   llvm::append_range(VectorDescs, Fns);
15470cac726aSFangrui Song   llvm::sort(VectorDescs, compareByScalarFnName);
1548e8f2551fSMichael Zolotukhin 
1549*f76e83bfSKazu Hirata   llvm::append_range(ScalarDescs, Fns);
15500cac726aSFangrui Song   llvm::sort(ScalarDescs, compareByVectorFnName);
1551e8f2551fSMichael Zolotukhin }
1552e8f2551fSMichael Zolotukhin 
15536d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1554ed03d948SMehdi Amini     enum VectorLibrary VecLib) {
15556d8a2aa9SMichael Zolotukhin   switch (VecLib) {
15566d8a2aa9SMichael Zolotukhin   case Accelerate: {
15576d8a2aa9SMichael Zolotukhin     const VecDesc VecFuncs[] = {
1558820b9031SNemanja Ivanovic     #define TLI_DEFINE_ACCELERATE_VECFUNCS
1559820b9031SNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
15606d8a2aa9SMichael Zolotukhin     };
1561ed03d948SMehdi Amini     addVectorizableFunctions(VecFuncs);
15626d8a2aa9SMichael Zolotukhin     break;
15636d8a2aa9SMichael Zolotukhin   }
156457cdc52cSVenkataramanan Kumar   case LIBMVEC_X86: {
156557cdc52cSVenkataramanan Kumar     const VecDesc VecFuncs[] = {
156657cdc52cSVenkataramanan Kumar     #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
156757cdc52cSVenkataramanan Kumar     #include "llvm/Analysis/VecFuncs.def"
156857cdc52cSVenkataramanan Kumar     };
156957cdc52cSVenkataramanan Kumar     addVectorizableFunctions(VecFuncs);
157057cdc52cSVenkataramanan Kumar     break;
157157cdc52cSVenkataramanan Kumar   }
1572fe97754aSNemanja Ivanovic   case MASSV: {
1573fe97754aSNemanja Ivanovic     const VecDesc VecFuncs[] = {
1574fe97754aSNemanja Ivanovic     #define TLI_DEFINE_MASSV_VECFUNCS
1575fe97754aSNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
1576fe97754aSNemanja Ivanovic     };
1577ed03d948SMehdi Amini     addVectorizableFunctions(VecFuncs);
1578fe97754aSNemanja Ivanovic     break;
1579fe97754aSNemanja Ivanovic   }
1580a6669a1eSMatt Masten   case SVML: {
1581a6669a1eSMatt Masten     const VecDesc VecFuncs[] = {
1582820b9031SNemanja Ivanovic     #define TLI_DEFINE_SVML_VECFUNCS
1583820b9031SNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
1584a6669a1eSMatt Masten     };
1585ed03d948SMehdi Amini     addVectorizableFunctions(VecFuncs);
1586a6669a1eSMatt Masten     break;
1587a6669a1eSMatt Masten   }
1588ed03d948SMehdi Amini   case NoLibrary:
15896d8a2aa9SMichael Zolotukhin     break;
15906d8a2aa9SMichael Zolotukhin   }
15916d8a2aa9SMichael Zolotukhin }
15926d8a2aa9SMichael Zolotukhin 
1593ed03d948SMehdi Amini bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1594e8f2551fSMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
1595ed03d948SMehdi Amini   if (funcName.empty())
1596e8f2551fSMichael Zolotukhin     return false;
1597e8f2551fSMichael Zolotukhin 
1598cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1599cecc4352SFangrui Song       llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1600e8f2551fSMichael Zolotukhin   return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1601e8f2551fSMichael Zolotukhin }
1602e8f2551fSMichael Zolotukhin 
1603ed03d948SMehdi Amini StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1604ed03d948SMehdi Amini                                                        unsigned VF) const {
1605e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1606ed03d948SMehdi Amini   if (F.empty())
1607e8f2551fSMichael Zolotukhin     return F;
1608cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1609cecc4352SFangrui Song       llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
1610e8f2551fSMichael Zolotukhin   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1611e8f2551fSMichael Zolotukhin     if (I->VectorizationFactor == VF)
1612e8f2551fSMichael Zolotukhin       return I->VectorFnName;
1613e8f2551fSMichael Zolotukhin     ++I;
1614e8f2551fSMichael Zolotukhin   }
1615e8f2551fSMichael Zolotukhin   return StringRef();
1616e8f2551fSMichael Zolotukhin }
1617e8f2551fSMichael Zolotukhin 
1618ed03d948SMehdi Amini StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1619ed03d948SMehdi Amini                                                        unsigned &VF) const {
1620e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1621ed03d948SMehdi Amini   if (F.empty())
1622e8f2551fSMichael Zolotukhin     return F;
1623e8f2551fSMichael Zolotukhin 
1624cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1625cecc4352SFangrui Song       llvm::lower_bound(ScalarDescs, F, compareWithVectorFnName);
1626e8f2551fSMichael Zolotukhin   if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1627e8f2551fSMichael Zolotukhin     return StringRef();
1628e8f2551fSMichael Zolotukhin   VF = I->VectorizationFactor;
1629e8f2551fSMichael Zolotukhin   return I->ScalarFnName;
1630e8f2551fSMichael Zolotukhin }
1631e8f2551fSMichael Zolotukhin 
1632878ab6dfSTeresa Johnson TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
1633164a2aa6SChandler Carruth                                              FunctionAnalysisManager &) {
1634878ab6dfSTeresa Johnson   if (!BaselineInfoImpl)
1635878ab6dfSTeresa Johnson     BaselineInfoImpl =
1636878ab6dfSTeresa Johnson         TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
1637878ab6dfSTeresa Johnson   return TargetLibraryInfo(*BaselineInfoImpl, &F);
1638c0291865SChandler Carruth }
1639c0291865SChandler Carruth 
164050ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
164150ec0b5dSMatthias Braun   if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
164250ec0b5dSMatthias Braun       M.getModuleFlag("wchar_size")))
164350ec0b5dSMatthias Braun     return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1644cc603ee3SMatthias Braun   return 0;
164550ec0b5dSMatthias Braun }
1646c0291865SChandler Carruth 
1647b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1648878ab6dfSTeresa Johnson     : ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
1649b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1650b98f63dbSChandler Carruth }
1651b98f63dbSChandler Carruth 
1652b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
1653878ab6dfSTeresa Johnson     : ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) {
1654b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1655b98f63dbSChandler Carruth }
1656b98f63dbSChandler Carruth 
1657b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1658c0291865SChandler Carruth     const TargetLibraryInfoImpl &TLIImpl)
1659878ab6dfSTeresa Johnson     : ImmutablePass(ID), TLA(TLIImpl) {
1660b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1661b98f63dbSChandler Carruth }
1662b98f63dbSChandler Carruth 
1663dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key;
1664df0cd726SNAKAMURA Takumi 
1665b98f63dbSChandler Carruth // Register the basic pass.
1666b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1667b98f63dbSChandler Carruth                 "Target Library Information", false, true)
1668b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0;
1669b98f63dbSChandler Carruth 
1670b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {}
1671d6de5f12SFrancesco Petrogalli 
1672ed03d948SMehdi Amini unsigned TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF) const {
1673d6de5f12SFrancesco Petrogalli   ScalarF = sanitizeFunctionName(ScalarF);
1674ed03d948SMehdi Amini   if (ScalarF.empty())
1675d6de5f12SFrancesco Petrogalli     return 1;
1676d6de5f12SFrancesco Petrogalli 
1677d6de5f12SFrancesco Petrogalli   unsigned VF = 1;
1678d6de5f12SFrancesco Petrogalli   std::vector<VecDesc>::const_iterator I =
1679d6de5f12SFrancesco Petrogalli       llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
1680d6de5f12SFrancesco Petrogalli   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) {
1681d6de5f12SFrancesco Petrogalli     if (I->VectorizationFactor > VF)
1682d6de5f12SFrancesco Petrogalli       VF = I->VectorizationFactor;
1683d6de5f12SFrancesco Petrogalli     ++I;
1684d6de5f12SFrancesco Petrogalli   }
1685d6de5f12SFrancesco Petrogalli   return VF;
1686d6de5f12SFrancesco Petrogalli }
1687