LLVM  14.0.0git
TargetLibraryInfo.cpp
Go to the documentation of this file.
1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the TargetLibraryInfo class.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/IR/Constants.h"
16 #include "llvm/InitializePasses.h"
18 using namespace llvm;
19 
21  "vector-library", cl::Hidden, cl::desc("Vector functions library"),
24  "No vector functions library"),
26  "Accelerate framework"),
28  "Darwin_libsystem_m", "Darwin libsystem_m"),
30  "GLIBC Vector Math library"),
32  "IBM MASS vector library"),
34  "Intel SVML library")));
35 
36 StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
37  {
38 #define TLI_DEFINE_STRING
39 #include "llvm/Analysis/TargetLibraryInfo.def"
40 };
41 
42 static bool hasSinCosPiStret(const Triple &T) {
43  // Only Darwin variants have _stret versions of combined trig functions.
44  if (!T.isOSDarwin())
45  return false;
46 
47  // The ABI is rather complicated on x86, so don't do anything special there.
48  if (T.getArch() == Triple::x86)
49  return false;
50 
51  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
52  return false;
53 
54  if (T.isiOS() && T.isOSVersionLT(7, 0))
55  return false;
56 
57  return true;
58 }
59 
60 static bool hasBcmp(const Triple &TT) {
61  // Posix removed support from bcmp() in 2001, but the glibc and several
62  // implementations of the libc still have it.
63  if (TT.isOSLinux())
64  return TT.isGNUEnvironment() || TT.isMusl();
65  // Both NetBSD and OpenBSD are planning to remove the function. Windows does
66  // not have it.
67  return TT.isOSFreeBSD() || TT.isOSSolaris();
68 }
69 
71  FunctionType *FuncTy) {
72  switch (CC) {
73  default:
74  return false;
76  return true;
80 
81  // The iOS ABI diverges from the standard in some cases, so for now don't
82  // try to simplify those calls.
83  if (Triple(TT).isiOS())
84  return false;
85 
86  if (!FuncTy->getReturnType()->isPointerTy() &&
87  !FuncTy->getReturnType()->isIntegerTy() &&
88  !FuncTy->getReturnType()->isVoidTy())
89  return false;
90 
91  for (auto *Param : FuncTy->params()) {
92  if (!Param->isPointerTy() && !Param->isIntegerTy())
93  return false;
94  }
95  return true;
96  }
97  }
98  return false;
99 }
100 
103  CI->getModule()->getTargetTriple(),
104  CI->getFunctionType());
105 }
106 
108  return ::isCallingConvCCompatible(F->getCallingConv(),
109  F->getParent()->getTargetTriple(),
110  F->getFunctionType());
111 }
112 
113 /// Initialize the set of available library functions based on the specified
114 /// target triple. This should be carefully written so that a missing target
115 /// triple gets a sane set of defaults.
116 static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
117  ArrayRef<StringLiteral> StandardNames) {
118  // Verify that the StandardNames array is in alphabetical order.
119  assert(
120  llvm::is_sorted(StandardNames,
121  [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) &&
122  "TargetLibraryInfoImpl function names must be sorted");
123 
124  // Set IO unlocked variants as unavailable
125  // Set them as available per system below
126  TLI.setUnavailable(LibFunc_getc_unlocked);
127  TLI.setUnavailable(LibFunc_getchar_unlocked);
128  TLI.setUnavailable(LibFunc_putc_unlocked);
129  TLI.setUnavailable(LibFunc_putchar_unlocked);
130  TLI.setUnavailable(LibFunc_fputc_unlocked);
131  TLI.setUnavailable(LibFunc_fgetc_unlocked);
132  TLI.setUnavailable(LibFunc_fread_unlocked);
133  TLI.setUnavailable(LibFunc_fwrite_unlocked);
134  TLI.setUnavailable(LibFunc_fputs_unlocked);
135  TLI.setUnavailable(LibFunc_fgets_unlocked);
136 
137  bool ShouldExtI32Param = false, ShouldExtI32Return = false,
138  ShouldSignExtI32Param = false;
139  // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
140  // returns corresponding to C-level ints and unsigned ints.
141  if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
142  T.getArch() == Triple::systemz) {
143  ShouldExtI32Param = true;
144  ShouldExtI32Return = true;
145  }
146  // Mips, on the other hand, needs signext on i32 parameters corresponding
147  // to both signed and unsigned ints.
148  if (T.isMIPS()) {
149  ShouldSignExtI32Param = true;
150  }
151  TLI.setShouldExtI32Param(ShouldExtI32Param);
152  TLI.setShouldExtI32Return(ShouldExtI32Return);
153  TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
154 
155  // Let's assume by default that the size of int is 32 bits, unless the target
156  // is a 16-bit architecture because then it most likely is 16 bits. If that
157  // isn't true for a target those defaults should be overridden below.
158  TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
159 
160  // There is really no runtime library on AMDGPU, apart from
161  // __kmpc_alloc/free_shared.
162  if (T.isAMDGPU()) {
163  TLI.disableAllFunctions();
164  TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
165  TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
166  return;
167  }
168 
169  // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
170  // All versions of watchOS support it.
171  if (T.isMacOSX()) {
172  // available IO unlocked variants on Mac OS X
173  TLI.setAvailable(LibFunc_getc_unlocked);
174  TLI.setAvailable(LibFunc_getchar_unlocked);
175  TLI.setAvailable(LibFunc_putc_unlocked);
176  TLI.setAvailable(LibFunc_putchar_unlocked);
177 
178  if (T.isMacOSXVersionLT(10, 5))
179  TLI.setUnavailable(LibFunc_memset_pattern16);
180  } else if (T.isiOS()) {
181  if (T.isOSVersionLT(3, 0))
182  TLI.setUnavailable(LibFunc_memset_pattern16);
183  } else if (!T.isWatchOS()) {
184  TLI.setUnavailable(LibFunc_memset_pattern16);
185  }
186 
187  if (!hasSinCosPiStret(T)) {
188  TLI.setUnavailable(LibFunc_sinpi);
189  TLI.setUnavailable(LibFunc_sinpif);
190  TLI.setUnavailable(LibFunc_cospi);
191  TLI.setUnavailable(LibFunc_cospif);
192  TLI.setUnavailable(LibFunc_sincospi_stret);
193  TLI.setUnavailable(LibFunc_sincospif_stret);
194  }
195 
196  if (!hasBcmp(T))
197  TLI.setUnavailable(LibFunc_bcmp);
198 
199  if (T.isMacOSX() && T.getArch() == Triple::x86 &&
200  !T.isMacOSXVersionLT(10, 7)) {
201  // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
202  // we don't care about) have two versions; on recent OSX, the one we want
203  // has a $UNIX2003 suffix. The two implementations are identical except
204  // for the return value in some edge cases. However, we don't want to
205  // generate code that depends on the old symbols.
206  TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
207  TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
208  }
209 
210  // iprintf and friends are only available on XCore, TCE, and Emscripten.
211  if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
212  T.getOS() != Triple::Emscripten) {
213  TLI.setUnavailable(LibFunc_iprintf);
214  TLI.setUnavailable(LibFunc_siprintf);
215  TLI.setUnavailable(LibFunc_fiprintf);
216  }
217 
218  // __small_printf and friends are only available on Emscripten.
219  if (T.getOS() != Triple::Emscripten) {
220  TLI.setUnavailable(LibFunc_small_printf);
221  TLI.setUnavailable(LibFunc_small_sprintf);
222  TLI.setUnavailable(LibFunc_small_fprintf);
223  }
224 
225  if (T.isOSWindows() && !T.isOSCygMing()) {
226  // XXX: The earliest documentation available at the moment is for VS2015/VC19:
227  // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
228  // XXX: In order to use an MSVCRT older than VC19,
229  // the specific library version must be explicit in the target triple,
230  // e.g., x86_64-pc-windows-msvc18.
231  bool hasPartialC99 = true;
232  if (T.isKnownWindowsMSVCEnvironment()) {
233  unsigned Major, Minor, Micro;
234  T.getEnvironmentVersion(Major, Minor, Micro);
235  hasPartialC99 = (Major == 0 || Major >= 19);
236  }
237 
238  // Latest targets support C89 math functions, in part.
239  bool isARM = (T.getArch() == Triple::aarch64 ||
240  T.getArch() == Triple::arm);
241  bool hasPartialFloat = (isARM ||
242  T.getArch() == Triple::x86_64);
243 
244  // Win32 does not support float C89 math functions, in general.
245  if (!hasPartialFloat) {
246  TLI.setUnavailable(LibFunc_acosf);
247  TLI.setUnavailable(LibFunc_asinf);
248  TLI.setUnavailable(LibFunc_atan2f);
249  TLI.setUnavailable(LibFunc_atanf);
250  TLI.setUnavailable(LibFunc_ceilf);
251  TLI.setUnavailable(LibFunc_cosf);
252  TLI.setUnavailable(LibFunc_coshf);
253  TLI.setUnavailable(LibFunc_expf);
254  TLI.setUnavailable(LibFunc_floorf);
255  TLI.setUnavailable(LibFunc_fmodf);
256  TLI.setUnavailable(LibFunc_log10f);
257  TLI.setUnavailable(LibFunc_logf);
258  TLI.setUnavailable(LibFunc_modff);
259  TLI.setUnavailable(LibFunc_powf);
260  TLI.setUnavailable(LibFunc_remainderf);
261  TLI.setUnavailable(LibFunc_sinf);
262  TLI.setUnavailable(LibFunc_sinhf);
263  TLI.setUnavailable(LibFunc_sqrtf);
264  TLI.setUnavailable(LibFunc_tanf);
265  TLI.setUnavailable(LibFunc_tanhf);
266  }
267  if (!isARM)
268  TLI.setUnavailable(LibFunc_fabsf);
269  TLI.setUnavailable(LibFunc_frexpf);
270  TLI.setUnavailable(LibFunc_ldexpf);
271 
272  // Win32 does not support long double C89 math functions.
273  TLI.setUnavailable(LibFunc_acosl);
274  TLI.setUnavailable(LibFunc_asinl);
275  TLI.setUnavailable(LibFunc_atan2l);
276  TLI.setUnavailable(LibFunc_atanl);
277  TLI.setUnavailable(LibFunc_ceill);
278  TLI.setUnavailable(LibFunc_cosl);
279  TLI.setUnavailable(LibFunc_coshl);
280  TLI.setUnavailable(LibFunc_expl);
281  TLI.setUnavailable(LibFunc_fabsl);
282  TLI.setUnavailable(LibFunc_floorl);
283  TLI.setUnavailable(LibFunc_fmodl);
284  TLI.setUnavailable(LibFunc_frexpl);
285  TLI.setUnavailable(LibFunc_ldexpl);
286  TLI.setUnavailable(LibFunc_log10l);
287  TLI.setUnavailable(LibFunc_logl);
288  TLI.setUnavailable(LibFunc_modfl);
289  TLI.setUnavailable(LibFunc_powl);
290  TLI.setUnavailable(LibFunc_remainderl);
291  TLI.setUnavailable(LibFunc_sinl);
292  TLI.setUnavailable(LibFunc_sinhl);
293  TLI.setUnavailable(LibFunc_sqrtl);
294  TLI.setUnavailable(LibFunc_tanl);
295  TLI.setUnavailable(LibFunc_tanhl);
296 
297  // Win32 does not fully support C99 math functions.
298  if (!hasPartialC99) {
299  TLI.setUnavailable(LibFunc_acosh);
300  TLI.setUnavailable(LibFunc_acoshf);
301  TLI.setUnavailable(LibFunc_asinh);
302  TLI.setUnavailable(LibFunc_asinhf);
303  TLI.setUnavailable(LibFunc_atanh);
304  TLI.setUnavailable(LibFunc_atanhf);
305  TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
306  TLI.setUnavailable(LibFunc_cabsf);
307  TLI.setUnavailable(LibFunc_cbrt);
308  TLI.setUnavailable(LibFunc_cbrtf);
309  TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
310  TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
311  TLI.setUnavailable(LibFunc_exp2);
312  TLI.setUnavailable(LibFunc_exp2f);
313  TLI.setUnavailable(LibFunc_expm1);
314  TLI.setUnavailable(LibFunc_expm1f);
315  TLI.setUnavailable(LibFunc_fmax);
316  TLI.setUnavailable(LibFunc_fmaxf);
317  TLI.setUnavailable(LibFunc_fmin);
318  TLI.setUnavailable(LibFunc_fminf);
319  TLI.setUnavailable(LibFunc_log1p);
320  TLI.setUnavailable(LibFunc_log1pf);
321  TLI.setUnavailable(LibFunc_log2);
322  TLI.setUnavailable(LibFunc_log2f);
323  TLI.setAvailableWithName(LibFunc_logb, "_logb");
324  if (hasPartialFloat)
325  TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
326  else
327  TLI.setUnavailable(LibFunc_logbf);
328  TLI.setUnavailable(LibFunc_rint);
329  TLI.setUnavailable(LibFunc_rintf);
330  TLI.setUnavailable(LibFunc_round);
331  TLI.setUnavailable(LibFunc_roundf);
332  TLI.setUnavailable(LibFunc_trunc);
333  TLI.setUnavailable(LibFunc_truncf);
334  }
335 
336  // Win32 does not support long double C99 math functions.
337  TLI.setUnavailable(LibFunc_acoshl);
338  TLI.setUnavailable(LibFunc_asinhl);
339  TLI.setUnavailable(LibFunc_atanhl);
340  TLI.setUnavailable(LibFunc_cabsl);
341  TLI.setUnavailable(LibFunc_cbrtl);
342  TLI.setUnavailable(LibFunc_copysignl);
343  TLI.setUnavailable(LibFunc_exp2l);
344  TLI.setUnavailable(LibFunc_expm1l);
345  TLI.setUnavailable(LibFunc_fmaxl);
346  TLI.setUnavailable(LibFunc_fminl);
347  TLI.setUnavailable(LibFunc_log1pl);
348  TLI.setUnavailable(LibFunc_log2l);
349  TLI.setUnavailable(LibFunc_logbl);
350  TLI.setUnavailable(LibFunc_nearbyintl);
351  TLI.setUnavailable(LibFunc_rintl);
352  TLI.setUnavailable(LibFunc_roundl);
353  TLI.setUnavailable(LibFunc_truncl);
354 
355  // Win32 does not support these functions, but
356  // they are generally available on POSIX-compliant systems.
357  TLI.setUnavailable(LibFunc_access);
358  TLI.setUnavailable(LibFunc_chmod);
359  TLI.setUnavailable(LibFunc_closedir);
360  TLI.setUnavailable(LibFunc_fdopen);
361  TLI.setUnavailable(LibFunc_fileno);
362  TLI.setUnavailable(LibFunc_fseeko);
363  TLI.setUnavailable(LibFunc_fstat);
364  TLI.setUnavailable(LibFunc_ftello);
365  TLI.setUnavailable(LibFunc_gettimeofday);
366  TLI.setUnavailable(LibFunc_memccpy);
367  TLI.setUnavailable(LibFunc_mkdir);
368  TLI.setUnavailable(LibFunc_open);
369  TLI.setUnavailable(LibFunc_opendir);
370  TLI.setUnavailable(LibFunc_pclose);
371  TLI.setUnavailable(LibFunc_popen);
372  TLI.setUnavailable(LibFunc_read);
373  TLI.setUnavailable(LibFunc_rmdir);
374  TLI.setUnavailable(LibFunc_stat);
375  TLI.setUnavailable(LibFunc_strcasecmp);
376  TLI.setUnavailable(LibFunc_strncasecmp);
377  TLI.setUnavailable(LibFunc_unlink);
378  TLI.setUnavailable(LibFunc_utime);
379  TLI.setUnavailable(LibFunc_write);
380  }
381 
382  if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) {
383  // These functions aren't available in either MSVC or MinGW environments.
384  TLI.setUnavailable(LibFunc_bcmp);
385  TLI.setUnavailable(LibFunc_bcopy);
386  TLI.setUnavailable(LibFunc_bzero);
387  TLI.setUnavailable(LibFunc_chown);
388  TLI.setUnavailable(LibFunc_ctermid);
389  TLI.setUnavailable(LibFunc_ffs);
390  TLI.setUnavailable(LibFunc_flockfile);
391  TLI.setUnavailable(LibFunc_fstatvfs);
392  TLI.setUnavailable(LibFunc_ftrylockfile);
393  TLI.setUnavailable(LibFunc_funlockfile);
394  TLI.setUnavailable(LibFunc_getitimer);
395  TLI.setUnavailable(LibFunc_getlogin_r);
396  TLI.setUnavailable(LibFunc_getpwnam);
397  TLI.setUnavailable(LibFunc_htonl);
398  TLI.setUnavailable(LibFunc_htons);
399  TLI.setUnavailable(LibFunc_lchown);
400  TLI.setUnavailable(LibFunc_lstat);
401  TLI.setUnavailable(LibFunc_ntohl);
402  TLI.setUnavailable(LibFunc_ntohs);
403  TLI.setUnavailable(LibFunc_pread);
404  TLI.setUnavailable(LibFunc_pwrite);
405  TLI.setUnavailable(LibFunc_readlink);
406  TLI.setUnavailable(LibFunc_realpath);
407  TLI.setUnavailable(LibFunc_setitimer);
408  TLI.setUnavailable(LibFunc_statvfs);
409  TLI.setUnavailable(LibFunc_stpcpy);
410  TLI.setUnavailable(LibFunc_stpncpy);
411  TLI.setUnavailable(LibFunc_times);
412  TLI.setUnavailable(LibFunc_uname);
413  TLI.setUnavailable(LibFunc_unsetenv);
414  TLI.setUnavailable(LibFunc_utimes);
415  }
416 
417  // Pick just one set of new/delete variants.
418  if (T.isOSMSVCRT()) {
419  // MSVC, doesn't have the Itanium new/delete.
420  TLI.setUnavailable(LibFunc_ZdaPv);
421  TLI.setUnavailable(LibFunc_ZdaPvRKSt9nothrow_t);
422  TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_t);
423  TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t);
424  TLI.setUnavailable(LibFunc_ZdaPvj);
425  TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
426  TLI.setUnavailable(LibFunc_ZdaPvm);
427  TLI.setUnavailable(LibFunc_ZdaPvmSt11align_val_t);
428  TLI.setUnavailable(LibFunc_ZdlPv);
429  TLI.setUnavailable(LibFunc_ZdlPvRKSt9nothrow_t);
430  TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_t);
431  TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t);
432  TLI.setUnavailable(LibFunc_ZdlPvj);
433  TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
434  TLI.setUnavailable(LibFunc_ZdlPvm);
435  TLI.setUnavailable(LibFunc_ZdlPvmSt11align_val_t);
436  TLI.setUnavailable(LibFunc_Znaj);
437  TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
438  TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
439  TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
440  TLI.setUnavailable(LibFunc_Znam);
441  TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t);
442  TLI.setUnavailable(LibFunc_ZnamSt11align_val_t);
443  TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t);
444  TLI.setUnavailable(LibFunc_Znwj);
445  TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
446  TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
447  TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
448  TLI.setUnavailable(LibFunc_Znwm);
449  TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t);
450  TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t);
451  TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t);
452  } else {
453  // Not MSVC, assume it's Itanium.
454  TLI.setUnavailable(LibFunc_msvc_new_int);
455  TLI.setUnavailable(LibFunc_msvc_new_int_nothrow);
456  TLI.setUnavailable(LibFunc_msvc_new_longlong);
457  TLI.setUnavailable(LibFunc_msvc_new_longlong_nothrow);
458  TLI.setUnavailable(LibFunc_msvc_delete_ptr32);
459  TLI.setUnavailable(LibFunc_msvc_delete_ptr32_nothrow);
460  TLI.setUnavailable(LibFunc_msvc_delete_ptr32_int);
461  TLI.setUnavailable(LibFunc_msvc_delete_ptr64);
462  TLI.setUnavailable(LibFunc_msvc_delete_ptr64_nothrow);
463  TLI.setUnavailable(LibFunc_msvc_delete_ptr64_longlong);
464  TLI.setUnavailable(LibFunc_msvc_new_array_int);
465  TLI.setUnavailable(LibFunc_msvc_new_array_int_nothrow);
466  TLI.setUnavailable(LibFunc_msvc_new_array_longlong);
467  TLI.setUnavailable(LibFunc_msvc_new_array_longlong_nothrow);
468  TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32);
469  TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_nothrow);
470  TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_int);
471  TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64);
472  TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_nothrow);
473  TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_longlong);
474  }
475 
476  switch (T.getOS()) {
477  case Triple::MacOSX:
478  // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
479  // and their names are __exp10 and __exp10f. exp10l is not available on
480  // OS X or iOS.
481  TLI.setUnavailable(LibFunc_exp10l);
482  if (T.isMacOSXVersionLT(10, 9)) {
483  TLI.setUnavailable(LibFunc_exp10);
484  TLI.setUnavailable(LibFunc_exp10f);
485  } else {
486  TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
487  TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
488  }
489  break;
490  case Triple::IOS:
491  case Triple::TvOS:
492  case Triple::WatchOS:
493  TLI.setUnavailable(LibFunc_exp10l);
494  if (!T.isWatchOS() &&
495  (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
496  TLI.setUnavailable(LibFunc_exp10);
497  TLI.setUnavailable(LibFunc_exp10f);
498  } else {
499  TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
500  TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
501  }
502  break;
503  case Triple::Linux:
504  // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
505  // buggy prior to glibc version 2.18. Until this version is widely deployed
506  // or we have a reasonable detection strategy, we cannot use exp10 reliably
507  // on Linux.
508  //
509  // Fall through to disable all of them.
511  default:
512  TLI.setUnavailable(LibFunc_exp10);
513  TLI.setUnavailable(LibFunc_exp10f);
514  TLI.setUnavailable(LibFunc_exp10l);
515  }
516 
517  // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
518  // Linux (GLIBC):
519  // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
520  // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
521  // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
522  switch (T.getOS()) {
523  case Triple::Darwin:
524  case Triple::MacOSX:
525  case Triple::IOS:
526  case Triple::TvOS:
527  case Triple::WatchOS:
528  case Triple::FreeBSD:
529  case Triple::Linux:
530  break;
531  default:
532  TLI.setUnavailable(LibFunc_ffsl);
533  }
534 
535  // ffsll is available on at least FreeBSD and Linux (GLIBC):
536  // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
537  // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
538  switch (T.getOS()) {
539  case Triple::Darwin:
540  case Triple::MacOSX:
541  case Triple::IOS:
542  case Triple::TvOS:
543  case Triple::WatchOS:
544  case Triple::FreeBSD:
545  case Triple::Linux:
546  break;
547  default:
548  TLI.setUnavailable(LibFunc_ffsll);
549  }
550 
551  // The following functions are available on at least FreeBSD:
552  // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
553  // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
554  // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
555  if (!T.isOSFreeBSD()) {
556  TLI.setUnavailable(LibFunc_fls);
557  TLI.setUnavailable(LibFunc_flsl);
558  TLI.setUnavailable(LibFunc_flsll);
559  }
560 
561  // The following functions are only available on GNU/Linux (using glibc).
562  // Linux variants without glibc (eg: bionic, musl) may have some subset.
563  if (!T.isOSLinux() || !T.isGNUEnvironment()) {
564  TLI.setUnavailable(LibFunc_dunder_strdup);
565  TLI.setUnavailable(LibFunc_dunder_strtok_r);
566  TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
567  TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
568  TLI.setUnavailable(LibFunc_under_IO_getc);
569  TLI.setUnavailable(LibFunc_under_IO_putc);
570  // But, Android and musl have memalign.
571  if (!T.isAndroid() && !T.isMusl())
572  TLI.setUnavailable(LibFunc_memalign);
573  TLI.setUnavailable(LibFunc_fopen64);
574  TLI.setUnavailable(LibFunc_fseeko64);
575  TLI.setUnavailable(LibFunc_fstat64);
576  TLI.setUnavailable(LibFunc_fstatvfs64);
577  TLI.setUnavailable(LibFunc_ftello64);
578  TLI.setUnavailable(LibFunc_lstat64);
579  TLI.setUnavailable(LibFunc_open64);
580  TLI.setUnavailable(LibFunc_stat64);
581  TLI.setUnavailable(LibFunc_statvfs64);
582  TLI.setUnavailable(LibFunc_tmpfile64);
583 
584  // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
585  // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
586  // so we keep these functions around just so that they're recognized by
587  // the ConstantFolder.
588  TLI.setUnavailable(LibFunc_acos_finite);
589  TLI.setUnavailable(LibFunc_acosf_finite);
590  TLI.setUnavailable(LibFunc_acosl_finite);
591  TLI.setUnavailable(LibFunc_acosh_finite);
592  TLI.setUnavailable(LibFunc_acoshf_finite);
593  TLI.setUnavailable(LibFunc_acoshl_finite);
594  TLI.setUnavailable(LibFunc_asin_finite);
595  TLI.setUnavailable(LibFunc_asinf_finite);
596  TLI.setUnavailable(LibFunc_asinl_finite);
597  TLI.setUnavailable(LibFunc_atan2_finite);
598  TLI.setUnavailable(LibFunc_atan2f_finite);
599  TLI.setUnavailable(LibFunc_atan2l_finite);
600  TLI.setUnavailable(LibFunc_atanh_finite);
601  TLI.setUnavailable(LibFunc_atanhf_finite);
602  TLI.setUnavailable(LibFunc_atanhl_finite);
603  TLI.setUnavailable(LibFunc_cosh_finite);
604  TLI.setUnavailable(LibFunc_coshf_finite);
605  TLI.setUnavailable(LibFunc_coshl_finite);
606  TLI.setUnavailable(LibFunc_exp10_finite);
607  TLI.setUnavailable(LibFunc_exp10f_finite);
608  TLI.setUnavailable(LibFunc_exp10l_finite);
609  TLI.setUnavailable(LibFunc_exp2_finite);
610  TLI.setUnavailable(LibFunc_exp2f_finite);
611  TLI.setUnavailable(LibFunc_exp2l_finite);
612  TLI.setUnavailable(LibFunc_exp_finite);
613  TLI.setUnavailable(LibFunc_expf_finite);
614  TLI.setUnavailable(LibFunc_expl_finite);
615  TLI.setUnavailable(LibFunc_log10_finite);
616  TLI.setUnavailable(LibFunc_log10f_finite);
617  TLI.setUnavailable(LibFunc_log10l_finite);
618  TLI.setUnavailable(LibFunc_log2_finite);
619  TLI.setUnavailable(LibFunc_log2f_finite);
620  TLI.setUnavailable(LibFunc_log2l_finite);
621  TLI.setUnavailable(LibFunc_log_finite);
622  TLI.setUnavailable(LibFunc_logf_finite);
623  TLI.setUnavailable(LibFunc_logl_finite);
624  TLI.setUnavailable(LibFunc_pow_finite);
625  TLI.setUnavailable(LibFunc_powf_finite);
626  TLI.setUnavailable(LibFunc_powl_finite);
627  TLI.setUnavailable(LibFunc_sinh_finite);
628  TLI.setUnavailable(LibFunc_sinhf_finite);
629  TLI.setUnavailable(LibFunc_sinhl_finite);
630  TLI.setUnavailable(LibFunc_sqrt_finite);
631  TLI.setUnavailable(LibFunc_sqrtf_finite);
632  TLI.setUnavailable(LibFunc_sqrtl_finite);
633  }
634 
635  if ((T.isOSLinux() && T.isGNUEnvironment()) ||
636  (T.isAndroid() && !T.isAndroidVersionLT(28))) {
637  // available IO unlocked variants on GNU/Linux and Android P or later
638  TLI.setAvailable(LibFunc_getc_unlocked);
639  TLI.setAvailable(LibFunc_getchar_unlocked);
640  TLI.setAvailable(LibFunc_putc_unlocked);
641  TLI.setAvailable(LibFunc_putchar_unlocked);
642  TLI.setAvailable(LibFunc_fputc_unlocked);
643  TLI.setAvailable(LibFunc_fgetc_unlocked);
644  TLI.setAvailable(LibFunc_fread_unlocked);
645  TLI.setAvailable(LibFunc_fwrite_unlocked);
646  TLI.setAvailable(LibFunc_fputs_unlocked);
647  TLI.setAvailable(LibFunc_fgets_unlocked);
648  }
649 
650  if (T.isAndroid() && T.isAndroidVersionLT(21)) {
651  TLI.setUnavailable(LibFunc_stpcpy);
652  TLI.setUnavailable(LibFunc_stpncpy);
653  }
654 
655  if (T.isPS4()) {
656  // PS4 does have memalign.
657  TLI.setAvailable(LibFunc_memalign);
658 
659  // PS4 does not have new/delete with "unsigned int" size parameter;
660  // it only has the "unsigned long" versions.
661  TLI.setUnavailable(LibFunc_ZdaPvj);
662  TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
663  TLI.setUnavailable(LibFunc_ZdlPvj);
664  TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
665  TLI.setUnavailable(LibFunc_Znaj);
666  TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
667  TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
668  TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
669  TLI.setUnavailable(LibFunc_Znwj);
670  TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
671  TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
672  TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
673 
674  // None of the *_chk functions.
675  TLI.setUnavailable(LibFunc_memccpy_chk);
676  TLI.setUnavailable(LibFunc_memcpy_chk);
677  TLI.setUnavailable(LibFunc_memmove_chk);
678  TLI.setUnavailable(LibFunc_mempcpy_chk);
679  TLI.setUnavailable(LibFunc_memset_chk);
680  TLI.setUnavailable(LibFunc_snprintf_chk);
681  TLI.setUnavailable(LibFunc_sprintf_chk);
682  TLI.setUnavailable(LibFunc_stpcpy_chk);
683  TLI.setUnavailable(LibFunc_stpncpy_chk);
684  TLI.setUnavailable(LibFunc_strcat_chk);
685  TLI.setUnavailable(LibFunc_strcpy_chk);
686  TLI.setUnavailable(LibFunc_strlcat_chk);
687  TLI.setUnavailable(LibFunc_strlcat_chk);
688  TLI.setUnavailable(LibFunc_strlcpy_chk);
689  TLI.setUnavailable(LibFunc_strlen_chk);
690  TLI.setUnavailable(LibFunc_strncat_chk);
691  TLI.setUnavailable(LibFunc_strncpy_chk);
692  TLI.setUnavailable(LibFunc_vsnprintf_chk);
693  TLI.setUnavailable(LibFunc_vsprintf_chk);
694 
695  // Various Posix system functions.
696  TLI.setUnavailable(LibFunc_access);
697  TLI.setUnavailable(LibFunc_chmod);
698  TLI.setUnavailable(LibFunc_chown);
699  TLI.setUnavailable(LibFunc_closedir);
700  TLI.setUnavailable(LibFunc_ctermid);
701  TLI.setUnavailable(LibFunc_execl);
702  TLI.setUnavailable(LibFunc_execle);
703  TLI.setUnavailable(LibFunc_execlp);
704  TLI.setUnavailable(LibFunc_execv);
705  TLI.setUnavailable(LibFunc_execvP);
706  TLI.setUnavailable(LibFunc_execve);
707  TLI.setUnavailable(LibFunc_execvp);
708  TLI.setUnavailable(LibFunc_execvpe);
709  TLI.setUnavailable(LibFunc_fork);
710  TLI.setUnavailable(LibFunc_fstat);
711  TLI.setUnavailable(LibFunc_fstatvfs);
712  TLI.setUnavailable(LibFunc_getenv);
713  TLI.setUnavailable(LibFunc_getitimer);
714  TLI.setUnavailable(LibFunc_getlogin_r);
715  TLI.setUnavailable(LibFunc_getpwnam);
716  TLI.setUnavailable(LibFunc_gettimeofday);
717  TLI.setUnavailable(LibFunc_lchown);
718  TLI.setUnavailable(LibFunc_lstat);
719  TLI.setUnavailable(LibFunc_mkdir);
720  TLI.setUnavailable(LibFunc_open);
721  TLI.setUnavailable(LibFunc_opendir);
722  TLI.setUnavailable(LibFunc_pclose);
723  TLI.setUnavailable(LibFunc_popen);
724  TLI.setUnavailable(LibFunc_pread);
725  TLI.setUnavailable(LibFunc_pwrite);
726  TLI.setUnavailable(LibFunc_read);
727  TLI.setUnavailable(LibFunc_readlink);
728  TLI.setUnavailable(LibFunc_realpath);
729  TLI.setUnavailable(LibFunc_rename);
730  TLI.setUnavailable(LibFunc_rmdir);
731  TLI.setUnavailable(LibFunc_setitimer);
732  TLI.setUnavailable(LibFunc_stat);
733  TLI.setUnavailable(LibFunc_statvfs);
734  TLI.setUnavailable(LibFunc_system);
735  TLI.setUnavailable(LibFunc_times);
736  TLI.setUnavailable(LibFunc_tmpfile);
737  TLI.setUnavailable(LibFunc_unlink);
738  TLI.setUnavailable(LibFunc_uname);
739  TLI.setUnavailable(LibFunc_unsetenv);
740  TLI.setUnavailable(LibFunc_utime);
741  TLI.setUnavailable(LibFunc_utimes);
742  TLI.setUnavailable(LibFunc_valloc);
743  TLI.setUnavailable(LibFunc_write);
744 
745  // Miscellaneous other functions not provided.
746  TLI.setUnavailable(LibFunc_atomic_load);
747  TLI.setUnavailable(LibFunc_atomic_store);
748  TLI.setUnavailable(LibFunc___kmpc_alloc_shared);
749  TLI.setUnavailable(LibFunc___kmpc_free_shared);
750  TLI.setUnavailable(LibFunc_dunder_strndup);
751  TLI.setUnavailable(LibFunc_bcmp);
752  TLI.setUnavailable(LibFunc_bcopy);
753  TLI.setUnavailable(LibFunc_bzero);
754  TLI.setUnavailable(LibFunc_cabs);
755  TLI.setUnavailable(LibFunc_cabsf);
756  TLI.setUnavailable(LibFunc_cabsl);
757  TLI.setUnavailable(LibFunc_ffs);
758  TLI.setUnavailable(LibFunc_flockfile);
759  TLI.setUnavailable(LibFunc_fseeko);
760  TLI.setUnavailable(LibFunc_ftello);
761  TLI.setUnavailable(LibFunc_ftrylockfile);
762  TLI.setUnavailable(LibFunc_funlockfile);
763  TLI.setUnavailable(LibFunc_htonl);
764  TLI.setUnavailable(LibFunc_htons);
765  TLI.setUnavailable(LibFunc_isascii);
766  TLI.setUnavailable(LibFunc_memccpy);
767  TLI.setUnavailable(LibFunc_mempcpy);
768  TLI.setUnavailable(LibFunc_memrchr);
769  TLI.setUnavailable(LibFunc_ntohl);
770  TLI.setUnavailable(LibFunc_ntohs);
771  TLI.setUnavailable(LibFunc_reallocf);
772  TLI.setUnavailable(LibFunc_roundeven);
773  TLI.setUnavailable(LibFunc_roundevenf);
774  TLI.setUnavailable(LibFunc_roundevenl);
775  TLI.setUnavailable(LibFunc_stpcpy);
776  TLI.setUnavailable(LibFunc_stpncpy);
777  TLI.setUnavailable(LibFunc_strlcat);
778  TLI.setUnavailable(LibFunc_strlcpy);
779  TLI.setUnavailable(LibFunc_strndup);
780  TLI.setUnavailable(LibFunc_strnlen);
781  TLI.setUnavailable(LibFunc_toascii);
782  }
783 
784  // As currently implemented in clang, NVPTX code has no standard library to
785  // speak of. Headers provide a standard-ish library implementation, but many
786  // of the signatures are wrong -- for example, many libm functions are not
787  // extern "C".
788  //
789  // libdevice, an IR library provided by nvidia, is linked in by the front-end,
790  // but only used functions are provided to llvm. Moreover, most of the
791  // functions in libdevice don't map precisely to standard library functions.
792  //
793  // FIXME: Having no standard library prevents e.g. many fastmath
794  // optimizations, so this situation should be fixed.
795  if (T.isNVPTX()) {
796  TLI.disableAllFunctions();
797  TLI.setAvailable(LibFunc_nvvm_reflect);
798  TLI.setAvailable(llvm::LibFunc_malloc);
799  TLI.setAvailable(llvm::LibFunc_free);
800 
801  // TODO: We could enable the following two according to [0] but we haven't
802  // done an evaluation wrt. the performance implications.
803  // [0]
804  // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations
805  //
806  // TLI.setAvailable(llvm::LibFunc_memcpy);
807  // TLI.setAvailable(llvm::LibFunc_memset);
808 
809  TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
810  TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
811  } else {
812  TLI.setUnavailable(LibFunc_nvvm_reflect);
813  }
814 
815  // These vec_malloc/free routines are only available on AIX.
816  if (!T.isOSAIX()) {
817  TLI.setUnavailable(LibFunc_vec_calloc);
818  TLI.setUnavailable(LibFunc_vec_malloc);
819  TLI.setUnavailable(LibFunc_vec_realloc);
820  TLI.setUnavailable(LibFunc_vec_free);
821  }
822 
824 }
825 
827  // Default to everything being available.
828  memset(AvailableArray, -1, sizeof(AvailableArray));
829 
830  initialize(*this, Triple(), StandardNames);
831 }
832 
834  // Default to everything being available.
835  memset(AvailableArray, -1, sizeof(AvailableArray));
836 
837  initialize(*this, T, StandardNames);
838 }
839 
841  : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
842  ShouldExtI32Return(TLI.ShouldExtI32Return),
843  ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
844  SizeOfInt(TLI.SizeOfInt) {
845  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
846  VectorDescs = TLI.VectorDescs;
847  ScalarDescs = TLI.ScalarDescs;
848 }
849 
851  : CustomNames(std::move(TLI.CustomNames)),
852  ShouldExtI32Param(TLI.ShouldExtI32Param),
853  ShouldExtI32Return(TLI.ShouldExtI32Return),
854  ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
855  SizeOfInt(TLI.SizeOfInt) {
856  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
857  AvailableArray);
858  VectorDescs = TLI.VectorDescs;
859  ScalarDescs = TLI.ScalarDescs;
860 }
861 
863  CustomNames = TLI.CustomNames;
864  ShouldExtI32Param = TLI.ShouldExtI32Param;
865  ShouldExtI32Return = TLI.ShouldExtI32Return;
866  ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
867  SizeOfInt = TLI.SizeOfInt;
868  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
869  return *this;
870 }
871 
873  CustomNames = std::move(TLI.CustomNames);
874  ShouldExtI32Param = TLI.ShouldExtI32Param;
875  ShouldExtI32Return = TLI.ShouldExtI32Return;
876  ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
877  SizeOfInt = TLI.SizeOfInt;
878  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
879  AvailableArray);
880  return *this;
881 }
882 
884  // Filter out empty names and names containing null bytes, those can't be in
885  // our table.
886  if (funcName.empty() || funcName.find('\0') != StringRef::npos)
887  return StringRef();
888 
889  // Check for \01 prefix that is used to mangle __asm declarations and
890  // strip it if present.
891  return GlobalValue::dropLLVMManglingEscape(funcName);
892 }
893 
895  funcName = sanitizeFunctionName(funcName);
896  if (funcName.empty())
897  return false;
898 
899  const auto *Start = std::begin(StandardNames);
900  const auto *End = std::end(StandardNames);
901  const auto *I = std::lower_bound(Start, End, funcName);
902  if (I != End && *I == funcName) {
903  F = (LibFunc)(I - Start);
904  return true;
905  }
906  return false;
907 }
908 
909 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
910  LibFunc F,
911  const Module &M) const {
912  // FIXME: There is really no guarantee that sizeof(size_t) is equal to
913  // sizeof(int*) for every target. So the assumption used here to derive the
914  // SizeTBits based on the size of an integer pointer in address space zero
915  // isn't always valid.
916  unsigned SizeTBits = M.getDataLayout().getPointerSizeInBits(/*AddrSpace=*/0);
917  unsigned NumParams = FTy.getNumParams();
918 
919  switch (F) {
920  case LibFunc_execl:
921  case LibFunc_execlp:
922  case LibFunc_execle:
923  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
924  FTy.getParamType(1)->isPointerTy() &&
925  FTy.getReturnType()->isIntegerTy(32));
926  case LibFunc_execv:
927  case LibFunc_execvp:
928  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
929  FTy.getParamType(1)->isPointerTy() &&
930  FTy.getReturnType()->isIntegerTy(32));
931  case LibFunc_execvP:
932  case LibFunc_execvpe:
933  case LibFunc_execve:
934  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
935  FTy.getParamType(1)->isPointerTy() &&
936  FTy.getParamType(2)->isPointerTy() &&
937  FTy.getReturnType()->isIntegerTy(32));
938  case LibFunc_strlen_chk:
939  --NumParams;
940  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
941  return false;
943  case LibFunc_strlen:
944  return NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
945  FTy.getReturnType()->isIntegerTy(SizeTBits);
946 
947  case LibFunc_strchr:
948  case LibFunc_strrchr:
949  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
950  FTy.getParamType(0) == FTy.getReturnType() &&
951  FTy.getParamType(1)->isIntegerTy());
952 
953  case LibFunc_strtol:
954  case LibFunc_strtod:
955  case LibFunc_strtof:
956  case LibFunc_strtoul:
957  case LibFunc_strtoll:
958  case LibFunc_strtold:
959  case LibFunc_strtoull:
960  return ((NumParams == 2 || NumParams == 3) &&
961  FTy.getParamType(0)->isPointerTy() &&
962  FTy.getParamType(1)->isPointerTy());
963  case LibFunc_strcat_chk:
964  --NumParams;
965  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
966  return false;
968  case LibFunc_strcat:
969  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
970  FTy.getParamType(0) == FTy.getReturnType() &&
971  FTy.getParamType(1) == FTy.getReturnType());
972 
973  case LibFunc_strncat_chk:
974  --NumParams;
975  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
976  return false;
978  case LibFunc_strncat:
979  return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
980  FTy.getParamType(0) == FTy.getReturnType() &&
981  FTy.getParamType(1) == FTy.getReturnType() &&
982  FTy.getParamType(2)->isIntegerTy(SizeTBits));
983 
984  case LibFunc_strcpy_chk:
985  case LibFunc_stpcpy_chk:
986  --NumParams;
987  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
988  return false;
990  case LibFunc_strcpy:
991  case LibFunc_stpcpy:
992  return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
993  FTy.getParamType(0) == FTy.getParamType(1) &&
994  FTy.getParamType(0)->isPointerTy());
995 
996  case LibFunc_strlcat_chk:
997  case LibFunc_strlcpy_chk:
998  --NumParams;
999  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
1000  return false;
1002  case LibFunc_strlcat:
1003  case LibFunc_strlcpy:
1004  return NumParams == 3 && FTy.getReturnType()->isIntegerTy(SizeTBits) &&
1005  FTy.getParamType(0)->isPointerTy() &&
1006  FTy.getParamType(1)->isPointerTy() &&
1007  FTy.getParamType(2)->isIntegerTy(SizeTBits);
1008 
1009  case LibFunc_strncpy_chk:
1010  case LibFunc_stpncpy_chk:
1011  --NumParams;
1012  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
1013  return false;
1015  case LibFunc_strncpy:
1016  case LibFunc_stpncpy:
1017  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
1018  FTy.getParamType(0) == FTy.getParamType(1) &&
1019  FTy.getParamType(0)->isPointerTy() &&
1020  FTy.getParamType(2)->isIntegerTy(SizeTBits));
1021 
1022  case LibFunc_strxfrm:
1023  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1024  FTy.getParamType(1)->isPointerTy());
1025 
1026  case LibFunc_strcmp:
1027  return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
1028  FTy.getParamType(0)->isPointerTy() &&
1029  FTy.getParamType(0) == FTy.getParamType(1));
1030 
1031  case LibFunc_strncmp:
1032  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1033  FTy.getParamType(0)->isPointerTy() &&
1034  FTy.getParamType(0) == FTy.getParamType(1) &&
1035  FTy.getParamType(2)->isIntegerTy(SizeTBits));
1036 
1037  case LibFunc_strspn:
1038  case LibFunc_strcspn:
1039  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1040  FTy.getParamType(0) == FTy.getParamType(1) &&
1041  FTy.getReturnType()->isIntegerTy());
1042 
1043  case LibFunc_strcoll:
1044  case LibFunc_strcasecmp:
1045  case LibFunc_strncasecmp:
1046  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1047  FTy.getParamType(1)->isPointerTy());
1048 
1049  case LibFunc_strstr:
1050  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1051  FTy.getParamType(0)->isPointerTy() &&
1052  FTy.getParamType(1)->isPointerTy());
1053 
1054  case LibFunc_strpbrk:
1055  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1056  FTy.getReturnType() == FTy.getParamType(0) &&
1057  FTy.getParamType(0) == FTy.getParamType(1));
1058 
1059  case LibFunc_strtok:
1060  case LibFunc_strtok_r:
1061  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
1062  case LibFunc_scanf:
1063  case LibFunc_setbuf:
1064  case LibFunc_setvbuf:
1065  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1066  case LibFunc_strdup:
1067  case LibFunc_strndup:
1068  return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
1069  FTy.getParamType(0)->isPointerTy());
1070  case LibFunc_sscanf:
1071  case LibFunc_stat:
1072  case LibFunc_statvfs:
1073  case LibFunc_siprintf:
1074  case LibFunc_small_sprintf:
1075  case LibFunc_sprintf:
1076  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1077  FTy.getParamType(1)->isPointerTy() &&
1078  FTy.getReturnType()->isIntegerTy(32));
1079 
1080  case LibFunc_sprintf_chk:
1081  return NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1082  FTy.getParamType(1)->isIntegerTy(32) &&
1083  FTy.getParamType(2)->isIntegerTy(SizeTBits) &&
1084  FTy.getParamType(3)->isPointerTy() &&
1085  FTy.getReturnType()->isIntegerTy(32);
1086 
1087  case LibFunc_snprintf:
1088  return NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1089  FTy.getParamType(1)->isIntegerTy(SizeTBits) &&
1090  FTy.getParamType(2)->isPointerTy() &&
1091  FTy.getReturnType()->isIntegerTy(32);
1092 
1093  case LibFunc_snprintf_chk:
1094  return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
1095  FTy.getParamType(1)->isIntegerTy(SizeTBits) &&
1096  FTy.getParamType(2)->isIntegerTy(32) &&
1097  FTy.getParamType(3)->isIntegerTy(SizeTBits) &&
1098  FTy.getParamType(4)->isPointerTy() &&
1099  FTy.getReturnType()->isIntegerTy(32);
1100 
1101  case LibFunc_setitimer:
1102  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1103  FTy.getParamType(2)->isPointerTy());
1104  case LibFunc_system:
1105  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1106  case LibFunc___kmpc_alloc_shared:
1107  case LibFunc_malloc:
1108  case LibFunc_vec_malloc:
1109  return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
1110  case LibFunc_memcmp:
1111  return NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1112  FTy.getParamType(0)->isPointerTy() &&
1113  FTy.getParamType(1)->isPointerTy() &&
1114  FTy.getParamType(2)->isIntegerTy(SizeTBits);
1115 
1116  case LibFunc_memchr:
1117  case LibFunc_memrchr:
1118  return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1119  FTy.getReturnType() == FTy.getParamType(0) &&
1120  FTy.getParamType(1)->isIntegerTy(32) &&
1121  FTy.getParamType(2)->isIntegerTy(SizeTBits));
1122  case LibFunc_modf:
1123  case LibFunc_modff:
1124  case LibFunc_modfl:
1125  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
1126 
1127  case LibFunc_memcpy_chk:
1128  case LibFunc_mempcpy_chk:
1129  case LibFunc_memmove_chk:
1130  --NumParams;
1131  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
1132  return false;
1134  case LibFunc_memcpy:
1135  case LibFunc_mempcpy:
1136  case LibFunc_memmove:
1137  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
1138  FTy.getParamType(0)->isPointerTy() &&
1139  FTy.getParamType(1)->isPointerTy() &&
1140  FTy.getParamType(2)->isIntegerTy(SizeTBits));
1141 
1142  case LibFunc_memset_chk:
1143  --NumParams;
1144  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
1145  return false;
1147  case LibFunc_memset:
1148  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
1149  FTy.getParamType(0)->isPointerTy() &&
1150  FTy.getParamType(1)->isIntegerTy() &&
1151  FTy.getParamType(2)->isIntegerTy(SizeTBits));
1152 
1153  case LibFunc_memccpy_chk:
1154  --NumParams;
1155  if (!FTy.getParamType(NumParams)->isIntegerTy(SizeTBits))
1156  return false;
1158  case LibFunc_memccpy:
1159  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
1160  case LibFunc_memalign:
1161  return (FTy.getReturnType()->isPointerTy());
1162  case LibFunc_realloc:
1163  case LibFunc_reallocf:
1164  case LibFunc_vec_realloc:
1165  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1166  FTy.getParamType(0) == FTy.getReturnType() &&
1167  FTy.getParamType(1)->isIntegerTy(SizeTBits));
1168  case LibFunc_read:
1169  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1170  case LibFunc_rewind:
1171  case LibFunc_rmdir:
1172  case LibFunc_remove:
1173  case LibFunc_realpath:
1174  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1175  case LibFunc_rename:
1176  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1177  FTy.getParamType(1)->isPointerTy());
1178  case LibFunc_readlink:
1179  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1180  FTy.getParamType(1)->isPointerTy());
1181  case LibFunc_write:
1182  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1183  case LibFunc_aligned_alloc:
1184  return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
1185  case LibFunc_bcopy:
1186  case LibFunc_bcmp:
1187  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1188  FTy.getParamType(1)->isPointerTy());
1189  case LibFunc_bzero:
1190  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1191  case LibFunc_calloc:
1192  case LibFunc_vec_calloc:
1193  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1194  FTy.getParamType(0) == FTy.getParamType(1));
1195 
1196  case LibFunc_atof:
1197  case LibFunc_atoi:
1198  case LibFunc_atol:
1199  case LibFunc_atoll:
1200  case LibFunc_ferror:
1201  case LibFunc_getenv:
1202  case LibFunc_getpwnam:
1203  case LibFunc_iprintf:
1204  case LibFunc_small_printf:
1205  case LibFunc_pclose:
1206  case LibFunc_perror:
1207  case LibFunc_printf:
1208  case LibFunc_puts:
1209  case LibFunc_uname:
1210  case LibFunc_under_IO_getc:
1211  case LibFunc_unlink:
1212  case LibFunc_unsetenv:
1213  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1214 
1215  case LibFunc_access:
1216  case LibFunc_chmod:
1217  case LibFunc_chown:
1218  case LibFunc_clearerr:
1219  case LibFunc_closedir:
1220  case LibFunc_ctermid:
1221  case LibFunc_fclose:
1222  case LibFunc_feof:
1223  case LibFunc_fflush:
1224  case LibFunc_fgetc:
1225  case LibFunc_fgetc_unlocked:
1226  case LibFunc_fileno:
1227  case LibFunc_flockfile:
1228  case LibFunc_free:
1229  case LibFunc_fseek:
1230  case LibFunc_fseeko64:
1231  case LibFunc_fseeko:
1232  case LibFunc_fsetpos:
1233  case LibFunc_ftell:
1234  case LibFunc_ftello64:
1235  case LibFunc_ftello:
1236  case LibFunc_ftrylockfile:
1237  case LibFunc_funlockfile:
1238  case LibFunc_getc:
1239  case LibFunc_getc_unlocked:
1240  case LibFunc_getlogin_r:
1241  case LibFunc_mkdir:
1242  case LibFunc_mktime:
1243  case LibFunc_times:
1244  case LibFunc_vec_free:
1245  return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
1246  case LibFunc___kmpc_free_shared:
1247  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1248  FTy.getParamType(1)->isIntegerTy(SizeTBits));
1249 
1250  case LibFunc_fopen:
1251  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1252  FTy.getParamType(0)->isPointerTy() &&
1253  FTy.getParamType(1)->isPointerTy());
1254  case LibFunc_fork:
1255  return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
1256  case LibFunc_fdopen:
1257  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1258  FTy.getParamType(1)->isPointerTy());
1259  case LibFunc_fputc:
1260  case LibFunc_fputc_unlocked:
1261  case LibFunc_fstat:
1262  case LibFunc_frexp:
1263  case LibFunc_frexpf:
1264  case LibFunc_frexpl:
1265  case LibFunc_fstatvfs:
1266  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1267  case LibFunc_fgets:
1268  case LibFunc_fgets_unlocked:
1269  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1270  FTy.getParamType(2)->isPointerTy());
1271  case LibFunc_fread:
1272  case LibFunc_fread_unlocked:
1273  return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1274  FTy.getParamType(3)->isPointerTy());
1275  case LibFunc_fwrite:
1276  case LibFunc_fwrite_unlocked:
1277  return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
1278  FTy.getParamType(0)->isPointerTy() &&
1279  FTy.getParamType(1)->isIntegerTy() &&
1280  FTy.getParamType(2)->isIntegerTy() &&
1281  FTy.getParamType(3)->isPointerTy());
1282  case LibFunc_fputs:
1283  case LibFunc_fputs_unlocked:
1284  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1285  FTy.getParamType(1)->isPointerTy());
1286  case LibFunc_fscanf:
1287  case LibFunc_fiprintf:
1288  case LibFunc_small_fprintf:
1289  case LibFunc_fprintf:
1290  return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
1291  FTy.getParamType(0)->isPointerTy() &&
1292  FTy.getParamType(1)->isPointerTy());
1293  case LibFunc_fgetpos:
1294  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1295  FTy.getParamType(1)->isPointerTy());
1296  case LibFunc_getchar:
1297  case LibFunc_getchar_unlocked:
1298  return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
1299  case LibFunc_gets:
1300  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1301  case LibFunc_getitimer:
1302  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1303  case LibFunc_ungetc:
1304  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1305  case LibFunc_utime:
1306  case LibFunc_utimes:
1307  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1308  FTy.getParamType(1)->isPointerTy());
1309  case LibFunc_putc:
1310  case LibFunc_putc_unlocked:
1311  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1312  case LibFunc_pread:
1313  case LibFunc_pwrite:
1314  return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
1315  case LibFunc_popen:
1316  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1317  FTy.getParamType(0)->isPointerTy() &&
1318  FTy.getParamType(1)->isPointerTy());
1319  case LibFunc_vscanf:
1320  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1321  case LibFunc_vsscanf:
1322  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1323  FTy.getParamType(2)->isPointerTy());
1324  case LibFunc_vfscanf:
1325  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1326  FTy.getParamType(2)->isPointerTy());
1327  case LibFunc_valloc:
1328  return (FTy.getReturnType()->isPointerTy());
1329  case LibFunc_vprintf:
1330  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1331  case LibFunc_vfprintf:
1332  case LibFunc_vsprintf:
1333  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1334  FTy.getParamType(1)->isPointerTy());
1335  case LibFunc_vsprintf_chk:
1336  return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
1337  FTy.getParamType(1)->isIntegerTy(32) &&
1338  FTy.getParamType(2)->isIntegerTy(SizeTBits) && FTy.getParamType(3)->isPointerTy();
1339  case LibFunc_vsnprintf:
1340  return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1341  FTy.getParamType(2)->isPointerTy());
1342  case LibFunc_vsnprintf_chk:
1343  return NumParams == 6 && FTy.getParamType(0)->isPointerTy() &&
1344  FTy.getParamType(2)->isIntegerTy(32) &&
1345  FTy.getParamType(3)->isIntegerTy(SizeTBits) && FTy.getParamType(4)->isPointerTy();
1346  case LibFunc_open:
1347  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1348  case LibFunc_opendir:
1349  return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
1350  FTy.getParamType(0)->isPointerTy());
1351  case LibFunc_tmpfile:
1352  return (FTy.getReturnType()->isPointerTy());
1353  case LibFunc_htonl:
1354  case LibFunc_ntohl:
1355  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1356  FTy.getReturnType() == FTy.getParamType(0));
1357  case LibFunc_htons:
1358  case LibFunc_ntohs:
1359  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
1360  FTy.getReturnType() == FTy.getParamType(0));
1361  case LibFunc_lstat:
1362  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1363  FTy.getParamType(1)->isPointerTy());
1364  case LibFunc_lchown:
1365  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1366  case LibFunc_qsort:
1367  return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
1368  case LibFunc_dunder_strdup:
1369  case LibFunc_dunder_strndup:
1370  return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
1371  FTy.getParamType(0)->isPointerTy());
1372  case LibFunc_dunder_strtok_r:
1373  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1374  case LibFunc_under_IO_putc:
1375  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1376  case LibFunc_dunder_isoc99_scanf:
1377  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1378  case LibFunc_stat64:
1379  case LibFunc_lstat64:
1380  case LibFunc_statvfs64:
1381  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1382  FTy.getParamType(1)->isPointerTy());
1383  case LibFunc_dunder_isoc99_sscanf:
1384  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1385  FTy.getParamType(1)->isPointerTy());
1386  case LibFunc_fopen64:
1387  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1388  FTy.getParamType(0)->isPointerTy() &&
1389  FTy.getParamType(1)->isPointerTy());
1390  case LibFunc_tmpfile64:
1391  return (FTy.getReturnType()->isPointerTy());
1392  case LibFunc_fstat64:
1393  case LibFunc_fstatvfs64:
1394  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1395  case LibFunc_open64:
1396  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1397  case LibFunc_gettimeofday:
1398  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1399  FTy.getParamType(1)->isPointerTy());
1400 
1401  // new(unsigned int);
1402  case LibFunc_Znwj:
1403  // new(unsigned long);
1404  case LibFunc_Znwm:
1405  // new[](unsigned int);
1406  case LibFunc_Znaj:
1407  // new[](unsigned long);
1408  case LibFunc_Znam:
1409  // new(unsigned int);
1410  case LibFunc_msvc_new_int:
1411  // new(unsigned long long);
1412  case LibFunc_msvc_new_longlong:
1413  // new[](unsigned int);
1414  case LibFunc_msvc_new_array_int:
1415  // new[](unsigned long long);
1416  case LibFunc_msvc_new_array_longlong:
1417  return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
1418 
1419  // new(unsigned int, nothrow);
1420  case LibFunc_ZnwjRKSt9nothrow_t:
1421  // new(unsigned long, nothrow);
1422  case LibFunc_ZnwmRKSt9nothrow_t:
1423  // new[](unsigned int, nothrow);
1424  case LibFunc_ZnajRKSt9nothrow_t:
1425  // new[](unsigned long, nothrow);
1426  case LibFunc_ZnamRKSt9nothrow_t:
1427  // new(unsigned int, nothrow);
1428  case LibFunc_msvc_new_int_nothrow:
1429  // new(unsigned long long, nothrow);
1430  case LibFunc_msvc_new_longlong_nothrow:
1431  // new[](unsigned int, nothrow);
1432  case LibFunc_msvc_new_array_int_nothrow:
1433  // new[](unsigned long long, nothrow);
1434  case LibFunc_msvc_new_array_longlong_nothrow:
1435  // new(unsigned int, align_val_t)
1436  case LibFunc_ZnwjSt11align_val_t:
1437  // new(unsigned long, align_val_t)
1438  case LibFunc_ZnwmSt11align_val_t:
1439  // new[](unsigned int, align_val_t)
1440  case LibFunc_ZnajSt11align_val_t:
1441  // new[](unsigned long, align_val_t)
1442  case LibFunc_ZnamSt11align_val_t:
1443  return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
1444 
1445  // new(unsigned int, align_val_t, nothrow)
1446  case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
1447  // new(unsigned long, align_val_t, nothrow)
1448  case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1449  // new[](unsigned int, align_val_t, nothrow)
1450  case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
1451  // new[](unsigned long, align_val_t, nothrow)
1452  case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1453  return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
1454 
1455  // void operator delete[](void*);
1456  case LibFunc_ZdaPv:
1457  // void operator delete(void*);
1458  case LibFunc_ZdlPv:
1459  // void operator delete[](void*);
1460  case LibFunc_msvc_delete_array_ptr32:
1461  // void operator delete[](void*);
1462  case LibFunc_msvc_delete_array_ptr64:
1463  // void operator delete(void*);
1464  case LibFunc_msvc_delete_ptr32:
1465  // void operator delete(void*);
1466  case LibFunc_msvc_delete_ptr64:
1467  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1468 
1469  // void operator delete[](void*, nothrow);
1470  case LibFunc_ZdaPvRKSt9nothrow_t:
1471  // void operator delete[](void*, unsigned int);
1472  case LibFunc_ZdaPvj:
1473  // void operator delete[](void*, unsigned long);
1474  case LibFunc_ZdaPvm:
1475  // void operator delete(void*, nothrow);
1476  case LibFunc_ZdlPvRKSt9nothrow_t:
1477  // void operator delete(void*, unsigned int);
1478  case LibFunc_ZdlPvj:
1479  // void operator delete(void*, unsigned long);
1480  case LibFunc_ZdlPvm:
1481  // void operator delete(void*, align_val_t)
1482  case LibFunc_ZdlPvSt11align_val_t:
1483  // void operator delete[](void*, align_val_t)
1484  case LibFunc_ZdaPvSt11align_val_t:
1485  // void operator delete[](void*, unsigned int);
1486  case LibFunc_msvc_delete_array_ptr32_int:
1487  // void operator delete[](void*, nothrow);
1488  case LibFunc_msvc_delete_array_ptr32_nothrow:
1489  // void operator delete[](void*, unsigned long long);
1490  case LibFunc_msvc_delete_array_ptr64_longlong:
1491  // void operator delete[](void*, nothrow);
1492  case LibFunc_msvc_delete_array_ptr64_nothrow:
1493  // void operator delete(void*, unsigned int);
1494  case LibFunc_msvc_delete_ptr32_int:
1495  // void operator delete(void*, nothrow);
1496  case LibFunc_msvc_delete_ptr32_nothrow:
1497  // void operator delete(void*, unsigned long long);
1498  case LibFunc_msvc_delete_ptr64_longlong:
1499  // void operator delete(void*, nothrow);
1500  case LibFunc_msvc_delete_ptr64_nothrow:
1501  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1502 
1503  // void operator delete(void*, align_val_t, nothrow)
1504  case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
1505  // void operator delete[](void*, align_val_t, nothrow)
1506  case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
1507  // void operator delete(void*, unsigned int, align_val_t)
1508  case LibFunc_ZdlPvjSt11align_val_t:
1509  // void operator delete(void*, unsigned long, align_val_t)
1510  case LibFunc_ZdlPvmSt11align_val_t:
1511  // void operator delete[](void*, unsigned int, align_val_t);
1512  case LibFunc_ZdaPvjSt11align_val_t:
1513  // void operator delete[](void*, unsigned long, align_val_t);
1514  case LibFunc_ZdaPvmSt11align_val_t:
1515  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1516 
1517  // void __atomic_load(size_t, void *, void *, int)
1518  case LibFunc_atomic_load:
1519  // void __atomic_store(size_t, void *, void *, int)
1520  case LibFunc_atomic_store:
1521  return (NumParams == 4 && FTy.getParamType(0)->isIntegerTy() &&
1522  FTy.getParamType(1)->isPointerTy() &&
1523  FTy.getParamType(2)->isPointerTy() &&
1524  FTy.getParamType(3)->isIntegerTy());
1525 
1526  case LibFunc_memset_pattern16:
1527  return (!FTy.isVarArg() && NumParams == 3 &&
1528  FTy.getParamType(0)->isPointerTy() &&
1529  FTy.getParamType(1)->isPointerTy() &&
1530  FTy.getParamType(2)->isIntegerTy());
1531 
1532  case LibFunc_cxa_guard_abort:
1533  case LibFunc_cxa_guard_acquire:
1534  case LibFunc_cxa_guard_release:
1535  case LibFunc_nvvm_reflect:
1536  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1537 
1538  case LibFunc_sincospi_stret:
1539  case LibFunc_sincospif_stret:
1540  return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1541 
1542  case LibFunc_acos:
1543  case LibFunc_acos_finite:
1544  case LibFunc_acosf:
1545  case LibFunc_acosf_finite:
1546  case LibFunc_acosh:
1547  case LibFunc_acosh_finite:
1548  case LibFunc_acoshf:
1549  case LibFunc_acoshf_finite:
1550  case LibFunc_acoshl:
1551  case LibFunc_acoshl_finite:
1552  case LibFunc_acosl:
1553  case LibFunc_acosl_finite:
1554  case LibFunc_asin:
1555  case LibFunc_asin_finite:
1556  case LibFunc_asinf:
1557  case LibFunc_asinf_finite:
1558  case LibFunc_asinh:
1559  case LibFunc_asinhf:
1560  case LibFunc_asinhl:
1561  case LibFunc_asinl:
1562  case LibFunc_asinl_finite:
1563  case LibFunc_atan:
1564  case LibFunc_atanf:
1565  case LibFunc_atanh:
1566  case LibFunc_atanh_finite:
1567  case LibFunc_atanhf:
1568  case LibFunc_atanhf_finite:
1569  case LibFunc_atanhl:
1570  case LibFunc_atanhl_finite:
1571  case LibFunc_atanl:
1572  case LibFunc_cbrt:
1573  case LibFunc_cbrtf:
1574  case LibFunc_cbrtl:
1575  case LibFunc_ceil:
1576  case LibFunc_ceilf:
1577  case LibFunc_ceill:
1578  case LibFunc_cos:
1579  case LibFunc_cosf:
1580  case LibFunc_cosh:
1581  case LibFunc_cosh_finite:
1582  case LibFunc_coshf:
1583  case LibFunc_coshf_finite:
1584  case LibFunc_coshl:
1585  case LibFunc_coshl_finite:
1586  case LibFunc_cosl:
1587  case LibFunc_exp10:
1588  case LibFunc_exp10_finite:
1589  case LibFunc_exp10f:
1590  case LibFunc_exp10f_finite:
1591  case LibFunc_exp10l:
1592  case LibFunc_exp10l_finite:
1593  case LibFunc_exp2:
1594  case LibFunc_exp2_finite:
1595  case LibFunc_exp2f:
1596  case LibFunc_exp2f_finite:
1597  case LibFunc_exp2l:
1598  case LibFunc_exp2l_finite:
1599  case LibFunc_exp:
1600  case LibFunc_exp_finite:
1601  case LibFunc_expf:
1602  case LibFunc_expf_finite:
1603  case LibFunc_expl:
1604  case LibFunc_expl_finite:
1605  case LibFunc_expm1:
1606  case LibFunc_expm1f:
1607  case LibFunc_expm1l:
1608  case LibFunc_fabs:
1609  case LibFunc_fabsf:
1610  case LibFunc_fabsl:
1611  case LibFunc_floor:
1612  case LibFunc_floorf:
1613  case LibFunc_floorl:
1614  case LibFunc_log10:
1615  case LibFunc_log10_finite:
1616  case LibFunc_log10f:
1617  case LibFunc_log10f_finite:
1618  case LibFunc_log10l:
1619  case LibFunc_log10l_finite:
1620  case LibFunc_log1p:
1621  case LibFunc_log1pf:
1622  case LibFunc_log1pl:
1623  case LibFunc_log2:
1624  case LibFunc_log2_finite:
1625  case LibFunc_log2f:
1626  case LibFunc_log2f_finite:
1627  case LibFunc_log2l:
1628  case LibFunc_log2l_finite:
1629  case LibFunc_log:
1630  case LibFunc_log_finite:
1631  case LibFunc_logb:
1632  case LibFunc_logbf:
1633  case LibFunc_logbl:
1634  case LibFunc_logf:
1635  case LibFunc_logf_finite:
1636  case LibFunc_logl:
1637  case LibFunc_logl_finite:
1638  case LibFunc_nearbyint:
1639  case LibFunc_nearbyintf:
1640  case LibFunc_nearbyintl:
1641  case LibFunc_rint:
1642  case LibFunc_rintf:
1643  case LibFunc_rintl:
1644  case LibFunc_round:
1645  case LibFunc_roundf:
1646  case LibFunc_roundl:
1647  case LibFunc_roundeven:
1648  case LibFunc_roundevenf:
1649  case LibFunc_roundevenl:
1650  case LibFunc_sin:
1651  case LibFunc_sinf:
1652  case LibFunc_sinh:
1653  case LibFunc_sinh_finite:
1654  case LibFunc_sinhf:
1655  case LibFunc_sinhf_finite:
1656  case LibFunc_sinhl:
1657  case LibFunc_sinhl_finite:
1658  case LibFunc_sinl:
1659  case LibFunc_sqrt:
1660  case LibFunc_sqrt_finite:
1661  case LibFunc_sqrtf:
1662  case LibFunc_sqrtf_finite:
1663  case LibFunc_sqrtl:
1664  case LibFunc_sqrtl_finite:
1665  case LibFunc_tan:
1666  case LibFunc_tanf:
1667  case LibFunc_tanh:
1668  case LibFunc_tanhf:
1669  case LibFunc_tanhl:
1670  case LibFunc_tanl:
1671  case LibFunc_trunc:
1672  case LibFunc_truncf:
1673  case LibFunc_truncl:
1674  return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1675  FTy.getReturnType() == FTy.getParamType(0));
1676 
1677  case LibFunc_atan2:
1678  case LibFunc_atan2_finite:
1679  case LibFunc_atan2f:
1680  case LibFunc_atan2f_finite:
1681  case LibFunc_atan2l:
1682  case LibFunc_atan2l_finite:
1683  case LibFunc_fmin:
1684  case LibFunc_fminf:
1685  case LibFunc_fminl:
1686  case LibFunc_fmax:
1687  case LibFunc_fmaxf:
1688  case LibFunc_fmaxl:
1689  case LibFunc_fmod:
1690  case LibFunc_fmodf:
1691  case LibFunc_fmodl:
1692  case LibFunc_remainder:
1693  case LibFunc_remainderf:
1694  case LibFunc_remainderl:
1695  case LibFunc_copysign:
1696  case LibFunc_copysignf:
1697  case LibFunc_copysignl:
1698  case LibFunc_pow:
1699  case LibFunc_pow_finite:
1700  case LibFunc_powf:
1701  case LibFunc_powf_finite:
1702  case LibFunc_powl:
1703  case LibFunc_powl_finite:
1704  return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1705  FTy.getReturnType() == FTy.getParamType(0) &&
1706  FTy.getReturnType() == FTy.getParamType(1));
1707 
1708  case LibFunc_ldexp:
1709  case LibFunc_ldexpf:
1710  case LibFunc_ldexpl:
1711  return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1712  FTy.getReturnType() == FTy.getParamType(0) &&
1713  FTy.getParamType(1)->isIntegerTy(getIntSize()));
1714 
1715  case LibFunc_ffs:
1716  case LibFunc_ffsl:
1717  case LibFunc_ffsll:
1718  case LibFunc_fls:
1719  case LibFunc_flsl:
1720  case LibFunc_flsll:
1721  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1722  FTy.getParamType(0)->isIntegerTy());
1723 
1724  case LibFunc_isdigit:
1725  case LibFunc_isascii:
1726  case LibFunc_toascii:
1727  case LibFunc_putchar:
1728  case LibFunc_putchar_unlocked:
1729  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1730  FTy.getReturnType() == FTy.getParamType(0));
1731 
1732  case LibFunc_abs:
1733  case LibFunc_labs:
1734  case LibFunc_llabs:
1735  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1736  FTy.getReturnType() == FTy.getParamType(0));
1737 
1738  case LibFunc_cxa_atexit:
1739  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1740  FTy.getParamType(0)->isPointerTy() &&
1741  FTy.getParamType(1)->isPointerTy() &&
1742  FTy.getParamType(2)->isPointerTy());
1743 
1744  case LibFunc_sinpi:
1745  case LibFunc_cospi:
1746  return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1747  FTy.getReturnType() == FTy.getParamType(0));
1748 
1749  case LibFunc_sinpif:
1750  case LibFunc_cospif:
1751  return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1752  FTy.getReturnType() == FTy.getParamType(0));
1753 
1754  case LibFunc_strnlen:
1755  return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1756  FTy.getParamType(0)->isPointerTy() &&
1757  FTy.getParamType(1)->isIntegerTy(SizeTBits));
1758 
1759  case LibFunc_posix_memalign:
1760  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1761  FTy.getParamType(0)->isPointerTy() &&
1762  FTy.getParamType(1)->isIntegerTy(SizeTBits) &&
1763  FTy.getParamType(2)->isIntegerTy(SizeTBits));
1764 
1765  case LibFunc_wcslen:
1766  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1767  FTy.getReturnType()->isIntegerTy());
1768 
1769  case LibFunc_cabs:
1770  case LibFunc_cabsf:
1771  case LibFunc_cabsl: {
1772  Type* RetTy = FTy.getReturnType();
1773  if (!RetTy->isFloatingPointTy())
1774  return false;
1775 
1776  // NOTE: These prototypes are target specific and currently support
1777  // "complex" passed as an array or discrete real & imaginary parameters.
1778  // Add other calling conventions to enable libcall optimizations.
1779  if (NumParams == 1)
1780  return (FTy.getParamType(0)->isArrayTy() &&
1781  FTy.getParamType(0)->getArrayNumElements() == 2 &&
1782  FTy.getParamType(0)->getArrayElementType() == RetTy);
1783  else if (NumParams == 2)
1784  return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1785  else
1786  return false;
1787  }
1788  case LibFunc::NumLibFuncs:
1789  case LibFunc::NotLibFunc:
1790  break;
1791  }
1792 
1793  llvm_unreachable("Invalid libfunc");
1794 }
1795 
1797  LibFunc &F) const {
1798  // Intrinsics don't overlap w/libcalls; if our module has a large number of
1799  // intrinsics, this ends up being an interesting compile time win since we
1800  // avoid string normalization and comparison.
1801  if (FDecl.isIntrinsic()) return false;
1802 
1803  const Module *M = FDecl.getParent();
1804  assert(M && "Expecting FDecl to be connected to a Module.");
1805 
1806  return getLibFunc(FDecl.getName(), F) &&
1807  isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M);
1808 }
1809 
1811  memset(AvailableArray, 0, sizeof(AvailableArray));
1812 }
1813 
1814 static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1815  return LHS.ScalarFnName < RHS.ScalarFnName;
1816 }
1817 
1818 static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1819  return LHS.VectorFnName < RHS.VectorFnName;
1820 }
1821 
1822 static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1823  return LHS.ScalarFnName < S;
1824 }
1825 
1827  llvm::append_range(VectorDescs, Fns);
1828  llvm::sort(VectorDescs, compareByScalarFnName);
1829 
1830  llvm::append_range(ScalarDescs, Fns);
1831  llvm::sort(ScalarDescs, compareByVectorFnName);
1832 }
1833 
1835  enum VectorLibrary VecLib) {
1836  switch (VecLib) {
1837  case Accelerate: {
1838  const VecDesc VecFuncs[] = {
1839  #define TLI_DEFINE_ACCELERATE_VECFUNCS
1840  #include "llvm/Analysis/VecFuncs.def"
1841  };
1842  addVectorizableFunctions(VecFuncs);
1843  break;
1844  }
1845  case DarwinLibSystemM: {
1846  const VecDesc VecFuncs[] = {
1847  #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1848  #include "llvm/Analysis/VecFuncs.def"
1849  };
1850  addVectorizableFunctions(VecFuncs);
1851  break;
1852  }
1853  case LIBMVEC_X86: {
1854  const VecDesc VecFuncs[] = {
1855  #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1856  #include "llvm/Analysis/VecFuncs.def"
1857  };
1858  addVectorizableFunctions(VecFuncs);
1859  break;
1860  }
1861  case MASSV: {
1862  const VecDesc VecFuncs[] = {
1863  #define TLI_DEFINE_MASSV_VECFUNCS
1864  #include "llvm/Analysis/VecFuncs.def"
1865  };
1866  addVectorizableFunctions(VecFuncs);
1867  break;
1868  }
1869  case SVML: {
1870  const VecDesc VecFuncs[] = {
1871  #define TLI_DEFINE_SVML_VECFUNCS
1872  #include "llvm/Analysis/VecFuncs.def"
1873  };
1874  addVectorizableFunctions(VecFuncs);
1875  break;
1876  }
1877  case NoLibrary:
1878  break;
1879  }
1880 }
1881 
1883  funcName = sanitizeFunctionName(funcName);
1884  if (funcName.empty())
1885  return false;
1886 
1887  std::vector<VecDesc>::const_iterator I =
1888  llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1889  return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1890 }
1891 
1892 StringRef
1894  const ElementCount &VF) const {
1896  if (F.empty())
1897  return F;
1898  std::vector<VecDesc>::const_iterator I =
1900  while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1901  if (I->VectorizationFactor == VF)
1902  return I->VectorFnName;
1903  ++I;
1904  }
1905  return StringRef();
1906 }
1907 
1910  if (!BaselineInfoImpl)
1911  BaselineInfoImpl =
1912  TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
1913  return TargetLibraryInfo(*BaselineInfoImpl, &F);
1914 }
1915 
1917  if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1918  M.getModuleFlag("wchar_size")))
1919  return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1920  return 0;
1921 }
1922 
1926 }
1927 
1931 }
1932 
1934  const TargetLibraryInfoImpl &TLIImpl)
1935  : ImmutablePass(ID), TLA(TLIImpl) {
1937 }
1938 
1939 AnalysisKey TargetLibraryAnalysis::Key;
1940 
1941 // Register the basic pass.
1943  "Target Library Information", false, true)
1945 
1946 void TargetLibraryInfoWrapperPass::anchor() {}
1947 
1949  ElementCount &FixedVF,
1950  ElementCount &ScalableVF) const {
1951  ScalarF = sanitizeFunctionName(ScalarF);
1952  // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the
1953  // same as a scalar.
1954  ScalableVF = ElementCount::getScalable(0);
1955  FixedVF = ElementCount::getFixed(1);
1956  if (ScalarF.empty())
1957  return;
1958 
1959  std::vector<VecDesc>::const_iterator I =
1960  llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
1961  while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) {
1962  ElementCount *VF =
1963  I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF;
1964  if (ElementCount::isKnownGT(I->VectorizationFactor, *VF))
1965  *VF = I->VectorizationFactor;
1966  ++I;
1967  }
1968 }
llvm::TargetLibraryInfoImpl::setShouldSignExtI32Param
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
Definition: TargetLibraryInfo.h:187
llvm::VecDesc
Describes a possible vectorization of a function.
Definition: TargetLibraryInfo.h:28
llvm::Function::isIntrinsic
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:212
llvm::TargetLibraryInfoImpl::setAvailable
void setAvailable(LibFunc F)
Forces a function to be marked as available.
Definition: TargetLibraryInfo.h:128
llvm::TargetLibraryInfoImpl::SVML
@ SVML
Definition: TargetLibraryInfo.h:95
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::CallingConv::ARM_AAPCS
@ ARM_AAPCS
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
Definition: CallingConv.h:115
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Instruction::getModule
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:66
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::TargetLibraryInfoImpl::getIntSize
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
Definition: TargetLibraryInfo.h:196
llvm::LinearPolySize< ElementCount >::isKnownGT
static bool isKnownGT(const LinearPolySize &LHS, const LinearPolySize &RHS)
Definition: TypeSize.h:335
llvm::Type::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:217
compareByVectorFnName
static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS)
Definition: TargetLibraryInfo.cpp:1818
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:269
llvm::ElementCount
Definition: TypeSize.h:386
llvm::GlobalValue::dropLLVMManglingEscape
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:488
T
llvm::Function
Definition: Function.h:62
llvm::lower_bound
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1661
llvm::VecDesc::VectorFnName
StringRef VectorFnName
Definition: TargetLibraryInfo.h:30
llvm::Triple::Darwin
@ Darwin
Definition: Triple.h:172
llvm::Triple::x86
@ x86
Definition: Triple.h:83
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:60
llvm::StringRef::find
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:315
llvm::TargetLibraryInfoImpl::MASSV
@ MASSV
Definition: TargetLibraryInfo.h:94
llvm::Triple::IOS
@ IOS
Definition: Triple.h:176
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1241
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::TargetLibraryInfoImpl::operator=
TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
Definition: TargetLibraryInfo.cpp:862
llvm::TargetLibraryInfoImpl
Implementation of the target library information.
Definition: TargetLibraryInfo.h:48
llvm::FunctionType::getNumParams
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:139
initialize
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
Definition: TargetLibraryInfo.cpp:116
llvm::NotLibFunc
@ NotLibFunc
Definition: TargetLibraryInfo.h:39
llvm::Type::isFloatingPointTy
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:162
llvm::TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib
void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib)
Calls addVectorizableFunctions with a known preset of functions for the given vector library.
Definition: TargetLibraryInfo.cpp:1834
llvm::CallingConv::ARM_AAPCS_VFP
@ ARM_AAPCS_VFP
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
Definition: CallingConv.h:118
llvm::Triple::WatchOS
@ WatchOS
Definition: Triple.h:197
llvm::initializeTargetLibraryInfoWrapperPassPass
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
llvm::TargetLibraryInfoImpl::isFunctionVectorizable
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
Definition: TargetLibraryInfo.h:159
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::FunctionType::isVarArg
bool isVarArg() const
Definition: DerivedTypes.h:123
llvm::TargetLibraryInfoImpl::setAvailableWithName
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used.
Definition: TargetLibraryInfo.h:134
CommandLine.h
llvm::Type::isArrayTy
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition: Type.h:214
llvm::StringLiteral
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:891
llvm::Triple::FreeBSD
@ FreeBSD
Definition: Triple.h:174
llvm::Triple::sparcv9
@ sparcv9
Definition: Triple.h:76
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
Constants.h
llvm::TargetLibraryInfoImpl::getVectorizedFunction
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF) const
Return the name of the equivalent of F, vectorized with factor VF.
Definition: TargetLibraryInfo.cpp:1893
llvm::Triple::TvOS
@ TvOS
Definition: Triple.h:196
llvm::TargetLibraryInfoImpl::getWidestVF
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &Scalable) const
Returns the largest vectorization factor used in the list of vector functions.
Definition: TargetLibraryInfo.cpp:1948
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:34
INITIALIZE_PASS
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:37
llvm::VecDesc::ScalarFnName
StringRef ScalarFnName
Definition: TargetLibraryInfo.h:29
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:163
llvm::Triple::Emscripten
@ Emscripten
Definition: Triple.h:204
llvm::TargetLibraryAnalysis::run
TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
Definition: TargetLibraryInfo.cpp:1908
TargetLibraryInfo.h
llvm::Triple::xcore
@ xcore
Definition: Triple.h:85
llvm::FunctionType::params
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1439
llvm::LinearPolySize< ElementCount >::getFixed
static ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:284
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:190
llvm::Type::getArrayElementType
Type * getArrayElementType() const
Definition: Type.h:364
llvm::cl::opt
Definition: CommandLine.h:1432
llvm::Triple::MacOSX
@ MacOSX
Definition: Triple.h:180
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:697
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:465
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:578
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:72
llvm::Triple::Linux
@ Linux
Definition: Triple.h:178
I
#define I(x, y, z)
Definition: MD5.cpp:59
compareByScalarFnName
static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS)
Definition: TargetLibraryInfo.cpp:1814
llvm::FunctionType::getParamType
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:441
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::TargetLibraryInfoImpl::setShouldExtI32Return
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
Definition: TargetLibraryInfo.h:181
llvm::Type::getArrayNumElements
uint64_t getArrayNumElements() const
Definition: DerivedTypes.h:384
llvm::TargetLibraryInfoImpl::addVectorizableFunctions
void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
Definition: TargetLibraryInfo.cpp:1826
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:138
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
isCallingConvCCompatible
static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT, FunctionType *FuncTy)
Definition: TargetLibraryInfo.cpp:70
hasBcmp
static bool hasBcmp(const Triple &TT)
Definition: TargetLibraryInfo.cpp:60
llvm::TargetLibraryInfoImpl::Accelerate
@ Accelerate
Definition: TargetLibraryInfo.h:91
llvm::CallingConv::ARM_APCS
@ ARM_APCS
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
Definition: CallingConv.h:111
Triple.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::Triple::arm
@ arm
Definition: Triple.h:50
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
hasSinCosPiStret
static bool hasSinCosPiStret(const Triple &T)
Definition: TargetLibraryInfo.cpp:42
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1748
llvm::TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass
TargetLibraryInfoWrapperPass()
Definition: TargetLibraryInfo.cpp:1923
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:672
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:286
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
llvm::TargetLibraryInfoImpl::disableAllFunctions
void disableAllFunctions()
Disables all builtins.
Definition: TargetLibraryInfo.cpp:1810
std
Definition: BitVector.h:838
llvm::Type::isFloatTy
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:147
ClVectorLibrary
static cl::opt< TargetLibraryInfoImpl::VectorLibrary > ClVectorLibrary("vector-library", cl::Hidden, cl::desc("Vector functions library"), cl::init(TargetLibraryInfoImpl::NoLibrary), cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", "No vector functions library"), clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", "Accelerate framework"), clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM, "Darwin_libsystem_m", "Darwin libsystem_m"), clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86", "GLIBC Vector Math library"), clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV", "IBM MASS vector library"), clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", "Intel SVML library")))
llvm::TargetLibraryInfoImpl::setUnavailable
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
Definition: TargetLibraryInfo.h:123
llvm::LinearPolySize< ElementCount >::getScalable
static ElementCount getScalable(ScalarTy MinVal)
Definition: TypeSize.h:287
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1492
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
llvm::is_sorted
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition: STLExtras.h:1622
llvm::Type::isDoubleTy
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:150
llvm::TargetLibraryInfoImpl::setShouldExtI32Param
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
Definition: TargetLibraryInfo.h:174
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:177
llvm::TargetLibraryInfoImpl::LIBMVEC_X86
@ LIBMVEC_X86
Definition: TargetLibraryInfo.h:93
llvm::Triple::systemz
@ systemz
Definition: Triple.h:78
llvm::TargetLibraryInfoImpl::getWCharSize
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
Definition: TargetLibraryInfo.cpp:1916
llvm::TargetLibraryInfoImpl::getLibFunc
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Definition: TargetLibraryInfo.cpp:894
llvm::Module::getTargetTriple
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:257
llvm::TargetLibraryInfoImpl::NoLibrary
@ NoLibrary
Definition: TargetLibraryInfo.h:90
llvm::NumLibFuncs
@ NumLibFuncs
Definition: TargetLibraryInfo.h:38
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::TargetLibraryInfoImpl::isCallingConvCCompatible
static bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
Definition: TargetLibraryInfo.cpp:101
llvm::CallingConv::C
@ C
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
compareWithScalarFnName
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S)
Definition: TargetLibraryInfo.cpp:1822
sanitizeFunctionName
static StringRef sanitizeFunctionName(StringRef funcName)
Definition: TargetLibraryInfo.cpp:883
llvm::cl::desc
Definition: CommandLine.h:412
llvm::TargetLibraryInfoImpl::VectorLibrary
VectorLibrary
List of known vector-functions libraries.
Definition: TargetLibraryInfo.h:89
llvm::TargetLibraryInfoImpl::TargetLibraryInfoImpl
TargetLibraryInfoImpl()
Definition: TargetLibraryInfo.cpp:826
InitializePasses.h
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition: DerivedTypes.h:124
llvm::Triple::tce
@ tce
Definition: Triple.h:79
llvm::TargetLibraryInfoImpl::setIntSize
void setIntSize(unsigned Bits)
Initialize the C-level size of an integer.
Definition: TargetLibraryInfo.h:201
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:52
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::TargetLibraryInfoImpl::DarwinLibSystemM
@ DarwinLibSystemM
Definition: TargetLibraryInfo.h:92