1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the TargetLibraryInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/TargetLibraryInfo.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/Support/CommandLine.h"
20 static cl::opt
<TargetLibraryInfoImpl::VectorLibrary
> ClVectorLibrary(
21 "vector-library", cl::Hidden
, cl::desc("Vector functions library"),
22 cl::init(TargetLibraryInfoImpl::NoLibrary
),
23 cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary
, "none",
24 "No vector functions library"),
25 clEnumValN(TargetLibraryInfoImpl::Accelerate
, "Accelerate",
26 "Accelerate framework"),
27 clEnumValN(TargetLibraryInfoImpl::SVML
, "SVML",
28 "Intel SVML library")));
30 StringRef
const TargetLibraryInfoImpl::StandardNames
[LibFunc::NumLibFuncs
] = {
31 #define TLI_DEFINE_STRING
32 #include "llvm/Analysis/TargetLibraryInfo.def"
35 static bool hasSinCosPiStret(const Triple
&T
) {
36 // Only Darwin variants have _stret versions of combined trig functions.
40 // The ABI is rather complicated on x86, so don't do anything special there.
41 if (T
.getArch() == Triple::x86
)
44 if (T
.isMacOSX() && T
.isMacOSXVersionLT(10, 9))
47 if (T
.isiOS() && T
.isOSVersionLT(7, 0))
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
) {
63 "TargetLibraryInfoImpl function names must be sorted");
65 // Set IO unlocked variants as unavailable
66 // Set them as available per system below
67 TLI
.setUnavailable(LibFunc_getchar_unlocked
);
68 TLI
.setUnavailable(LibFunc_putc_unlocked
);
69 TLI
.setUnavailable(LibFunc_putchar_unlocked
);
70 TLI
.setUnavailable(LibFunc_fputc_unlocked
);
71 TLI
.setUnavailable(LibFunc_fgetc_unlocked
);
72 TLI
.setUnavailable(LibFunc_fread_unlocked
);
73 TLI
.setUnavailable(LibFunc_fwrite_unlocked
);
74 TLI
.setUnavailable(LibFunc_fputs_unlocked
);
75 TLI
.setUnavailable(LibFunc_fgets_unlocked
);
77 bool ShouldExtI32Param
= false, ShouldExtI32Return
= false,
78 ShouldSignExtI32Param
= false;
79 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
80 // returns corresponding to C-level ints and unsigned ints.
81 if (T
.getArch() == Triple::ppc64
|| T
.getArch() == Triple::ppc64le
||
82 T
.getArch() == Triple::sparcv9
|| T
.getArch() == Triple::systemz
) {
83 ShouldExtI32Param
= true;
84 ShouldExtI32Return
= true;
86 // Mips, on the other hand, needs signext on i32 parameters corresponding
87 // to both signed and unsigned ints.
89 ShouldSignExtI32Param
= true;
91 TLI
.setShouldExtI32Param(ShouldExtI32Param
);
92 TLI
.setShouldExtI32Return(ShouldExtI32Return
);
93 TLI
.setShouldSignExtI32Param(ShouldSignExtI32Param
);
95 if (T
.getArch() == Triple::r600
||
96 T
.getArch() == Triple::amdgcn
) {
97 TLI
.setUnavailable(LibFunc_ldexp
);
98 TLI
.setUnavailable(LibFunc_ldexpf
);
99 TLI
.setUnavailable(LibFunc_ldexpl
);
100 TLI
.setUnavailable(LibFunc_exp10
);
101 TLI
.setUnavailable(LibFunc_exp10f
);
102 TLI
.setUnavailable(LibFunc_exp10l
);
103 TLI
.setUnavailable(LibFunc_log10
);
104 TLI
.setUnavailable(LibFunc_log10f
);
105 TLI
.setUnavailable(LibFunc_log10l
);
108 // There are no library implementations of mempcy and memset for AMD gpus and
109 // these can be difficult to lower in the backend.
110 if (T
.getArch() == Triple::r600
||
111 T
.getArch() == Triple::amdgcn
) {
112 TLI
.setUnavailable(LibFunc_memcpy
);
113 TLI
.setUnavailable(LibFunc_memset
);
114 TLI
.setUnavailable(LibFunc_memset_pattern16
);
118 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
119 // All versions of watchOS support it.
121 // available IO unlocked variants on Mac OS X
122 TLI
.setAvailable(LibFunc_getc_unlocked
);
123 TLI
.setAvailable(LibFunc_getchar_unlocked
);
124 TLI
.setAvailable(LibFunc_putc_unlocked
);
125 TLI
.setAvailable(LibFunc_putchar_unlocked
);
127 if (T
.isMacOSXVersionLT(10, 5))
128 TLI
.setUnavailable(LibFunc_memset_pattern16
);
129 } else if (T
.isiOS()) {
130 if (T
.isOSVersionLT(3, 0))
131 TLI
.setUnavailable(LibFunc_memset_pattern16
);
132 } else if (!T
.isWatchOS()) {
133 TLI
.setUnavailable(LibFunc_memset_pattern16
);
136 if (!hasSinCosPiStret(T
)) {
137 TLI
.setUnavailable(LibFunc_sinpi
);
138 TLI
.setUnavailable(LibFunc_sinpif
);
139 TLI
.setUnavailable(LibFunc_cospi
);
140 TLI
.setUnavailable(LibFunc_cospif
);
141 TLI
.setUnavailable(LibFunc_sincospi_stret
);
142 TLI
.setUnavailable(LibFunc_sincospif_stret
);
145 if (T
.isMacOSX() && T
.getArch() == Triple::x86
&&
146 !T
.isMacOSXVersionLT(10, 7)) {
147 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
148 // we don't care about) have two versions; on recent OSX, the one we want
149 // has a $UNIX2003 suffix. The two implementations are identical except
150 // for the return value in some edge cases. However, we don't want to
151 // generate code that depends on the old symbols.
152 TLI
.setAvailableWithName(LibFunc_fwrite
, "fwrite$UNIX2003");
153 TLI
.setAvailableWithName(LibFunc_fputs
, "fputs$UNIX2003");
156 // iprintf and friends are only available on XCore and TCE.
157 if (T
.getArch() != Triple::xcore
&& T
.getArch() != Triple::tce
) {
158 TLI
.setUnavailable(LibFunc_iprintf
);
159 TLI
.setUnavailable(LibFunc_siprintf
);
160 TLI
.setUnavailable(LibFunc_fiprintf
);
163 if (T
.isOSWindows() && !T
.isOSCygMing()) {
164 // Win32 does not support long double
165 TLI
.setUnavailable(LibFunc_acosl
);
166 TLI
.setUnavailable(LibFunc_asinl
);
167 TLI
.setUnavailable(LibFunc_atanl
);
168 TLI
.setUnavailable(LibFunc_atan2l
);
169 TLI
.setUnavailable(LibFunc_ceill
);
170 TLI
.setUnavailable(LibFunc_copysignl
);
171 TLI
.setUnavailable(LibFunc_cosl
);
172 TLI
.setUnavailable(LibFunc_coshl
);
173 TLI
.setUnavailable(LibFunc_expl
);
174 TLI
.setUnavailable(LibFunc_fabsf
); // Win32 and Win64 both lack fabsf
175 TLI
.setUnavailable(LibFunc_fabsl
);
176 TLI
.setUnavailable(LibFunc_floorl
);
177 TLI
.setUnavailable(LibFunc_fmaxl
);
178 TLI
.setUnavailable(LibFunc_fminl
);
179 TLI
.setUnavailable(LibFunc_fmodl
);
180 TLI
.setUnavailable(LibFunc_frexpl
);
181 TLI
.setUnavailable(LibFunc_ldexpf
);
182 TLI
.setUnavailable(LibFunc_ldexpl
);
183 TLI
.setUnavailable(LibFunc_logl
);
184 TLI
.setUnavailable(LibFunc_modfl
);
185 TLI
.setUnavailable(LibFunc_powl
);
186 TLI
.setUnavailable(LibFunc_sinl
);
187 TLI
.setUnavailable(LibFunc_sinhl
);
188 TLI
.setUnavailable(LibFunc_sqrtl
);
189 TLI
.setUnavailable(LibFunc_tanl
);
190 TLI
.setUnavailable(LibFunc_tanhl
);
192 // Win32 only has C89 math
193 TLI
.setUnavailable(LibFunc_acosh
);
194 TLI
.setUnavailable(LibFunc_acoshf
);
195 TLI
.setUnavailable(LibFunc_acoshl
);
196 TLI
.setUnavailable(LibFunc_asinh
);
197 TLI
.setUnavailable(LibFunc_asinhf
);
198 TLI
.setUnavailable(LibFunc_asinhl
);
199 TLI
.setUnavailable(LibFunc_atanh
);
200 TLI
.setUnavailable(LibFunc_atanhf
);
201 TLI
.setUnavailable(LibFunc_atanhl
);
202 TLI
.setUnavailable(LibFunc_cabs
);
203 TLI
.setUnavailable(LibFunc_cabsf
);
204 TLI
.setUnavailable(LibFunc_cabsl
);
205 TLI
.setUnavailable(LibFunc_cbrt
);
206 TLI
.setUnavailable(LibFunc_cbrtf
);
207 TLI
.setUnavailable(LibFunc_cbrtl
);
208 TLI
.setUnavailable(LibFunc_exp2
);
209 TLI
.setUnavailable(LibFunc_exp2f
);
210 TLI
.setUnavailable(LibFunc_exp2l
);
211 TLI
.setUnavailable(LibFunc_expm1
);
212 TLI
.setUnavailable(LibFunc_expm1f
);
213 TLI
.setUnavailable(LibFunc_expm1l
);
214 TLI
.setUnavailable(LibFunc_log2
);
215 TLI
.setUnavailable(LibFunc_log2f
);
216 TLI
.setUnavailable(LibFunc_log2l
);
217 TLI
.setUnavailable(LibFunc_log1p
);
218 TLI
.setUnavailable(LibFunc_log1pf
);
219 TLI
.setUnavailable(LibFunc_log1pl
);
220 TLI
.setUnavailable(LibFunc_logb
);
221 TLI
.setUnavailable(LibFunc_logbf
);
222 TLI
.setUnavailable(LibFunc_logbl
);
223 TLI
.setUnavailable(LibFunc_nearbyint
);
224 TLI
.setUnavailable(LibFunc_nearbyintf
);
225 TLI
.setUnavailable(LibFunc_nearbyintl
);
226 TLI
.setUnavailable(LibFunc_rint
);
227 TLI
.setUnavailable(LibFunc_rintf
);
228 TLI
.setUnavailable(LibFunc_rintl
);
229 TLI
.setUnavailable(LibFunc_round
);
230 TLI
.setUnavailable(LibFunc_roundf
);
231 TLI
.setUnavailable(LibFunc_roundl
);
232 TLI
.setUnavailable(LibFunc_trunc
);
233 TLI
.setUnavailable(LibFunc_truncf
);
234 TLI
.setUnavailable(LibFunc_truncl
);
236 // Win32 provides some C99 math with mangled names
237 TLI
.setAvailableWithName(LibFunc_copysign
, "_copysign");
239 if (T
.getArch() == Triple::x86
) {
240 // Win32 on x86 implements single-precision math functions as macros
241 TLI
.setUnavailable(LibFunc_acosf
);
242 TLI
.setUnavailable(LibFunc_asinf
);
243 TLI
.setUnavailable(LibFunc_atanf
);
244 TLI
.setUnavailable(LibFunc_atan2f
);
245 TLI
.setUnavailable(LibFunc_ceilf
);
246 TLI
.setUnavailable(LibFunc_copysignf
);
247 TLI
.setUnavailable(LibFunc_cosf
);
248 TLI
.setUnavailable(LibFunc_coshf
);
249 TLI
.setUnavailable(LibFunc_expf
);
250 TLI
.setUnavailable(LibFunc_floorf
);
251 TLI
.setUnavailable(LibFunc_fminf
);
252 TLI
.setUnavailable(LibFunc_fmaxf
);
253 TLI
.setUnavailable(LibFunc_fmodf
);
254 TLI
.setUnavailable(LibFunc_logf
);
255 TLI
.setUnavailable(LibFunc_log10f
);
256 TLI
.setUnavailable(LibFunc_modff
);
257 TLI
.setUnavailable(LibFunc_powf
);
258 TLI
.setUnavailable(LibFunc_sinf
);
259 TLI
.setUnavailable(LibFunc_sinhf
);
260 TLI
.setUnavailable(LibFunc_sqrtf
);
261 TLI
.setUnavailable(LibFunc_tanf
);
262 TLI
.setUnavailable(LibFunc_tanhf
);
265 // Win32 does *not* provide these functions, but they are
266 // generally available on POSIX-compliant systems:
267 TLI
.setUnavailable(LibFunc_access
);
268 TLI
.setUnavailable(LibFunc_bcmp
);
269 TLI
.setUnavailable(LibFunc_bcopy
);
270 TLI
.setUnavailable(LibFunc_bzero
);
271 TLI
.setUnavailable(LibFunc_chmod
);
272 TLI
.setUnavailable(LibFunc_chown
);
273 TLI
.setUnavailable(LibFunc_closedir
);
274 TLI
.setUnavailable(LibFunc_ctermid
);
275 TLI
.setUnavailable(LibFunc_fdopen
);
276 TLI
.setUnavailable(LibFunc_ffs
);
277 TLI
.setUnavailable(LibFunc_fileno
);
278 TLI
.setUnavailable(LibFunc_flockfile
);
279 TLI
.setUnavailable(LibFunc_fseeko
);
280 TLI
.setUnavailable(LibFunc_fstat
);
281 TLI
.setUnavailable(LibFunc_fstatvfs
);
282 TLI
.setUnavailable(LibFunc_ftello
);
283 TLI
.setUnavailable(LibFunc_ftrylockfile
);
284 TLI
.setUnavailable(LibFunc_funlockfile
);
285 TLI
.setUnavailable(LibFunc_getitimer
);
286 TLI
.setUnavailable(LibFunc_getlogin_r
);
287 TLI
.setUnavailable(LibFunc_getpwnam
);
288 TLI
.setUnavailable(LibFunc_gettimeofday
);
289 TLI
.setUnavailable(LibFunc_htonl
);
290 TLI
.setUnavailable(LibFunc_htons
);
291 TLI
.setUnavailable(LibFunc_lchown
);
292 TLI
.setUnavailable(LibFunc_lstat
);
293 TLI
.setUnavailable(LibFunc_memccpy
);
294 TLI
.setUnavailable(LibFunc_mkdir
);
295 TLI
.setUnavailable(LibFunc_ntohl
);
296 TLI
.setUnavailable(LibFunc_ntohs
);
297 TLI
.setUnavailable(LibFunc_open
);
298 TLI
.setUnavailable(LibFunc_opendir
);
299 TLI
.setUnavailable(LibFunc_pclose
);
300 TLI
.setUnavailable(LibFunc_popen
);
301 TLI
.setUnavailable(LibFunc_pread
);
302 TLI
.setUnavailable(LibFunc_pwrite
);
303 TLI
.setUnavailable(LibFunc_read
);
304 TLI
.setUnavailable(LibFunc_readlink
);
305 TLI
.setUnavailable(LibFunc_realpath
);
306 TLI
.setUnavailable(LibFunc_rmdir
);
307 TLI
.setUnavailable(LibFunc_setitimer
);
308 TLI
.setUnavailable(LibFunc_stat
);
309 TLI
.setUnavailable(LibFunc_statvfs
);
310 TLI
.setUnavailable(LibFunc_stpcpy
);
311 TLI
.setUnavailable(LibFunc_stpncpy
);
312 TLI
.setUnavailable(LibFunc_strcasecmp
);
313 TLI
.setUnavailable(LibFunc_strncasecmp
);
314 TLI
.setUnavailable(LibFunc_times
);
315 TLI
.setUnavailable(LibFunc_uname
);
316 TLI
.setUnavailable(LibFunc_unlink
);
317 TLI
.setUnavailable(LibFunc_unsetenv
);
318 TLI
.setUnavailable(LibFunc_utime
);
319 TLI
.setUnavailable(LibFunc_utimes
);
320 TLI
.setUnavailable(LibFunc_write
);
322 // Win32 does *not* provide provide these functions, but they are
324 TLI
.setUnavailable(LibFunc_atoll
);
325 TLI
.setUnavailable(LibFunc_frexpf
);
326 TLI
.setUnavailable(LibFunc_llabs
);
331 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
332 // and their names are __exp10 and __exp10f. exp10l is not available on
334 TLI
.setUnavailable(LibFunc_exp10l
);
335 if (T
.isMacOSXVersionLT(10, 9)) {
336 TLI
.setUnavailable(LibFunc_exp10
);
337 TLI
.setUnavailable(LibFunc_exp10f
);
339 TLI
.setAvailableWithName(LibFunc_exp10
, "__exp10");
340 TLI
.setAvailableWithName(LibFunc_exp10f
, "__exp10f");
345 case Triple::WatchOS
:
346 TLI
.setUnavailable(LibFunc_exp10l
);
347 if (!T
.isWatchOS() && (T
.isOSVersionLT(7, 0) ||
348 (T
.isOSVersionLT(9, 0) &&
349 (T
.getArch() == Triple::x86
||
350 T
.getArch() == Triple::x86_64
)))) {
351 TLI
.setUnavailable(LibFunc_exp10
);
352 TLI
.setUnavailable(LibFunc_exp10f
);
354 TLI
.setAvailableWithName(LibFunc_exp10
, "__exp10");
355 TLI
.setAvailableWithName(LibFunc_exp10f
, "__exp10f");
359 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
360 // buggy prior to glibc version 2.18. Until this version is widely deployed
361 // or we have a reasonable detection strategy, we cannot use exp10 reliably
364 // Fall through to disable all of them.
367 TLI
.setUnavailable(LibFunc_exp10
);
368 TLI
.setUnavailable(LibFunc_exp10f
);
369 TLI
.setUnavailable(LibFunc_exp10l
);
372 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
374 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
375 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
376 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
382 case Triple::WatchOS
:
383 case Triple::FreeBSD
:
387 TLI
.setUnavailable(LibFunc_ffsl
);
390 // ffsll is available on at least FreeBSD and Linux (GLIBC):
391 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
392 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
398 case Triple::WatchOS
:
399 case Triple::FreeBSD
:
403 TLI
.setUnavailable(LibFunc_ffsll
);
406 // The following functions are available on at least FreeBSD:
407 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
408 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
409 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
410 if (!T
.isOSFreeBSD()) {
411 TLI
.setUnavailable(LibFunc_fls
);
412 TLI
.setUnavailable(LibFunc_flsl
);
413 TLI
.setUnavailable(LibFunc_flsll
);
416 // The following functions are available on Linux,
417 // but Android uses bionic instead of glibc.
418 if (!T
.isOSLinux() || T
.isAndroid()) {
419 TLI
.setUnavailable(LibFunc_dunder_strdup
);
420 TLI
.setUnavailable(LibFunc_dunder_strtok_r
);
421 TLI
.setUnavailable(LibFunc_dunder_isoc99_scanf
);
422 TLI
.setUnavailable(LibFunc_dunder_isoc99_sscanf
);
423 TLI
.setUnavailable(LibFunc_under_IO_getc
);
424 TLI
.setUnavailable(LibFunc_under_IO_putc
);
425 // But, Android has memalign.
427 TLI
.setUnavailable(LibFunc_memalign
);
428 TLI
.setUnavailable(LibFunc_fopen64
);
429 TLI
.setUnavailable(LibFunc_fseeko64
);
430 TLI
.setUnavailable(LibFunc_fstat64
);
431 TLI
.setUnavailable(LibFunc_fstatvfs64
);
432 TLI
.setUnavailable(LibFunc_ftello64
);
433 TLI
.setUnavailable(LibFunc_lstat64
);
434 TLI
.setUnavailable(LibFunc_open64
);
435 TLI
.setUnavailable(LibFunc_stat64
);
436 TLI
.setUnavailable(LibFunc_statvfs64
);
437 TLI
.setUnavailable(LibFunc_tmpfile64
);
439 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
440 TLI
.setUnavailable(LibFunc_acos_finite
);
441 TLI
.setUnavailable(LibFunc_acosf_finite
);
442 TLI
.setUnavailable(LibFunc_acosl_finite
);
443 TLI
.setUnavailable(LibFunc_acosh_finite
);
444 TLI
.setUnavailable(LibFunc_acoshf_finite
);
445 TLI
.setUnavailable(LibFunc_acoshl_finite
);
446 TLI
.setUnavailable(LibFunc_asin_finite
);
447 TLI
.setUnavailable(LibFunc_asinf_finite
);
448 TLI
.setUnavailable(LibFunc_asinl_finite
);
449 TLI
.setUnavailable(LibFunc_atan2_finite
);
450 TLI
.setUnavailable(LibFunc_atan2f_finite
);
451 TLI
.setUnavailable(LibFunc_atan2l_finite
);
452 TLI
.setUnavailable(LibFunc_atanh_finite
);
453 TLI
.setUnavailable(LibFunc_atanhf_finite
);
454 TLI
.setUnavailable(LibFunc_atanhl_finite
);
455 TLI
.setUnavailable(LibFunc_cosh_finite
);
456 TLI
.setUnavailable(LibFunc_coshf_finite
);
457 TLI
.setUnavailable(LibFunc_coshl_finite
);
458 TLI
.setUnavailable(LibFunc_exp10_finite
);
459 TLI
.setUnavailable(LibFunc_exp10f_finite
);
460 TLI
.setUnavailable(LibFunc_exp10l_finite
);
461 TLI
.setUnavailable(LibFunc_exp2_finite
);
462 TLI
.setUnavailable(LibFunc_exp2f_finite
);
463 TLI
.setUnavailable(LibFunc_exp2l_finite
);
464 TLI
.setUnavailable(LibFunc_exp_finite
);
465 TLI
.setUnavailable(LibFunc_expf_finite
);
466 TLI
.setUnavailable(LibFunc_expl_finite
);
467 TLI
.setUnavailable(LibFunc_log10_finite
);
468 TLI
.setUnavailable(LibFunc_log10f_finite
);
469 TLI
.setUnavailable(LibFunc_log10l_finite
);
470 TLI
.setUnavailable(LibFunc_log2_finite
);
471 TLI
.setUnavailable(LibFunc_log2f_finite
);
472 TLI
.setUnavailable(LibFunc_log2l_finite
);
473 TLI
.setUnavailable(LibFunc_log_finite
);
474 TLI
.setUnavailable(LibFunc_logf_finite
);
475 TLI
.setUnavailable(LibFunc_logl_finite
);
476 TLI
.setUnavailable(LibFunc_pow_finite
);
477 TLI
.setUnavailable(LibFunc_powf_finite
);
478 TLI
.setUnavailable(LibFunc_powl_finite
);
479 TLI
.setUnavailable(LibFunc_sinh_finite
);
480 TLI
.setUnavailable(LibFunc_sinhf_finite
);
481 TLI
.setUnavailable(LibFunc_sinhl_finite
);
484 if ((T
.isOSLinux() && T
.isGNUEnvironment()) ||
485 (T
.isAndroid() && !T
.isAndroidVersionLT(28))) {
486 // available IO unlocked variants on GNU/Linux and Android P or later
487 TLI
.setAvailable(LibFunc_getc_unlocked
);
488 TLI
.setAvailable(LibFunc_getchar_unlocked
);
489 TLI
.setAvailable(LibFunc_putc_unlocked
);
490 TLI
.setAvailable(LibFunc_putchar_unlocked
);
491 TLI
.setAvailable(LibFunc_fputc_unlocked
);
492 TLI
.setAvailable(LibFunc_fgetc_unlocked
);
493 TLI
.setAvailable(LibFunc_fread_unlocked
);
494 TLI
.setAvailable(LibFunc_fwrite_unlocked
);
495 TLI
.setAvailable(LibFunc_fputs_unlocked
);
496 TLI
.setAvailable(LibFunc_fgets_unlocked
);
499 // As currently implemented in clang, NVPTX code has no standard library to
500 // speak of. Headers provide a standard-ish library implementation, but many
501 // of the signatures are wrong -- for example, many libm functions are not
504 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
505 // but only used functions are provided to llvm. Moreover, most of the
506 // functions in libdevice don't map precisely to standard library functions.
508 // FIXME: Having no standard library prevents e.g. many fastmath
509 // optimizations, so this situation should be fixed.
511 TLI
.disableAllFunctions();
512 TLI
.setAvailable(LibFunc_nvvm_reflect
);
514 TLI
.setUnavailable(LibFunc_nvvm_reflect
);
517 TLI
.addVectorizableFunctionsFromVecLib(ClVectorLibrary
);
520 TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
521 // Default to everything being available.
522 memset(AvailableArray
, -1, sizeof(AvailableArray
));
524 initialize(*this, Triple(), StandardNames
);
527 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple
&T
) {
528 // Default to everything being available.
529 memset(AvailableArray
, -1, sizeof(AvailableArray
));
531 initialize(*this, T
, StandardNames
);
534 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl
&TLI
)
535 : CustomNames(TLI
.CustomNames
), ShouldExtI32Param(TLI
.ShouldExtI32Param
),
536 ShouldExtI32Return(TLI
.ShouldExtI32Return
),
537 ShouldSignExtI32Param(TLI
.ShouldSignExtI32Param
) {
538 memcpy(AvailableArray
, TLI
.AvailableArray
, sizeof(AvailableArray
));
539 VectorDescs
= TLI
.VectorDescs
;
540 ScalarDescs
= TLI
.ScalarDescs
;
543 TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl
&&TLI
)
544 : CustomNames(std::move(TLI
.CustomNames
)),
545 ShouldExtI32Param(TLI
.ShouldExtI32Param
),
546 ShouldExtI32Return(TLI
.ShouldExtI32Return
),
547 ShouldSignExtI32Param(TLI
.ShouldSignExtI32Param
) {
548 std::move(std::begin(TLI
.AvailableArray
), std::end(TLI
.AvailableArray
),
550 VectorDescs
= TLI
.VectorDescs
;
551 ScalarDescs
= TLI
.ScalarDescs
;
554 TargetLibraryInfoImpl
&TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl
&TLI
) {
555 CustomNames
= TLI
.CustomNames
;
556 ShouldExtI32Param
= TLI
.ShouldExtI32Param
;
557 ShouldExtI32Return
= TLI
.ShouldExtI32Return
;
558 ShouldSignExtI32Param
= TLI
.ShouldSignExtI32Param
;
559 memcpy(AvailableArray
, TLI
.AvailableArray
, sizeof(AvailableArray
));
563 TargetLibraryInfoImpl
&TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl
&&TLI
) {
564 CustomNames
= std::move(TLI
.CustomNames
);
565 ShouldExtI32Param
= TLI
.ShouldExtI32Param
;
566 ShouldExtI32Return
= TLI
.ShouldExtI32Return
;
567 ShouldSignExtI32Param
= TLI
.ShouldSignExtI32Param
;
568 std::move(std::begin(TLI
.AvailableArray
), std::end(TLI
.AvailableArray
),
573 static StringRef
sanitizeFunctionName(StringRef funcName
) {
574 // Filter out empty names and names containing null bytes, those can't be in
576 if (funcName
.empty() || funcName
.find('\0') != StringRef::npos
)
579 // Check for \01 prefix that is used to mangle __asm declarations and
580 // strip it if present.
581 return GlobalValue::dropLLVMManglingEscape(funcName
);
584 bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName
,
586 StringRef
const *Start
= &StandardNames
[0];
587 StringRef
const *End
= &StandardNames
[NumLibFuncs
];
589 funcName
= sanitizeFunctionName(funcName
);
590 if (funcName
.empty())
593 StringRef
const *I
= std::lower_bound(
594 Start
, End
, funcName
, [](StringRef LHS
, StringRef RHS
) {
597 if (I
!= End
&& *I
== funcName
) {
598 F
= (LibFunc
)(I
- Start
);
604 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType
&FTy
,
606 const DataLayout
*DL
) const {
607 LLVMContext
&Ctx
= FTy
.getContext();
608 Type
*PCharTy
= Type::getInt8PtrTy(Ctx
);
609 Type
*SizeTTy
= DL
? DL
->getIntPtrType(Ctx
, /*AS=*/0) : nullptr;
610 auto IsSizeTTy
= [SizeTTy
](Type
*Ty
) {
611 return SizeTTy
? Ty
== SizeTTy
: Ty
->isIntegerTy();
613 unsigned NumParams
= FTy
.getNumParams();
617 return (NumParams
== 1 && FTy
.getParamType(0)->isPointerTy() &&
618 FTy
.getReturnType()->isIntegerTy());
621 case LibFunc_strrchr
:
622 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
623 FTy
.getParamType(0) == FTy
.getReturnType() &&
624 FTy
.getParamType(1)->isIntegerTy());
629 case LibFunc_strtoul
:
630 case LibFunc_strtoll
:
631 case LibFunc_strtold
:
632 case LibFunc_strtoull
:
633 return ((NumParams
== 2 || NumParams
== 3) &&
634 FTy
.getParamType(0)->isPointerTy() &&
635 FTy
.getParamType(1)->isPointerTy());
637 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
638 FTy
.getParamType(0) == FTy
.getReturnType() &&
639 FTy
.getParamType(1) == FTy
.getReturnType());
641 case LibFunc_strncat
:
642 return (NumParams
== 3 && FTy
.getReturnType()->isPointerTy() &&
643 FTy
.getParamType(0) == FTy
.getReturnType() &&
644 FTy
.getParamType(1) == FTy
.getReturnType() &&
645 IsSizeTTy(FTy
.getParamType(2)));
647 case LibFunc_strcpy_chk
:
648 case LibFunc_stpcpy_chk
:
650 if (!IsSizeTTy(FTy
.getParamType(NumParams
)))
655 return (NumParams
== 2 && FTy
.getReturnType() == FTy
.getParamType(0) &&
656 FTy
.getParamType(0) == FTy
.getParamType(1) &&
657 FTy
.getParamType(0) == PCharTy
);
659 case LibFunc_strncpy_chk
:
660 case LibFunc_stpncpy_chk
:
662 if (!IsSizeTTy(FTy
.getParamType(NumParams
)))
665 case LibFunc_strncpy
:
666 case LibFunc_stpncpy
:
667 return (NumParams
== 3 && FTy
.getReturnType() == FTy
.getParamType(0) &&
668 FTy
.getParamType(0) == FTy
.getParamType(1) &&
669 FTy
.getParamType(0) == PCharTy
&&
670 IsSizeTTy(FTy
.getParamType(2)));
672 case LibFunc_strxfrm
:
673 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy() &&
674 FTy
.getParamType(1)->isPointerTy());
677 return (NumParams
== 2 && FTy
.getReturnType()->isIntegerTy(32) &&
678 FTy
.getParamType(0)->isPointerTy() &&
679 FTy
.getParamType(0) == FTy
.getParamType(1));
681 case LibFunc_strncmp
:
682 return (NumParams
== 3 && FTy
.getReturnType()->isIntegerTy(32) &&
683 FTy
.getParamType(0)->isPointerTy() &&
684 FTy
.getParamType(0) == FTy
.getParamType(1) &&
685 IsSizeTTy(FTy
.getParamType(2)));
688 case LibFunc_strcspn
:
689 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy() &&
690 FTy
.getParamType(0) == FTy
.getParamType(1) &&
691 FTy
.getReturnType()->isIntegerTy());
693 case LibFunc_strcoll
:
694 case LibFunc_strcasecmp
:
695 case LibFunc_strncasecmp
:
696 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
697 FTy
.getParamType(1)->isPointerTy());
700 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
701 FTy
.getParamType(0)->isPointerTy() &&
702 FTy
.getParamType(1)->isPointerTy());
704 case LibFunc_strpbrk
:
705 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy() &&
706 FTy
.getReturnType() == FTy
.getParamType(0) &&
707 FTy
.getParamType(0) == FTy
.getParamType(1));
710 case LibFunc_strtok_r
:
711 return (NumParams
>= 2 && FTy
.getParamType(1)->isPointerTy());
714 case LibFunc_setvbuf
:
715 return (NumParams
>= 1 && FTy
.getParamType(0)->isPointerTy());
717 case LibFunc_strndup
:
718 return (NumParams
>= 1 && FTy
.getReturnType()->isPointerTy() &&
719 FTy
.getParamType(0)->isPointerTy());
722 case LibFunc_statvfs
:
723 case LibFunc_siprintf
:
724 case LibFunc_sprintf
:
725 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
726 FTy
.getParamType(1)->isPointerTy() &&
727 FTy
.getReturnType()->isIntegerTy(32));
728 case LibFunc_snprintf
:
729 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy() &&
730 FTy
.getParamType(2)->isPointerTy() &&
731 FTy
.getReturnType()->isIntegerTy(32));
732 case LibFunc_setitimer
:
733 return (NumParams
== 3 && FTy
.getParamType(1)->isPointerTy() &&
734 FTy
.getParamType(2)->isPointerTy());
736 return (NumParams
== 1 && FTy
.getParamType(0)->isPointerTy());
738 return (NumParams
== 1 && FTy
.getReturnType()->isPointerTy());
740 return (NumParams
== 3 && FTy
.getReturnType()->isIntegerTy(32) &&
741 FTy
.getParamType(0)->isPointerTy() &&
742 FTy
.getParamType(1)->isPointerTy());
745 case LibFunc_memrchr
:
746 return (NumParams
== 3 && FTy
.getReturnType()->isPointerTy() &&
747 FTy
.getReturnType() == FTy
.getParamType(0) &&
748 FTy
.getParamType(1)->isIntegerTy(32) &&
749 IsSizeTTy(FTy
.getParamType(2)));
753 return (NumParams
>= 2 && FTy
.getParamType(1)->isPointerTy());
755 case LibFunc_memcpy_chk
:
756 case LibFunc_memmove_chk
:
758 if (!IsSizeTTy(FTy
.getParamType(NumParams
)))
762 case LibFunc_mempcpy
:
763 case LibFunc_memmove
:
764 return (NumParams
== 3 && FTy
.getReturnType() == FTy
.getParamType(0) &&
765 FTy
.getParamType(0)->isPointerTy() &&
766 FTy
.getParamType(1)->isPointerTy() &&
767 IsSizeTTy(FTy
.getParamType(2)));
769 case LibFunc_memset_chk
:
771 if (!IsSizeTTy(FTy
.getParamType(NumParams
)))
775 return (NumParams
== 3 && FTy
.getReturnType() == FTy
.getParamType(0) &&
776 FTy
.getParamType(0)->isPointerTy() &&
777 FTy
.getParamType(1)->isIntegerTy() &&
778 IsSizeTTy(FTy
.getParamType(2)));
780 case LibFunc_memccpy
:
781 return (NumParams
>= 2 && FTy
.getParamType(1)->isPointerTy());
782 case LibFunc_memalign
:
783 return (FTy
.getReturnType()->isPointerTy());
784 case LibFunc_realloc
:
785 case LibFunc_reallocf
:
786 return (NumParams
== 2 && FTy
.getReturnType() == PCharTy
&&
787 FTy
.getParamType(0) == FTy
.getReturnType() &&
788 IsSizeTTy(FTy
.getParamType(1)));
790 return (NumParams
== 3 && FTy
.getParamType(1)->isPointerTy());
794 case LibFunc_realpath
:
795 return (NumParams
>= 1 && FTy
.getParamType(0)->isPointerTy());
797 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
798 FTy
.getParamType(1)->isPointerTy());
799 case LibFunc_readlink
:
800 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
801 FTy
.getParamType(1)->isPointerTy());
803 return (NumParams
== 3 && FTy
.getParamType(1)->isPointerTy());
806 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy() &&
807 FTy
.getParamType(1)->isPointerTy());
809 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy());
811 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy());
819 case LibFunc_getpwnam
:
820 case LibFunc_iprintf
:
826 case LibFunc_under_IO_getc
:
828 case LibFunc_unsetenv
:
829 return (NumParams
== 1 && FTy
.getParamType(0)->isPointerTy());
834 case LibFunc_clearerr
:
835 case LibFunc_closedir
:
836 case LibFunc_ctermid
:
841 case LibFunc_fgetc_unlocked
:
843 case LibFunc_flockfile
:
846 case LibFunc_fseeko64
:
848 case LibFunc_fsetpos
:
850 case LibFunc_ftello64
:
852 case LibFunc_ftrylockfile
:
853 case LibFunc_funlockfile
:
855 case LibFunc_getc_unlocked
:
856 case LibFunc_getlogin_r
:
860 return (NumParams
!= 0 && FTy
.getParamType(0)->isPointerTy());
863 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
864 FTy
.getParamType(0)->isPointerTy() &&
865 FTy
.getParamType(1)->isPointerTy());
867 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
868 FTy
.getParamType(1)->isPointerTy());
870 case LibFunc_fputc_unlocked
:
875 case LibFunc_fstatvfs
:
876 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
878 case LibFunc_fgets_unlocked
:
879 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy() &&
880 FTy
.getParamType(2)->isPointerTy());
882 case LibFunc_fread_unlocked
:
883 return (NumParams
== 4 && FTy
.getParamType(0)->isPointerTy() &&
884 FTy
.getParamType(3)->isPointerTy());
886 case LibFunc_fwrite_unlocked
:
887 return (NumParams
== 4 && FTy
.getReturnType()->isIntegerTy() &&
888 FTy
.getParamType(0)->isPointerTy() &&
889 FTy
.getParamType(1)->isIntegerTy() &&
890 FTy
.getParamType(2)->isIntegerTy() &&
891 FTy
.getParamType(3)->isPointerTy());
893 case LibFunc_fputs_unlocked
:
894 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
895 FTy
.getParamType(1)->isPointerTy());
897 case LibFunc_fiprintf
:
898 case LibFunc_fprintf
:
899 return (NumParams
>= 2 && FTy
.getReturnType()->isIntegerTy() &&
900 FTy
.getParamType(0)->isPointerTy() &&
901 FTy
.getParamType(1)->isPointerTy());
902 case LibFunc_fgetpos
:
903 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
904 FTy
.getParamType(1)->isPointerTy());
905 case LibFunc_getchar
:
906 case LibFunc_getchar_unlocked
:
907 return (NumParams
== 0 && FTy
.getReturnType()->isIntegerTy());
909 return (NumParams
== 1 && FTy
.getParamType(0) == PCharTy
);
910 case LibFunc_getitimer
:
911 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
913 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
916 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy() &&
917 FTy
.getParamType(1)->isPointerTy());
919 case LibFunc_putc_unlocked
:
920 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
923 return (NumParams
== 4 && FTy
.getParamType(1)->isPointerTy());
925 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
926 FTy
.getParamType(0)->isPointerTy() &&
927 FTy
.getParamType(1)->isPointerTy());
929 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
930 case LibFunc_vsscanf
:
931 return (NumParams
== 3 && FTy
.getParamType(1)->isPointerTy() &&
932 FTy
.getParamType(2)->isPointerTy());
933 case LibFunc_vfscanf
:
934 return (NumParams
== 3 && FTy
.getParamType(1)->isPointerTy() &&
935 FTy
.getParamType(2)->isPointerTy());
937 return (FTy
.getReturnType()->isPointerTy());
938 case LibFunc_vprintf
:
939 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy());
940 case LibFunc_vfprintf
:
941 case LibFunc_vsprintf
:
942 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy() &&
943 FTy
.getParamType(1)->isPointerTy());
944 case LibFunc_vsnprintf
:
945 return (NumParams
== 4 && FTy
.getParamType(0)->isPointerTy() &&
946 FTy
.getParamType(2)->isPointerTy());
948 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy());
949 case LibFunc_opendir
:
950 return (NumParams
== 1 && FTy
.getReturnType()->isPointerTy() &&
951 FTy
.getParamType(0)->isPointerTy());
952 case LibFunc_tmpfile
:
953 return (FTy
.getReturnType()->isPointerTy());
956 return (NumParams
== 1 && FTy
.getReturnType()->isIntegerTy(32) &&
957 FTy
.getReturnType() == FTy
.getParamType(0));
960 return (NumParams
== 1 && FTy
.getReturnType()->isIntegerTy(16) &&
961 FTy
.getReturnType() == FTy
.getParamType(0));
963 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy() &&
964 FTy
.getParamType(1)->isPointerTy());
966 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy());
968 return (NumParams
== 4 && FTy
.getParamType(3)->isPointerTy());
969 case LibFunc_dunder_strdup
:
970 case LibFunc_dunder_strndup
:
971 return (NumParams
>= 1 && FTy
.getReturnType()->isPointerTy() &&
972 FTy
.getParamType(0)->isPointerTy());
973 case LibFunc_dunder_strtok_r
:
974 return (NumParams
== 3 && FTy
.getParamType(1)->isPointerTy());
975 case LibFunc_under_IO_putc
:
976 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
977 case LibFunc_dunder_isoc99_scanf
:
978 return (NumParams
>= 1 && FTy
.getParamType(0)->isPointerTy());
980 case LibFunc_lstat64
:
981 case LibFunc_statvfs64
:
982 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy() &&
983 FTy
.getParamType(1)->isPointerTy());
984 case LibFunc_dunder_isoc99_sscanf
:
985 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy() &&
986 FTy
.getParamType(1)->isPointerTy());
987 case LibFunc_fopen64
:
988 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy() &&
989 FTy
.getParamType(0)->isPointerTy() &&
990 FTy
.getParamType(1)->isPointerTy());
991 case LibFunc_tmpfile64
:
992 return (FTy
.getReturnType()->isPointerTy());
993 case LibFunc_fstat64
:
994 case LibFunc_fstatvfs64
:
995 return (NumParams
== 2 && FTy
.getParamType(1)->isPointerTy());
997 return (NumParams
>= 2 && FTy
.getParamType(0)->isPointerTy());
998 case LibFunc_gettimeofday
:
999 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy() &&
1000 FTy
.getParamType(1)->isPointerTy());
1002 // new(unsigned int);
1004 // new(unsigned long);
1006 // new[](unsigned int);
1008 // new[](unsigned long);
1010 // new(unsigned int);
1011 case LibFunc_msvc_new_int
:
1012 // new(unsigned long long);
1013 case LibFunc_msvc_new_longlong
:
1014 // new[](unsigned int);
1015 case LibFunc_msvc_new_array_int
:
1016 // new[](unsigned long long);
1017 case LibFunc_msvc_new_array_longlong
:
1018 return (NumParams
== 1 && FTy
.getReturnType()->isPointerTy());
1020 // new(unsigned int, nothrow);
1021 case LibFunc_ZnwjRKSt9nothrow_t
:
1022 // new(unsigned long, nothrow);
1023 case LibFunc_ZnwmRKSt9nothrow_t
:
1024 // new[](unsigned int, nothrow);
1025 case LibFunc_ZnajRKSt9nothrow_t
:
1026 // new[](unsigned long, nothrow);
1027 case LibFunc_ZnamRKSt9nothrow_t
:
1028 // new(unsigned int, nothrow);
1029 case LibFunc_msvc_new_int_nothrow
:
1030 // new(unsigned long long, nothrow);
1031 case LibFunc_msvc_new_longlong_nothrow
:
1032 // new[](unsigned int, nothrow);
1033 case LibFunc_msvc_new_array_int_nothrow
:
1034 // new[](unsigned long long, nothrow);
1035 case LibFunc_msvc_new_array_longlong_nothrow
:
1036 // new(unsigned int, align_val_t)
1037 case LibFunc_ZnwjSt11align_val_t
:
1038 // new(unsigned long, align_val_t)
1039 case LibFunc_ZnwmSt11align_val_t
:
1040 // new[](unsigned int, align_val_t)
1041 case LibFunc_ZnajSt11align_val_t
:
1042 // new[](unsigned long, align_val_t)
1043 case LibFunc_ZnamSt11align_val_t
:
1044 return (NumParams
== 2 && FTy
.getReturnType()->isPointerTy());
1046 // new(unsigned int, align_val_t, nothrow)
1047 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t
:
1048 // new(unsigned long, align_val_t, nothrow)
1049 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t
:
1050 // new[](unsigned int, align_val_t, nothrow)
1051 case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t
:
1052 // new[](unsigned long, align_val_t, nothrow)
1053 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t
:
1054 return (NumParams
== 3 && FTy
.getReturnType()->isPointerTy());
1056 // void operator delete[](void*);
1058 // void operator delete(void*);
1060 // void operator delete[](void*);
1061 case LibFunc_msvc_delete_array_ptr32
:
1062 // void operator delete[](void*);
1063 case LibFunc_msvc_delete_array_ptr64
:
1064 // void operator delete(void*);
1065 case LibFunc_msvc_delete_ptr32
:
1066 // void operator delete(void*);
1067 case LibFunc_msvc_delete_ptr64
:
1068 return (NumParams
== 1 && FTy
.getParamType(0)->isPointerTy());
1070 // void operator delete[](void*, nothrow);
1071 case LibFunc_ZdaPvRKSt9nothrow_t
:
1072 // void operator delete[](void*, unsigned int);
1073 case LibFunc_ZdaPvj
:
1074 // void operator delete[](void*, unsigned long);
1075 case LibFunc_ZdaPvm
:
1076 // void operator delete(void*, nothrow);
1077 case LibFunc_ZdlPvRKSt9nothrow_t
:
1078 // void operator delete(void*, unsigned int);
1079 case LibFunc_ZdlPvj
:
1080 // void operator delete(void*, unsigned long);
1081 case LibFunc_ZdlPvm
:
1082 // void operator delete(void*, align_val_t)
1083 case LibFunc_ZdlPvSt11align_val_t
:
1084 // void operator delete[](void*, align_val_t)
1085 case LibFunc_ZdaPvSt11align_val_t
:
1086 // void operator delete[](void*, unsigned int);
1087 case LibFunc_msvc_delete_array_ptr32_int
:
1088 // void operator delete[](void*, nothrow);
1089 case LibFunc_msvc_delete_array_ptr32_nothrow
:
1090 // void operator delete[](void*, unsigned long long);
1091 case LibFunc_msvc_delete_array_ptr64_longlong
:
1092 // void operator delete[](void*, nothrow);
1093 case LibFunc_msvc_delete_array_ptr64_nothrow
:
1094 // void operator delete(void*, unsigned int);
1095 case LibFunc_msvc_delete_ptr32_int
:
1096 // void operator delete(void*, nothrow);
1097 case LibFunc_msvc_delete_ptr32_nothrow
:
1098 // void operator delete(void*, unsigned long long);
1099 case LibFunc_msvc_delete_ptr64_longlong
:
1100 // void operator delete(void*, nothrow);
1101 case LibFunc_msvc_delete_ptr64_nothrow
:
1102 return (NumParams
== 2 && FTy
.getParamType(0)->isPointerTy());
1104 // void operator delete(void*, align_val_t, nothrow)
1105 case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t
:
1106 // void operator delete[](void*, align_val_t, nothrow)
1107 case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t
:
1108 return (NumParams
== 3 && FTy
.getParamType(0)->isPointerTy());
1110 case LibFunc_memset_pattern16
:
1111 return (!FTy
.isVarArg() && NumParams
== 3 &&
1112 FTy
.getParamType(0)->isPointerTy() &&
1113 FTy
.getParamType(1)->isPointerTy() &&
1114 FTy
.getParamType(2)->isIntegerTy());
1116 case LibFunc_cxa_guard_abort
:
1117 case LibFunc_cxa_guard_acquire
:
1118 case LibFunc_cxa_guard_release
:
1119 case LibFunc_nvvm_reflect
:
1120 return (NumParams
== 1 && FTy
.getParamType(0)->isPointerTy());
1122 case LibFunc_sincospi_stret
:
1123 case LibFunc_sincospif_stret
:
1124 return (NumParams
== 1 && FTy
.getParamType(0)->isFloatingPointTy());
1127 case LibFunc_acos_finite
:
1129 case LibFunc_acosf_finite
:
1131 case LibFunc_acosh_finite
:
1132 case LibFunc_acoshf
:
1133 case LibFunc_acoshf_finite
:
1134 case LibFunc_acoshl
:
1135 case LibFunc_acoshl_finite
:
1137 case LibFunc_acosl_finite
:
1139 case LibFunc_asin_finite
:
1141 case LibFunc_asinf_finite
:
1143 case LibFunc_asinhf
:
1144 case LibFunc_asinhl
:
1146 case LibFunc_asinl_finite
:
1150 case LibFunc_atanh_finite
:
1151 case LibFunc_atanhf
:
1152 case LibFunc_atanhf_finite
:
1153 case LibFunc_atanhl
:
1154 case LibFunc_atanhl_finite
:
1165 case LibFunc_cosh_finite
:
1167 case LibFunc_coshf_finite
:
1169 case LibFunc_coshl_finite
:
1172 case LibFunc_exp10_finite
:
1173 case LibFunc_exp10f
:
1174 case LibFunc_exp10f_finite
:
1175 case LibFunc_exp10l
:
1176 case LibFunc_exp10l_finite
:
1178 case LibFunc_exp2_finite
:
1180 case LibFunc_exp2f_finite
:
1182 case LibFunc_exp2l_finite
:
1184 case LibFunc_exp_finite
:
1186 case LibFunc_expf_finite
:
1188 case LibFunc_expl_finite
:
1190 case LibFunc_expm1f
:
1191 case LibFunc_expm1l
:
1196 case LibFunc_floorf
:
1197 case LibFunc_floorl
:
1199 case LibFunc_log10_finite
:
1200 case LibFunc_log10f
:
1201 case LibFunc_log10f_finite
:
1202 case LibFunc_log10l
:
1203 case LibFunc_log10l_finite
:
1205 case LibFunc_log1pf
:
1206 case LibFunc_log1pl
:
1208 case LibFunc_log2_finite
:
1210 case LibFunc_log2f_finite
:
1212 case LibFunc_log2l_finite
:
1214 case LibFunc_log_finite
:
1219 case LibFunc_logf_finite
:
1221 case LibFunc_logl_finite
:
1222 case LibFunc_nearbyint
:
1223 case LibFunc_nearbyintf
:
1224 case LibFunc_nearbyintl
:
1229 case LibFunc_roundf
:
1230 case LibFunc_roundl
:
1234 case LibFunc_sinh_finite
:
1236 case LibFunc_sinhf_finite
:
1238 case LibFunc_sinhl_finite
:
1241 case LibFunc_sqrt_finite
:
1243 case LibFunc_sqrtf_finite
:
1245 case LibFunc_sqrtl_finite
:
1253 case LibFunc_truncf
:
1254 case LibFunc_truncl
:
1255 return (NumParams
== 1 && FTy
.getReturnType()->isFloatingPointTy() &&
1256 FTy
.getReturnType() == FTy
.getParamType(0));
1259 case LibFunc_atan2_finite
:
1260 case LibFunc_atan2f
:
1261 case LibFunc_atan2f_finite
:
1262 case LibFunc_atan2l
:
1263 case LibFunc_atan2l_finite
:
1273 case LibFunc_copysign
:
1274 case LibFunc_copysignf
:
1275 case LibFunc_copysignl
:
1277 case LibFunc_pow_finite
:
1279 case LibFunc_powf_finite
:
1281 case LibFunc_powl_finite
:
1282 return (NumParams
== 2 && FTy
.getReturnType()->isFloatingPointTy() &&
1283 FTy
.getReturnType() == FTy
.getParamType(0) &&
1284 FTy
.getReturnType() == FTy
.getParamType(1));
1287 case LibFunc_ldexpf
:
1288 case LibFunc_ldexpl
:
1289 return (NumParams
== 2 && FTy
.getReturnType()->isFloatingPointTy() &&
1290 FTy
.getReturnType() == FTy
.getParamType(0) &&
1291 FTy
.getParamType(1)->isIntegerTy(32));
1299 return (NumParams
== 1 && FTy
.getReturnType()->isIntegerTy(32) &&
1300 FTy
.getParamType(0)->isIntegerTy());
1302 case LibFunc_isdigit
:
1303 case LibFunc_isascii
:
1304 case LibFunc_toascii
:
1305 case LibFunc_putchar
:
1306 case LibFunc_putchar_unlocked
:
1307 return (NumParams
== 1 && FTy
.getReturnType()->isIntegerTy(32) &&
1308 FTy
.getReturnType() == FTy
.getParamType(0));
1313 return (NumParams
== 1 && FTy
.getReturnType()->isIntegerTy() &&
1314 FTy
.getReturnType() == FTy
.getParamType(0));
1316 case LibFunc_cxa_atexit
:
1317 return (NumParams
== 3 && FTy
.getReturnType()->isIntegerTy() &&
1318 FTy
.getParamType(0)->isPointerTy() &&
1319 FTy
.getParamType(1)->isPointerTy() &&
1320 FTy
.getParamType(2)->isPointerTy());
1324 return (NumParams
== 1 && FTy
.getReturnType()->isDoubleTy() &&
1325 FTy
.getReturnType() == FTy
.getParamType(0));
1327 case LibFunc_sinpif
:
1328 case LibFunc_cospif
:
1329 return (NumParams
== 1 && FTy
.getReturnType()->isFloatTy() &&
1330 FTy
.getReturnType() == FTy
.getParamType(0));
1332 case LibFunc_strnlen
:
1333 return (NumParams
== 2 && FTy
.getReturnType() == FTy
.getParamType(1) &&
1334 FTy
.getParamType(0) == PCharTy
&&
1335 FTy
.getParamType(1) == SizeTTy
);
1337 case LibFunc_posix_memalign
:
1338 return (NumParams
== 3 && FTy
.getReturnType()->isIntegerTy(32) &&
1339 FTy
.getParamType(0)->isPointerTy() &&
1340 FTy
.getParamType(1) == SizeTTy
&& FTy
.getParamType(2) == SizeTTy
);
1342 case LibFunc_wcslen
:
1343 return (NumParams
== 1 && FTy
.getParamType(0)->isPointerTy() &&
1344 FTy
.getReturnType()->isIntegerTy());
1348 case LibFunc_cabsl
: {
1349 Type
* RetTy
= FTy
.getReturnType();
1350 if (!RetTy
->isFloatingPointTy())
1353 // NOTE: These prototypes are target specific and currently support
1354 // "complex" passed as an array or discrete real & imaginary parameters.
1355 // Add other calling conventions to enable libcall optimizations.
1357 return (FTy
.getParamType(0)->isArrayTy() &&
1358 FTy
.getParamType(0)->getArrayNumElements() == 2 &&
1359 FTy
.getParamType(0)->getArrayElementType() == RetTy
);
1360 else if (NumParams
== 2)
1361 return (FTy
.getParamType(0) == RetTy
&& FTy
.getParamType(1) == RetTy
);
1365 case LibFunc::NumLibFuncs
:
1369 llvm_unreachable("Invalid libfunc");
1372 bool TargetLibraryInfoImpl::getLibFunc(const Function
&FDecl
,
1374 const DataLayout
*DL
=
1375 FDecl
.getParent() ? &FDecl
.getParent()->getDataLayout() : nullptr;
1376 return getLibFunc(FDecl
.getName(), F
) &&
1377 isValidProtoForLibFunc(*FDecl
.getFunctionType(), F
, DL
);
1380 void TargetLibraryInfoImpl::disableAllFunctions() {
1381 memset(AvailableArray
, 0, sizeof(AvailableArray
));
1384 static bool compareByScalarFnName(const VecDesc
&LHS
, const VecDesc
&RHS
) {
1385 return LHS
.ScalarFnName
< RHS
.ScalarFnName
;
1388 static bool compareByVectorFnName(const VecDesc
&LHS
, const VecDesc
&RHS
) {
1389 return LHS
.VectorFnName
< RHS
.VectorFnName
;
1392 static bool compareWithScalarFnName(const VecDesc
&LHS
, StringRef S
) {
1393 return LHS
.ScalarFnName
< S
;
1396 static bool compareWithVectorFnName(const VecDesc
&LHS
, StringRef S
) {
1397 return LHS
.VectorFnName
< S
;
1400 void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef
<VecDesc
> Fns
) {
1401 VectorDescs
.insert(VectorDescs
.end(), Fns
.begin(), Fns
.end());
1402 llvm::sort(VectorDescs
, compareByScalarFnName
);
1404 ScalarDescs
.insert(ScalarDescs
.end(), Fns
.begin(), Fns
.end());
1405 llvm::sort(ScalarDescs
, compareByVectorFnName
);
1408 void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1409 enum VectorLibrary VecLib
) {
1412 const VecDesc VecFuncs
[] = {
1413 // Floating-Point Arithmetic and Auxiliary Functions
1414 {"ceilf", "vceilf", 4},
1415 {"fabsf", "vfabsf", 4},
1416 {"llvm.fabs.f32", "vfabsf", 4},
1417 {"floorf", "vfloorf", 4},
1418 {"sqrtf", "vsqrtf", 4},
1419 {"llvm.sqrt.f32", "vsqrtf", 4},
1421 // Exponential and Logarithmic Functions
1422 {"expf", "vexpf", 4},
1423 {"llvm.exp.f32", "vexpf", 4},
1424 {"expm1f", "vexpm1f", 4},
1425 {"logf", "vlogf", 4},
1426 {"llvm.log.f32", "vlogf", 4},
1427 {"log1pf", "vlog1pf", 4},
1428 {"log10f", "vlog10f", 4},
1429 {"llvm.log10.f32", "vlog10f", 4},
1430 {"logbf", "vlogbf", 4},
1432 // Trigonometric Functions
1433 {"sinf", "vsinf", 4},
1434 {"llvm.sin.f32", "vsinf", 4},
1435 {"cosf", "vcosf", 4},
1436 {"llvm.cos.f32", "vcosf", 4},
1437 {"tanf", "vtanf", 4},
1438 {"asinf", "vasinf", 4},
1439 {"acosf", "vacosf", 4},
1440 {"atanf", "vatanf", 4},
1442 // Hyperbolic Functions
1443 {"sinhf", "vsinhf", 4},
1444 {"coshf", "vcoshf", 4},
1445 {"tanhf", "vtanhf", 4},
1446 {"asinhf", "vasinhf", 4},
1447 {"acoshf", "vacoshf", 4},
1448 {"atanhf", "vatanhf", 4},
1450 addVectorizableFunctions(VecFuncs
);
1454 const VecDesc VecFuncs
[] = {
1455 {"sin", "__svml_sin2", 2},
1456 {"sin", "__svml_sin4", 4},
1457 {"sin", "__svml_sin8", 8},
1459 {"sinf", "__svml_sinf4", 4},
1460 {"sinf", "__svml_sinf8", 8},
1461 {"sinf", "__svml_sinf16", 16},
1463 {"llvm.sin.f64", "__svml_sin2", 2},
1464 {"llvm.sin.f64", "__svml_sin4", 4},
1465 {"llvm.sin.f64", "__svml_sin8", 8},
1467 {"llvm.sin.f32", "__svml_sinf4", 4},
1468 {"llvm.sin.f32", "__svml_sinf8", 8},
1469 {"llvm.sin.f32", "__svml_sinf16", 16},
1471 {"cos", "__svml_cos2", 2},
1472 {"cos", "__svml_cos4", 4},
1473 {"cos", "__svml_cos8", 8},
1475 {"cosf", "__svml_cosf4", 4},
1476 {"cosf", "__svml_cosf8", 8},
1477 {"cosf", "__svml_cosf16", 16},
1479 {"llvm.cos.f64", "__svml_cos2", 2},
1480 {"llvm.cos.f64", "__svml_cos4", 4},
1481 {"llvm.cos.f64", "__svml_cos8", 8},
1483 {"llvm.cos.f32", "__svml_cosf4", 4},
1484 {"llvm.cos.f32", "__svml_cosf8", 8},
1485 {"llvm.cos.f32", "__svml_cosf16", 16},
1487 {"pow", "__svml_pow2", 2},
1488 {"pow", "__svml_pow4", 4},
1489 {"pow", "__svml_pow8", 8},
1491 {"powf", "__svml_powf4", 4},
1492 {"powf", "__svml_powf8", 8},
1493 {"powf", "__svml_powf16", 16},
1495 { "__pow_finite", "__svml_pow2", 2 },
1496 { "__pow_finite", "__svml_pow4", 4 },
1497 { "__pow_finite", "__svml_pow8", 8 },
1499 { "__powf_finite", "__svml_powf4", 4 },
1500 { "__powf_finite", "__svml_powf8", 8 },
1501 { "__powf_finite", "__svml_powf16", 16 },
1503 {"llvm.pow.f64", "__svml_pow2", 2},
1504 {"llvm.pow.f64", "__svml_pow4", 4},
1505 {"llvm.pow.f64", "__svml_pow8", 8},
1507 {"llvm.pow.f32", "__svml_powf4", 4},
1508 {"llvm.pow.f32", "__svml_powf8", 8},
1509 {"llvm.pow.f32", "__svml_powf16", 16},
1511 {"exp", "__svml_exp2", 2},
1512 {"exp", "__svml_exp4", 4},
1513 {"exp", "__svml_exp8", 8},
1515 {"expf", "__svml_expf4", 4},
1516 {"expf", "__svml_expf8", 8},
1517 {"expf", "__svml_expf16", 16},
1519 { "__exp_finite", "__svml_exp2", 2 },
1520 { "__exp_finite", "__svml_exp4", 4 },
1521 { "__exp_finite", "__svml_exp8", 8 },
1523 { "__expf_finite", "__svml_expf4", 4 },
1524 { "__expf_finite", "__svml_expf8", 8 },
1525 { "__expf_finite", "__svml_expf16", 16 },
1527 {"llvm.exp.f64", "__svml_exp2", 2},
1528 {"llvm.exp.f64", "__svml_exp4", 4},
1529 {"llvm.exp.f64", "__svml_exp8", 8},
1531 {"llvm.exp.f32", "__svml_expf4", 4},
1532 {"llvm.exp.f32", "__svml_expf8", 8},
1533 {"llvm.exp.f32", "__svml_expf16", 16},
1535 {"log", "__svml_log2", 2},
1536 {"log", "__svml_log4", 4},
1537 {"log", "__svml_log8", 8},
1539 {"logf", "__svml_logf4", 4},
1540 {"logf", "__svml_logf8", 8},
1541 {"logf", "__svml_logf16", 16},
1543 { "__log_finite", "__svml_log2", 2 },
1544 { "__log_finite", "__svml_log4", 4 },
1545 { "__log_finite", "__svml_log8", 8 },
1547 { "__logf_finite", "__svml_logf4", 4 },
1548 { "__logf_finite", "__svml_logf8", 8 },
1549 { "__logf_finite", "__svml_logf16", 16 },
1551 {"llvm.log.f64", "__svml_log2", 2},
1552 {"llvm.log.f64", "__svml_log4", 4},
1553 {"llvm.log.f64", "__svml_log8", 8},
1555 {"llvm.log.f32", "__svml_logf4", 4},
1556 {"llvm.log.f32", "__svml_logf8", 8},
1557 {"llvm.log.f32", "__svml_logf16", 16},
1559 addVectorizableFunctions(VecFuncs
);
1567 bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName
) const {
1568 funcName
= sanitizeFunctionName(funcName
);
1569 if (funcName
.empty())
1572 std::vector
<VecDesc
>::const_iterator I
= std::lower_bound(
1573 VectorDescs
.begin(), VectorDescs
.end(), funcName
,
1574 compareWithScalarFnName
);
1575 return I
!= VectorDescs
.end() && StringRef(I
->ScalarFnName
) == funcName
;
1578 StringRef
TargetLibraryInfoImpl::getVectorizedFunction(StringRef F
,
1579 unsigned VF
) const {
1580 F
= sanitizeFunctionName(F
);
1583 std::vector
<VecDesc
>::const_iterator I
= std::lower_bound(
1584 VectorDescs
.begin(), VectorDescs
.end(), F
, compareWithScalarFnName
);
1585 while (I
!= VectorDescs
.end() && StringRef(I
->ScalarFnName
) == F
) {
1586 if (I
->VectorizationFactor
== VF
)
1587 return I
->VectorFnName
;
1593 StringRef
TargetLibraryInfoImpl::getScalarizedFunction(StringRef F
,
1594 unsigned &VF
) const {
1595 F
= sanitizeFunctionName(F
);
1599 std::vector
<VecDesc
>::const_iterator I
= std::lower_bound(
1600 ScalarDescs
.begin(), ScalarDescs
.end(), F
, compareWithVectorFnName
);
1601 if (I
== VectorDescs
.end() || StringRef(I
->VectorFnName
) != F
)
1603 VF
= I
->VectorizationFactor
;
1604 return I
->ScalarFnName
;
1607 TargetLibraryInfo
TargetLibraryAnalysis::run(Module
&M
,
1608 ModuleAnalysisManager
&) {
1610 return TargetLibraryInfo(*PresetInfoImpl
);
1612 return TargetLibraryInfo(lookupInfoImpl(Triple(M
.getTargetTriple())));
1615 TargetLibraryInfo
TargetLibraryAnalysis::run(Function
&F
,
1616 FunctionAnalysisManager
&) {
1618 return TargetLibraryInfo(*PresetInfoImpl
);
1620 return TargetLibraryInfo(
1621 lookupInfoImpl(Triple(F
.getParent()->getTargetTriple())));
1624 TargetLibraryInfoImpl
&TargetLibraryAnalysis::lookupInfoImpl(const Triple
&T
) {
1625 std::unique_ptr
<TargetLibraryInfoImpl
> &Impl
=
1626 Impls
[T
.normalize()];
1628 Impl
.reset(new TargetLibraryInfoImpl(T
));
1633 unsigned TargetLibraryInfoImpl::getWCharSize(const Module
&M
) const {
1634 if (auto *ShortWChar
= cast_or_null
<ConstantAsMetadata
>(
1635 M
.getModuleFlag("wchar_size")))
1636 return cast
<ConstantInt
>(ShortWChar
->getValue())->getZExtValue();
1640 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1641 : ImmutablePass(ID
), TLIImpl(), TLI(TLIImpl
) {
1642 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1645 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple
&T
)
1646 : ImmutablePass(ID
), TLIImpl(T
), TLI(TLIImpl
) {
1647 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1650 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1651 const TargetLibraryInfoImpl
&TLIImpl
)
1652 : ImmutablePass(ID
), TLIImpl(TLIImpl
), TLI(this->TLIImpl
) {
1653 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1656 AnalysisKey
TargetLibraryAnalysis::Key
;
1658 // Register the basic pass.
1659 INITIALIZE_PASS(TargetLibraryInfoWrapperPass
, "targetlibinfo",
1660 "Target Library Information", false, true)
1661 char TargetLibraryInfoWrapperPass::ID
= 0;
1663 void TargetLibraryInfoWrapperPass::anchor() {}