1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the TargetLibraryInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/TargetLibraryInfo.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Support/CommandLine.h"
19 static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
20 "vector-library", cl::Hidden, cl::desc("Vector functions library"),
21 cl::init(TargetLibraryInfoImpl::NoLibrary),
22 cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
23 "No vector functions library"),
24 clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
25 "Accelerate framework"),
26 clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
27 "Intel SVML library")));
29 StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
30 #define TLI_DEFINE_STRING
31 #include "llvm/Analysis/TargetLibraryInfo.def"
34 static bool hasSinCosPiStret(const Triple &T) {
35 // Only Darwin variants have _stret versions of combined trig functions.
39 // The ABI is rather complicated on x86, so don't do anything special there.
40 if (T.getArch() == Triple::x86)
43 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
46 if (T.isiOS() && T.isOSVersionLT(7, 0))
52 /// initialize - Initialize the set of available library functions based on the
53 /// specified target triple. This should be carefully written so that a missing
54 /// target triple gets a sane set of defaults.
55 static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
56 ArrayRef<StringRef> StandardNames) {
57 // Verify that the StandardNames array is in alphabetical order.
58 assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
59 [](StringRef LHS, StringRef RHS) {
62 "TargetLibraryInfoImpl function names must be sorted");
64 bool ShouldExtI32Param = false, ShouldExtI32Return = false,
65 ShouldSignExtI32Param = false;
66 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
67 // returns corresponding to C-level ints and unsigned ints.
68 if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
69 T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
70 ShouldExtI32Param = true;
71 ShouldExtI32Return = true;
73 // Mips, on the other hand, needs signext on i32 parameters corresponding
74 // to both signed and unsigned ints.
75 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
76 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
77 ShouldSignExtI32Param = true;
79 TLI.setShouldExtI32Param(ShouldExtI32Param);
80 TLI.setShouldExtI32Return(ShouldExtI32Return);
81 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
83 if (T.getArch() == Triple::r600 ||
84 T.getArch() == Triple::amdgcn) {
85 TLI.setUnavailable(LibFunc::ldexp);
86 TLI.setUnavailable(LibFunc::ldexpf);
87 TLI.setUnavailable(LibFunc::ldexpl);
88 TLI.setUnavailable(LibFunc::exp10);
89 TLI.setUnavailable(LibFunc::exp10f);
90 TLI.setUnavailable(LibFunc::exp10l);
91 TLI.setUnavailable(LibFunc::log10);
92 TLI.setUnavailable(LibFunc::log10f);
93 TLI.setUnavailable(LibFunc::log10l);
96 // There are no library implementations of mempcy and memset for AMD gpus and
97 // these can be difficult to lower in the backend.
98 if (T.getArch() == Triple::r600 ||
99 T.getArch() == Triple::amdgcn) {
100 TLI.setUnavailable(LibFunc::memcpy);
101 TLI.setUnavailable(LibFunc::memset);
102 TLI.setUnavailable(LibFunc::memset_pattern16);
106 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
107 // All versions of watchOS support it.
109 if (T.isMacOSXVersionLT(10, 5))
110 TLI.setUnavailable(LibFunc::memset_pattern16);
111 } else if (T.isiOS()) {
112 if (T.isOSVersionLT(3, 0))
113 TLI.setUnavailable(LibFunc::memset_pattern16);
114 } else if (!T.isWatchOS()) {
115 TLI.setUnavailable(LibFunc::memset_pattern16);
118 if (!hasSinCosPiStret(T)) {
119 TLI.setUnavailable(LibFunc::sinpi);
120 TLI.setUnavailable(LibFunc::sinpif);
121 TLI.setUnavailable(LibFunc::cospi);
122 TLI.setUnavailable(LibFunc::cospif);
123 TLI.setUnavailable(LibFunc::sincospi_stret);
124 TLI.setUnavailable(LibFunc::sincospif_stret);
127 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
128 !T.isMacOSXVersionLT(10, 7)) {
129 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
130 // we don't care about) have two versions; on recent OSX, the one we want
131 // has a $UNIX2003 suffix. The two implementations are identical except
132 // for the return value in some edge cases. However, we don't want to
133 // generate code that depends on the old symbols.
134 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
135 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
138 // iprintf and friends are only available on XCore and TCE.
139 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
140 TLI.setUnavailable(LibFunc::iprintf);
141 TLI.setUnavailable(LibFunc::siprintf);
142 TLI.setUnavailable(LibFunc::fiprintf);
145 if (T.isOSWindows() && !T.isOSCygMing()) {
146 // Win32 does not support long double
147 TLI.setUnavailable(LibFunc::acosl);
148 TLI.setUnavailable(LibFunc::asinl);
149 TLI.setUnavailable(LibFunc::atanl);
150 TLI.setUnavailable(LibFunc::atan2l);
151 TLI.setUnavailable(LibFunc::ceill);
152 TLI.setUnavailable(LibFunc::copysignl);
153 TLI.setUnavailable(LibFunc::cosl);
154 TLI.setUnavailable(LibFunc::coshl);
155 TLI.setUnavailable(LibFunc::expl);
156 TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
157 TLI.setUnavailable(LibFunc::fabsl);
158 TLI.setUnavailable(LibFunc::floorl);
159 TLI.setUnavailable(LibFunc::fmaxl);
160 TLI.setUnavailable(LibFunc::fminl);
161 TLI.setUnavailable(LibFunc::fmodl);
162 TLI.setUnavailable(LibFunc::frexpl);
163 TLI.setUnavailable(LibFunc::ldexpf);
164 TLI.setUnavailable(LibFunc::ldexpl);
165 TLI.setUnavailable(LibFunc::logl);
166 TLI.setUnavailable(LibFunc::modfl);
167 TLI.setUnavailable(LibFunc::powl);
168 TLI.setUnavailable(LibFunc::sinl);
169 TLI.setUnavailable(LibFunc::sinhl);
170 TLI.setUnavailable(LibFunc::sqrtl);
171 TLI.setUnavailable(LibFunc::tanl);
172 TLI.setUnavailable(LibFunc::tanhl);
174 // Win32 only has C89 math
175 TLI.setUnavailable(LibFunc::acosh);
176 TLI.setUnavailable(LibFunc::acoshf);
177 TLI.setUnavailable(LibFunc::acoshl);
178 TLI.setUnavailable(LibFunc::asinh);
179 TLI.setUnavailable(LibFunc::asinhf);
180 TLI.setUnavailable(LibFunc::asinhl);
181 TLI.setUnavailable(LibFunc::atanh);
182 TLI.setUnavailable(LibFunc::atanhf);
183 TLI.setUnavailable(LibFunc::atanhl);
184 TLI.setUnavailable(LibFunc::cbrt);
185 TLI.setUnavailable(LibFunc::cbrtf);
186 TLI.setUnavailable(LibFunc::cbrtl);
187 TLI.setUnavailable(LibFunc::exp2);
188 TLI.setUnavailable(LibFunc::exp2f);
189 TLI.setUnavailable(LibFunc::exp2l);
190 TLI.setUnavailable(LibFunc::expm1);
191 TLI.setUnavailable(LibFunc::expm1f);
192 TLI.setUnavailable(LibFunc::expm1l);
193 TLI.setUnavailable(LibFunc::log2);
194 TLI.setUnavailable(LibFunc::log2f);
195 TLI.setUnavailable(LibFunc::log2l);
196 TLI.setUnavailable(LibFunc::log1p);
197 TLI.setUnavailable(LibFunc::log1pf);
198 TLI.setUnavailable(LibFunc::log1pl);
199 TLI.setUnavailable(LibFunc::logb);
200 TLI.setUnavailable(LibFunc::logbf);
201 TLI.setUnavailable(LibFunc::logbl);
202 TLI.setUnavailable(LibFunc::nearbyint);
203 TLI.setUnavailable(LibFunc::nearbyintf);
204 TLI.setUnavailable(LibFunc::nearbyintl);
205 TLI.setUnavailable(LibFunc::rint);
206 TLI.setUnavailable(LibFunc::rintf);
207 TLI.setUnavailable(LibFunc::rintl);
208 TLI.setUnavailable(LibFunc::round);
209 TLI.setUnavailable(LibFunc::roundf);
210 TLI.setUnavailable(LibFunc::roundl);
211 TLI.setUnavailable(LibFunc::trunc);
212 TLI.setUnavailable(LibFunc::truncf);
213 TLI.setUnavailable(LibFunc::truncl);
215 // Win32 provides some C99 math with mangled names
216 TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
218 if (T.getArch() == Triple::x86) {
219 // Win32 on x86 implements single-precision math functions as macros
220 TLI.setUnavailable(LibFunc::acosf);
221 TLI.setUnavailable(LibFunc::asinf);
222 TLI.setUnavailable(LibFunc::atanf);
223 TLI.setUnavailable(LibFunc::atan2f);
224 TLI.setUnavailable(LibFunc::ceilf);
225 TLI.setUnavailable(LibFunc::copysignf);
226 TLI.setUnavailable(LibFunc::cosf);
227 TLI.setUnavailable(LibFunc::coshf);
228 TLI.setUnavailable(LibFunc::expf);
229 TLI.setUnavailable(LibFunc::floorf);
230 TLI.setUnavailable(LibFunc::fminf);
231 TLI.setUnavailable(LibFunc::fmaxf);
232 TLI.setUnavailable(LibFunc::fmodf);
233 TLI.setUnavailable(LibFunc::logf);
234 TLI.setUnavailable(LibFunc::log10f);
235 TLI.setUnavailable(LibFunc::modff);
236 TLI.setUnavailable(LibFunc::powf);
237 TLI.setUnavailable(LibFunc::sinf);
238 TLI.setUnavailable(LibFunc::sinhf);
239 TLI.setUnavailable(LibFunc::sqrtf);
240 TLI.setUnavailable(LibFunc::tanf);
241 TLI.setUnavailable(LibFunc::tanhf);
244 // Win32 does *not* provide provide these functions, but they are
245 // generally available on POSIX-compliant systems:
246 TLI.setUnavailable(LibFunc::access);
247 TLI.setUnavailable(LibFunc::bcmp);
248 TLI.setUnavailable(LibFunc::bcopy);
249 TLI.setUnavailable(LibFunc::bzero);
250 TLI.setUnavailable(LibFunc::chmod);
251 TLI.setUnavailable(LibFunc::chown);
252 TLI.setUnavailable(LibFunc::closedir);
253 TLI.setUnavailable(LibFunc::ctermid);
254 TLI.setUnavailable(LibFunc::fdopen);
255 TLI.setUnavailable(LibFunc::ffs);
256 TLI.setUnavailable(LibFunc::fileno);
257 TLI.setUnavailable(LibFunc::flockfile);
258 TLI.setUnavailable(LibFunc::fseeko);
259 TLI.setUnavailable(LibFunc::fstat);
260 TLI.setUnavailable(LibFunc::fstatvfs);
261 TLI.setUnavailable(LibFunc::ftello);
262 TLI.setUnavailable(LibFunc::ftrylockfile);
263 TLI.setUnavailable(LibFunc::funlockfile);
264 TLI.setUnavailable(LibFunc::getc_unlocked);
265 TLI.setUnavailable(LibFunc::getitimer);
266 TLI.setUnavailable(LibFunc::getlogin_r);
267 TLI.setUnavailable(LibFunc::getpwnam);
268 TLI.setUnavailable(LibFunc::gettimeofday);
269 TLI.setUnavailable(LibFunc::htonl);
270 TLI.setUnavailable(LibFunc::htons);
271 TLI.setUnavailable(LibFunc::lchown);
272 TLI.setUnavailable(LibFunc::lstat);
273 TLI.setUnavailable(LibFunc::memccpy);
274 TLI.setUnavailable(LibFunc::mkdir);
275 TLI.setUnavailable(LibFunc::ntohl);
276 TLI.setUnavailable(LibFunc::ntohs);
277 TLI.setUnavailable(LibFunc::open);
278 TLI.setUnavailable(LibFunc::opendir);
279 TLI.setUnavailable(LibFunc::pclose);
280 TLI.setUnavailable(LibFunc::popen);
281 TLI.setUnavailable(LibFunc::pread);
282 TLI.setUnavailable(LibFunc::pwrite);
283 TLI.setUnavailable(LibFunc::read);
284 TLI.setUnavailable(LibFunc::readlink);
285 TLI.setUnavailable(LibFunc::realpath);
286 TLI.setUnavailable(LibFunc::rmdir);
287 TLI.setUnavailable(LibFunc::setitimer);
288 TLI.setUnavailable(LibFunc::stat);
289 TLI.setUnavailable(LibFunc::statvfs);
290 TLI.setUnavailable(LibFunc::stpcpy);
291 TLI.setUnavailable(LibFunc::stpncpy);
292 TLI.setUnavailable(LibFunc::strcasecmp);
293 TLI.setUnavailable(LibFunc::strncasecmp);
294 TLI.setUnavailable(LibFunc::times);
295 TLI.setUnavailable(LibFunc::uname);
296 TLI.setUnavailable(LibFunc::unlink);
297 TLI.setUnavailable(LibFunc::unsetenv);
298 TLI.setUnavailable(LibFunc::utime);
299 TLI.setUnavailable(LibFunc::utimes);
300 TLI.setUnavailable(LibFunc::write);
302 // Win32 does *not* provide provide these functions, but they are
304 TLI.setUnavailable(LibFunc::atoll);
305 TLI.setUnavailable(LibFunc::frexpf);
306 TLI.setUnavailable(LibFunc::llabs);
311 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
312 // and their names are __exp10 and __exp10f. exp10l is not available on
314 TLI.setUnavailable(LibFunc::exp10l);
315 if (T.isMacOSXVersionLT(10, 9)) {
316 TLI.setUnavailable(LibFunc::exp10);
317 TLI.setUnavailable(LibFunc::exp10f);
319 TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
320 TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
325 case Triple::WatchOS:
326 TLI.setUnavailable(LibFunc::exp10l);
327 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
328 (T.isOSVersionLT(9, 0) &&
329 (T.getArch() == Triple::x86 ||
330 T.getArch() == Triple::x86_64)))) {
331 TLI.setUnavailable(LibFunc::exp10);
332 TLI.setUnavailable(LibFunc::exp10f);
334 TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
335 TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
339 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
340 // buggy prior to glibc version 2.18. Until this version is widely deployed
341 // or we have a reasonable detection strategy, we cannot use exp10 reliably
344 // Fall through to disable all of them.
347 TLI.setUnavailable(LibFunc::exp10);
348 TLI.setUnavailable(LibFunc::exp10f);
349 TLI.setUnavailable(LibFunc::exp10l);
352 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
354 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
355 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
356 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
362 case Triple::WatchOS:
363 case Triple::FreeBSD:
367 TLI.setUnavailable(LibFunc::ffsl);
370 // ffsll is available on at least FreeBSD and Linux (GLIBC):
371 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
372 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
378 case Triple::WatchOS:
379 case Triple::FreeBSD:
383 TLI.setUnavailable(LibFunc::ffsll);
386 // The following functions are available on at least FreeBSD:
387 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
388 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
389 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
390 if (!T.isOSFreeBSD()) {
391 TLI.setUnavailable(LibFunc::fls);
392 TLI.setUnavailable(LibFunc::flsl);
393 TLI.setUnavailable(LibFunc::flsll);
396 // The following functions are available on at least Linux:
397 if (!T.isOSLinux()) {
398 TLI.setUnavailable(LibFunc::dunder_strdup);
399 TLI.setUnavailable(LibFunc::dunder_strtok_r);
400 TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
401 TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
402 TLI.setUnavailable(LibFunc::under_IO_getc);
403 TLI.setUnavailable(LibFunc::under_IO_putc);
404 TLI.setUnavailable(LibFunc::memalign);
405 TLI.setUnavailable(LibFunc::fopen64);
406 TLI.setUnavailable(LibFunc::fseeko64);
407 TLI.setUnavailable(LibFunc::fstat64);
408 TLI.setUnavailable(LibFunc::fstatvfs64);
409 TLI.setUnavailable(LibFunc::ftello64);
410 TLI.setUnavailable(LibFunc::lstat64);
411 TLI.setUnavailable(LibFunc::open64);
412 TLI.setUnavailable(LibFunc::stat64);
413 TLI.setUnavailable(LibFunc::statvfs64);
414 TLI.setUnavailable(LibFunc::tmpfile64);
417 // As currently implemented in clang, NVPTX code has no standard library to
418 // speak of. Headers provide a standard-ish library implementation, but many
419 // of the signatures are wrong -- for example, many libm functions are not
422 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
423 // but only used functions are provided to llvm. Moreover, most of the
424 // functions in libdevice don't map precisely to standard library functions.
426 // FIXME: Having no standard library prevents e.g. many fastmath
427 // optimizations, so this situation should be fixed.
429 TLI.disableAllFunctions();
430 TLI.setAvailable(LibFunc::nvvm_reflect);
432 TLI.setUnavailable(LibFunc::nvvm_reflect);
435 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
438 TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
439 // Default to everything being available.
440 memset(AvailableArray, -1, sizeof(AvailableArray));
442 initialize(*this, Triple(), StandardNames);
445 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
446 // Default to everything being available.
447 memset(AvailableArray, -1, sizeof(AvailableArray));
449 initialize(*this, T, StandardNames);
452 TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
453 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
454 ShouldExtI32Return(TLI.ShouldExtI32Return),
455 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
456 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
457 VectorDescs = TLI.VectorDescs;
458 ScalarDescs = TLI.ScalarDescs;
461 TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
462 : CustomNames(std::move(TLI.CustomNames)),
463 ShouldExtI32Param(TLI.ShouldExtI32Param),
464 ShouldExtI32Return(TLI.ShouldExtI32Return),
465 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
466 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
468 VectorDescs = TLI.VectorDescs;
469 ScalarDescs = TLI.ScalarDescs;
472 TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
473 CustomNames = TLI.CustomNames;
474 ShouldExtI32Param = TLI.ShouldExtI32Param;
475 ShouldExtI32Return = TLI.ShouldExtI32Return;
476 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
477 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
481 TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
482 CustomNames = std::move(TLI.CustomNames);
483 ShouldExtI32Param = TLI.ShouldExtI32Param;
484 ShouldExtI32Return = TLI.ShouldExtI32Return;
485 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
486 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
491 static StringRef sanitizeFunctionName(StringRef funcName) {
492 // Filter out empty names and names containing null bytes, those can't be in
494 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
497 // Check for \01 prefix that is used to mangle __asm declarations and
498 // strip it if present.
499 return GlobalValue::getRealLinkageName(funcName);
502 bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
503 LibFunc::Func &F) const {
504 StringRef const *Start = &StandardNames[0];
505 StringRef const *End = &StandardNames[LibFunc::NumLibFuncs];
507 funcName = sanitizeFunctionName(funcName);
508 if (funcName.empty())
511 StringRef const *I = std::lower_bound(
512 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
515 if (I != End && *I == funcName) {
516 F = (LibFunc::Func)(I - Start);
522 bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
524 const DataLayout *DL) const {
525 LLVMContext &Ctx = FTy.getContext();
526 Type *PCharTy = Type::getInt8PtrTy(Ctx);
527 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
528 auto IsSizeTTy = [SizeTTy](Type *Ty) {
529 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
531 unsigned NumParams = FTy.getNumParams();
534 case LibFunc::strlen:
535 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
536 FTy.getReturnType()->isIntegerTy());
538 case LibFunc::strchr:
539 case LibFunc::strrchr:
540 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
541 FTy.getParamType(0) == FTy.getReturnType() &&
542 FTy.getParamType(1)->isIntegerTy());
544 case LibFunc::strtol:
545 case LibFunc::strtod:
546 case LibFunc::strtof:
547 case LibFunc::strtoul:
548 case LibFunc::strtoll:
549 case LibFunc::strtold:
550 case LibFunc::strtoull:
551 return ((NumParams == 2 || NumParams == 3) &&
552 FTy.getParamType(0)->isPointerTy() &&
553 FTy.getParamType(1)->isPointerTy());
554 case LibFunc::strcat:
555 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
556 FTy.getParamType(0) == FTy.getReturnType() &&
557 FTy.getParamType(1) == FTy.getReturnType());
559 case LibFunc::strncat:
560 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
561 FTy.getParamType(0) == FTy.getReturnType() &&
562 FTy.getParamType(1) == FTy.getReturnType() &&
563 FTy.getParamType(2)->isIntegerTy());
565 case LibFunc::strcpy_chk:
566 case LibFunc::stpcpy_chk:
568 if (!IsSizeTTy(FTy.getParamType(NumParams)))
571 case LibFunc::strcpy:
572 case LibFunc::stpcpy:
573 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
574 FTy.getParamType(0) == FTy.getParamType(1) &&
575 FTy.getParamType(0) == PCharTy);
577 case LibFunc::strncpy_chk:
578 case LibFunc::stpncpy_chk:
580 if (!IsSizeTTy(FTy.getParamType(NumParams)))
583 case LibFunc::strncpy:
584 case LibFunc::stpncpy:
585 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
586 FTy.getParamType(0) == FTy.getParamType(1) &&
587 FTy.getParamType(0) == PCharTy &&
588 FTy.getParamType(2)->isIntegerTy());
590 case LibFunc::strxfrm:
591 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
592 FTy.getParamType(1)->isPointerTy());
594 case LibFunc::strcmp:
595 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
596 FTy.getParamType(0)->isPointerTy() &&
597 FTy.getParamType(0) == FTy.getParamType(1));
599 case LibFunc::strncmp:
600 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
601 FTy.getParamType(0)->isPointerTy() &&
602 FTy.getParamType(0) == FTy.getParamType(1) &&
603 FTy.getParamType(2)->isIntegerTy());
605 case LibFunc::strspn:
606 case LibFunc::strcspn:
607 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
608 FTy.getParamType(0) == FTy.getParamType(1) &&
609 FTy.getReturnType()->isIntegerTy());
611 case LibFunc::strcoll:
612 case LibFunc::strcasecmp:
613 case LibFunc::strncasecmp:
614 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
615 FTy.getParamType(1)->isPointerTy());
617 case LibFunc::strstr:
618 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
619 FTy.getParamType(0)->isPointerTy() &&
620 FTy.getParamType(1)->isPointerTy());
622 case LibFunc::strpbrk:
623 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
624 FTy.getReturnType() == FTy.getParamType(0) &&
625 FTy.getParamType(0) == FTy.getParamType(1));
627 case LibFunc::strtok:
628 case LibFunc::strtok_r:
629 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
631 case LibFunc::setbuf:
632 case LibFunc::setvbuf:
633 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
634 case LibFunc::strdup:
635 case LibFunc::strndup:
636 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
637 FTy.getParamType(0)->isPointerTy());
638 case LibFunc::sscanf:
640 case LibFunc::statvfs:
641 case LibFunc::sprintf:
642 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
643 FTy.getParamType(1)->isPointerTy());
644 case LibFunc::snprintf:
645 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
646 FTy.getParamType(2)->isPointerTy());
647 case LibFunc::setitimer:
648 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
649 FTy.getParamType(2)->isPointerTy());
650 case LibFunc::system:
651 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
652 case LibFunc::malloc:
653 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
654 case LibFunc::memcmp:
655 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
656 FTy.getParamType(1)->isPointerTy() &&
657 FTy.getReturnType()->isIntegerTy(32));
659 case LibFunc::memchr:
660 case LibFunc::memrchr:
661 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
662 FTy.getParamType(1)->isIntegerTy(32) &&
663 FTy.getParamType(2)->isIntegerTy() &&
664 FTy.getReturnType()->isPointerTy());
668 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
670 case LibFunc::memcpy_chk:
671 case LibFunc::memmove_chk:
673 if (!IsSizeTTy(FTy.getParamType(NumParams)))
676 case LibFunc::memcpy:
677 case LibFunc::mempcpy:
678 case LibFunc::memmove:
679 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
680 FTy.getParamType(0)->isPointerTy() &&
681 FTy.getParamType(1)->isPointerTy() &&
682 IsSizeTTy(FTy.getParamType(2)));
684 case LibFunc::memset_chk:
686 if (!IsSizeTTy(FTy.getParamType(NumParams)))
689 case LibFunc::memset:
690 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
691 FTy.getParamType(0)->isPointerTy() &&
692 FTy.getParamType(1)->isIntegerTy() &&
693 IsSizeTTy(FTy.getParamType(2)));
695 case LibFunc::memccpy:
696 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
697 case LibFunc::memalign:
698 return (FTy.getReturnType()->isPointerTy());
699 case LibFunc::realloc:
700 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
701 FTy.getReturnType()->isPointerTy());
703 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
704 case LibFunc::rewind:
706 case LibFunc::remove:
707 case LibFunc::realpath:
708 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
709 case LibFunc::rename:
710 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
711 FTy.getParamType(1)->isPointerTy());
712 case LibFunc::readlink:
713 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
714 FTy.getParamType(1)->isPointerTy());
716 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
719 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
720 FTy.getParamType(1)->isPointerTy());
722 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
723 case LibFunc::calloc:
724 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
730 case LibFunc::ferror:
731 case LibFunc::getenv:
732 case LibFunc::getpwnam:
733 case LibFunc::pclose:
734 case LibFunc::perror:
735 case LibFunc::printf:
738 case LibFunc::under_IO_getc:
739 case LibFunc::unlink:
740 case LibFunc::unsetenv:
741 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
745 case LibFunc::clearerr:
746 case LibFunc::closedir:
747 case LibFunc::ctermid:
748 case LibFunc::fclose:
750 case LibFunc::fflush:
752 case LibFunc::fileno:
753 case LibFunc::flockfile:
756 case LibFunc::fseeko64:
757 case LibFunc::fseeko:
758 case LibFunc::fsetpos:
760 case LibFunc::ftello64:
761 case LibFunc::ftello:
762 case LibFunc::ftrylockfile:
763 case LibFunc::funlockfile:
765 case LibFunc::getc_unlocked:
766 case LibFunc::getlogin_r:
768 case LibFunc::mktime:
770 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
772 case LibFunc::access:
773 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
775 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
776 FTy.getParamType(0)->isPointerTy() &&
777 FTy.getParamType(1)->isPointerTy());
778 case LibFunc::fdopen:
779 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
780 FTy.getParamType(1)->isPointerTy());
784 case LibFunc::frexpf:
785 case LibFunc::frexpl:
786 case LibFunc::fstatvfs:
787 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
789 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
790 FTy.getParamType(2)->isPointerTy());
792 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
793 FTy.getParamType(3)->isPointerTy());
794 case LibFunc::fwrite:
795 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
796 FTy.getParamType(0)->isPointerTy() &&
797 FTy.getParamType(1)->isIntegerTy() &&
798 FTy.getParamType(2)->isIntegerTy() &&
799 FTy.getParamType(3)->isPointerTy());
801 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
802 FTy.getParamType(1)->isPointerTy());
803 case LibFunc::fscanf:
804 case LibFunc::fprintf:
805 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
806 FTy.getParamType(1)->isPointerTy());
807 case LibFunc::fgetpos:
808 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
809 FTy.getParamType(1)->isPointerTy());
811 case LibFunc::getchar:
812 case LibFunc::getitimer:
813 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
814 case LibFunc::ungetc:
815 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
817 case LibFunc::utimes:
818 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
819 FTy.getParamType(1)->isPointerTy());
821 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
823 case LibFunc::pwrite:
824 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
826 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
827 FTy.getParamType(0)->isPointerTy() &&
828 FTy.getParamType(1)->isPointerTy());
829 case LibFunc::vscanf:
830 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
831 case LibFunc::vsscanf:
832 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
833 FTy.getParamType(2)->isPointerTy());
834 case LibFunc::vfscanf:
835 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
836 FTy.getParamType(2)->isPointerTy());
837 case LibFunc::valloc:
838 return (FTy.getReturnType()->isPointerTy());
839 case LibFunc::vprintf:
840 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
841 case LibFunc::vfprintf:
842 case LibFunc::vsprintf:
843 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
844 FTy.getParamType(1)->isPointerTy());
845 case LibFunc::vsnprintf:
846 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
847 FTy.getParamType(2)->isPointerTy());
849 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
850 case LibFunc::opendir:
851 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
852 FTy.getParamType(0)->isPointerTy());
853 case LibFunc::tmpfile:
854 return (FTy.getReturnType()->isPointerTy());
860 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
861 FTy.getParamType(1)->isPointerTy());
862 case LibFunc::lchown:
863 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
865 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
866 case LibFunc::dunder_strdup:
867 case LibFunc::dunder_strndup:
868 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
869 FTy.getParamType(0)->isPointerTy());
870 case LibFunc::dunder_strtok_r:
871 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
872 case LibFunc::under_IO_putc:
873 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
874 case LibFunc::dunder_isoc99_scanf:
875 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
876 case LibFunc::stat64:
877 case LibFunc::lstat64:
878 case LibFunc::statvfs64:
879 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
880 FTy.getParamType(1)->isPointerTy());
881 case LibFunc::dunder_isoc99_sscanf:
882 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
883 FTy.getParamType(1)->isPointerTy());
884 case LibFunc::fopen64:
885 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
886 FTy.getParamType(0)->isPointerTy() &&
887 FTy.getParamType(1)->isPointerTy());
888 case LibFunc::tmpfile64:
889 return (FTy.getReturnType()->isPointerTy());
890 case LibFunc::fstat64:
891 case LibFunc::fstatvfs64:
892 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
893 case LibFunc::open64:
894 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
895 case LibFunc::gettimeofday:
896 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
897 FTy.getParamType(1)->isPointerTy());
899 case LibFunc::Znwj: // new(unsigned int);
900 case LibFunc::Znwm: // new(unsigned long);
901 case LibFunc::Znaj: // new[](unsigned int);
902 case LibFunc::Znam: // new[](unsigned long);
903 case LibFunc::msvc_new_int: // new(unsigned int);
904 case LibFunc::msvc_new_longlong: // new(unsigned long long);
905 case LibFunc::msvc_new_array_int: // new[](unsigned int);
906 case LibFunc::msvc_new_array_longlong: // new[](unsigned long long);
907 return (NumParams == 1);
909 case LibFunc::memset_pattern16:
910 return (!FTy.isVarArg() && NumParams == 3 &&
911 isa<PointerType>(FTy.getParamType(0)) &&
912 isa<PointerType>(FTy.getParamType(1)) &&
913 isa<IntegerType>(FTy.getParamType(2)));
915 // int __nvvm_reflect(const char *);
916 case LibFunc::nvvm_reflect:
917 return (NumParams == 1 && isa<PointerType>(FTy.getParamType(0)));
938 case LibFunc::log10f:
939 case LibFunc::log10l:
947 case LibFunc::floorf:
948 case LibFunc::floorl:
953 case LibFunc::truncf:
954 case LibFunc::truncl:
958 case LibFunc::nearbyint:
959 case LibFunc::nearbyintf:
960 case LibFunc::nearbyintl:
962 case LibFunc::roundf:
963 case LibFunc::roundl:
967 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
968 FTy.getReturnType() == FTy.getParamType(0));
976 case LibFunc::copysign:
977 case LibFunc::copysignf:
978 case LibFunc::copysignl:
982 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
983 FTy.getReturnType() == FTy.getParamType(0) &&
984 FTy.getReturnType() == FTy.getParamType(1));
992 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
993 FTy.getParamType(0)->isIntegerTy());
995 case LibFunc::isdigit:
996 case LibFunc::isascii:
997 case LibFunc::toascii:
998 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
999 FTy.getReturnType() == FTy.getParamType(0));
1003 case LibFunc::llabs:
1004 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1005 FTy.getReturnType() == FTy.getParamType(0));
1007 case LibFunc::cxa_atexit:
1008 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1009 FTy.getParamType(0)->isPointerTy() &&
1010 FTy.getParamType(1)->isPointerTy() &&
1011 FTy.getParamType(2)->isPointerTy());
1013 case LibFunc::sinpi:
1014 case LibFunc::cospi:
1015 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1016 FTy.getReturnType() == FTy.getParamType(0));
1018 case LibFunc::sinpif:
1019 case LibFunc::cospif:
1020 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1021 FTy.getReturnType() == FTy.getParamType(0));
1024 // Assume the other functions are correct.
1025 // FIXME: It'd be really nice to cover them all.
1030 bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1031 LibFunc::Func &F) const {
1032 const DataLayout *DL =
1033 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1034 return getLibFunc(FDecl.getName(), F) &&
1035 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1038 void TargetLibraryInfoImpl::disableAllFunctions() {
1039 memset(AvailableArray, 0, sizeof(AvailableArray));
1042 static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1043 return LHS.ScalarFnName < RHS.ScalarFnName;
1046 static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1047 return LHS.VectorFnName < RHS.VectorFnName;
1050 static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1051 return LHS.ScalarFnName < S;
1054 static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
1055 return LHS.VectorFnName < S;
1058 void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1059 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1060 std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1062 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1063 std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1066 void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1067 enum VectorLibrary VecLib) {
1070 const VecDesc VecFuncs[] = {
1071 // Floating-Point Arithmetic and Auxiliary Functions
1072 {"ceilf", "vceilf", 4},
1073 {"fabsf", "vfabsf", 4},
1074 {"llvm.fabs.f32", "vfabsf", 4},
1075 {"floorf", "vfloorf", 4},
1076 {"sqrtf", "vsqrtf", 4},
1077 {"llvm.sqrt.f32", "vsqrtf", 4},
1079 // Exponential and Logarithmic Functions
1080 {"expf", "vexpf", 4},
1081 {"llvm.exp.f32", "vexpf", 4},
1082 {"expm1f", "vexpm1f", 4},
1083 {"logf", "vlogf", 4},
1084 {"llvm.log.f32", "vlogf", 4},
1085 {"log1pf", "vlog1pf", 4},
1086 {"log10f", "vlog10f", 4},
1087 {"llvm.log10.f32", "vlog10f", 4},
1088 {"logbf", "vlogbf", 4},
1090 // Trigonometric Functions
1091 {"sinf", "vsinf", 4},
1092 {"llvm.sin.f32", "vsinf", 4},
1093 {"cosf", "vcosf", 4},
1094 {"llvm.cos.f32", "vcosf", 4},
1095 {"tanf", "vtanf", 4},
1096 {"asinf", "vasinf", 4},
1097 {"acosf", "vacosf", 4},
1098 {"atanf", "vatanf", 4},
1100 // Hyperbolic Functions
1101 {"sinhf", "vsinhf", 4},
1102 {"coshf", "vcoshf", 4},
1103 {"tanhf", "vtanhf", 4},
1104 {"asinhf", "vasinhf", 4},
1105 {"acoshf", "vacoshf", 4},
1106 {"atanhf", "vatanhf", 4},
1108 addVectorizableFunctions(VecFuncs);
1112 const VecDesc VecFuncs[] = {
1113 {"sin", "__svml_sin2", 2},
1114 {"sin", "__svml_sin4", 4},
1115 {"sin", "__svml_sin8", 8},
1117 {"sinf", "__svml_sinf4", 4},
1118 {"sinf", "__svml_sinf8", 8},
1119 {"sinf", "__svml_sinf16", 16},
1121 {"cos", "__svml_cos2", 2},
1122 {"cos", "__svml_cos4", 4},
1123 {"cos", "__svml_cos8", 8},
1125 {"cosf", "__svml_cosf4", 4},
1126 {"cosf", "__svml_cosf8", 8},
1127 {"cosf", "__svml_cosf16", 16},
1129 {"pow", "__svml_pow2", 2},
1130 {"pow", "__svml_pow4", 4},
1131 {"pow", "__svml_pow8", 8},
1133 {"powf", "__svml_powf4", 4},
1134 {"powf", "__svml_powf8", 8},
1135 {"powf", "__svml_powf16", 16},
1137 {"llvm.pow.f64", "__svml_pow2", 2},
1138 {"llvm.pow.f64", "__svml_pow4", 4},
1139 {"llvm.pow.f64", "__svml_pow8", 8},
1141 {"llvm.pow.f32", "__svml_powf4", 4},
1142 {"llvm.pow.f32", "__svml_powf8", 8},
1143 {"llvm.pow.f32", "__svml_powf16", 16},
1145 {"exp", "__svml_exp2", 2},
1146 {"exp", "__svml_exp4", 4},
1147 {"exp", "__svml_exp8", 8},
1149 {"expf", "__svml_expf4", 4},
1150 {"expf", "__svml_expf8", 8},
1151 {"expf", "__svml_expf16", 16},
1153 {"llvm.exp.f64", "__svml_exp2", 2},
1154 {"llvm.exp.f64", "__svml_exp4", 4},
1155 {"llvm.exp.f64", "__svml_exp8", 8},
1157 {"llvm.exp.f32", "__svml_expf4", 4},
1158 {"llvm.exp.f32", "__svml_expf8", 8},
1159 {"llvm.exp.f32", "__svml_expf16", 16},
1161 {"log", "__svml_log2", 2},
1162 {"log", "__svml_log4", 4},
1163 {"log", "__svml_log8", 8},
1165 {"logf", "__svml_logf4", 4},
1166 {"logf", "__svml_logf8", 8},
1167 {"logf", "__svml_logf16", 16},
1169 {"llvm.log.f64", "__svml_log2", 2},
1170 {"llvm.log.f64", "__svml_log4", 4},
1171 {"llvm.log.f64", "__svml_log8", 8},
1173 {"llvm.log.f32", "__svml_logf4", 4},
1174 {"llvm.log.f32", "__svml_logf8", 8},
1175 {"llvm.log.f32", "__svml_logf16", 16},
1177 addVectorizableFunctions(VecFuncs);
1185 bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1186 funcName = sanitizeFunctionName(funcName);
1187 if (funcName.empty())
1190 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1191 VectorDescs.begin(), VectorDescs.end(), funcName,
1192 compareWithScalarFnName);
1193 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1196 StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1197 unsigned VF) const {
1198 F = sanitizeFunctionName(F);
1201 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1202 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1203 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1204 if (I->VectorizationFactor == VF)
1205 return I->VectorFnName;
1211 StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1212 unsigned &VF) const {
1213 F = sanitizeFunctionName(F);
1217 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1218 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1219 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1221 VF = I->VectorizationFactor;
1222 return I->ScalarFnName;
1225 TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1226 ModuleAnalysisManager &) {
1228 return TargetLibraryInfo(*PresetInfoImpl);
1230 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1233 TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1234 FunctionAnalysisManager &) {
1236 return TargetLibraryInfo(*PresetInfoImpl);
1238 return TargetLibraryInfo(
1239 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1242 TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
1243 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1244 Impls[T.normalize()];
1246 Impl.reset(new TargetLibraryInfoImpl(T));
1252 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
1253 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
1254 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1257 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
1258 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
1259 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1262 TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
1263 const TargetLibraryInfoImpl &TLIImpl)
1264 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
1265 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1268 AnalysisKey TargetLibraryAnalysis::Key;
1270 // Register the basic pass.
1271 INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1272 "Target Library Information", false, true)
1273 char TargetLibraryInfoWrapperPass::ID = 0;
1275 void TargetLibraryInfoWrapperPass::anchor() {}