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