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"
166d8a2aa9SMichael Zolotukhin #include "llvm/Support/CommandLine.h"
1762d4215bSChandler Carruth using namespace llvm;
1862d4215bSChandler Carruth 
196d8a2aa9SMichael Zolotukhin static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
206d8a2aa9SMichael Zolotukhin     "vector-library", cl::Hidden, cl::desc("Vector functions library"),
216d8a2aa9SMichael Zolotukhin     cl::init(TargetLibraryInfoImpl::NoLibrary),
226d8a2aa9SMichael Zolotukhin     cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
236d8a2aa9SMichael Zolotukhin                           "No vector functions library"),
246d8a2aa9SMichael Zolotukhin                clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
256d8a2aa9SMichael Zolotukhin                           "Accelerate framework"),
26fe97754aSNemanja Ivanovic                clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
27fe97754aSNemanja Ivanovic                           "IBM MASS vector library"),
28a6669a1eSMatt Masten                clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
297459398aSJoel Jones                           "Intel SVML library")));
306d8a2aa9SMichael Zolotukhin 
319a72cd7bSMehdi Amini StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
32cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING
33cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def"
3462d4215bSChandler Carruth };
3562d4215bSChandler Carruth 
3662d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) {
3762d4215bSChandler Carruth   // Only Darwin variants have _stret versions of combined trig functions.
3862d4215bSChandler Carruth   if (!T.isOSDarwin())
3962d4215bSChandler Carruth     return false;
4062d4215bSChandler Carruth 
4162d4215bSChandler Carruth   // The ABI is rather complicated on x86, so don't do anything special there.
4262d4215bSChandler Carruth   if (T.getArch() == Triple::x86)
4362d4215bSChandler Carruth     return false;
4462d4215bSChandler Carruth 
4562d4215bSChandler Carruth   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
4662d4215bSChandler Carruth     return false;
4762d4215bSChandler Carruth 
4862d4215bSChandler Carruth   if (T.isiOS() && T.isOSVersionLT(7, 0))
4962d4215bSChandler Carruth     return false;
5062d4215bSChandler Carruth 
5162d4215bSChandler Carruth   return true;
5262d4215bSChandler Carruth }
5362d4215bSChandler Carruth 
548e16d733SClement Courbet static bool hasBcmp(const Triple &TT) {
558e16d733SClement Courbet   // Posix removed support from bcmp() in 2001, but the glibc and several
568e16d733SClement Courbet   // implementations of the libc still have it.
578e16d733SClement Courbet   if (TT.isOSLinux())
588e16d733SClement Courbet     return TT.isGNUEnvironment() || TT.isMusl();
598e16d733SClement Courbet   // Both NetBSD and OpenBSD are planning to remove the function. Windows does
608e16d733SClement Courbet   // not have it.
618e16d733SClement Courbet   return TT.isOSFreeBSD() || TT.isOSSolaris() || TT.isOSDarwin();
628e16d733SClement Courbet }
638e16d733SClement Courbet 
64600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified
65600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target
66600d24b4SSanjay Patel /// triple gets a sane set of defaults.
67c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
689a72cd7bSMehdi Amini                        ArrayRef<StringRef> StandardNames) {
6962d4215bSChandler Carruth   // Verify that the StandardNames array is in alphabetical order.
70e30b8ca1SCraig Topper   assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
719a72cd7bSMehdi Amini                         [](StringRef LHS, StringRef RHS) {
729a72cd7bSMehdi Amini                           return LHS < RHS;
73e30b8ca1SCraig Topper                         }) &&
74e30b8ca1SCraig Topper          "TargetLibraryInfoImpl function names must be sorted");
7562d4215bSChandler Carruth 
76ca22d427SDavid Bolvansky   // Set IO unlocked variants as unavailable
77ca22d427SDavid Bolvansky   // Set them as available per system below
78ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_getchar_unlocked);
79ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_putc_unlocked);
80ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_putchar_unlocked);
81ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fputc_unlocked);
82ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fgetc_unlocked);
83ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fread_unlocked);
84ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fwrite_unlocked);
85ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fputs_unlocked);
86ca22d427SDavid Bolvansky   TLI.setUnavailable(LibFunc_fgets_unlocked);
87ca22d427SDavid Bolvansky 
886af8e6c3SMarcin Koscielnicki   bool ShouldExtI32Param = false, ShouldExtI32Return = false,
896af8e6c3SMarcin Koscielnicki        ShouldSignExtI32Param = false;
906af8e6c3SMarcin Koscielnicki   // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
916af8e6c3SMarcin Koscielnicki   // returns corresponding to C-level ints and unsigned ints.
923e92df3eSFangrui Song   if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
933e92df3eSFangrui Song       T.getArch() == Triple::systemz) {
946af8e6c3SMarcin Koscielnicki     ShouldExtI32Param = true;
956af8e6c3SMarcin Koscielnicki     ShouldExtI32Return = true;
966af8e6c3SMarcin Koscielnicki   }
976af8e6c3SMarcin Koscielnicki   // Mips, on the other hand, needs signext on i32 parameters corresponding
986af8e6c3SMarcin Koscielnicki   // to both signed and unsigned ints.
9985e200e9SAlexander Richardson   if (T.isMIPS()) {
1006af8e6c3SMarcin Koscielnicki     ShouldSignExtI32Param = true;
1016af8e6c3SMarcin Koscielnicki   }
1026af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Param(ShouldExtI32Param);
1036af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Return(ShouldExtI32Return);
1046af8e6c3SMarcin Koscielnicki   TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
1056af8e6c3SMarcin Koscielnicki 
10678fd4f08SNicolai Hahnle   if (T.getArch() == Triple::r600 ||
10778fd4f08SNicolai Hahnle       T.getArch() == Triple::amdgcn) {
108d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexp);
109d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexpf);
110d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexpl);
111d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10);
112d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10f);
113d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
114d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log10);
115d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log10f);
116d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log10l);
11778fd4f08SNicolai Hahnle   }
11878fd4f08SNicolai Hahnle 
119*ef72cdedSDavid Bolvansky   // There are no library implementations of memcpy and memset for AMD gpus and
12062d4215bSChandler Carruth   // these can be difficult to lower in the backend.
12162d4215bSChandler Carruth   if (T.getArch() == Triple::r600 ||
12205532995SDan Gohman       T.getArch() == Triple::amdgcn) {
123d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memcpy);
124d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset);
125d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
12662d4215bSChandler Carruth     return;
12762d4215bSChandler Carruth   }
12862d4215bSChandler Carruth 
12962d4215bSChandler Carruth   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
1308b40366bSTim Northover   // All versions of watchOS support it.
13162d4215bSChandler Carruth   if (T.isMacOSX()) {
132ca22d427SDavid Bolvansky     // available IO unlocked variants on Mac OS X
133ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getc_unlocked);
134ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getchar_unlocked);
135ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putc_unlocked);
136ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putchar_unlocked);
137ca22d427SDavid Bolvansky 
13862d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 5))
139d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
14062d4215bSChandler Carruth   } else if (T.isiOS()) {
14162d4215bSChandler Carruth     if (T.isOSVersionLT(3, 0))
142d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
1438b40366bSTim Northover   } else if (!T.isWatchOS()) {
144d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
14562d4215bSChandler Carruth   }
14662d4215bSChandler Carruth 
14762d4215bSChandler Carruth   if (!hasSinCosPiStret(T)) {
148d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpi);
149d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpif);
150d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospi);
151d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospif);
152d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospi_stret);
153d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospif_stret);
15462d4215bSChandler Carruth   }
15562d4215bSChandler Carruth 
1568e16d733SClement Courbet   if (!hasBcmp(T))
1578e16d733SClement Courbet     TLI.setUnavailable(LibFunc_bcmp);
1588e16d733SClement Courbet 
15962d4215bSChandler Carruth   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
16062d4215bSChandler Carruth       !T.isMacOSXVersionLT(10, 7)) {
16162d4215bSChandler Carruth     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
16262d4215bSChandler Carruth     // we don't care about) have two versions; on recent OSX, the one we want
16362d4215bSChandler Carruth     // has a $UNIX2003 suffix. The two implementations are identical except
16462d4215bSChandler Carruth     // for the return value in some edge cases.  However, we don't want to
16562d4215bSChandler Carruth     // generate code that depends on the old symbols.
166d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
167d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
16862d4215bSChandler Carruth   }
16962d4215bSChandler Carruth 
170b4f9991fSAlon Zakai   // iprintf and friends are only available on XCore, TCE, and Emscripten.
171b4f9991fSAlon Zakai   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
172b4f9991fSAlon Zakai       T.getOS() != Triple::Emscripten) {
173d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_iprintf);
174d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_siprintf);
175d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fiprintf);
17662d4215bSChandler Carruth   }
17762d4215bSChandler Carruth 
178b4f9991fSAlon Zakai   // __small_printf and friends are only available on Emscripten.
179b4f9991fSAlon Zakai   if (T.getOS() != Triple::Emscripten) {
180b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_printf);
181b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_sprintf);
182b4f9991fSAlon Zakai     TLI.setUnavailable(LibFunc_small_fprintf);
183b4f9991fSAlon Zakai   }
184b4f9991fSAlon Zakai 
18562d4215bSChandler Carruth   if (T.isOSWindows() && !T.isOSCygMing()) {
1864b86c474SEvandro Menezes     // XXX: The earliest documentation available at the moment is for VS2015/VC19:
1874b86c474SEvandro Menezes     // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
1884b86c474SEvandro Menezes     // XXX: In order to use an MSVCRT older than VC19,
1894b86c474SEvandro Menezes     // the specific library version must be explicit in the target triple,
1904b86c474SEvandro Menezes     // e.g., x86_64-pc-windows-msvc18.
1914b86c474SEvandro Menezes     bool hasPartialC99 = true;
1924b86c474SEvandro Menezes     if (T.isKnownWindowsMSVCEnvironment()) {
1934b86c474SEvandro Menezes       unsigned Major, Minor, Micro;
1944b86c474SEvandro Menezes       T.getEnvironmentVersion(Major, Minor, Micro);
1954b86c474SEvandro Menezes       hasPartialC99 = (Major == 0 || Major >= 19);
1964b86c474SEvandro Menezes     }
1974b86c474SEvandro Menezes 
198f4a36959SEvandro Menezes     // Latest targets support C89 math functions, in part.
199f4a36959SEvandro Menezes     bool isARM = (T.getArch() == Triple::aarch64 ||
200f4a36959SEvandro Menezes                   T.getArch() == Triple::arm);
201f4a36959SEvandro Menezes     bool hasPartialFloat = (isARM ||
2024b86c474SEvandro Menezes                             T.getArch() == Triple::x86_64);
2034b86c474SEvandro Menezes 
204f4a36959SEvandro Menezes     // Win32 does not support float C89 math functions, in general.
2054b86c474SEvandro Menezes     if (!hasPartialFloat) {
206e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_acosf);
207e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_asinf);
208e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_atan2f);
209f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_atanf);
210e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_ceilf);
211e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_cosf);
212e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_coshf);
213e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_expf);
214e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_floorf);
215e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_fmodf);
216e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_log10f);
217f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_logf);
218e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_modff);
219e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_powf);
220e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sinf);
221e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sinhf);
222e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_sqrtf);
223e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_tanf);
224e5bb58b1SEvandro Menezes       TLI.setUnavailable(LibFunc_tanhf);
225e5bb58b1SEvandro Menezes     }
226f4a36959SEvandro Menezes     if (!isARM)
2274b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_fabsf);
228e5bb58b1SEvandro Menezes     TLI.setUnavailable(LibFunc_frexpf);
229e5bb58b1SEvandro Menezes     TLI.setUnavailable(LibFunc_ldexpf);
230e5bb58b1SEvandro Menezes 
231f4a36959SEvandro Menezes     // Win32 does not support long double C89 math functions.
23298f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_acosl);
23398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_asinl);
23498f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_atan2l);
235f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_atanl);
23698f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_ceill);
23798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_cosl);
23898f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_coshl);
23998f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_expl);
24098f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_fabsl);
24198f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_floorl);
24298f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_fmodl);
24398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_frexpl);
24498f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_ldexpl);
2454b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log10l);
246f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_logl);
24798f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_modfl);
24898f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_powl);
24998f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sinl);
25098f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sinhl);
25198f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_sqrtl);
25298f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_tanl);
25398f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_tanhl);
25462d4215bSChandler Carruth 
255e5bb58b1SEvandro Menezes     // Win32 does not fully support C99 math functions.
2564b86c474SEvandro Menezes     if (!hasPartialC99) {
25798f356cdSEvandro Menezes       TLI.setUnavailable(LibFunc_acosh);
2584b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_acoshf);
259f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_asinh);
2604b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_asinhf);
261f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_atanh);
2624b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_atanhf);
263f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
2644b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_cabsf);
265f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_cbrt);
2664b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_cbrtf);
267f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
268f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
269f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_exp2);
2704b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_exp2f);
271f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_expm1);
2724b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_expm1f);
273f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmax);
274f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmaxf);
275f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fmin);
276f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_fminf);
277f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_log1p);
2784b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_log1pf);
279f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_log2);
2804b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_log2f);
281f4a36959SEvandro Menezes       TLI.setAvailableWithName(LibFunc_logb, "_logb");
282f4a36959SEvandro Menezes       if (hasPartialFloat)
283f4a36959SEvandro Menezes         TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
284f4a36959SEvandro Menezes       else
2854b86c474SEvandro Menezes         TLI.setUnavailable(LibFunc_logbf);
286f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_rint);
2874b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_rintf);
288f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_round);
2894b86c474SEvandro Menezes       TLI.setUnavailable(LibFunc_roundf);
290f4a36959SEvandro Menezes       TLI.setUnavailable(LibFunc_trunc);
29198f356cdSEvandro Menezes       TLI.setUnavailable(LibFunc_truncf);
292f4a36959SEvandro Menezes     }
2934b86c474SEvandro Menezes 
2944b86c474SEvandro Menezes     // Win32 does not support long double C99 math functions.
2954b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_acoshl);
2964b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_asinhl);
2974b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_atanhl);
2984b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_cabsl);
2994b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_cbrtl);
300f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_copysignl);
3014b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_exp2l);
3024b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_expm1l);
303f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_fmaxl);
304f4a36959SEvandro Menezes     TLI.setUnavailable(LibFunc_fminl);
3054b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log1pl);
3064b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_log2l);
3074b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_logbl);
3084b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_nearbyintl);
3094b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_rintl);
3104b86c474SEvandro Menezes     TLI.setUnavailable(LibFunc_roundl);
31198f356cdSEvandro Menezes     TLI.setUnavailable(LibFunc_truncl);
31298f356cdSEvandro Menezes 
313e5bb58b1SEvandro Menezes     // Win32 does not support these functions, but
314e5bb58b1SEvandro Menezes     // they are generally available on POSIX-compliant systems.
315d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_access);
316d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcmp);
317d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcopy);
318d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bzero);
319d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chmod);
320d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chown);
321d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_closedir);
322d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ctermid);
323d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fdopen);
324d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffs);
325d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fileno);
326d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flockfile);
327d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko);
328d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat);
329d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs);
330d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello);
331d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftrylockfile);
332d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_funlockfile);
333d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getitimer);
334d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getlogin_r);
335d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getpwnam);
336d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_gettimeofday);
337d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htonl);
338d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htons);
339d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lchown);
340d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat);
341d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memccpy);
342d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_mkdir);
343d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohl);
344d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohs);
345d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open);
346d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_opendir);
347d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pclose);
348d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_popen);
349d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pread);
350d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pwrite);
351d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_read);
352d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_readlink);
353d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_realpath);
354d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_rmdir);
355d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_setitimer);
356d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat);
357d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs);
358d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpcpy);
359d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpncpy);
360d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_strcasecmp);
361d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_strncasecmp);
362d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_times);
363d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_uname);
364d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unlink);
365d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unsetenv);
366d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utime);
367d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utimes);
368d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_write);
36962d4215bSChandler Carruth   }
37062d4215bSChandler Carruth 
37162d4215bSChandler Carruth   switch (T.getOS()) {
37262d4215bSChandler Carruth   case Triple::MacOSX:
37362d4215bSChandler Carruth     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
37462d4215bSChandler Carruth     // and their names are __exp10 and __exp10f. exp10l is not available on
37562d4215bSChandler Carruth     // OS X or iOS.
376d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
37762d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 9)) {
378d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
379d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
38062d4215bSChandler Carruth     } else {
381d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
382d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
38362d4215bSChandler Carruth     }
38462d4215bSChandler Carruth     break;
38562d4215bSChandler Carruth   case Triple::IOS:
38689a6eefeSTim Northover   case Triple::TvOS:
3878b40366bSTim Northover   case Triple::WatchOS:
388d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
3898b40366bSTim Northover     if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
3908b40366bSTim Northover                            (T.isOSVersionLT(9, 0) &&
3918b40366bSTim Northover                             (T.getArch() == Triple::x86 ||
3928b40366bSTim Northover                              T.getArch() == Triple::x86_64)))) {
393d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
394d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
39562d4215bSChandler Carruth     } else {
396d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
397d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
39862d4215bSChandler Carruth     }
39962d4215bSChandler Carruth     break;
40062d4215bSChandler Carruth   case Triple::Linux:
40162d4215bSChandler Carruth     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
40262d4215bSChandler Carruth     // buggy prior to glibc version 2.18. Until this version is widely deployed
40362d4215bSChandler Carruth     // or we have a reasonable detection strategy, we cannot use exp10 reliably
40462d4215bSChandler Carruth     // on Linux.
40562d4215bSChandler Carruth     //
40662d4215bSChandler Carruth     // Fall through to disable all of them.
407cd1d5aafSJustin Bogner     LLVM_FALLTHROUGH;
40862d4215bSChandler Carruth   default:
409d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10);
410d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10f);
411d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
41262d4215bSChandler Carruth   }
41362d4215bSChandler Carruth 
41462d4215bSChandler Carruth   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
41562d4215bSChandler Carruth   // Linux (GLIBC):
41662d4215bSChandler Carruth   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
41783b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
41862d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
41962d4215bSChandler Carruth   switch (T.getOS()) {
42062d4215bSChandler Carruth   case Triple::Darwin:
42162d4215bSChandler Carruth   case Triple::MacOSX:
42262d4215bSChandler Carruth   case Triple::IOS:
42389a6eefeSTim Northover   case Triple::TvOS:
4248b40366bSTim Northover   case Triple::WatchOS:
42562d4215bSChandler Carruth   case Triple::FreeBSD:
42662d4215bSChandler Carruth   case Triple::Linux:
42762d4215bSChandler Carruth     break;
42862d4215bSChandler Carruth   default:
429d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsl);
43062d4215bSChandler Carruth   }
43162d4215bSChandler Carruth 
43262d4215bSChandler Carruth   // ffsll is available on at least FreeBSD and Linux (GLIBC):
43383b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
43462d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
43562d4215bSChandler Carruth   switch (T.getOS()) {
43689a6eefeSTim Northover   case Triple::Darwin:
43789a6eefeSTim Northover   case Triple::MacOSX:
43889a6eefeSTim Northover   case Triple::IOS:
43989a6eefeSTim Northover   case Triple::TvOS:
44089a6eefeSTim Northover   case Triple::WatchOS:
44162d4215bSChandler Carruth   case Triple::FreeBSD:
44262d4215bSChandler Carruth   case Triple::Linux:
44362d4215bSChandler Carruth     break;
44462d4215bSChandler Carruth   default:
445d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsll);
44662d4215bSChandler Carruth   }
44762d4215bSChandler Carruth 
448bfd3082eSDavide Italiano   // The following functions are available on at least FreeBSD:
449bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
450bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
451bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
452bfd3082eSDavide Italiano   if (!T.isOSFreeBSD()) {
453d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fls);
454d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsl);
455d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsll);
456bfd3082eSDavide Italiano   }
457bfd3082eSDavide Italiano 
458e3a5fc6dSEli Friedman   // The following functions are only available on GNU/Linux (using glibc).
459e3a5fc6dSEli Friedman   // Linux variants without glibc (eg: bionic, musl) may have some subset.
460e3a5fc6dSEli Friedman   if (!T.isOSLinux() || !T.isGNUEnvironment()) {
461d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strdup);
462d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strtok_r);
463d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
464d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
465d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_getc);
466d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_putc);
467e3a5fc6dSEli Friedman     // But, Android and musl have memalign.
468e3a5fc6dSEli Friedman     if (!T.isAndroid() && !T.isMusl())
469d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memalign);
470d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fopen64);
471d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko64);
472d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat64);
473d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs64);
474d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello64);
475d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat64);
476d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open64);
477d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat64);
478d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs64);
479d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_tmpfile64);
48052149f03SSanjay Patel 
48152149f03SSanjay Patel     // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
48252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acos_finite);
48352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosf_finite);
48452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosl_finite);
48552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosh_finite);
48652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshf_finite);
48752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshl_finite);
48852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asin_finite);
48952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinf_finite);
49052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinl_finite);
49152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2_finite);
49252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2f_finite);
49352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2l_finite);
49452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanh_finite);
49552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhf_finite);
49652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhl_finite);
49752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_cosh_finite);
49852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshf_finite);
49952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshl_finite);
50052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10_finite);
50152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10f_finite);
50252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10l_finite);
50352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2_finite);
50452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2f_finite);
50552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2l_finite);
50652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp_finite);
50752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expf_finite);
50852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expl_finite);
50952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10_finite);
51052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10f_finite);
51152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10l_finite);
51252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2_finite);
51352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2f_finite);
51452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2l_finite);
51552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log_finite);
51652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logf_finite);
51752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logl_finite);
51852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_pow_finite);
51952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powf_finite);
52052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powl_finite);
52152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinh_finite);
52252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhf_finite);
52352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhl_finite);
52462d4215bSChandler Carruth   }
5256d8a2aa9SMichael Zolotukhin 
526c1078872SMartin Storsjo   if ((T.isOSLinux() && T.isGNUEnvironment()) ||
527c1078872SMartin Storsjo       (T.isAndroid() && !T.isAndroidVersionLT(28))) {
528ca22d427SDavid Bolvansky     // available IO unlocked variants on GNU/Linux and Android P or later
529ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getc_unlocked);
530ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_getchar_unlocked);
531ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putc_unlocked);
532ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_putchar_unlocked);
533ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fputc_unlocked);
534ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fgetc_unlocked);
535ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fread_unlocked);
536ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fwrite_unlocked);
537ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fputs_unlocked);
538ca22d427SDavid Bolvansky     TLI.setAvailable(LibFunc_fgets_unlocked);
539ca22d427SDavid Bolvansky   }
540ca22d427SDavid Bolvansky 
54151132881SJustin Lebar   // As currently implemented in clang, NVPTX code has no standard library to
54251132881SJustin Lebar   // speak of.  Headers provide a standard-ish library implementation, but many
54351132881SJustin Lebar   // of the signatures are wrong -- for example, many libm functions are not
54451132881SJustin Lebar   // extern "C".
54551132881SJustin Lebar   //
54651132881SJustin Lebar   // libdevice, an IR library provided by nvidia, is linked in by the front-end,
54751132881SJustin Lebar   // but only used functions are provided to llvm.  Moreover, most of the
54851132881SJustin Lebar   // functions in libdevice don't map precisely to standard library functions.
54951132881SJustin Lebar   //
55051132881SJustin Lebar   // FIXME: Having no standard library prevents e.g. many fastmath
55151132881SJustin Lebar   // optimizations, so this situation should be fixed.
552ae272d71SDavid Majnemer   if (T.isNVPTX()) {
55351132881SJustin Lebar     TLI.disableAllFunctions();
554d21529faSDavid L. Jones     TLI.setAvailable(LibFunc_nvvm_reflect);
555ae272d71SDavid Majnemer   } else {
556d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nvvm_reflect);
557ae272d71SDavid Majnemer   }
55851132881SJustin Lebar 
5596d8a2aa9SMichael Zolotukhin   TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
56062d4215bSChandler Carruth }
56162d4215bSChandler Carruth 
562c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
56362d4215bSChandler Carruth   // Default to everything being available.
56462d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
56562d4215bSChandler Carruth 
56662d4215bSChandler Carruth   initialize(*this, Triple(), StandardNames);
56762d4215bSChandler Carruth }
56862d4215bSChandler Carruth 
5697459398aSJoel Jones TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
57062d4215bSChandler Carruth   // Default to everything being available.
57162d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
57262d4215bSChandler Carruth 
57362d4215bSChandler Carruth   initialize(*this, T, StandardNames);
57462d4215bSChandler Carruth }
57562d4215bSChandler Carruth 
576c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
5777459398aSJoel Jones     : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
5785ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
5795ae2c526SMarcin Koscielnicki       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
58062d4215bSChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
581e8f2551fSMichael Zolotukhin   VectorDescs = TLI.VectorDescs;
582e8f2551fSMichael Zolotukhin   ScalarDescs = TLI.ScalarDescs;
5838ca43224SChandler Carruth }
5848ca43224SChandler Carruth 
585c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
5867459398aSJoel Jones     : CustomNames(std::move(TLI.CustomNames)),
5875ae2c526SMarcin Koscielnicki       ShouldExtI32Param(TLI.ShouldExtI32Param),
5885ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
5895ae2c526SMarcin Koscielnicki       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
5908ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
5918ca43224SChandler Carruth             AvailableArray);
592e8f2551fSMichael Zolotukhin   VectorDescs = TLI.VectorDescs;
593e8f2551fSMichael Zolotukhin   ScalarDescs = TLI.ScalarDescs;
5948ca43224SChandler Carruth }
5958ca43224SChandler Carruth 
596c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
59762d4215bSChandler Carruth   CustomNames = TLI.CustomNames;
5985ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
5995ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
6005ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
6018ca43224SChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
6028ca43224SChandler Carruth   return *this;
6038ca43224SChandler Carruth }
6048ca43224SChandler Carruth 
605c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
6068ca43224SChandler Carruth   CustomNames = std::move(TLI.CustomNames);
6075ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
6085ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
6095ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
6108ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
6118ca43224SChandler Carruth             AvailableArray);
6128ca43224SChandler Carruth   return *this;
61362d4215bSChandler Carruth }
61462d4215bSChandler Carruth 
61521abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) {
61662d4215bSChandler Carruth   // Filter out empty names and names containing null bytes, those can't be in
61762d4215bSChandler Carruth   // our table.
61862d4215bSChandler Carruth   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
61921abdf98SMichael Zolotukhin     return StringRef();
62062d4215bSChandler Carruth 
62162d4215bSChandler Carruth   // Check for \01 prefix that is used to mangle __asm declarations and
62262d4215bSChandler Carruth   // strip it if present.
6236f0ecca3SPeter Collingbourne   return GlobalValue::dropLLVMManglingEscape(funcName);
62421abdf98SMichael Zolotukhin }
62521abdf98SMichael Zolotukhin 
62621abdf98SMichael Zolotukhin bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
627d21529faSDavid L. Jones                                        LibFunc &F) const {
6289a72cd7bSMehdi Amini   StringRef const *Start = &StandardNames[0];
629d21529faSDavid L. Jones   StringRef const *End = &StandardNames[NumLibFuncs];
63021abdf98SMichael Zolotukhin 
63121abdf98SMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
63221abdf98SMichael Zolotukhin   if (funcName.empty())
63321abdf98SMichael Zolotukhin     return false;
63421abdf98SMichael Zolotukhin 
6359a72cd7bSMehdi Amini   StringRef const *I = std::lower_bound(
6369a72cd7bSMehdi Amini       Start, End, funcName, [](StringRef LHS, StringRef RHS) {
6379a72cd7bSMehdi Amini         return LHS < RHS;
638d3b76a3bSMichael Zolotukhin       });
63962d4215bSChandler Carruth   if (I != End && *I == funcName) {
640d21529faSDavid L. Jones     F = (LibFunc)(I - Start);
64162d4215bSChandler Carruth     return true;
64262d4215bSChandler Carruth   }
64362d4215bSChandler Carruth   return false;
64462d4215bSChandler Carruth }
64562d4215bSChandler Carruth 
646d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
647d21529faSDavid L. Jones                                                    LibFunc F,
648d765a82bSAhmed Bougacha                                                    const DataLayout *DL) const {
649d765a82bSAhmed Bougacha   LLVMContext &Ctx = FTy.getContext();
650d765a82bSAhmed Bougacha   Type *PCharTy = Type::getInt8PtrTy(Ctx);
651d765a82bSAhmed Bougacha   Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
652d765a82bSAhmed Bougacha   auto IsSizeTTy = [SizeTTy](Type *Ty) {
653d765a82bSAhmed Bougacha     return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
654d765a82bSAhmed Bougacha   };
655d765a82bSAhmed Bougacha   unsigned NumParams = FTy.getNumParams();
656d765a82bSAhmed Bougacha 
657d765a82bSAhmed Bougacha   switch (F) {
658c3bed1e8SCalixte Denizet   case LibFunc_execl:
659c3bed1e8SCalixte Denizet   case LibFunc_execlp:
6608f07efc7SCalixte Denizet   case LibFunc_execle:
661c3bed1e8SCalixte Denizet     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
662c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
663c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
664c3bed1e8SCalixte Denizet   case LibFunc_execv:
665c3bed1e8SCalixte Denizet   case LibFunc_execvp:
666c3bed1e8SCalixte Denizet     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
667c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
668c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
669c3bed1e8SCalixte Denizet   case LibFunc_execvP:
670c3bed1e8SCalixte Denizet   case LibFunc_execvpe:
671c3bed1e8SCalixte Denizet   case LibFunc_execve:
672c3bed1e8SCalixte Denizet     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
673c3bed1e8SCalixte Denizet             FTy.getParamType(1)->isPointerTy() &&
674c3bed1e8SCalixte Denizet             FTy.getParamType(2)->isPointerTy() &&
675c3bed1e8SCalixte Denizet             FTy.getReturnType()->isIntegerTy(32));
676d21529faSDavid L. Jones   case LibFunc_strlen:
677d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
678d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
679d765a82bSAhmed Bougacha 
680d21529faSDavid L. Jones   case LibFunc_strchr:
681d21529faSDavid L. Jones   case LibFunc_strrchr:
682d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
683d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
684d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy());
685d765a82bSAhmed Bougacha 
686d21529faSDavid L. Jones   case LibFunc_strtol:
687d21529faSDavid L. Jones   case LibFunc_strtod:
688d21529faSDavid L. Jones   case LibFunc_strtof:
689d21529faSDavid L. Jones   case LibFunc_strtoul:
690d21529faSDavid L. Jones   case LibFunc_strtoll:
691d21529faSDavid L. Jones   case LibFunc_strtold:
692d21529faSDavid L. Jones   case LibFunc_strtoull:
693d765a82bSAhmed Bougacha     return ((NumParams == 2 || NumParams == 3) &&
694d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
695d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
696abb2a93cSErik Pilkington   case LibFunc_strcat_chk:
697abb2a93cSErik Pilkington     --NumParams;
698abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
699abb2a93cSErik Pilkington       return false;
700abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
701d21529faSDavid L. Jones   case LibFunc_strcat:
702d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
703d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
704d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType());
705d765a82bSAhmed Bougacha 
706abb2a93cSErik Pilkington   case LibFunc_strncat_chk:
707abb2a93cSErik Pilkington     --NumParams;
708abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
709abb2a93cSErik Pilkington       return false;
710abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
711d21529faSDavid L. Jones   case LibFunc_strncat:
712d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
713d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
714d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType() &&
7157bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
716d765a82bSAhmed Bougacha 
717d21529faSDavid L. Jones   case LibFunc_strcpy_chk:
718d21529faSDavid L. Jones   case LibFunc_stpcpy_chk:
719d765a82bSAhmed Bougacha     --NumParams;
720d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
721d765a82bSAhmed Bougacha       return false;
722b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
723d21529faSDavid L. Jones   case LibFunc_strcpy:
724d21529faSDavid L. Jones   case LibFunc_stpcpy:
725d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
726d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
727d765a82bSAhmed Bougacha             FTy.getParamType(0) == PCharTy);
728d765a82bSAhmed Bougacha 
729abb2a93cSErik Pilkington   case LibFunc_strlcat_chk:
730abb2a93cSErik Pilkington   case LibFunc_strlcpy_chk:
731abb2a93cSErik Pilkington     --NumParams;
732abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
733abb2a93cSErik Pilkington       return false;
734abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
735abb2a93cSErik Pilkington   case LibFunc_strlcat:
736abb2a93cSErik Pilkington   case LibFunc_strlcpy:
737abb2a93cSErik Pilkington     return NumParams == 3 && IsSizeTTy(FTy.getReturnType()) &&
738abb2a93cSErik Pilkington            FTy.getParamType(0)->isPointerTy() &&
739abb2a93cSErik Pilkington            FTy.getParamType(1)->isPointerTy() &&
740abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2));
741abb2a93cSErik Pilkington 
742d21529faSDavid L. Jones   case LibFunc_strncpy_chk:
743d21529faSDavid L. Jones   case LibFunc_stpncpy_chk:
744d765a82bSAhmed Bougacha     --NumParams;
745d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
746d765a82bSAhmed Bougacha       return false;
747b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
748d21529faSDavid L. Jones   case LibFunc_strncpy:
749d21529faSDavid L. Jones   case LibFunc_stpncpy:
750d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
751d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
752d765a82bSAhmed Bougacha             FTy.getParamType(0) == PCharTy &&
7537bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
754d765a82bSAhmed Bougacha 
755d21529faSDavid L. Jones   case LibFunc_strxfrm:
756d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
757d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
758d765a82bSAhmed Bougacha 
759d21529faSDavid L. Jones   case LibFunc_strcmp:
760d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
761d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
762d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
763d765a82bSAhmed Bougacha 
764d21529faSDavid L. Jones   case LibFunc_strncmp:
765d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
766d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
767d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
7687bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
769d765a82bSAhmed Bougacha 
770d21529faSDavid L. Jones   case LibFunc_strspn:
771d21529faSDavid L. Jones   case LibFunc_strcspn:
772d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
773d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
774d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
775d765a82bSAhmed Bougacha 
776d21529faSDavid L. Jones   case LibFunc_strcoll:
777d21529faSDavid L. Jones   case LibFunc_strcasecmp:
778d21529faSDavid L. Jones   case LibFunc_strncasecmp:
779d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
780d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
781d765a82bSAhmed Bougacha 
782d21529faSDavid L. Jones   case LibFunc_strstr:
783d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
784d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
785d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
786d765a82bSAhmed Bougacha 
787d21529faSDavid L. Jones   case LibFunc_strpbrk:
788d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
789d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
790d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
791d765a82bSAhmed Bougacha 
792d21529faSDavid L. Jones   case LibFunc_strtok:
793d21529faSDavid L. Jones   case LibFunc_strtok_r:
794d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
795d21529faSDavid L. Jones   case LibFunc_scanf:
796d21529faSDavid L. Jones   case LibFunc_setbuf:
797d21529faSDavid L. Jones   case LibFunc_setvbuf:
798d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
799d21529faSDavid L. Jones   case LibFunc_strdup:
800d21529faSDavid L. Jones   case LibFunc_strndup:
801d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
802d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
803d21529faSDavid L. Jones   case LibFunc_sscanf:
804d21529faSDavid L. Jones   case LibFunc_stat:
805d21529faSDavid L. Jones   case LibFunc_statvfs:
806d21529faSDavid L. Jones   case LibFunc_siprintf:
807b4f9991fSAlon Zakai   case LibFunc_small_sprintf:
808d21529faSDavid L. Jones   case LibFunc_sprintf:
809d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
8100d7c3775SMartin Storsjo             FTy.getParamType(1)->isPointerTy() &&
8110d7c3775SMartin Storsjo             FTy.getReturnType()->isIntegerTy(32));
812abb2a93cSErik Pilkington 
813abb2a93cSErik Pilkington   case LibFunc_sprintf_chk:
814abb2a93cSErik Pilkington     return NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
815abb2a93cSErik Pilkington            FTy.getParamType(1)->isIntegerTy(32) &&
816abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2)) &&
817abb2a93cSErik Pilkington            FTy.getParamType(3)->isPointerTy() &&
818abb2a93cSErik Pilkington            FTy.getReturnType()->isIntegerTy(32);
819abb2a93cSErik Pilkington 
820d21529faSDavid L. Jones   case LibFunc_snprintf:
821d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
8220d7c3775SMartin Storsjo             FTy.getParamType(2)->isPointerTy() &&
8230d7c3775SMartin Storsjo             FTy.getReturnType()->isIntegerTy(32));
824abb2a93cSErik Pilkington 
825abb2a93cSErik Pilkington   case LibFunc_snprintf_chk:
826abb2a93cSErik Pilkington     return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
827abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(1)) &&
828abb2a93cSErik Pilkington            FTy.getParamType(2)->isIntegerTy(32) &&
829abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(3)) &&
830abb2a93cSErik Pilkington            FTy.getParamType(4)->isPointerTy() &&
831abb2a93cSErik Pilkington            FTy.getReturnType()->isIntegerTy(32);
832abb2a93cSErik Pilkington 
833d21529faSDavid L. Jones   case LibFunc_setitimer:
834d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
835d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
836d21529faSDavid L. Jones   case LibFunc_system:
837d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
838d21529faSDavid L. Jones   case LibFunc_malloc:
839d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
840d21529faSDavid L. Jones   case LibFunc_memcmp:
8416b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
8426b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
8436b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
844d765a82bSAhmed Bougacha 
845d21529faSDavid L. Jones   case LibFunc_memchr:
846d21529faSDavid L. Jones   case LibFunc_memrchr:
8476b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
8486b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
849d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32) &&
8506b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
851d21529faSDavid L. Jones   case LibFunc_modf:
852d21529faSDavid L. Jones   case LibFunc_modff:
853d21529faSDavid L. Jones   case LibFunc_modfl:
854d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
855d765a82bSAhmed Bougacha 
856d21529faSDavid L. Jones   case LibFunc_memcpy_chk:
857d21529faSDavid L. Jones   case LibFunc_memmove_chk:
858d765a82bSAhmed Bougacha     --NumParams;
859d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
860d765a82bSAhmed Bougacha       return false;
861b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
862d21529faSDavid L. Jones   case LibFunc_memcpy:
863d21529faSDavid L. Jones   case LibFunc_mempcpy:
864d21529faSDavid L. Jones   case LibFunc_memmove:
865d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
866d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
867d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
868d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
869d765a82bSAhmed Bougacha 
870d21529faSDavid L. Jones   case LibFunc_memset_chk:
871d765a82bSAhmed Bougacha     --NumParams;
872d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
873d765a82bSAhmed Bougacha       return false;
874b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
875d21529faSDavid L. Jones   case LibFunc_memset:
876d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
877d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
878d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
879d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
880d765a82bSAhmed Bougacha 
881abb2a93cSErik Pilkington   case LibFunc_memccpy_chk:
882abb2a93cSErik Pilkington       --NumParams;
883abb2a93cSErik Pilkington     if (!IsSizeTTy(FTy.getParamType(NumParams)))
884abb2a93cSErik Pilkington       return false;
885abb2a93cSErik Pilkington     LLVM_FALLTHROUGH;
886d21529faSDavid L. Jones   case LibFunc_memccpy:
887d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
888d21529faSDavid L. Jones   case LibFunc_memalign:
889d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
890d21529faSDavid L. Jones   case LibFunc_realloc:
891d21529faSDavid L. Jones   case LibFunc_reallocf:
8926b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
8936b9be1dbSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
8946b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(1)));
895d21529faSDavid L. Jones   case LibFunc_read:
896d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
897d21529faSDavid L. Jones   case LibFunc_rewind:
898d21529faSDavid L. Jones   case LibFunc_rmdir:
899d21529faSDavid L. Jones   case LibFunc_remove:
900d21529faSDavid L. Jones   case LibFunc_realpath:
901d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
902d21529faSDavid L. Jones   case LibFunc_rename:
903d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
904d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
905d21529faSDavid L. Jones   case LibFunc_readlink:
906d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
907d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
908d21529faSDavid L. Jones   case LibFunc_write:
909d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
910d21529faSDavid L. Jones   case LibFunc_bcopy:
911d21529faSDavid L. Jones   case LibFunc_bcmp:
912d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
913d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
914d21529faSDavid L. Jones   case LibFunc_bzero:
915d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
916d21529faSDavid L. Jones   case LibFunc_calloc:
917d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
9181fe3f1caSAhmed Bougacha 
919d21529faSDavid L. Jones   case LibFunc_atof:
920d21529faSDavid L. Jones   case LibFunc_atoi:
921d21529faSDavid L. Jones   case LibFunc_atol:
922d21529faSDavid L. Jones   case LibFunc_atoll:
923d21529faSDavid L. Jones   case LibFunc_ferror:
924d21529faSDavid L. Jones   case LibFunc_getenv:
925d21529faSDavid L. Jones   case LibFunc_getpwnam:
926d21529faSDavid L. Jones   case LibFunc_iprintf:
927b4f9991fSAlon Zakai   case LibFunc_small_printf:
928d21529faSDavid L. Jones   case LibFunc_pclose:
929d21529faSDavid L. Jones   case LibFunc_perror:
930d21529faSDavid L. Jones   case LibFunc_printf:
931d21529faSDavid L. Jones   case LibFunc_puts:
932d21529faSDavid L. Jones   case LibFunc_uname:
933d21529faSDavid L. Jones   case LibFunc_under_IO_getc:
934d21529faSDavid L. Jones   case LibFunc_unlink:
935d21529faSDavid L. Jones   case LibFunc_unsetenv:
936d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
9371fe3f1caSAhmed Bougacha 
938d21529faSDavid L. Jones   case LibFunc_access:
939d21529faSDavid L. Jones   case LibFunc_chmod:
940d21529faSDavid L. Jones   case LibFunc_chown:
941d21529faSDavid L. Jones   case LibFunc_clearerr:
942d21529faSDavid L. Jones   case LibFunc_closedir:
943d21529faSDavid L. Jones   case LibFunc_ctermid:
944d21529faSDavid L. Jones   case LibFunc_fclose:
945d21529faSDavid L. Jones   case LibFunc_feof:
946d21529faSDavid L. Jones   case LibFunc_fflush:
947d21529faSDavid L. Jones   case LibFunc_fgetc:
948ca22d427SDavid Bolvansky   case LibFunc_fgetc_unlocked:
949d21529faSDavid L. Jones   case LibFunc_fileno:
950d21529faSDavid L. Jones   case LibFunc_flockfile:
951d21529faSDavid L. Jones   case LibFunc_free:
952d21529faSDavid L. Jones   case LibFunc_fseek:
953d21529faSDavid L. Jones   case LibFunc_fseeko64:
954d21529faSDavid L. Jones   case LibFunc_fseeko:
955d21529faSDavid L. Jones   case LibFunc_fsetpos:
956d21529faSDavid L. Jones   case LibFunc_ftell:
957d21529faSDavid L. Jones   case LibFunc_ftello64:
958d21529faSDavid L. Jones   case LibFunc_ftello:
959d21529faSDavid L. Jones   case LibFunc_ftrylockfile:
960d21529faSDavid L. Jones   case LibFunc_funlockfile:
961d21529faSDavid L. Jones   case LibFunc_getc:
962d21529faSDavid L. Jones   case LibFunc_getc_unlocked:
963d21529faSDavid L. Jones   case LibFunc_getlogin_r:
964d21529faSDavid L. Jones   case LibFunc_mkdir:
965d21529faSDavid L. Jones   case LibFunc_mktime:
966d21529faSDavid L. Jones   case LibFunc_times:
9671fe3f1caSAhmed Bougacha     return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
9681fe3f1caSAhmed Bougacha 
969d21529faSDavid L. Jones   case LibFunc_fopen:
970d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
971d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
972d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
973c3bed1e8SCalixte Denizet   case LibFunc_fork:
974c3bed1e8SCalixte Denizet     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
975d21529faSDavid L. Jones   case LibFunc_fdopen:
976d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
977d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
978d21529faSDavid L. Jones   case LibFunc_fputc:
979ca22d427SDavid Bolvansky   case LibFunc_fputc_unlocked:
980d21529faSDavid L. Jones   case LibFunc_fstat:
981d21529faSDavid L. Jones   case LibFunc_frexp:
982d21529faSDavid L. Jones   case LibFunc_frexpf:
983d21529faSDavid L. Jones   case LibFunc_frexpl:
984d21529faSDavid L. Jones   case LibFunc_fstatvfs:
985d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
986d21529faSDavid L. Jones   case LibFunc_fgets:
987ca22d427SDavid Bolvansky   case LibFunc_fgets_unlocked:
988d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
989d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
990d21529faSDavid L. Jones   case LibFunc_fread:
991ca22d427SDavid Bolvansky   case LibFunc_fread_unlocked:
992d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
993d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
994d21529faSDavid L. Jones   case LibFunc_fwrite:
995ca22d427SDavid Bolvansky   case LibFunc_fwrite_unlocked:
996d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
997d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
998d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
999d765a82bSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy() &&
1000d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
1001d21529faSDavid L. Jones   case LibFunc_fputs:
1002ca22d427SDavid Bolvansky   case LibFunc_fputs_unlocked:
1003d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1004d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1005d21529faSDavid L. Jones   case LibFunc_fscanf:
1006d21529faSDavid L. Jones   case LibFunc_fiprintf:
1007b4f9991fSAlon Zakai   case LibFunc_small_fprintf:
1008d21529faSDavid L. Jones   case LibFunc_fprintf:
10096b9be1dbSAhmed Bougacha     return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
10106b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1011d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1012d21529faSDavid L. Jones   case LibFunc_fgetpos:
1013d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1014d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1015d21529faSDavid L. Jones   case LibFunc_getchar:
1016ca22d427SDavid Bolvansky   case LibFunc_getchar_unlocked:
10176b9be1dbSAhmed Bougacha     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
1018d21529faSDavid L. Jones   case LibFunc_gets:
10196b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
1020d21529faSDavid L. Jones   case LibFunc_getitimer:
1021d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1022d21529faSDavid L. Jones   case LibFunc_ungetc:
1023d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1024d21529faSDavid L. Jones   case LibFunc_utime:
1025d21529faSDavid L. Jones   case LibFunc_utimes:
1026d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1027d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1028d21529faSDavid L. Jones   case LibFunc_putc:
1029ca22d427SDavid Bolvansky   case LibFunc_putc_unlocked:
1030d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1031d21529faSDavid L. Jones   case LibFunc_pread:
1032d21529faSDavid L. Jones   case LibFunc_pwrite:
1033d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
1034d21529faSDavid L. Jones   case LibFunc_popen:
1035d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1036d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1037d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1038d21529faSDavid L. Jones   case LibFunc_vscanf:
1039d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1040d21529faSDavid L. Jones   case LibFunc_vsscanf:
1041d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1042d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1043d21529faSDavid L. Jones   case LibFunc_vfscanf:
1044d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1045d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1046d21529faSDavid L. Jones   case LibFunc_valloc:
1047d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1048d21529faSDavid L. Jones   case LibFunc_vprintf:
1049d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1050d21529faSDavid L. Jones   case LibFunc_vfprintf:
1051d21529faSDavid L. Jones   case LibFunc_vsprintf:
1052d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1053d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1054abb2a93cSErik Pilkington   case LibFunc_vsprintf_chk:
1055abb2a93cSErik Pilkington     return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
1056abb2a93cSErik Pilkington            FTy.getParamType(1)->isIntegerTy(32) &&
1057abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(2)) && FTy.getParamType(3)->isPointerTy();
1058d21529faSDavid L. Jones   case LibFunc_vsnprintf:
1059d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1060d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1061abb2a93cSErik Pilkington   case LibFunc_vsnprintf_chk:
1062abb2a93cSErik Pilkington     return NumParams == 6 && FTy.getParamType(0)->isPointerTy() &&
1063abb2a93cSErik Pilkington            FTy.getParamType(2)->isIntegerTy(32) &&
1064abb2a93cSErik Pilkington            IsSizeTTy(FTy.getParamType(3)) && FTy.getParamType(4)->isPointerTy();
1065d21529faSDavid L. Jones   case LibFunc_open:
1066d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1067d21529faSDavid L. Jones   case LibFunc_opendir:
1068d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
1069d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
1070d21529faSDavid L. Jones   case LibFunc_tmpfile:
1071d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1072d21529faSDavid L. Jones   case LibFunc_htonl:
1073d21529faSDavid L. Jones   case LibFunc_ntohl:
10746b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
10756b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1076d21529faSDavid L. Jones   case LibFunc_htons:
1077d21529faSDavid L. Jones   case LibFunc_ntohs:
10786b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
10796b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1080d21529faSDavid L. Jones   case LibFunc_lstat:
1081d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1082d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1083d21529faSDavid L. Jones   case LibFunc_lchown:
1084d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1085d21529faSDavid L. Jones   case LibFunc_qsort:
1086d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
1087d21529faSDavid L. Jones   case LibFunc_dunder_strdup:
1088d21529faSDavid L. Jones   case LibFunc_dunder_strndup:
1089d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
1090d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
1091d21529faSDavid L. Jones   case LibFunc_dunder_strtok_r:
1092d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1093d21529faSDavid L. Jones   case LibFunc_under_IO_putc:
1094d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1095d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_scanf:
1096d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1097d21529faSDavid L. Jones   case LibFunc_stat64:
1098d21529faSDavid L. Jones   case LibFunc_lstat64:
1099d21529faSDavid L. Jones   case LibFunc_statvfs64:
110079dcc274SMichael Kuperstein     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1101d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1102d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_sscanf:
110379dcc274SMichael Kuperstein     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1104d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1105d21529faSDavid L. Jones   case LibFunc_fopen64:
1106d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1107d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1108d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1109d21529faSDavid L. Jones   case LibFunc_tmpfile64:
1110d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
1111d21529faSDavid L. Jones   case LibFunc_fstat64:
1112d21529faSDavid L. Jones   case LibFunc_fstatvfs64:
1113d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1114d21529faSDavid L. Jones   case LibFunc_open64:
1115d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1116d21529faSDavid L. Jones   case LibFunc_gettimeofday:
1117d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1118d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
1119d765a82bSAhmed Bougacha 
11206b9be1dbSAhmed Bougacha   // new(unsigned int);
1121d21529faSDavid L. Jones   case LibFunc_Znwj:
11226b9be1dbSAhmed Bougacha   // new(unsigned long);
1123d21529faSDavid L. Jones   case LibFunc_Znwm:
11246b9be1dbSAhmed Bougacha   // new[](unsigned int);
1125d21529faSDavid L. Jones   case LibFunc_Znaj:
11266b9be1dbSAhmed Bougacha   // new[](unsigned long);
1127d21529faSDavid L. Jones   case LibFunc_Znam:
11286b9be1dbSAhmed Bougacha   // new(unsigned int);
1129d21529faSDavid L. Jones   case LibFunc_msvc_new_int:
11306b9be1dbSAhmed Bougacha   // new(unsigned long long);
1131d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong:
11326b9be1dbSAhmed Bougacha   // new[](unsigned int);
1133d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int:
11346b9be1dbSAhmed Bougacha   // new[](unsigned long long);
1135d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong:
11366b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
11376b9be1dbSAhmed Bougacha 
11386b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
1139d21529faSDavid L. Jones   case LibFunc_ZnwjRKSt9nothrow_t:
11406b9be1dbSAhmed Bougacha   // new(unsigned long, nothrow);
1141d21529faSDavid L. Jones   case LibFunc_ZnwmRKSt9nothrow_t:
11426b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
1143d21529faSDavid L. Jones   case LibFunc_ZnajRKSt9nothrow_t:
11446b9be1dbSAhmed Bougacha   // new[](unsigned long, nothrow);
1145d21529faSDavid L. Jones   case LibFunc_ZnamRKSt9nothrow_t:
11466b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
1147d21529faSDavid L. Jones   case LibFunc_msvc_new_int_nothrow:
11486b9be1dbSAhmed Bougacha   // new(unsigned long long, nothrow);
1149d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong_nothrow:
11506b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
1151d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int_nothrow:
11526b9be1dbSAhmed Bougacha   // new[](unsigned long long, nothrow);
1153d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong_nothrow:
115496bbec79SEric Fiselier   // new(unsigned int, align_val_t)
115596bbec79SEric Fiselier   case LibFunc_ZnwjSt11align_val_t:
115696bbec79SEric Fiselier   // new(unsigned long, align_val_t)
115796bbec79SEric Fiselier   case LibFunc_ZnwmSt11align_val_t:
115896bbec79SEric Fiselier   // new[](unsigned int, align_val_t)
115996bbec79SEric Fiselier   case LibFunc_ZnajSt11align_val_t:
116096bbec79SEric Fiselier   // new[](unsigned long, align_val_t)
116196bbec79SEric Fiselier   case LibFunc_ZnamSt11align_val_t:
11626b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
11636b9be1dbSAhmed Bougacha 
116496bbec79SEric Fiselier   // new(unsigned int, align_val_t, nothrow)
116596bbec79SEric Fiselier   case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
116696bbec79SEric Fiselier   // new(unsigned long, align_val_t, nothrow)
116796bbec79SEric Fiselier   case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
116896bbec79SEric Fiselier   // new[](unsigned int, align_val_t, nothrow)
116996bbec79SEric Fiselier   case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
117096bbec79SEric Fiselier   // new[](unsigned long, align_val_t, nothrow)
117196bbec79SEric Fiselier   case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
117296bbec79SEric Fiselier     return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
117396bbec79SEric Fiselier 
11746b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1175d21529faSDavid L. Jones   case LibFunc_ZdaPv:
11766b9be1dbSAhmed Bougacha   // void operator delete(void*);
1177d21529faSDavid L. Jones   case LibFunc_ZdlPv:
11786b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1179d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32:
11806b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1181d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64:
11826b9be1dbSAhmed Bougacha   // void operator delete(void*);
1183d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32:
11846b9be1dbSAhmed Bougacha   // void operator delete(void*);
1185d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64:
11866b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
11876b9be1dbSAhmed Bougacha 
11886b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1189d21529faSDavid L. Jones   case LibFunc_ZdaPvRKSt9nothrow_t:
11906b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1191d21529faSDavid L. Jones   case LibFunc_ZdaPvj:
11926b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long);
1193d21529faSDavid L. Jones   case LibFunc_ZdaPvm:
11946b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1195d21529faSDavid L. Jones   case LibFunc_ZdlPvRKSt9nothrow_t:
11966b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1197d21529faSDavid L. Jones   case LibFunc_ZdlPvj:
11986b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long);
1199d21529faSDavid L. Jones   case LibFunc_ZdlPvm:
120096bbec79SEric Fiselier   // void operator delete(void*, align_val_t)
120196bbec79SEric Fiselier   case LibFunc_ZdlPvSt11align_val_t:
120296bbec79SEric Fiselier   // void operator delete[](void*, align_val_t)
120396bbec79SEric Fiselier   case LibFunc_ZdaPvSt11align_val_t:
12046b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1205d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_int:
12066b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1207d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_nothrow:
12086b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long long);
1209d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_longlong:
12106b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1211d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_nothrow:
12126b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1213d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_int:
12146b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1215d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_nothrow:
12166b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long long);
1217d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_longlong:
12186b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1219d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_nothrow:
12206b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1221d765a82bSAhmed Bougacha 
122296bbec79SEric Fiselier   // void operator delete(void*, align_val_t, nothrow)
122396bbec79SEric Fiselier   case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
122496bbec79SEric Fiselier   // void operator delete[](void*, align_val_t, nothrow)
122596bbec79SEric Fiselier   case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
122696bbec79SEric Fiselier     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
122796bbec79SEric Fiselier 
1228d21529faSDavid L. Jones   case LibFunc_memset_pattern16:
1229d765a82bSAhmed Bougacha     return (!FTy.isVarArg() && NumParams == 3 &&
12306b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
12316b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
12326b9be1dbSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy());
1233d765a82bSAhmed Bougacha 
1234d21529faSDavid L. Jones   case LibFunc_cxa_guard_abort:
1235d21529faSDavid L. Jones   case LibFunc_cxa_guard_acquire:
1236d21529faSDavid L. Jones   case LibFunc_cxa_guard_release:
1237d21529faSDavid L. Jones   case LibFunc_nvvm_reflect:
12386b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1239d765a82bSAhmed Bougacha 
1240d21529faSDavid L. Jones   case LibFunc_sincospi_stret:
1241d21529faSDavid L. Jones   case LibFunc_sincospif_stret:
12426b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
12436b9be1dbSAhmed Bougacha 
1244d21529faSDavid L. Jones   case LibFunc_acos:
12453cd8c16dSAndrew Kaylor   case LibFunc_acos_finite:
1246d21529faSDavid L. Jones   case LibFunc_acosf:
12473cd8c16dSAndrew Kaylor   case LibFunc_acosf_finite:
1248d21529faSDavid L. Jones   case LibFunc_acosh:
12493cd8c16dSAndrew Kaylor   case LibFunc_acosh_finite:
1250d21529faSDavid L. Jones   case LibFunc_acoshf:
12513cd8c16dSAndrew Kaylor   case LibFunc_acoshf_finite:
1252d21529faSDavid L. Jones   case LibFunc_acoshl:
12533cd8c16dSAndrew Kaylor   case LibFunc_acoshl_finite:
1254d21529faSDavid L. Jones   case LibFunc_acosl:
12553cd8c16dSAndrew Kaylor   case LibFunc_acosl_finite:
1256d21529faSDavid L. Jones   case LibFunc_asin:
12573cd8c16dSAndrew Kaylor   case LibFunc_asin_finite:
1258d21529faSDavid L. Jones   case LibFunc_asinf:
12593cd8c16dSAndrew Kaylor   case LibFunc_asinf_finite:
1260d21529faSDavid L. Jones   case LibFunc_asinh:
1261d21529faSDavid L. Jones   case LibFunc_asinhf:
1262d21529faSDavid L. Jones   case LibFunc_asinhl:
1263d21529faSDavid L. Jones   case LibFunc_asinl:
12643cd8c16dSAndrew Kaylor   case LibFunc_asinl_finite:
1265d21529faSDavid L. Jones   case LibFunc_atan:
1266d21529faSDavid L. Jones   case LibFunc_atanf:
1267d21529faSDavid L. Jones   case LibFunc_atanh:
12683cd8c16dSAndrew Kaylor   case LibFunc_atanh_finite:
1269d21529faSDavid L. Jones   case LibFunc_atanhf:
12703cd8c16dSAndrew Kaylor   case LibFunc_atanhf_finite:
1271d21529faSDavid L. Jones   case LibFunc_atanhl:
12723cd8c16dSAndrew Kaylor   case LibFunc_atanhl_finite:
1273d21529faSDavid L. Jones   case LibFunc_atanl:
1274d21529faSDavid L. Jones   case LibFunc_cbrt:
1275d21529faSDavid L. Jones   case LibFunc_cbrtf:
1276d21529faSDavid L. Jones   case LibFunc_cbrtl:
1277d21529faSDavid L. Jones   case LibFunc_ceil:
1278d21529faSDavid L. Jones   case LibFunc_ceilf:
1279d21529faSDavid L. Jones   case LibFunc_ceill:
1280d21529faSDavid L. Jones   case LibFunc_cos:
1281d21529faSDavid L. Jones   case LibFunc_cosf:
1282d21529faSDavid L. Jones   case LibFunc_cosh:
12833cd8c16dSAndrew Kaylor   case LibFunc_cosh_finite:
1284d21529faSDavid L. Jones   case LibFunc_coshf:
12853cd8c16dSAndrew Kaylor   case LibFunc_coshf_finite:
1286d21529faSDavid L. Jones   case LibFunc_coshl:
12873cd8c16dSAndrew Kaylor   case LibFunc_coshl_finite:
1288d21529faSDavid L. Jones   case LibFunc_cosl:
1289d21529faSDavid L. Jones   case LibFunc_exp10:
12903cd8c16dSAndrew Kaylor   case LibFunc_exp10_finite:
1291d21529faSDavid L. Jones   case LibFunc_exp10f:
12923cd8c16dSAndrew Kaylor   case LibFunc_exp10f_finite:
1293d21529faSDavid L. Jones   case LibFunc_exp10l:
12943cd8c16dSAndrew Kaylor   case LibFunc_exp10l_finite:
1295d21529faSDavid L. Jones   case LibFunc_exp2:
12963cd8c16dSAndrew Kaylor   case LibFunc_exp2_finite:
1297d21529faSDavid L. Jones   case LibFunc_exp2f:
12983cd8c16dSAndrew Kaylor   case LibFunc_exp2f_finite:
1299d21529faSDavid L. Jones   case LibFunc_exp2l:
13003cd8c16dSAndrew Kaylor   case LibFunc_exp2l_finite:
1301d21529faSDavid L. Jones   case LibFunc_exp:
13023cd8c16dSAndrew Kaylor   case LibFunc_exp_finite:
1303d21529faSDavid L. Jones   case LibFunc_expf:
13043cd8c16dSAndrew Kaylor   case LibFunc_expf_finite:
1305d21529faSDavid L. Jones   case LibFunc_expl:
13063cd8c16dSAndrew Kaylor   case LibFunc_expl_finite:
1307d21529faSDavid L. Jones   case LibFunc_expm1:
1308d21529faSDavid L. Jones   case LibFunc_expm1f:
1309d21529faSDavid L. Jones   case LibFunc_expm1l:
1310d21529faSDavid L. Jones   case LibFunc_fabs:
1311d21529faSDavid L. Jones   case LibFunc_fabsf:
1312d21529faSDavid L. Jones   case LibFunc_fabsl:
1313d21529faSDavid L. Jones   case LibFunc_floor:
1314d21529faSDavid L. Jones   case LibFunc_floorf:
1315d21529faSDavid L. Jones   case LibFunc_floorl:
1316d21529faSDavid L. Jones   case LibFunc_log10:
13173cd8c16dSAndrew Kaylor   case LibFunc_log10_finite:
1318d21529faSDavid L. Jones   case LibFunc_log10f:
13193cd8c16dSAndrew Kaylor   case LibFunc_log10f_finite:
1320d21529faSDavid L. Jones   case LibFunc_log10l:
13213cd8c16dSAndrew Kaylor   case LibFunc_log10l_finite:
1322d21529faSDavid L. Jones   case LibFunc_log1p:
1323d21529faSDavid L. Jones   case LibFunc_log1pf:
1324d21529faSDavid L. Jones   case LibFunc_log1pl:
1325d21529faSDavid L. Jones   case LibFunc_log2:
13263cd8c16dSAndrew Kaylor   case LibFunc_log2_finite:
1327d21529faSDavid L. Jones   case LibFunc_log2f:
13283cd8c16dSAndrew Kaylor   case LibFunc_log2f_finite:
1329d21529faSDavid L. Jones   case LibFunc_log2l:
13303cd8c16dSAndrew Kaylor   case LibFunc_log2l_finite:
1331d21529faSDavid L. Jones   case LibFunc_log:
13323cd8c16dSAndrew Kaylor   case LibFunc_log_finite:
1333d21529faSDavid L. Jones   case LibFunc_logb:
1334d21529faSDavid L. Jones   case LibFunc_logbf:
1335d21529faSDavid L. Jones   case LibFunc_logbl:
1336d21529faSDavid L. Jones   case LibFunc_logf:
13373cd8c16dSAndrew Kaylor   case LibFunc_logf_finite:
1338d21529faSDavid L. Jones   case LibFunc_logl:
13393cd8c16dSAndrew Kaylor   case LibFunc_logl_finite:
1340d21529faSDavid L. Jones   case LibFunc_nearbyint:
1341d21529faSDavid L. Jones   case LibFunc_nearbyintf:
1342d21529faSDavid L. Jones   case LibFunc_nearbyintl:
1343d21529faSDavid L. Jones   case LibFunc_rint:
1344d21529faSDavid L. Jones   case LibFunc_rintf:
1345d21529faSDavid L. Jones   case LibFunc_rintl:
1346d21529faSDavid L. Jones   case LibFunc_round:
1347d21529faSDavid L. Jones   case LibFunc_roundf:
1348d21529faSDavid L. Jones   case LibFunc_roundl:
1349d21529faSDavid L. Jones   case LibFunc_sin:
1350d21529faSDavid L. Jones   case LibFunc_sinf:
1351d21529faSDavid L. Jones   case LibFunc_sinh:
13523cd8c16dSAndrew Kaylor   case LibFunc_sinh_finite:
1353d21529faSDavid L. Jones   case LibFunc_sinhf:
13543cd8c16dSAndrew Kaylor   case LibFunc_sinhf_finite:
1355d21529faSDavid L. Jones   case LibFunc_sinhl:
13563cd8c16dSAndrew Kaylor   case LibFunc_sinhl_finite:
1357d21529faSDavid L. Jones   case LibFunc_sinl:
1358d21529faSDavid L. Jones   case LibFunc_sqrt:
1359d21529faSDavid L. Jones   case LibFunc_sqrt_finite:
1360d21529faSDavid L. Jones   case LibFunc_sqrtf:
1361d21529faSDavid L. Jones   case LibFunc_sqrtf_finite:
1362d21529faSDavid L. Jones   case LibFunc_sqrtl:
1363d21529faSDavid L. Jones   case LibFunc_sqrtl_finite:
1364d21529faSDavid L. Jones   case LibFunc_tan:
1365d21529faSDavid L. Jones   case LibFunc_tanf:
1366d21529faSDavid L. Jones   case LibFunc_tanh:
1367d21529faSDavid L. Jones   case LibFunc_tanhf:
1368d21529faSDavid L. Jones   case LibFunc_tanhl:
1369d21529faSDavid L. Jones   case LibFunc_tanl:
1370d21529faSDavid L. Jones   case LibFunc_trunc:
1371d21529faSDavid L. Jones   case LibFunc_truncf:
1372d21529faSDavid L. Jones   case LibFunc_truncl:
1373d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1374d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1375d765a82bSAhmed Bougacha 
1376d21529faSDavid L. Jones   case LibFunc_atan2:
13773cd8c16dSAndrew Kaylor   case LibFunc_atan2_finite:
1378d21529faSDavid L. Jones   case LibFunc_atan2f:
13793cd8c16dSAndrew Kaylor   case LibFunc_atan2f_finite:
1380d21529faSDavid L. Jones   case LibFunc_atan2l:
13813cd8c16dSAndrew Kaylor   case LibFunc_atan2l_finite:
1382d21529faSDavid L. Jones   case LibFunc_fmin:
1383d21529faSDavid L. Jones   case LibFunc_fminf:
1384d21529faSDavid L. Jones   case LibFunc_fminl:
1385d21529faSDavid L. Jones   case LibFunc_fmax:
1386d21529faSDavid L. Jones   case LibFunc_fmaxf:
1387d21529faSDavid L. Jones   case LibFunc_fmaxl:
1388d21529faSDavid L. Jones   case LibFunc_fmod:
1389d21529faSDavid L. Jones   case LibFunc_fmodf:
1390d21529faSDavid L. Jones   case LibFunc_fmodl:
1391d21529faSDavid L. Jones   case LibFunc_copysign:
1392d21529faSDavid L. Jones   case LibFunc_copysignf:
1393d21529faSDavid L. Jones   case LibFunc_copysignl:
1394d21529faSDavid L. Jones   case LibFunc_pow:
13953cd8c16dSAndrew Kaylor   case LibFunc_pow_finite:
1396d21529faSDavid L. Jones   case LibFunc_powf:
13973cd8c16dSAndrew Kaylor   case LibFunc_powf_finite:
1398d21529faSDavid L. Jones   case LibFunc_powl:
13993cd8c16dSAndrew Kaylor   case LibFunc_powl_finite:
1400d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1401d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
1402d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(1));
1403d765a82bSAhmed Bougacha 
1404d21529faSDavid L. Jones   case LibFunc_ldexp:
1405d21529faSDavid L. Jones   case LibFunc_ldexpf:
1406d21529faSDavid L. Jones   case LibFunc_ldexpl:
14076b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
14086b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
14096b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32));
14106b9be1dbSAhmed Bougacha 
1411d21529faSDavid L. Jones   case LibFunc_ffs:
1412d21529faSDavid L. Jones   case LibFunc_ffsl:
1413d21529faSDavid L. Jones   case LibFunc_ffsll:
1414d21529faSDavid L. Jones   case LibFunc_fls:
1415d21529faSDavid L. Jones   case LibFunc_flsl:
1416d21529faSDavid L. Jones   case LibFunc_flsll:
141704949fafSSanjay Patel     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
141804949fafSSanjay Patel             FTy.getParamType(0)->isIntegerTy());
141904949fafSSanjay Patel 
1420d21529faSDavid L. Jones   case LibFunc_isdigit:
1421d21529faSDavid L. Jones   case LibFunc_isascii:
1422d21529faSDavid L. Jones   case LibFunc_toascii:
1423d21529faSDavid L. Jones   case LibFunc_putchar:
1424ca22d427SDavid Bolvansky   case LibFunc_putchar_unlocked:
1425d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
142604949fafSSanjay Patel             FTy.getReturnType() == FTy.getParamType(0));
1427d765a82bSAhmed Bougacha 
1428d21529faSDavid L. Jones   case LibFunc_abs:
1429d21529faSDavid L. Jones   case LibFunc_labs:
1430d21529faSDavid L. Jones   case LibFunc_llabs:
1431d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1432d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1433d765a82bSAhmed Bougacha 
1434d21529faSDavid L. Jones   case LibFunc_cxa_atexit:
1435d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1436d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1437d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
1438d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1439d765a82bSAhmed Bougacha 
1440d21529faSDavid L. Jones   case LibFunc_sinpi:
1441d21529faSDavid L. Jones   case LibFunc_cospi:
1442d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1443d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1444d765a82bSAhmed Bougacha 
1445d21529faSDavid L. Jones   case LibFunc_sinpif:
1446d21529faSDavid L. Jones   case LibFunc_cospif:
1447d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1448d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1449d765a82bSAhmed Bougacha 
1450d21529faSDavid L. Jones   case LibFunc_strnlen:
14516b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
14526b9be1dbSAhmed Bougacha             FTy.getParamType(0) == PCharTy &&
14536b9be1dbSAhmed Bougacha             FTy.getParamType(1) == SizeTTy);
14546b9be1dbSAhmed Bougacha 
1455d21529faSDavid L. Jones   case LibFunc_posix_memalign:
14566b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
14576b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
14586b9be1dbSAhmed Bougacha             FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
14596b9be1dbSAhmed Bougacha 
146060b40b8fSMatthias Braun   case LibFunc_wcslen:
146160b40b8fSMatthias Braun     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
146260b40b8fSMatthias Braun             FTy.getReturnType()->isIntegerTy());
146360b40b8fSMatthias Braun 
14642ff24731SHal Finkel   case LibFunc_cabs:
14652ff24731SHal Finkel   case LibFunc_cabsf:
14662ff24731SHal Finkel   case LibFunc_cabsl: {
14672ff24731SHal Finkel     Type* RetTy = FTy.getReturnType();
14682ff24731SHal Finkel     if (!RetTy->isFloatingPointTy())
14692ff24731SHal Finkel       return false;
14702ff24731SHal Finkel 
14712ff24731SHal Finkel     // NOTE: These prototypes are target specific and currently support
14722ff24731SHal Finkel     // "complex" passed as an array or discrete real & imaginary parameters.
14732ff24731SHal Finkel     // Add other calling conventions to enable libcall optimizations.
14742ff24731SHal Finkel     if (NumParams == 1)
14752ff24731SHal Finkel       return (FTy.getParamType(0)->isArrayTy() &&
14762ff24731SHal Finkel               FTy.getParamType(0)->getArrayNumElements() == 2 &&
14772ff24731SHal Finkel               FTy.getParamType(0)->getArrayElementType() == RetTy);
14782ff24731SHal Finkel     else if (NumParams == 2)
14792ff24731SHal Finkel       return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
14802ff24731SHal Finkel     else
14812ff24731SHal Finkel       return false;
14822ff24731SHal Finkel   }
14836b9be1dbSAhmed Bougacha   case LibFunc::NumLibFuncs:
148486b680a3SAhmed Bougacha     break;
1485d765a82bSAhmed Bougacha   }
14866b9be1dbSAhmed Bougacha 
148786b680a3SAhmed Bougacha   llvm_unreachable("Invalid libfunc");
1488d765a82bSAhmed Bougacha }
1489d765a82bSAhmed Bougacha 
1490d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1491d21529faSDavid L. Jones                                        LibFunc &F) const {
149276ea748dSPhilip Reames   // Intrinsics don't overlap w/libcalls; if our module has a large number of
149376ea748dSPhilip Reames   // intrinsics, this ends up being an interesting compile time win since we
149476ea748dSPhilip Reames   // avoid string normalization and comparison.
149576ea748dSPhilip Reames   if (FDecl.isIntrinsic()) return false;
149676ea748dSPhilip Reames 
1497d765a82bSAhmed Bougacha   const DataLayout *DL =
1498d765a82bSAhmed Bougacha       FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1499d765a82bSAhmed Bougacha   return getLibFunc(FDecl.getName(), F) &&
1500d765a82bSAhmed Bougacha          isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1501d765a82bSAhmed Bougacha }
1502d765a82bSAhmed Bougacha 
1503c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() {
150462d4215bSChandler Carruth   memset(AvailableArray, 0, sizeof(AvailableArray));
150562d4215bSChandler Carruth }
1506b98f63dbSChandler Carruth 
1507e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
15089a72cd7bSMehdi Amini   return LHS.ScalarFnName < RHS.ScalarFnName;
1509e8f2551fSMichael Zolotukhin }
1510e8f2551fSMichael Zolotukhin 
1511e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
15129a72cd7bSMehdi Amini   return LHS.VectorFnName < RHS.VectorFnName;
1513e8f2551fSMichael Zolotukhin }
1514e8f2551fSMichael Zolotukhin 
1515e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
15169a72cd7bSMehdi Amini   return LHS.ScalarFnName < S;
1517e8f2551fSMichael Zolotukhin }
1518e8f2551fSMichael Zolotukhin 
1519e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
15209a72cd7bSMehdi Amini   return LHS.VectorFnName < S;
1521e8f2551fSMichael Zolotukhin }
1522e8f2551fSMichael Zolotukhin 
1523e8f2551fSMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1524e8f2551fSMichael Zolotukhin   VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
15250cac726aSFangrui Song   llvm::sort(VectorDescs, compareByScalarFnName);
1526e8f2551fSMichael Zolotukhin 
1527e8f2551fSMichael Zolotukhin   ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
15280cac726aSFangrui Song   llvm::sort(ScalarDescs, compareByVectorFnName);
1529e8f2551fSMichael Zolotukhin }
1530e8f2551fSMichael Zolotukhin 
15316d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
15326d8a2aa9SMichael Zolotukhin     enum VectorLibrary VecLib) {
15336d8a2aa9SMichael Zolotukhin   switch (VecLib) {
15346d8a2aa9SMichael Zolotukhin   case Accelerate: {
15356d8a2aa9SMichael Zolotukhin     const VecDesc VecFuncs[] = {
1536820b9031SNemanja Ivanovic     #define TLI_DEFINE_ACCELERATE_VECFUNCS
1537820b9031SNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
15386d8a2aa9SMichael Zolotukhin     };
15396d8a2aa9SMichael Zolotukhin     addVectorizableFunctions(VecFuncs);
15406d8a2aa9SMichael Zolotukhin     break;
15416d8a2aa9SMichael Zolotukhin   }
1542fe97754aSNemanja Ivanovic   case MASSV: {
1543fe97754aSNemanja Ivanovic     const VecDesc VecFuncs[] = {
1544fe97754aSNemanja Ivanovic     #define TLI_DEFINE_MASSV_VECFUNCS
1545fe97754aSNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
1546fe97754aSNemanja Ivanovic     };
1547fe97754aSNemanja Ivanovic     addVectorizableFunctions(VecFuncs);
1548fe97754aSNemanja Ivanovic     break;
1549fe97754aSNemanja Ivanovic   }
1550a6669a1eSMatt Masten   case SVML: {
1551a6669a1eSMatt Masten     const VecDesc VecFuncs[] = {
1552820b9031SNemanja Ivanovic     #define TLI_DEFINE_SVML_VECFUNCS
1553820b9031SNemanja Ivanovic     #include "llvm/Analysis/VecFuncs.def"
1554a6669a1eSMatt Masten     };
1555a6669a1eSMatt Masten     addVectorizableFunctions(VecFuncs);
1556a6669a1eSMatt Masten     break;
1557a6669a1eSMatt Masten   }
15586d8a2aa9SMichael Zolotukhin   case NoLibrary:
15596d8a2aa9SMichael Zolotukhin     break;
15606d8a2aa9SMichael Zolotukhin   }
15616d8a2aa9SMichael Zolotukhin }
15626d8a2aa9SMichael Zolotukhin 
1563e8f2551fSMichael Zolotukhin bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1564e8f2551fSMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
1565e8f2551fSMichael Zolotukhin   if (funcName.empty())
1566e8f2551fSMichael Zolotukhin     return false;
1567e8f2551fSMichael Zolotukhin 
1568cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1569cecc4352SFangrui Song       llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1570e8f2551fSMichael Zolotukhin   return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1571e8f2551fSMichael Zolotukhin }
1572e8f2551fSMichael Zolotukhin 
1573e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1574e8f2551fSMichael Zolotukhin                                                        unsigned VF) const {
1575e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1576e8f2551fSMichael Zolotukhin   if (F.empty())
1577e8f2551fSMichael Zolotukhin     return F;
1578cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1579cecc4352SFangrui Song       llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
1580e8f2551fSMichael Zolotukhin   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1581e8f2551fSMichael Zolotukhin     if (I->VectorizationFactor == VF)
1582e8f2551fSMichael Zolotukhin       return I->VectorFnName;
1583e8f2551fSMichael Zolotukhin     ++I;
1584e8f2551fSMichael Zolotukhin   }
1585e8f2551fSMichael Zolotukhin   return StringRef();
1586e8f2551fSMichael Zolotukhin }
1587e8f2551fSMichael Zolotukhin 
1588e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1589e8f2551fSMichael Zolotukhin                                                        unsigned &VF) const {
1590e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1591e8f2551fSMichael Zolotukhin   if (F.empty())
1592e8f2551fSMichael Zolotukhin     return F;
1593e8f2551fSMichael Zolotukhin 
1594cecc4352SFangrui Song   std::vector<VecDesc>::const_iterator I =
1595cecc4352SFangrui Song       llvm::lower_bound(ScalarDescs, F, compareWithVectorFnName);
1596e8f2551fSMichael Zolotukhin   if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1597e8f2551fSMichael Zolotukhin     return StringRef();
1598e8f2551fSMichael Zolotukhin   VF = I->VectorizationFactor;
1599e8f2551fSMichael Zolotukhin   return I->ScalarFnName;
1600e8f2551fSMichael Zolotukhin }
1601e8f2551fSMichael Zolotukhin 
1602164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1603164a2aa6SChandler Carruth                                              ModuleAnalysisManager &) {
1604c0291865SChandler Carruth   if (PresetInfoImpl)
1605c0291865SChandler Carruth     return TargetLibraryInfo(*PresetInfoImpl);
1606c0291865SChandler Carruth 
1607c0291865SChandler Carruth   return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1608c0291865SChandler Carruth }
1609c0291865SChandler Carruth 
1610164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1611164a2aa6SChandler Carruth                                              FunctionAnalysisManager &) {
1612c0291865SChandler Carruth   if (PresetInfoImpl)
1613c0291865SChandler Carruth     return TargetLibraryInfo(*PresetInfoImpl);
1614c0291865SChandler Carruth 
1615c0291865SChandler Carruth   return TargetLibraryInfo(
1616c0291865SChandler Carruth       lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1617c0291865SChandler Carruth }
1618c0291865SChandler Carruth 
1619c321e534SBenjamin Kramer TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
1620c0291865SChandler Carruth   std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1621c0291865SChandler Carruth       Impls[T.normalize()];
1622c0291865SChandler Carruth   if (!Impl)
1623c0291865SChandler Carruth     Impl.reset(new TargetLibraryInfoImpl(T));
1624c0291865SChandler Carruth 
1625c0291865SChandler Carruth   return *Impl;
1626c0291865SChandler Carruth }
1627c0291865SChandler Carruth 
162850ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
162950ec0b5dSMatthias Braun   if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
163050ec0b5dSMatthias Braun       M.getModuleFlag("wchar_size")))
163150ec0b5dSMatthias Braun     return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1632cc603ee3SMatthias Braun   return 0;
163350ec0b5dSMatthias Braun }
1634c0291865SChandler Carruth 
1635b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1636c0291865SChandler Carruth     : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
1637b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1638b98f63dbSChandler Carruth }
1639b98f63dbSChandler Carruth 
1640b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
1641c0291865SChandler Carruth     : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
1642b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1643b98f63dbSChandler Carruth }
1644b98f63dbSChandler Carruth 
1645b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1646c0291865SChandler Carruth     const TargetLibraryInfoImpl &TLIImpl)
1647c0291865SChandler Carruth     : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
1648b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1649b98f63dbSChandler Carruth }
1650b98f63dbSChandler Carruth 
1651dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key;
1652df0cd726SNAKAMURA Takumi 
1653b98f63dbSChandler Carruth // Register the basic pass.
1654b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1655b98f63dbSChandler Carruth                 "Target Library Information", false, true)
1656b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0;
1657b98f63dbSChandler Carruth 
1658b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {}
1659