[ARM] MVE sext costs
[llvm-complete.git] / lib / Analysis / TargetLibraryInfo.cpp
blob24ca57f3a94a698a14ffdc8e979781189e0499cf
1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the TargetLibraryInfo class.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Analysis/TargetLibraryInfo.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/IR/Constants.h"
16 #include "llvm/Support/CommandLine.h"
17 using namespace llvm;
19 static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
20 "vector-library", cl::Hidden, cl::desc("Vector functions library"),
21 cl::init(TargetLibraryInfoImpl::NoLibrary),
22 cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
23 "No vector functions library"),
24 clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
25 "Accelerate framework"),
26 clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
27 "IBM MASS vector library"),
28 clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
29 "Intel SVML library")));
31 StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
32 #define TLI_DEFINE_STRING
33 #include "llvm/Analysis/TargetLibraryInfo.def"
36 static bool hasSinCosPiStret(const Triple &T) {
37 // Only Darwin variants have _stret versions of combined trig functions.
38 if (!T.isOSDarwin())
39 return false;
41 // The ABI is rather complicated on x86, so don't do anything special there.
42 if (T.getArch() == Triple::x86)
43 return false;
45 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
46 return false;
48 if (T.isiOS() && T.isOSVersionLT(7, 0))
49 return false;
51 return true;
54 static bool hasBcmp(const Triple &TT) {
55 // Posix removed support from bcmp() in 2001, but the glibc and several
56 // implementations of the libc still have it.
57 if (TT.isOSLinux())
58 return TT.isGNUEnvironment() || TT.isMusl();
59 // Both NetBSD and OpenBSD are planning to remove the function. Windows does
60 // not have it.
61 return TT.isOSFreeBSD() || TT.isOSSolaris();
64 /// Initialize the set of available library functions based on the specified
65 /// target triple. This should be carefully written so that a missing target
66 /// triple gets a sane set of defaults.
67 static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
68 ArrayRef<StringRef> StandardNames) {
69 // Verify that the StandardNames array is in alphabetical order.
70 assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
71 [](StringRef LHS, StringRef RHS) {
72 return LHS < RHS;
73 }) &&
74 "TargetLibraryInfoImpl function names must be sorted");
76 // Set IO unlocked variants as unavailable
77 // Set them as available per system below
78 TLI.setUnavailable(LibFunc_getchar_unlocked);
79 TLI.setUnavailable(LibFunc_putc_unlocked);
80 TLI.setUnavailable(LibFunc_putchar_unlocked);
81 TLI.setUnavailable(LibFunc_fputc_unlocked);
82 TLI.setUnavailable(LibFunc_fgetc_unlocked);
83 TLI.setUnavailable(LibFunc_fread_unlocked);
84 TLI.setUnavailable(LibFunc_fwrite_unlocked);
85 TLI.setUnavailable(LibFunc_fputs_unlocked);
86 TLI.setUnavailable(LibFunc_fgets_unlocked);
88 bool ShouldExtI32Param = false, ShouldExtI32Return = false,
89 ShouldSignExtI32Param = false;
90 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
91 // returns corresponding to C-level ints and unsigned ints.
92 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
93 T.getArch() == Triple::systemz) {
94 ShouldExtI32Param = true;
95 ShouldExtI32Return = true;
97 // Mips, on the other hand, needs signext on i32 parameters corresponding
98 // to both signed and unsigned ints.
99 if (T.isMIPS()) {
100 ShouldSignExtI32Param = true;
102 TLI.setShouldExtI32Param(ShouldExtI32Param);
103 TLI.setShouldExtI32Return(ShouldExtI32Return);
104 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
106 if (T.getArch() == Triple::r600 ||
107 T.getArch() == Triple::amdgcn) {
108 TLI.setUnavailable(LibFunc_ldexp);
109 TLI.setUnavailable(LibFunc_ldexpf);
110 TLI.setUnavailable(LibFunc_ldexpl);
111 TLI.setUnavailable(LibFunc_exp10);
112 TLI.setUnavailable(LibFunc_exp10f);
113 TLI.setUnavailable(LibFunc_exp10l);
114 TLI.setUnavailable(LibFunc_log10);
115 TLI.setUnavailable(LibFunc_log10f);
116 TLI.setUnavailable(LibFunc_log10l);
117 TLI.setUnavailable(LibFunc_printf);
120 // There are no library implementations of memcpy and memset for AMD gpus and
121 // these can be difficult to lower in the backend.
122 if (T.getArch() == Triple::r600 ||
123 T.getArch() == Triple::amdgcn) {
124 TLI.setUnavailable(LibFunc_memcpy);
125 TLI.setUnavailable(LibFunc_memset);
126 TLI.setUnavailable(LibFunc_memset_pattern16);
127 return;
130 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
131 // All versions of watchOS support it.
132 if (T.isMacOSX()) {
133 // available IO unlocked variants on Mac OS X
134 TLI.setAvailable(LibFunc_getc_unlocked);
135 TLI.setAvailable(LibFunc_getchar_unlocked);
136 TLI.setAvailable(LibFunc_putc_unlocked);
137 TLI.setAvailable(LibFunc_putchar_unlocked);
139 if (T.isMacOSXVersionLT(10, 5))
140 TLI.setUnavailable(LibFunc_memset_pattern16);
141 } else if (T.isiOS()) {
142 if (T.isOSVersionLT(3, 0))
143 TLI.setUnavailable(LibFunc_memset_pattern16);
144 } else if (!T.isWatchOS()) {
145 TLI.setUnavailable(LibFunc_memset_pattern16);
148 if (!hasSinCosPiStret(T)) {
149 TLI.setUnavailable(LibFunc_sinpi);
150 TLI.setUnavailable(LibFunc_sinpif);
151 TLI.setUnavailable(LibFunc_cospi);
152 TLI.setUnavailable(LibFunc_cospif);
153 TLI.setUnavailable(LibFunc_sincospi_stret);
154 TLI.setUnavailable(LibFunc_sincospif_stret);
157 if (!hasBcmp(T))
158 TLI.setUnavailable(LibFunc_bcmp);
160 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
161 !T.isMacOSXVersionLT(10, 7)) {
162 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
163 // we don't care about) have two versions; on recent OSX, the one we want
164 // has a $UNIX2003 suffix. The two implementations are identical except
165 // for the return value in some edge cases. However, we don't want to
166 // generate code that depends on the old symbols.
167 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
168 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
171 // iprintf and friends are only available on XCore, TCE, and Emscripten.
172 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
173 T.getOS() != Triple::Emscripten) {
174 TLI.setUnavailable(LibFunc_iprintf);
175 TLI.setUnavailable(LibFunc_siprintf);
176 TLI.setUnavailable(LibFunc_fiprintf);
179 // __small_printf and friends are only available on Emscripten.
180 if (T.getOS() != Triple::Emscripten) {
181 TLI.setUnavailable(LibFunc_small_printf);
182 TLI.setUnavailable(LibFunc_small_sprintf);
183 TLI.setUnavailable(LibFunc_small_fprintf);
186 if (T.isOSWindows() && !T.isOSCygMing()) {
187 // XXX: The earliest documentation available at the moment is for VS2015/VC19:
188 // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
189 // XXX: In order to use an MSVCRT older than VC19,
190 // the specific library version must be explicit in the target triple,
191 // e.g., x86_64-pc-windows-msvc18.
192 bool hasPartialC99 = true;
193 if (T.isKnownWindowsMSVCEnvironment()) {
194 unsigned Major, Minor, Micro;
195 T.getEnvironmentVersion(Major, Minor, Micro);
196 hasPartialC99 = (Major == 0 || Major >= 19);
199 // Latest targets support C89 math functions, in part.
200 bool isARM = (T.getArch() == Triple::aarch64 ||
201 T.getArch() == Triple::arm);
202 bool hasPartialFloat = (isARM ||
203 T.getArch() == Triple::x86_64);
205 // Win32 does not support float C89 math functions, in general.
206 if (!hasPartialFloat) {
207 TLI.setUnavailable(LibFunc_acosf);
208 TLI.setUnavailable(LibFunc_asinf);
209 TLI.setUnavailable(LibFunc_atan2f);
210 TLI.setUnavailable(LibFunc_atanf);
211 TLI.setUnavailable(LibFunc_ceilf);
212 TLI.setUnavailable(LibFunc_cosf);
213 TLI.setUnavailable(LibFunc_coshf);
214 TLI.setUnavailable(LibFunc_expf);
215 TLI.setUnavailable(LibFunc_floorf);
216 TLI.setUnavailable(LibFunc_fmodf);
217 TLI.setUnavailable(LibFunc_log10f);
218 TLI.setUnavailable(LibFunc_logf);
219 TLI.setUnavailable(LibFunc_modff);
220 TLI.setUnavailable(LibFunc_powf);
221 TLI.setUnavailable(LibFunc_sinf);
222 TLI.setUnavailable(LibFunc_sinhf);
223 TLI.setUnavailable(LibFunc_sqrtf);
224 TLI.setUnavailable(LibFunc_tanf);
225 TLI.setUnavailable(LibFunc_tanhf);
227 if (!isARM)
228 TLI.setUnavailable(LibFunc_fabsf);
229 TLI.setUnavailable(LibFunc_frexpf);
230 TLI.setUnavailable(LibFunc_ldexpf);
232 // Win32 does not support long double C89 math functions.
233 TLI.setUnavailable(LibFunc_acosl);
234 TLI.setUnavailable(LibFunc_asinl);
235 TLI.setUnavailable(LibFunc_atan2l);
236 TLI.setUnavailable(LibFunc_atanl);
237 TLI.setUnavailable(LibFunc_ceill);
238 TLI.setUnavailable(LibFunc_cosl);
239 TLI.setUnavailable(LibFunc_coshl);
240 TLI.setUnavailable(LibFunc_expl);
241 TLI.setUnavailable(LibFunc_fabsl);
242 TLI.setUnavailable(LibFunc_floorl);
243 TLI.setUnavailable(LibFunc_fmodl);
244 TLI.setUnavailable(LibFunc_frexpl);
245 TLI.setUnavailable(LibFunc_ldexpl);
246 TLI.setUnavailable(LibFunc_log10l);
247 TLI.setUnavailable(LibFunc_logl);
248 TLI.setUnavailable(LibFunc_modfl);
249 TLI.setUnavailable(LibFunc_powl);
250 TLI.setUnavailable(LibFunc_sinl);
251 TLI.setUnavailable(LibFunc_sinhl);
252 TLI.setUnavailable(LibFunc_sqrtl);
253 TLI.setUnavailable(LibFunc_tanl);
254 TLI.setUnavailable(LibFunc_tanhl);
256 // Win32 does not fully support C99 math functions.
257 if (!hasPartialC99) {
258 TLI.setUnavailable(LibFunc_acosh);
259 TLI.setUnavailable(LibFunc_acoshf);
260 TLI.setUnavailable(LibFunc_asinh);
261 TLI.setUnavailable(LibFunc_asinhf);
262 TLI.setUnavailable(LibFunc_atanh);
263 TLI.setUnavailable(LibFunc_atanhf);
264 TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
265 TLI.setUnavailable(LibFunc_cabsf);
266 TLI.setUnavailable(LibFunc_cbrt);
267 TLI.setUnavailable(LibFunc_cbrtf);
268 TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
269 TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
270 TLI.setUnavailable(LibFunc_exp2);
271 TLI.setUnavailable(LibFunc_exp2f);
272 TLI.setUnavailable(LibFunc_expm1);
273 TLI.setUnavailable(LibFunc_expm1f);
274 TLI.setUnavailable(LibFunc_fmax);
275 TLI.setUnavailable(LibFunc_fmaxf);
276 TLI.setUnavailable(LibFunc_fmin);
277 TLI.setUnavailable(LibFunc_fminf);
278 TLI.setUnavailable(LibFunc_log1p);
279 TLI.setUnavailable(LibFunc_log1pf);
280 TLI.setUnavailable(LibFunc_log2);
281 TLI.setUnavailable(LibFunc_log2f);
282 TLI.setAvailableWithName(LibFunc_logb, "_logb");
283 if (hasPartialFloat)
284 TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
285 else
286 TLI.setUnavailable(LibFunc_logbf);
287 TLI.setUnavailable(LibFunc_rint);
288 TLI.setUnavailable(LibFunc_rintf);
289 TLI.setUnavailable(LibFunc_round);
290 TLI.setUnavailable(LibFunc_roundf);
291 TLI.setUnavailable(LibFunc_trunc);
292 TLI.setUnavailable(LibFunc_truncf);
295 // Win32 does not support long double C99 math functions.
296 TLI.setUnavailable(LibFunc_acoshl);
297 TLI.setUnavailable(LibFunc_asinhl);
298 TLI.setUnavailable(LibFunc_atanhl);
299 TLI.setUnavailable(LibFunc_cabsl);
300 TLI.setUnavailable(LibFunc_cbrtl);
301 TLI.setUnavailable(LibFunc_copysignl);
302 TLI.setUnavailable(LibFunc_exp2l);
303 TLI.setUnavailable(LibFunc_expm1l);
304 TLI.setUnavailable(LibFunc_fmaxl);
305 TLI.setUnavailable(LibFunc_fminl);
306 TLI.setUnavailable(LibFunc_log1pl);
307 TLI.setUnavailable(LibFunc_log2l);
308 TLI.setUnavailable(LibFunc_logbl);
309 TLI.setUnavailable(LibFunc_nearbyintl);
310 TLI.setUnavailable(LibFunc_rintl);
311 TLI.setUnavailable(LibFunc_roundl);
312 TLI.setUnavailable(LibFunc_truncl);
314 // Win32 does not support these functions, but
315 // they are generally available on POSIX-compliant systems.
316 TLI.setUnavailable(LibFunc_access);
317 TLI.setUnavailable(LibFunc_bcmp);
318 TLI.setUnavailable(LibFunc_bcopy);
319 TLI.setUnavailable(LibFunc_bzero);
320 TLI.setUnavailable(LibFunc_chmod);
321 TLI.setUnavailable(LibFunc_chown);
322 TLI.setUnavailable(LibFunc_closedir);
323 TLI.setUnavailable(LibFunc_ctermid);
324 TLI.setUnavailable(LibFunc_fdopen);
325 TLI.setUnavailable(LibFunc_ffs);
326 TLI.setUnavailable(LibFunc_fileno);
327 TLI.setUnavailable(LibFunc_flockfile);
328 TLI.setUnavailable(LibFunc_fseeko);
329 TLI.setUnavailable(LibFunc_fstat);
330 TLI.setUnavailable(LibFunc_fstatvfs);
331 TLI.setUnavailable(LibFunc_ftello);
332 TLI.setUnavailable(LibFunc_ftrylockfile);
333 TLI.setUnavailable(LibFunc_funlockfile);
334 TLI.setUnavailable(LibFunc_getitimer);
335 TLI.setUnavailable(LibFunc_getlogin_r);
336 TLI.setUnavailable(LibFunc_getpwnam);
337 TLI.setUnavailable(LibFunc_gettimeofday);
338 TLI.setUnavailable(LibFunc_htonl);
339 TLI.setUnavailable(LibFunc_htons);
340 TLI.setUnavailable(LibFunc_lchown);
341 TLI.setUnavailable(LibFunc_lstat);
342 TLI.setUnavailable(LibFunc_memccpy);
343 TLI.setUnavailable(LibFunc_mkdir);
344 TLI.setUnavailable(LibFunc_ntohl);
345 TLI.setUnavailable(LibFunc_ntohs);
346 TLI.setUnavailable(LibFunc_open);
347 TLI.setUnavailable(LibFunc_opendir);
348 TLI.setUnavailable(LibFunc_pclose);
349 TLI.setUnavailable(LibFunc_popen);
350 TLI.setUnavailable(LibFunc_pread);
351 TLI.setUnavailable(LibFunc_pwrite);
352 TLI.setUnavailable(LibFunc_read);
353 TLI.setUnavailable(LibFunc_readlink);
354 TLI.setUnavailable(LibFunc_realpath);
355 TLI.setUnavailable(LibFunc_rmdir);
356 TLI.setUnavailable(LibFunc_setitimer);
357 TLI.setUnavailable(LibFunc_stat);
358 TLI.setUnavailable(LibFunc_statvfs);
359 TLI.setUnavailable(LibFunc_stpcpy);
360 TLI.setUnavailable(LibFunc_stpncpy);
361 TLI.setUnavailable(LibFunc_strcasecmp);
362 TLI.setUnavailable(LibFunc_strncasecmp);
363 TLI.setUnavailable(LibFunc_times);
364 TLI.setUnavailable(LibFunc_uname);
365 TLI.setUnavailable(LibFunc_unlink);
366 TLI.setUnavailable(LibFunc_unsetenv);
367 TLI.setUnavailable(LibFunc_utime);
368 TLI.setUnavailable(LibFunc_utimes);
369 TLI.setUnavailable(LibFunc_write);
372 switch (T.getOS()) {
373 case Triple::MacOSX:
374 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
375 // and their names are __exp10 and __exp10f. exp10l is not available on
376 // OS X or iOS.
377 TLI.setUnavailable(LibFunc_exp10l);
378 if (T.isMacOSXVersionLT(10, 9)) {
379 TLI.setUnavailable(LibFunc_exp10);
380 TLI.setUnavailable(LibFunc_exp10f);
381 } else {
382 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
383 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
385 break;
386 case Triple::IOS:
387 case Triple::TvOS:
388 case Triple::WatchOS:
389 TLI.setUnavailable(LibFunc_exp10l);
390 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
391 (T.isOSVersionLT(9, 0) &&
392 (T.getArch() == Triple::x86 ||
393 T.getArch() == Triple::x86_64)))) {
394 TLI.setUnavailable(LibFunc_exp10);
395 TLI.setUnavailable(LibFunc_exp10f);
396 } else {
397 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
398 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
400 break;
401 case Triple::Linux:
402 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
403 // buggy prior to glibc version 2.18. Until this version is widely deployed
404 // or we have a reasonable detection strategy, we cannot use exp10 reliably
405 // on Linux.
407 // Fall through to disable all of them.
408 LLVM_FALLTHROUGH;
409 default:
410 TLI.setUnavailable(LibFunc_exp10);
411 TLI.setUnavailable(LibFunc_exp10f);
412 TLI.setUnavailable(LibFunc_exp10l);
415 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
416 // Linux (GLIBC):
417 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
418 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
419 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
420 switch (T.getOS()) {
421 case Triple::Darwin:
422 case Triple::MacOSX:
423 case Triple::IOS:
424 case Triple::TvOS:
425 case Triple::WatchOS:
426 case Triple::FreeBSD:
427 case Triple::Linux:
428 break;
429 default:
430 TLI.setUnavailable(LibFunc_ffsl);
433 // ffsll is available on at least FreeBSD and Linux (GLIBC):
434 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
435 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
436 switch (T.getOS()) {
437 case Triple::Darwin:
438 case Triple::MacOSX:
439 case Triple::IOS:
440 case Triple::TvOS:
441 case Triple::WatchOS:
442 case Triple::FreeBSD:
443 case Triple::Linux:
444 break;
445 default:
446 TLI.setUnavailable(LibFunc_ffsll);
449 // The following functions are available on at least FreeBSD:
450 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
451 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
452 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
453 if (!T.isOSFreeBSD()) {
454 TLI.setUnavailable(LibFunc_fls);
455 TLI.setUnavailable(LibFunc_flsl);
456 TLI.setUnavailable(LibFunc_flsll);
459 // The following functions are only available on GNU/Linux (using glibc).
460 // Linux variants without glibc (eg: bionic, musl) may have some subset.
461 if (!T.isOSLinux() || !T.isGNUEnvironment()) {
462 TLI.setUnavailable(LibFunc_dunder_strdup);
463 TLI.setUnavailable(LibFunc_dunder_strtok_r);
464 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
465 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
466 TLI.setUnavailable(LibFunc_under_IO_getc);
467 TLI.setUnavailable(LibFunc_under_IO_putc);
468 // But, Android and musl have memalign.
469 if (!T.isAndroid() && !T.isMusl())
470 TLI.setUnavailable(LibFunc_memalign);
471 TLI.setUnavailable(LibFunc_fopen64);
472 TLI.setUnavailable(LibFunc_fseeko64);
473 TLI.setUnavailable(LibFunc_fstat64);
474 TLI.setUnavailable(LibFunc_fstatvfs64);
475 TLI.setUnavailable(LibFunc_ftello64);
476 TLI.setUnavailable(LibFunc_lstat64);
477 TLI.setUnavailable(LibFunc_open64);
478 TLI.setUnavailable(LibFunc_stat64);
479 TLI.setUnavailable(LibFunc_statvfs64);
480 TLI.setUnavailable(LibFunc_tmpfile64);
482 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
483 TLI.setUnavailable(LibFunc_acos_finite);
484 TLI.setUnavailable(LibFunc_acosf_finite);
485 TLI.setUnavailable(LibFunc_acosl_finite);
486 TLI.setUnavailable(LibFunc_acosh_finite);
487 TLI.setUnavailable(LibFunc_acoshf_finite);
488 TLI.setUnavailable(LibFunc_acoshl_finite);
489 TLI.setUnavailable(LibFunc_asin_finite);
490 TLI.setUnavailable(LibFunc_asinf_finite);
491 TLI.setUnavailable(LibFunc_asinl_finite);
492 TLI.setUnavailable(LibFunc_atan2_finite);
493 TLI.setUnavailable(LibFunc_atan2f_finite);
494 TLI.setUnavailable(LibFunc_atan2l_finite);
495 TLI.setUnavailable(LibFunc_atanh_finite);
496 TLI.setUnavailable(LibFunc_atanhf_finite);
497 TLI.setUnavailable(LibFunc_atanhl_finite);
498 TLI.setUnavailable(LibFunc_cosh_finite);
499 TLI.setUnavailable(LibFunc_coshf_finite);
500 TLI.setUnavailable(LibFunc_coshl_finite);
501 TLI.setUnavailable(LibFunc_exp10_finite);
502 TLI.setUnavailable(LibFunc_exp10f_finite);
503 TLI.setUnavailable(LibFunc_exp10l_finite);
504 TLI.setUnavailable(LibFunc_exp2_finite);
505 TLI.setUnavailable(LibFunc_exp2f_finite);
506 TLI.setUnavailable(LibFunc_exp2l_finite);
507 TLI.setUnavailable(LibFunc_exp_finite);
508 TLI.setUnavailable(LibFunc_expf_finite);
509 TLI.setUnavailable(LibFunc_expl_finite);
510 TLI.setUnavailable(LibFunc_log10_finite);
511 TLI.setUnavailable(LibFunc_log10f_finite);
512 TLI.setUnavailable(LibFunc_log10l_finite);
513 TLI.setUnavailable(LibFunc_log2_finite);
514 TLI.setUnavailable(LibFunc_log2f_finite);
515 TLI.setUnavailable(LibFunc_log2l_finite);
516 TLI.setUnavailable(LibFunc_log_finite);
517 TLI.setUnavailable(LibFunc_logf_finite);
518 TLI.setUnavailable(LibFunc_logl_finite);
519 TLI.setUnavailable(LibFunc_pow_finite);
520 TLI.setUnavailable(LibFunc_powf_finite);
521 TLI.setUnavailable(LibFunc_powl_finite);
522 TLI.setUnavailable(LibFunc_sinh_finite);
523 TLI.setUnavailable(LibFunc_sinhf_finite);
524 TLI.setUnavailable(LibFunc_sinhl_finite);
527 if ((T.isOSLinux() && T.isGNUEnvironment()) ||
528 (T.isAndroid() && !T.isAndroidVersionLT(28))) {
529 // available IO unlocked variants on GNU/Linux and Android P or later
530 TLI.setAvailable(LibFunc_getc_unlocked);
531 TLI.setAvailable(LibFunc_getchar_unlocked);
532 TLI.setAvailable(LibFunc_putc_unlocked);
533 TLI.setAvailable(LibFunc_putchar_unlocked);
534 TLI.setAvailable(LibFunc_fputc_unlocked);
535 TLI.setAvailable(LibFunc_fgetc_unlocked);
536 TLI.setAvailable(LibFunc_fread_unlocked);
537 TLI.setAvailable(LibFunc_fwrite_unlocked);
538 TLI.setAvailable(LibFunc_fputs_unlocked);
539 TLI.setAvailable(LibFunc_fgets_unlocked);
542 // As currently implemented in clang, NVPTX code has no standard library to
543 // speak of. Headers provide a standard-ish library implementation, but many
544 // of the signatures are wrong -- for example, many libm functions are not
545 // extern "C".
547 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
548 // but only used functions are provided to llvm. Moreover, most of the
549 // functions in libdevice don't map precisely to standard library functions.
551 // FIXME: Having no standard library prevents e.g. many fastmath
552 // optimizations, so this situation should be fixed.
553 if (T.isNVPTX()) {
554 TLI.disableAllFunctions();
555 TLI.setAvailable(LibFunc_nvvm_reflect);
556 } else {
557 TLI.setUnavailable(LibFunc_nvvm_reflect);
560 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
563 TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
564 // Default to everything being available.
565 memset(AvailableArray, -1, sizeof(AvailableArray));
567 initialize(*this, Triple(), StandardNames);
570 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
571 // Default to everything being available.
572 memset(AvailableArray, -1, sizeof(AvailableArray));
574 initialize(*this, T, StandardNames);
577 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
578 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
579 ShouldExtI32Return(TLI.ShouldExtI32Return),
580 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
581 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
582 VectorDescs = TLI.VectorDescs;
583 ScalarDescs = TLI.ScalarDescs;
586 TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
587 : CustomNames(std::move(TLI.CustomNames)),
588 ShouldExtI32Param(TLI.ShouldExtI32Param),
589 ShouldExtI32Return(TLI.ShouldExtI32Return),
590 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
591 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
592 AvailableArray);
593 VectorDescs = TLI.VectorDescs;
594 ScalarDescs = TLI.ScalarDescs;
597 TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
598 CustomNames = TLI.CustomNames;
599 ShouldExtI32Param = TLI.ShouldExtI32Param;
600 ShouldExtI32Return = TLI.ShouldExtI32Return;
601 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
602 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
603 return *this;
606 TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
607 CustomNames = std::move(TLI.CustomNames);
608 ShouldExtI32Param = TLI.ShouldExtI32Param;
609 ShouldExtI32Return = TLI.ShouldExtI32Return;
610 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
611 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
612 AvailableArray);
613 return *this;
616 static StringRef sanitizeFunctionName(StringRef funcName) {
617 // Filter out empty names and names containing null bytes, those can't be in
618 // our table.
619 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
620 return StringRef();
622 // Check for \01 prefix that is used to mangle __asm declarations and
623 // strip it if present.
624 return GlobalValue::dropLLVMManglingEscape(funcName);
627 bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
628 LibFunc &F) const {
629 StringRef const *Start = &StandardNames[0];
630 StringRef const *End = &StandardNames[NumLibFuncs];
632 funcName = sanitizeFunctionName(funcName);
633 if (funcName.empty())
634 return false;
636 StringRef const *I = std::lower_bound(
637 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
638 return LHS < RHS;
640 if (I != End && *I == funcName) {
641 F = (LibFunc)(I - Start);
642 return true;
644 return false;
647 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
648 LibFunc F,
649 const DataLayout *DL) const {
650 LLVMContext &Ctx = FTy.getContext();
651 Type *PCharTy = Type::getInt8PtrTy(Ctx);
652 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
653 auto IsSizeTTy = [SizeTTy](Type *Ty) {
654 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
656 unsigned NumParams = FTy.getNumParams();
658 switch (F) {
659 case LibFunc_execl:
660 case LibFunc_execlp:
661 case LibFunc_execle:
662 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
663 FTy.getParamType(1)->isPointerTy() &&
664 FTy.getReturnType()->isIntegerTy(32));
665 case LibFunc_execv:
666 case LibFunc_execvp:
667 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
668 FTy.getParamType(1)->isPointerTy() &&
669 FTy.getReturnType()->isIntegerTy(32));
670 case LibFunc_execvP:
671 case LibFunc_execvpe:
672 case LibFunc_execve:
673 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
674 FTy.getParamType(1)->isPointerTy() &&
675 FTy.getParamType(2)->isPointerTy() &&
676 FTy.getReturnType()->isIntegerTy(32));
677 case LibFunc_strlen:
678 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
679 FTy.getReturnType()->isIntegerTy());
681 case LibFunc_strchr:
682 case LibFunc_strrchr:
683 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
684 FTy.getParamType(0) == FTy.getReturnType() &&
685 FTy.getParamType(1)->isIntegerTy());
687 case LibFunc_strtol:
688 case LibFunc_strtod:
689 case LibFunc_strtof:
690 case LibFunc_strtoul:
691 case LibFunc_strtoll:
692 case LibFunc_strtold:
693 case LibFunc_strtoull:
694 return ((NumParams == 2 || NumParams == 3) &&
695 FTy.getParamType(0)->isPointerTy() &&
696 FTy.getParamType(1)->isPointerTy());
697 case LibFunc_strcat_chk:
698 --NumParams;
699 if (!IsSizeTTy(FTy.getParamType(NumParams)))
700 return false;
701 LLVM_FALLTHROUGH;
702 case LibFunc_strcat:
703 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
704 FTy.getParamType(0) == FTy.getReturnType() &&
705 FTy.getParamType(1) == FTy.getReturnType());
707 case LibFunc_strncat_chk:
708 --NumParams;
709 if (!IsSizeTTy(FTy.getParamType(NumParams)))
710 return false;
711 LLVM_FALLTHROUGH;
712 case LibFunc_strncat:
713 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
714 FTy.getParamType(0) == FTy.getReturnType() &&
715 FTy.getParamType(1) == FTy.getReturnType() &&
716 IsSizeTTy(FTy.getParamType(2)));
718 case LibFunc_strcpy_chk:
719 case LibFunc_stpcpy_chk:
720 --NumParams;
721 if (!IsSizeTTy(FTy.getParamType(NumParams)))
722 return false;
723 LLVM_FALLTHROUGH;
724 case LibFunc_strcpy:
725 case LibFunc_stpcpy:
726 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
727 FTy.getParamType(0) == FTy.getParamType(1) &&
728 FTy.getParamType(0) == PCharTy);
730 case LibFunc_strlcat_chk:
731 case LibFunc_strlcpy_chk:
732 --NumParams;
733 if (!IsSizeTTy(FTy.getParamType(NumParams)))
734 return false;
735 LLVM_FALLTHROUGH;
736 case LibFunc_strlcat:
737 case LibFunc_strlcpy:
738 return NumParams == 3 && IsSizeTTy(FTy.getReturnType()) &&
739 FTy.getParamType(0)->isPointerTy() &&
740 FTy.getParamType(1)->isPointerTy() &&
741 IsSizeTTy(FTy.getParamType(2));
743 case LibFunc_strncpy_chk:
744 case LibFunc_stpncpy_chk:
745 --NumParams;
746 if (!IsSizeTTy(FTy.getParamType(NumParams)))
747 return false;
748 LLVM_FALLTHROUGH;
749 case LibFunc_strncpy:
750 case LibFunc_stpncpy:
751 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
752 FTy.getParamType(0) == FTy.getParamType(1) &&
753 FTy.getParamType(0) == PCharTy &&
754 IsSizeTTy(FTy.getParamType(2)));
756 case LibFunc_strxfrm:
757 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
758 FTy.getParamType(1)->isPointerTy());
760 case LibFunc_strcmp:
761 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
762 FTy.getParamType(0)->isPointerTy() &&
763 FTy.getParamType(0) == FTy.getParamType(1));
765 case LibFunc_strncmp:
766 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
767 FTy.getParamType(0)->isPointerTy() &&
768 FTy.getParamType(0) == FTy.getParamType(1) &&
769 IsSizeTTy(FTy.getParamType(2)));
771 case LibFunc_strspn:
772 case LibFunc_strcspn:
773 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
774 FTy.getParamType(0) == FTy.getParamType(1) &&
775 FTy.getReturnType()->isIntegerTy());
777 case LibFunc_strcoll:
778 case LibFunc_strcasecmp:
779 case LibFunc_strncasecmp:
780 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
781 FTy.getParamType(1)->isPointerTy());
783 case LibFunc_strstr:
784 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
785 FTy.getParamType(0)->isPointerTy() &&
786 FTy.getParamType(1)->isPointerTy());
788 case LibFunc_strpbrk:
789 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
790 FTy.getReturnType() == FTy.getParamType(0) &&
791 FTy.getParamType(0) == FTy.getParamType(1));
793 case LibFunc_strtok:
794 case LibFunc_strtok_r:
795 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
796 case LibFunc_scanf:
797 case LibFunc_setbuf:
798 case LibFunc_setvbuf:
799 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
800 case LibFunc_strdup:
801 case LibFunc_strndup:
802 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
803 FTy.getParamType(0)->isPointerTy());
804 case LibFunc_sscanf:
805 case LibFunc_stat:
806 case LibFunc_statvfs:
807 case LibFunc_siprintf:
808 case LibFunc_small_sprintf:
809 case LibFunc_sprintf:
810 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
811 FTy.getParamType(1)->isPointerTy() &&
812 FTy.getReturnType()->isIntegerTy(32));
814 case LibFunc_sprintf_chk:
815 return NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
816 FTy.getParamType(1)->isIntegerTy(32) &&
817 IsSizeTTy(FTy.getParamType(2)) &&
818 FTy.getParamType(3)->isPointerTy() &&
819 FTy.getReturnType()->isIntegerTy(32);
821 case LibFunc_snprintf:
822 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
823 FTy.getParamType(2)->isPointerTy() &&
824 FTy.getReturnType()->isIntegerTy(32));
826 case LibFunc_snprintf_chk:
827 return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
828 IsSizeTTy(FTy.getParamType(1)) &&
829 FTy.getParamType(2)->isIntegerTy(32) &&
830 IsSizeTTy(FTy.getParamType(3)) &&
831 FTy.getParamType(4)->isPointerTy() &&
832 FTy.getReturnType()->isIntegerTy(32);
834 case LibFunc_setitimer:
835 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
836 FTy.getParamType(2)->isPointerTy());
837 case LibFunc_system:
838 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
839 case LibFunc_malloc:
840 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
841 case LibFunc_memcmp:
842 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
843 FTy.getParamType(0)->isPointerTy() &&
844 FTy.getParamType(1)->isPointerTy());
846 case LibFunc_memchr:
847 case LibFunc_memrchr:
848 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
849 FTy.getReturnType() == FTy.getParamType(0) &&
850 FTy.getParamType(1)->isIntegerTy(32) &&
851 IsSizeTTy(FTy.getParamType(2)));
852 case LibFunc_modf:
853 case LibFunc_modff:
854 case LibFunc_modfl:
855 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
857 case LibFunc_memcpy_chk:
858 case LibFunc_memmove_chk:
859 --NumParams;
860 if (!IsSizeTTy(FTy.getParamType(NumParams)))
861 return false;
862 LLVM_FALLTHROUGH;
863 case LibFunc_memcpy:
864 case LibFunc_mempcpy:
865 case LibFunc_memmove:
866 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
867 FTy.getParamType(0)->isPointerTy() &&
868 FTy.getParamType(1)->isPointerTy() &&
869 IsSizeTTy(FTy.getParamType(2)));
871 case LibFunc_memset_chk:
872 --NumParams;
873 if (!IsSizeTTy(FTy.getParamType(NumParams)))
874 return false;
875 LLVM_FALLTHROUGH;
876 case LibFunc_memset:
877 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
878 FTy.getParamType(0)->isPointerTy() &&
879 FTy.getParamType(1)->isIntegerTy() &&
880 IsSizeTTy(FTy.getParamType(2)));
882 case LibFunc_memccpy_chk:
883 --NumParams;
884 if (!IsSizeTTy(FTy.getParamType(NumParams)))
885 return false;
886 LLVM_FALLTHROUGH;
887 case LibFunc_memccpy:
888 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
889 case LibFunc_memalign:
890 return (FTy.getReturnType()->isPointerTy());
891 case LibFunc_realloc:
892 case LibFunc_reallocf:
893 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
894 FTy.getParamType(0) == FTy.getReturnType() &&
895 IsSizeTTy(FTy.getParamType(1)));
896 case LibFunc_read:
897 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
898 case LibFunc_rewind:
899 case LibFunc_rmdir:
900 case LibFunc_remove:
901 case LibFunc_realpath:
902 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
903 case LibFunc_rename:
904 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
905 FTy.getParamType(1)->isPointerTy());
906 case LibFunc_readlink:
907 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
908 FTy.getParamType(1)->isPointerTy());
909 case LibFunc_write:
910 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
911 case LibFunc_bcopy:
912 case LibFunc_bcmp:
913 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
914 FTy.getParamType(1)->isPointerTy());
915 case LibFunc_bzero:
916 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
917 case LibFunc_calloc:
918 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
920 case LibFunc_atof:
921 case LibFunc_atoi:
922 case LibFunc_atol:
923 case LibFunc_atoll:
924 case LibFunc_ferror:
925 case LibFunc_getenv:
926 case LibFunc_getpwnam:
927 case LibFunc_iprintf:
928 case LibFunc_small_printf:
929 case LibFunc_pclose:
930 case LibFunc_perror:
931 case LibFunc_printf:
932 case LibFunc_puts:
933 case LibFunc_uname:
934 case LibFunc_under_IO_getc:
935 case LibFunc_unlink:
936 case LibFunc_unsetenv:
937 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
939 case LibFunc_access:
940 case LibFunc_chmod:
941 case LibFunc_chown:
942 case LibFunc_clearerr:
943 case LibFunc_closedir:
944 case LibFunc_ctermid:
945 case LibFunc_fclose:
946 case LibFunc_feof:
947 case LibFunc_fflush:
948 case LibFunc_fgetc:
949 case LibFunc_fgetc_unlocked:
950 case LibFunc_fileno:
951 case LibFunc_flockfile:
952 case LibFunc_free:
953 case LibFunc_fseek:
954 case LibFunc_fseeko64:
955 case LibFunc_fseeko:
956 case LibFunc_fsetpos:
957 case LibFunc_ftell:
958 case LibFunc_ftello64:
959 case LibFunc_ftello:
960 case LibFunc_ftrylockfile:
961 case LibFunc_funlockfile:
962 case LibFunc_getc:
963 case LibFunc_getc_unlocked:
964 case LibFunc_getlogin_r:
965 case LibFunc_mkdir:
966 case LibFunc_mktime:
967 case LibFunc_times:
968 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
970 case LibFunc_fopen:
971 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
972 FTy.getParamType(0)->isPointerTy() &&
973 FTy.getParamType(1)->isPointerTy());
974 case LibFunc_fork:
975 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
976 case LibFunc_fdopen:
977 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
978 FTy.getParamType(1)->isPointerTy());
979 case LibFunc_fputc:
980 case LibFunc_fputc_unlocked:
981 case LibFunc_fstat:
982 case LibFunc_frexp:
983 case LibFunc_frexpf:
984 case LibFunc_frexpl:
985 case LibFunc_fstatvfs:
986 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
987 case LibFunc_fgets:
988 case LibFunc_fgets_unlocked:
989 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
990 FTy.getParamType(2)->isPointerTy());
991 case LibFunc_fread:
992 case LibFunc_fread_unlocked:
993 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
994 FTy.getParamType(3)->isPointerTy());
995 case LibFunc_fwrite:
996 case LibFunc_fwrite_unlocked:
997 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
998 FTy.getParamType(0)->isPointerTy() &&
999 FTy.getParamType(1)->isIntegerTy() &&
1000 FTy.getParamType(2)->isIntegerTy() &&
1001 FTy.getParamType(3)->isPointerTy());
1002 case LibFunc_fputs:
1003 case LibFunc_fputs_unlocked:
1004 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1005 FTy.getParamType(1)->isPointerTy());
1006 case LibFunc_fscanf:
1007 case LibFunc_fiprintf:
1008 case LibFunc_small_fprintf:
1009 case LibFunc_fprintf:
1010 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
1011 FTy.getParamType(0)->isPointerTy() &&
1012 FTy.getParamType(1)->isPointerTy());
1013 case LibFunc_fgetpos:
1014 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1015 FTy.getParamType(1)->isPointerTy());
1016 case LibFunc_getchar:
1017 case LibFunc_getchar_unlocked:
1018 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
1019 case LibFunc_gets:
1020 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
1021 case LibFunc_getitimer:
1022 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1023 case LibFunc_ungetc:
1024 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1025 case LibFunc_utime:
1026 case LibFunc_utimes:
1027 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1028 FTy.getParamType(1)->isPointerTy());
1029 case LibFunc_putc:
1030 case LibFunc_putc_unlocked:
1031 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1032 case LibFunc_pread:
1033 case LibFunc_pwrite:
1034 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
1035 case LibFunc_popen:
1036 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1037 FTy.getParamType(0)->isPointerTy() &&
1038 FTy.getParamType(1)->isPointerTy());
1039 case LibFunc_vscanf:
1040 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1041 case LibFunc_vsscanf:
1042 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1043 FTy.getParamType(2)->isPointerTy());
1044 case LibFunc_vfscanf:
1045 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
1046 FTy.getParamType(2)->isPointerTy());
1047 case LibFunc_valloc:
1048 return (FTy.getReturnType()->isPointerTy());
1049 case LibFunc_vprintf:
1050 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1051 case LibFunc_vfprintf:
1052 case LibFunc_vsprintf:
1053 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
1054 FTy.getParamType(1)->isPointerTy());
1055 case LibFunc_vsprintf_chk:
1056 return NumParams == 5 && FTy.getParamType(0)->isPointerTy() &&
1057 FTy.getParamType(1)->isIntegerTy(32) &&
1058 IsSizeTTy(FTy.getParamType(2)) && FTy.getParamType(3)->isPointerTy();
1059 case LibFunc_vsnprintf:
1060 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
1061 FTy.getParamType(2)->isPointerTy());
1062 case LibFunc_vsnprintf_chk:
1063 return NumParams == 6 && FTy.getParamType(0)->isPointerTy() &&
1064 FTy.getParamType(2)->isIntegerTy(32) &&
1065 IsSizeTTy(FTy.getParamType(3)) && FTy.getParamType(4)->isPointerTy();
1066 case LibFunc_open:
1067 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1068 case LibFunc_opendir:
1069 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
1070 FTy.getParamType(0)->isPointerTy());
1071 case LibFunc_tmpfile:
1072 return (FTy.getReturnType()->isPointerTy());
1073 case LibFunc_htonl:
1074 case LibFunc_ntohl:
1075 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1076 FTy.getReturnType() == FTy.getParamType(0));
1077 case LibFunc_htons:
1078 case LibFunc_ntohs:
1079 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
1080 FTy.getReturnType() == FTy.getParamType(0));
1081 case LibFunc_lstat:
1082 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1083 FTy.getParamType(1)->isPointerTy());
1084 case LibFunc_lchown:
1085 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1086 case LibFunc_qsort:
1087 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
1088 case LibFunc_dunder_strdup:
1089 case LibFunc_dunder_strndup:
1090 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
1091 FTy.getParamType(0)->isPointerTy());
1092 case LibFunc_dunder_strtok_r:
1093 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
1094 case LibFunc_under_IO_putc:
1095 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1096 case LibFunc_dunder_isoc99_scanf:
1097 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
1098 case LibFunc_stat64:
1099 case LibFunc_lstat64:
1100 case LibFunc_statvfs64:
1101 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1102 FTy.getParamType(1)->isPointerTy());
1103 case LibFunc_dunder_isoc99_sscanf:
1104 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
1105 FTy.getParamType(1)->isPointerTy());
1106 case LibFunc_fopen64:
1107 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1108 FTy.getParamType(0)->isPointerTy() &&
1109 FTy.getParamType(1)->isPointerTy());
1110 case LibFunc_tmpfile64:
1111 return (FTy.getReturnType()->isPointerTy());
1112 case LibFunc_fstat64:
1113 case LibFunc_fstatvfs64:
1114 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
1115 case LibFunc_open64:
1116 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
1117 case LibFunc_gettimeofday:
1118 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1119 FTy.getParamType(1)->isPointerTy());
1121 // new(unsigned int);
1122 case LibFunc_Znwj:
1123 // new(unsigned long);
1124 case LibFunc_Znwm:
1125 // new[](unsigned int);
1126 case LibFunc_Znaj:
1127 // new[](unsigned long);
1128 case LibFunc_Znam:
1129 // new(unsigned int);
1130 case LibFunc_msvc_new_int:
1131 // new(unsigned long long);
1132 case LibFunc_msvc_new_longlong:
1133 // new[](unsigned int);
1134 case LibFunc_msvc_new_array_int:
1135 // new[](unsigned long long);
1136 case LibFunc_msvc_new_array_longlong:
1137 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
1139 // new(unsigned int, nothrow);
1140 case LibFunc_ZnwjRKSt9nothrow_t:
1141 // new(unsigned long, nothrow);
1142 case LibFunc_ZnwmRKSt9nothrow_t:
1143 // new[](unsigned int, nothrow);
1144 case LibFunc_ZnajRKSt9nothrow_t:
1145 // new[](unsigned long, nothrow);
1146 case LibFunc_ZnamRKSt9nothrow_t:
1147 // new(unsigned int, nothrow);
1148 case LibFunc_msvc_new_int_nothrow:
1149 // new(unsigned long long, nothrow);
1150 case LibFunc_msvc_new_longlong_nothrow:
1151 // new[](unsigned int, nothrow);
1152 case LibFunc_msvc_new_array_int_nothrow:
1153 // new[](unsigned long long, nothrow);
1154 case LibFunc_msvc_new_array_longlong_nothrow:
1155 // new(unsigned int, align_val_t)
1156 case LibFunc_ZnwjSt11align_val_t:
1157 // new(unsigned long, align_val_t)
1158 case LibFunc_ZnwmSt11align_val_t:
1159 // new[](unsigned int, align_val_t)
1160 case LibFunc_ZnajSt11align_val_t:
1161 // new[](unsigned long, align_val_t)
1162 case LibFunc_ZnamSt11align_val_t:
1163 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
1165 // new(unsigned int, align_val_t, nothrow)
1166 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
1167 // new(unsigned long, align_val_t, nothrow)
1168 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1169 // new[](unsigned int, align_val_t, nothrow)
1170 case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
1171 // new[](unsigned long, align_val_t, nothrow)
1172 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1173 return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
1175 // void operator delete[](void*);
1176 case LibFunc_ZdaPv:
1177 // void operator delete(void*);
1178 case LibFunc_ZdlPv:
1179 // void operator delete[](void*);
1180 case LibFunc_msvc_delete_array_ptr32:
1181 // void operator delete[](void*);
1182 case LibFunc_msvc_delete_array_ptr64:
1183 // void operator delete(void*);
1184 case LibFunc_msvc_delete_ptr32:
1185 // void operator delete(void*);
1186 case LibFunc_msvc_delete_ptr64:
1187 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1189 // void operator delete[](void*, nothrow);
1190 case LibFunc_ZdaPvRKSt9nothrow_t:
1191 // void operator delete[](void*, unsigned int);
1192 case LibFunc_ZdaPvj:
1193 // void operator delete[](void*, unsigned long);
1194 case LibFunc_ZdaPvm:
1195 // void operator delete(void*, nothrow);
1196 case LibFunc_ZdlPvRKSt9nothrow_t:
1197 // void operator delete(void*, unsigned int);
1198 case LibFunc_ZdlPvj:
1199 // void operator delete(void*, unsigned long);
1200 case LibFunc_ZdlPvm:
1201 // void operator delete(void*, align_val_t)
1202 case LibFunc_ZdlPvSt11align_val_t:
1203 // void operator delete[](void*, align_val_t)
1204 case LibFunc_ZdaPvSt11align_val_t:
1205 // void operator delete[](void*, unsigned int);
1206 case LibFunc_msvc_delete_array_ptr32_int:
1207 // void operator delete[](void*, nothrow);
1208 case LibFunc_msvc_delete_array_ptr32_nothrow:
1209 // void operator delete[](void*, unsigned long long);
1210 case LibFunc_msvc_delete_array_ptr64_longlong:
1211 // void operator delete[](void*, nothrow);
1212 case LibFunc_msvc_delete_array_ptr64_nothrow:
1213 // void operator delete(void*, unsigned int);
1214 case LibFunc_msvc_delete_ptr32_int:
1215 // void operator delete(void*, nothrow);
1216 case LibFunc_msvc_delete_ptr32_nothrow:
1217 // void operator delete(void*, unsigned long long);
1218 case LibFunc_msvc_delete_ptr64_longlong:
1219 // void operator delete(void*, nothrow);
1220 case LibFunc_msvc_delete_ptr64_nothrow:
1221 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
1223 // void operator delete(void*, align_val_t, nothrow)
1224 case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
1225 // void operator delete[](void*, align_val_t, nothrow)
1226 case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
1227 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1229 case LibFunc_memset_pattern16:
1230 return (!FTy.isVarArg() && NumParams == 3 &&
1231 FTy.getParamType(0)->isPointerTy() &&
1232 FTy.getParamType(1)->isPointerTy() &&
1233 FTy.getParamType(2)->isIntegerTy());
1235 case LibFunc_cxa_guard_abort:
1236 case LibFunc_cxa_guard_acquire:
1237 case LibFunc_cxa_guard_release:
1238 case LibFunc_nvvm_reflect:
1239 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1241 case LibFunc_sincospi_stret:
1242 case LibFunc_sincospif_stret:
1243 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1245 case LibFunc_acos:
1246 case LibFunc_acos_finite:
1247 case LibFunc_acosf:
1248 case LibFunc_acosf_finite:
1249 case LibFunc_acosh:
1250 case LibFunc_acosh_finite:
1251 case LibFunc_acoshf:
1252 case LibFunc_acoshf_finite:
1253 case LibFunc_acoshl:
1254 case LibFunc_acoshl_finite:
1255 case LibFunc_acosl:
1256 case LibFunc_acosl_finite:
1257 case LibFunc_asin:
1258 case LibFunc_asin_finite:
1259 case LibFunc_asinf:
1260 case LibFunc_asinf_finite:
1261 case LibFunc_asinh:
1262 case LibFunc_asinhf:
1263 case LibFunc_asinhl:
1264 case LibFunc_asinl:
1265 case LibFunc_asinl_finite:
1266 case LibFunc_atan:
1267 case LibFunc_atanf:
1268 case LibFunc_atanh:
1269 case LibFunc_atanh_finite:
1270 case LibFunc_atanhf:
1271 case LibFunc_atanhf_finite:
1272 case LibFunc_atanhl:
1273 case LibFunc_atanhl_finite:
1274 case LibFunc_atanl:
1275 case LibFunc_cbrt:
1276 case LibFunc_cbrtf:
1277 case LibFunc_cbrtl:
1278 case LibFunc_ceil:
1279 case LibFunc_ceilf:
1280 case LibFunc_ceill:
1281 case LibFunc_cos:
1282 case LibFunc_cosf:
1283 case LibFunc_cosh:
1284 case LibFunc_cosh_finite:
1285 case LibFunc_coshf:
1286 case LibFunc_coshf_finite:
1287 case LibFunc_coshl:
1288 case LibFunc_coshl_finite:
1289 case LibFunc_cosl:
1290 case LibFunc_exp10:
1291 case LibFunc_exp10_finite:
1292 case LibFunc_exp10f:
1293 case LibFunc_exp10f_finite:
1294 case LibFunc_exp10l:
1295 case LibFunc_exp10l_finite:
1296 case LibFunc_exp2:
1297 case LibFunc_exp2_finite:
1298 case LibFunc_exp2f:
1299 case LibFunc_exp2f_finite:
1300 case LibFunc_exp2l:
1301 case LibFunc_exp2l_finite:
1302 case LibFunc_exp:
1303 case LibFunc_exp_finite:
1304 case LibFunc_expf:
1305 case LibFunc_expf_finite:
1306 case LibFunc_expl:
1307 case LibFunc_expl_finite:
1308 case LibFunc_expm1:
1309 case LibFunc_expm1f:
1310 case LibFunc_expm1l:
1311 case LibFunc_fabs:
1312 case LibFunc_fabsf:
1313 case LibFunc_fabsl:
1314 case LibFunc_floor:
1315 case LibFunc_floorf:
1316 case LibFunc_floorl:
1317 case LibFunc_log10:
1318 case LibFunc_log10_finite:
1319 case LibFunc_log10f:
1320 case LibFunc_log10f_finite:
1321 case LibFunc_log10l:
1322 case LibFunc_log10l_finite:
1323 case LibFunc_log1p:
1324 case LibFunc_log1pf:
1325 case LibFunc_log1pl:
1326 case LibFunc_log2:
1327 case LibFunc_log2_finite:
1328 case LibFunc_log2f:
1329 case LibFunc_log2f_finite:
1330 case LibFunc_log2l:
1331 case LibFunc_log2l_finite:
1332 case LibFunc_log:
1333 case LibFunc_log_finite:
1334 case LibFunc_logb:
1335 case LibFunc_logbf:
1336 case LibFunc_logbl:
1337 case LibFunc_logf:
1338 case LibFunc_logf_finite:
1339 case LibFunc_logl:
1340 case LibFunc_logl_finite:
1341 case LibFunc_nearbyint:
1342 case LibFunc_nearbyintf:
1343 case LibFunc_nearbyintl:
1344 case LibFunc_rint:
1345 case LibFunc_rintf:
1346 case LibFunc_rintl:
1347 case LibFunc_round:
1348 case LibFunc_roundf:
1349 case LibFunc_roundl:
1350 case LibFunc_sin:
1351 case LibFunc_sinf:
1352 case LibFunc_sinh:
1353 case LibFunc_sinh_finite:
1354 case LibFunc_sinhf:
1355 case LibFunc_sinhf_finite:
1356 case LibFunc_sinhl:
1357 case LibFunc_sinhl_finite:
1358 case LibFunc_sinl:
1359 case LibFunc_sqrt:
1360 case LibFunc_sqrt_finite:
1361 case LibFunc_sqrtf:
1362 case LibFunc_sqrtf_finite:
1363 case LibFunc_sqrtl:
1364 case LibFunc_sqrtl_finite:
1365 case LibFunc_tan:
1366 case LibFunc_tanf:
1367 case LibFunc_tanh:
1368 case LibFunc_tanhf:
1369 case LibFunc_tanhl:
1370 case LibFunc_tanl:
1371 case LibFunc_trunc:
1372 case LibFunc_truncf:
1373 case LibFunc_truncl:
1374 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1375 FTy.getReturnType() == FTy.getParamType(0));
1377 case LibFunc_atan2:
1378 case LibFunc_atan2_finite:
1379 case LibFunc_atan2f:
1380 case LibFunc_atan2f_finite:
1381 case LibFunc_atan2l:
1382 case LibFunc_atan2l_finite:
1383 case LibFunc_fmin:
1384 case LibFunc_fminf:
1385 case LibFunc_fminl:
1386 case LibFunc_fmax:
1387 case LibFunc_fmaxf:
1388 case LibFunc_fmaxl:
1389 case LibFunc_fmod:
1390 case LibFunc_fmodf:
1391 case LibFunc_fmodl:
1392 case LibFunc_copysign:
1393 case LibFunc_copysignf:
1394 case LibFunc_copysignl:
1395 case LibFunc_pow:
1396 case LibFunc_pow_finite:
1397 case LibFunc_powf:
1398 case LibFunc_powf_finite:
1399 case LibFunc_powl:
1400 case LibFunc_powl_finite:
1401 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1402 FTy.getReturnType() == FTy.getParamType(0) &&
1403 FTy.getReturnType() == FTy.getParamType(1));
1405 case LibFunc_ldexp:
1406 case LibFunc_ldexpf:
1407 case LibFunc_ldexpl:
1408 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1409 FTy.getReturnType() == FTy.getParamType(0) &&
1410 FTy.getParamType(1)->isIntegerTy(32));
1412 case LibFunc_ffs:
1413 case LibFunc_ffsl:
1414 case LibFunc_ffsll:
1415 case LibFunc_fls:
1416 case LibFunc_flsl:
1417 case LibFunc_flsll:
1418 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1419 FTy.getParamType(0)->isIntegerTy());
1421 case LibFunc_isdigit:
1422 case LibFunc_isascii:
1423 case LibFunc_toascii:
1424 case LibFunc_putchar:
1425 case LibFunc_putchar_unlocked:
1426 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1427 FTy.getReturnType() == FTy.getParamType(0));
1429 case LibFunc_abs:
1430 case LibFunc_labs:
1431 case LibFunc_llabs:
1432 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1433 FTy.getReturnType() == FTy.getParamType(0));
1435 case LibFunc_cxa_atexit:
1436 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1437 FTy.getParamType(0)->isPointerTy() &&
1438 FTy.getParamType(1)->isPointerTy() &&
1439 FTy.getParamType(2)->isPointerTy());
1441 case LibFunc_sinpi:
1442 case LibFunc_cospi:
1443 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1444 FTy.getReturnType() == FTy.getParamType(0));
1446 case LibFunc_sinpif:
1447 case LibFunc_cospif:
1448 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1449 FTy.getReturnType() == FTy.getParamType(0));
1451 case LibFunc_strnlen:
1452 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1453 FTy.getParamType(0) == PCharTy &&
1454 FTy.getParamType(1) == SizeTTy);
1456 case LibFunc_posix_memalign:
1457 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1458 FTy.getParamType(0)->isPointerTy() &&
1459 FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1461 case LibFunc_wcslen:
1462 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1463 FTy.getReturnType()->isIntegerTy());
1465 case LibFunc_cabs:
1466 case LibFunc_cabsf:
1467 case LibFunc_cabsl: {
1468 Type* RetTy = FTy.getReturnType();
1469 if (!RetTy->isFloatingPointTy())
1470 return false;
1472 // NOTE: These prototypes are target specific and currently support
1473 // "complex" passed as an array or discrete real & imaginary parameters.
1474 // Add other calling conventions to enable libcall optimizations.
1475 if (NumParams == 1)
1476 return (FTy.getParamType(0)->isArrayTy() &&
1477 FTy.getParamType(0)->getArrayNumElements() == 2 &&
1478 FTy.getParamType(0)->getArrayElementType() == RetTy);
1479 else if (NumParams == 2)
1480 return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1481 else
1482 return false;
1484 case LibFunc::NumLibFuncs:
1485 break;
1488 llvm_unreachable("Invalid libfunc");
1491 bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1492 LibFunc &F) const {
1493 // Intrinsics don't overlap w/libcalls; if our module has a large number of
1494 // intrinsics, this ends up being an interesting compile time win since we
1495 // avoid string normalization and comparison.
1496 if (FDecl.isIntrinsic()) return false;
1498 const DataLayout *DL =
1499 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1500 return getLibFunc(FDecl.getName(), F) &&
1501 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1504 void TargetLibraryInfoImpl::disableAllFunctions() {
1505 memset(AvailableArray, 0, sizeof(AvailableArray));
1508 static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1509 return LHS.ScalarFnName < RHS.ScalarFnName;
1512 static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1513 return LHS.VectorFnName < RHS.VectorFnName;
1516 static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1517 return LHS.ScalarFnName < S;
1520 static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
1521 return LHS.VectorFnName < S;
1524 void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1525 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1526 llvm::sort(VectorDescs, compareByScalarFnName);
1528 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1529 llvm::sort(ScalarDescs, compareByVectorFnName);
1532 void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1533 enum VectorLibrary VecLib) {
1534 switch (VecLib) {
1535 case Accelerate: {
1536 const VecDesc VecFuncs[] = {
1537 #define TLI_DEFINE_ACCELERATE_VECFUNCS
1538 #include "llvm/Analysis/VecFuncs.def"
1540 addVectorizableFunctions(VecFuncs);
1541 break;
1543 case MASSV: {
1544 const VecDesc VecFuncs[] = {
1545 #define TLI_DEFINE_MASSV_VECFUNCS
1546 #include "llvm/Analysis/VecFuncs.def"
1548 addVectorizableFunctions(VecFuncs);
1549 break;
1551 case SVML: {
1552 const VecDesc VecFuncs[] = {
1553 #define TLI_DEFINE_SVML_VECFUNCS
1554 #include "llvm/Analysis/VecFuncs.def"
1556 addVectorizableFunctions(VecFuncs);
1557 break;
1559 case NoLibrary:
1560 break;
1564 bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1565 funcName = sanitizeFunctionName(funcName);
1566 if (funcName.empty())
1567 return false;
1569 std::vector<VecDesc>::const_iterator I =
1570 llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1571 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1574 StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1575 unsigned VF) const {
1576 F = sanitizeFunctionName(F);
1577 if (F.empty())
1578 return F;
1579 std::vector<VecDesc>::const_iterator I =
1580 llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
1581 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1582 if (I->VectorizationFactor == VF)
1583 return I->VectorFnName;
1584 ++I;
1586 return StringRef();
1589 StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1590 unsigned &VF) const {
1591 F = sanitizeFunctionName(F);
1592 if (F.empty())
1593 return F;
1595 std::vector<VecDesc>::const_iterator I =
1596 llvm::lower_bound(ScalarDescs, F, compareWithVectorFnName);
1597 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1598 return StringRef();
1599 VF = I->VectorizationFactor;
1600 return I->ScalarFnName;
1603 TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1604 ModuleAnalysisManager &) {
1605 if (PresetInfoImpl)
1606 return TargetLibraryInfo(*PresetInfoImpl);
1608 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1611 TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1612 FunctionAnalysisManager &) {
1613 if (PresetInfoImpl)
1614 return TargetLibraryInfo(*PresetInfoImpl);
1616 return TargetLibraryInfo(
1617 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1620 TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
1621 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1622 Impls[T.normalize()];
1623 if (!Impl)
1624 Impl.reset(new TargetLibraryInfoImpl(T));
1626 return *Impl;
1629 unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
1630 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1631 M.getModuleFlag("wchar_size")))
1632 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1633 return 0;
1636 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1637 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
1638 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1641 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
1642 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
1643 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1646 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1647 const TargetLibraryInfoImpl &TLIImpl)
1648 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
1649 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1652 AnalysisKey TargetLibraryAnalysis::Key;
1654 // Register the basic pass.
1655 INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1656 "Target Library Information", false, true)
1657 char TargetLibraryInfoWrapperPass::ID = 0;
1659 void TargetLibraryInfoWrapperPass::anchor() {}