LLVM 19.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 (Triple(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 // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and
209 // later. All versions of watchOS support it.
210 if (T.isMacOSX()) {
211 // available IO unlocked variants on Mac OS X
212 TLI.setAvailable(LibFunc_getc_unlocked);
213 TLI.setAvailable(LibFunc_getchar_unlocked);
214 TLI.setAvailable(LibFunc_putc_unlocked);
215 TLI.setAvailable(LibFunc_putchar_unlocked);
216 TLI.setUnavailable(LibFunc_memrchr);
217
218 if (T.isMacOSXVersionLT(10, 5)) {
219 TLI.setUnavailable(LibFunc_memset_pattern4);
220 TLI.setUnavailable(LibFunc_memset_pattern8);
221 TLI.setUnavailable(LibFunc_memset_pattern16);
222 }
223 } else if (T.isiOS()) {
224 if (T.isOSVersionLT(3, 0)) {
225 TLI.setUnavailable(LibFunc_memset_pattern4);
226 TLI.setUnavailable(LibFunc_memset_pattern8);
227 TLI.setUnavailable(LibFunc_memset_pattern16);
228 }
229 } else if (!T.isWatchOS()) {
230 TLI.setUnavailable(LibFunc_memset_pattern4);
231 TLI.setUnavailable(LibFunc_memset_pattern8);
232 TLI.setUnavailable(LibFunc_memset_pattern16);
233 }
234
235 if (!hasSinCosPiStret(T)) {
236 TLI.setUnavailable(LibFunc_sinpi);
237 TLI.setUnavailable(LibFunc_sinpif);
238 TLI.setUnavailable(LibFunc_cospi);
239 TLI.setUnavailable(LibFunc_cospif);
240 TLI.setUnavailable(LibFunc_sincospi_stret);
241 TLI.setUnavailable(LibFunc_sincospif_stret);
242 }
243
244 if (!hasBcmp(T))
245 TLI.setUnavailable(LibFunc_bcmp);
246
247 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
248 !T.isMacOSXVersionLT(10, 7)) {
249 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
250 // we don't care about) have two versions; on recent OSX, the one we want
251 // has a $UNIX2003 suffix. The two implementations are identical except
252 // for the return value in some edge cases. However, we don't want to
253 // generate code that depends on the old symbols.
254 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
255 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
256 }
257
258 // iprintf and friends are only available on XCore, TCE, and Emscripten.
259 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce &&
260 T.getOS() != Triple::Emscripten) {
261 TLI.setUnavailable(LibFunc_iprintf);
262 TLI.setUnavailable(LibFunc_siprintf);
263 TLI.setUnavailable(LibFunc_fiprintf);
264 }
265
266 // __small_printf and friends are only available on Emscripten.
267 if (T.getOS() != Triple::Emscripten) {
268 TLI.setUnavailable(LibFunc_small_printf);
269 TLI.setUnavailable(LibFunc_small_sprintf);
270 TLI.setUnavailable(LibFunc_small_fprintf);
271 }
272
273 if (T.isOSWindows() && !T.isOSCygMing()) {
274 // XXX: The earliest documentation available at the moment is for VS2015/VC19:
275 // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015
276 // XXX: In order to use an MSVCRT older than VC19,
277 // the specific library version must be explicit in the target triple,
278 // e.g., x86_64-pc-windows-msvc18.
279 bool hasPartialC99 = true;
280 if (T.isKnownWindowsMSVCEnvironment()) {
281 VersionTuple Version = T.getEnvironmentVersion();
282 hasPartialC99 = (Version.getMajor() == 0 || Version.getMajor() >= 19);
283 }
284
285 // Latest targets support C89 math functions, in part.
286 bool isARM = (T.getArch() == Triple::aarch64 ||
287 T.getArch() == Triple::arm);
288 bool hasPartialFloat = (isARM ||
289 T.getArch() == Triple::x86_64);
290
291 // Win32 does not support float C89 math functions, in general.
292 if (!hasPartialFloat) {
293 TLI.setUnavailable(LibFunc_acosf);
294 TLI.setUnavailable(LibFunc_asinf);
295 TLI.setUnavailable(LibFunc_atan2f);
296 TLI.setUnavailable(LibFunc_atanf);
297 TLI.setUnavailable(LibFunc_ceilf);
298 TLI.setUnavailable(LibFunc_cosf);
299 TLI.setUnavailable(LibFunc_coshf);
300 TLI.setUnavailable(LibFunc_expf);
301 TLI.setUnavailable(LibFunc_floorf);
302 TLI.setUnavailable(LibFunc_fmodf);
303 TLI.setUnavailable(LibFunc_log10f);
304 TLI.setUnavailable(LibFunc_logf);
305 TLI.setUnavailable(LibFunc_modff);
306 TLI.setUnavailable(LibFunc_powf);
307 TLI.setUnavailable(LibFunc_remainderf);
308 TLI.setUnavailable(LibFunc_sinf);
309 TLI.setUnavailable(LibFunc_sinhf);
310 TLI.setUnavailable(LibFunc_sqrtf);
311 TLI.setUnavailable(LibFunc_tanf);
312 TLI.setUnavailable(LibFunc_tanhf);
313 }
314 if (!isARM)
315 TLI.setUnavailable(LibFunc_fabsf);
316 TLI.setUnavailable(LibFunc_frexpf);
317 TLI.setUnavailable(LibFunc_ldexpf);
318
319 // Win32 does not support long double C89 math functions.
320 TLI.setUnavailable(LibFunc_acosl);
321 TLI.setUnavailable(LibFunc_asinl);
322 TLI.setUnavailable(LibFunc_atan2l);
323 TLI.setUnavailable(LibFunc_atanl);
324 TLI.setUnavailable(LibFunc_ceill);
325 TLI.setUnavailable(LibFunc_cosl);
326 TLI.setUnavailable(LibFunc_coshl);
327 TLI.setUnavailable(LibFunc_expl);
328 TLI.setUnavailable(LibFunc_fabsl);
329 TLI.setUnavailable(LibFunc_floorl);
330 TLI.setUnavailable(LibFunc_fmodl);
331 TLI.setUnavailable(LibFunc_frexpl);
332 TLI.setUnavailable(LibFunc_ldexpl);
333 TLI.setUnavailable(LibFunc_log10l);
334 TLI.setUnavailable(LibFunc_logl);
335 TLI.setUnavailable(LibFunc_modfl);
336 TLI.setUnavailable(LibFunc_powl);
337 TLI.setUnavailable(LibFunc_remainderl);
338 TLI.setUnavailable(LibFunc_sinl);
339 TLI.setUnavailable(LibFunc_sinhl);
340 TLI.setUnavailable(LibFunc_sqrtl);
341 TLI.setUnavailable(LibFunc_tanl);
342 TLI.setUnavailable(LibFunc_tanhl);
343
344 // Win32 does not fully support C99 math functions.
345 if (!hasPartialC99) {
346 TLI.setUnavailable(LibFunc_acosh);
347 TLI.setUnavailable(LibFunc_acoshf);
348 TLI.setUnavailable(LibFunc_asinh);
349 TLI.setUnavailable(LibFunc_asinhf);
350 TLI.setUnavailable(LibFunc_atanh);
351 TLI.setUnavailable(LibFunc_atanhf);
352 TLI.setAvailableWithName(LibFunc_cabs, "_cabs");
353 TLI.setUnavailable(LibFunc_cabsf);
354 TLI.setUnavailable(LibFunc_cbrt);
355 TLI.setUnavailable(LibFunc_cbrtf);
356 TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
357 TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf");
358 TLI.setUnavailable(LibFunc_exp2);
359 TLI.setUnavailable(LibFunc_exp2f);
360 TLI.setUnavailable(LibFunc_expm1);
361 TLI.setUnavailable(LibFunc_expm1f);
362 TLI.setUnavailable(LibFunc_fmax);
363 TLI.setUnavailable(LibFunc_fmaxf);
364 TLI.setUnavailable(LibFunc_fmin);
365 TLI.setUnavailable(LibFunc_fminf);
366 TLI.setUnavailable(LibFunc_log1p);
367 TLI.setUnavailable(LibFunc_log1pf);
368 TLI.setUnavailable(LibFunc_log2);
369 TLI.setUnavailable(LibFunc_log2f);
370 TLI.setAvailableWithName(LibFunc_logb, "_logb");
371 if (hasPartialFloat)
372 TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
373 else
374 TLI.setUnavailable(LibFunc_logbf);
375 TLI.setUnavailable(LibFunc_rint);
376 TLI.setUnavailable(LibFunc_rintf);
377 TLI.setUnavailable(LibFunc_round);
378 TLI.setUnavailable(LibFunc_roundf);
379 TLI.setUnavailable(LibFunc_trunc);
380 TLI.setUnavailable(LibFunc_truncf);
381 }
382
383 // Win32 does not support long double C99 math functions.
384 TLI.setUnavailable(LibFunc_acoshl);
385 TLI.setUnavailable(LibFunc_asinhl);
386 TLI.setUnavailable(LibFunc_atanhl);
387 TLI.setUnavailable(LibFunc_cabsl);
388 TLI.setUnavailable(LibFunc_cbrtl);
389 TLI.setUnavailable(LibFunc_copysignl);
390 TLI.setUnavailable(LibFunc_exp2l);
391 TLI.setUnavailable(LibFunc_expm1l);
392 TLI.setUnavailable(LibFunc_fmaxl);
393 TLI.setUnavailable(LibFunc_fminl);
394 TLI.setUnavailable(LibFunc_log1pl);
395 TLI.setUnavailable(LibFunc_log2l);
396 TLI.setUnavailable(LibFunc_logbl);
397 TLI.setUnavailable(LibFunc_nearbyintl);
398 TLI.setUnavailable(LibFunc_rintl);
399 TLI.setUnavailable(LibFunc_roundl);
400 TLI.setUnavailable(LibFunc_truncl);
401
402 // Win32 does not support these functions, but
403 // they are generally available on POSIX-compliant systems.
404 TLI.setUnavailable(LibFunc_access);
405 TLI.setUnavailable(LibFunc_chmod);
406 TLI.setUnavailable(LibFunc_closedir);
407 TLI.setUnavailable(LibFunc_fdopen);
408 TLI.setUnavailable(LibFunc_fileno);
409 TLI.setUnavailable(LibFunc_fseeko);
410 TLI.setUnavailable(LibFunc_fstat);
411 TLI.setUnavailable(LibFunc_ftello);
412 TLI.setUnavailable(LibFunc_gettimeofday);
413 TLI.setUnavailable(LibFunc_memccpy);
414 TLI.setUnavailable(LibFunc_mkdir);
415 TLI.setUnavailable(LibFunc_open);
416 TLI.setUnavailable(LibFunc_opendir);
417 TLI.setUnavailable(LibFunc_pclose);
418 TLI.setUnavailable(LibFunc_popen);
419 TLI.setUnavailable(LibFunc_read);
420 TLI.setUnavailable(LibFunc_rmdir);
421 TLI.setUnavailable(LibFunc_stat);
422 TLI.setUnavailable(LibFunc_strcasecmp);
423 TLI.setUnavailable(LibFunc_strncasecmp);
424 TLI.setUnavailable(LibFunc_unlink);
425 TLI.setUnavailable(LibFunc_utime);
426 TLI.setUnavailable(LibFunc_write);
427 }
428
429 if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) {
430 // These functions aren't available in either MSVC or MinGW environments.
431 TLI.setUnavailable(LibFunc_bcmp);
432 TLI.setUnavailable(LibFunc_bcopy);
433 TLI.setUnavailable(LibFunc_bzero);
434 TLI.setUnavailable(LibFunc_chown);
435 TLI.setUnavailable(LibFunc_ctermid);
436 TLI.setUnavailable(LibFunc_ffs);
437 TLI.setUnavailable(LibFunc_flockfile);
438 TLI.setUnavailable(LibFunc_fstatvfs);
439 TLI.setUnavailable(LibFunc_ftrylockfile);
440 TLI.setUnavailable(LibFunc_funlockfile);
441 TLI.setUnavailable(LibFunc_getitimer);
442 TLI.setUnavailable(LibFunc_getlogin_r);
443 TLI.setUnavailable(LibFunc_getpwnam);
444 TLI.setUnavailable(LibFunc_htonl);
445 TLI.setUnavailable(LibFunc_htons);
446 TLI.setUnavailable(LibFunc_lchown);
447 TLI.setUnavailable(LibFunc_lstat);
448 TLI.setUnavailable(LibFunc_memrchr);
449 TLI.setUnavailable(LibFunc_ntohl);
450 TLI.setUnavailable(LibFunc_ntohs);
451 TLI.setUnavailable(LibFunc_pread);
452 TLI.setUnavailable(LibFunc_pwrite);
453 TLI.setUnavailable(LibFunc_readlink);
454 TLI.setUnavailable(LibFunc_realpath);
455 TLI.setUnavailable(LibFunc_setitimer);
456 TLI.setUnavailable(LibFunc_statvfs);
457 TLI.setUnavailable(LibFunc_stpcpy);
458 TLI.setUnavailable(LibFunc_stpncpy);
459 TLI.setUnavailable(LibFunc_times);
460 TLI.setUnavailable(LibFunc_uname);
461 TLI.setUnavailable(LibFunc_unsetenv);
462 TLI.setUnavailable(LibFunc_utimes);
463
464 // MinGW does have ldexpf, but it is a plain wrapper over regular ldexp.
465 // Therefore it's not beneficial to transform code to use it, i.e.
466 // just pretend that the function is not available.
467 TLI.setUnavailable(LibFunc_ldexpf);
468 }
469
470 // Pick just one set of new/delete variants.
471 if (T.isOSMSVCRT()) {
472 // MSVC, doesn't have the Itanium new/delete.
473 TLI.setUnavailable(LibFunc_ZdaPv);
474 TLI.setUnavailable(LibFunc_ZdaPvRKSt9nothrow_t);
475 TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_t);
476 TLI.setUnavailable(LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t);
477 TLI.setUnavailable(LibFunc_ZdaPvj);
478 TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
479 TLI.setUnavailable(LibFunc_ZdaPvm);
480 TLI.setUnavailable(LibFunc_ZdaPvmSt11align_val_t);
481 TLI.setUnavailable(LibFunc_ZdlPv);
482 TLI.setUnavailable(LibFunc_ZdlPvRKSt9nothrow_t);
483 TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_t);
484 TLI.setUnavailable(LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t);
485 TLI.setUnavailable(LibFunc_ZdlPvj);
486 TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
487 TLI.setUnavailable(LibFunc_ZdlPvm);
488 TLI.setUnavailable(LibFunc_ZdlPvmSt11align_val_t);
489 TLI.setUnavailable(LibFunc_Znaj);
490 TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
491 TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
492 TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
493 TLI.setUnavailable(LibFunc_Znam);
494 TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t);
495 TLI.setUnavailable(LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t);
496 TLI.setUnavailable(LibFunc_ZnamSt11align_val_t);
497 TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t);
498 TLI.setUnavailable(LibFunc_Znwj);
499 TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
500 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
501 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
502 TLI.setUnavailable(LibFunc_Znwm);
503 TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t);
504 TLI.setUnavailable(LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t);
505 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t);
506 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t);
507 TLI.setUnavailable(LibFunc_Znwm12__hot_cold_t);
508 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_t12__hot_cold_t);
509 TLI.setUnavailable(LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
510 TLI.setUnavailable(LibFunc_Znam12__hot_cold_t);
511 TLI.setUnavailable(LibFunc_ZnamSt11align_val_t12__hot_cold_t);
512 TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
513 } else {
514 // Not MSVC, assume it's Itanium.
515 TLI.setUnavailable(LibFunc_msvc_new_int);
516 TLI.setUnavailable(LibFunc_msvc_new_int_nothrow);
517 TLI.setUnavailable(LibFunc_msvc_new_longlong);
518 TLI.setUnavailable(LibFunc_msvc_new_longlong_nothrow);
519 TLI.setUnavailable(LibFunc_msvc_delete_ptr32);
520 TLI.setUnavailable(LibFunc_msvc_delete_ptr32_nothrow);
521 TLI.setUnavailable(LibFunc_msvc_delete_ptr32_int);
522 TLI.setUnavailable(LibFunc_msvc_delete_ptr64);
523 TLI.setUnavailable(LibFunc_msvc_delete_ptr64_nothrow);
524 TLI.setUnavailable(LibFunc_msvc_delete_ptr64_longlong);
525 TLI.setUnavailable(LibFunc_msvc_new_array_int);
526 TLI.setUnavailable(LibFunc_msvc_new_array_int_nothrow);
527 TLI.setUnavailable(LibFunc_msvc_new_array_longlong);
528 TLI.setUnavailable(LibFunc_msvc_new_array_longlong_nothrow);
529 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32);
530 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_nothrow);
531 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr32_int);
532 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64);
533 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_nothrow);
534 TLI.setUnavailable(LibFunc_msvc_delete_array_ptr64_longlong);
535 }
536
537 switch (T.getOS()) {
538 case Triple::MacOSX:
539 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
540 // and their names are __exp10 and __exp10f. exp10l is not available on
541 // OS X or iOS.
542 TLI.setUnavailable(LibFunc_exp10l);
543 if (T.isMacOSXVersionLT(10, 9)) {
544 TLI.setUnavailable(LibFunc_exp10);
545 TLI.setUnavailable(LibFunc_exp10f);
546 } else {
547 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
548 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
549 }
550 break;
551 case Triple::IOS:
552 case Triple::TvOS:
553 case Triple::WatchOS:
554 case Triple::XROS:
555 TLI.setUnavailable(LibFunc_exp10l);
556 if (!T.isWatchOS() &&
557 (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) {
558 TLI.setUnavailable(LibFunc_exp10);
559 TLI.setUnavailable(LibFunc_exp10f);
560 } else {
561 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
562 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
563 }
564 break;
565 case Triple::Linux:
566 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
567 // buggy prior to glibc version 2.18. Until this version is widely deployed
568 // or we have a reasonable detection strategy, we cannot use exp10 reliably
569 // on Linux.
570 //
571 // Fall through to disable all of them.
572 [[fallthrough]];
573 default:
574 TLI.setUnavailable(LibFunc_exp10);
575 TLI.setUnavailable(LibFunc_exp10f);
576 TLI.setUnavailable(LibFunc_exp10l);
577 }
578
579 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
580 // Linux (GLIBC):
581 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
582 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
583 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
584 switch (T.getOS()) {
585 case Triple::Darwin:
586 case Triple::MacOSX:
587 case Triple::IOS:
588 case Triple::TvOS:
589 case Triple::WatchOS:
590 case Triple::XROS:
591 case Triple::FreeBSD:
592 case Triple::Linux:
593 break;
594 default:
595 TLI.setUnavailable(LibFunc_ffsl);
596 }
597
598 // ffsll is available on at least FreeBSD and Linux (GLIBC):
599 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
600 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
601 switch (T.getOS()) {
602 case Triple::Darwin:
603 case Triple::MacOSX:
604 case Triple::IOS:
605 case Triple::TvOS:
606 case Triple::WatchOS:
607 case Triple::XROS:
608 case Triple::FreeBSD:
609 case Triple::Linux:
610 break;
611 default:
612 TLI.setUnavailable(LibFunc_ffsll);
613 }
614
615 // The following functions are available on at least FreeBSD:
616 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
617 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
618 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
619 if (!T.isOSFreeBSD()) {
620 TLI.setUnavailable(LibFunc_fls);
621 TLI.setUnavailable(LibFunc_flsl);
622 TLI.setUnavailable(LibFunc_flsll);
623 }
624
625 // The following functions are only available on GNU/Linux (using glibc).
626 // Linux variants without glibc (eg: bionic, musl) may have some subset.
627 if (!T.isOSLinux() || !T.isGNUEnvironment()) {
628 TLI.setUnavailable(LibFunc_dunder_strdup);
629 TLI.setUnavailable(LibFunc_dunder_strtok_r);
630 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
631 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
632 TLI.setUnavailable(LibFunc_under_IO_getc);
633 TLI.setUnavailable(LibFunc_under_IO_putc);
634 // But, Android and musl have memalign.
635 if (!T.isAndroid() && !T.isMusl())
636 TLI.setUnavailable(LibFunc_memalign);
637 TLI.setUnavailable(LibFunc_fopen64);
638 TLI.setUnavailable(LibFunc_fseeko64);
639 TLI.setUnavailable(LibFunc_fstat64);
640 TLI.setUnavailable(LibFunc_fstatvfs64);
641 TLI.setUnavailable(LibFunc_ftello64);
642 TLI.setUnavailable(LibFunc_lstat64);
643 TLI.setUnavailable(LibFunc_open64);
644 TLI.setUnavailable(LibFunc_stat64);
645 TLI.setUnavailable(LibFunc_statvfs64);
646 TLI.setUnavailable(LibFunc_tmpfile64);
647
648 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
649 // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
650 // so we keep these functions around just so that they're recognized by
651 // the ConstantFolder.
652 TLI.setUnavailable(LibFunc_acos_finite);
653 TLI.setUnavailable(LibFunc_acosf_finite);
654 TLI.setUnavailable(LibFunc_acosl_finite);
655 TLI.setUnavailable(LibFunc_acosh_finite);
656 TLI.setUnavailable(LibFunc_acoshf_finite);
657 TLI.setUnavailable(LibFunc_acoshl_finite);
658 TLI.setUnavailable(LibFunc_asin_finite);
659 TLI.setUnavailable(LibFunc_asinf_finite);
660 TLI.setUnavailable(LibFunc_asinl_finite);
661 TLI.setUnavailable(LibFunc_atan2_finite);
662 TLI.setUnavailable(LibFunc_atan2f_finite);
663 TLI.setUnavailable(LibFunc_atan2l_finite);
664 TLI.setUnavailable(LibFunc_atanh_finite);
665 TLI.setUnavailable(LibFunc_atanhf_finite);
666 TLI.setUnavailable(LibFunc_atanhl_finite);
667 TLI.setUnavailable(LibFunc_cosh_finite);
668 TLI.setUnavailable(LibFunc_coshf_finite);
669 TLI.setUnavailable(LibFunc_coshl_finite);
670 TLI.setUnavailable(LibFunc_exp10_finite);
671 TLI.setUnavailable(LibFunc_exp10f_finite);
672 TLI.setUnavailable(LibFunc_exp10l_finite);
673 TLI.setUnavailable(LibFunc_exp2_finite);
674 TLI.setUnavailable(LibFunc_exp2f_finite);
675 TLI.setUnavailable(LibFunc_exp2l_finite);
676 TLI.setUnavailable(LibFunc_exp_finite);
677 TLI.setUnavailable(LibFunc_expf_finite);
678 TLI.setUnavailable(LibFunc_expl_finite);
679 TLI.setUnavailable(LibFunc_log10_finite);
680 TLI.setUnavailable(LibFunc_log10f_finite);
681 TLI.setUnavailable(LibFunc_log10l_finite);
682 TLI.setUnavailable(LibFunc_log2_finite);
683 TLI.setUnavailable(LibFunc_log2f_finite);
684 TLI.setUnavailable(LibFunc_log2l_finite);
685 TLI.setUnavailable(LibFunc_log_finite);
686 TLI.setUnavailable(LibFunc_logf_finite);
687 TLI.setUnavailable(LibFunc_logl_finite);
688 TLI.setUnavailable(LibFunc_pow_finite);
689 TLI.setUnavailable(LibFunc_powf_finite);
690 TLI.setUnavailable(LibFunc_powl_finite);
691 TLI.setUnavailable(LibFunc_sinh_finite);
692 TLI.setUnavailable(LibFunc_sinhf_finite);
693 TLI.setUnavailable(LibFunc_sinhl_finite);
694 TLI.setUnavailable(LibFunc_sqrt_finite);
695 TLI.setUnavailable(LibFunc_sqrtf_finite);
696 TLI.setUnavailable(LibFunc_sqrtl_finite);
697 }
698
699 if ((T.isOSLinux() && T.isGNUEnvironment()) ||
700 (T.isAndroid() && !T.isAndroidVersionLT(28))) {
701 // available IO unlocked variants on GNU/Linux and Android P or later
702 TLI.setAvailable(LibFunc_getc_unlocked);
703 TLI.setAvailable(LibFunc_getchar_unlocked);
704 TLI.setAvailable(LibFunc_putc_unlocked);
705 TLI.setAvailable(LibFunc_putchar_unlocked);
706 TLI.setAvailable(LibFunc_fputc_unlocked);
707 TLI.setAvailable(LibFunc_fgetc_unlocked);
708 TLI.setAvailable(LibFunc_fread_unlocked);
709 TLI.setAvailable(LibFunc_fwrite_unlocked);
710 TLI.setAvailable(LibFunc_fputs_unlocked);
711 TLI.setAvailable(LibFunc_fgets_unlocked);
712 }
713
714 if (T.isAndroid() && T.isAndroidVersionLT(21)) {
715 TLI.setUnavailable(LibFunc_stpcpy);
716 TLI.setUnavailable(LibFunc_stpncpy);
717 }
718
719 if (T.isPS()) {
720 // PS4/PS5 do have memalign.
721 TLI.setAvailable(LibFunc_memalign);
722
723 // PS4/PS5 do not have new/delete with "unsigned int" size parameter;
724 // they only have the "unsigned long" versions.
725 TLI.setUnavailable(LibFunc_ZdaPvj);
726 TLI.setUnavailable(LibFunc_ZdaPvjSt11align_val_t);
727 TLI.setUnavailable(LibFunc_ZdlPvj);
728 TLI.setUnavailable(LibFunc_ZdlPvjSt11align_val_t);
729 TLI.setUnavailable(LibFunc_Znaj);
730 TLI.setUnavailable(LibFunc_ZnajRKSt9nothrow_t);
731 TLI.setUnavailable(LibFunc_ZnajSt11align_val_t);
732 TLI.setUnavailable(LibFunc_ZnajSt11align_val_tRKSt9nothrow_t);
733 TLI.setUnavailable(LibFunc_Znwj);
734 TLI.setUnavailable(LibFunc_ZnwjRKSt9nothrow_t);
735 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_t);
736 TLI.setUnavailable(LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t);
737
738 // None of the *_chk functions.
739 TLI.setUnavailable(LibFunc_memccpy_chk);
740 TLI.setUnavailable(LibFunc_memcpy_chk);
741 TLI.setUnavailable(LibFunc_memmove_chk);
742 TLI.setUnavailable(LibFunc_mempcpy_chk);
743 TLI.setUnavailable(LibFunc_memset_chk);
744 TLI.setUnavailable(LibFunc_snprintf_chk);
745 TLI.setUnavailable(LibFunc_sprintf_chk);
746 TLI.setUnavailable(LibFunc_stpcpy_chk);
747 TLI.setUnavailable(LibFunc_stpncpy_chk);
748 TLI.setUnavailable(LibFunc_strcat_chk);
749 TLI.setUnavailable(LibFunc_strcpy_chk);
750 TLI.setUnavailable(LibFunc_strlcat_chk);
751 TLI.setUnavailable(LibFunc_strlcpy_chk);
752 TLI.setUnavailable(LibFunc_strlen_chk);
753 TLI.setUnavailable(LibFunc_strncat_chk);
754 TLI.setUnavailable(LibFunc_strncpy_chk);
755 TLI.setUnavailable(LibFunc_vsnprintf_chk);
756 TLI.setUnavailable(LibFunc_vsprintf_chk);
757
758 // Various Posix system functions.
759 TLI.setUnavailable(LibFunc_access);
760 TLI.setUnavailable(LibFunc_chmod);
761 TLI.setUnavailable(LibFunc_chown);
762 TLI.setUnavailable(LibFunc_closedir);
763 TLI.setUnavailable(LibFunc_ctermid);
764 TLI.setUnavailable(LibFunc_execl);
765 TLI.setUnavailable(LibFunc_execle);
766 TLI.setUnavailable(LibFunc_execlp);
767 TLI.setUnavailable(LibFunc_execv);
768 TLI.setUnavailable(LibFunc_execvP);
769 TLI.setUnavailable(LibFunc_execve);
770 TLI.setUnavailable(LibFunc_execvp);
771 TLI.setUnavailable(LibFunc_execvpe);
772 TLI.setUnavailable(LibFunc_fork);
773 TLI.setUnavailable(LibFunc_fstat);
774 TLI.setUnavailable(LibFunc_fstatvfs);
775 TLI.setUnavailable(LibFunc_getenv);
776 TLI.setUnavailable(LibFunc_getitimer);
777 TLI.setUnavailable(LibFunc_getlogin_r);
778 TLI.setUnavailable(LibFunc_getpwnam);
779 TLI.setUnavailable(LibFunc_gettimeofday);
780 TLI.setUnavailable(LibFunc_lchown);
781 TLI.setUnavailable(LibFunc_lstat);
782 TLI.setUnavailable(LibFunc_mkdir);
783 TLI.setUnavailable(LibFunc_open);
784 TLI.setUnavailable(LibFunc_opendir);
785 TLI.setUnavailable(LibFunc_pclose);
786 TLI.setUnavailable(LibFunc_popen);
787 TLI.setUnavailable(LibFunc_pread);
788 TLI.setUnavailable(LibFunc_pwrite);
789 TLI.setUnavailable(LibFunc_read);
790 TLI.setUnavailable(LibFunc_readlink);
791 TLI.setUnavailable(LibFunc_realpath);
792 TLI.setUnavailable(LibFunc_rename);
793 TLI.setUnavailable(LibFunc_rmdir);
794 TLI.setUnavailable(LibFunc_setitimer);
795 TLI.setUnavailable(LibFunc_stat);
796 TLI.setUnavailable(LibFunc_statvfs);
797 TLI.setUnavailable(LibFunc_system);
798 TLI.setUnavailable(LibFunc_times);
799 TLI.setUnavailable(LibFunc_tmpfile);
800 TLI.setUnavailable(LibFunc_unlink);
801 TLI.setUnavailable(LibFunc_uname);
802 TLI.setUnavailable(LibFunc_unsetenv);
803 TLI.setUnavailable(LibFunc_utime);
804 TLI.setUnavailable(LibFunc_utimes);
805 TLI.setUnavailable(LibFunc_valloc);
806 TLI.setUnavailable(LibFunc_write);
807
808 // Miscellaneous other functions not provided.
809 TLI.setUnavailable(LibFunc_atomic_load);
810 TLI.setUnavailable(LibFunc_atomic_store);
811 TLI.setUnavailable(LibFunc___kmpc_alloc_shared);
812 TLI.setUnavailable(LibFunc___kmpc_free_shared);
813 TLI.setUnavailable(LibFunc_dunder_strndup);
814 TLI.setUnavailable(LibFunc_bcmp);
815 TLI.setUnavailable(LibFunc_bcopy);
816 TLI.setUnavailable(LibFunc_bzero);
817 TLI.setUnavailable(LibFunc_cabs);
818 TLI.setUnavailable(LibFunc_cabsf);
819 TLI.setUnavailable(LibFunc_cabsl);
820 TLI.setUnavailable(LibFunc_ffs);
821 TLI.setUnavailable(LibFunc_flockfile);
822 TLI.setUnavailable(LibFunc_fseeko);
823 TLI.setUnavailable(LibFunc_ftello);
824 TLI.setUnavailable(LibFunc_ftrylockfile);
825 TLI.setUnavailable(LibFunc_funlockfile);
826 TLI.setUnavailable(LibFunc_htonl);
827 TLI.setUnavailable(LibFunc_htons);
828 TLI.setUnavailable(LibFunc_isascii);
829 TLI.setUnavailable(LibFunc_memccpy);
830 TLI.setUnavailable(LibFunc_mempcpy);
831 TLI.setUnavailable(LibFunc_memrchr);
832 TLI.setUnavailable(LibFunc_ntohl);
833 TLI.setUnavailable(LibFunc_ntohs);
834 TLI.setUnavailable(LibFunc_reallocf);
835 TLI.setUnavailable(LibFunc_roundeven);
836 TLI.setUnavailable(LibFunc_roundevenf);
837 TLI.setUnavailable(LibFunc_roundevenl);
838 TLI.setUnavailable(LibFunc_stpcpy);
839 TLI.setUnavailable(LibFunc_stpncpy);
840 TLI.setUnavailable(LibFunc_strlcat);
841 TLI.setUnavailable(LibFunc_strlcpy);
842 TLI.setUnavailable(LibFunc_strndup);
843 TLI.setUnavailable(LibFunc_strnlen);
844 TLI.setUnavailable(LibFunc_toascii);
845 }
846
847 // As currently implemented in clang, NVPTX code has no standard library to
848 // speak of. Headers provide a standard-ish library implementation, but many
849 // of the signatures are wrong -- for example, many libm functions are not
850 // extern "C".
851 //
852 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
853 // but only used functions are provided to llvm. Moreover, most of the
854 // functions in libdevice don't map precisely to standard library functions.
855 //
856 // FIXME: Having no standard library prevents e.g. many fastmath
857 // optimizations, so this situation should be fixed.
858 if (T.isNVPTX()) {
860 TLI.setAvailable(LibFunc_nvvm_reflect);
861 TLI.setAvailable(llvm::LibFunc_malloc);
862 TLI.setAvailable(llvm::LibFunc_free);
863
864 // TODO: We could enable the following two according to [0] but we haven't
865 // done an evaluation wrt. the performance implications.
866 // [0]
867 // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations
868 //
869 // TLI.setAvailable(llvm::LibFunc_memcpy);
870 // TLI.setAvailable(llvm::LibFunc_memset);
871
872 TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared);
873 TLI.setAvailable(llvm::LibFunc___kmpc_free_shared);
874 } else {
875 TLI.setUnavailable(LibFunc_nvvm_reflect);
876 }
877
878 // These vec_malloc/free routines are only available on AIX.
879 if (!T.isOSAIX()) {
880 TLI.setUnavailable(LibFunc_vec_calloc);
881 TLI.setUnavailable(LibFunc_vec_malloc);
882 TLI.setUnavailable(LibFunc_vec_realloc);
883 TLI.setUnavailable(LibFunc_vec_free);
884 }
885
886 if (T.isOSAIX())
887 TLI.setUnavailable(LibFunc_memrchr);
888
890}
891
892/// Initialize the set of available library functions based on the specified
893/// target triple. This should be carefully written so that a missing target
894/// triple gets a sane set of defaults.
895static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
896 ArrayRef<StringLiteral> StandardNames) {
897 initializeBase(TLI, T);
898 initializeLibCalls(TLI, T, StandardNames);
899}
900
902 // Default to nothing being available.
903 memset(AvailableArray, 0, sizeof(AvailableArray));
904 initializeBase(*this, Triple());
905}
906
908 // Default to everything being available.
909 memset(AvailableArray, -1, sizeof(AvailableArray));
910
911 initialize(*this, T, StandardNames);
912}
913
915 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
916 ShouldExtI32Return(TLI.ShouldExtI32Return),
917 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
918 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
919 SizeOfInt(TLI.SizeOfInt) {
920 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
921 VectorDescs = TLI.VectorDescs;
922 ScalarDescs = TLI.ScalarDescs;
923}
924
926 : CustomNames(std::move(TLI.CustomNames)),
927 ShouldExtI32Param(TLI.ShouldExtI32Param),
928 ShouldExtI32Return(TLI.ShouldExtI32Return),
929 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param),
930 ShouldSignExtI32Return(TLI.ShouldSignExtI32Return),
931 SizeOfInt(TLI.SizeOfInt) {
932 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
933 AvailableArray);
934 VectorDescs = TLI.VectorDescs;
935 ScalarDescs = TLI.ScalarDescs;
936}
937
939 CustomNames = TLI.CustomNames;
940 ShouldExtI32Param = TLI.ShouldExtI32Param;
941 ShouldExtI32Return = TLI.ShouldExtI32Return;
942 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
943 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
944 SizeOfInt = TLI.SizeOfInt;
945 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
946 return *this;
947}
948
950 CustomNames = std::move(TLI.CustomNames);
951 ShouldExtI32Param = TLI.ShouldExtI32Param;
952 ShouldExtI32Return = TLI.ShouldExtI32Return;
953 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
954 ShouldSignExtI32Return = TLI.ShouldSignExtI32Return;
955 SizeOfInt = TLI.SizeOfInt;
956 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
957 AvailableArray);
958 return *this;
959}
960
962 // Filter out empty names and names containing null bytes, those can't be in
963 // our table.
964 if (funcName.empty() || funcName.contains('\0'))
965 return StringRef();
966
967 // Check for \01 prefix that is used to mangle __asm declarations and
968 // strip it if present.
970}
971
975 unsigned Idx = 0;
977 for (const auto &Func : StandardNames)
978 Indices[Func] = static_cast<LibFunc>(Idx++);
979 return Indices;
980}
981
983 funcName = sanitizeFunctionName(funcName);
984 if (funcName.empty())
985 return false;
986
987 static const DenseMap<StringRef, LibFunc> Indices =
988 buildIndexMap(StandardNames);
989
990 if (auto Loc = Indices.find(funcName); Loc != Indices.end()) {
991 F = Loc->second;
992 return true;
993 }
994 return false;
995}
996
997// Return true if ArgTy matches Ty.
998
999static bool matchType(FuncArgTypeID ArgTy, const Type *Ty, unsigned IntBits,
1000 unsigned SizeTBits) {
1001 switch (ArgTy) {
1002 case Void:
1003 return Ty->isVoidTy();
1004 case Bool:
1005 return Ty->isIntegerTy(8);
1006 case Int16:
1007 return Ty->isIntegerTy(16);
1008 case Int32:
1009 return Ty->isIntegerTy(32);
1010 case Int:
1011 return Ty->isIntegerTy(IntBits);
1012 case IntPlus:
1013 return Ty->isIntegerTy() && Ty->getPrimitiveSizeInBits() >= IntBits;
1014 case IntX:
1015 return Ty->isIntegerTy();
1016 case Long:
1017 // TODO: Figure out and use long size.
1018 return Ty->isIntegerTy() && Ty->getPrimitiveSizeInBits() >= IntBits;
1019 case Int64:
1020 return Ty->isIntegerTy(64);
1021 case LLong:
1022 return Ty->isIntegerTy(64);
1023 case SizeT:
1024 case SSizeT:
1025 return Ty->isIntegerTy(SizeTBits);
1026 case Flt:
1027 return Ty->isFloatTy();
1028 case Dbl:
1029 return Ty->isDoubleTy();
1030 // TODO: Tighten this up.
1031 case LDbl:
1032 return Ty->isFloatingPointTy();
1033 case Floating:
1034 return Ty->isFloatingPointTy();
1035 case Ptr:
1036 return Ty->isPointerTy();
1037 case Struct:
1038 return Ty->isStructTy();
1039 default:
1040 break;
1041 }
1042
1043 llvm_unreachable("Invalid type");
1044}
1045
1046bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
1047 LibFunc F,
1048 const Module &M) const {
1049 unsigned NumParams = FTy.getNumParams();
1050
1051 switch (F) {
1052 // Special handling for <complex.h> functions:
1053 case LibFunc_cabs:
1054 case LibFunc_cabsf:
1055 case LibFunc_cabsl: {
1056 Type *RetTy = FTy.getReturnType();
1057 if (!RetTy->isFloatingPointTy())
1058 return false;
1059
1060 Type *ParamTy = FTy.getParamType(0);
1061 // NOTE: These prototypes are target specific and currently support
1062 // "complex" passed as an array or discrete real & imaginary parameters.
1063 // Add other calling conventions to enable libcall optimizations.
1064 if (NumParams == 1)
1065 return (ParamTy->isArrayTy() && ParamTy->getArrayNumElements() == 2 &&
1066 ParamTy->getArrayElementType() == RetTy);
1067 else if (NumParams == 2)
1068 return ParamTy == RetTy && FTy.getParamType(1) == RetTy;
1069
1070 return false;
1071 }
1072 // Special handling for the sincospi functions that return either
1073 // a struct or vector:
1074 case LibFunc_sincospi_stret:
1075 case LibFunc_sincospif_stret: {
1076 if (NumParams != 1)
1077 return false;
1078
1079 Type *RetTy = FTy.getReturnType();
1080 Type *ParamTy = FTy.getParamType(0);
1081 if (auto *Ty = dyn_cast<StructType>(RetTy)) {
1082 if (Ty->getNumElements() != 2)
1083 return false;
1084 return (Ty->getElementType(0) == ParamTy &&
1085 Ty->getElementType(1) == ParamTy);
1086 }
1087
1088 if (auto *Ty = dyn_cast<FixedVectorType>(RetTy)) {
1089 if (Ty->getNumElements() != 2)
1090 return false;
1091 return Ty->getElementType() == ParamTy;
1092 }
1093
1094 return false;
1095 }
1096
1097 default:
1098 break;
1099 }
1100
1101 unsigned IntBits = getIntSize();
1102 unsigned SizeTBits = getSizeTSize(M);
1103 unsigned Idx = 0;
1104
1105 // Iterate over the type ids in the function prototype, matching each
1106 // against the function's type FTy, starting with its return type.
1107 // Return true if both match in number and kind, inclduing the ellipsis.
1108 Type *Ty = FTy.getReturnType(), *LastTy = Ty;
1109 const auto &ProtoTypes = Signatures[F];
1110 for (auto TyID : ProtoTypes) {
1111 if (Idx && TyID == Void)
1112 // Except in the first position where it designates the function's
1113 // return type Void ends the argument list.
1114 break;
1115
1116 if (TyID == Ellip) {
1117 // The ellipsis ends the protoype list but is not a part of FTy's
1118 // argument list. Except when it's last it must be followed by
1119 // Void.
1120 assert(Idx == ProtoTypes.size() - 1 || ProtoTypes[Idx + 1] == Void);
1121 return FTy.isFunctionVarArg();
1122 }
1123
1124 if (TyID == Same) {
1125 assert(Idx != 0 && "Type ID 'Same' must not be first!");
1126 if (Ty != LastTy)
1127 return false;
1128 } else {
1129 if (!Ty || !matchType(TyID, Ty, IntBits, SizeTBits))
1130 return false;
1131 LastTy = Ty;
1132 }
1133
1134 if (Idx == NumParams) {
1135 // There's at least one and at most two more type ids than there are
1136 // arguments in FTy's argument list.
1137 Ty = nullptr;
1138 ++Idx;
1139 continue;
1140 }
1141
1142 Ty = FTy.getParamType(Idx++);
1143 }
1144
1145 // Return success only if all entries on both lists have been processed
1146 // and the function is not a variadic one.
1147 return Idx == NumParams + 1 && !FTy.isFunctionVarArg();
1148}
1149
1151 LibFunc &F) const {
1152 // Intrinsics don't overlap w/libcalls; if our module has a large number of
1153 // intrinsics, this ends up being an interesting compile time win since we
1154 // avoid string normalization and comparison.
1155 if (FDecl.isIntrinsic()) return false;
1156
1157 const Module *M = FDecl.getParent();
1158 assert(M && "Expecting FDecl to be connected to a Module.");
1159
1160 if (FDecl.LibFuncCache == Function::UnknownLibFunc)
1161 if (!getLibFunc(FDecl.getName(), FDecl.LibFuncCache))
1162 FDecl.LibFuncCache = NotLibFunc;
1163
1164 if (FDecl.LibFuncCache == NotLibFunc)
1165 return false;
1166
1167 F = FDecl.LibFuncCache;
1168 return isValidProtoForLibFunc(*FDecl.getFunctionType(), F, *M);
1169}
1170
1171bool TargetLibraryInfoImpl::getLibFunc(unsigned int Opcode, Type *Ty,
1172 LibFunc &F) const {
1173 // Must be a frem instruction with float or double arguments.
1174 if (Opcode != Instruction::FRem || (!Ty->isDoubleTy() && !Ty->isFloatTy()))
1175 return false;
1176
1177 F = Ty->isDoubleTy() ? LibFunc_fmod : LibFunc_fmodf;
1178 return true;
1179}
1180
1182 memset(AvailableArray, 0, sizeof(AvailableArray));
1183}
1184
1185static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1186 return LHS.getScalarFnName() < RHS.getScalarFnName();
1187}
1188
1189static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1190 return LHS.getVectorFnName() < RHS.getVectorFnName();
1191}
1192
1193static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1194 return LHS.getScalarFnName() < S;
1195}
1196
1198 llvm::append_range(VectorDescs, Fns);
1199 llvm::sort(VectorDescs, compareByScalarFnName);
1200
1201 llvm::append_range(ScalarDescs, Fns);
1202 llvm::sort(ScalarDescs, compareByVectorFnName);
1203}
1204
1206#define TLI_DEFINE_ACCELERATE_VECFUNCS
1207#include "llvm/Analysis/VecFuncs.def"
1208#undef TLI_DEFINE_ACCELERATE_VECFUNCS
1209};
1210
1212#define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1213#include "llvm/Analysis/VecFuncs.def"
1214#undef TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
1215};
1216
1218#define TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1219#include "llvm/Analysis/VecFuncs.def"
1220#undef TLI_DEFINE_LIBMVEC_X86_VECFUNCS
1221};
1222
1223static const VecDesc VecFuncs_MASSV[] = {
1224#define TLI_DEFINE_MASSV_VECFUNCS
1225#include "llvm/Analysis/VecFuncs.def"
1226#undef TLI_DEFINE_MASSV_VECFUNCS
1227};
1228
1229static const VecDesc VecFuncs_SVML[] = {
1230#define TLI_DEFINE_SVML_VECFUNCS
1231#include "llvm/Analysis/VecFuncs.def"
1232#undef TLI_DEFINE_SVML_VECFUNCS
1233};
1234
1236#define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1237#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \
1238 {SCAL, VEC, VF, /* MASK = */ false, VABI_PREFIX},
1239#include "llvm/Analysis/VecFuncs.def"
1240#undef TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1241};
1243#define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1244#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) \
1245 {SCAL, VEC, VF, /* MASK = */ false, VABI_PREFIX},
1246#include "llvm/Analysis/VecFuncs.def"
1247#undef TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1248};
1250#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1251#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1252 {SCAL, VEC, VF, MASK, VABI_PREFIX},
1253#include "llvm/Analysis/VecFuncs.def"
1254#undef TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1255};
1256
1257static const VecDesc VecFuncs_ArmPL[] = {
1258#define TLI_DEFINE_ARMPL_VECFUNCS
1259#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1260 {SCAL, VEC, VF, MASK, VABI_PREFIX},
1261#include "llvm/Analysis/VecFuncs.def"
1262#undef TLI_DEFINE_ARMPL_VECFUNCS
1263};
1264
1266#define TLI_DEFINE_AMDLIBM_VECFUNCS
1267#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK, VABI_PREFIX) \
1268 {SCAL, VEC, VF, MASK, VABI_PREFIX},
1269#include "llvm/Analysis/VecFuncs.def"
1270#undef TLI_DEFINE_AMDLIBM_VECFUNCS
1271};
1272
1274 enum VectorLibrary VecLib, const llvm::Triple &TargetTriple) {
1275 switch (VecLib) {
1276 case Accelerate: {
1278 break;
1279 }
1280 case DarwinLibSystemM: {
1282 break;
1283 }
1284 case LIBMVEC_X86: {
1286 break;
1287 }
1288 case MASSV: {
1290 break;
1291 }
1292 case SVML: {
1294 break;
1295 }
1296 case SLEEFGNUABI: {
1297 switch (TargetTriple.getArch()) {
1298 default:
1299 break;
1305 break;
1306 }
1307 break;
1308 }
1309 case ArmPL: {
1310 switch (TargetTriple.getArch()) {
1311 default:
1312 break;
1316 break;
1317 }
1318 break;
1319 }
1320 case AMDLIBM: {
1322 break;
1323 }
1324 case NoLibrary:
1325 break;
1326 }
1327}
1328
1330 funcName = sanitizeFunctionName(funcName);
1331 if (funcName.empty())
1332 return false;
1333
1334 std::vector<VecDesc>::const_iterator I =
1335 llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1336 return I != VectorDescs.end() && StringRef(I->getScalarFnName()) == funcName;
1337}
1338
1340 const ElementCount &VF,
1341 bool Masked) const {
1342 const VecDesc *VD = getVectorMappingInfo(F, VF, Masked);
1343 if (VD)
1344 return VD->getVectorFnName();
1345 return StringRef();
1346}
1347
1348const VecDesc *
1350 bool Masked) const {
1352 if (F.empty())
1353 return nullptr;
1354 std::vector<VecDesc>::const_iterator I =
1356 while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == F) {
1357 if ((I->getVectorizationFactor() == VF) && (I->isMasked() == Masked))
1358 return &(*I);
1359 ++I;
1360 }
1361 return nullptr;
1362}
1363
1366 if (!BaselineInfoImpl)
1367 BaselineInfoImpl =
1368 TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple()));
1369 return TargetLibraryInfo(*BaselineInfoImpl, &F);
1370}
1371
1373 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1374 M.getModuleFlag("wchar_size")))
1375 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
1376 return 0;
1377}
1378
1380 // There is really no guarantee that sizeof(size_t) is equal to sizeof(int*).
1381 // If that isn't true then it should be possible to derive the SizeTTy from
1382 // the target triple here instead and do an early return.
1383
1384 // Historically LLVM assume that size_t has same size as intptr_t (hence
1385 // deriving the size from sizeof(int*) in address space zero). This should
1386 // work for most targets. For future consideration: DataLayout also implement
1387 // getIndexSizeInBits which might map better to size_t compared to
1388 // getPointerSizeInBits. Hard coding address space zero here might be
1389 // unfortunate as well. Maybe getDefaultGlobalsAddressSpace() or
1390 // getAllocaAddrSpace() is better.
1391 unsigned AddressSpace = 0;
1392 return M.getDataLayout().getPointerSizeInBits(AddressSpace);
1393}
1394
1398}
1399
1403}
1404
1406 const TargetLibraryInfoImpl &TLIImpl)
1407 : ImmutablePass(ID), TLA(TLIImpl) {
1409}
1410
1412 const TargetLibraryInfo &TLIOther)
1413 : TargetLibraryInfoWrapperPass(*TLIOther.Impl) {}
1414
1415AnalysisKey TargetLibraryAnalysis::Key;
1416
1417// Register the basic pass.
1419 "Target Library Information", false, true)
1421
1422void TargetLibraryInfoWrapperPass::anchor() {}
1423
1425 ElementCount &FixedVF,
1426 ElementCount &ScalableVF) const {
1427 ScalarF = sanitizeFunctionName(ScalarF);
1428 // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the
1429 // same as a scalar.
1430 ScalableVF = ElementCount::getScalable(0);
1431 FixedVF = ElementCount::getFixed(1);
1432 if (ScalarF.empty())
1433 return;
1434
1435 std::vector<VecDesc>::const_iterator I =
1436 llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
1437 while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == ScalarF) {
1438 ElementCount *VF =
1439 I->getVectorizationFactor().isScalable() ? &ScalableVF : &FixedVF;
1440 if (ElementCount::isKnownGT(I->getVectorizationFactor(), *VF))
1441 *VF = I->getVectorizationFactor();
1442 ++I;
1443 }
1444}
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:686
This file contains the declarations for the subclasses of Constant, which represent the different fla...
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
static bool hasSinCosPiStret(const Triple &T)
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 bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS)
static const VecDesc VecFuncs_SLEEFGNUABI_VF4[]
static const FuncProtoTy Signatures[]
static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT, FunctionType *FuncTy)
static const VecDesc VecFuncs_ArmPL[]
const VecDesc VecFuncs_AMDLIBM[]
static const VecDesc VecFuncs_LIBMVEC_X86[]
FuncArgTypeID
@ IntPlus
@ Floating
@ Struct
@ SSizeT
static const VecDesc VecFuncs_DarwinLibSystemM[]
static const VecDesc VecFuncs_SVML[]
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_X86, "LIBMVEC-X86", "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")))
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 DenseMap< StringRef, LibFunc > buildIndexMap(ArrayRef< StringLiteral > StandardNames)
Value * RHS
Value * LHS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
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...
Definition: InstrTypes.h:1236
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1523
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1323
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Definition: DenseMap.h:103
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition: TypeSize.h:311
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:308
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:207
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Definition: Function.h:247
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:567
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:656
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:282
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:66
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:297
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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:846
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:417
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 ...
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
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.
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.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
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 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...
TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
void disableAllFunctions()
Disables all builtins.
VectorLibrary
List of known vector-functions libraries.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
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.
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:44
@ Emscripten
Definition: Triple.h:237
@ aarch64_be
Definition: Triple.h:52
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:373
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:252
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:255
Type * getArrayElementType() const
Definition: Type.h:404
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
uint64_t getArrayNumElements() const
bool isStructTy() const
True if this is an instance of StructType.
Definition: Type.h:249
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:185
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:228
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:140
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
Provides info so a possible vectorization of a function can be computed.
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]]].
Definition: VersionTuple.h:29
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
Definition: TypeSize.h:222
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:691
StringRef str() const
Return a StringRef for the vector contents.
Definition: raw_ostream.h:720
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ ARM_APCS
ARM Procedure Calling Standard (obsolete, but still used on some targets).
Definition: CallingConv.h:107
@ ARM_AAPCS
ARM Architecture Procedure Calling Standard calling convention (aka EABI).
Definition: CallingConv.h:111
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
Definition: CallingConv.h:114
@ 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 ...
Definition: CommandLine.h:711
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AddressSpace
Definition: NVPTXBaseInfo.h:21
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2067
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1647
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:1954
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:1849
void initializeTargetLibraryInfoWrapperPassPass(PassRegistry &)
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28