162d4215bSChandler Carruth //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
262d4215bSChandler Carruth //
362d4215bSChandler Carruth //                     The LLVM Compiler Infrastructure
462d4215bSChandler Carruth //
562d4215bSChandler Carruth // This file is distributed under the University of Illinois Open Source
662d4215bSChandler Carruth // License. See LICENSE.TXT for details.
762d4215bSChandler Carruth //
862d4215bSChandler Carruth //===----------------------------------------------------------------------===//
962d4215bSChandler Carruth //
1062d4215bSChandler Carruth // This file implements the TargetLibraryInfo class.
1162d4215bSChandler Carruth //
1262d4215bSChandler Carruth //===----------------------------------------------------------------------===//
1362d4215bSChandler Carruth 
1462d4215bSChandler Carruth #include "llvm/Analysis/TargetLibraryInfo.h"
1562d4215bSChandler Carruth #include "llvm/ADT/Triple.h"
1650ec0b5dSMatthias Braun #include "llvm/IR/Constants.h"
176d8a2aa9SMichael Zolotukhin #include "llvm/Support/CommandLine.h"
1862d4215bSChandler Carruth using namespace llvm;
1962d4215bSChandler Carruth 
206d8a2aa9SMichael Zolotukhin static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
216d8a2aa9SMichael Zolotukhin     "vector-library", cl::Hidden, cl::desc("Vector functions library"),
226d8a2aa9SMichael Zolotukhin     cl::init(TargetLibraryInfoImpl::NoLibrary),
236d8a2aa9SMichael Zolotukhin     cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
246d8a2aa9SMichael Zolotukhin                           "No vector functions library"),
256d8a2aa9SMichael Zolotukhin                clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
266d8a2aa9SMichael Zolotukhin                           "Accelerate framework"),
27a6669a1eSMatt Masten                clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
28732afdd0SMehdi Amini                           "Intel SVML library")));
296d8a2aa9SMichael Zolotukhin 
309a72cd7bSMehdi Amini StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
31cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING
32cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def"
3362d4215bSChandler Carruth };
3462d4215bSChandler Carruth 
3562d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) {
3662d4215bSChandler Carruth   // Only Darwin variants have _stret versions of combined trig functions.
3762d4215bSChandler Carruth   if (!T.isOSDarwin())
3862d4215bSChandler Carruth     return false;
3962d4215bSChandler Carruth 
4062d4215bSChandler Carruth   // The ABI is rather complicated on x86, so don't do anything special there.
4162d4215bSChandler Carruth   if (T.getArch() == Triple::x86)
4262d4215bSChandler Carruth     return false;
4362d4215bSChandler Carruth 
4462d4215bSChandler Carruth   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
4562d4215bSChandler Carruth     return false;
4662d4215bSChandler Carruth 
4762d4215bSChandler Carruth   if (T.isiOS() && T.isOSVersionLT(7, 0))
4862d4215bSChandler Carruth     return false;
4962d4215bSChandler Carruth 
5062d4215bSChandler Carruth   return true;
5162d4215bSChandler Carruth }
5262d4215bSChandler Carruth 
53600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified
54600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target
55600d24b4SSanjay Patel /// triple gets a sane set of defaults.
56c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
579a72cd7bSMehdi Amini                        ArrayRef<StringRef> StandardNames) {
5862d4215bSChandler Carruth   // Verify that the StandardNames array is in alphabetical order.
59e30b8ca1SCraig Topper   assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
609a72cd7bSMehdi Amini                         [](StringRef LHS, StringRef RHS) {
619a72cd7bSMehdi Amini                           return LHS < RHS;
62e30b8ca1SCraig Topper                         }) &&
63e30b8ca1SCraig Topper          "TargetLibraryInfoImpl function names must be sorted");
6462d4215bSChandler Carruth 
656af8e6c3SMarcin Koscielnicki   bool ShouldExtI32Param = false, ShouldExtI32Return = false,
666af8e6c3SMarcin Koscielnicki        ShouldSignExtI32Param = false;
676af8e6c3SMarcin Koscielnicki   // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
686af8e6c3SMarcin Koscielnicki   // returns corresponding to C-level ints and unsigned ints.
696af8e6c3SMarcin Koscielnicki   if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
706af8e6c3SMarcin Koscielnicki       T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
716af8e6c3SMarcin Koscielnicki     ShouldExtI32Param = true;
726af8e6c3SMarcin Koscielnicki     ShouldExtI32Return = true;
736af8e6c3SMarcin Koscielnicki   }
746af8e6c3SMarcin Koscielnicki   // Mips, on the other hand, needs signext on i32 parameters corresponding
756af8e6c3SMarcin Koscielnicki   // to both signed and unsigned ints.
766af8e6c3SMarcin Koscielnicki   if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
776af8e6c3SMarcin Koscielnicki       T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
786af8e6c3SMarcin Koscielnicki     ShouldSignExtI32Param = true;
796af8e6c3SMarcin Koscielnicki   }
806af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Param(ShouldExtI32Param);
816af8e6c3SMarcin Koscielnicki   TLI.setShouldExtI32Return(ShouldExtI32Return);
826af8e6c3SMarcin Koscielnicki   TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
836af8e6c3SMarcin Koscielnicki 
8478fd4f08SNicolai Hahnle   if (T.getArch() == Triple::r600 ||
8578fd4f08SNicolai Hahnle       T.getArch() == Triple::amdgcn) {
86d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexp);
87d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexpf);
88d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexpl);
89d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10);
90d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10f);
91d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
92d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log10);
93d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log10f);
94d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log10l);
9578fd4f08SNicolai Hahnle   }
9678fd4f08SNicolai Hahnle 
9762d4215bSChandler Carruth   // There are no library implementations of mempcy and memset for AMD gpus and
9862d4215bSChandler Carruth   // these can be difficult to lower in the backend.
9962d4215bSChandler Carruth   if (T.getArch() == Triple::r600 ||
10005532995SDan Gohman       T.getArch() == Triple::amdgcn) {
101d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memcpy);
102d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset);
103d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
10462d4215bSChandler Carruth     return;
10562d4215bSChandler Carruth   }
10662d4215bSChandler Carruth 
10762d4215bSChandler Carruth   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
1088b40366bSTim Northover   // All versions of watchOS support it.
10962d4215bSChandler Carruth   if (T.isMacOSX()) {
11062d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 5))
111d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
11262d4215bSChandler Carruth   } else if (T.isiOS()) {
11362d4215bSChandler Carruth     if (T.isOSVersionLT(3, 0))
114d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memset_pattern16);
1158b40366bSTim Northover   } else if (!T.isWatchOS()) {
116d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memset_pattern16);
11762d4215bSChandler Carruth   }
11862d4215bSChandler Carruth 
11962d4215bSChandler Carruth   if (!hasSinCosPiStret(T)) {
120d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpi);
121d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinpif);
122d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospi);
123d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cospif);
124d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospi_stret);
125d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sincospif_stret);
12662d4215bSChandler Carruth   }
12762d4215bSChandler Carruth 
12862d4215bSChandler Carruth   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
12962d4215bSChandler Carruth       !T.isMacOSXVersionLT(10, 7)) {
13062d4215bSChandler Carruth     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
13162d4215bSChandler Carruth     // we don't care about) have two versions; on recent OSX, the one we want
13262d4215bSChandler Carruth     // has a $UNIX2003 suffix. The two implementations are identical except
13362d4215bSChandler Carruth     // for the return value in some edge cases.  However, we don't want to
13462d4215bSChandler Carruth     // generate code that depends on the old symbols.
135d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
136d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
13762d4215bSChandler Carruth   }
13862d4215bSChandler Carruth 
13962d4215bSChandler Carruth   // iprintf and friends are only available on XCore and TCE.
14062d4215bSChandler Carruth   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
141d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_iprintf);
142d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_siprintf);
143d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fiprintf);
14462d4215bSChandler Carruth   }
14562d4215bSChandler Carruth 
14662d4215bSChandler Carruth   if (T.isOSWindows() && !T.isOSCygMing()) {
14762d4215bSChandler Carruth     // Win32 does not support long double
148d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_acosl);
149d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_asinl);
150d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_atanl);
151d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_atan2l);
152d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ceill);
153d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_copysignl);
154d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cosl);
155d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_coshl);
156d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_expl);
157d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf
158d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fabsl);
159d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_floorl);
160d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fmaxl);
161d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fminl);
162d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fmodl);
163d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_frexpl);
164d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexpf);
165d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ldexpl);
166d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_logl);
167d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_modfl);
168d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_powl);
169d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinl);
170d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sinhl);
171d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_sqrtl);
172d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_tanl);
173d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_tanhl);
17462d4215bSChandler Carruth 
17562d4215bSChandler Carruth     // Win32 only has C89 math
176d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_acosh);
177d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_acoshf);
178d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_acoshl);
179d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_asinh);
180d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_asinhf);
181d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_asinhl);
182d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_atanh);
183d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_atanhf);
184d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_atanhl);
1852ff24731SHal Finkel     TLI.setUnavailable(LibFunc_cabs);
1862ff24731SHal Finkel     TLI.setUnavailable(LibFunc_cabsf);
1872ff24731SHal Finkel     TLI.setUnavailable(LibFunc_cabsl);
188d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cbrt);
189d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cbrtf);
190d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_cbrtl);
191d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp2);
192d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp2f);
193d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp2l);
194d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_expm1);
195d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_expm1f);
196d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_expm1l);
197d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log2);
198d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log2f);
199d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log2l);
200d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log1p);
201d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log1pf);
202d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_log1pl);
203d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_logb);
204d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_logbf);
205d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_logbl);
206d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nearbyint);
207d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nearbyintf);
208d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nearbyintl);
209d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_rint);
210d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_rintf);
211d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_rintl);
212d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_round);
213d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_roundf);
214d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_roundl);
215d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_trunc);
216d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_truncf);
217d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_truncl);
21862d4215bSChandler Carruth 
21962d4215bSChandler Carruth     // Win32 provides some C99 math with mangled names
220d21529faSDavid L. Jones     TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
22162d4215bSChandler Carruth 
22262d4215bSChandler Carruth     if (T.getArch() == Triple::x86) {
22362d4215bSChandler Carruth       // Win32 on x86 implements single-precision math functions as macros
224d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_acosf);
225d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_asinf);
226d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_atanf);
227d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_atan2f);
228d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_ceilf);
229d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_copysignf);
230d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_cosf);
231d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_coshf);
232d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_expf);
233d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_floorf);
234d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_fminf);
235d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_fmaxf);
236d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_fmodf);
237d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_logf);
238d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_log10f);
239d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_modff);
240d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_powf);
241d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_sinf);
242d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_sinhf);
243d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_sqrtf);
244d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_tanf);
245d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_tanhf);
24662d4215bSChandler Carruth     }
24762d4215bSChandler Carruth 
248*956ee797SFangrui Song     // Win32 does *not* provide these functions, but they are
24962d4215bSChandler Carruth     // generally available on POSIX-compliant systems:
250d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_access);
251d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcmp);
252d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bcopy);
253d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_bzero);
254d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chmod);
255d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_chown);
256d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_closedir);
257d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ctermid);
258d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fdopen);
259d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffs);
260d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fileno);
261d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flockfile);
262d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko);
263d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat);
264d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs);
265d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello);
266d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftrylockfile);
267d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_funlockfile);
268d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getc_unlocked);
269d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getitimer);
270d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getlogin_r);
271d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_getpwnam);
272d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_gettimeofday);
273d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htonl);
274d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_htons);
275d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lchown);
276d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat);
277d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_memccpy);
278d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_mkdir);
279d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohl);
280d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ntohs);
281d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open);
282d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_opendir);
283d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pclose);
284d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_popen);
285d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pread);
286d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_pwrite);
287d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_read);
288d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_readlink);
289d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_realpath);
290d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_rmdir);
291d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_setitimer);
292d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat);
293d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs);
294d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpcpy);
295d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stpncpy);
296d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_strcasecmp);
297d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_strncasecmp);
298d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_times);
299d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_uname);
300d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unlink);
301d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_unsetenv);
302d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utime);
303d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_utimes);
304d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_write);
30562d4215bSChandler Carruth 
30662d4215bSChandler Carruth     // Win32 does *not* provide provide these functions, but they are
30762d4215bSChandler Carruth     // specified by C99:
308d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_atoll);
309d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_frexpf);
310d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_llabs);
31162d4215bSChandler Carruth   }
31262d4215bSChandler Carruth 
31362d4215bSChandler Carruth   switch (T.getOS()) {
31462d4215bSChandler Carruth   case Triple::MacOSX:
31562d4215bSChandler Carruth     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
31662d4215bSChandler Carruth     // and their names are __exp10 and __exp10f. exp10l is not available on
31762d4215bSChandler Carruth     // OS X or iOS.
318d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
31962d4215bSChandler Carruth     if (T.isMacOSXVersionLT(10, 9)) {
320d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
321d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
32262d4215bSChandler Carruth     } else {
323d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
324d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
32562d4215bSChandler Carruth     }
32662d4215bSChandler Carruth     break;
32762d4215bSChandler Carruth   case Triple::IOS:
32889a6eefeSTim Northover   case Triple::TvOS:
3298b40366bSTim Northover   case Triple::WatchOS:
330d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
3318b40366bSTim Northover     if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
3328b40366bSTim Northover                            (T.isOSVersionLT(9, 0) &&
3338b40366bSTim Northover                             (T.getArch() == Triple::x86 ||
3348b40366bSTim Northover                              T.getArch() == Triple::x86_64)))) {
335d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10);
336d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_exp10f);
33762d4215bSChandler Carruth     } else {
338d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
339d21529faSDavid L. Jones       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
34062d4215bSChandler Carruth     }
34162d4215bSChandler Carruth     break;
34262d4215bSChandler Carruth   case Triple::Linux:
34362d4215bSChandler Carruth     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
34462d4215bSChandler Carruth     // buggy prior to glibc version 2.18. Until this version is widely deployed
34562d4215bSChandler Carruth     // or we have a reasonable detection strategy, we cannot use exp10 reliably
34662d4215bSChandler Carruth     // on Linux.
34762d4215bSChandler Carruth     //
34862d4215bSChandler Carruth     // Fall through to disable all of them.
349cd1d5aafSJustin Bogner     LLVM_FALLTHROUGH;
35062d4215bSChandler Carruth   default:
351d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10);
352d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10f);
353d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_exp10l);
35462d4215bSChandler Carruth   }
35562d4215bSChandler Carruth 
35662d4215bSChandler Carruth   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
35762d4215bSChandler Carruth   // Linux (GLIBC):
35862d4215bSChandler Carruth   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
35983b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
36062d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
36162d4215bSChandler Carruth   switch (T.getOS()) {
36262d4215bSChandler Carruth   case Triple::Darwin:
36362d4215bSChandler Carruth   case Triple::MacOSX:
36462d4215bSChandler Carruth   case Triple::IOS:
36589a6eefeSTim Northover   case Triple::TvOS:
3668b40366bSTim Northover   case Triple::WatchOS:
36762d4215bSChandler Carruth   case Triple::FreeBSD:
36862d4215bSChandler Carruth   case Triple::Linux:
36962d4215bSChandler Carruth     break;
37062d4215bSChandler Carruth   default:
371d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsl);
37262d4215bSChandler Carruth   }
37362d4215bSChandler Carruth 
37462d4215bSChandler Carruth   // ffsll is available on at least FreeBSD and Linux (GLIBC):
37583b34816SDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
37662d4215bSChandler Carruth   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
37762d4215bSChandler Carruth   switch (T.getOS()) {
37889a6eefeSTim Northover   case Triple::Darwin:
37989a6eefeSTim Northover   case Triple::MacOSX:
38089a6eefeSTim Northover   case Triple::IOS:
38189a6eefeSTim Northover   case Triple::TvOS:
38289a6eefeSTim Northover   case Triple::WatchOS:
38362d4215bSChandler Carruth   case Triple::FreeBSD:
38462d4215bSChandler Carruth   case Triple::Linux:
38562d4215bSChandler Carruth     break;
38662d4215bSChandler Carruth   default:
387d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ffsll);
38862d4215bSChandler Carruth   }
38962d4215bSChandler Carruth 
390bfd3082eSDavide Italiano   // The following functions are available on at least FreeBSD:
391bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
392bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
393bfd3082eSDavide Italiano   // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
394bfd3082eSDavide Italiano   if (!T.isOSFreeBSD()) {
395d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fls);
396d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsl);
397d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_flsll);
398bfd3082eSDavide Italiano   }
399bfd3082eSDavide Italiano 
40060d1e79fSChih-Hung Hsieh   // The following functions are available on Linux,
40160d1e79fSChih-Hung Hsieh   // but Android uses bionic instead of glibc.
40260d1e79fSChih-Hung Hsieh   if (!T.isOSLinux() || T.isAndroid()) {
403d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strdup);
404d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_strtok_r);
405d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
406d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
407d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_getc);
408d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_under_IO_putc);
40960d1e79fSChih-Hung Hsieh     // But, Android has memalign.
41060d1e79fSChih-Hung Hsieh     if (!T.isAndroid())
411d21529faSDavid L. Jones       TLI.setUnavailable(LibFunc_memalign);
412d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fopen64);
413d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fseeko64);
414d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstat64);
415d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_fstatvfs64);
416d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_ftello64);
417d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_lstat64);
418d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_open64);
419d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_stat64);
420d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_statvfs64);
421d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_tmpfile64);
42252149f03SSanjay Patel 
42352149f03SSanjay Patel     // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
42452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acos_finite);
42552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosf_finite);
42652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosl_finite);
42752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acosh_finite);
42852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshf_finite);
42952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_acoshl_finite);
43052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asin_finite);
43152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinf_finite);
43252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_asinl_finite);
43352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2_finite);
43452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2f_finite);
43552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atan2l_finite);
43652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanh_finite);
43752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhf_finite);
43852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_atanhl_finite);
43952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_cosh_finite);
44052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshf_finite);
44152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_coshl_finite);
44252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10_finite);
44352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10f_finite);
44452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp10l_finite);
44552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2_finite);
44652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2f_finite);
44752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp2l_finite);
44852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_exp_finite);
44952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expf_finite);
45052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_expl_finite);
45152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10_finite);
45252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10f_finite);
45352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log10l_finite);
45452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2_finite);
45552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2f_finite);
45652149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log2l_finite);
45752149f03SSanjay Patel     TLI.setUnavailable(LibFunc_log_finite);
45852149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logf_finite);
45952149f03SSanjay Patel     TLI.setUnavailable(LibFunc_logl_finite);
46052149f03SSanjay Patel     TLI.setUnavailable(LibFunc_pow_finite);
46152149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powf_finite);
46252149f03SSanjay Patel     TLI.setUnavailable(LibFunc_powl_finite);
46352149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinh_finite);
46452149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhf_finite);
46552149f03SSanjay Patel     TLI.setUnavailable(LibFunc_sinhl_finite);
46662d4215bSChandler Carruth   }
4676d8a2aa9SMichael Zolotukhin 
46851132881SJustin Lebar   // As currently implemented in clang, NVPTX code has no standard library to
46951132881SJustin Lebar   // speak of.  Headers provide a standard-ish library implementation, but many
47051132881SJustin Lebar   // of the signatures are wrong -- for example, many libm functions are not
47151132881SJustin Lebar   // extern "C".
47251132881SJustin Lebar   //
47351132881SJustin Lebar   // libdevice, an IR library provided by nvidia, is linked in by the front-end,
47451132881SJustin Lebar   // but only used functions are provided to llvm.  Moreover, most of the
47551132881SJustin Lebar   // functions in libdevice don't map precisely to standard library functions.
47651132881SJustin Lebar   //
47751132881SJustin Lebar   // FIXME: Having no standard library prevents e.g. many fastmath
47851132881SJustin Lebar   // optimizations, so this situation should be fixed.
479ae272d71SDavid Majnemer   if (T.isNVPTX()) {
48051132881SJustin Lebar     TLI.disableAllFunctions();
481d21529faSDavid L. Jones     TLI.setAvailable(LibFunc_nvvm_reflect);
482ae272d71SDavid Majnemer   } else {
483d21529faSDavid L. Jones     TLI.setUnavailable(LibFunc_nvvm_reflect);
484ae272d71SDavid Majnemer   }
48551132881SJustin Lebar 
4866d8a2aa9SMichael Zolotukhin   TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
48762d4215bSChandler Carruth }
48862d4215bSChandler Carruth 
489c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
49062d4215bSChandler Carruth   // Default to everything being available.
49162d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
49262d4215bSChandler Carruth 
49362d4215bSChandler Carruth   initialize(*this, Triple(), StandardNames);
49462d4215bSChandler Carruth }
49562d4215bSChandler Carruth 
496c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
49762d4215bSChandler Carruth   // Default to everything being available.
49862d4215bSChandler Carruth   memset(AvailableArray, -1, sizeof(AvailableArray));
49962d4215bSChandler Carruth 
50062d4215bSChandler Carruth   initialize(*this, T, StandardNames);
50162d4215bSChandler Carruth }
50262d4215bSChandler Carruth 
503c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
5045ae2c526SMarcin Koscielnicki     : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
5055ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
5065ae2c526SMarcin Koscielnicki       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
50762d4215bSChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
508e8f2551fSMichael Zolotukhin   VectorDescs = TLI.VectorDescs;
509e8f2551fSMichael Zolotukhin   ScalarDescs = TLI.ScalarDescs;
5108ca43224SChandler Carruth }
5118ca43224SChandler Carruth 
512c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
5135ae2c526SMarcin Koscielnicki     : CustomNames(std::move(TLI.CustomNames)),
5145ae2c526SMarcin Koscielnicki       ShouldExtI32Param(TLI.ShouldExtI32Param),
5155ae2c526SMarcin Koscielnicki       ShouldExtI32Return(TLI.ShouldExtI32Return),
5165ae2c526SMarcin Koscielnicki       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
5178ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
5188ca43224SChandler Carruth             AvailableArray);
519e8f2551fSMichael Zolotukhin   VectorDescs = TLI.VectorDescs;
520e8f2551fSMichael Zolotukhin   ScalarDescs = TLI.ScalarDescs;
5218ca43224SChandler Carruth }
5228ca43224SChandler Carruth 
523c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
52462d4215bSChandler Carruth   CustomNames = TLI.CustomNames;
5255ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
5265ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
5275ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
5288ca43224SChandler Carruth   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
5298ca43224SChandler Carruth   return *this;
5308ca43224SChandler Carruth }
5318ca43224SChandler Carruth 
532c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
5338ca43224SChandler Carruth   CustomNames = std::move(TLI.CustomNames);
5345ae2c526SMarcin Koscielnicki   ShouldExtI32Param = TLI.ShouldExtI32Param;
5355ae2c526SMarcin Koscielnicki   ShouldExtI32Return = TLI.ShouldExtI32Return;
5365ae2c526SMarcin Koscielnicki   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
5378ca43224SChandler Carruth   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
5388ca43224SChandler Carruth             AvailableArray);
5398ca43224SChandler Carruth   return *this;
54062d4215bSChandler Carruth }
54162d4215bSChandler Carruth 
54221abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) {
54362d4215bSChandler Carruth   // Filter out empty names and names containing null bytes, those can't be in
54462d4215bSChandler Carruth   // our table.
54562d4215bSChandler Carruth   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
54621abdf98SMichael Zolotukhin     return StringRef();
54762d4215bSChandler Carruth 
54862d4215bSChandler Carruth   // Check for \01 prefix that is used to mangle __asm declarations and
54962d4215bSChandler Carruth   // strip it if present.
5506f0ecca3SPeter Collingbourne   return GlobalValue::dropLLVMManglingEscape(funcName);
55121abdf98SMichael Zolotukhin }
55221abdf98SMichael Zolotukhin 
55321abdf98SMichael Zolotukhin bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
554d21529faSDavid L. Jones                                        LibFunc &F) const {
5559a72cd7bSMehdi Amini   StringRef const *Start = &StandardNames[0];
556d21529faSDavid L. Jones   StringRef const *End = &StandardNames[NumLibFuncs];
55721abdf98SMichael Zolotukhin 
55821abdf98SMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
55921abdf98SMichael Zolotukhin   if (funcName.empty())
56021abdf98SMichael Zolotukhin     return false;
56121abdf98SMichael Zolotukhin 
5629a72cd7bSMehdi Amini   StringRef const *I = std::lower_bound(
5639a72cd7bSMehdi Amini       Start, End, funcName, [](StringRef LHS, StringRef RHS) {
5649a72cd7bSMehdi Amini         return LHS < RHS;
565d3b76a3bSMichael Zolotukhin       });
56662d4215bSChandler Carruth   if (I != End && *I == funcName) {
567d21529faSDavid L. Jones     F = (LibFunc)(I - Start);
56862d4215bSChandler Carruth     return true;
56962d4215bSChandler Carruth   }
57062d4215bSChandler Carruth   return false;
57162d4215bSChandler Carruth }
57262d4215bSChandler Carruth 
573d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
574d21529faSDavid L. Jones                                                    LibFunc F,
575d765a82bSAhmed Bougacha                                                    const DataLayout *DL) const {
576d765a82bSAhmed Bougacha   LLVMContext &Ctx = FTy.getContext();
577d765a82bSAhmed Bougacha   Type *PCharTy = Type::getInt8PtrTy(Ctx);
578d765a82bSAhmed Bougacha   Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
579d765a82bSAhmed Bougacha   auto IsSizeTTy = [SizeTTy](Type *Ty) {
580d765a82bSAhmed Bougacha     return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
581d765a82bSAhmed Bougacha   };
582d765a82bSAhmed Bougacha   unsigned NumParams = FTy.getNumParams();
583d765a82bSAhmed Bougacha 
584d765a82bSAhmed Bougacha   switch (F) {
585d21529faSDavid L. Jones   case LibFunc_strlen:
586d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
587d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
588d765a82bSAhmed Bougacha 
589d21529faSDavid L. Jones   case LibFunc_strchr:
590d21529faSDavid L. Jones   case LibFunc_strrchr:
591d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
592d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
593d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy());
594d765a82bSAhmed Bougacha 
595d21529faSDavid L. Jones   case LibFunc_strtol:
596d21529faSDavid L. Jones   case LibFunc_strtod:
597d21529faSDavid L. Jones   case LibFunc_strtof:
598d21529faSDavid L. Jones   case LibFunc_strtoul:
599d21529faSDavid L. Jones   case LibFunc_strtoll:
600d21529faSDavid L. Jones   case LibFunc_strtold:
601d21529faSDavid L. Jones   case LibFunc_strtoull:
602d765a82bSAhmed Bougacha     return ((NumParams == 2 || NumParams == 3) &&
603d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
604d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
605d21529faSDavid L. Jones   case LibFunc_strcat:
606d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
607d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
608d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType());
609d765a82bSAhmed Bougacha 
610d21529faSDavid L. Jones   case LibFunc_strncat:
611d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
612d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
613d765a82bSAhmed Bougacha             FTy.getParamType(1) == FTy.getReturnType() &&
6147bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
615d765a82bSAhmed Bougacha 
616d21529faSDavid L. Jones   case LibFunc_strcpy_chk:
617d21529faSDavid L. Jones   case LibFunc_stpcpy_chk:
618d765a82bSAhmed Bougacha     --NumParams;
619d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
620d765a82bSAhmed Bougacha       return false;
621b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
622d21529faSDavid L. Jones   case LibFunc_strcpy:
623d21529faSDavid L. Jones   case LibFunc_stpcpy:
624d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
625d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
626d765a82bSAhmed Bougacha             FTy.getParamType(0) == PCharTy);
627d765a82bSAhmed Bougacha 
628d21529faSDavid L. Jones   case LibFunc_strncpy_chk:
629d21529faSDavid L. Jones   case LibFunc_stpncpy_chk:
630d765a82bSAhmed Bougacha     --NumParams;
631d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
632d765a82bSAhmed Bougacha       return false;
633b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
634d21529faSDavid L. Jones   case LibFunc_strncpy:
635d21529faSDavid L. Jones   case LibFunc_stpncpy:
636d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
637d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
638d765a82bSAhmed Bougacha             FTy.getParamType(0) == PCharTy &&
6397bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
640d765a82bSAhmed Bougacha 
641d21529faSDavid L. Jones   case LibFunc_strxfrm:
642d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
643d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
644d765a82bSAhmed Bougacha 
645d21529faSDavid L. Jones   case LibFunc_strcmp:
646d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
647d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
648d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
649d765a82bSAhmed Bougacha 
650d21529faSDavid L. Jones   case LibFunc_strncmp:
651d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
652d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
653d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
6547bd3fb15SIgor Laevsky             IsSizeTTy(FTy.getParamType(2)));
655d765a82bSAhmed Bougacha 
656d21529faSDavid L. Jones   case LibFunc_strspn:
657d21529faSDavid L. Jones   case LibFunc_strcspn:
658d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
659d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1) &&
660d765a82bSAhmed Bougacha             FTy.getReturnType()->isIntegerTy());
661d765a82bSAhmed Bougacha 
662d21529faSDavid L. Jones   case LibFunc_strcoll:
663d21529faSDavid L. Jones   case LibFunc_strcasecmp:
664d21529faSDavid L. Jones   case LibFunc_strncasecmp:
665d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
666d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
667d765a82bSAhmed Bougacha 
668d21529faSDavid L. Jones   case LibFunc_strstr:
669d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
670d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
671d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
672d765a82bSAhmed Bougacha 
673d21529faSDavid L. Jones   case LibFunc_strpbrk:
674d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
675d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
676d765a82bSAhmed Bougacha             FTy.getParamType(0) == FTy.getParamType(1));
677d765a82bSAhmed Bougacha 
678d21529faSDavid L. Jones   case LibFunc_strtok:
679d21529faSDavid L. Jones   case LibFunc_strtok_r:
680d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
681d21529faSDavid L. Jones   case LibFunc_scanf:
682d21529faSDavid L. Jones   case LibFunc_setbuf:
683d21529faSDavid L. Jones   case LibFunc_setvbuf:
684d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
685d21529faSDavid L. Jones   case LibFunc_strdup:
686d21529faSDavid L. Jones   case LibFunc_strndup:
687d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
688d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
689d21529faSDavid L. Jones   case LibFunc_sscanf:
690d21529faSDavid L. Jones   case LibFunc_stat:
691d21529faSDavid L. Jones   case LibFunc_statvfs:
692d21529faSDavid L. Jones   case LibFunc_siprintf:
693d21529faSDavid L. Jones   case LibFunc_sprintf:
694d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
695d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
696d21529faSDavid L. Jones   case LibFunc_snprintf:
697d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
698d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
699d21529faSDavid L. Jones   case LibFunc_setitimer:
700d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
701d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
702d21529faSDavid L. Jones   case LibFunc_system:
703d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
704d21529faSDavid L. Jones   case LibFunc_malloc:
705d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
706d21529faSDavid L. Jones   case LibFunc_memcmp:
7076b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
7086b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
7096b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
710d765a82bSAhmed Bougacha 
711d21529faSDavid L. Jones   case LibFunc_memchr:
712d21529faSDavid L. Jones   case LibFunc_memrchr:
7136b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
7146b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
715d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32) &&
7166b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
717d21529faSDavid L. Jones   case LibFunc_modf:
718d21529faSDavid L. Jones   case LibFunc_modff:
719d21529faSDavid L. Jones   case LibFunc_modfl:
720d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
721d765a82bSAhmed Bougacha 
722d21529faSDavid L. Jones   case LibFunc_memcpy_chk:
723d21529faSDavid L. Jones   case LibFunc_memmove_chk:
724d765a82bSAhmed Bougacha     --NumParams;
725d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
726d765a82bSAhmed Bougacha       return false;
727b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
728d21529faSDavid L. Jones   case LibFunc_memcpy:
729d21529faSDavid L. Jones   case LibFunc_mempcpy:
730d21529faSDavid L. Jones   case LibFunc_memmove:
731d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
732d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
733d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
734d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
735d765a82bSAhmed Bougacha 
736d21529faSDavid L. Jones   case LibFunc_memset_chk:
737d765a82bSAhmed Bougacha     --NumParams;
738d765a82bSAhmed Bougacha     if (!IsSizeTTy(FTy.getParamType(NumParams)))
739d765a82bSAhmed Bougacha       return false;
740b03fd12cSJustin Bogner     LLVM_FALLTHROUGH;
741d21529faSDavid L. Jones   case LibFunc_memset:
742d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
743d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
744d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
745d765a82bSAhmed Bougacha             IsSizeTTy(FTy.getParamType(2)));
746d765a82bSAhmed Bougacha 
747d21529faSDavid L. Jones   case LibFunc_memccpy:
748d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
749d21529faSDavid L. Jones   case LibFunc_memalign:
750d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
751d21529faSDavid L. Jones   case LibFunc_realloc:
752d21529faSDavid L. Jones   case LibFunc_reallocf:
7536b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
7546b9be1dbSAhmed Bougacha             FTy.getParamType(0) == FTy.getReturnType() &&
7556b9be1dbSAhmed Bougacha             IsSizeTTy(FTy.getParamType(1)));
756d21529faSDavid L. Jones   case LibFunc_read:
757d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
758d21529faSDavid L. Jones   case LibFunc_rewind:
759d21529faSDavid L. Jones   case LibFunc_rmdir:
760d21529faSDavid L. Jones   case LibFunc_remove:
761d21529faSDavid L. Jones   case LibFunc_realpath:
762d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
763d21529faSDavid L. Jones   case LibFunc_rename:
764d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
765d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
766d21529faSDavid L. Jones   case LibFunc_readlink:
767d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
768d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
769d21529faSDavid L. Jones   case LibFunc_write:
770d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
771d21529faSDavid L. Jones   case LibFunc_bcopy:
772d21529faSDavid L. Jones   case LibFunc_bcmp:
773d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
774d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
775d21529faSDavid L. Jones   case LibFunc_bzero:
776d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
777d21529faSDavid L. Jones   case LibFunc_calloc:
778d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
7791fe3f1caSAhmed Bougacha 
780d21529faSDavid L. Jones   case LibFunc_atof:
781d21529faSDavid L. Jones   case LibFunc_atoi:
782d21529faSDavid L. Jones   case LibFunc_atol:
783d21529faSDavid L. Jones   case LibFunc_atoll:
784d21529faSDavid L. Jones   case LibFunc_ferror:
785d21529faSDavid L. Jones   case LibFunc_getenv:
786d21529faSDavid L. Jones   case LibFunc_getpwnam:
787d21529faSDavid L. Jones   case LibFunc_iprintf:
788d21529faSDavid L. Jones   case LibFunc_pclose:
789d21529faSDavid L. Jones   case LibFunc_perror:
790d21529faSDavid L. Jones   case LibFunc_printf:
791d21529faSDavid L. Jones   case LibFunc_puts:
792d21529faSDavid L. Jones   case LibFunc_uname:
793d21529faSDavid L. Jones   case LibFunc_under_IO_getc:
794d21529faSDavid L. Jones   case LibFunc_unlink:
795d21529faSDavid L. Jones   case LibFunc_unsetenv:
796d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
7971fe3f1caSAhmed Bougacha 
798d21529faSDavid L. Jones   case LibFunc_access:
799d21529faSDavid L. Jones   case LibFunc_chmod:
800d21529faSDavid L. Jones   case LibFunc_chown:
801d21529faSDavid L. Jones   case LibFunc_clearerr:
802d21529faSDavid L. Jones   case LibFunc_closedir:
803d21529faSDavid L. Jones   case LibFunc_ctermid:
804d21529faSDavid L. Jones   case LibFunc_fclose:
805d21529faSDavid L. Jones   case LibFunc_feof:
806d21529faSDavid L. Jones   case LibFunc_fflush:
807d21529faSDavid L. Jones   case LibFunc_fgetc:
808d21529faSDavid L. Jones   case LibFunc_fileno:
809d21529faSDavid L. Jones   case LibFunc_flockfile:
810d21529faSDavid L. Jones   case LibFunc_free:
811d21529faSDavid L. Jones   case LibFunc_fseek:
812d21529faSDavid L. Jones   case LibFunc_fseeko64:
813d21529faSDavid L. Jones   case LibFunc_fseeko:
814d21529faSDavid L. Jones   case LibFunc_fsetpos:
815d21529faSDavid L. Jones   case LibFunc_ftell:
816d21529faSDavid L. Jones   case LibFunc_ftello64:
817d21529faSDavid L. Jones   case LibFunc_ftello:
818d21529faSDavid L. Jones   case LibFunc_ftrylockfile:
819d21529faSDavid L. Jones   case LibFunc_funlockfile:
820d21529faSDavid L. Jones   case LibFunc_getc:
821d21529faSDavid L. Jones   case LibFunc_getc_unlocked:
822d21529faSDavid L. Jones   case LibFunc_getlogin_r:
823d21529faSDavid L. Jones   case LibFunc_mkdir:
824d21529faSDavid L. Jones   case LibFunc_mktime:
825d21529faSDavid L. Jones   case LibFunc_times:
8261fe3f1caSAhmed Bougacha     return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
8271fe3f1caSAhmed Bougacha 
828d21529faSDavid L. Jones   case LibFunc_fopen:
829d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
830d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
831d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
832d21529faSDavid L. Jones   case LibFunc_fdopen:
833d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
834d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
835d21529faSDavid L. Jones   case LibFunc_fputc:
836d21529faSDavid L. Jones   case LibFunc_fstat:
837d21529faSDavid L. Jones   case LibFunc_frexp:
838d21529faSDavid L. Jones   case LibFunc_frexpf:
839d21529faSDavid L. Jones   case LibFunc_frexpl:
840d21529faSDavid L. Jones   case LibFunc_fstatvfs:
841d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
842d21529faSDavid L. Jones   case LibFunc_fgets:
843d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
844d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
845d21529faSDavid L. Jones   case LibFunc_fread:
846d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
847d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
848d21529faSDavid L. Jones   case LibFunc_fwrite:
849d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
850d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
851d765a82bSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy() &&
852d765a82bSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy() &&
853d765a82bSAhmed Bougacha             FTy.getParamType(3)->isPointerTy());
854d21529faSDavid L. Jones   case LibFunc_fputs:
855d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
856d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
857d21529faSDavid L. Jones   case LibFunc_fscanf:
858d21529faSDavid L. Jones   case LibFunc_fiprintf:
859d21529faSDavid L. Jones   case LibFunc_fprintf:
8606b9be1dbSAhmed Bougacha     return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
8616b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
862d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
863d21529faSDavid L. Jones   case LibFunc_fgetpos:
864d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
865d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
866d21529faSDavid L. Jones   case LibFunc_getchar:
8676b9be1dbSAhmed Bougacha     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
868d21529faSDavid L. Jones   case LibFunc_gets:
8696b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
870d21529faSDavid L. Jones   case LibFunc_getitimer:
871d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
872d21529faSDavid L. Jones   case LibFunc_ungetc:
873d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
874d21529faSDavid L. Jones   case LibFunc_utime:
875d21529faSDavid L. Jones   case LibFunc_utimes:
876d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
877d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
878d21529faSDavid L. Jones   case LibFunc_putc:
879d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
880d21529faSDavid L. Jones   case LibFunc_pread:
881d21529faSDavid L. Jones   case LibFunc_pwrite:
882d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
883d21529faSDavid L. Jones   case LibFunc_popen:
884d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
885d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
886d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
887d21529faSDavid L. Jones   case LibFunc_vscanf:
888d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
889d21529faSDavid L. Jones   case LibFunc_vsscanf:
890d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
891d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
892d21529faSDavid L. Jones   case LibFunc_vfscanf:
893d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
894d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
895d21529faSDavid L. Jones   case LibFunc_valloc:
896d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
897d21529faSDavid L. Jones   case LibFunc_vprintf:
898d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
899d21529faSDavid L. Jones   case LibFunc_vfprintf:
900d21529faSDavid L. Jones   case LibFunc_vsprintf:
901d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
902d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
903d21529faSDavid L. Jones   case LibFunc_vsnprintf:
904d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
905d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
906d21529faSDavid L. Jones   case LibFunc_open:
907d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
908d21529faSDavid L. Jones   case LibFunc_opendir:
909d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
910d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
911d21529faSDavid L. Jones   case LibFunc_tmpfile:
912d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
913d21529faSDavid L. Jones   case LibFunc_htonl:
914d21529faSDavid L. Jones   case LibFunc_ntohl:
9156b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
9166b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
917d21529faSDavid L. Jones   case LibFunc_htons:
918d21529faSDavid L. Jones   case LibFunc_ntohs:
9196b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
9206b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
921d21529faSDavid L. Jones   case LibFunc_lstat:
922d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
923d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
924d21529faSDavid L. Jones   case LibFunc_lchown:
925d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
926d21529faSDavid L. Jones   case LibFunc_qsort:
927d765a82bSAhmed Bougacha     return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
928d21529faSDavid L. Jones   case LibFunc_dunder_strdup:
929d21529faSDavid L. Jones   case LibFunc_dunder_strndup:
930d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
931d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy());
932d21529faSDavid L. Jones   case LibFunc_dunder_strtok_r:
933d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
934d21529faSDavid L. Jones   case LibFunc_under_IO_putc:
935d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
936d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_scanf:
937d765a82bSAhmed Bougacha     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
938d21529faSDavid L. Jones   case LibFunc_stat64:
939d21529faSDavid L. Jones   case LibFunc_lstat64:
940d21529faSDavid L. Jones   case LibFunc_statvfs64:
94179dcc274SMichael Kuperstein     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
942d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
943d21529faSDavid L. Jones   case LibFunc_dunder_isoc99_sscanf:
94479dcc274SMichael Kuperstein     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
945d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
946d21529faSDavid L. Jones   case LibFunc_fopen64:
947d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
948d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
949d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
950d21529faSDavid L. Jones   case LibFunc_tmpfile64:
951d765a82bSAhmed Bougacha     return (FTy.getReturnType()->isPointerTy());
952d21529faSDavid L. Jones   case LibFunc_fstat64:
953d21529faSDavid L. Jones   case LibFunc_fstatvfs64:
954d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
955d21529faSDavid L. Jones   case LibFunc_open64:
956d765a82bSAhmed Bougacha     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
957d21529faSDavid L. Jones   case LibFunc_gettimeofday:
958d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
959d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy());
960d765a82bSAhmed Bougacha 
9616b9be1dbSAhmed Bougacha   // new(unsigned int);
962d21529faSDavid L. Jones   case LibFunc_Znwj:
9636b9be1dbSAhmed Bougacha   // new(unsigned long);
964d21529faSDavid L. Jones   case LibFunc_Znwm:
9656b9be1dbSAhmed Bougacha   // new[](unsigned int);
966d21529faSDavid L. Jones   case LibFunc_Znaj:
9676b9be1dbSAhmed Bougacha   // new[](unsigned long);
968d21529faSDavid L. Jones   case LibFunc_Znam:
9696b9be1dbSAhmed Bougacha   // new(unsigned int);
970d21529faSDavid L. Jones   case LibFunc_msvc_new_int:
9716b9be1dbSAhmed Bougacha   // new(unsigned long long);
972d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong:
9736b9be1dbSAhmed Bougacha   // new[](unsigned int);
974d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int:
9756b9be1dbSAhmed Bougacha   // new[](unsigned long long);
976d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong:
9776b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
9786b9be1dbSAhmed Bougacha 
9796b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
980d21529faSDavid L. Jones   case LibFunc_ZnwjRKSt9nothrow_t:
9816b9be1dbSAhmed Bougacha   // new(unsigned long, nothrow);
982d21529faSDavid L. Jones   case LibFunc_ZnwmRKSt9nothrow_t:
9836b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
984d21529faSDavid L. Jones   case LibFunc_ZnajRKSt9nothrow_t:
9856b9be1dbSAhmed Bougacha   // new[](unsigned long, nothrow);
986d21529faSDavid L. Jones   case LibFunc_ZnamRKSt9nothrow_t:
9876b9be1dbSAhmed Bougacha   // new(unsigned int, nothrow);
988d21529faSDavid L. Jones   case LibFunc_msvc_new_int_nothrow:
9896b9be1dbSAhmed Bougacha   // new(unsigned long long, nothrow);
990d21529faSDavid L. Jones   case LibFunc_msvc_new_longlong_nothrow:
9916b9be1dbSAhmed Bougacha   // new[](unsigned int, nothrow);
992d21529faSDavid L. Jones   case LibFunc_msvc_new_array_int_nothrow:
9936b9be1dbSAhmed Bougacha   // new[](unsigned long long, nothrow);
994d21529faSDavid L. Jones   case LibFunc_msvc_new_array_longlong_nothrow:
9956b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
9966b9be1dbSAhmed Bougacha 
9976b9be1dbSAhmed Bougacha   // void operator delete[](void*);
998d21529faSDavid L. Jones   case LibFunc_ZdaPv:
9996b9be1dbSAhmed Bougacha   // void operator delete(void*);
1000d21529faSDavid L. Jones   case LibFunc_ZdlPv:
10016b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1002d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32:
10036b9be1dbSAhmed Bougacha   // void operator delete[](void*);
1004d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64:
10056b9be1dbSAhmed Bougacha   // void operator delete(void*);
1006d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32:
10076b9be1dbSAhmed Bougacha   // void operator delete(void*);
1008d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64:
10096b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
10106b9be1dbSAhmed Bougacha 
10116b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1012d21529faSDavid L. Jones   case LibFunc_ZdaPvRKSt9nothrow_t:
10136b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1014d21529faSDavid L. Jones   case LibFunc_ZdaPvj:
10156b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long);
1016d21529faSDavid L. Jones   case LibFunc_ZdaPvm:
10176b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1018d21529faSDavid L. Jones   case LibFunc_ZdlPvRKSt9nothrow_t:
10196b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1020d21529faSDavid L. Jones   case LibFunc_ZdlPvj:
10216b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long);
1022d21529faSDavid L. Jones   case LibFunc_ZdlPvm:
10236b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned int);
1024d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_int:
10256b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1026d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr32_nothrow:
10276b9be1dbSAhmed Bougacha   // void operator delete[](void*, unsigned long long);
1028d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_longlong:
10296b9be1dbSAhmed Bougacha   // void operator delete[](void*, nothrow);
1030d21529faSDavid L. Jones   case LibFunc_msvc_delete_array_ptr64_nothrow:
10316b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned int);
1032d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_int:
10336b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1034d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr32_nothrow:
10356b9be1dbSAhmed Bougacha   // void operator delete(void*, unsigned long long);
1036d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_longlong:
10376b9be1dbSAhmed Bougacha   // void operator delete(void*, nothrow);
1038d21529faSDavid L. Jones   case LibFunc_msvc_delete_ptr64_nothrow:
10396b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1040d765a82bSAhmed Bougacha 
1041d21529faSDavid L. Jones   case LibFunc_memset_pattern16:
1042d765a82bSAhmed Bougacha     return (!FTy.isVarArg() && NumParams == 3 &&
10436b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
10446b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
10456b9be1dbSAhmed Bougacha             FTy.getParamType(2)->isIntegerTy());
1046d765a82bSAhmed Bougacha 
1047d21529faSDavid L. Jones   case LibFunc_cxa_guard_abort:
1048d21529faSDavid L. Jones   case LibFunc_cxa_guard_acquire:
1049d21529faSDavid L. Jones   case LibFunc_cxa_guard_release:
1050d21529faSDavid L. Jones   case LibFunc_nvvm_reflect:
10516b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1052d765a82bSAhmed Bougacha 
1053d21529faSDavid L. Jones   case LibFunc_sincospi_stret:
1054d21529faSDavid L. Jones   case LibFunc_sincospif_stret:
10556b9be1dbSAhmed Bougacha     return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
10566b9be1dbSAhmed Bougacha 
1057d21529faSDavid L. Jones   case LibFunc_acos:
10583cd8c16dSAndrew Kaylor   case LibFunc_acos_finite:
1059d21529faSDavid L. Jones   case LibFunc_acosf:
10603cd8c16dSAndrew Kaylor   case LibFunc_acosf_finite:
1061d21529faSDavid L. Jones   case LibFunc_acosh:
10623cd8c16dSAndrew Kaylor   case LibFunc_acosh_finite:
1063d21529faSDavid L. Jones   case LibFunc_acoshf:
10643cd8c16dSAndrew Kaylor   case LibFunc_acoshf_finite:
1065d21529faSDavid L. Jones   case LibFunc_acoshl:
10663cd8c16dSAndrew Kaylor   case LibFunc_acoshl_finite:
1067d21529faSDavid L. Jones   case LibFunc_acosl:
10683cd8c16dSAndrew Kaylor   case LibFunc_acosl_finite:
1069d21529faSDavid L. Jones   case LibFunc_asin:
10703cd8c16dSAndrew Kaylor   case LibFunc_asin_finite:
1071d21529faSDavid L. Jones   case LibFunc_asinf:
10723cd8c16dSAndrew Kaylor   case LibFunc_asinf_finite:
1073d21529faSDavid L. Jones   case LibFunc_asinh:
1074d21529faSDavid L. Jones   case LibFunc_asinhf:
1075d21529faSDavid L. Jones   case LibFunc_asinhl:
1076d21529faSDavid L. Jones   case LibFunc_asinl:
10773cd8c16dSAndrew Kaylor   case LibFunc_asinl_finite:
1078d21529faSDavid L. Jones   case LibFunc_atan:
1079d21529faSDavid L. Jones   case LibFunc_atanf:
1080d21529faSDavid L. Jones   case LibFunc_atanh:
10813cd8c16dSAndrew Kaylor   case LibFunc_atanh_finite:
1082d21529faSDavid L. Jones   case LibFunc_atanhf:
10833cd8c16dSAndrew Kaylor   case LibFunc_atanhf_finite:
1084d21529faSDavid L. Jones   case LibFunc_atanhl:
10853cd8c16dSAndrew Kaylor   case LibFunc_atanhl_finite:
1086d21529faSDavid L. Jones   case LibFunc_atanl:
1087d21529faSDavid L. Jones   case LibFunc_cbrt:
1088d21529faSDavid L. Jones   case LibFunc_cbrtf:
1089d21529faSDavid L. Jones   case LibFunc_cbrtl:
1090d21529faSDavid L. Jones   case LibFunc_ceil:
1091d21529faSDavid L. Jones   case LibFunc_ceilf:
1092d21529faSDavid L. Jones   case LibFunc_ceill:
1093d21529faSDavid L. Jones   case LibFunc_cos:
1094d21529faSDavid L. Jones   case LibFunc_cosf:
1095d21529faSDavid L. Jones   case LibFunc_cosh:
10963cd8c16dSAndrew Kaylor   case LibFunc_cosh_finite:
1097d21529faSDavid L. Jones   case LibFunc_coshf:
10983cd8c16dSAndrew Kaylor   case LibFunc_coshf_finite:
1099d21529faSDavid L. Jones   case LibFunc_coshl:
11003cd8c16dSAndrew Kaylor   case LibFunc_coshl_finite:
1101d21529faSDavid L. Jones   case LibFunc_cosl:
1102d21529faSDavid L. Jones   case LibFunc_exp10:
11033cd8c16dSAndrew Kaylor   case LibFunc_exp10_finite:
1104d21529faSDavid L. Jones   case LibFunc_exp10f:
11053cd8c16dSAndrew Kaylor   case LibFunc_exp10f_finite:
1106d21529faSDavid L. Jones   case LibFunc_exp10l:
11073cd8c16dSAndrew Kaylor   case LibFunc_exp10l_finite:
1108d21529faSDavid L. Jones   case LibFunc_exp2:
11093cd8c16dSAndrew Kaylor   case LibFunc_exp2_finite:
1110d21529faSDavid L. Jones   case LibFunc_exp2f:
11113cd8c16dSAndrew Kaylor   case LibFunc_exp2f_finite:
1112d21529faSDavid L. Jones   case LibFunc_exp2l:
11133cd8c16dSAndrew Kaylor   case LibFunc_exp2l_finite:
1114d21529faSDavid L. Jones   case LibFunc_exp:
11153cd8c16dSAndrew Kaylor   case LibFunc_exp_finite:
1116d21529faSDavid L. Jones   case LibFunc_expf:
11173cd8c16dSAndrew Kaylor   case LibFunc_expf_finite:
1118d21529faSDavid L. Jones   case LibFunc_expl:
11193cd8c16dSAndrew Kaylor   case LibFunc_expl_finite:
1120d21529faSDavid L. Jones   case LibFunc_expm1:
1121d21529faSDavid L. Jones   case LibFunc_expm1f:
1122d21529faSDavid L. Jones   case LibFunc_expm1l:
1123d21529faSDavid L. Jones   case LibFunc_fabs:
1124d21529faSDavid L. Jones   case LibFunc_fabsf:
1125d21529faSDavid L. Jones   case LibFunc_fabsl:
1126d21529faSDavid L. Jones   case LibFunc_floor:
1127d21529faSDavid L. Jones   case LibFunc_floorf:
1128d21529faSDavid L. Jones   case LibFunc_floorl:
1129d21529faSDavid L. Jones   case LibFunc_log10:
11303cd8c16dSAndrew Kaylor   case LibFunc_log10_finite:
1131d21529faSDavid L. Jones   case LibFunc_log10f:
11323cd8c16dSAndrew Kaylor   case LibFunc_log10f_finite:
1133d21529faSDavid L. Jones   case LibFunc_log10l:
11343cd8c16dSAndrew Kaylor   case LibFunc_log10l_finite:
1135d21529faSDavid L. Jones   case LibFunc_log1p:
1136d21529faSDavid L. Jones   case LibFunc_log1pf:
1137d21529faSDavid L. Jones   case LibFunc_log1pl:
1138d21529faSDavid L. Jones   case LibFunc_log2:
11393cd8c16dSAndrew Kaylor   case LibFunc_log2_finite:
1140d21529faSDavid L. Jones   case LibFunc_log2f:
11413cd8c16dSAndrew Kaylor   case LibFunc_log2f_finite:
1142d21529faSDavid L. Jones   case LibFunc_log2l:
11433cd8c16dSAndrew Kaylor   case LibFunc_log2l_finite:
1144d21529faSDavid L. Jones   case LibFunc_log:
11453cd8c16dSAndrew Kaylor   case LibFunc_log_finite:
1146d21529faSDavid L. Jones   case LibFunc_logb:
1147d21529faSDavid L. Jones   case LibFunc_logbf:
1148d21529faSDavid L. Jones   case LibFunc_logbl:
1149d21529faSDavid L. Jones   case LibFunc_logf:
11503cd8c16dSAndrew Kaylor   case LibFunc_logf_finite:
1151d21529faSDavid L. Jones   case LibFunc_logl:
11523cd8c16dSAndrew Kaylor   case LibFunc_logl_finite:
1153d21529faSDavid L. Jones   case LibFunc_nearbyint:
1154d21529faSDavid L. Jones   case LibFunc_nearbyintf:
1155d21529faSDavid L. Jones   case LibFunc_nearbyintl:
1156d21529faSDavid L. Jones   case LibFunc_rint:
1157d21529faSDavid L. Jones   case LibFunc_rintf:
1158d21529faSDavid L. Jones   case LibFunc_rintl:
1159d21529faSDavid L. Jones   case LibFunc_round:
1160d21529faSDavid L. Jones   case LibFunc_roundf:
1161d21529faSDavid L. Jones   case LibFunc_roundl:
1162d21529faSDavid L. Jones   case LibFunc_sin:
1163d21529faSDavid L. Jones   case LibFunc_sinf:
1164d21529faSDavid L. Jones   case LibFunc_sinh:
11653cd8c16dSAndrew Kaylor   case LibFunc_sinh_finite:
1166d21529faSDavid L. Jones   case LibFunc_sinhf:
11673cd8c16dSAndrew Kaylor   case LibFunc_sinhf_finite:
1168d21529faSDavid L. Jones   case LibFunc_sinhl:
11693cd8c16dSAndrew Kaylor   case LibFunc_sinhl_finite:
1170d21529faSDavid L. Jones   case LibFunc_sinl:
1171d21529faSDavid L. Jones   case LibFunc_sqrt:
1172d21529faSDavid L. Jones   case LibFunc_sqrt_finite:
1173d21529faSDavid L. Jones   case LibFunc_sqrtf:
1174d21529faSDavid L. Jones   case LibFunc_sqrtf_finite:
1175d21529faSDavid L. Jones   case LibFunc_sqrtl:
1176d21529faSDavid L. Jones   case LibFunc_sqrtl_finite:
1177d21529faSDavid L. Jones   case LibFunc_tan:
1178d21529faSDavid L. Jones   case LibFunc_tanf:
1179d21529faSDavid L. Jones   case LibFunc_tanh:
1180d21529faSDavid L. Jones   case LibFunc_tanhf:
1181d21529faSDavid L. Jones   case LibFunc_tanhl:
1182d21529faSDavid L. Jones   case LibFunc_tanl:
1183d21529faSDavid L. Jones   case LibFunc_trunc:
1184d21529faSDavid L. Jones   case LibFunc_truncf:
1185d21529faSDavid L. Jones   case LibFunc_truncl:
1186d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1187d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1188d765a82bSAhmed Bougacha 
1189d21529faSDavid L. Jones   case LibFunc_atan2:
11903cd8c16dSAndrew Kaylor   case LibFunc_atan2_finite:
1191d21529faSDavid L. Jones   case LibFunc_atan2f:
11923cd8c16dSAndrew Kaylor   case LibFunc_atan2f_finite:
1193d21529faSDavid L. Jones   case LibFunc_atan2l:
11943cd8c16dSAndrew Kaylor   case LibFunc_atan2l_finite:
1195d21529faSDavid L. Jones   case LibFunc_fmin:
1196d21529faSDavid L. Jones   case LibFunc_fminf:
1197d21529faSDavid L. Jones   case LibFunc_fminl:
1198d21529faSDavid L. Jones   case LibFunc_fmax:
1199d21529faSDavid L. Jones   case LibFunc_fmaxf:
1200d21529faSDavid L. Jones   case LibFunc_fmaxl:
1201d21529faSDavid L. Jones   case LibFunc_fmod:
1202d21529faSDavid L. Jones   case LibFunc_fmodf:
1203d21529faSDavid L. Jones   case LibFunc_fmodl:
1204d21529faSDavid L. Jones   case LibFunc_copysign:
1205d21529faSDavid L. Jones   case LibFunc_copysignf:
1206d21529faSDavid L. Jones   case LibFunc_copysignl:
1207d21529faSDavid L. Jones   case LibFunc_pow:
12083cd8c16dSAndrew Kaylor   case LibFunc_pow_finite:
1209d21529faSDavid L. Jones   case LibFunc_powf:
12103cd8c16dSAndrew Kaylor   case LibFunc_powf_finite:
1211d21529faSDavid L. Jones   case LibFunc_powl:
12123cd8c16dSAndrew Kaylor   case LibFunc_powl_finite:
1213d765a82bSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1214d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
1215d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(1));
1216d765a82bSAhmed Bougacha 
1217d21529faSDavid L. Jones   case LibFunc_ldexp:
1218d21529faSDavid L. Jones   case LibFunc_ldexpf:
1219d21529faSDavid L. Jones   case LibFunc_ldexpl:
12206b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
12216b9be1dbSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0) &&
12226b9be1dbSAhmed Bougacha             FTy.getParamType(1)->isIntegerTy(32));
12236b9be1dbSAhmed Bougacha 
1224d21529faSDavid L. Jones   case LibFunc_ffs:
1225d21529faSDavid L. Jones   case LibFunc_ffsl:
1226d21529faSDavid L. Jones   case LibFunc_ffsll:
1227d21529faSDavid L. Jones   case LibFunc_fls:
1228d21529faSDavid L. Jones   case LibFunc_flsl:
1229d21529faSDavid L. Jones   case LibFunc_flsll:
123004949fafSSanjay Patel     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
123104949fafSSanjay Patel             FTy.getParamType(0)->isIntegerTy());
123204949fafSSanjay Patel 
1233d21529faSDavid L. Jones   case LibFunc_isdigit:
1234d21529faSDavid L. Jones   case LibFunc_isascii:
1235d21529faSDavid L. Jones   case LibFunc_toascii:
1236d21529faSDavid L. Jones   case LibFunc_putchar:
1237d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
123804949fafSSanjay Patel             FTy.getReturnType() == FTy.getParamType(0));
1239d765a82bSAhmed Bougacha 
1240d21529faSDavid L. Jones   case LibFunc_abs:
1241d21529faSDavid L. Jones   case LibFunc_labs:
1242d21529faSDavid L. Jones   case LibFunc_llabs:
1243d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1244d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1245d765a82bSAhmed Bougacha 
1246d21529faSDavid L. Jones   case LibFunc_cxa_atexit:
1247d765a82bSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1248d765a82bSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
1249d765a82bSAhmed Bougacha             FTy.getParamType(1)->isPointerTy() &&
1250d765a82bSAhmed Bougacha             FTy.getParamType(2)->isPointerTy());
1251d765a82bSAhmed Bougacha 
1252d21529faSDavid L. Jones   case LibFunc_sinpi:
1253d21529faSDavid L. Jones   case LibFunc_cospi:
1254d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1255d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1256d765a82bSAhmed Bougacha 
1257d21529faSDavid L. Jones   case LibFunc_sinpif:
1258d21529faSDavid L. Jones   case LibFunc_cospif:
1259d765a82bSAhmed Bougacha     return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1260d765a82bSAhmed Bougacha             FTy.getReturnType() == FTy.getParamType(0));
1261d765a82bSAhmed Bougacha 
1262d21529faSDavid L. Jones   case LibFunc_strnlen:
12636b9be1dbSAhmed Bougacha     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
12646b9be1dbSAhmed Bougacha             FTy.getParamType(0) == PCharTy &&
12656b9be1dbSAhmed Bougacha             FTy.getParamType(1) == SizeTTy);
12666b9be1dbSAhmed Bougacha 
1267d21529faSDavid L. Jones   case LibFunc_posix_memalign:
12686b9be1dbSAhmed Bougacha     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
12696b9be1dbSAhmed Bougacha             FTy.getParamType(0)->isPointerTy() &&
12706b9be1dbSAhmed Bougacha             FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
12716b9be1dbSAhmed Bougacha 
127260b40b8fSMatthias Braun   case LibFunc_wcslen:
127360b40b8fSMatthias Braun     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
127460b40b8fSMatthias Braun             FTy.getReturnType()->isIntegerTy());
127560b40b8fSMatthias Braun 
12762ff24731SHal Finkel   case LibFunc_cabs:
12772ff24731SHal Finkel   case LibFunc_cabsf:
12782ff24731SHal Finkel   case LibFunc_cabsl: {
12792ff24731SHal Finkel     Type* RetTy = FTy.getReturnType();
12802ff24731SHal Finkel     if (!RetTy->isFloatingPointTy())
12812ff24731SHal Finkel       return false;
12822ff24731SHal Finkel 
12832ff24731SHal Finkel     // NOTE: These prototypes are target specific and currently support
12842ff24731SHal Finkel     // "complex" passed as an array or discrete real & imaginary parameters.
12852ff24731SHal Finkel     // Add other calling conventions to enable libcall optimizations.
12862ff24731SHal Finkel     if (NumParams == 1)
12872ff24731SHal Finkel       return (FTy.getParamType(0)->isArrayTy() &&
12882ff24731SHal Finkel               FTy.getParamType(0)->getArrayNumElements() == 2 &&
12892ff24731SHal Finkel               FTy.getParamType(0)->getArrayElementType() == RetTy);
12902ff24731SHal Finkel     else if (NumParams == 2)
12912ff24731SHal Finkel       return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
12922ff24731SHal Finkel     else
12932ff24731SHal Finkel       return false;
12942ff24731SHal Finkel   }
12956b9be1dbSAhmed Bougacha   case LibFunc::NumLibFuncs:
129686b680a3SAhmed Bougacha     break;
1297d765a82bSAhmed Bougacha   }
12986b9be1dbSAhmed Bougacha 
129986b680a3SAhmed Bougacha   llvm_unreachable("Invalid libfunc");
1300d765a82bSAhmed Bougacha }
1301d765a82bSAhmed Bougacha 
1302d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1303d21529faSDavid L. Jones                                        LibFunc &F) const {
1304d765a82bSAhmed Bougacha   const DataLayout *DL =
1305d765a82bSAhmed Bougacha       FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1306d765a82bSAhmed Bougacha   return getLibFunc(FDecl.getName(), F) &&
1307d765a82bSAhmed Bougacha          isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1308d765a82bSAhmed Bougacha }
1309d765a82bSAhmed Bougacha 
1310c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() {
131162d4215bSChandler Carruth   memset(AvailableArray, 0, sizeof(AvailableArray));
131262d4215bSChandler Carruth }
1313b98f63dbSChandler Carruth 
1314e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
13159a72cd7bSMehdi Amini   return LHS.ScalarFnName < RHS.ScalarFnName;
1316e8f2551fSMichael Zolotukhin }
1317e8f2551fSMichael Zolotukhin 
1318e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
13199a72cd7bSMehdi Amini   return LHS.VectorFnName < RHS.VectorFnName;
1320e8f2551fSMichael Zolotukhin }
1321e8f2551fSMichael Zolotukhin 
1322e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
13239a72cd7bSMehdi Amini   return LHS.ScalarFnName < S;
1324e8f2551fSMichael Zolotukhin }
1325e8f2551fSMichael Zolotukhin 
1326e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
13279a72cd7bSMehdi Amini   return LHS.VectorFnName < S;
1328e8f2551fSMichael Zolotukhin }
1329e8f2551fSMichael Zolotukhin 
1330e8f2551fSMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1331e8f2551fSMichael Zolotukhin   VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1332e8f2551fSMichael Zolotukhin   std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1333e8f2551fSMichael Zolotukhin 
1334e8f2551fSMichael Zolotukhin   ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1335e8f2551fSMichael Zolotukhin   std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1336e8f2551fSMichael Zolotukhin }
1337e8f2551fSMichael Zolotukhin 
13386d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
13396d8a2aa9SMichael Zolotukhin     enum VectorLibrary VecLib) {
13406d8a2aa9SMichael Zolotukhin   switch (VecLib) {
13416d8a2aa9SMichael Zolotukhin   case Accelerate: {
13426d8a2aa9SMichael Zolotukhin     const VecDesc VecFuncs[] = {
1343de63aaceSMichael Zolotukhin         // Floating-Point Arithmetic and Auxiliary Functions
1344de63aaceSMichael Zolotukhin         {"ceilf", "vceilf", 4},
13456d8a2aa9SMichael Zolotukhin         {"fabsf", "vfabsf", 4},
13466d8a2aa9SMichael Zolotukhin         {"llvm.fabs.f32", "vfabsf", 4},
1347de63aaceSMichael Zolotukhin         {"floorf", "vfloorf", 4},
1348de63aaceSMichael Zolotukhin         {"sqrtf", "vsqrtf", 4},
1349de63aaceSMichael Zolotukhin         {"llvm.sqrt.f32", "vsqrtf", 4},
1350de63aaceSMichael Zolotukhin 
1351de63aaceSMichael Zolotukhin         // Exponential and Logarithmic Functions
1352de63aaceSMichael Zolotukhin         {"expf", "vexpf", 4},
1353de63aaceSMichael Zolotukhin         {"llvm.exp.f32", "vexpf", 4},
1354de63aaceSMichael Zolotukhin         {"expm1f", "vexpm1f", 4},
1355de63aaceSMichael Zolotukhin         {"logf", "vlogf", 4},
1356de63aaceSMichael Zolotukhin         {"llvm.log.f32", "vlogf", 4},
1357de63aaceSMichael Zolotukhin         {"log1pf", "vlog1pf", 4},
1358de63aaceSMichael Zolotukhin         {"log10f", "vlog10f", 4},
1359de63aaceSMichael Zolotukhin         {"llvm.log10.f32", "vlog10f", 4},
1360de63aaceSMichael Zolotukhin         {"logbf", "vlogbf", 4},
1361de63aaceSMichael Zolotukhin 
1362de63aaceSMichael Zolotukhin         // Trigonometric Functions
1363de63aaceSMichael Zolotukhin         {"sinf", "vsinf", 4},
1364de63aaceSMichael Zolotukhin         {"llvm.sin.f32", "vsinf", 4},
1365de63aaceSMichael Zolotukhin         {"cosf", "vcosf", 4},
1366de63aaceSMichael Zolotukhin         {"llvm.cos.f32", "vcosf", 4},
1367de63aaceSMichael Zolotukhin         {"tanf", "vtanf", 4},
1368de63aaceSMichael Zolotukhin         {"asinf", "vasinf", 4},
1369de63aaceSMichael Zolotukhin         {"acosf", "vacosf", 4},
1370de63aaceSMichael Zolotukhin         {"atanf", "vatanf", 4},
1371de63aaceSMichael Zolotukhin 
1372de63aaceSMichael Zolotukhin         // Hyperbolic Functions
1373de63aaceSMichael Zolotukhin         {"sinhf", "vsinhf", 4},
1374de63aaceSMichael Zolotukhin         {"coshf", "vcoshf", 4},
1375de63aaceSMichael Zolotukhin         {"tanhf", "vtanhf", 4},
1376de63aaceSMichael Zolotukhin         {"asinhf", "vasinhf", 4},
1377de63aaceSMichael Zolotukhin         {"acoshf", "vacoshf", 4},
1378de63aaceSMichael Zolotukhin         {"atanhf", "vatanhf", 4},
13796d8a2aa9SMichael Zolotukhin     };
13806d8a2aa9SMichael Zolotukhin     addVectorizableFunctions(VecFuncs);
13816d8a2aa9SMichael Zolotukhin     break;
13826d8a2aa9SMichael Zolotukhin   }
1383a6669a1eSMatt Masten   case SVML: {
1384a6669a1eSMatt Masten     const VecDesc VecFuncs[] = {
1385a6669a1eSMatt Masten         {"sin", "__svml_sin2", 2},
1386a6669a1eSMatt Masten         {"sin", "__svml_sin4", 4},
1387a6669a1eSMatt Masten         {"sin", "__svml_sin8", 8},
1388a6669a1eSMatt Masten 
1389a6669a1eSMatt Masten         {"sinf", "__svml_sinf4", 4},
1390a6669a1eSMatt Masten         {"sinf", "__svml_sinf8", 8},
1391a6669a1eSMatt Masten         {"sinf", "__svml_sinf16", 16},
1392a6669a1eSMatt Masten 
1393a6669a1eSMatt Masten         {"cos", "__svml_cos2", 2},
1394a6669a1eSMatt Masten         {"cos", "__svml_cos4", 4},
1395a6669a1eSMatt Masten         {"cos", "__svml_cos8", 8},
1396a6669a1eSMatt Masten 
1397a6669a1eSMatt Masten         {"cosf", "__svml_cosf4", 4},
1398a6669a1eSMatt Masten         {"cosf", "__svml_cosf8", 8},
1399a6669a1eSMatt Masten         {"cosf", "__svml_cosf16", 16},
1400a6669a1eSMatt Masten 
1401a6669a1eSMatt Masten         {"pow", "__svml_pow2", 2},
1402a6669a1eSMatt Masten         {"pow", "__svml_pow4", 4},
1403a6669a1eSMatt Masten         {"pow", "__svml_pow8", 8},
1404a6669a1eSMatt Masten 
1405a6669a1eSMatt Masten         {"powf", "__svml_powf4", 4},
1406a6669a1eSMatt Masten         {"powf", "__svml_powf8", 8},
1407a6669a1eSMatt Masten         {"powf", "__svml_powf16", 16},
1408a6669a1eSMatt Masten 
1409b01e94eeSAndrew Kaylor         { "__pow_finite", "__svml_pow2", 2 },
1410b01e94eeSAndrew Kaylor         { "__pow_finite", "__svml_pow4", 4 },
1411b01e94eeSAndrew Kaylor         { "__pow_finite", "__svml_pow8", 8 },
1412b01e94eeSAndrew Kaylor 
1413b01e94eeSAndrew Kaylor         { "__powf_finite", "__svml_powf4", 4 },
1414b01e94eeSAndrew Kaylor         { "__powf_finite", "__svml_powf8", 8 },
1415b01e94eeSAndrew Kaylor         { "__powf_finite", "__svml_powf16", 16 },
1416b01e94eeSAndrew Kaylor 
1417a6669a1eSMatt Masten         {"llvm.pow.f64", "__svml_pow2", 2},
1418a6669a1eSMatt Masten         {"llvm.pow.f64", "__svml_pow4", 4},
1419a6669a1eSMatt Masten         {"llvm.pow.f64", "__svml_pow8", 8},
1420a6669a1eSMatt Masten 
1421a6669a1eSMatt Masten         {"llvm.pow.f32", "__svml_powf4", 4},
1422a6669a1eSMatt Masten         {"llvm.pow.f32", "__svml_powf8", 8},
1423a6669a1eSMatt Masten         {"llvm.pow.f32", "__svml_powf16", 16},
1424a6669a1eSMatt Masten 
1425a6669a1eSMatt Masten         {"exp", "__svml_exp2", 2},
1426a6669a1eSMatt Masten         {"exp", "__svml_exp4", 4},
1427a6669a1eSMatt Masten         {"exp", "__svml_exp8", 8},
1428a6669a1eSMatt Masten 
1429a6669a1eSMatt Masten         {"expf", "__svml_expf4", 4},
1430a6669a1eSMatt Masten         {"expf", "__svml_expf8", 8},
1431a6669a1eSMatt Masten         {"expf", "__svml_expf16", 16},
1432a6669a1eSMatt Masten 
1433b01e94eeSAndrew Kaylor         { "__exp_finite", "__svml_exp2", 2 },
1434b01e94eeSAndrew Kaylor         { "__exp_finite", "__svml_exp4", 4 },
1435b01e94eeSAndrew Kaylor         { "__exp_finite", "__svml_exp8", 8 },
1436b01e94eeSAndrew Kaylor 
1437b01e94eeSAndrew Kaylor         { "__expf_finite", "__svml_expf4", 4 },
1438b01e94eeSAndrew Kaylor         { "__expf_finite", "__svml_expf8", 8 },
1439b01e94eeSAndrew Kaylor         { "__expf_finite", "__svml_expf16", 16 },
1440b01e94eeSAndrew Kaylor 
1441a6669a1eSMatt Masten         {"llvm.exp.f64", "__svml_exp2", 2},
1442a6669a1eSMatt Masten         {"llvm.exp.f64", "__svml_exp4", 4},
1443a6669a1eSMatt Masten         {"llvm.exp.f64", "__svml_exp8", 8},
1444a6669a1eSMatt Masten 
1445a6669a1eSMatt Masten         {"llvm.exp.f32", "__svml_expf4", 4},
1446a6669a1eSMatt Masten         {"llvm.exp.f32", "__svml_expf8", 8},
1447a6669a1eSMatt Masten         {"llvm.exp.f32", "__svml_expf16", 16},
1448a6669a1eSMatt Masten 
1449a6669a1eSMatt Masten         {"log", "__svml_log2", 2},
1450a6669a1eSMatt Masten         {"log", "__svml_log4", 4},
1451a6669a1eSMatt Masten         {"log", "__svml_log8", 8},
1452a6669a1eSMatt Masten 
1453a6669a1eSMatt Masten         {"logf", "__svml_logf4", 4},
1454a6669a1eSMatt Masten         {"logf", "__svml_logf8", 8},
1455a6669a1eSMatt Masten         {"logf", "__svml_logf16", 16},
1456a6669a1eSMatt Masten 
1457b01e94eeSAndrew Kaylor         { "__log_finite", "__svml_log2", 2 },
1458b01e94eeSAndrew Kaylor         { "__log_finite", "__svml_log4", 4 },
1459b01e94eeSAndrew Kaylor         { "__log_finite", "__svml_log8", 8 },
1460b01e94eeSAndrew Kaylor 
1461b01e94eeSAndrew Kaylor         { "__logf_finite", "__svml_logf4", 4 },
1462b01e94eeSAndrew Kaylor         { "__logf_finite", "__svml_logf8", 8 },
1463b01e94eeSAndrew Kaylor         { "__logf_finite", "__svml_logf16", 16 },
1464b01e94eeSAndrew Kaylor 
1465a6669a1eSMatt Masten         {"llvm.log.f64", "__svml_log2", 2},
1466a6669a1eSMatt Masten         {"llvm.log.f64", "__svml_log4", 4},
1467a6669a1eSMatt Masten         {"llvm.log.f64", "__svml_log8", 8},
1468a6669a1eSMatt Masten 
1469a6669a1eSMatt Masten         {"llvm.log.f32", "__svml_logf4", 4},
1470a6669a1eSMatt Masten         {"llvm.log.f32", "__svml_logf8", 8},
1471a6669a1eSMatt Masten         {"llvm.log.f32", "__svml_logf16", 16},
1472a6669a1eSMatt Masten     };
1473a6669a1eSMatt Masten     addVectorizableFunctions(VecFuncs);
1474a6669a1eSMatt Masten     break;
1475a6669a1eSMatt Masten   }
14766d8a2aa9SMichael Zolotukhin   case NoLibrary:
14776d8a2aa9SMichael Zolotukhin     break;
14786d8a2aa9SMichael Zolotukhin   }
14796d8a2aa9SMichael Zolotukhin }
14806d8a2aa9SMichael Zolotukhin 
1481e8f2551fSMichael Zolotukhin bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1482e8f2551fSMichael Zolotukhin   funcName = sanitizeFunctionName(funcName);
1483e8f2551fSMichael Zolotukhin   if (funcName.empty())
1484e8f2551fSMichael Zolotukhin     return false;
1485e8f2551fSMichael Zolotukhin 
1486e8f2551fSMichael Zolotukhin   std::vector<VecDesc>::const_iterator I = std::lower_bound(
1487e8f2551fSMichael Zolotukhin       VectorDescs.begin(), VectorDescs.end(), funcName,
1488e8f2551fSMichael Zolotukhin       compareWithScalarFnName);
1489e8f2551fSMichael Zolotukhin   return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1490e8f2551fSMichael Zolotukhin }
1491e8f2551fSMichael Zolotukhin 
1492e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1493e8f2551fSMichael Zolotukhin                                                        unsigned VF) const {
1494e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1495e8f2551fSMichael Zolotukhin   if (F.empty())
1496e8f2551fSMichael Zolotukhin     return F;
1497e8f2551fSMichael Zolotukhin   std::vector<VecDesc>::const_iterator I = std::lower_bound(
1498e8f2551fSMichael Zolotukhin       VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1499e8f2551fSMichael Zolotukhin   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1500e8f2551fSMichael Zolotukhin     if (I->VectorizationFactor == VF)
1501e8f2551fSMichael Zolotukhin       return I->VectorFnName;
1502e8f2551fSMichael Zolotukhin     ++I;
1503e8f2551fSMichael Zolotukhin   }
1504e8f2551fSMichael Zolotukhin   return StringRef();
1505e8f2551fSMichael Zolotukhin }
1506e8f2551fSMichael Zolotukhin 
1507e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1508e8f2551fSMichael Zolotukhin                                                        unsigned &VF) const {
1509e8f2551fSMichael Zolotukhin   F = sanitizeFunctionName(F);
1510e8f2551fSMichael Zolotukhin   if (F.empty())
1511e8f2551fSMichael Zolotukhin     return F;
1512e8f2551fSMichael Zolotukhin 
1513e8f2551fSMichael Zolotukhin   std::vector<VecDesc>::const_iterator I = std::lower_bound(
1514e8f2551fSMichael Zolotukhin       ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1515e8f2551fSMichael Zolotukhin   if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1516e8f2551fSMichael Zolotukhin     return StringRef();
1517e8f2551fSMichael Zolotukhin   VF = I->VectorizationFactor;
1518e8f2551fSMichael Zolotukhin   return I->ScalarFnName;
1519e8f2551fSMichael Zolotukhin }
1520e8f2551fSMichael Zolotukhin 
1521164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1522164a2aa6SChandler Carruth                                              ModuleAnalysisManager &) {
1523c0291865SChandler Carruth   if (PresetInfoImpl)
1524c0291865SChandler Carruth     return TargetLibraryInfo(*PresetInfoImpl);
1525c0291865SChandler Carruth 
1526c0291865SChandler Carruth   return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1527c0291865SChandler Carruth }
1528c0291865SChandler Carruth 
1529164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1530164a2aa6SChandler Carruth                                              FunctionAnalysisManager &) {
1531c0291865SChandler Carruth   if (PresetInfoImpl)
1532c0291865SChandler Carruth     return TargetLibraryInfo(*PresetInfoImpl);
1533c0291865SChandler Carruth 
1534c0291865SChandler Carruth   return TargetLibraryInfo(
1535c0291865SChandler Carruth       lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1536c0291865SChandler Carruth }
1537c0291865SChandler Carruth 
1538c321e534SBenjamin Kramer TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
1539c0291865SChandler Carruth   std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1540c0291865SChandler Carruth       Impls[T.normalize()];
1541c0291865SChandler Carruth   if (!Impl)
1542c0291865SChandler Carruth     Impl.reset(new TargetLibraryInfoImpl(T));
1543c0291865SChandler Carruth 
1544c0291865SChandler Carruth   return *Impl;
1545c0291865SChandler Carruth }
1546c0291865SChandler Carruth 
154750ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
154850ec0b5dSMatthias Braun   if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
154950ec0b5dSMatthias Braun       M.getModuleFlag("wchar_size")))
155050ec0b5dSMatthias Braun     return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1551cc603ee3SMatthias Braun   return 0;
155250ec0b5dSMatthias Braun }
1553c0291865SChandler Carruth 
1554b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1555c0291865SChandler Carruth     : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
1556b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1557b98f63dbSChandler Carruth }
1558b98f63dbSChandler Carruth 
1559b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
1560c0291865SChandler Carruth     : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
1561b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1562b98f63dbSChandler Carruth }
1563b98f63dbSChandler Carruth 
1564b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1565c0291865SChandler Carruth     const TargetLibraryInfoImpl &TLIImpl)
1566c0291865SChandler Carruth     : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
1567b98f63dbSChandler Carruth   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1568b98f63dbSChandler Carruth }
1569b98f63dbSChandler Carruth 
1570dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key;
1571df0cd726SNAKAMURA Takumi 
1572b98f63dbSChandler Carruth // Register the basic pass.
1573b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1574b98f63dbSChandler Carruth                 "Target Library Information", false, true)
1575b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0;
1576b98f63dbSChandler Carruth 
1577b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {}
1578