LLVM 22.0.0git
TargetLibraryInfo.cpp
Go to the documentation of this file.
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.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/DenseMap.h"
16#include "llvm/IR/Constants.h"
17#include "llvm/IR/Module.h"
21using namespace llvm;
22
24 "vector-library", cl::Hidden, cl::desc("Vector functions library"),
27 "No vector functions library"),
29 "Accelerate framework"),
31 "Darwin_libsystem_m", "Darwin libsystem_m"),
33 "GLIBC Vector Math library"),
35 "IBM MASS vector library"),
37 "Intel SVML library"),
39 "SIMD Library for Evaluating Elementary Functions"),
41 "Arm Performance Libraries"),
43 "AMD vector math library")));
44
45StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
46 {
47#define TLI_DEFINE_STRING
48#include "llvm/Analysis/TargetLibraryInfo.def"
49};
50
52 assert(!VectorFnName.empty() && "Vector function name must not be empty.");
53 SmallString<256> Buffer;
54 llvm::raw_svector_ostream Out(Buffer);
55 Out << VABIPrefix << "_" << ScalarFnName << "(" << VectorFnName << ")";
56 return std::string(Out.str());
57}
58
59// Recognized types of library function arguments and return types.
60enum FuncArgTypeID : char {
61 Void = 0, // Must be zero.
62 Bool, // 8 bits on all targets
66 IntPlus, // Int or bigger.
67 Long, // Either 32 or 64 bits.
68 IntX, // Any integer type.
70 LLong, // 64 bits on all targets.
71 SizeT, // size_t.
72 SSizeT, // POSIX ssize_t.
73 Flt, // IEEE float.
74 Dbl, // IEEE double.
75 LDbl, // Any floating type (TODO: tighten this up).
76 Floating, // Any floating type.
77 Ptr, // Any pointer type.
78 Struct, // Any struct type.
79 Ellip, // The ellipsis (...).
80 Same, // Same argument type as the previous one.
81};
82
83typedef std::array<FuncArgTypeID, 8> FuncProtoTy;
84
85static const FuncProtoTy Signatures[] = {
86#define TLI_DEFINE_SIG
87#include "llvm/Analysis/TargetLibraryInfo.def"
88};
89
90static_assert(sizeof Signatures / sizeof *Signatures == LibFunc::NumLibFuncs,
91 "Missing library function signatures");
92
93static bool hasSinCosPiStret(const Triple &T) {
94 // Only Darwin variants have _stret versions of combined trig functions.
95 if (!T.isOSDarwin())
96 return false;
97
98 // The ABI is rather complicated on x86, so don't do anything special there.
99 if (T.getArch() == Triple::x86)
100 return false;
101
102 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
103 return false;
104
105 if (T.isiOS() && T.isOSVersionLT(7, 0))
106 return false;
107
108 return true;
109}
110
111static bool hasBcmp(const Triple &TT) {
112 // Posix removed support from bcmp() in 2001, but the glibc and several
113 // implementations of the libc still have it.
114 if (TT.isOSLinux())
115 return TT.isGNUEnvironment() || TT.isMusl();
116 // Both NetBSD and OpenBSD are planning to remove the function. Windows does
117 // not have it.
118 return TT.isOSFreeBSD() || TT.isOSSolaris();
119}
120
122 FunctionType *FuncTy) {
123 switch (CC) {
124 default:
125 return false;
127 return true;
131
132 // The iOS ABI diverges from the standard in some cases, so for now don't
133 // try to simplify those calls.
134 if (TT.isiOS())
135 return false;
136
137 if (!FuncTy->getReturnType()->isPointerTy() &&
138 !FuncTy->getReturnType()->isIntegerTy() &&
139 !FuncTy->getReturnType()->isVoidTy())
140 return false;
141
142 for (auto *Param : FuncTy->params()) {
143 if (!Param->isPointerTy() && !Param->isIntegerTy())
144 return false;
145 }
146 return true;
147 }
148 }
149 return false;
150}
151
153 return ::isCallingConvCCompatible(CI->getCallingConv(),
154 CI->getModule()->getTargetTriple(),
155 CI->getFunctionType());
156}
157
159 return ::isCallingConvCCompatible(F->getCallingConv(),
160 F->getParent()->getTargetTriple(),
161 F->getFunctionType());
162}
163
164static void initializeBase(TargetLibraryInfoImpl &TLI, const Triple &T) {
165 bool ShouldExtI32Param, ShouldExtI32Return;
166 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
168 ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param,
169 ShouldSignExtI32Return, T);
170 TLI.setShouldExtI32Param(ShouldExtI32Param);
171 TLI.setShouldExtI32Return(ShouldExtI32Return);
172 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
173 TLI.setShouldSignExtI32Return(ShouldSignExtI32Return);
174
175 // Let's assume by default that the size of int is 32 bits, unless the target
176 // is a 16-bit architecture because then it most likely is 16 bits. If that
177 // isn't true for a target those defaults should be overridden below.
178 TLI.setIntSize(T.isArch16Bit() ? 16 : 32);
179}
180
181/// Initialize the set of available library functions based on the specified
182/// target triple. This should be carefully written so that a missing target
183/// triple gets a sane set of defaults.
185 ArrayRef<StringLiteral> StandardNames) {
186 // Set IO unlocked variants as unavailable
187 // Set them as available per system below
188 TLI.setUnavailable(LibFunc_getc_unlocked);
189 TLI.setUnavailable(LibFunc_getchar_unlocked);
190 TLI.setUnavailable(LibFunc_putc_unlocked);
191 TLI.setUnavailable(LibFunc_putchar_unlocked);
192 TLI.setUnavailable(LibFunc_fputc_unlocked);
193 TLI.setUnavailable(LibFunc_fgetc_unlocked);
194 TLI.setUnavailable(LibFunc_fread_unlocked);
195 TLI.setUnavailable(LibFunc_fwrite_unlocked);
196 TLI.setUnavailable(LibFunc_fputs_unlocked);
197 TLI.setUnavailable(LibFunc_fgets_unlocked);
198
199 // There is really no runtime library on AMDGPU, apart from
200 // __kmpc_alloc/free_shared.
201 if (T.isAMDGPU()) {
203 TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
204 TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
205 return;
206 }
207
208 // DXIL does not support libcalls, and disabling them here prevents a number
209 // of passes from introducing libcalls into DXIL which would otherwise
210 // complicate lowering/legalization
211 if (T.isDXIL()) {
213 return;
214 }
215
216 // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and
217 // later. All versions of watchOS support it.
218 if (T.isMacOSX()) {
219 // available IO unlocked variants on Mac OS X
220 TLI.setAvailable(LibFunc_getc_unlocked);
221 TLI.setAvailable(LibFunc_getchar_unlocked);
222 TLI.setAvailable(LibFunc_putc_unlocked);
223 TLI.setAvailable(LibFunc_putchar_unlocked);
224 TLI.setUnavailable(LibFunc_memrchr);
225
226 if (T.isMacOSXVersionLT(10, 5)) {
227 TLI.setUnavailable(LibFunc_memset_pattern4);
228 TLI.setUnavailable(LibFunc_memset_pattern8);
229 TLI.setUnavailable(LibFunc_memset_pattern16);
230 }
231 } else if (T.isiOS()) {
232 if (T.isOSVersionLT(3, 0)) {
233 TLI.setUnavailable(LibFunc_memset_pattern4);
234 TLI.setUnavailable(LibFunc_memset_pattern8);
235 TLI.setUnavailable(LibFunc_memset_pattern16);
236 }
237 } else if (!T.isWatchOS()) {
238 TLI.setUnavailable(LibFunc_memset_pattern4);
239 TLI.setUnavailable(LibFunc_memset_pattern8);
240 TLI.setUnavailable(LibFunc_memset_pattern16);
241 }
242
243 if (!hasSinCosPiStret(T)) {
244 TLI.setUnavailable(LibFunc_sinpi);
245 TLI.setUnavailable(LibFunc_sinpif);
246 TLI.setUnavailable(LibFunc_cospi);
247 TLI.setUnavailable(LibFunc_cospif);
248 TLI.setUnavailable(LibFunc_sincospi_stret);
249 TLI.setUnavailable(LibFunc_sincospif_stret);
250 }
251
252 if (!hasBcmp(T))
253 TLI.setUnavailable(LibFunc_bcmp);
254
255 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
256 !T.isMacOSXVersionLT(10, 7)) {
257 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
258 // we don't care about) have two versions; on recent OSX, the one we want
259 // has a $UNIX2003 suffix. The two implementations are identical except
260 // for the return value in some edge cases. However, we don't want to
261 // generate code that depends on the old symbols.
262 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
263 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
264 }
265
266 // iprintf and friends are only available on XCore, TCE, and Emscripten.
267 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
268 T.getOS() != Triple::Emscripten) {
269 TLI.setUnavailable(LibFunc_iprintf);
270 TLI.setUnavailable(LibFunc_siprintf);
271 TLI.setUnavailable(LibFunc_fiprintf);
272 }
273
274 // __small_printf and friends are only available on Emscripten.
275 if (T.getOS() != Triple::Emscripten) {
276 TLI.setUnavailable(LibFunc_small_printf);
277 TLI.setUnavailable(LibFunc_small_sprintf);
278 TLI.setUnavailable(LibFunc_small_fprintf);
279 }
280
281 if (T.isOSWindows() && !T.isOSCygMing()) {
282 // XXX: The earliest documentation available at the moment is for VS2015/VC19:
283 // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
284 // XXX: In order to use an MSVCRT older than VC19,
285 // the specific library version must be explicit in the target triple,
286 // e.g., x86_64-pc-windows-msvc18.
287 bool hasPartialC99 = true;
288 if (T.isKnownWindowsMSVCEnvironment()) {
289 VersionTuple Version = T.getEnvironmentVersion();
290 hasPartialC99 = (Version.getMajor() == 0 || Version.getMajor() >= 19);
291 }
292
293 // Latest targets support C89 math functions, in part.
294 bool isARM = (T.getArch() == Triple::aarch64 ||
295 T.getArch() == Triple::arm);
296 bool hasPartialFloat = (isARM ||
297 T.getArch() == Triple::x86_64);
298
299 // Win32 does not support float C89 math functions, in general.
300 if (!hasPartialFloat) {
301 TLI.setUnavailable(LibFunc_acosf);
302 TLI.setUnavailable(LibFunc_asinf);
303 TLI.setUnavailable(LibFunc_atan2f);
304 TLI.setUnavailable(LibFunc_atanf);
305 TLI.setUnavailable(LibFunc_ceilf);
306 TLI.setUnavailable(LibFunc_cosf);
307 TLI.setUnavailable(LibFunc_coshf);
308 TLI.setUnavailable(LibFunc_expf);
309 TLI.setUnavailable(LibFunc_floorf);
310 TLI.setUnavailable(LibFunc_fmodf);
311 TLI.setUnavailable(LibFunc_hypotf);
312 TLI.setUnavailable(LibFunc_log10f);
313 TLI.setUnavailable(LibFunc_logf);
314 TLI.setUnavailable(LibFunc_modff);
315 TLI.setUnavailable(LibFunc_powf);
316 TLI.setUnavailable(LibFunc_remainderf);
317 TLI.setUnavailable(LibFunc_remquof);
318 TLI.setUnavailable(LibFunc_fdimf);
319 TLI.setUnavailable(LibFunc_sinf);
320 TLI.setUnavailable(LibFunc_sinhf);
321 TLI.setUnavailable(LibFunc_sqrtf);
322 TLI.setUnavailable(LibFunc_tanf);
323 TLI.setUnavailable(LibFunc_tanhf);
324 }
325 if (!isARM)
326 TLI.setUnavailable(LibFunc_fabsf);
327 TLI.setUnavailable(LibFunc_frexpf);
328 TLI.setUnavailable(LibFunc_ldexpf);
329
330 // Win32 does not support long double C89 math functions.
331 TLI.setUnavailable(LibFunc_acosl);
332 TLI.setUnavailable(LibFunc_asinl);
333 TLI.setUnavailable(LibFunc_atan2l);
334 TLI.setUnavailable(LibFunc_atanl);
335 TLI.setUnavailable(LibFunc_ceill);
336 TLI.setUnavailable(LibFunc_cosl);
337 TLI.setUnavailable(LibFunc_coshl);
338 TLI.setUnavailable(LibFunc_expl);
339 TLI.setUnavailable(LibFunc_fabsl);
340 TLI.setUnavailable(LibFunc_floorl);
341 TLI.setUnavailable(LibFunc_fmodl);
342 TLI.setUnavailable(LibFunc_frexpl);
343 TLI.setUnavailable(LibFunc_hypotl);
344 TLI.setUnavailable(LibFunc_ldexpl);
345 TLI.setUnavailable(LibFunc_log10l);
346 TLI.setUnavailable(LibFunc_logl);
347 TLI.setUnavailable(LibFunc_modfl);
348 TLI.setUnavailable(LibFunc_powl);
349 TLI.setUnavailable(LibFunc_remainderl);
350 TLI.setUnavailable(LibFunc_remquol);
351 TLI.setUnavailable(LibFunc_fdiml);
352 TLI.setUnavailable(LibFunc_sinl);
353 TLI.setUnavailable(LibFunc_sinhl);
354 TLI.setUnavailable(LibFunc_sqrtl);
355 TLI.setUnavailable(LibFunc_tanl);
356 TLI.setUnavailable(LibFunc_tanhl);
357
358 // Win32 does not fully support C99 math functions.
359 if (!hasPartialC99) {
360 TLI.setUnavailable(LibFunc_acosh);
361 TLI.setUnavailable(LibFunc_acoshf);
362 TLI.setUnavailable(LibFunc_asinh);
363 TLI.setUnavailable(LibFunc_asinhf);
364 TLI.setUnavailable(LibFunc_atanh);
365 TLI.setUnavailable(LibFunc_atanhf);
366 TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
367 TLI.setUnavailable(LibFunc_cabsf);
368 TLI.setUnavailable(LibFunc_cbrt);
369 TLI.setUnavailable(LibFunc_cbrtf);
370 TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
371 TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
372 TLI.setUnavailable(LibFunc_exp2);
373 TLI.setUnavailable(LibFunc_exp2f);
374 TLI.setUnavailable(LibFunc_expm1);
375 TLI.setUnavailable(LibFunc_expm1f);
376 TLI.setUnavailable(LibFunc_fmax);
377 TLI.setUnavailable(LibFunc_fmaxf);
378 TLI.setUnavailable(LibFunc_fmin);
379 TLI.setUnavailable(LibFunc_fminf);
380 TLI.setUnavailable(LibFunc_log1p);
381 TLI.setUnavailable(LibFunc_log1pf);
382 TLI.setUnavailable(LibFunc_log2);
383 TLI.setUnavailable(LibFunc_log2f);
384 TLI.setAvailableWithName(LibFunc_logb, "_logb");
385 TLI.setUnavailable(LibFunc_ilogb);
386 TLI.setUnavailable(LibFunc_ilogbf);
387 if (hasPartialFloat)
388 TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
389 else
390 TLI.setUnavailable(LibFunc_logbf);
391 TLI.setUnavailable(LibFunc_nextafter);
392 TLI.setUnavailable(LibFunc_nextafterf);
393 TLI.setUnavailable(LibFunc_nexttoward);
394 TLI.setUnavailable(LibFunc_nexttowardf);
395 TLI.setUnavailable(LibFunc_rint);
396 TLI.setUnavailable(LibFunc_rintf);
397 TLI.setUnavailable(LibFunc_round);
398 TLI.setUnavailable(LibFunc_roundf);
399 TLI.setUnavailable(LibFunc_scalbln);
400 TLI.setUnavailable(LibFunc_scalblnf);
401 TLI.setUnavailable(LibFunc_scalblnl);
402 TLI.setUnavailable(LibFunc_scalbn);
403 TLI.setUnavailable(LibFunc_scalbnf);
404 TLI.setUnavailable(LibFunc_scalbnl);
405 TLI.setUnavailable(LibFunc_trunc);
406 TLI.setUnavailable(LibFunc_truncf);
407 }
408
409 // Win32 does not support long double C99 math functions.
410 TLI.setUnavailable(LibFunc_acoshl);
411 TLI.setUnavailable(LibFunc_asinhl);
412 TLI.setUnavailable(LibFunc_atanhl);
413 TLI.setUnavailable(LibFunc_cabsl);
414 TLI.setUnavailable(LibFunc_cbrtl);
415 TLI.setUnavailable(LibFunc_copysignl);
416 TLI.setUnavailable(LibFunc_exp2l);
417 TLI.setUnavailable(LibFunc_expm1l);
418 TLI.setUnavailable(LibFunc_fmaxl);
419 TLI.setUnavailable(LibFunc_fminl);
420 TLI.setUnavailable(LibFunc_log1pl);
421 TLI.setUnavailable(LibFunc_log2l);
422 TLI.setUnavailable(LibFunc_logbl);
423 TLI.setUnavailable(LibFunc_ilogbl);
424 TLI.setUnavailable(LibFunc_nearbyintl);
425 TLI.setUnavailable(LibFunc_nextafterl);
426 TLI.setUnavailable(LibFunc_nexttowardl);
427 TLI.setUnavailable(LibFunc_rintl);
428 TLI.setUnavailable(LibFunc_roundl);
429 TLI.setUnavailable(LibFunc_scalblnl);
430 TLI.setUnavailable(LibFunc_scalbnl);
431 TLI.setUnavailable(LibFunc_truncl);
432
433 // Win32 does not support these functions, but
434 // they are generally available on POSIX-compliant systems.
435 TLI.setUnavailable(LibFunc_access);
436 TLI.setUnavailable(LibFunc_chmod);
437 TLI.setUnavailable(LibFunc_closedir);
438 TLI.setUnavailable(LibFunc_fdopen);
439 TLI.setUnavailable(LibFunc_fileno);
440 TLI.setUnavailable(LibFunc_fseeko);
441 TLI.setUnavailable(LibFunc_fstat);
442 TLI.setUnavailable(LibFunc_ftello);
443 TLI.setUnavailable(LibFunc_gettimeofday);
444 TLI.setUnavailable(LibFunc_memccpy);
445 TLI.setUnavailable(LibFunc_mkdir);
446 TLI.setUnavailable(LibFunc_open);
447 TLI.setUnavailable(LibFunc_opendir);
448 TLI.setUnavailable(LibFunc_pclose);
449 TLI.setUnavailable(LibFunc_popen);
450 TLI.setUnavailable(LibFunc_read);
451 TLI.setUnavailable(LibFunc_rmdir);
452 TLI.setUnavailable(LibFunc_stat);
453 TLI.setUnavailable(LibFunc_strcasecmp);
454 TLI.setUnavailable(LibFunc_strncasecmp);
455 TLI.setUnavailable(LibFunc_unlink);
456 TLI.setUnavailable(LibFunc_utime);
457 TLI.setUnavailable(LibFunc_write);
458 }
459
460 if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) {
461 // These functions aren't available in either MSVC or MinGW environments.
462 TLI.setUnavailable(LibFunc_bcmp);
463 TLI.setUnavailable(LibFunc_bcopy);
464 TLI.setUnavailable(LibFunc_bzero);
465 TLI.setUnavailable(LibFunc_chown);
466 TLI.setUnavailable(LibFunc_ctermid);
467 TLI.setUnavailable(LibFunc_ffs);
468 TLI.setUnavailable(LibFunc_flockfile);
469 TLI.setUnavailable(LibFunc_fstatvfs);
470 TLI.setUnavailable(LibFunc_ftrylockfile);
471 TLI.setUnavailable(LibFunc_funlockfile);
472 TLI.setUnavailable(LibFunc_getitimer);
473 TLI.setUnavailable(LibFunc_getlogin_r);
474 TLI.setUnavailable(LibFunc_getpwnam);
475 TLI.setUnavailable(LibFunc_htonl);
476 TLI.setUnavailable(LibFunc_htons);
477 TLI.setUnavailable(LibFunc_lchown);
478 TLI.setUnavailable(LibFunc_lstat);
479 TLI.setUnavailable(LibFunc_memrchr);
480 TLI.setUnavailable(LibFunc_ntohl);
481 TLI.setUnavailable(LibFunc_ntohs);
482 TLI.setUnavailable(LibFunc_pread);
483 TLI.setUnavailable(LibFunc_pwrite);
484 TLI.setUnavailable(LibFunc_readlink);
485 TLI.setUnavailable(LibFunc_realpath);
486 TLI.setUnavailable(LibFunc_setitimer);
487 TLI.setUnavailable(LibFunc_statvfs);
488 TLI.setUnavailable(LibFunc_stpcpy);
489 TLI.setUnavailable(LibFunc_stpncpy);
490 TLI.setUnavailable(LibFunc_times);
491 TLI.setUnavailable(LibFunc_uname);
492 TLI.setUnavailable(LibFunc_unsetenv);
493 TLI.setUnavailable(LibFunc_utimes);
494
495 // MinGW does have ldexpf, but it is a plain wrapper over regular ldexp.
496 // Therefore it's not beneficial to transform code to use it, i.e.
497 // just pretend that the function is not available.
498 TLI.setUnavailable(LibFunc_ldexpf);
499 }
500
501 // Pick just one set of new/delete variants.
502 if (T.isOSMSVCRT()) {
503 // MSVC, doesn't have the Itanium new/delete.
504 TLI.setUnavailable(LibFunc_ZdaPv);
505 TLI.setUnavailable(LibFunc_ZdaPvRKSt9nothrow_t);
506 TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_t);
507 TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t);
508 TLI.setUnavailable(LibFunc_ZdaPvj);
509 TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
510 TLI.setUnavailable(LibFunc_ZdaPvm);
511 TLI.setUnavailable(LibFunc_ZdaPvmSt11align_val_t);
512 TLI.setUnavailable(LibFunc_ZdlPv);
513 TLI.setUnavailable(LibFunc_ZdlPvRKSt9nothrow_t);
514 TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_t);
515 TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t);
516 TLI.setUnavailable(LibFunc_ZdlPvj);
517 TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
518 TLI.setUnavailable(LibFunc_ZdlPvm);
519 TLI.setUnavailable(LibFunc_ZdlPvmSt11align_val_t);
520 TLI.setUnavailable(LibFunc_Znaj);
521 TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
522 TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
523 TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
524 TLI.setUnavailable(LibFunc_Znam);
525 TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t);
526 TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t);
527 TLI.setUnavailable(LibFunc_ZnamSt11align_val_t);
528 TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t);
529 TLI.setUnavailable(LibFunc_Znwj);
530 TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
531 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
532 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
533 TLI.setUnavailable(LibFunc_Znwm);
534 TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t);
535 TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t);
536 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t);
537 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t);
538 TLI.setUnavailable(LibFunc_Znwm12__hot_cold_t);
539 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t12__hot_cold_t);
540 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
541 TLI.setUnavailable(LibFunc_Znam12__hot_cold_t);
542 TLI.setUnavailable(LibFunc_ZnamSt11align_val_t12__hot_cold_t);
543 TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
544 TLI.setUnavailable(LibFunc_size_returning_new);
545 TLI.setUnavailable(LibFunc_size_returning_new_hot_cold);
546 TLI.setUnavailable(LibFunc_size_returning_new_aligned);
547 TLI.setUnavailable(LibFunc_size_returning_new_aligned_hot_cold);
548 } else {
549 // Not MSVC, assume it's Itanium.
550 TLI.setUnavailable(LibFunc_msvc_new_int);
551 TLI.setUnavailable(LibFunc_msvc_new_int_nothrow);
552 TLI.setUnavailable(LibFunc_msvc_new_longlong);
553 TLI.setUnavailable(LibFunc_msvc_new_longlong_nothrow);
554 TLI.setUnavailable(LibFunc_msvc_delete_ptr32);
555 TLI.setUnavailable(LibFunc_msvc_delete_ptr32_nothrow);
556 TLI.setUnavailable(LibFunc_msvc_delete_ptr32_int);
557 TLI.setUnavailable(LibFunc_msvc_delete_ptr64);
558 TLI.setUnavailable(LibFunc_msvc_delete_ptr64_nothrow);
559 TLI.setUnavailable(LibFunc_msvc_delete_ptr64_longlong);
560 TLI.setUnavailable(LibFunc_msvc_new_array_int);
561 TLI.setUnavailable(LibFunc_msvc_new_array_int_nothrow);
562 TLI.setUnavailable(LibFunc_msvc_new_array_longlong);
563 TLI.setUnavailable(LibFunc_msvc_new_array_longlong_nothrow);
564 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32);
565 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_nothrow);
566 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_int);
567 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64);
568 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_nothrow);
569 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_longlong);
570 }
571
572 switch (T.getOS()) {
573 case Triple::MacOSX:
574 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
575 // and their names are __exp10 and __exp10f. exp10l is not available on
576 // OS X or iOS.
577 TLI.setUnavailable(LibFunc_exp10l);
578 if (T.isMacOSXVersionLT(10, 9)) {
579 TLI.setUnavailable(LibFunc_exp10);
580 TLI.setUnavailable(LibFunc_exp10f);
581 } else {
582 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
583 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
584 }
585 break;
586 case Triple::IOS:
587 case Triple::TvOS:
588 case Triple::WatchOS:
589 case Triple::XROS:
590 TLI.setUnavailable(LibFunc_exp10l);
591 if (!T.isWatchOS() &&
592 (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
593 TLI.setUnavailable(LibFunc_exp10);
594 TLI.setUnavailable(LibFunc_exp10f);
595 } else {
596 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
597 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
598 }
599 break;
600 case Triple::Linux:
601 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
602 // buggy prior to glibc version 2.18. Until this version is widely deployed
603 // or we have a reasonable detection strategy, we cannot use exp10 reliably
604 // on Linux.
605 //
606 // Fall through to disable all of them.
607 [[fallthrough]];
608 default:
609 TLI.setUnavailable(LibFunc_exp10);
610 TLI.setUnavailable(LibFunc_exp10f);
611 TLI.setUnavailable(LibFunc_exp10l);
612 }
613
614 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
615 // Linux (GLIBC):
616 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
617 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
618 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
619 switch (T.getOS()) {
620 case Triple::Darwin:
621 case Triple::MacOSX:
622 case Triple::IOS:
623 case Triple::TvOS:
624 case Triple::WatchOS:
625 case Triple::XROS:
626 case Triple::FreeBSD:
627 case Triple::Linux:
628 break;
629 default:
630 TLI.setUnavailable(LibFunc_ffsl);
631 }
632
633 // ffsll is available on at least FreeBSD and Linux (GLIBC):
634 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
635 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
636 switch (T.getOS()) {
637 case Triple::Darwin:
638 case Triple::MacOSX:
639 case Triple::IOS:
640 case Triple::TvOS:
641 case Triple::WatchOS:
642 case Triple::XROS:
643 case Triple::FreeBSD:
644 case Triple::Linux:
645 break;
646 default:
647 TLI.setUnavailable(LibFunc_ffsll);
648 }
649
650 // The following functions are available on at least FreeBSD:
651 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
652 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
653 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
654 if (!T.isOSFreeBSD()) {
655 TLI.setUnavailable(LibFunc_fls);
656 TLI.setUnavailable(LibFunc_flsl);
657 TLI.setUnavailable(LibFunc_flsll);
658 }
659
660 // The following functions are only available on GNU/Linux (using glibc).
661 // Linux variants without glibc (eg: bionic, musl) may have some subset.
662 if (!T.isOSLinux() || !T.isGNUEnvironment()) {
663 TLI.setUnavailable(LibFunc_dunder_strdup);
664 TLI.setUnavailable(LibFunc_dunder_strtok_r);
665 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
666 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
667 TLI.setUnavailable(LibFunc_under_IO_getc);
668 TLI.setUnavailable(LibFunc_under_IO_putc);
669 // But, Android and musl have memalign.
670 if (!T.isAndroid() && !T.isMusl())
671 TLI.setUnavailable(LibFunc_memalign);
672 TLI.setUnavailable(LibFunc_fopen64);
673 TLI.setUnavailable(LibFunc_fseeko64);
674 TLI.setUnavailable(LibFunc_fstat64);
675 TLI.setUnavailable(LibFunc_fstatvfs64);
676 TLI.setUnavailable(LibFunc_ftello64);
677 TLI.setUnavailable(LibFunc_lstat64);
678 TLI.setUnavailable(LibFunc_open64);
679 TLI.setUnavailable(LibFunc_stat64);
680 TLI.setUnavailable(LibFunc_statvfs64);
681 TLI.setUnavailable(LibFunc_tmpfile64);
682
683 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
684 // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
685 // so we keep these functions around just so that they're recognized by
686 // the ConstantFolder.
687 TLI.setUnavailable(LibFunc_acos_finite);
688 TLI.setUnavailable(LibFunc_acosf_finite);
689 TLI.setUnavailable(LibFunc_acosl_finite);
690 TLI.setUnavailable(LibFunc_acosh_finite);
691 TLI.setUnavailable(LibFunc_acoshf_finite);
692 TLI.setUnavailable(LibFunc_acoshl_finite);
693 TLI.setUnavailable(LibFunc_asin_finite);
694 TLI.setUnavailable(LibFunc_asinf_finite);
695 TLI.setUnavailable(LibFunc_asinl_finite);
696 TLI.setUnavailable(LibFunc_atan2_finite);
697 TLI.setUnavailable(LibFunc_atan2f_finite);
698 TLI.setUnavailable(LibFunc_atan2l_finite);
699 TLI.setUnavailable(LibFunc_atanh_finite);
700 TLI.setUnavailable(LibFunc_atanhf_finite);
701 TLI.setUnavailable(LibFunc_atanhl_finite);
702 TLI.setUnavailable(LibFunc_cosh_finite);
703 TLI.setUnavailable(LibFunc_coshf_finite);
704 TLI.setUnavailable(LibFunc_coshl_finite);
705 TLI.setUnavailable(LibFunc_exp10_finite);
706 TLI.setUnavailable(LibFunc_exp10f_finite);
707 TLI.setUnavailable(LibFunc_exp10l_finite);
708 TLI.setUnavailable(LibFunc_exp2_finite);
709 TLI.setUnavailable(LibFunc_exp2f_finite);
710 TLI.setUnavailable(LibFunc_exp2l_finite);
711 TLI.setUnavailable(LibFunc_exp_finite);
712 TLI.setUnavailable(LibFunc_expf_finite);
713 TLI.setUnavailable(LibFunc_expl_finite);
714 TLI.setUnavailable(LibFunc_log10_finite);
715 TLI.setUnavailable(LibFunc_log10f_finite);
716 TLI.setUnavailable(LibFunc_log10l_finite);
717 TLI.setUnavailable(LibFunc_log2_finite);
718 TLI.setUnavailable(LibFunc_log2f_finite);
719 TLI.setUnavailable(LibFunc_log2l_finite);
720 TLI.setUnavailable(LibFunc_log_finite);
721 TLI.setUnavailable(LibFunc_logf_finite);
722 TLI.setUnavailable(LibFunc_logl_finite);
723 TLI.setUnavailable(LibFunc_pow_finite);
724 TLI.setUnavailable(LibFunc_powf_finite);
725 TLI.setUnavailable(LibFunc_powl_finite);
726 TLI.setUnavailable(LibFunc_sinh_finite);
727 TLI.setUnavailable(LibFunc_sinhf_finite);
728 TLI.setUnavailable(LibFunc_sinhl_finite);
729 TLI.setUnavailable(LibFunc_sqrt_finite);
730 TLI.setUnavailable(LibFunc_sqrtf_finite);
731 TLI.setUnavailable(LibFunc_sqrtl_finite);
732 }
733
734 if ((T.isOSLinux() && T.isGNUEnvironment()) ||
735 (T.isAndroid() && !T.isAndroidVersionLT(28))) {
736 // available IO unlocked variants on GNU/Linux and Android P or later
737 TLI.setAvailable(LibFunc_getc_unlocked);
738 TLI.setAvailable(LibFunc_getchar_unlocked);
739 TLI.setAvailable(LibFunc_putc_unlocked);
740 TLI.setAvailable(LibFunc_putchar_unlocked);
741 TLI.setAvailable(LibFunc_fputc_unlocked);
742 TLI.setAvailable(LibFunc_fgetc_unlocked);
743 TLI.setAvailable(LibFunc_fread_unlocked);
744 TLI.setAvailable(LibFunc_fwrite_unlocked);
745 TLI.setAvailable(LibFunc_fputs_unlocked);
746 TLI.setAvailable(LibFunc_fgets_unlocked);
747 }
748
749 if (T.isPS()) {
750 // PS4/PS5 do have memalign.
751 TLI.setAvailable(LibFunc_memalign);
752
753 // PS4/PS5 do not have new/delete with "unsigned int" size parameter;
754 // they only have the "unsigned long" versions.
755 TLI.setUnavailable(LibFunc_ZdaPvj);
756 TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
757 TLI.setUnavailable(LibFunc_ZdlPvj);
758 TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
759 TLI.setUnavailable(LibFunc_Znaj);
760 TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
761 TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
762 TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
763 TLI.setUnavailable(LibFunc_Znwj);
764 TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
765 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
766 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
767
768 // None of the *_chk functions.
769 TLI.setUnavailable(LibFunc_memccpy_chk);
770 TLI.setUnavailable(LibFunc_memcpy_chk);
771 TLI.setUnavailable(LibFunc_memmove_chk);
772 TLI.setUnavailable(LibFunc_mempcpy_chk);
773 TLI.setUnavailable(LibFunc_memset_chk);
774 TLI.setUnavailable(LibFunc_snprintf_chk);
775 TLI.setUnavailable(LibFunc_sprintf_chk);
776 TLI.setUnavailable(LibFunc_stpcpy_chk);
777 TLI.setUnavailable(LibFunc_stpncpy_chk);
778 TLI.setUnavailable(LibFunc_strcat_chk);
779 TLI.setUnavailable(LibFunc_strcpy_chk);
780 TLI.setUnavailable(LibFunc_strlcat_chk);
781 TLI.setUnavailable(LibFunc_strlcpy_chk);
782 TLI.setUnavailable(LibFunc_strlen_chk);
783 TLI.setUnavailable(LibFunc_strncat_chk);
784 TLI.setUnavailable(LibFunc_strncpy_chk);
785 TLI.setUnavailable(LibFunc_vsnprintf_chk);
786 TLI.setUnavailable(LibFunc_vsprintf_chk);
787
788 // Various Posix system functions.
789 TLI.setUnavailable(LibFunc_access);
790 TLI.setUnavailable(LibFunc_chmod);
791 TLI.setUnavailable(LibFunc_chown);
792 TLI.setUnavailable(LibFunc_closedir);
793 TLI.setUnavailable(LibFunc_ctermid);
794 TLI.setUnavailable(LibFunc_execl);
795 TLI.setUnavailable(LibFunc_execle);
796 TLI.setUnavailable(LibFunc_execlp);
797 TLI.setUnavailable(LibFunc_execv);
798 TLI.setUnavailable(LibFunc_execvP);
799 TLI.setUnavailable(LibFunc_execve);
800 TLI.setUnavailable(LibFunc_execvp);
801 TLI.setUnavailable(LibFunc_execvpe);
802 TLI.setUnavailable(LibFunc_fork);
803 TLI.setUnavailable(LibFunc_fstat);
804 TLI.setUnavailable(LibFunc_fstatvfs);
805 TLI.setUnavailable(LibFunc_getenv);
806 TLI.setUnavailable(LibFunc_getitimer);
807 TLI.setUnavailable(LibFunc_getlogin_r);
808 TLI.setUnavailable(LibFunc_getpwnam);
809 TLI.setUnavailable(LibFunc_gettimeofday);
810 TLI.setUnavailable(LibFunc_lchown);
811 TLI.setUnavailable(LibFunc_lstat);
812 TLI.setUnavailable(LibFunc_mkdir);
813 TLI.setUnavailable(LibFunc_open);
814 TLI.setUnavailable(LibFunc_opendir);
815 TLI.setUnavailable(LibFunc_pclose);
816 TLI.setUnavailable(LibFunc_popen);
817 TLI.setUnavailable(LibFunc_pread);
818 TLI.setUnavailable(LibFunc_pvalloc);
819 TLI.setUnavailable(LibFunc_pwrite);
820 TLI.setUnavailable(LibFunc_read);
821 TLI.setUnavailable(LibFunc_readlink);
822 TLI.setUnavailable(LibFunc_realpath);
823 TLI.setUnavailable(LibFunc_rename);
824 TLI.setUnavailable(LibFunc_rmdir);
825 TLI.setUnavailable(LibFunc_setitimer);
826 TLI.setUnavailable(LibFunc_stat);
827 TLI.setUnavailable(LibFunc_statvfs);
828 TLI.setUnavailable(LibFunc_system);
829 TLI.setUnavailable(LibFunc_times);
830 TLI.setUnavailable(LibFunc_tmpfile);
831 TLI.setUnavailable(LibFunc_unlink);
832 TLI.setUnavailable(LibFunc_uname);
833 TLI.setUnavailable(LibFunc_unsetenv);
834 TLI.setUnavailable(LibFunc_utime);
835 TLI.setUnavailable(LibFunc_utimes);
836 TLI.setUnavailable(LibFunc_valloc);
837 TLI.setUnavailable(LibFunc_write);
838
839 // Miscellaneous other functions not provided.
840 TLI.setUnavailable(LibFunc_atomic_load);
841 TLI.setUnavailable(LibFunc_atomic_store);
842 TLI.setUnavailable(LibFunc___kmpc_alloc_shared);
843 TLI.setUnavailable(LibFunc___kmpc_free_shared);
844 TLI.setUnavailable(LibFunc_dunder_strndup);
845 TLI.setUnavailable(LibFunc_bcmp);
846 TLI.setUnavailable(LibFunc_bcopy);
847 TLI.setUnavailable(LibFunc_bzero);
848 TLI.setUnavailable(LibFunc_cabs);
849 TLI.setUnavailable(LibFunc_cabsf);
850 TLI.setUnavailable(LibFunc_cabsl);
851 TLI.setUnavailable(LibFunc_ffs);
852 TLI.setUnavailable(LibFunc_flockfile);
853 TLI.setUnavailable(LibFunc_fseeko);
854 TLI.setUnavailable(LibFunc_ftello);
855 TLI.setUnavailable(LibFunc_ftrylockfile);
856 TLI.setUnavailable(LibFunc_funlockfile);
857 TLI.setUnavailable(LibFunc_htonl);
858 TLI.setUnavailable(LibFunc_htons);
859 TLI.setUnavailable(LibFunc_isascii);
860 TLI.setUnavailable(LibFunc_memccpy);
861 TLI.setUnavailable(LibFunc_mempcpy);
862 TLI.setUnavailable(LibFunc_memrchr);
863 TLI.setUnavailable(LibFunc_ntohl);
864 TLI.setUnavailable(LibFunc_ntohs);
865 TLI.setUnavailable(LibFunc_reallocarray);
866 TLI.setUnavailable(LibFunc_reallocf);
867 TLI.setUnavailable(LibFunc_roundeven);
868 TLI.setUnavailable(LibFunc_roundevenf);
869 TLI.setUnavailable(LibFunc_roundevenl);
870 TLI.setUnavailable(LibFunc_stpcpy);
871 TLI.setUnavailable(LibFunc_stpncpy);
872 TLI.setUnavailable(LibFunc_strlcat);
873 TLI.setUnavailable(LibFunc_strlcpy);
874 TLI.setUnavailable(LibFunc_strndup);
875 TLI.setUnavailable(LibFunc_strnlen);
876 TLI.setUnavailable(LibFunc_toascii);
877 }
878
879 if (T.isOSFreeBSD()) {
880 TLI.setAvailable(LibFunc_dunder_strtok_r);
881 TLI.setAvailable(LibFunc_memalign);
882 TLI.setAvailable(LibFunc_fputc_unlocked);
883 TLI.setAvailable(LibFunc_fputs_unlocked);
884 TLI.setAvailable(LibFunc_fread_unlocked);
885 TLI.setAvailable(LibFunc_fwrite_unlocked);
886 TLI.setAvailable(LibFunc_getc_unlocked);
887 TLI.setAvailable(LibFunc_getchar_unlocked);
888 TLI.setAvailable(LibFunc_putc_unlocked);
889 TLI.setAvailable(LibFunc_putchar_unlocked);
890
891 TLI.setUnavailable(LibFunc___kmpc_alloc_shared);
892 TLI.setUnavailable(LibFunc___kmpc_free_shared);
893 TLI.setUnavailable(LibFunc_dunder_strndup);
894 TLI.setUnavailable(LibFunc_memccpy_chk);
895 TLI.setUnavailable(LibFunc_strlen_chk);
896 TLI.setUnavailable(LibFunc_fmaximum_num);
897 TLI.setUnavailable(LibFunc_fmaximum_numf);
898 TLI.setUnavailable(LibFunc_fmaximum_numl);
899 TLI.setUnavailable(LibFunc_fminimum_num);
900 TLI.setUnavailable(LibFunc_fminimum_numf);
901 TLI.setUnavailable(LibFunc_fminimum_numl);
902 TLI.setUnavailable(LibFunc_roundeven);
903 TLI.setUnavailable(LibFunc_roundevenf);
904 TLI.setUnavailable(LibFunc_roundevenl);
905 }
906
907 // As currently implemented in clang, NVPTX code has no standard library to
908 // speak of. Headers provide a standard-ish library implementation, but many
909 // of the signatures are wrong -- for example, many libm functions are not
910 // extern "C".
911 //
912 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
913 // but only used functions are provided to llvm. Moreover, most of the
914 // functions in libdevice don't map precisely to standard library functions.
915 //
916 // FIXME: Having no standard library prevents e.g. many fastmath
917 // optimizations, so this situation should be fixed.
918 if (T.isNVPTX()) {
920 TLI.setAvailable(LibFunc_nvvm_reflect);
921 TLI.setAvailable(llvm::LibFunc_malloc);
922 TLI.setAvailable(llvm::LibFunc_free);
923
924 // TODO: We could enable the following two according to [0] but we haven't
925 // done an evaluation wrt. the performance implications.
926 // [0]
927 // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations
928 //
929 // TLI.setAvailable(llvm::LibFunc_memcpy);
930 // TLI.setAvailable(llvm::LibFunc_memset);
931
932 TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
933 TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
934 } else {
935 TLI.setUnavailable(LibFunc_nvvm_reflect);
936 }
937
938 // These vec_malloc/free routines are only available on AIX.
939 if (!T.isOSAIX()) {
940 TLI.setUnavailable(LibFunc_vec_calloc);
941 TLI.setUnavailable(LibFunc_vec_malloc);
942 TLI.setUnavailable(LibFunc_vec_realloc);
943 TLI.setUnavailable(LibFunc_vec_free);
944 }
945
946 if (T.isOSAIX())
947 TLI.setUnavailable(LibFunc_memrchr);
948
950}
951
952/// Initialize the set of available library functions based on the specified
953/// target triple. This should be carefully written so that a missing target
954/// triple gets a sane set of defaults.
955static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
956 ArrayRef<StringLiteral> StandardNames) {
957 initializeBase(TLI, T);
958 initializeLibCalls(TLI, T, StandardNames);
959}
960
962 // Default to everything being available.
963 memset(AvailableArray, -1, sizeof(AvailableArray));
964
965 initialize(*this, T, StandardNames);
966}
967
969 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
970 ShouldExtI32Return(TLI.ShouldExtI32Return),
971 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
972 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
973 SizeOfInt(TLI.SizeOfInt) {
974 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
975 VectorDescs = TLI.VectorDescs;
976 ScalarDescs = TLI.ScalarDescs;
977}
978
980 : CustomNames(std::move(TLI.CustomNames)),
981 ShouldExtI32Param(TLI.ShouldExtI32Param),
982 ShouldExtI32Return(TLI.ShouldExtI32Return),
983 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
984 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
985 SizeOfInt(TLI.SizeOfInt) {
986 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
987 AvailableArray);
988 VectorDescs = TLI.VectorDescs;
989 ScalarDescs = TLI.ScalarDescs;
990}
991
993 CustomNames = TLI.CustomNames;
994 ShouldExtI32Param = TLI.ShouldExtI32Param;
995 ShouldExtI32Return = TLI.ShouldExtI32Return;
996 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
997 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
998 SizeOfInt = TLI.SizeOfInt;
999 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
1000 return *this;
1001}
1002
1004 CustomNames = std::move(TLI.CustomNames);
1005 ShouldExtI32Param = TLI.ShouldExtI32Param;
1006 ShouldExtI32Return = TLI.ShouldExtI32Return;
1007 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
1008 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
1009 SizeOfInt = TLI.SizeOfInt;
1010 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
1011 AvailableArray);
1012 return *this;
1013}
1014
1016 // Filter out empty names and names containing null bytes, those can't be in
1017 // our table.
1018 if (funcName.empty() || funcName.contains('\0'))
1019 return StringRef();
1020
1021 // Check for \01 prefix that is used to mangle __asm declarations and
1022 // strip it if present.
1023 return GlobalValue::dropLLVMManglingEscape(funcName);
1024}
1025
1029 unsigned Idx = 0;
1031 for (const auto &Func : StandardNames)
1032 Indices[Func] = static_cast<LibFunc>(Idx++);
1033 return Indices;
1034}
1035
1037 funcName = sanitizeFunctionName(funcName);
1038 if (funcName.empty())
1039 return false;
1040
1041 static const DenseMap<StringRef, LibFunc> Indices =
1042 buildIndexMap(StandardNames);
1043
1044 if (auto Loc = Indices.find(funcName); Loc != Indices.end()) {
1045 F = Loc->second;
1046 return true;
1047 }
1048 return false;
1049}
1050
1051// Return true if ArgTy matches Ty.
1052
1053static bool matchType(FuncArgTypeID ArgTy, const Type *Ty, unsigned IntBits,
1054 unsigned SizeTBits) {
1055 switch (ArgTy) {
1056 case Void:
1057 return Ty->isVoidTy();
1058 case Bool:
1059 return Ty->isIntegerTy(8);
1060 case Int16:
1061 return Ty->isIntegerTy(16);
1062 case Int32:
1063 return Ty->isIntegerTy(32);
1064 case Int:
1065 return Ty->isIntegerTy(IntBits);
1066 case IntPlus:
1067 return Ty->isIntegerTy() && Ty->getPrimitiveSizeInBits() >= IntBits;
1068 case IntX:
1069 return Ty->isIntegerTy();
1070 case Long:
1071 // TODO: Figure out and use long size.
1072 return Ty->isIntegerTy() && Ty->getPrimitiveSizeInBits() >= IntBits;
1073 case Int64:
1074 return Ty->isIntegerTy(64);
1075 case LLong:
1076 return Ty->isIntegerTy(64);
1077 case SizeT:
1078 case SSizeT:
1079 return Ty->isIntegerTy(SizeTBits);
1080 case Flt:
1081 return Ty->isFloatTy();
1082 case Dbl:
1083 return Ty->isDoubleTy();
1084 // TODO: Tighten this up.
1085 case LDbl:
1086 return Ty->isFloatingPointTy();
1087 case Floating:
1088 return Ty->isFloatingPointTy();
1089 case Ptr:
1090 return Ty->isPointerTy();
1091 case Struct:
1092 return Ty->isStructTy();
1093 default:
1094 break;
1095 }
1096
1097 llvm_unreachable("Invalid type");
1098}
1099
1101 const Module &M,
1102 int SizeTSizeBits) {
1103 switch (F) {
1104 case LibFunc_size_returning_new: {
1105 if (FTy.getNumParams() != 1 ||
1106 !FTy.getParamType(0)->isIntegerTy(SizeTSizeBits)) {
1107 return false;
1108 }
1109 } break;
1110 case LibFunc_size_returning_new_hot_cold: {
1111 if (FTy.getNumParams() != 2 ||
1112 !FTy.getParamType(0)->isIntegerTy(SizeTSizeBits) ||
1113 !FTy.getParamType(1)->isIntegerTy(8)) {
1114 return false;
1115 }
1116 } break;
1117 case LibFunc_size_returning_new_aligned: {
1118 if (FTy.getNumParams() != 2 ||
1119 !FTy.getParamType(0)->isIntegerTy(SizeTSizeBits) ||
1120 !FTy.getParamType(1)->isIntegerTy(SizeTSizeBits)) {
1121 return false;
1122 }
1123 } break;
1124 case LibFunc_size_returning_new_aligned_hot_cold:
1125 if (FTy.getNumParams() != 3 ||
1126 !FTy.getParamType(0)->isIntegerTy(SizeTSizeBits) ||
1127 !FTy.getParamType(1)->isIntegerTy(SizeTSizeBits) ||
1128 !FTy.getParamType(2)->isIntegerTy(8)) {
1129 return false;
1130 }
1131 break;
1132 default:
1133 return false;
1134 }
1135
1136 auto &Context = M.getContext();
1137 PointerType *PtrTy = PointerType::get(Context, 0);
1138 StructType *SizedPtrTy = StructType::get(
1139 Context, {PtrTy, Type::getIntNTy(Context, SizeTSizeBits)});
1140 return FTy.getReturnType() == SizedPtrTy;
1141}
1142
1143bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
1144 LibFunc F,
1145 const Module &M) const {
1146 unsigned NumParams = FTy.getNumParams();
1147
1148 switch (F) {
1149 // Special handling for <complex.h> functions:
1150 case LibFunc_cabs:
1151 case LibFunc_cabsf:
1152 case LibFunc_cabsl: {
1153 Type *RetTy = FTy.getReturnType();
1154 if (!RetTy->isFloatingPointTy() || NumParams == 0)
1155 return false;
1156
1157 Type *ParamTy = FTy.getParamType(0);
1158 // NOTE: These prototypes are target specific and currently support
1159 // "complex" passed as an array or discrete real & imaginary parameters.
1160 // Add other calling conventions to enable libcall optimizations.
1161 if (NumParams == 1)
1162 return (ParamTy->isArrayTy() && ParamTy->getArrayNumElements() == 2 &&
1163 ParamTy->getArrayElementType() == RetTy);
1164 else if (NumParams == 2)
1165 return ParamTy == RetTy && FTy.getParamType(1) == RetTy;
1166
1167 return false;
1168 }
1169 // Special handling for the sincospi functions that return either
1170 // a struct or vector:
1171 case LibFunc_sincospi_stret:
1172 case LibFunc_sincospif_stret: {
1173 if (NumParams != 1)
1174 return false;
1175
1176 Type *RetTy = FTy.getReturnType();
1177 Type *ParamTy = FTy.getParamType(0);
1178 if (auto *Ty = dyn_cast<StructType>(RetTy)) {
1179 if (Ty->getNumElements() != 2)
1180 return false;
1181 return (Ty->getElementType(0) == ParamTy &&
1182 Ty->getElementType(1) == ParamTy);
1183 }
1184
1185 if (auto *Ty = dyn_cast<FixedVectorType>(RetTy)) {
1186 if (Ty->getNumElements() != 2)
1187 return false;
1188 return Ty->getElementType() == ParamTy;
1189 }
1190
1191 return false;
1192 }
1193 // Special handling of __size_returning_new functions that return a struct
1194 // of type {void*, size_t}.
1195 case LibFunc_size_returning_new:
1196 case LibFunc_size_returning_new_hot_cold:
1197 case LibFunc_size_returning_new_aligned:
1198 case LibFunc_size_returning_new_aligned_hot_cold:
1200 default:
1201 break;
1202 }
1203
1204 unsigned IntBits = getIntSize();
1205 unsigned SizeTBits = getSizeTSize(M);
1206 unsigned Idx = 0;
1207
1208 // Iterate over the type ids in the function prototype, matching each
1209 // against the function's type FTy, starting with its return type.
1210 // Return true if both match in number and kind, inclduing the ellipsis.
1211 Type *Ty = FTy.getReturnType(), *LastTy = Ty;
1212 const auto &ProtoTypes = Signatures[F];
1213 for (auto TyID : ProtoTypes) {
1214 if (Idx && TyID == Void)
1215 // Except in the first position where it designates the function's
1216 // return type Void ends the argument list.
1217 break;
1218
1219 if (TyID == Ellip) {
1220 // The ellipsis ends the protoype list but is not a part of FTy's
1221 // argument list. Except when it's last it must be followed by
1222 // Void.
1223 assert(Idx == ProtoTypes.size() - 1 || ProtoTypes[Idx + 1] == Void);
1224 return FTy.isFunctionVarArg();
1225 }
1226
1227 if (TyID == Same) {
1228 assert(Idx != 0 && "Type ID 'Same' must not be first!");
1229 if (Ty != LastTy)
1230 return false;
1231 } else {
1232 if (!Ty || !matchType(TyID, Ty, IntBits, SizeTBits))
1233 return false;
1234 LastTy = Ty;
1235 }
1236
1237 if (Idx == NumParams) {
1238 // There's at least one and at most two more type ids than there are
1239 // arguments in FTy's argument list.
1240 Ty = nullptr;
1241 ++Idx;
1242 continue;
1243 }
1244
1245 Ty = FTy.getParamType(Idx++);
1246 }
1247
1248 // Return success only if all entries on both lists have been processed
1249 // and the function is not a variadic one.
1250 return Idx == NumParams + 1 && !FTy.isFunctionVarArg();
1251}
1252
1254 LibFunc &F) const {
1255 // Intrinsics don't overlap w/libcalls; if our module has a large number of
1256 // intrinsics, this ends up being an interesting compile time win since we
1257 // avoid string normalization and comparison.
1258 if (FDecl.isIntrinsic()) return false;
1259
1260 const Module *M = FDecl.getParent();
1261 assert(M && "Expecting FDecl to be connected to a Module.");
1262
1263 if (FDecl.LibFuncCache == Function::UnknownLibFunc)
1264 if (!getLibFunc(FDecl.getName(), FDecl.LibFuncCache))
1265 FDecl.LibFuncCache = NotLibFunc;
1266
1267 if (FDecl.LibFuncCache == NotLibFunc)
1268 return false;
1269
1270 F = FDecl.LibFuncCache;
1271 return isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M);
1272}
1273
1274bool TargetLibraryInfoImpl::getLibFunc(unsigned int Opcode, Type *Ty,
1275 LibFunc &F) const {
1276 // Must be a frem instruction with float or double arguments.
1277 if (Opcode != Instruction::FRem || (!Ty->isDoubleTy() && !Ty->isFloatTy()))
1278 return false;
1279
1280 F = Ty->isDoubleTy() ? LibFunc_fmod : LibFunc_fmodf;
1281 return true;
1282}
1283
1285 memset(AvailableArray, 0, sizeof(AvailableArray));
1286}
1287
1288static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1289 return LHS.getScalarFnName() < RHS.getScalarFnName();
1290}
1291
1292static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1293 return LHS.getVectorFnName() < RHS.getVectorFnName();
1294}
1295
1297 return LHS.getScalarFnName() < S;
1298}
1299
1301 llvm::append_range(VectorDescs, Fns);
1302 llvm::sort(VectorDescs, compareByScalarFnName);
1303
1304 llvm::append_range(ScalarDescs, Fns);
1305 llvm::sort(ScalarDescs, compareByVectorFnName);
1306}
1307
1309#define TLI_DEFINE_ACCELERATE_VECFUNCS
1310#include "llvm/Analysis/VecFuncs.def"
1311#undef TLI_DEFINE_ACCELERATE_VECFUNCS
1312};
1313
1315#define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1316#include "llvm/Analysis/VecFuncs.def"
1317#undef TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1318};
1319
1321#define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1322#include "llvm/Analysis/VecFuncs.def"
1323#undef TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1324};
1325
1327#define TLI_DEFINE_LIBMVEC_AARCH64_VECFUNCS
1328#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX, CC) \
1329 {SCAL, VEC, VF, MASK, VABI_PREFIX, CC},
1330#include "llvm/Analysis/VecFuncs.def"
1331#undef TLI_DEFINE_LIBMVEC_AARCH64_VECFUNCS
1332};
1333
1334static const VecDesc VecFuncs_MASSV[] = {
1335#define TLI_DEFINE_MASSV_VECFUNCS
1336#include "llvm/Analysis/VecFuncs.def"
1337#undef TLI_DEFINE_MASSV_VECFUNCS
1338};
1339
1340static const VecDesc VecFuncs_SVML[] = {
1341#define TLI_DEFINE_SVML_VECFUNCS
1342#include "llvm/Analysis/VecFuncs.def"
1343#undef TLI_DEFINE_SVML_VECFUNCS
1344};
1345
1347#define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1348#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \
1349 {SCAL, VEC, VF, /* MASK = */ false, VABI_PREFIX, /* CC = */ std::nullopt},
1350#include "llvm/Analysis/VecFuncs.def"
1351#undef TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1352};
1354#define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1355#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \
1356 {SCAL, VEC, VF, /* MASK = */ false, VABI_PREFIX, /* CC = */ std::nullopt},
1357#include "llvm/Analysis/VecFuncs.def"
1358#undef TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1359};
1361#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1362#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1363 {SCAL, VEC, VF, MASK, VABI_PREFIX, /* CC = */ std::nullopt},
1364#include "llvm/Analysis/VecFuncs.def"
1365#undef TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1366};
1367
1369#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS_RISCV
1370#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1371 {SCAL, VEC, VF, MASK, VABI_PREFIX, /* CC = */ std::nullopt},
1372#include "llvm/Analysis/VecFuncs.def"
1373#undef TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS_RISCV
1374};
1375
1376static const VecDesc VecFuncs_ArmPL[] = {
1377#define TLI_DEFINE_ARMPL_VECFUNCS
1378#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX, CC) \
1379 {SCAL, VEC, VF, MASK, VABI_PREFIX, CC},
1380#include "llvm/Analysis/VecFuncs.def"
1381#undef TLI_DEFINE_ARMPL_VECFUNCS
1382};
1383
1385#define TLI_DEFINE_AMDLIBM_VECFUNCS
1386#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1387 {SCAL, VEC, VF, MASK, VABI_PREFIX, /* CC = */ std::nullopt},
1388#include "llvm/Analysis/VecFuncs.def"
1389#undef TLI_DEFINE_AMDLIBM_VECFUNCS
1390};
1391
1393 enum VectorLibrary VecLib, const llvm::Triple &TargetTriple) {
1394 switch (VecLib) {
1395 case Accelerate: {
1397 break;
1398 }
1399 case DarwinLibSystemM: {
1401 break;
1402 }
1403 case LIBMVEC: {
1404 switch (TargetTriple.getArch()) {
1405 default:
1406 break;
1407 case llvm::Triple::x86:
1410 break;
1414 break;
1415 }
1416 break;
1417 }
1418 case MASSV: {
1420 break;
1421 }
1422 case SVML: {
1424 break;
1425 }
1426 case SLEEFGNUABI: {
1427 switch (TargetTriple.getArch()) {
1428 default:
1429 break;
1435 break;
1438 break;
1439 }
1440 break;
1441 }
1442 case ArmPL: {
1443 switch (TargetTriple.getArch()) {
1444 default:
1445 break;
1449 break;
1450 }
1451 break;
1452 }
1453 case AMDLIBM: {
1455 break;
1456 }
1457 case NoLibrary:
1458 break;
1459 }
1460}
1461
1463 funcName = sanitizeFunctionName(funcName);
1464 if (funcName.empty())
1465 return false;
1466
1467 std::vector<VecDesc>::const_iterator I =
1468 llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1469 return I != VectorDescs.end() && StringRef(I->getScalarFnName()) == funcName;
1470}
1471
1473 const ElementCount &VF,
1474 bool Masked) const {
1475 const VecDesc *VD = getVectorMappingInfo(F, VF, Masked);
1476 if (VD)
1477 return VD->getVectorFnName();
1478 return StringRef();
1479}
1480
1481const VecDesc *
1483 bool Masked) const {
1485 if (F.empty())
1486 return nullptr;
1487 std::vector<VecDesc>::const_iterator I =
1489 while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == F) {
1490 if ((I->getVectorizationFactor() == VF) && (I->isMasked() == Masked))
1491 return &(*I);
1492 ++I;
1493 }
1494 return nullptr;
1495}
1496
1499 if (!BaselineInfoImpl)
1500 BaselineInfoImpl = TargetLibraryInfoImpl(F.getParent()->getTargetTriple());
1501 return TargetLibraryInfo(*BaselineInfoImpl, &F);
1502}
1503
1505 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1506 M.getModuleFlag("wchar_size")))
1507 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1508 return 0;
1509}
1510
1512 // There is really no guarantee that sizeof(size_t) is equal to the index
1513 // size of the default address space. If that isn't true then it should be
1514 // possible to derive the SizeTTy from the target triple here instead and do
1515 // an early return.
1516
1517 // Hard coding address space zero may seem unfortunate, but a number of
1518 // configurations of common targets (i386, x86-64 x32, aarch64 x32, possibly
1519 // others) have larger-than-size_t index sizes on non-default address spaces,
1520 // making this the best default.
1521 return M.getDataLayout().getIndexSizeInBits(/*AddressSpace=*/0);
1522}
1523
1526
1529
1533
1537
1538AnalysisKey TargetLibraryAnalysis::Key;
1539
1540// Register the basic pass.
1542 "Target Library Information", false, true)
1544
1545void TargetLibraryInfoWrapperPass::anchor() {}
1546
1548 ElementCount &FixedVF,
1549 ElementCount &ScalableVF) const {
1550 ScalarF = sanitizeFunctionName(ScalarF);
1551 // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the
1552 // same as a scalar.
1553 ScalableVF = ElementCount::getScalable(0);
1554 FixedVF = ElementCount::getFixed(1);
1555 if (ScalarF.empty())
1556 return;
1557
1558 std::vector<VecDesc>::const_iterator I =
1559 llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
1560 while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == ScalarF) {
1561 ElementCount *VF =
1562 I->getVectorizationFactor().isScalable() ? &ScalableVF : &FixedVF;
1563 if (ElementCount::isKnownGT(I->getVectorizationFactor(), *VF))
1564 *VF = I->getVectorizationFactor();
1565 ++I;
1566 }
1567}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
#define T
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file defines the SmallString class.
static bool hasSinCosPiStret(const Triple &T)
static bool isCallingConvCCompatible(CallingConv::ID CC, const Triple &TT, FunctionType *FuncTy)
static StringRef sanitizeFunctionName(StringRef funcName)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
static const VecDesc VecFuncs_MASSV[]
static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
static bool matchType(FuncArgTypeID ArgTy, const Type *Ty, unsigned IntBits, unsigned SizeTBits)
static bool hasBcmp(const Triple &TT)
static const VecDesc VecFuncs_SLEEFGNUABI_VF2[]
static void initializeBase(TargetLibraryInfoImpl &TLI, const Triple &T)
static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS)
static const VecDesc VecFuncs_LIBMVEC_AARCH64[]
static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS)
static const VecDesc VecFuncs_SLEEFGNUABI_VF4[]
static const FuncProtoTy Signatures[]
static const VecDesc VecFuncs_ArmPL[]
const VecDesc VecFuncs_AMDLIBM[]
static bool isValidProtoForSizeReturningNew(const FunctionType &FTy, LibFunc F, const Module &M, int SizeTSizeBits)
static const VecDesc VecFuncs_LIBMVEC_X86[]
static cl::opt< TargetLibraryInfoImpl::VectorLibrary > ClVectorLibrary("vector-library", cl::Hidden, cl::desc("Vector functions library"), cl::init(TargetLibraryInfoImpl::NoLibrary), cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", "No vector functions library"), clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", "Accelerate framework"), clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM, "Darwin_libsystem_m", "Darwin libsystem_m"), clEnumValN(TargetLibraryInfoImpl::LIBMVEC, "LIBMVEC", "GLIBC Vector Math library"), clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV", "IBM MASS vector library"), clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", "Intel SVML library"), clEnumValN(TargetLibraryInfoImpl::SLEEFGNUABI, "sleefgnuabi", "SIMD Library for Evaluating Elementary Functions"), clEnumValN(TargetLibraryInfoImpl::ArmPL, "ArmPL", "Arm Performance Libraries"), clEnumValN(TargetLibraryInfoImpl::AMDLIBM, "AMDLIBM", "AMD vector math library")))
static const VecDesc VecFuncs_DarwinLibSystemM[]
static const VecDesc VecFuncs_SVML[]
std::array< FuncArgTypeID, 8 > FuncProtoTy
static const VecDesc VecFuncs_SLEEFGNUABI_VFScalable[]
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S)
static const VecDesc VecFuncs_Accelerate[]
static const VecDesc VecFuncs_SLEEFGNUABI_VFScalableRISCV[]
static DenseMap< StringRef, LibFunc > buildIndexMap(ArrayRef< StringLiteral > StandardNames)
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallingConv::ID getCallingConv() const
FunctionType * getFunctionType() const
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:178
iterator end()
Definition DenseMap.h:81
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Definition DenseMap.h:114
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition TypeSize.h:313
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:310
Class to represent function types.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:209
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition Function.h:249
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Module * getParent()
Get the module that this global value is contained inside of...
ImmutablePass(char &pid)
Definition Pass.h:287
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition Module.h:281
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:426
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:414
LLVM_ABI TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
Implementation of the target library information.
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
LLVM_ABI unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &Scalable) const
Returns the largest vectorization factor used in the list of vector functions.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used.
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
LLVM_ABI void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib, const llvm::Triple &TargetTriple)
Calls addVectorizableFunctions with a known preset of functions for the given vector library.
void setIntSize(unsigned Bits)
Initialize the C-level size of an integer.
LLVM_ABI unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
LLVM_ABI void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
LLVM_ABI const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
Return a pointer to a VecDesc object holding all info for scalar to vector mappings in TLI for the eq...
static LLVM_ABI bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
void setShouldSignExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext attribute if they correspond t...
LLVM_ABI TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
LLVM_ABI void disableAllFunctions()
Disables all builtins.
VectorLibrary
List of known vector-functions libraries.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
LLVM_ABI StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked) const
Return the name of the equivalent of F, vectorized with factor VF.
void setAvailable(LibFunc F)
Forces a function to be marked as available.
TargetLibraryInfoWrapperPass()
The default constructor should not be used and is only for pass manager initialization purposes.
Provides information about what library functions are available for the current target.
static void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition Triple.h:413
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition Type.h:264
Type * getArrayElementType() const
Definition Type.h:408
LLVM_ABI uint64_t getArrayNumElements() const
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:184
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:301
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
Provides info so a possible vectorization of a function can be computed.
LLVM_ABI std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
StringRef getVectorFnName() const
Represents a version number in the form major[.minor[.subminor[.build]]].
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition TypeSize.h:224
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2136
auto cast_or_null(const Y &Val)
Definition Casting.h:714
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1622
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:1994
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1867
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29