LLVM  6.0.0svn
TargetLibraryInfo.cpp
Go to the documentation of this file.
1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the TargetLibraryInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/IR/Constants.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  "Intel SVML library")));
29 
30 StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
31 #define TLI_DEFINE_STRING
32 #include "llvm/Analysis/TargetLibraryInfo.def"
33 };
34 
35 static bool hasSinCosPiStret(const Triple &T) {
36  // Only Darwin variants have _stret versions of combined trig functions.
37  if (!T.isOSDarwin())
38  return false;
39 
40  // The ABI is rather complicated on x86, so don't do anything special there.
41  if (T.getArch() == Triple::x86)
42  return false;
43 
44  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
45  return false;
46 
47  if (T.isiOS() && T.isOSVersionLT(7, 0))
48  return false;
49 
50  return true;
51 }
52 
53 /// initialize - Initialize the set of available library functions based on the
54 /// specified target triple. This should be carefully written so that a missing
55 /// target triple gets a sane set of defaults.
56 static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
57  ArrayRef<StringRef> StandardNames) {
58  // Verify that the StandardNames array is in alphabetical order.
59  assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
60  [](StringRef LHS, StringRef RHS) {
61  return LHS < RHS;
62  }) &&
63  "TargetLibraryInfoImpl function names must be sorted");
64 
65  bool ShouldExtI32Param = false, ShouldExtI32Return = false,
66  ShouldSignExtI32Param = false;
67  // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
68  // returns corresponding to C-level ints and unsigned ints.
69  if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
71  ShouldExtI32Param = true;
72  ShouldExtI32Return = true;
73  }
74  // Mips, on the other hand, needs signext on i32 parameters corresponding
75  // to both signed and unsigned ints.
76  if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
78  ShouldSignExtI32Param = true;
79  }
80  TLI.setShouldExtI32Param(ShouldExtI32Param);
81  TLI.setShouldExtI32Return(ShouldExtI32Return);
82  TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
83 
84  if (T.getArch() == Triple::r600 ||
85  T.getArch() == Triple::amdgcn) {
86  TLI.setUnavailable(LibFunc_ldexp);
87  TLI.setUnavailable(LibFunc_ldexpf);
88  TLI.setUnavailable(LibFunc_ldexpl);
89  TLI.setUnavailable(LibFunc_exp10);
90  TLI.setUnavailable(LibFunc_exp10f);
91  TLI.setUnavailable(LibFunc_exp10l);
92  TLI.setUnavailable(LibFunc_log10);
93  TLI.setUnavailable(LibFunc_log10f);
94  TLI.setUnavailable(LibFunc_log10l);
95  }
96 
97  // There are no library implementations of mempcy and memset for AMD gpus and
98  // these can be difficult to lower in the backend.
99  if (T.getArch() == Triple::r600 ||
100  T.getArch() == Triple::amdgcn) {
101  TLI.setUnavailable(LibFunc_memcpy);
102  TLI.setUnavailable(LibFunc_memset);
103  TLI.setUnavailable(LibFunc_memset_pattern16);
104  return;
105  }
106 
107  // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
108  // All versions of watchOS support it.
109  if (T.isMacOSX()) {
110  if (T.isMacOSXVersionLT(10, 5))
111  TLI.setUnavailable(LibFunc_memset_pattern16);
112  } else if (T.isiOS()) {
113  if (T.isOSVersionLT(3, 0))
114  TLI.setUnavailable(LibFunc_memset_pattern16);
115  } else if (!T.isWatchOS()) {
116  TLI.setUnavailable(LibFunc_memset_pattern16);
117  }
118 
119  if (!hasSinCosPiStret(T)) {
120  TLI.setUnavailable(LibFunc_sinpi);
121  TLI.setUnavailable(LibFunc_sinpif);
122  TLI.setUnavailable(LibFunc_cospi);
123  TLI.setUnavailable(LibFunc_cospif);
124  TLI.setUnavailable(LibFunc_sincospi_stret);
125  TLI.setUnavailable(LibFunc_sincospif_stret);
126  }
127 
128  if (T.isMacOSX() && T.getArch() == Triple::x86 &&
129  !T.isMacOSXVersionLT(10, 7)) {
130  // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
131  // we don't care about) have two versions; on recent OSX, the one we want
132  // has a $UNIX2003 suffix. The two implementations are identical except
133  // for the return value in some edge cases. However, we don't want to
134  // generate code that depends on the old symbols.
135  TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
136  TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
137  }
138 
139  // iprintf and friends are only available on XCore and TCE.
140  if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
141  TLI.setUnavailable(LibFunc_iprintf);
142  TLI.setUnavailable(LibFunc_siprintf);
143  TLI.setUnavailable(LibFunc_fiprintf);
144  }
145 
146  if (T.isOSWindows() && !T.isOSCygMing()) {
147  // Win32 does not support long double
148  TLI.setUnavailable(LibFunc_acosl);
149  TLI.setUnavailable(LibFunc_asinl);
150  TLI.setUnavailable(LibFunc_atanl);
151  TLI.setUnavailable(LibFunc_atan2l);
152  TLI.setUnavailable(LibFunc_ceill);
153  TLI.setUnavailable(LibFunc_copysignl);
154  TLI.setUnavailable(LibFunc_cosl);
155  TLI.setUnavailable(LibFunc_coshl);
156  TLI.setUnavailable(LibFunc_expl);
157  TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf
158  TLI.setUnavailable(LibFunc_fabsl);
159  TLI.setUnavailable(LibFunc_floorl);
160  TLI.setUnavailable(LibFunc_fmaxl);
161  TLI.setUnavailable(LibFunc_fminl);
162  TLI.setUnavailable(LibFunc_fmodl);
163  TLI.setUnavailable(LibFunc_frexpl);
164  TLI.setUnavailable(LibFunc_ldexpf);
165  TLI.setUnavailable(LibFunc_ldexpl);
166  TLI.setUnavailable(LibFunc_logl);
167  TLI.setUnavailable(LibFunc_modfl);
168  TLI.setUnavailable(LibFunc_powl);
169  TLI.setUnavailable(LibFunc_sinl);
170  TLI.setUnavailable(LibFunc_sinhl);
171  TLI.setUnavailable(LibFunc_sqrtl);
172  TLI.setUnavailable(LibFunc_tanl);
173  TLI.setUnavailable(LibFunc_tanhl);
174 
175  // Win32 only has C89 math
176  TLI.setUnavailable(LibFunc_acosh);
177  TLI.setUnavailable(LibFunc_acoshf);
178  TLI.setUnavailable(LibFunc_acoshl);
179  TLI.setUnavailable(LibFunc_asinh);
180  TLI.setUnavailable(LibFunc_asinhf);
181  TLI.setUnavailable(LibFunc_asinhl);
182  TLI.setUnavailable(LibFunc_atanh);
183  TLI.setUnavailable(LibFunc_atanhf);
184  TLI.setUnavailable(LibFunc_atanhl);
185  TLI.setUnavailable(LibFunc_cbrt);
186  TLI.setUnavailable(LibFunc_cbrtf);
187  TLI.setUnavailable(LibFunc_cbrtl);
188  TLI.setUnavailable(LibFunc_exp2);
189  TLI.setUnavailable(LibFunc_exp2f);
190  TLI.setUnavailable(LibFunc_exp2l);
191  TLI.setUnavailable(LibFunc_expm1);
192  TLI.setUnavailable(LibFunc_expm1f);
193  TLI.setUnavailable(LibFunc_expm1l);
194  TLI.setUnavailable(LibFunc_log2);
195  TLI.setUnavailable(LibFunc_log2f);
196  TLI.setUnavailable(LibFunc_log2l);
197  TLI.setUnavailable(LibFunc_log1p);
198  TLI.setUnavailable(LibFunc_log1pf);
199  TLI.setUnavailable(LibFunc_log1pl);
200  TLI.setUnavailable(LibFunc_logb);
201  TLI.setUnavailable(LibFunc_logbf);
202  TLI.setUnavailable(LibFunc_logbl);
203  TLI.setUnavailable(LibFunc_nearbyint);
204  TLI.setUnavailable(LibFunc_nearbyintf);
205  TLI.setUnavailable(LibFunc_nearbyintl);
206  TLI.setUnavailable(LibFunc_rint);
207  TLI.setUnavailable(LibFunc_rintf);
208  TLI.setUnavailable(LibFunc_rintl);
209  TLI.setUnavailable(LibFunc_round);
210  TLI.setUnavailable(LibFunc_roundf);
211  TLI.setUnavailable(LibFunc_roundl);
212  TLI.setUnavailable(LibFunc_trunc);
213  TLI.setUnavailable(LibFunc_truncf);
214  TLI.setUnavailable(LibFunc_truncl);
215 
216  // Win32 provides some C99 math with mangled names
217  TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
218 
219  if (T.getArch() == Triple::x86) {
220  // Win32 on x86 implements single-precision math functions as macros
221  TLI.setUnavailable(LibFunc_acosf);
222  TLI.setUnavailable(LibFunc_asinf);
223  TLI.setUnavailable(LibFunc_atanf);
224  TLI.setUnavailable(LibFunc_atan2f);
225  TLI.setUnavailable(LibFunc_ceilf);
226  TLI.setUnavailable(LibFunc_copysignf);
227  TLI.setUnavailable(LibFunc_cosf);
228  TLI.setUnavailable(LibFunc_coshf);
229  TLI.setUnavailable(LibFunc_expf);
230  TLI.setUnavailable(LibFunc_floorf);
231  TLI.setUnavailable(LibFunc_fminf);
232  TLI.setUnavailable(LibFunc_fmaxf);
233  TLI.setUnavailable(LibFunc_fmodf);
234  TLI.setUnavailable(LibFunc_logf);
235  TLI.setUnavailable(LibFunc_log10f);
236  TLI.setUnavailable(LibFunc_modff);
237  TLI.setUnavailable(LibFunc_powf);
238  TLI.setUnavailable(LibFunc_sinf);
239  TLI.setUnavailable(LibFunc_sinhf);
240  TLI.setUnavailable(LibFunc_sqrtf);
241  TLI.setUnavailable(LibFunc_tanf);
242  TLI.setUnavailable(LibFunc_tanhf);
243  }
244 
245  // These definitions are due to math-finite.h header on Linux
246  TLI.setUnavailable(LibFunc_acos_finite);
247  TLI.setUnavailable(LibFunc_acosf_finite);
248  TLI.setUnavailable(LibFunc_acosl_finite);
249  TLI.setUnavailable(LibFunc_acosh_finite);
250  TLI.setUnavailable(LibFunc_acoshf_finite);
251  TLI.setUnavailable(LibFunc_acoshl_finite);
252  TLI.setUnavailable(LibFunc_asin_finite);
253  TLI.setUnavailable(LibFunc_asinf_finite);
254  TLI.setUnavailable(LibFunc_asinl_finite);
255  TLI.setUnavailable(LibFunc_atan2_finite);
256  TLI.setUnavailable(LibFunc_atan2f_finite);
257  TLI.setUnavailable(LibFunc_atan2l_finite);
258  TLI.setUnavailable(LibFunc_atanh_finite);
259  TLI.setUnavailable(LibFunc_atanhf_finite);
260  TLI.setUnavailable(LibFunc_atanhl_finite);
261  TLI.setUnavailable(LibFunc_cosh_finite);
262  TLI.setUnavailable(LibFunc_coshf_finite);
263  TLI.setUnavailable(LibFunc_coshl_finite);
264  TLI.setUnavailable(LibFunc_exp10_finite);
265  TLI.setUnavailable(LibFunc_exp10f_finite);
266  TLI.setUnavailable(LibFunc_exp10l_finite);
267  TLI.setUnavailable(LibFunc_exp2_finite);
268  TLI.setUnavailable(LibFunc_exp2f_finite);
269  TLI.setUnavailable(LibFunc_exp2l_finite);
270  TLI.setUnavailable(LibFunc_exp_finite);
271  TLI.setUnavailable(LibFunc_expf_finite);
272  TLI.setUnavailable(LibFunc_expl_finite);
273  TLI.setUnavailable(LibFunc_log10_finite);
274  TLI.setUnavailable(LibFunc_log10f_finite);
275  TLI.setUnavailable(LibFunc_log10l_finite);
276  TLI.setUnavailable(LibFunc_log2_finite);
277  TLI.setUnavailable(LibFunc_log2f_finite);
278  TLI.setUnavailable(LibFunc_log2l_finite);
279  TLI.setUnavailable(LibFunc_log_finite);
280  TLI.setUnavailable(LibFunc_logf_finite);
281  TLI.setUnavailable(LibFunc_logl_finite);
282  TLI.setUnavailable(LibFunc_pow_finite);
283  TLI.setUnavailable(LibFunc_powf_finite);
284  TLI.setUnavailable(LibFunc_powl_finite);
285  TLI.setUnavailable(LibFunc_sinh_finite);
286  TLI.setUnavailable(LibFunc_sinhf_finite);
287  TLI.setUnavailable(LibFunc_sinhl_finite);
288 
289  // Win32 does *not* provide provide these functions, but they are
290  // generally available on POSIX-compliant systems:
291  TLI.setUnavailable(LibFunc_access);
292  TLI.setUnavailable(LibFunc_bcmp);
293  TLI.setUnavailable(LibFunc_bcopy);
294  TLI.setUnavailable(LibFunc_bzero);
295  TLI.setUnavailable(LibFunc_chmod);
296  TLI.setUnavailable(LibFunc_chown);
297  TLI.setUnavailable(LibFunc_closedir);
298  TLI.setUnavailable(LibFunc_ctermid);
299  TLI.setUnavailable(LibFunc_fdopen);
300  TLI.setUnavailable(LibFunc_ffs);
301  TLI.setUnavailable(LibFunc_fileno);
302  TLI.setUnavailable(LibFunc_flockfile);
303  TLI.setUnavailable(LibFunc_fseeko);
304  TLI.setUnavailable(LibFunc_fstat);
305  TLI.setUnavailable(LibFunc_fstatvfs);
306  TLI.setUnavailable(LibFunc_ftello);
307  TLI.setUnavailable(LibFunc_ftrylockfile);
308  TLI.setUnavailable(LibFunc_funlockfile);
309  TLI.setUnavailable(LibFunc_getc_unlocked);
310  TLI.setUnavailable(LibFunc_getitimer);
311  TLI.setUnavailable(LibFunc_getlogin_r);
312  TLI.setUnavailable(LibFunc_getpwnam);
313  TLI.setUnavailable(LibFunc_gettimeofday);
314  TLI.setUnavailable(LibFunc_htonl);
315  TLI.setUnavailable(LibFunc_htons);
316  TLI.setUnavailable(LibFunc_lchown);
317  TLI.setUnavailable(LibFunc_lstat);
318  TLI.setUnavailable(LibFunc_memccpy);
319  TLI.setUnavailable(LibFunc_mkdir);
320  TLI.setUnavailable(LibFunc_ntohl);
321  TLI.setUnavailable(LibFunc_ntohs);
322  TLI.setUnavailable(LibFunc_open);
323  TLI.setUnavailable(LibFunc_opendir);
324  TLI.setUnavailable(LibFunc_pclose);
325  TLI.setUnavailable(LibFunc_popen);
326  TLI.setUnavailable(LibFunc_pread);
327  TLI.setUnavailable(LibFunc_pwrite);
328  TLI.setUnavailable(LibFunc_read);
329  TLI.setUnavailable(LibFunc_readlink);
330  TLI.setUnavailable(LibFunc_realpath);
331  TLI.setUnavailable(LibFunc_rmdir);
332  TLI.setUnavailable(LibFunc_setitimer);
333  TLI.setUnavailable(LibFunc_stat);
334  TLI.setUnavailable(LibFunc_statvfs);
335  TLI.setUnavailable(LibFunc_stpcpy);
336  TLI.setUnavailable(LibFunc_stpncpy);
337  TLI.setUnavailable(LibFunc_strcasecmp);
338  TLI.setUnavailable(LibFunc_strncasecmp);
339  TLI.setUnavailable(LibFunc_times);
340  TLI.setUnavailable(LibFunc_uname);
341  TLI.setUnavailable(LibFunc_unlink);
342  TLI.setUnavailable(LibFunc_unsetenv);
343  TLI.setUnavailable(LibFunc_utime);
344  TLI.setUnavailable(LibFunc_utimes);
345  TLI.setUnavailable(LibFunc_write);
346 
347  // Win32 does *not* provide provide these functions, but they are
348  // specified by C99:
349  TLI.setUnavailable(LibFunc_atoll);
350  TLI.setUnavailable(LibFunc_frexpf);
351  TLI.setUnavailable(LibFunc_llabs);
352  }
353 
354  switch (T.getOS()) {
355  case Triple::MacOSX:
356  // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
357  // and their names are __exp10 and __exp10f. exp10l is not available on
358  // OS X or iOS.
359  TLI.setUnavailable(LibFunc_exp10l);
360  if (T.isMacOSXVersionLT(10, 9)) {
361  TLI.setUnavailable(LibFunc_exp10);
362  TLI.setUnavailable(LibFunc_exp10f);
363  } else {
364  TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
365  TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
366  }
367  break;
368  case Triple::IOS:
369  case Triple::TvOS:
370  case Triple::WatchOS:
371  TLI.setUnavailable(LibFunc_exp10l);
372  if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
373  (T.isOSVersionLT(9, 0) &&
374  (T.getArch() == Triple::x86 ||
375  T.getArch() == Triple::x86_64)))) {
376  TLI.setUnavailable(LibFunc_exp10);
377  TLI.setUnavailable(LibFunc_exp10f);
378  } else {
379  TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
380  TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
381  }
382  break;
383  case Triple::Linux:
384  // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
385  // buggy prior to glibc version 2.18. Until this version is widely deployed
386  // or we have a reasonable detection strategy, we cannot use exp10 reliably
387  // on Linux.
388  //
389  // Fall through to disable all of them.
391  default:
392  TLI.setUnavailable(LibFunc_exp10);
393  TLI.setUnavailable(LibFunc_exp10f);
394  TLI.setUnavailable(LibFunc_exp10l);
395  }
396 
397  // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
398  // Linux (GLIBC):
399  // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
400  // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
401  // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
402  switch (T.getOS()) {
403  case Triple::Darwin:
404  case Triple::MacOSX:
405  case Triple::IOS:
406  case Triple::TvOS:
407  case Triple::WatchOS:
408  case Triple::FreeBSD:
409  case Triple::Linux:
410  break;
411  default:
412  TLI.setUnavailable(LibFunc_ffsl);
413  }
414 
415  // ffsll is available on at least FreeBSD and Linux (GLIBC):
416  // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
417  // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
418  switch (T.getOS()) {
419  case Triple::Darwin:
420  case Triple::MacOSX:
421  case Triple::IOS:
422  case Triple::TvOS:
423  case Triple::WatchOS:
424  case Triple::FreeBSD:
425  case Triple::Linux:
426  break;
427  default:
428  TLI.setUnavailable(LibFunc_ffsll);
429  }
430 
431  // The following functions are available on at least FreeBSD:
432  // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
433  // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
434  // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
435  if (!T.isOSFreeBSD()) {
436  TLI.setUnavailable(LibFunc_fls);
437  TLI.setUnavailable(LibFunc_flsl);
438  TLI.setUnavailable(LibFunc_flsll);
439  }
440 
441  // The following functions are available on at least Linux:
442  if (!T.isOSLinux()) {
443  TLI.setUnavailable(LibFunc_dunder_strdup);
444  TLI.setUnavailable(LibFunc_dunder_strtok_r);
445  TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
446  TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
447  TLI.setUnavailable(LibFunc_under_IO_getc);
448  TLI.setUnavailable(LibFunc_under_IO_putc);
449  TLI.setUnavailable(LibFunc_memalign);
450  TLI.setUnavailable(LibFunc_fopen64);
451  TLI.setUnavailable(LibFunc_fseeko64);
452  TLI.setUnavailable(LibFunc_fstat64);
453  TLI.setUnavailable(LibFunc_fstatvfs64);
454  TLI.setUnavailable(LibFunc_ftello64);
455  TLI.setUnavailable(LibFunc_lstat64);
456  TLI.setUnavailable(LibFunc_open64);
457  TLI.setUnavailable(LibFunc_stat64);
458  TLI.setUnavailable(LibFunc_statvfs64);
459  TLI.setUnavailable(LibFunc_tmpfile64);
460  }
461 
462  // As currently implemented in clang, NVPTX code has no standard library to
463  // speak of. Headers provide a standard-ish library implementation, but many
464  // of the signatures are wrong -- for example, many libm functions are not
465  // extern "C".
466  //
467  // libdevice, an IR library provided by nvidia, is linked in by the front-end,
468  // but only used functions are provided to llvm. Moreover, most of the
469  // functions in libdevice don't map precisely to standard library functions.
470  //
471  // FIXME: Having no standard library prevents e.g. many fastmath
472  // optimizations, so this situation should be fixed.
473  if (T.isNVPTX()) {
474  TLI.disableAllFunctions();
475  TLI.setAvailable(LibFunc_nvvm_reflect);
476  } else {
477  TLI.setUnavailable(LibFunc_nvvm_reflect);
478  }
479 
481 }
482 
484  // Default to everything being available.
485  memset(AvailableArray, -1, sizeof(AvailableArray));
486 
487  initialize(*this, Triple(), StandardNames);
488 }
489 
491  // Default to everything being available.
492  memset(AvailableArray, -1, sizeof(AvailableArray));
493 
494  initialize(*this, T, StandardNames);
495 }
496 
498  : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
499  ShouldExtI32Return(TLI.ShouldExtI32Return),
500  ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
501  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
502  VectorDescs = TLI.VectorDescs;
503  ScalarDescs = TLI.ScalarDescs;
504 }
505 
507  : CustomNames(std::move(TLI.CustomNames)),
508  ShouldExtI32Param(TLI.ShouldExtI32Param),
509  ShouldExtI32Return(TLI.ShouldExtI32Return),
510  ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
511  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
512  AvailableArray);
513  VectorDescs = TLI.VectorDescs;
514  ScalarDescs = TLI.ScalarDescs;
515 }
516 
518  CustomNames = TLI.CustomNames;
519  ShouldExtI32Param = TLI.ShouldExtI32Param;
520  ShouldExtI32Return = TLI.ShouldExtI32Return;
521  ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
522  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
523  return *this;
524 }
525 
527  CustomNames = std::move(TLI.CustomNames);
528  ShouldExtI32Param = TLI.ShouldExtI32Param;
529  ShouldExtI32Return = TLI.ShouldExtI32Return;
530  ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
531  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
532  AvailableArray);
533  return *this;
534 }
535 
537  // Filter out empty names and names containing null bytes, those can't be in
538  // our table.
539  if (funcName.empty() || funcName.find('\0') != StringRef::npos)
540  return StringRef();
541 
542  // Check for \01 prefix that is used to mangle __asm declarations and
543  // strip it if present.
544  return GlobalValue::dropLLVMManglingEscape(funcName);
545 }
546 
548  LibFunc &F) const {
549  StringRef const *Start = &StandardNames[0];
550  StringRef const *End = &StandardNames[NumLibFuncs];
551 
552  funcName = sanitizeFunctionName(funcName);
553  if (funcName.empty())
554  return false;
555 
556  StringRef const *I = std::lower_bound(
557  Start, End, funcName, [](StringRef LHS, StringRef RHS) {
558  return LHS < RHS;
559  });
560  if (I != End && *I == funcName) {
561  F = (LibFunc)(I - Start);
562  return true;
563  }
564  return false;
565 }
566 
567 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
568  LibFunc F,
569  const DataLayout *DL) const {
570  LLVMContext &Ctx = FTy.getContext();
571  Type *PCharTy = Type::getInt8PtrTy(Ctx);
572  Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
573  auto IsSizeTTy = [SizeTTy](Type *Ty) {
574  return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
575  };
576  unsigned NumParams = FTy.getNumParams();
577 
578  switch (F) {
579  case LibFunc_strlen:
580  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
581  FTy.getReturnType()->isIntegerTy());
582 
583  case LibFunc_strchr:
584  case LibFunc_strrchr:
585  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
586  FTy.getParamType(0) == FTy.getReturnType() &&
587  FTy.getParamType(1)->isIntegerTy());
588 
589  case LibFunc_strtol:
590  case LibFunc_strtod:
591  case LibFunc_strtof:
592  case LibFunc_strtoul:
593  case LibFunc_strtoll:
594  case LibFunc_strtold:
595  case LibFunc_strtoull:
596  return ((NumParams == 2 || NumParams == 3) &&
597  FTy.getParamType(0)->isPointerTy() &&
598  FTy.getParamType(1)->isPointerTy());
599  case LibFunc_strcat:
600  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
601  FTy.getParamType(0) == FTy.getReturnType() &&
602  FTy.getParamType(1) == FTy.getReturnType());
603 
604  case LibFunc_strncat:
605  return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
606  FTy.getParamType(0) == FTy.getReturnType() &&
607  FTy.getParamType(1) == FTy.getReturnType() &&
608  FTy.getParamType(2)->isIntegerTy());
609 
610  case LibFunc_strcpy_chk:
611  case LibFunc_stpcpy_chk:
612  --NumParams;
613  if (!IsSizeTTy(FTy.getParamType(NumParams)))
614  return false;
616  case LibFunc_strcpy:
617  case LibFunc_stpcpy:
618  return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
619  FTy.getParamType(0) == FTy.getParamType(1) &&
620  FTy.getParamType(0) == PCharTy);
621 
622  case LibFunc_strncpy_chk:
623  case LibFunc_stpncpy_chk:
624  --NumParams;
625  if (!IsSizeTTy(FTy.getParamType(NumParams)))
626  return false;
628  case LibFunc_strncpy:
629  case LibFunc_stpncpy:
630  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
631  FTy.getParamType(0) == FTy.getParamType(1) &&
632  FTy.getParamType(0) == PCharTy &&
633  FTy.getParamType(2)->isIntegerTy());
634 
635  case LibFunc_strxfrm:
636  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
637  FTy.getParamType(1)->isPointerTy());
638 
639  case LibFunc_strcmp:
640  return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
641  FTy.getParamType(0)->isPointerTy() &&
642  FTy.getParamType(0) == FTy.getParamType(1));
643 
644  case LibFunc_strncmp:
645  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
646  FTy.getParamType(0)->isPointerTy() &&
647  FTy.getParamType(0) == FTy.getParamType(1) &&
648  FTy.getParamType(2)->isIntegerTy());
649 
650  case LibFunc_strspn:
651  case LibFunc_strcspn:
652  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
653  FTy.getParamType(0) == FTy.getParamType(1) &&
654  FTy.getReturnType()->isIntegerTy());
655 
656  case LibFunc_strcoll:
657  case LibFunc_strcasecmp:
658  case LibFunc_strncasecmp:
659  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
660  FTy.getParamType(1)->isPointerTy());
661 
662  case LibFunc_strstr:
663  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
664  FTy.getParamType(0)->isPointerTy() &&
665  FTy.getParamType(1)->isPointerTy());
666 
667  case LibFunc_strpbrk:
668  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
669  FTy.getReturnType() == FTy.getParamType(0) &&
670  FTy.getParamType(0) == FTy.getParamType(1));
671 
672  case LibFunc_strtok:
673  case LibFunc_strtok_r:
674  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
675  case LibFunc_scanf:
676  case LibFunc_setbuf:
677  case LibFunc_setvbuf:
678  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
679  case LibFunc_strdup:
680  case LibFunc_strndup:
681  return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
682  FTy.getParamType(0)->isPointerTy());
683  case LibFunc_sscanf:
684  case LibFunc_stat:
685  case LibFunc_statvfs:
686  case LibFunc_siprintf:
687  case LibFunc_sprintf:
688  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
689  FTy.getParamType(1)->isPointerTy());
690  case LibFunc_snprintf:
691  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
692  FTy.getParamType(2)->isPointerTy());
693  case LibFunc_setitimer:
694  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
695  FTy.getParamType(2)->isPointerTy());
696  case LibFunc_system:
697  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
698  case LibFunc_malloc:
699  return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
700  case LibFunc_memcmp:
701  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
702  FTy.getParamType(0)->isPointerTy() &&
703  FTy.getParamType(1)->isPointerTy());
704 
705  case LibFunc_memchr:
706  case LibFunc_memrchr:
707  return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
708  FTy.getReturnType() == FTy.getParamType(0) &&
709  FTy.getParamType(1)->isIntegerTy(32) &&
710  IsSizeTTy(FTy.getParamType(2)));
711  case LibFunc_modf:
712  case LibFunc_modff:
713  case LibFunc_modfl:
714  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
715 
716  case LibFunc_memcpy_chk:
717  case LibFunc_memmove_chk:
718  --NumParams;
719  if (!IsSizeTTy(FTy.getParamType(NumParams)))
720  return false;
722  case LibFunc_memcpy:
723  case LibFunc_mempcpy:
724  case LibFunc_memmove:
725  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
726  FTy.getParamType(0)->isPointerTy() &&
727  FTy.getParamType(1)->isPointerTy() &&
728  IsSizeTTy(FTy.getParamType(2)));
729 
730  case LibFunc_memset_chk:
731  --NumParams;
732  if (!IsSizeTTy(FTy.getParamType(NumParams)))
733  return false;
735  case LibFunc_memset:
736  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
737  FTy.getParamType(0)->isPointerTy() &&
738  FTy.getParamType(1)->isIntegerTy() &&
739  IsSizeTTy(FTy.getParamType(2)));
740 
741  case LibFunc_memccpy:
742  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
743  case LibFunc_memalign:
744  return (FTy.getReturnType()->isPointerTy());
745  case LibFunc_realloc:
746  case LibFunc_reallocf:
747  return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
748  FTy.getParamType(0) == FTy.getReturnType() &&
749  IsSizeTTy(FTy.getParamType(1)));
750  case LibFunc_read:
751  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
752  case LibFunc_rewind:
753  case LibFunc_rmdir:
754  case LibFunc_remove:
755  case LibFunc_realpath:
756  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
757  case LibFunc_rename:
758  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
759  FTy.getParamType(1)->isPointerTy());
760  case LibFunc_readlink:
761  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
762  FTy.getParamType(1)->isPointerTy());
763  case LibFunc_write:
764  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
765  case LibFunc_bcopy:
766  case LibFunc_bcmp:
767  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
768  FTy.getParamType(1)->isPointerTy());
769  case LibFunc_bzero:
770  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
771  case LibFunc_calloc:
772  return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
773 
774  case LibFunc_atof:
775  case LibFunc_atoi:
776  case LibFunc_atol:
777  case LibFunc_atoll:
778  case LibFunc_ferror:
779  case LibFunc_getenv:
780  case LibFunc_getpwnam:
781  case LibFunc_iprintf:
782  case LibFunc_pclose:
783  case LibFunc_perror:
784  case LibFunc_printf:
785  case LibFunc_puts:
786  case LibFunc_uname:
787  case LibFunc_under_IO_getc:
788  case LibFunc_unlink:
789  case LibFunc_unsetenv:
790  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
791 
792  case LibFunc_access:
793  case LibFunc_chmod:
794  case LibFunc_chown:
795  case LibFunc_clearerr:
796  case LibFunc_closedir:
797  case LibFunc_ctermid:
798  case LibFunc_fclose:
799  case LibFunc_feof:
800  case LibFunc_fflush:
801  case LibFunc_fgetc:
802  case LibFunc_fileno:
803  case LibFunc_flockfile:
804  case LibFunc_free:
805  case LibFunc_fseek:
806  case LibFunc_fseeko64:
807  case LibFunc_fseeko:
808  case LibFunc_fsetpos:
809  case LibFunc_ftell:
810  case LibFunc_ftello64:
811  case LibFunc_ftello:
812  case LibFunc_ftrylockfile:
813  case LibFunc_funlockfile:
814  case LibFunc_getc:
815  case LibFunc_getc_unlocked:
816  case LibFunc_getlogin_r:
817  case LibFunc_mkdir:
818  case LibFunc_mktime:
819  case LibFunc_times:
820  return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
821 
822  case LibFunc_fopen:
823  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
824  FTy.getParamType(0)->isPointerTy() &&
825  FTy.getParamType(1)->isPointerTy());
826  case LibFunc_fdopen:
827  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
828  FTy.getParamType(1)->isPointerTy());
829  case LibFunc_fputc:
830  case LibFunc_fstat:
831  case LibFunc_frexp:
832  case LibFunc_frexpf:
833  case LibFunc_frexpl:
834  case LibFunc_fstatvfs:
835  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
836  case LibFunc_fgets:
837  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
838  FTy.getParamType(2)->isPointerTy());
839  case LibFunc_fread:
840  return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
841  FTy.getParamType(3)->isPointerTy());
842  case LibFunc_fwrite:
843  return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
844  FTy.getParamType(0)->isPointerTy() &&
845  FTy.getParamType(1)->isIntegerTy() &&
846  FTy.getParamType(2)->isIntegerTy() &&
847  FTy.getParamType(3)->isPointerTy());
848  case LibFunc_fputs:
849  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
850  FTy.getParamType(1)->isPointerTy());
851  case LibFunc_fscanf:
852  case LibFunc_fiprintf:
853  case LibFunc_fprintf:
854  return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
855  FTy.getParamType(0)->isPointerTy() &&
856  FTy.getParamType(1)->isPointerTy());
857  case LibFunc_fgetpos:
858  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
859  FTy.getParamType(1)->isPointerTy());
860  case LibFunc_getchar:
861  return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
862  case LibFunc_gets:
863  return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
864  case LibFunc_getitimer:
865  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
866  case LibFunc_ungetc:
867  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
868  case LibFunc_utime:
869  case LibFunc_utimes:
870  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
871  FTy.getParamType(1)->isPointerTy());
872  case LibFunc_putc:
873  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
874  case LibFunc_pread:
875  case LibFunc_pwrite:
876  return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
877  case LibFunc_popen:
878  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
879  FTy.getParamType(0)->isPointerTy() &&
880  FTy.getParamType(1)->isPointerTy());
881  case LibFunc_vscanf:
882  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
883  case LibFunc_vsscanf:
884  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
885  FTy.getParamType(2)->isPointerTy());
886  case LibFunc_vfscanf:
887  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
888  FTy.getParamType(2)->isPointerTy());
889  case LibFunc_valloc:
890  return (FTy.getReturnType()->isPointerTy());
891  case LibFunc_vprintf:
892  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
893  case LibFunc_vfprintf:
894  case LibFunc_vsprintf:
895  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
896  FTy.getParamType(1)->isPointerTy());
897  case LibFunc_vsnprintf:
898  return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
899  FTy.getParamType(2)->isPointerTy());
900  case LibFunc_open:
901  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
902  case LibFunc_opendir:
903  return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
904  FTy.getParamType(0)->isPointerTy());
905  case LibFunc_tmpfile:
906  return (FTy.getReturnType()->isPointerTy());
907  case LibFunc_htonl:
908  case LibFunc_ntohl:
909  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
910  FTy.getReturnType() == FTy.getParamType(0));
911  case LibFunc_htons:
912  case LibFunc_ntohs:
913  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
914  FTy.getReturnType() == FTy.getParamType(0));
915  case LibFunc_lstat:
916  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
917  FTy.getParamType(1)->isPointerTy());
918  case LibFunc_lchown:
919  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
920  case LibFunc_qsort:
921  return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
922  case LibFunc_dunder_strdup:
923  case LibFunc_dunder_strndup:
924  return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
925  FTy.getParamType(0)->isPointerTy());
926  case LibFunc_dunder_strtok_r:
927  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
928  case LibFunc_under_IO_putc:
929  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
930  case LibFunc_dunder_isoc99_scanf:
931  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
932  case LibFunc_stat64:
933  case LibFunc_lstat64:
934  case LibFunc_statvfs64:
935  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
936  FTy.getParamType(1)->isPointerTy());
937  case LibFunc_dunder_isoc99_sscanf:
938  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
939  FTy.getParamType(1)->isPointerTy());
940  case LibFunc_fopen64:
941  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
942  FTy.getParamType(0)->isPointerTy() &&
943  FTy.getParamType(1)->isPointerTy());
944  case LibFunc_tmpfile64:
945  return (FTy.getReturnType()->isPointerTy());
946  case LibFunc_fstat64:
947  case LibFunc_fstatvfs64:
948  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
949  case LibFunc_open64:
950  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
951  case LibFunc_gettimeofday:
952  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
953  FTy.getParamType(1)->isPointerTy());
954 
955  // new(unsigned int);
956  case LibFunc_Znwj:
957  // new(unsigned long);
958  case LibFunc_Znwm:
959  // new[](unsigned int);
960  case LibFunc_Znaj:
961  // new[](unsigned long);
962  case LibFunc_Znam:
963  // new(unsigned int);
964  case LibFunc_msvc_new_int:
965  // new(unsigned long long);
966  case LibFunc_msvc_new_longlong:
967  // new[](unsigned int);
968  case LibFunc_msvc_new_array_int:
969  // new[](unsigned long long);
970  case LibFunc_msvc_new_array_longlong:
971  return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
972 
973  // new(unsigned int, nothrow);
974  case LibFunc_ZnwjRKSt9nothrow_t:
975  // new(unsigned long, nothrow);
976  case LibFunc_ZnwmRKSt9nothrow_t:
977  // new[](unsigned int, nothrow);
978  case LibFunc_ZnajRKSt9nothrow_t:
979  // new[](unsigned long, nothrow);
980  case LibFunc_ZnamRKSt9nothrow_t:
981  // new(unsigned int, nothrow);
982  case LibFunc_msvc_new_int_nothrow:
983  // new(unsigned long long, nothrow);
984  case LibFunc_msvc_new_longlong_nothrow:
985  // new[](unsigned int, nothrow);
986  case LibFunc_msvc_new_array_int_nothrow:
987  // new[](unsigned long long, nothrow);
988  case LibFunc_msvc_new_array_longlong_nothrow:
989  return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
990 
991  // void operator delete[](void*);
992  case LibFunc_ZdaPv:
993  // void operator delete(void*);
994  case LibFunc_ZdlPv:
995  // void operator delete[](void*);
996  case LibFunc_msvc_delete_array_ptr32:
997  // void operator delete[](void*);
998  case LibFunc_msvc_delete_array_ptr64:
999  // void operator delete(void*);
1000  case LibFunc_msvc_delete_ptr32:
1001  // void operator delete(void*);
1002  case LibFunc_msvc_delete_ptr64:
1003  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1004 
1005  // void operator delete[](void*, nothrow);
1006  case LibFunc_ZdaPvRKSt9nothrow_t:
1007  // void operator delete[](void*, unsigned int);
1008  case LibFunc_ZdaPvj:
1009  // void operator delete[](void*, unsigned long);
1010  case LibFunc_ZdaPvm:
1011  // void operator delete(void*, nothrow);
1012  case LibFunc_ZdlPvRKSt9nothrow_t:
1013  // void operator delete(void*, unsigned int);
1014  case LibFunc_ZdlPvj:
1015  // void operator delete(void*, unsigned long);
1016  case LibFunc_ZdlPvm:
1017  // void operator delete[](void*, unsigned int);
1018  case LibFunc_msvc_delete_array_ptr32_int:
1019  // void operator delete[](void*, nothrow);
1020  case LibFunc_msvc_delete_array_ptr32_nothrow:
1021  // void operator delete[](void*, unsigned long long);
1022  case LibFunc_msvc_delete_array_ptr64_longlong:
1023  // void operator delete[](void*, nothrow);
1024  case LibFunc_msvc_delete_array_ptr64_nothrow:
1025  // void operator delete(void*, unsigned int);
1026  case LibFunc_msvc_delete_ptr32_int:
1027  // void operator delete(void*, nothrow);
1028  case LibFunc_msvc_delete_ptr32_nothrow:
1029  // void operator delete(void*, unsigned long long);
1030  case LibFunc_msvc_delete_ptr64_longlong:
1031  // void operator delete(void*, nothrow);
1032  case LibFunc_msvc_delete_ptr64_nothrow:
1033  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1034 
1035  case LibFunc_memset_pattern16:
1036  return (!FTy.isVarArg() && NumParams == 3 &&
1037  FTy.getParamType(0)->isPointerTy() &&
1038  FTy.getParamType(1)->isPointerTy() &&
1039  FTy.getParamType(2)->isIntegerTy());
1040 
1041  case LibFunc_cxa_guard_abort:
1042  case LibFunc_cxa_guard_acquire:
1043  case LibFunc_cxa_guard_release:
1044  case LibFunc_nvvm_reflect:
1045  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1046 
1047  case LibFunc_sincospi_stret:
1048  case LibFunc_sincospif_stret:
1049  return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1050 
1051  case LibFunc_acos:
1052  case LibFunc_acos_finite:
1053  case LibFunc_acosf:
1054  case LibFunc_acosf_finite:
1055  case LibFunc_acosh:
1056  case LibFunc_acosh_finite:
1057  case LibFunc_acoshf:
1058  case LibFunc_acoshf_finite:
1059  case LibFunc_acoshl:
1060  case LibFunc_acoshl_finite:
1061  case LibFunc_acosl:
1062  case LibFunc_acosl_finite:
1063  case LibFunc_asin:
1064  case LibFunc_asin_finite:
1065  case LibFunc_asinf:
1066  case LibFunc_asinf_finite:
1067  case LibFunc_asinh:
1068  case LibFunc_asinhf:
1069  case LibFunc_asinhl:
1070  case LibFunc_asinl:
1071  case LibFunc_asinl_finite:
1072  case LibFunc_atan:
1073  case LibFunc_atanf:
1074  case LibFunc_atanh:
1075  case LibFunc_atanh_finite:
1076  case LibFunc_atanhf:
1077  case LibFunc_atanhf_finite:
1078  case LibFunc_atanhl:
1079  case LibFunc_atanhl_finite:
1080  case LibFunc_atanl:
1081  case LibFunc_cbrt:
1082  case LibFunc_cbrtf:
1083  case LibFunc_cbrtl:
1084  case LibFunc_ceil:
1085  case LibFunc_ceilf:
1086  case LibFunc_ceill:
1087  case LibFunc_cos:
1088  case LibFunc_cosf:
1089  case LibFunc_cosh:
1090  case LibFunc_cosh_finite:
1091  case LibFunc_coshf:
1092  case LibFunc_coshf_finite:
1093  case LibFunc_coshl:
1094  case LibFunc_coshl_finite:
1095  case LibFunc_cosl:
1096  case LibFunc_exp10:
1097  case LibFunc_exp10_finite:
1098  case LibFunc_exp10f:
1099  case LibFunc_exp10f_finite:
1100  case LibFunc_exp10l:
1101  case LibFunc_exp10l_finite:
1102  case LibFunc_exp2:
1103  case LibFunc_exp2_finite:
1104  case LibFunc_exp2f:
1105  case LibFunc_exp2f_finite:
1106  case LibFunc_exp2l:
1107  case LibFunc_exp2l_finite:
1108  case LibFunc_exp:
1109  case LibFunc_exp_finite:
1110  case LibFunc_expf:
1111  case LibFunc_expf_finite:
1112  case LibFunc_expl:
1113  case LibFunc_expl_finite:
1114  case LibFunc_expm1:
1115  case LibFunc_expm1f:
1116  case LibFunc_expm1l:
1117  case LibFunc_fabs:
1118  case LibFunc_fabsf:
1119  case LibFunc_fabsl:
1120  case LibFunc_floor:
1121  case LibFunc_floorf:
1122  case LibFunc_floorl:
1123  case LibFunc_log10:
1124  case LibFunc_log10_finite:
1125  case LibFunc_log10f:
1126  case LibFunc_log10f_finite:
1127  case LibFunc_log10l:
1128  case LibFunc_log10l_finite:
1129  case LibFunc_log1p:
1130  case LibFunc_log1pf:
1131  case LibFunc_log1pl:
1132  case LibFunc_log2:
1133  case LibFunc_log2_finite:
1134  case LibFunc_log2f:
1135  case LibFunc_log2f_finite:
1136  case LibFunc_log2l:
1137  case LibFunc_log2l_finite:
1138  case LibFunc_log:
1139  case LibFunc_log_finite:
1140  case LibFunc_logb:
1141  case LibFunc_logbf:
1142  case LibFunc_logbl:
1143  case LibFunc_logf:
1144  case LibFunc_logf_finite:
1145  case LibFunc_logl:
1146  case LibFunc_logl_finite:
1147  case LibFunc_nearbyint:
1148  case LibFunc_nearbyintf:
1149  case LibFunc_nearbyintl:
1150  case LibFunc_rint:
1151  case LibFunc_rintf:
1152  case LibFunc_rintl:
1153  case LibFunc_round:
1154  case LibFunc_roundf:
1155  case LibFunc_roundl:
1156  case LibFunc_sin:
1157  case LibFunc_sinf:
1158  case LibFunc_sinh:
1159  case LibFunc_sinh_finite:
1160  case LibFunc_sinhf:
1161  case LibFunc_sinhf_finite:
1162  case LibFunc_sinhl:
1163  case LibFunc_sinhl_finite:
1164  case LibFunc_sinl:
1165  case LibFunc_sqrt:
1166  case LibFunc_sqrt_finite:
1167  case LibFunc_sqrtf:
1168  case LibFunc_sqrtf_finite:
1169  case LibFunc_sqrtl:
1170  case LibFunc_sqrtl_finite:
1171  case LibFunc_tan:
1172  case LibFunc_tanf:
1173  case LibFunc_tanh:
1174  case LibFunc_tanhf:
1175  case LibFunc_tanhl:
1176  case LibFunc_tanl:
1177  case LibFunc_trunc:
1178  case LibFunc_truncf:
1179  case LibFunc_truncl:
1180  return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1181  FTy.getReturnType() == FTy.getParamType(0));
1182 
1183  case LibFunc_atan2:
1184  case LibFunc_atan2_finite:
1185  case LibFunc_atan2f:
1186  case LibFunc_atan2f_finite:
1187  case LibFunc_atan2l:
1188  case LibFunc_atan2l_finite:
1189  case LibFunc_fmin:
1190  case LibFunc_fminf:
1191  case LibFunc_fminl:
1192  case LibFunc_fmax:
1193  case LibFunc_fmaxf:
1194  case LibFunc_fmaxl:
1195  case LibFunc_fmod:
1196  case LibFunc_fmodf:
1197  case LibFunc_fmodl:
1198  case LibFunc_copysign:
1199  case LibFunc_copysignf:
1200  case LibFunc_copysignl:
1201  case LibFunc_pow:
1202  case LibFunc_pow_finite:
1203  case LibFunc_powf:
1204  case LibFunc_powf_finite:
1205  case LibFunc_powl:
1206  case LibFunc_powl_finite:
1207  return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1208  FTy.getReturnType() == FTy.getParamType(0) &&
1209  FTy.getReturnType() == FTy.getParamType(1));
1210 
1211  case LibFunc_ldexp:
1212  case LibFunc_ldexpf:
1213  case LibFunc_ldexpl:
1214  return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1215  FTy.getReturnType() == FTy.getParamType(0) &&
1216  FTy.getParamType(1)->isIntegerTy(32));
1217 
1218  case LibFunc_ffs:
1219  case LibFunc_ffsl:
1220  case LibFunc_ffsll:
1221  case LibFunc_fls:
1222  case LibFunc_flsl:
1223  case LibFunc_flsll:
1224  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1225  FTy.getParamType(0)->isIntegerTy());
1226 
1227  case LibFunc_isdigit:
1228  case LibFunc_isascii:
1229  case LibFunc_toascii:
1230  case LibFunc_putchar:
1231  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1232  FTy.getReturnType() == FTy.getParamType(0));
1233 
1234  case LibFunc_abs:
1235  case LibFunc_labs:
1236  case LibFunc_llabs:
1237  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1238  FTy.getReturnType() == FTy.getParamType(0));
1239 
1240  case LibFunc_cxa_atexit:
1241  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1242  FTy.getParamType(0)->isPointerTy() &&
1243  FTy.getParamType(1)->isPointerTy() &&
1244  FTy.getParamType(2)->isPointerTy());
1245 
1246  case LibFunc_sinpi:
1247  case LibFunc_cospi:
1248  return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1249  FTy.getReturnType() == FTy.getParamType(0));
1250 
1251  case LibFunc_sinpif:
1252  case LibFunc_cospif:
1253  return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1254  FTy.getReturnType() == FTy.getParamType(0));
1255 
1256  case LibFunc_strnlen:
1257  return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1258  FTy.getParamType(0) == PCharTy &&
1259  FTy.getParamType(1) == SizeTTy);
1260 
1261  case LibFunc_posix_memalign:
1262  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1263  FTy.getParamType(0)->isPointerTy() &&
1264  FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1265 
1266  case LibFunc_wcslen:
1267  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1268  FTy.getReturnType()->isIntegerTy());
1269 
1270  case LibFunc::NumLibFuncs:
1271  break;
1272  }
1273 
1274  llvm_unreachable("Invalid libfunc");
1275 }
1276 
1278  LibFunc &F) const {
1279  const DataLayout *DL =
1280  FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1281  return getLibFunc(FDecl.getName(), F) &&
1282  isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1283 }
1284 
1286  memset(AvailableArray, 0, sizeof(AvailableArray));
1287 }
1288 
1289 static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1290  return LHS.ScalarFnName < RHS.ScalarFnName;
1291 }
1292 
1293 static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1294  return LHS.VectorFnName < RHS.VectorFnName;
1295 }
1296 
1297 static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1298  return LHS.ScalarFnName < S;
1299 }
1300 
1301 static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
1302  return LHS.VectorFnName < S;
1303 }
1304 
1306  VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1307  std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1308 
1309  ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1310  std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1311 }
1312 
1314  enum VectorLibrary VecLib) {
1315  switch (VecLib) {
1316  case Accelerate: {
1317  const VecDesc VecFuncs[] = {
1318  // Floating-Point Arithmetic and Auxiliary Functions
1319  {"ceilf", "vceilf", 4},
1320  {"fabsf", "vfabsf", 4},
1321  {"llvm.fabs.f32", "vfabsf", 4},
1322  {"floorf", "vfloorf", 4},
1323  {"sqrtf", "vsqrtf", 4},
1324  {"llvm.sqrt.f32", "vsqrtf", 4},
1325 
1326  // Exponential and Logarithmic Functions
1327  {"expf", "vexpf", 4},
1328  {"llvm.exp.f32", "vexpf", 4},
1329  {"expm1f", "vexpm1f", 4},
1330  {"logf", "vlogf", 4},
1331  {"llvm.log.f32", "vlogf", 4},
1332  {"log1pf", "vlog1pf", 4},
1333  {"log10f", "vlog10f", 4},
1334  {"llvm.log10.f32", "vlog10f", 4},
1335  {"logbf", "vlogbf", 4},
1336 
1337  // Trigonometric Functions
1338  {"sinf", "vsinf", 4},
1339  {"llvm.sin.f32", "vsinf", 4},
1340  {"cosf", "vcosf", 4},
1341  {"llvm.cos.f32", "vcosf", 4},
1342  {"tanf", "vtanf", 4},
1343  {"asinf", "vasinf", 4},
1344  {"acosf", "vacosf", 4},
1345  {"atanf", "vatanf", 4},
1346 
1347  // Hyperbolic Functions
1348  {"sinhf", "vsinhf", 4},
1349  {"coshf", "vcoshf", 4},
1350  {"tanhf", "vtanhf", 4},
1351  {"asinhf", "vasinhf", 4},
1352  {"acoshf", "vacoshf", 4},
1353  {"atanhf", "vatanhf", 4},
1354  };
1355  addVectorizableFunctions(VecFuncs);
1356  break;
1357  }
1358  case SVML: {
1359  const VecDesc VecFuncs[] = {
1360  {"sin", "__svml_sin2", 2},
1361  {"sin", "__svml_sin4", 4},
1362  {"sin", "__svml_sin8", 8},
1363 
1364  {"sinf", "__svml_sinf4", 4},
1365  {"sinf", "__svml_sinf8", 8},
1366  {"sinf", "__svml_sinf16", 16},
1367 
1368  {"cos", "__svml_cos2", 2},
1369  {"cos", "__svml_cos4", 4},
1370  {"cos", "__svml_cos8", 8},
1371 
1372  {"cosf", "__svml_cosf4", 4},
1373  {"cosf", "__svml_cosf8", 8},
1374  {"cosf", "__svml_cosf16", 16},
1375 
1376  {"pow", "__svml_pow2", 2},
1377  {"pow", "__svml_pow4", 4},
1378  {"pow", "__svml_pow8", 8},
1379 
1380  {"powf", "__svml_powf4", 4},
1381  {"powf", "__svml_powf8", 8},
1382  {"powf", "__svml_powf16", 16},
1383 
1384  { "__pow_finite", "__svml_pow2", 2 },
1385  { "__pow_finite", "__svml_pow4", 4 },
1386  { "__pow_finite", "__svml_pow8", 8 },
1387 
1388  { "__powf_finite", "__svml_powf4", 4 },
1389  { "__powf_finite", "__svml_powf8", 8 },
1390  { "__powf_finite", "__svml_powf16", 16 },
1391 
1392  {"llvm.pow.f64", "__svml_pow2", 2},
1393  {"llvm.pow.f64", "__svml_pow4", 4},
1394  {"llvm.pow.f64", "__svml_pow8", 8},
1395 
1396  {"llvm.pow.f32", "__svml_powf4", 4},
1397  {"llvm.pow.f32", "__svml_powf8", 8},
1398  {"llvm.pow.f32", "__svml_powf16", 16},
1399 
1400  {"exp", "__svml_exp2", 2},
1401  {"exp", "__svml_exp4", 4},
1402  {"exp", "__svml_exp8", 8},
1403 
1404  {"expf", "__svml_expf4", 4},
1405  {"expf", "__svml_expf8", 8},
1406  {"expf", "__svml_expf16", 16},
1407 
1408  { "__exp_finite", "__svml_exp2", 2 },
1409  { "__exp_finite", "__svml_exp4", 4 },
1410  { "__exp_finite", "__svml_exp8", 8 },
1411 
1412  { "__expf_finite", "__svml_expf4", 4 },
1413  { "__expf_finite", "__svml_expf8", 8 },
1414  { "__expf_finite", "__svml_expf16", 16 },
1415 
1416  {"llvm.exp.f64", "__svml_exp2", 2},
1417  {"llvm.exp.f64", "__svml_exp4", 4},
1418  {"llvm.exp.f64", "__svml_exp8", 8},
1419 
1420  {"llvm.exp.f32", "__svml_expf4", 4},
1421  {"llvm.exp.f32", "__svml_expf8", 8},
1422  {"llvm.exp.f32", "__svml_expf16", 16},
1423 
1424  {"log", "__svml_log2", 2},
1425  {"log", "__svml_log4", 4},
1426  {"log", "__svml_log8", 8},
1427 
1428  {"logf", "__svml_logf4", 4},
1429  {"logf", "__svml_logf8", 8},
1430  {"logf", "__svml_logf16", 16},
1431 
1432  { "__log_finite", "__svml_log2", 2 },
1433  { "__log_finite", "__svml_log4", 4 },
1434  { "__log_finite", "__svml_log8", 8 },
1435 
1436  { "__logf_finite", "__svml_logf4", 4 },
1437  { "__logf_finite", "__svml_logf8", 8 },
1438  { "__logf_finite", "__svml_logf16", 16 },
1439 
1440  {"llvm.log.f64", "__svml_log2", 2},
1441  {"llvm.log.f64", "__svml_log4", 4},
1442  {"llvm.log.f64", "__svml_log8", 8},
1443 
1444  {"llvm.log.f32", "__svml_logf4", 4},
1445  {"llvm.log.f32", "__svml_logf8", 8},
1446  {"llvm.log.f32", "__svml_logf16", 16},
1447  };
1448  addVectorizableFunctions(VecFuncs);
1449  break;
1450  }
1451  case NoLibrary:
1452  break;
1453  }
1454 }
1455 
1457  funcName = sanitizeFunctionName(funcName);
1458  if (funcName.empty())
1459  return false;
1460 
1461  std::vector<VecDesc>::const_iterator I = std::lower_bound(
1462  VectorDescs.begin(), VectorDescs.end(), funcName,
1464  return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1465 }
1466 
1468  unsigned VF) const {
1469  F = sanitizeFunctionName(F);
1470  if (F.empty())
1471  return F;
1472  std::vector<VecDesc>::const_iterator I = std::lower_bound(
1473  VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1474  while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1475  if (I->VectorizationFactor == VF)
1476  return I->VectorFnName;
1477  ++I;
1478  }
1479  return StringRef();
1480 }
1481 
1483  unsigned &VF) const {
1484  F = sanitizeFunctionName(F);
1485  if (F.empty())
1486  return F;
1487 
1488  std::vector<VecDesc>::const_iterator I = std::lower_bound(
1489  ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1490  if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1491  return StringRef();
1492  VF = I->VectorizationFactor;
1493  return I->ScalarFnName;
1494 }
1495 
1498  if (PresetInfoImpl)
1499  return TargetLibraryInfo(*PresetInfoImpl);
1500 
1501  return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1502 }
1503 
1506  if (PresetInfoImpl)
1507  return TargetLibraryInfo(*PresetInfoImpl);
1508 
1509  return TargetLibraryInfo(
1510  lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1511 }
1512 
1513 TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
1514  std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1515  Impls[T.normalize()];
1516  if (!Impl)
1517  Impl.reset(new TargetLibraryInfoImpl(T));
1518 
1519  return *Impl;
1520 }
1521 
1523  if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1524  M.getModuleFlag("wchar_size")))
1525  return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1526  return 0;
1527 }
1528 
1530  : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
1532 }
1533 
1535  : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
1537 }
1538 
1540  const TargetLibraryInfoImpl &TLIImpl)
1541  : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
1543 }
1544 
1545 AnalysisKey TargetLibraryAnalysis::Key;
1546 
1547 // Register the basic pass.
1549  "Target Library Information", false, true)
1551 
1552 void TargetLibraryInfoWrapperPass::anchor() {}
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:470
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:244
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:233
static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS)
static std::string normalize(StringRef Str)
normalize - Turn an arbitrary machine specification into the canonical triple form (or something sens...
Definition: Triple.cpp:751
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:235
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:442
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
iterator begin() const
Definition: ArrayRef.h:137
static StringRef sanitizeFunctionName(StringRef funcName)
VectorLibrary
List of known vector-functions libraries.
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:294
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
StringRef VectorFnName
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
void disableAllFunctions()
Disables all builtins.
bool isWatchOS() const
Is this an Apple watchOS triple.
Definition: Triple.h:461
Implementation of the target library information.
F(f)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
StringRef ScalarFnName
Definition: BitVector.h:920
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:361
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:162
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
Class to represent function types.
Definition: DerivedTypes.h:103
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:285
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool isVarArg() const
Definition: DerivedTypes.h:123
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:451
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
TargetLibraryInfo run(Module &M, ModuleAnalysisManager &)
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:562
bool isFloatTy() const
Return true if this is &#39;float&#39;, a 32-bit IEEE fp type.
Definition: Type.h:147
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:702
StringRef getScalarizedFunction(StringRef F, unsigned &VF) const
Return the name of the equivalent of F, scalarized.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:406
bool isFunctionVectorizable(StringRef F, unsigned VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:302
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:626
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:139
static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS)
static const unsigned End
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
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::SVML, "SVML", "Intel SVML library")))
static bool hasSinCosPiStret(const Triple &T)
ImmutablePass class - This class is used to provide information that does not need to be run...
Definition: Pass.h:256
Describes a possible vectorization of a function.
Provides information about what library functions are available for the current target.
StringRef getVectorizedFunction(StringRef F, unsigned VF) const
Return the name of the equivalent of F, vectorized with factor VF.
iterator end() const
Definition: ArrayRef.h:138
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:572
TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
Type * getReturnType() const
Definition: DerivedTypes.h:124
bool isOSFreeBSD() const
Definition: Triple.h:486
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:145
void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib)
Calls addVectorizableFunctions with a known preset of functions for the given vector library...
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character &#39;\1&#39;, drop it.
Definition: GlobalValue.h:462
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringRef > StandardNames)
initialize - Initialize the set of available library functions based on the specified target triple...
bool isOSCygMing() const
Tests for either Cygwin or MinGW OS.
Definition: Triple.h:551
auto lower_bound(R &&Range, ForwardIt I) -> decltype(std::begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:859
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:601
static const size_t npos
Definition: StringRef.h:51
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:220
#define I(x, y, z)
Definition: MD5.cpp:58
static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S)
bool isMacOSXVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
isMacOSXVersionLT - Comparison function for checking OS X version compatibility, which handles suppor...
Definition: Triple.h:427
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:556
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition: Triple.h:644
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A container for analyses that lazily runs them and caches their results.
bool isOSVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
isOSVersionLT - Helper function for doing comparisons against version numbers included in the target ...
Definition: Triple.h:403
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
Definition: Parallel.h:199
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:298
void setAvailable(LibFunc F)
Forces a function to be marked as available.
bool isDoubleTy() const
Return true if this is &#39;double&#39;, a 64-bit IEEE fp type.
Definition: Type.h:150
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S)