LLVM  7.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 the set of available library functions based on the specified
54 /// target triple. This should be carefully written so that a missing target
55 /// 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_cabs);
186  TLI.setUnavailable(LibFunc_cabsf);
187  TLI.setUnavailable(LibFunc_cabsl);
188  TLI.setUnavailable(LibFunc_cbrt);
189  TLI.setUnavailable(LibFunc_cbrtf);
190  TLI.setUnavailable(LibFunc_cbrtl);
191  TLI.setUnavailable(LibFunc_exp2);
192  TLI.setUnavailable(LibFunc_exp2f);
193  TLI.setUnavailable(LibFunc_exp2l);
194  TLI.setUnavailable(LibFunc_expm1);
195  TLI.setUnavailable(LibFunc_expm1f);
196  TLI.setUnavailable(LibFunc_expm1l);
197  TLI.setUnavailable(LibFunc_log2);
198  TLI.setUnavailable(LibFunc_log2f);
199  TLI.setUnavailable(LibFunc_log2l);
200  TLI.setUnavailable(LibFunc_log1p);
201  TLI.setUnavailable(LibFunc_log1pf);
202  TLI.setUnavailable(LibFunc_log1pl);
203  TLI.setUnavailable(LibFunc_logb);
204  TLI.setUnavailable(LibFunc_logbf);
205  TLI.setUnavailable(LibFunc_logbl);
206  TLI.setUnavailable(LibFunc_nearbyint);
207  TLI.setUnavailable(LibFunc_nearbyintf);
208  TLI.setUnavailable(LibFunc_nearbyintl);
209  TLI.setUnavailable(LibFunc_rint);
210  TLI.setUnavailable(LibFunc_rintf);
211  TLI.setUnavailable(LibFunc_rintl);
212  TLI.setUnavailable(LibFunc_round);
213  TLI.setUnavailable(LibFunc_roundf);
214  TLI.setUnavailable(LibFunc_roundl);
215  TLI.setUnavailable(LibFunc_trunc);
216  TLI.setUnavailable(LibFunc_truncf);
217  TLI.setUnavailable(LibFunc_truncl);
218 
219  // Win32 provides some C99 math with mangled names
220  TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
221 
222  if (T.getArch() == Triple::x86) {
223  // Win32 on x86 implements single-precision math functions as macros
224  TLI.setUnavailable(LibFunc_acosf);
225  TLI.setUnavailable(LibFunc_asinf);
226  TLI.setUnavailable(LibFunc_atanf);
227  TLI.setUnavailable(LibFunc_atan2f);
228  TLI.setUnavailable(LibFunc_ceilf);
229  TLI.setUnavailable(LibFunc_copysignf);
230  TLI.setUnavailable(LibFunc_cosf);
231  TLI.setUnavailable(LibFunc_coshf);
232  TLI.setUnavailable(LibFunc_expf);
233  TLI.setUnavailable(LibFunc_floorf);
234  TLI.setUnavailable(LibFunc_fminf);
235  TLI.setUnavailable(LibFunc_fmaxf);
236  TLI.setUnavailable(LibFunc_fmodf);
237  TLI.setUnavailable(LibFunc_logf);
238  TLI.setUnavailable(LibFunc_log10f);
239  TLI.setUnavailable(LibFunc_modff);
240  TLI.setUnavailable(LibFunc_powf);
241  TLI.setUnavailable(LibFunc_sinf);
242  TLI.setUnavailable(LibFunc_sinhf);
243  TLI.setUnavailable(LibFunc_sqrtf);
244  TLI.setUnavailable(LibFunc_tanf);
245  TLI.setUnavailable(LibFunc_tanhf);
246  }
247 
248  // Win32 does *not* provide these functions, but they are
249  // generally available on POSIX-compliant systems:
250  TLI.setUnavailable(LibFunc_access);
251  TLI.setUnavailable(LibFunc_bcmp);
252  TLI.setUnavailable(LibFunc_bcopy);
253  TLI.setUnavailable(LibFunc_bzero);
254  TLI.setUnavailable(LibFunc_chmod);
255  TLI.setUnavailable(LibFunc_chown);
256  TLI.setUnavailable(LibFunc_closedir);
257  TLI.setUnavailable(LibFunc_ctermid);
258  TLI.setUnavailable(LibFunc_fdopen);
259  TLI.setUnavailable(LibFunc_ffs);
260  TLI.setUnavailable(LibFunc_fileno);
261  TLI.setUnavailable(LibFunc_flockfile);
262  TLI.setUnavailable(LibFunc_fseeko);
263  TLI.setUnavailable(LibFunc_fstat);
264  TLI.setUnavailable(LibFunc_fstatvfs);
265  TLI.setUnavailable(LibFunc_ftello);
266  TLI.setUnavailable(LibFunc_ftrylockfile);
267  TLI.setUnavailable(LibFunc_funlockfile);
268  TLI.setUnavailable(LibFunc_getc_unlocked);
269  TLI.setUnavailable(LibFunc_getitimer);
270  TLI.setUnavailable(LibFunc_getlogin_r);
271  TLI.setUnavailable(LibFunc_getpwnam);
272  TLI.setUnavailable(LibFunc_gettimeofday);
273  TLI.setUnavailable(LibFunc_htonl);
274  TLI.setUnavailable(LibFunc_htons);
275  TLI.setUnavailable(LibFunc_lchown);
276  TLI.setUnavailable(LibFunc_lstat);
277  TLI.setUnavailable(LibFunc_memccpy);
278  TLI.setUnavailable(LibFunc_mkdir);
279  TLI.setUnavailable(LibFunc_ntohl);
280  TLI.setUnavailable(LibFunc_ntohs);
281  TLI.setUnavailable(LibFunc_open);
282  TLI.setUnavailable(LibFunc_opendir);
283  TLI.setUnavailable(LibFunc_pclose);
284  TLI.setUnavailable(LibFunc_popen);
285  TLI.setUnavailable(LibFunc_pread);
286  TLI.setUnavailable(LibFunc_pwrite);
287  TLI.setUnavailable(LibFunc_read);
288  TLI.setUnavailable(LibFunc_readlink);
289  TLI.setUnavailable(LibFunc_realpath);
290  TLI.setUnavailable(LibFunc_rmdir);
291  TLI.setUnavailable(LibFunc_setitimer);
292  TLI.setUnavailable(LibFunc_stat);
293  TLI.setUnavailable(LibFunc_statvfs);
294  TLI.setUnavailable(LibFunc_stpcpy);
295  TLI.setUnavailable(LibFunc_stpncpy);
296  TLI.setUnavailable(LibFunc_strcasecmp);
297  TLI.setUnavailable(LibFunc_strncasecmp);
298  TLI.setUnavailable(LibFunc_times);
299  TLI.setUnavailable(LibFunc_uname);
300  TLI.setUnavailable(LibFunc_unlink);
301  TLI.setUnavailable(LibFunc_unsetenv);
302  TLI.setUnavailable(LibFunc_utime);
303  TLI.setUnavailable(LibFunc_utimes);
304  TLI.setUnavailable(LibFunc_write);
305 
306  // Win32 does *not* provide provide these functions, but they are
307  // specified by C99:
308  TLI.setUnavailable(LibFunc_atoll);
309  TLI.setUnavailable(LibFunc_frexpf);
310  TLI.setUnavailable(LibFunc_llabs);
311  }
312 
313  switch (T.getOS()) {
314  case Triple::MacOSX:
315  // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
316  // and their names are __exp10 and __exp10f. exp10l is not available on
317  // OS X or iOS.
318  TLI.setUnavailable(LibFunc_exp10l);
319  if (T.isMacOSXVersionLT(10, 9)) {
320  TLI.setUnavailable(LibFunc_exp10);
321  TLI.setUnavailable(LibFunc_exp10f);
322  } else {
323  TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
324  TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
325  }
326  break;
327  case Triple::IOS:
328  case Triple::TvOS:
329  case Triple::WatchOS:
330  TLI.setUnavailable(LibFunc_exp10l);
331  if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
332  (T.isOSVersionLT(9, 0) &&
333  (T.getArch() == Triple::x86 ||
334  T.getArch() == Triple::x86_64)))) {
335  TLI.setUnavailable(LibFunc_exp10);
336  TLI.setUnavailable(LibFunc_exp10f);
337  } else {
338  TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
339  TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
340  }
341  break;
342  case Triple::Linux:
343  // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
344  // buggy prior to glibc version 2.18. Until this version is widely deployed
345  // or we have a reasonable detection strategy, we cannot use exp10 reliably
346  // on Linux.
347  //
348  // Fall through to disable all of them.
350  default:
351  TLI.setUnavailable(LibFunc_exp10);
352  TLI.setUnavailable(LibFunc_exp10f);
353  TLI.setUnavailable(LibFunc_exp10l);
354  }
355 
356  // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
357  // Linux (GLIBC):
358  // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
359  // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
360  // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
361  switch (T.getOS()) {
362  case Triple::Darwin:
363  case Triple::MacOSX:
364  case Triple::IOS:
365  case Triple::TvOS:
366  case Triple::WatchOS:
367  case Triple::FreeBSD:
368  case Triple::Linux:
369  break;
370  default:
371  TLI.setUnavailable(LibFunc_ffsl);
372  }
373 
374  // ffsll is available on at least FreeBSD and Linux (GLIBC):
375  // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
376  // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
377  switch (T.getOS()) {
378  case Triple::Darwin:
379  case Triple::MacOSX:
380  case Triple::IOS:
381  case Triple::TvOS:
382  case Triple::WatchOS:
383  case Triple::FreeBSD:
384  case Triple::Linux:
385  break;
386  default:
387  TLI.setUnavailable(LibFunc_ffsll);
388  }
389 
390  // The following functions are available on at least FreeBSD:
391  // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
392  // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
393  // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
394  if (!T.isOSFreeBSD()) {
395  TLI.setUnavailable(LibFunc_fls);
396  TLI.setUnavailable(LibFunc_flsl);
397  TLI.setUnavailable(LibFunc_flsll);
398  }
399 
400  // The following functions are available on Linux,
401  // but Android uses bionic instead of glibc.
402  if (!T.isOSLinux() || T.isAndroid()) {
403  TLI.setUnavailable(LibFunc_dunder_strdup);
404  TLI.setUnavailable(LibFunc_dunder_strtok_r);
405  TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
406  TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
407  TLI.setUnavailable(LibFunc_under_IO_getc);
408  TLI.setUnavailable(LibFunc_under_IO_putc);
409  // But, Android has memalign.
410  if (!T.isAndroid())
411  TLI.setUnavailable(LibFunc_memalign);
412  TLI.setUnavailable(LibFunc_fopen64);
413  TLI.setUnavailable(LibFunc_fseeko64);
414  TLI.setUnavailable(LibFunc_fstat64);
415  TLI.setUnavailable(LibFunc_fstatvfs64);
416  TLI.setUnavailable(LibFunc_ftello64);
417  TLI.setUnavailable(LibFunc_lstat64);
418  TLI.setUnavailable(LibFunc_open64);
419  TLI.setUnavailable(LibFunc_stat64);
420  TLI.setUnavailable(LibFunc_statvfs64);
421  TLI.setUnavailable(LibFunc_tmpfile64);
422 
423  // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
424  TLI.setUnavailable(LibFunc_acos_finite);
425  TLI.setUnavailable(LibFunc_acosf_finite);
426  TLI.setUnavailable(LibFunc_acosl_finite);
427  TLI.setUnavailable(LibFunc_acosh_finite);
428  TLI.setUnavailable(LibFunc_acoshf_finite);
429  TLI.setUnavailable(LibFunc_acoshl_finite);
430  TLI.setUnavailable(LibFunc_asin_finite);
431  TLI.setUnavailable(LibFunc_asinf_finite);
432  TLI.setUnavailable(LibFunc_asinl_finite);
433  TLI.setUnavailable(LibFunc_atan2_finite);
434  TLI.setUnavailable(LibFunc_atan2f_finite);
435  TLI.setUnavailable(LibFunc_atan2l_finite);
436  TLI.setUnavailable(LibFunc_atanh_finite);
437  TLI.setUnavailable(LibFunc_atanhf_finite);
438  TLI.setUnavailable(LibFunc_atanhl_finite);
439  TLI.setUnavailable(LibFunc_cosh_finite);
440  TLI.setUnavailable(LibFunc_coshf_finite);
441  TLI.setUnavailable(LibFunc_coshl_finite);
442  TLI.setUnavailable(LibFunc_exp10_finite);
443  TLI.setUnavailable(LibFunc_exp10f_finite);
444  TLI.setUnavailable(LibFunc_exp10l_finite);
445  TLI.setUnavailable(LibFunc_exp2_finite);
446  TLI.setUnavailable(LibFunc_exp2f_finite);
447  TLI.setUnavailable(LibFunc_exp2l_finite);
448  TLI.setUnavailable(LibFunc_exp_finite);
449  TLI.setUnavailable(LibFunc_expf_finite);
450  TLI.setUnavailable(LibFunc_expl_finite);
451  TLI.setUnavailable(LibFunc_log10_finite);
452  TLI.setUnavailable(LibFunc_log10f_finite);
453  TLI.setUnavailable(LibFunc_log10l_finite);
454  TLI.setUnavailable(LibFunc_log2_finite);
455  TLI.setUnavailable(LibFunc_log2f_finite);
456  TLI.setUnavailable(LibFunc_log2l_finite);
457  TLI.setUnavailable(LibFunc_log_finite);
458  TLI.setUnavailable(LibFunc_logf_finite);
459  TLI.setUnavailable(LibFunc_logl_finite);
460  TLI.setUnavailable(LibFunc_pow_finite);
461  TLI.setUnavailable(LibFunc_powf_finite);
462  TLI.setUnavailable(LibFunc_powl_finite);
463  TLI.setUnavailable(LibFunc_sinh_finite);
464  TLI.setUnavailable(LibFunc_sinhf_finite);
465  TLI.setUnavailable(LibFunc_sinhl_finite);
466  }
467 
468  // As currently implemented in clang, NVPTX code has no standard library to
469  // speak of. Headers provide a standard-ish library implementation, but many
470  // of the signatures are wrong -- for example, many libm functions are not
471  // extern "C".
472  //
473  // libdevice, an IR library provided by nvidia, is linked in by the front-end,
474  // but only used functions are provided to llvm. Moreover, most of the
475  // functions in libdevice don't map precisely to standard library functions.
476  //
477  // FIXME: Having no standard library prevents e.g. many fastmath
478  // optimizations, so this situation should be fixed.
479  if (T.isNVPTX()) {
480  TLI.disableAllFunctions();
481  TLI.setAvailable(LibFunc_nvvm_reflect);
482  } else {
483  TLI.setUnavailable(LibFunc_nvvm_reflect);
484  }
485 
487 }
488 
490  // Default to everything being available.
491  memset(AvailableArray, -1, sizeof(AvailableArray));
492 
493  initialize(*this, Triple(), StandardNames);
494 }
495 
497  // Default to everything being available.
498  memset(AvailableArray, -1, sizeof(AvailableArray));
499 
500  initialize(*this, T, StandardNames);
501 }
502 
504  : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
505  ShouldExtI32Return(TLI.ShouldExtI32Return),
506  ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
507  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
508  VectorDescs = TLI.VectorDescs;
509  ScalarDescs = TLI.ScalarDescs;
510 }
511 
513  : CustomNames(std::move(TLI.CustomNames)),
514  ShouldExtI32Param(TLI.ShouldExtI32Param),
515  ShouldExtI32Return(TLI.ShouldExtI32Return),
516  ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
517  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
518  AvailableArray);
519  VectorDescs = TLI.VectorDescs;
520  ScalarDescs = TLI.ScalarDescs;
521 }
522 
524  CustomNames = TLI.CustomNames;
525  ShouldExtI32Param = TLI.ShouldExtI32Param;
526  ShouldExtI32Return = TLI.ShouldExtI32Return;
527  ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
528  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
529  return *this;
530 }
531 
533  CustomNames = std::move(TLI.CustomNames);
534  ShouldExtI32Param = TLI.ShouldExtI32Param;
535  ShouldExtI32Return = TLI.ShouldExtI32Return;
536  ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
537  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
538  AvailableArray);
539  return *this;
540 }
541 
543  // Filter out empty names and names containing null bytes, those can't be in
544  // our table.
545  if (funcName.empty() || funcName.find('\0') != StringRef::npos)
546  return StringRef();
547 
548  // Check for \01 prefix that is used to mangle __asm declarations and
549  // strip it if present.
550  return GlobalValue::dropLLVMManglingEscape(funcName);
551 }
552 
554  LibFunc &F) const {
555  StringRef const *Start = &StandardNames[0];
556  StringRef const *End = &StandardNames[NumLibFuncs];
557 
558  funcName = sanitizeFunctionName(funcName);
559  if (funcName.empty())
560  return false;
561 
562  StringRef const *I = std::lower_bound(
563  Start, End, funcName, [](StringRef LHS, StringRef RHS) {
564  return LHS < RHS;
565  });
566  if (I != End && *I == funcName) {
567  F = (LibFunc)(I - Start);
568  return true;
569  }
570  return false;
571 }
572 
573 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
574  LibFunc F,
575  const DataLayout *DL) const {
576  LLVMContext &Ctx = FTy.getContext();
577  Type *PCharTy = Type::getInt8PtrTy(Ctx);
578  Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
579  auto IsSizeTTy = [SizeTTy](Type *Ty) {
580  return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
581  };
582  unsigned NumParams = FTy.getNumParams();
583 
584  switch (F) {
585  case LibFunc_strlen:
586  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
587  FTy.getReturnType()->isIntegerTy());
588 
589  case LibFunc_strchr:
590  case LibFunc_strrchr:
591  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
592  FTy.getParamType(0) == FTy.getReturnType() &&
593  FTy.getParamType(1)->isIntegerTy());
594 
595  case LibFunc_strtol:
596  case LibFunc_strtod:
597  case LibFunc_strtof:
598  case LibFunc_strtoul:
599  case LibFunc_strtoll:
600  case LibFunc_strtold:
601  case LibFunc_strtoull:
602  return ((NumParams == 2 || NumParams == 3) &&
603  FTy.getParamType(0)->isPointerTy() &&
604  FTy.getParamType(1)->isPointerTy());
605  case LibFunc_strcat:
606  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
607  FTy.getParamType(0) == FTy.getReturnType() &&
608  FTy.getParamType(1) == FTy.getReturnType());
609 
610  case LibFunc_strncat:
611  return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
612  FTy.getParamType(0) == FTy.getReturnType() &&
613  FTy.getParamType(1) == FTy.getReturnType() &&
614  IsSizeTTy(FTy.getParamType(2)));
615 
616  case LibFunc_strcpy_chk:
617  case LibFunc_stpcpy_chk:
618  --NumParams;
619  if (!IsSizeTTy(FTy.getParamType(NumParams)))
620  return false;
622  case LibFunc_strcpy:
623  case LibFunc_stpcpy:
624  return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
625  FTy.getParamType(0) == FTy.getParamType(1) &&
626  FTy.getParamType(0) == PCharTy);
627 
628  case LibFunc_strncpy_chk:
629  case LibFunc_stpncpy_chk:
630  --NumParams;
631  if (!IsSizeTTy(FTy.getParamType(NumParams)))
632  return false;
634  case LibFunc_strncpy:
635  case LibFunc_stpncpy:
636  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
637  FTy.getParamType(0) == FTy.getParamType(1) &&
638  FTy.getParamType(0) == PCharTy &&
639  IsSizeTTy(FTy.getParamType(2)));
640 
641  case LibFunc_strxfrm:
642  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
643  FTy.getParamType(1)->isPointerTy());
644 
645  case LibFunc_strcmp:
646  return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
647  FTy.getParamType(0)->isPointerTy() &&
648  FTy.getParamType(0) == FTy.getParamType(1));
649 
650  case LibFunc_strncmp:
651  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
652  FTy.getParamType(0)->isPointerTy() &&
653  FTy.getParamType(0) == FTy.getParamType(1) &&
654  IsSizeTTy(FTy.getParamType(2)));
655 
656  case LibFunc_strspn:
657  case LibFunc_strcspn:
658  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
659  FTy.getParamType(0) == FTy.getParamType(1) &&
660  FTy.getReturnType()->isIntegerTy());
661 
662  case LibFunc_strcoll:
663  case LibFunc_strcasecmp:
664  case LibFunc_strncasecmp:
665  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
666  FTy.getParamType(1)->isPointerTy());
667 
668  case LibFunc_strstr:
669  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
670  FTy.getParamType(0)->isPointerTy() &&
671  FTy.getParamType(1)->isPointerTy());
672 
673  case LibFunc_strpbrk:
674  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
675  FTy.getReturnType() == FTy.getParamType(0) &&
676  FTy.getParamType(0) == FTy.getParamType(1));
677 
678  case LibFunc_strtok:
679  case LibFunc_strtok_r:
680  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
681  case LibFunc_scanf:
682  case LibFunc_setbuf:
683  case LibFunc_setvbuf:
684  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
685  case LibFunc_strdup:
686  case LibFunc_strndup:
687  return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
688  FTy.getParamType(0)->isPointerTy());
689  case LibFunc_sscanf:
690  case LibFunc_stat:
691  case LibFunc_statvfs:
692  case LibFunc_siprintf:
693  case LibFunc_sprintf:
694  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
695  FTy.getParamType(1)->isPointerTy());
696  case LibFunc_snprintf:
697  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
698  FTy.getParamType(2)->isPointerTy());
699  case LibFunc_setitimer:
700  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
701  FTy.getParamType(2)->isPointerTy());
702  case LibFunc_system:
703  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
704  case LibFunc_malloc:
705  return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
706  case LibFunc_memcmp:
707  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
708  FTy.getParamType(0)->isPointerTy() &&
709  FTy.getParamType(1)->isPointerTy());
710 
711  case LibFunc_memchr:
712  case LibFunc_memrchr:
713  return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
714  FTy.getReturnType() == FTy.getParamType(0) &&
715  FTy.getParamType(1)->isIntegerTy(32) &&
716  IsSizeTTy(FTy.getParamType(2)));
717  case LibFunc_modf:
718  case LibFunc_modff:
719  case LibFunc_modfl:
720  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
721 
722  case LibFunc_memcpy_chk:
723  case LibFunc_memmove_chk:
724  --NumParams;
725  if (!IsSizeTTy(FTy.getParamType(NumParams)))
726  return false;
728  case LibFunc_memcpy:
729  case LibFunc_mempcpy:
730  case LibFunc_memmove:
731  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
732  FTy.getParamType(0)->isPointerTy() &&
733  FTy.getParamType(1)->isPointerTy() &&
734  IsSizeTTy(FTy.getParamType(2)));
735 
736  case LibFunc_memset_chk:
737  --NumParams;
738  if (!IsSizeTTy(FTy.getParamType(NumParams)))
739  return false;
741  case LibFunc_memset:
742  return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
743  FTy.getParamType(0)->isPointerTy() &&
744  FTy.getParamType(1)->isIntegerTy() &&
745  IsSizeTTy(FTy.getParamType(2)));
746 
747  case LibFunc_memccpy:
748  return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
749  case LibFunc_memalign:
750  return (FTy.getReturnType()->isPointerTy());
751  case LibFunc_realloc:
752  case LibFunc_reallocf:
753  return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
754  FTy.getParamType(0) == FTy.getReturnType() &&
755  IsSizeTTy(FTy.getParamType(1)));
756  case LibFunc_read:
757  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
758  case LibFunc_rewind:
759  case LibFunc_rmdir:
760  case LibFunc_remove:
761  case LibFunc_realpath:
762  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
763  case LibFunc_rename:
764  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
765  FTy.getParamType(1)->isPointerTy());
766  case LibFunc_readlink:
767  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
768  FTy.getParamType(1)->isPointerTy());
769  case LibFunc_write:
770  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
771  case LibFunc_bcopy:
772  case LibFunc_bcmp:
773  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
774  FTy.getParamType(1)->isPointerTy());
775  case LibFunc_bzero:
776  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
777  case LibFunc_calloc:
778  return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
779 
780  case LibFunc_atof:
781  case LibFunc_atoi:
782  case LibFunc_atol:
783  case LibFunc_atoll:
784  case LibFunc_ferror:
785  case LibFunc_getenv:
786  case LibFunc_getpwnam:
787  case LibFunc_iprintf:
788  case LibFunc_pclose:
789  case LibFunc_perror:
790  case LibFunc_printf:
791  case LibFunc_puts:
792  case LibFunc_uname:
793  case LibFunc_under_IO_getc:
794  case LibFunc_unlink:
795  case LibFunc_unsetenv:
796  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
797 
798  case LibFunc_access:
799  case LibFunc_chmod:
800  case LibFunc_chown:
801  case LibFunc_clearerr:
802  case LibFunc_closedir:
803  case LibFunc_ctermid:
804  case LibFunc_fclose:
805  case LibFunc_feof:
806  case LibFunc_fflush:
807  case LibFunc_fgetc:
808  case LibFunc_fileno:
809  case LibFunc_flockfile:
810  case LibFunc_free:
811  case LibFunc_fseek:
812  case LibFunc_fseeko64:
813  case LibFunc_fseeko:
814  case LibFunc_fsetpos:
815  case LibFunc_ftell:
816  case LibFunc_ftello64:
817  case LibFunc_ftello:
818  case LibFunc_ftrylockfile:
819  case LibFunc_funlockfile:
820  case LibFunc_getc:
821  case LibFunc_getc_unlocked:
822  case LibFunc_getlogin_r:
823  case LibFunc_mkdir:
824  case LibFunc_mktime:
825  case LibFunc_times:
826  return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
827 
828  case LibFunc_fopen:
829  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
830  FTy.getParamType(0)->isPointerTy() &&
831  FTy.getParamType(1)->isPointerTy());
832  case LibFunc_fdopen:
833  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
834  FTy.getParamType(1)->isPointerTy());
835  case LibFunc_fputc:
836  case LibFunc_fstat:
837  case LibFunc_frexp:
838  case LibFunc_frexpf:
839  case LibFunc_frexpl:
840  case LibFunc_fstatvfs:
841  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
842  case LibFunc_fgets:
843  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
844  FTy.getParamType(2)->isPointerTy());
845  case LibFunc_fread:
846  return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
847  FTy.getParamType(3)->isPointerTy());
848  case LibFunc_fwrite:
849  return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
850  FTy.getParamType(0)->isPointerTy() &&
851  FTy.getParamType(1)->isIntegerTy() &&
852  FTy.getParamType(2)->isIntegerTy() &&
853  FTy.getParamType(3)->isPointerTy());
854  case LibFunc_fputs:
855  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
856  FTy.getParamType(1)->isPointerTy());
857  case LibFunc_fscanf:
858  case LibFunc_fiprintf:
859  case LibFunc_fprintf:
860  return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
861  FTy.getParamType(0)->isPointerTy() &&
862  FTy.getParamType(1)->isPointerTy());
863  case LibFunc_fgetpos:
864  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
865  FTy.getParamType(1)->isPointerTy());
866  case LibFunc_getchar:
867  return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
868  case LibFunc_gets:
869  return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
870  case LibFunc_getitimer:
871  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
872  case LibFunc_ungetc:
873  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
874  case LibFunc_utime:
875  case LibFunc_utimes:
876  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
877  FTy.getParamType(1)->isPointerTy());
878  case LibFunc_putc:
879  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
880  case LibFunc_pread:
881  case LibFunc_pwrite:
882  return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
883  case LibFunc_popen:
884  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
885  FTy.getParamType(0)->isPointerTy() &&
886  FTy.getParamType(1)->isPointerTy());
887  case LibFunc_vscanf:
888  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
889  case LibFunc_vsscanf:
890  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
891  FTy.getParamType(2)->isPointerTy());
892  case LibFunc_vfscanf:
893  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
894  FTy.getParamType(2)->isPointerTy());
895  case LibFunc_valloc:
896  return (FTy.getReturnType()->isPointerTy());
897  case LibFunc_vprintf:
898  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
899  case LibFunc_vfprintf:
900  case LibFunc_vsprintf:
901  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
902  FTy.getParamType(1)->isPointerTy());
903  case LibFunc_vsnprintf:
904  return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
905  FTy.getParamType(2)->isPointerTy());
906  case LibFunc_open:
907  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
908  case LibFunc_opendir:
909  return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
910  FTy.getParamType(0)->isPointerTy());
911  case LibFunc_tmpfile:
912  return (FTy.getReturnType()->isPointerTy());
913  case LibFunc_htonl:
914  case LibFunc_ntohl:
915  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
916  FTy.getReturnType() == FTy.getParamType(0));
917  case LibFunc_htons:
918  case LibFunc_ntohs:
919  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
920  FTy.getReturnType() == FTy.getParamType(0));
921  case LibFunc_lstat:
922  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
923  FTy.getParamType(1)->isPointerTy());
924  case LibFunc_lchown:
925  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
926  case LibFunc_qsort:
927  return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
928  case LibFunc_dunder_strdup:
929  case LibFunc_dunder_strndup:
930  return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
931  FTy.getParamType(0)->isPointerTy());
932  case LibFunc_dunder_strtok_r:
933  return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
934  case LibFunc_under_IO_putc:
935  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
936  case LibFunc_dunder_isoc99_scanf:
937  return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
938  case LibFunc_stat64:
939  case LibFunc_lstat64:
940  case LibFunc_statvfs64:
941  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
942  FTy.getParamType(1)->isPointerTy());
943  case LibFunc_dunder_isoc99_sscanf:
944  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
945  FTy.getParamType(1)->isPointerTy());
946  case LibFunc_fopen64:
947  return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
948  FTy.getParamType(0)->isPointerTy() &&
949  FTy.getParamType(1)->isPointerTy());
950  case LibFunc_tmpfile64:
951  return (FTy.getReturnType()->isPointerTy());
952  case LibFunc_fstat64:
953  case LibFunc_fstatvfs64:
954  return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
955  case LibFunc_open64:
956  return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
957  case LibFunc_gettimeofday:
958  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
959  FTy.getParamType(1)->isPointerTy());
960 
961  // new(unsigned int);
962  case LibFunc_Znwj:
963  // new(unsigned long);
964  case LibFunc_Znwm:
965  // new[](unsigned int);
966  case LibFunc_Znaj:
967  // new[](unsigned long);
968  case LibFunc_Znam:
969  // new(unsigned int);
970  case LibFunc_msvc_new_int:
971  // new(unsigned long long);
972  case LibFunc_msvc_new_longlong:
973  // new[](unsigned int);
974  case LibFunc_msvc_new_array_int:
975  // new[](unsigned long long);
976  case LibFunc_msvc_new_array_longlong:
977  return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
978 
979  // new(unsigned int, nothrow);
980  case LibFunc_ZnwjRKSt9nothrow_t:
981  // new(unsigned long, nothrow);
982  case LibFunc_ZnwmRKSt9nothrow_t:
983  // new[](unsigned int, nothrow);
984  case LibFunc_ZnajRKSt9nothrow_t:
985  // new[](unsigned long, nothrow);
986  case LibFunc_ZnamRKSt9nothrow_t:
987  // new(unsigned int, nothrow);
988  case LibFunc_msvc_new_int_nothrow:
989  // new(unsigned long long, nothrow);
990  case LibFunc_msvc_new_longlong_nothrow:
991  // new[](unsigned int, nothrow);
992  case LibFunc_msvc_new_array_int_nothrow:
993  // new[](unsigned long long, nothrow);
994  case LibFunc_msvc_new_array_longlong_nothrow:
995  // new(unsigned int, align_val_t)
996  case LibFunc_ZnwjSt11align_val_t:
997  // new(unsigned long, align_val_t)
998  case LibFunc_ZnwmSt11align_val_t:
999  // new[](unsigned int, align_val_t)
1000  case LibFunc_ZnajSt11align_val_t:
1001  // new[](unsigned long, align_val_t)
1002  case LibFunc_ZnamSt11align_val_t:
1003  return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
1004 
1005  // new(unsigned int, align_val_t, nothrow)
1006  case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
1007  // new(unsigned long, align_val_t, nothrow)
1008  case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1009  // new[](unsigned int, align_val_t, nothrow)
1010  case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
1011  // new[](unsigned long, align_val_t, nothrow)
1012  case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1013  return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
1014 
1015  // void operator delete[](void*);
1016  case LibFunc_ZdaPv:
1017  // void operator delete(void*);
1018  case LibFunc_ZdlPv:
1019  // void operator delete[](void*);
1020  case LibFunc_msvc_delete_array_ptr32:
1021  // void operator delete[](void*);
1022  case LibFunc_msvc_delete_array_ptr64:
1023  // void operator delete(void*);
1024  case LibFunc_msvc_delete_ptr32:
1025  // void operator delete(void*);
1026  case LibFunc_msvc_delete_ptr64:
1027  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1028 
1029  // void operator delete[](void*, nothrow);
1030  case LibFunc_ZdaPvRKSt9nothrow_t:
1031  // void operator delete[](void*, unsigned int);
1032  case LibFunc_ZdaPvj:
1033  // void operator delete[](void*, unsigned long);
1034  case LibFunc_ZdaPvm:
1035  // void operator delete(void*, nothrow);
1036  case LibFunc_ZdlPvRKSt9nothrow_t:
1037  // void operator delete(void*, unsigned int);
1038  case LibFunc_ZdlPvj:
1039  // void operator delete(void*, unsigned long);
1040  case LibFunc_ZdlPvm:
1041  // void operator delete(void*, align_val_t)
1042  case LibFunc_ZdlPvSt11align_val_t:
1043  // void operator delete[](void*, align_val_t)
1044  case LibFunc_ZdaPvSt11align_val_t:
1045  // void operator delete[](void*, unsigned int);
1046  case LibFunc_msvc_delete_array_ptr32_int:
1047  // void operator delete[](void*, nothrow);
1048  case LibFunc_msvc_delete_array_ptr32_nothrow:
1049  // void operator delete[](void*, unsigned long long);
1050  case LibFunc_msvc_delete_array_ptr64_longlong:
1051  // void operator delete[](void*, nothrow);
1052  case LibFunc_msvc_delete_array_ptr64_nothrow:
1053  // void operator delete(void*, unsigned int);
1054  case LibFunc_msvc_delete_ptr32_int:
1055  // void operator delete(void*, nothrow);
1056  case LibFunc_msvc_delete_ptr32_nothrow:
1057  // void operator delete(void*, unsigned long long);
1058  case LibFunc_msvc_delete_ptr64_longlong:
1059  // void operator delete(void*, nothrow);
1060  case LibFunc_msvc_delete_ptr64_nothrow:
1061  return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1062 
1063  // void operator delete(void*, align_val_t, nothrow)
1064  case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
1065  // void operator delete[](void*, align_val_t, nothrow)
1066  case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
1067  return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1068 
1069  case LibFunc_memset_pattern16:
1070  return (!FTy.isVarArg() && NumParams == 3 &&
1071  FTy.getParamType(0)->isPointerTy() &&
1072  FTy.getParamType(1)->isPointerTy() &&
1073  FTy.getParamType(2)->isIntegerTy());
1074 
1075  case LibFunc_cxa_guard_abort:
1076  case LibFunc_cxa_guard_acquire:
1077  case LibFunc_cxa_guard_release:
1078  case LibFunc_nvvm_reflect:
1079  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1080 
1081  case LibFunc_sincospi_stret:
1082  case LibFunc_sincospif_stret:
1083  return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1084 
1085  case LibFunc_acos:
1086  case LibFunc_acos_finite:
1087  case LibFunc_acosf:
1088  case LibFunc_acosf_finite:
1089  case LibFunc_acosh:
1090  case LibFunc_acosh_finite:
1091  case LibFunc_acoshf:
1092  case LibFunc_acoshf_finite:
1093  case LibFunc_acoshl:
1094  case LibFunc_acoshl_finite:
1095  case LibFunc_acosl:
1096  case LibFunc_acosl_finite:
1097  case LibFunc_asin:
1098  case LibFunc_asin_finite:
1099  case LibFunc_asinf:
1100  case LibFunc_asinf_finite:
1101  case LibFunc_asinh:
1102  case LibFunc_asinhf:
1103  case LibFunc_asinhl:
1104  case LibFunc_asinl:
1105  case LibFunc_asinl_finite:
1106  case LibFunc_atan:
1107  case LibFunc_atanf:
1108  case LibFunc_atanh:
1109  case LibFunc_atanh_finite:
1110  case LibFunc_atanhf:
1111  case LibFunc_atanhf_finite:
1112  case LibFunc_atanhl:
1113  case LibFunc_atanhl_finite:
1114  case LibFunc_atanl:
1115  case LibFunc_cbrt:
1116  case LibFunc_cbrtf:
1117  case LibFunc_cbrtl:
1118  case LibFunc_ceil:
1119  case LibFunc_ceilf:
1120  case LibFunc_ceill:
1121  case LibFunc_cos:
1122  case LibFunc_cosf:
1123  case LibFunc_cosh:
1124  case LibFunc_cosh_finite:
1125  case LibFunc_coshf:
1126  case LibFunc_coshf_finite:
1127  case LibFunc_coshl:
1128  case LibFunc_coshl_finite:
1129  case LibFunc_cosl:
1130  case LibFunc_exp10:
1131  case LibFunc_exp10_finite:
1132  case LibFunc_exp10f:
1133  case LibFunc_exp10f_finite:
1134  case LibFunc_exp10l:
1135  case LibFunc_exp10l_finite:
1136  case LibFunc_exp2:
1137  case LibFunc_exp2_finite:
1138  case LibFunc_exp2f:
1139  case LibFunc_exp2f_finite:
1140  case LibFunc_exp2l:
1141  case LibFunc_exp2l_finite:
1142  case LibFunc_exp:
1143  case LibFunc_exp_finite:
1144  case LibFunc_expf:
1145  case LibFunc_expf_finite:
1146  case LibFunc_expl:
1147  case LibFunc_expl_finite:
1148  case LibFunc_expm1:
1149  case LibFunc_expm1f:
1150  case LibFunc_expm1l:
1151  case LibFunc_fabs:
1152  case LibFunc_fabsf:
1153  case LibFunc_fabsl:
1154  case LibFunc_floor:
1155  case LibFunc_floorf:
1156  case LibFunc_floorl:
1157  case LibFunc_log10:
1158  case LibFunc_log10_finite:
1159  case LibFunc_log10f:
1160  case LibFunc_log10f_finite:
1161  case LibFunc_log10l:
1162  case LibFunc_log10l_finite:
1163  case LibFunc_log1p:
1164  case LibFunc_log1pf:
1165  case LibFunc_log1pl:
1166  case LibFunc_log2:
1167  case LibFunc_log2_finite:
1168  case LibFunc_log2f:
1169  case LibFunc_log2f_finite:
1170  case LibFunc_log2l:
1171  case LibFunc_log2l_finite:
1172  case LibFunc_log:
1173  case LibFunc_log_finite:
1174  case LibFunc_logb:
1175  case LibFunc_logbf:
1176  case LibFunc_logbl:
1177  case LibFunc_logf:
1178  case LibFunc_logf_finite:
1179  case LibFunc_logl:
1180  case LibFunc_logl_finite:
1181  case LibFunc_nearbyint:
1182  case LibFunc_nearbyintf:
1183  case LibFunc_nearbyintl:
1184  case LibFunc_rint:
1185  case LibFunc_rintf:
1186  case LibFunc_rintl:
1187  case LibFunc_round:
1188  case LibFunc_roundf:
1189  case LibFunc_roundl:
1190  case LibFunc_sin:
1191  case LibFunc_sinf:
1192  case LibFunc_sinh:
1193  case LibFunc_sinh_finite:
1194  case LibFunc_sinhf:
1195  case LibFunc_sinhf_finite:
1196  case LibFunc_sinhl:
1197  case LibFunc_sinhl_finite:
1198  case LibFunc_sinl:
1199  case LibFunc_sqrt:
1200  case LibFunc_sqrt_finite:
1201  case LibFunc_sqrtf:
1202  case LibFunc_sqrtf_finite:
1203  case LibFunc_sqrtl:
1204  case LibFunc_sqrtl_finite:
1205  case LibFunc_tan:
1206  case LibFunc_tanf:
1207  case LibFunc_tanh:
1208  case LibFunc_tanhf:
1209  case LibFunc_tanhl:
1210  case LibFunc_tanl:
1211  case LibFunc_trunc:
1212  case LibFunc_truncf:
1213  case LibFunc_truncl:
1214  return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1215  FTy.getReturnType() == FTy.getParamType(0));
1216 
1217  case LibFunc_atan2:
1218  case LibFunc_atan2_finite:
1219  case LibFunc_atan2f:
1220  case LibFunc_atan2f_finite:
1221  case LibFunc_atan2l:
1222  case LibFunc_atan2l_finite:
1223  case LibFunc_fmin:
1224  case LibFunc_fminf:
1225  case LibFunc_fminl:
1226  case LibFunc_fmax:
1227  case LibFunc_fmaxf:
1228  case LibFunc_fmaxl:
1229  case LibFunc_fmod:
1230  case LibFunc_fmodf:
1231  case LibFunc_fmodl:
1232  case LibFunc_copysign:
1233  case LibFunc_copysignf:
1234  case LibFunc_copysignl:
1235  case LibFunc_pow:
1236  case LibFunc_pow_finite:
1237  case LibFunc_powf:
1238  case LibFunc_powf_finite:
1239  case LibFunc_powl:
1240  case LibFunc_powl_finite:
1241  return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1242  FTy.getReturnType() == FTy.getParamType(0) &&
1243  FTy.getReturnType() == FTy.getParamType(1));
1244 
1245  case LibFunc_ldexp:
1246  case LibFunc_ldexpf:
1247  case LibFunc_ldexpl:
1248  return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1249  FTy.getReturnType() == FTy.getParamType(0) &&
1250  FTy.getParamType(1)->isIntegerTy(32));
1251 
1252  case LibFunc_ffs:
1253  case LibFunc_ffsl:
1254  case LibFunc_ffsll:
1255  case LibFunc_fls:
1256  case LibFunc_flsl:
1257  case LibFunc_flsll:
1258  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1259  FTy.getParamType(0)->isIntegerTy());
1260 
1261  case LibFunc_isdigit:
1262  case LibFunc_isascii:
1263  case LibFunc_toascii:
1264  case LibFunc_putchar:
1265  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1266  FTy.getReturnType() == FTy.getParamType(0));
1267 
1268  case LibFunc_abs:
1269  case LibFunc_labs:
1270  case LibFunc_llabs:
1271  return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1272  FTy.getReturnType() == FTy.getParamType(0));
1273 
1274  case LibFunc_cxa_atexit:
1275  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1276  FTy.getParamType(0)->isPointerTy() &&
1277  FTy.getParamType(1)->isPointerTy() &&
1278  FTy.getParamType(2)->isPointerTy());
1279 
1280  case LibFunc_sinpi:
1281  case LibFunc_cospi:
1282  return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1283  FTy.getReturnType() == FTy.getParamType(0));
1284 
1285  case LibFunc_sinpif:
1286  case LibFunc_cospif:
1287  return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1288  FTy.getReturnType() == FTy.getParamType(0));
1289 
1290  case LibFunc_strnlen:
1291  return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1292  FTy.getParamType(0) == PCharTy &&
1293  FTy.getParamType(1) == SizeTTy);
1294 
1295  case LibFunc_posix_memalign:
1296  return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1297  FTy.getParamType(0)->isPointerTy() &&
1298  FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1299 
1300  case LibFunc_wcslen:
1301  return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1302  FTy.getReturnType()->isIntegerTy());
1303 
1304  case LibFunc_cabs:
1305  case LibFunc_cabsf:
1306  case LibFunc_cabsl: {
1307  Type* RetTy = FTy.getReturnType();
1308  if (!RetTy->isFloatingPointTy())
1309  return false;
1310 
1311  // NOTE: These prototypes are target specific and currently support
1312  // "complex" passed as an array or discrete real & imaginary parameters.
1313  // Add other calling conventions to enable libcall optimizations.
1314  if (NumParams == 1)
1315  return (FTy.getParamType(0)->isArrayTy() &&
1316  FTy.getParamType(0)->getArrayNumElements() == 2 &&
1317  FTy.getParamType(0)->getArrayElementType() == RetTy);
1318  else if (NumParams == 2)
1319  return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1320  else
1321  return false;
1322  }
1323  case LibFunc::NumLibFuncs:
1324  break;
1325  }
1326 
1327  llvm_unreachable("Invalid libfunc");
1328 }
1329 
1331  LibFunc &F) const {
1332  const DataLayout *DL =
1333  FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1334  return getLibFunc(FDecl.getName(), F) &&
1335  isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1336 }
1337 
1339  memset(AvailableArray, 0, sizeof(AvailableArray));
1340 }
1341 
1342 static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1343  return LHS.ScalarFnName < RHS.ScalarFnName;
1344 }
1345 
1346 static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1347  return LHS.VectorFnName < RHS.VectorFnName;
1348 }
1349 
1350 static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1351  return LHS.ScalarFnName < S;
1352 }
1353 
1354 static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
1355  return LHS.VectorFnName < S;
1356 }
1357 
1359  VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1360  llvm::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1361 
1362  ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1363  llvm::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1364 }
1365 
1367  enum VectorLibrary VecLib) {
1368  switch (VecLib) {
1369  case Accelerate: {
1370  const VecDesc VecFuncs[] = {
1371  // Floating-Point Arithmetic and Auxiliary Functions
1372  {"ceilf", "vceilf", 4},
1373  {"fabsf", "vfabsf", 4},
1374  {"llvm.fabs.f32", "vfabsf", 4},
1375  {"floorf", "vfloorf", 4},
1376  {"sqrtf", "vsqrtf", 4},
1377  {"llvm.sqrt.f32", "vsqrtf", 4},
1378 
1379  // Exponential and Logarithmic Functions
1380  {"expf", "vexpf", 4},
1381  {"llvm.exp.f32", "vexpf", 4},
1382  {"expm1f", "vexpm1f", 4},
1383  {"logf", "vlogf", 4},
1384  {"llvm.log.f32", "vlogf", 4},
1385  {"log1pf", "vlog1pf", 4},
1386  {"log10f", "vlog10f", 4},
1387  {"llvm.log10.f32", "vlog10f", 4},
1388  {"logbf", "vlogbf", 4},
1389 
1390  // Trigonometric Functions
1391  {"sinf", "vsinf", 4},
1392  {"llvm.sin.f32", "vsinf", 4},
1393  {"cosf", "vcosf", 4},
1394  {"llvm.cos.f32", "vcosf", 4},
1395  {"tanf", "vtanf", 4},
1396  {"asinf", "vasinf", 4},
1397  {"acosf", "vacosf", 4},
1398  {"atanf", "vatanf", 4},
1399 
1400  // Hyperbolic Functions
1401  {"sinhf", "vsinhf", 4},
1402  {"coshf", "vcoshf", 4},
1403  {"tanhf", "vtanhf", 4},
1404  {"asinhf", "vasinhf", 4},
1405  {"acoshf", "vacoshf", 4},
1406  {"atanhf", "vatanhf", 4},
1407  };
1408  addVectorizableFunctions(VecFuncs);
1409  break;
1410  }
1411  case SVML: {
1412  const VecDesc VecFuncs[] = {
1413  {"sin", "__svml_sin2", 2},
1414  {"sin", "__svml_sin4", 4},
1415  {"sin", "__svml_sin8", 8},
1416 
1417  {"sinf", "__svml_sinf4", 4},
1418  {"sinf", "__svml_sinf8", 8},
1419  {"sinf", "__svml_sinf16", 16},
1420 
1421  {"cos", "__svml_cos2", 2},
1422  {"cos", "__svml_cos4", 4},
1423  {"cos", "__svml_cos8", 8},
1424 
1425  {"cosf", "__svml_cosf4", 4},
1426  {"cosf", "__svml_cosf8", 8},
1427  {"cosf", "__svml_cosf16", 16},
1428 
1429  {"pow", "__svml_pow2", 2},
1430  {"pow", "__svml_pow4", 4},
1431  {"pow", "__svml_pow8", 8},
1432 
1433  {"powf", "__svml_powf4", 4},
1434  {"powf", "__svml_powf8", 8},
1435  {"powf", "__svml_powf16", 16},
1436 
1437  { "__pow_finite", "__svml_pow2", 2 },
1438  { "__pow_finite", "__svml_pow4", 4 },
1439  { "__pow_finite", "__svml_pow8", 8 },
1440 
1441  { "__powf_finite", "__svml_powf4", 4 },
1442  { "__powf_finite", "__svml_powf8", 8 },
1443  { "__powf_finite", "__svml_powf16", 16 },
1444 
1445  {"llvm.pow.f64", "__svml_pow2", 2},
1446  {"llvm.pow.f64", "__svml_pow4", 4},
1447  {"llvm.pow.f64", "__svml_pow8", 8},
1448 
1449  {"llvm.pow.f32", "__svml_powf4", 4},
1450  {"llvm.pow.f32", "__svml_powf8", 8},
1451  {"llvm.pow.f32", "__svml_powf16", 16},
1452 
1453  {"exp", "__svml_exp2", 2},
1454  {"exp", "__svml_exp4", 4},
1455  {"exp", "__svml_exp8", 8},
1456 
1457  {"expf", "__svml_expf4", 4},
1458  {"expf", "__svml_expf8", 8},
1459  {"expf", "__svml_expf16", 16},
1460 
1461  { "__exp_finite", "__svml_exp2", 2 },
1462  { "__exp_finite", "__svml_exp4", 4 },
1463  { "__exp_finite", "__svml_exp8", 8 },
1464 
1465  { "__expf_finite", "__svml_expf4", 4 },
1466  { "__expf_finite", "__svml_expf8", 8 },
1467  { "__expf_finite", "__svml_expf16", 16 },
1468 
1469  {"llvm.exp.f64", "__svml_exp2", 2},
1470  {"llvm.exp.f64", "__svml_exp4", 4},
1471  {"llvm.exp.f64", "__svml_exp8", 8},
1472 
1473  {"llvm.exp.f32", "__svml_expf4", 4},
1474  {"llvm.exp.f32", "__svml_expf8", 8},
1475  {"llvm.exp.f32", "__svml_expf16", 16},
1476 
1477  {"log", "__svml_log2", 2},
1478  {"log", "__svml_log4", 4},
1479  {"log", "__svml_log8", 8},
1480 
1481  {"logf", "__svml_logf4", 4},
1482  {"logf", "__svml_logf8", 8},
1483  {"logf", "__svml_logf16", 16},
1484 
1485  { "__log_finite", "__svml_log2", 2 },
1486  { "__log_finite", "__svml_log4", 4 },
1487  { "__log_finite", "__svml_log8", 8 },
1488 
1489  { "__logf_finite", "__svml_logf4", 4 },
1490  { "__logf_finite", "__svml_logf8", 8 },
1491  { "__logf_finite", "__svml_logf16", 16 },
1492 
1493  {"llvm.log.f64", "__svml_log2", 2},
1494  {"llvm.log.f64", "__svml_log4", 4},
1495  {"llvm.log.f64", "__svml_log8", 8},
1496 
1497  {"llvm.log.f32", "__svml_logf4", 4},
1498  {"llvm.log.f32", "__svml_logf8", 8},
1499  {"llvm.log.f32", "__svml_logf16", 16},
1500  };
1501  addVectorizableFunctions(VecFuncs);
1502  break;
1503  }
1504  case NoLibrary:
1505  break;
1506  }
1507 }
1508 
1510  funcName = sanitizeFunctionName(funcName);
1511  if (funcName.empty())
1512  return false;
1513 
1514  std::vector<VecDesc>::const_iterator I = std::lower_bound(
1515  VectorDescs.begin(), VectorDescs.end(), funcName,
1517  return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1518 }
1519 
1521  unsigned VF) const {
1522  F = sanitizeFunctionName(F);
1523  if (F.empty())
1524  return F;
1525  std::vector<VecDesc>::const_iterator I = std::lower_bound(
1526  VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1527  while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1528  if (I->VectorizationFactor == VF)
1529  return I->VectorFnName;
1530  ++I;
1531  }
1532  return StringRef();
1533 }
1534 
1536  unsigned &VF) const {
1537  F = sanitizeFunctionName(F);
1538  if (F.empty())
1539  return F;
1540 
1541  std::vector<VecDesc>::const_iterator I = std::lower_bound(
1542  ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1543  if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1544  return StringRef();
1545  VF = I->VectorizationFactor;
1546  return I->ScalarFnName;
1547 }
1548 
1551  if (PresetInfoImpl)
1552  return TargetLibraryInfo(*PresetInfoImpl);
1553 
1554  return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1555 }
1556 
1559  if (PresetInfoImpl)
1560  return TargetLibraryInfo(*PresetInfoImpl);
1561 
1562  return TargetLibraryInfo(
1563  lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1564 }
1565 
1566 TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
1567  std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1568  Impls[T.normalize()];
1569  if (!Impl)
1570  Impl.reset(new TargetLibraryInfoImpl(T));
1571 
1572  return *Impl;
1573 }
1574 
1576  if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1577  M.getModuleFlag("wchar_size")))
1578  return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1579  return 0;
1580 }
1581 
1583  : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
1585 }
1586 
1588  : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
1590 }
1591 
1593  const TargetLibraryInfoImpl &TLIImpl)
1594  : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
1596 }
1597 
1598 AnalysisKey TargetLibraryAnalysis::Key;
1599 
1600 // Register the basic pass.
1602  "Target Library Information", false, true)
1604 
1605 void TargetLibraryInfoWrapperPass::anchor() {}
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:468
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:245
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:749
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:236
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:440
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
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
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:292
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:459
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:921
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
uint64_t getArrayNumElements() const
Definition: DerivedTypes.h:388
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:283
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
auto lower_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:942
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:449
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:560
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:744
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
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:797
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:570
TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
Type * getReturnType() const
Definition: DerivedTypes.h:124
bool isOSFreeBSD() const
Definition: Triple.h:484
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:471
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringRef > StandardNames)
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:549
#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:224
#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:425
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used...
bool isAndroid() const
Tests whether the target is Android.
Definition: Triple.h:619
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition: Triple.h:642
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:401
Type * getArrayElementType() const
Definition: Type.h:362
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)
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition: Type.h:218