162d4215bSChandler Carruth //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==// 262d4215bSChandler Carruth // 362d4215bSChandler Carruth // The LLVM Compiler Infrastructure 462d4215bSChandler Carruth // 562d4215bSChandler Carruth // This file is distributed under the University of Illinois Open Source 662d4215bSChandler Carruth // License. See LICENSE.TXT for details. 762d4215bSChandler Carruth // 862d4215bSChandler Carruth //===----------------------------------------------------------------------===// 962d4215bSChandler Carruth // 1062d4215bSChandler Carruth // This file implements the TargetLibraryInfo class. 1162d4215bSChandler Carruth // 1262d4215bSChandler Carruth //===----------------------------------------------------------------------===// 1362d4215bSChandler Carruth 1462d4215bSChandler Carruth #include "llvm/Analysis/TargetLibraryInfo.h" 1562d4215bSChandler Carruth #include "llvm/ADT/Triple.h" 166d8a2aa9SMichael Zolotukhin #include "llvm/Support/CommandLine.h" 1762d4215bSChandler Carruth using namespace llvm; 1862d4215bSChandler Carruth 196d8a2aa9SMichael Zolotukhin static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary( 206d8a2aa9SMichael Zolotukhin "vector-library", cl::Hidden, cl::desc("Vector functions library"), 216d8a2aa9SMichael Zolotukhin cl::init(TargetLibraryInfoImpl::NoLibrary), 226d8a2aa9SMichael Zolotukhin cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", 236d8a2aa9SMichael Zolotukhin "No vector functions library"), 246d8a2aa9SMichael Zolotukhin clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", 256d8a2aa9SMichael Zolotukhin "Accelerate framework"), 26a6669a1eSMatt Masten clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", 27732afdd0SMehdi Amini "Intel SVML library"))); 286d8a2aa9SMichael Zolotukhin 299a72cd7bSMehdi Amini StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = { 30cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING 31cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def" 3262d4215bSChandler Carruth }; 3362d4215bSChandler Carruth 3462d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) { 3562d4215bSChandler Carruth // Only Darwin variants have _stret versions of combined trig functions. 3662d4215bSChandler Carruth if (!T.isOSDarwin()) 3762d4215bSChandler Carruth return false; 3862d4215bSChandler Carruth 3962d4215bSChandler Carruth // The ABI is rather complicated on x86, so don't do anything special there. 4062d4215bSChandler Carruth if (T.getArch() == Triple::x86) 4162d4215bSChandler Carruth return false; 4262d4215bSChandler Carruth 4362d4215bSChandler Carruth if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) 4462d4215bSChandler Carruth return false; 4562d4215bSChandler Carruth 4662d4215bSChandler Carruth if (T.isiOS() && T.isOSVersionLT(7, 0)) 4762d4215bSChandler Carruth return false; 4862d4215bSChandler Carruth 4962d4215bSChandler Carruth return true; 5062d4215bSChandler Carruth } 5162d4215bSChandler Carruth 5262d4215bSChandler Carruth /// initialize - Initialize the set of available library functions based on the 5362d4215bSChandler Carruth /// specified target triple. This should be carefully written so that a missing 5462d4215bSChandler Carruth /// target triple gets a sane set of defaults. 55c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, 569a72cd7bSMehdi Amini ArrayRef<StringRef> StandardNames) { 5762d4215bSChandler Carruth // Verify that the StandardNames array is in alphabetical order. 58e30b8ca1SCraig Topper assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), 599a72cd7bSMehdi Amini [](StringRef LHS, StringRef RHS) { 609a72cd7bSMehdi Amini return LHS < RHS; 61e30b8ca1SCraig Topper }) && 62e30b8ca1SCraig Topper "TargetLibraryInfoImpl function names must be sorted"); 6362d4215bSChandler Carruth 646af8e6c3SMarcin Koscielnicki bool ShouldExtI32Param = false, ShouldExtI32Return = false, 656af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = false; 666af8e6c3SMarcin Koscielnicki // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and 676af8e6c3SMarcin Koscielnicki // returns corresponding to C-level ints and unsigned ints. 686af8e6c3SMarcin Koscielnicki if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le || 696af8e6c3SMarcin Koscielnicki T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) { 706af8e6c3SMarcin Koscielnicki ShouldExtI32Param = true; 716af8e6c3SMarcin Koscielnicki ShouldExtI32Return = true; 726af8e6c3SMarcin Koscielnicki } 736af8e6c3SMarcin Koscielnicki // Mips, on the other hand, needs signext on i32 parameters corresponding 746af8e6c3SMarcin Koscielnicki // to both signed and unsigned ints. 756af8e6c3SMarcin Koscielnicki if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel || 766af8e6c3SMarcin Koscielnicki T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) { 776af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = true; 786af8e6c3SMarcin Koscielnicki } 796af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Param(ShouldExtI32Param); 806af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Return(ShouldExtI32Return); 816af8e6c3SMarcin Koscielnicki TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); 826af8e6c3SMarcin Koscielnicki 8378fd4f08SNicolai Hahnle if (T.getArch() == Triple::r600 || 8478fd4f08SNicolai Hahnle T.getArch() == Triple::amdgcn) { 8578fd4f08SNicolai Hahnle TLI.setUnavailable(LibFunc::ldexp); 8678fd4f08SNicolai Hahnle TLI.setUnavailable(LibFunc::ldexpf); 8778fd4f08SNicolai Hahnle TLI.setUnavailable(LibFunc::ldexpl); 88377975f2SNicolai Haehnle TLI.setUnavailable(LibFunc::exp10); 89377975f2SNicolai Haehnle TLI.setUnavailable(LibFunc::exp10f); 90377975f2SNicolai Haehnle TLI.setUnavailable(LibFunc::exp10l); 91377975f2SNicolai Haehnle TLI.setUnavailable(LibFunc::log10); 92377975f2SNicolai Haehnle TLI.setUnavailable(LibFunc::log10f); 93377975f2SNicolai Haehnle TLI.setUnavailable(LibFunc::log10l); 9478fd4f08SNicolai Hahnle } 9578fd4f08SNicolai Hahnle 9662d4215bSChandler Carruth // There are no library implementations of mempcy and memset for AMD gpus and 9762d4215bSChandler Carruth // these can be difficult to lower in the backend. 9862d4215bSChandler Carruth if (T.getArch() == Triple::r600 || 9905532995SDan Gohman T.getArch() == Triple::amdgcn) { 10062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memcpy); 10162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memset); 10262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memset_pattern16); 10362d4215bSChandler Carruth return; 10462d4215bSChandler Carruth } 10562d4215bSChandler Carruth 10662d4215bSChandler Carruth // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. 1078b40366bSTim Northover // All versions of watchOS support it. 10862d4215bSChandler Carruth if (T.isMacOSX()) { 10962d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 5)) 11062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memset_pattern16); 11162d4215bSChandler Carruth } else if (T.isiOS()) { 11262d4215bSChandler Carruth if (T.isOSVersionLT(3, 0)) 11362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memset_pattern16); 1148b40366bSTim Northover } else if (!T.isWatchOS()) { 11562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memset_pattern16); 11662d4215bSChandler Carruth } 11762d4215bSChandler Carruth 11862d4215bSChandler Carruth if (!hasSinCosPiStret(T)) { 11962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sinpi); 12062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sinpif); 12162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cospi); 12262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cospif); 12362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sincospi_stret); 12462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sincospif_stret); 12562d4215bSChandler Carruth } 12662d4215bSChandler Carruth 12762d4215bSChandler Carruth if (T.isMacOSX() && T.getArch() == Triple::x86 && 12862d4215bSChandler Carruth !T.isMacOSXVersionLT(10, 7)) { 12962d4215bSChandler Carruth // x86-32 OSX has a scheme where fwrite and fputs (and some other functions 13062d4215bSChandler Carruth // we don't care about) have two versions; on recent OSX, the one we want 13162d4215bSChandler Carruth // has a $UNIX2003 suffix. The two implementations are identical except 13262d4215bSChandler Carruth // for the return value in some edge cases. However, we don't want to 13362d4215bSChandler Carruth // generate code that depends on the old symbols. 13462d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003"); 13562d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003"); 13662d4215bSChandler Carruth } 13762d4215bSChandler Carruth 13862d4215bSChandler Carruth // iprintf and friends are only available on XCore and TCE. 13962d4215bSChandler Carruth if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { 14062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::iprintf); 14162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::siprintf); 14262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fiprintf); 14362d4215bSChandler Carruth } 14462d4215bSChandler Carruth 14562d4215bSChandler Carruth if (T.isOSWindows() && !T.isOSCygMing()) { 14662d4215bSChandler Carruth // Win32 does not support long double 14762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::acosl); 14862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::asinl); 14962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atanl); 15062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atan2l); 15162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ceill); 15262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::copysignl); 15362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cosl); 15462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::coshl); 15562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::expl); 15662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf 15762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fabsl); 15862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::floorl); 15962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fmaxl); 16062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fminl); 16162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fmodl); 16262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::frexpl); 16362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ldexpf); 16462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ldexpl); 16562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::logl); 16662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::modfl); 16762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::powl); 16862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sinl); 16962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sinhl); 17062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sqrtl); 17162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::tanl); 17262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::tanhl); 17362d4215bSChandler Carruth 17462d4215bSChandler Carruth // Win32 only has C89 math 17562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::acosh); 17662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::acoshf); 17762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::acoshl); 17862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::asinh); 17962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::asinhf); 18062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::asinhl); 18162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atanh); 18262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atanhf); 18362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atanhl); 18462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cbrt); 18562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cbrtf); 18662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cbrtl); 18762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp2); 18862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp2f); 18962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp2l); 19062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::expm1); 19162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::expm1f); 19262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::expm1l); 19362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::log2); 19462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::log2f); 19562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::log2l); 19662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::log1p); 19762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::log1pf); 19862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::log1pl); 19962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::logb); 20062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::logbf); 20162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::logbl); 20262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::nearbyint); 20362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::nearbyintf); 20462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::nearbyintl); 20562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::rint); 20662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::rintf); 20762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::rintl); 20862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::round); 20962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::roundf); 21062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::roundl); 21162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::trunc); 21262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::truncf); 21362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::truncl); 21462d4215bSChandler Carruth 21562d4215bSChandler Carruth // Win32 provides some C99 math with mangled names 21662d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::copysign, "_copysign"); 21762d4215bSChandler Carruth 21862d4215bSChandler Carruth if (T.getArch() == Triple::x86) { 21962d4215bSChandler Carruth // Win32 on x86 implements single-precision math functions as macros 22062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::acosf); 22162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::asinf); 22262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atanf); 22362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atan2f); 22462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ceilf); 22562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::copysignf); 22662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::cosf); 22762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::coshf); 22862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::expf); 22962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::floorf); 23062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fminf); 23162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fmaxf); 23262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fmodf); 23362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::logf); 234eac58d8fSDavid Majnemer TLI.setUnavailable(LibFunc::log10f); 235eac58d8fSDavid Majnemer TLI.setUnavailable(LibFunc::modff); 23662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::powf); 23762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sinf); 23862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sinhf); 23962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::sqrtf); 24062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::tanf); 24162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::tanhf); 24262d4215bSChandler Carruth } 24362d4215bSChandler Carruth 24462d4215bSChandler Carruth // Win32 does *not* provide provide these functions, but they are 24562d4215bSChandler Carruth // generally available on POSIX-compliant systems: 24662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::access); 24762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::bcmp); 24862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::bcopy); 24962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::bzero); 25062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::chmod); 25162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::chown); 25262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::closedir); 25362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ctermid); 25462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fdopen); 25562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ffs); 25662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fileno); 25762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::flockfile); 25862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fseeko); 25962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fstat); 26062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fstatvfs); 26162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ftello); 26262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ftrylockfile); 26362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::funlockfile); 26462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::getc_unlocked); 26562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::getitimer); 26662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::getlogin_r); 26762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::getpwnam); 26862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::gettimeofday); 26962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::htonl); 27062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::htons); 27162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::lchown); 27262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::lstat); 27362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memccpy); 27462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::mkdir); 27562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ntohl); 27662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ntohs); 27762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::open); 27862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::opendir); 27962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::pclose); 28062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::popen); 28162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::pread); 28262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::pwrite); 28362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::read); 28462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::readlink); 28562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::realpath); 28662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::rmdir); 28762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::setitimer); 28862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::stat); 28962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::statvfs); 29062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::stpcpy); 29162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::stpncpy); 29262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::strcasecmp); 29362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::strncasecmp); 29462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::times); 29562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::uname); 29662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::unlink); 29762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::unsetenv); 29862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::utime); 29962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::utimes); 30062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::write); 30162d4215bSChandler Carruth 30262d4215bSChandler Carruth // Win32 does *not* provide provide these functions, but they are 30362d4215bSChandler Carruth // specified by C99: 30462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::atoll); 30562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::frexpf); 30662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::llabs); 30762d4215bSChandler Carruth } 30862d4215bSChandler Carruth 30962d4215bSChandler Carruth switch (T.getOS()) { 31062d4215bSChandler Carruth case Triple::MacOSX: 31162d4215bSChandler Carruth // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 31262d4215bSChandler Carruth // and their names are __exp10 and __exp10f. exp10l is not available on 31362d4215bSChandler Carruth // OS X or iOS. 31462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10l); 31562d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 9)) { 31662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10); 31762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10f); 31862d4215bSChandler Carruth } else { 31962d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::exp10, "__exp10"); 32062d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f"); 32162d4215bSChandler Carruth } 32262d4215bSChandler Carruth break; 32362d4215bSChandler Carruth case Triple::IOS: 32489a6eefeSTim Northover case Triple::TvOS: 3258b40366bSTim Northover case Triple::WatchOS: 32662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10l); 3278b40366bSTim Northover if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) || 3288b40366bSTim Northover (T.isOSVersionLT(9, 0) && 3298b40366bSTim Northover (T.getArch() == Triple::x86 || 3308b40366bSTim Northover T.getArch() == Triple::x86_64)))) { 33162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10); 33262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10f); 33362d4215bSChandler Carruth } else { 33462d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::exp10, "__exp10"); 33562d4215bSChandler Carruth TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f"); 33662d4215bSChandler Carruth } 33762d4215bSChandler Carruth break; 33862d4215bSChandler Carruth case Triple::Linux: 33962d4215bSChandler Carruth // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely 34062d4215bSChandler Carruth // buggy prior to glibc version 2.18. Until this version is widely deployed 34162d4215bSChandler Carruth // or we have a reasonable detection strategy, we cannot use exp10 reliably 34262d4215bSChandler Carruth // on Linux. 34362d4215bSChandler Carruth // 34462d4215bSChandler Carruth // Fall through to disable all of them. 345cd1d5aafSJustin Bogner LLVM_FALLTHROUGH; 34662d4215bSChandler Carruth default: 34762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10); 34862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10f); 34962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::exp10l); 35062d4215bSChandler Carruth } 35162d4215bSChandler Carruth 35262d4215bSChandler Carruth // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and 35362d4215bSChandler Carruth // Linux (GLIBC): 35462d4215bSChandler Carruth // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html 35583b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c 35662d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html 35762d4215bSChandler Carruth switch (T.getOS()) { 35862d4215bSChandler Carruth case Triple::Darwin: 35962d4215bSChandler Carruth case Triple::MacOSX: 36062d4215bSChandler Carruth case Triple::IOS: 36189a6eefeSTim Northover case Triple::TvOS: 3628b40366bSTim Northover case Triple::WatchOS: 36362d4215bSChandler Carruth case Triple::FreeBSD: 36462d4215bSChandler Carruth case Triple::Linux: 36562d4215bSChandler Carruth break; 36662d4215bSChandler Carruth default: 36762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ffsl); 36862d4215bSChandler Carruth } 36962d4215bSChandler Carruth 37062d4215bSChandler Carruth // ffsll is available on at least FreeBSD and Linux (GLIBC): 37183b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c 37262d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html 37362d4215bSChandler Carruth switch (T.getOS()) { 37489a6eefeSTim Northover case Triple::Darwin: 37589a6eefeSTim Northover case Triple::MacOSX: 37689a6eefeSTim Northover case Triple::IOS: 37789a6eefeSTim Northover case Triple::TvOS: 37889a6eefeSTim Northover case Triple::WatchOS: 37962d4215bSChandler Carruth case Triple::FreeBSD: 38062d4215bSChandler Carruth case Triple::Linux: 38162d4215bSChandler Carruth break; 38262d4215bSChandler Carruth default: 38362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ffsll); 38462d4215bSChandler Carruth } 38562d4215bSChandler Carruth 386bfd3082eSDavide Italiano // The following functions are available on at least FreeBSD: 387bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/fls.c 388bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c 389bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c 390bfd3082eSDavide Italiano if (!T.isOSFreeBSD()) { 391bfd3082eSDavide Italiano TLI.setUnavailable(LibFunc::fls); 392bfd3082eSDavide Italiano TLI.setUnavailable(LibFunc::flsl); 393bfd3082eSDavide Italiano TLI.setUnavailable(LibFunc::flsll); 394bfd3082eSDavide Italiano } 395bfd3082eSDavide Italiano 39662d4215bSChandler Carruth // The following functions are available on at least Linux: 39762d4215bSChandler Carruth if (!T.isOSLinux()) { 39862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::dunder_strdup); 39962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::dunder_strtok_r); 40062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::dunder_isoc99_scanf); 40162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf); 40262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::under_IO_getc); 40362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::under_IO_putc); 40462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::memalign); 40562d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fopen64); 40662d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fseeko64); 40762d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fstat64); 40862d4215bSChandler Carruth TLI.setUnavailable(LibFunc::fstatvfs64); 40962d4215bSChandler Carruth TLI.setUnavailable(LibFunc::ftello64); 41062d4215bSChandler Carruth TLI.setUnavailable(LibFunc::lstat64); 41162d4215bSChandler Carruth TLI.setUnavailable(LibFunc::open64); 41262d4215bSChandler Carruth TLI.setUnavailable(LibFunc::stat64); 41362d4215bSChandler Carruth TLI.setUnavailable(LibFunc::statvfs64); 41462d4215bSChandler Carruth TLI.setUnavailable(LibFunc::tmpfile64); 41562d4215bSChandler Carruth } 4166d8a2aa9SMichael Zolotukhin 41751132881SJustin Lebar // As currently implemented in clang, NVPTX code has no standard library to 41851132881SJustin Lebar // speak of. Headers provide a standard-ish library implementation, but many 41951132881SJustin Lebar // of the signatures are wrong -- for example, many libm functions are not 42051132881SJustin Lebar // extern "C". 42151132881SJustin Lebar // 42251132881SJustin Lebar // libdevice, an IR library provided by nvidia, is linked in by the front-end, 42351132881SJustin Lebar // but only used functions are provided to llvm. Moreover, most of the 42451132881SJustin Lebar // functions in libdevice don't map precisely to standard library functions. 42551132881SJustin Lebar // 42651132881SJustin Lebar // FIXME: Having no standard library prevents e.g. many fastmath 42751132881SJustin Lebar // optimizations, so this situation should be fixed. 428ae272d71SDavid Majnemer if (T.isNVPTX()) { 42951132881SJustin Lebar TLI.disableAllFunctions(); 430ae272d71SDavid Majnemer TLI.setAvailable(LibFunc::nvvm_reflect); 431ae272d71SDavid Majnemer } else { 432ae272d71SDavid Majnemer TLI.setUnavailable(LibFunc::nvvm_reflect); 433ae272d71SDavid Majnemer } 43451132881SJustin Lebar 4356d8a2aa9SMichael Zolotukhin TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); 43662d4215bSChandler Carruth } 43762d4215bSChandler Carruth 438c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() { 43962d4215bSChandler Carruth // Default to everything being available. 44062d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 44162d4215bSChandler Carruth 44262d4215bSChandler Carruth initialize(*this, Triple(), StandardNames); 44362d4215bSChandler Carruth } 44462d4215bSChandler Carruth 445c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { 44662d4215bSChandler Carruth // Default to everything being available. 44762d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 44862d4215bSChandler Carruth 44962d4215bSChandler Carruth initialize(*this, T, StandardNames); 45062d4215bSChandler Carruth } 45162d4215bSChandler Carruth 452c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) 4535ae2c526SMarcin Koscielnicki : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), 4545ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 4555ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 45662d4215bSChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 457e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 458e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 4598ca43224SChandler Carruth } 4608ca43224SChandler Carruth 461c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) 4625ae2c526SMarcin Koscielnicki : CustomNames(std::move(TLI.CustomNames)), 4635ae2c526SMarcin Koscielnicki ShouldExtI32Param(TLI.ShouldExtI32Param), 4645ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 4655ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 4668ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 4678ca43224SChandler Carruth AvailableArray); 468e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 469e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 4708ca43224SChandler Carruth } 4718ca43224SChandler Carruth 472c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { 47362d4215bSChandler Carruth CustomNames = TLI.CustomNames; 4745ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 4755ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 4765ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 4778ca43224SChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 4788ca43224SChandler Carruth return *this; 4798ca43224SChandler Carruth } 4808ca43224SChandler Carruth 481c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { 4828ca43224SChandler Carruth CustomNames = std::move(TLI.CustomNames); 4835ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 4845ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 4855ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 4868ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 4878ca43224SChandler Carruth AvailableArray); 4888ca43224SChandler Carruth return *this; 48962d4215bSChandler Carruth } 49062d4215bSChandler Carruth 49121abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) { 49262d4215bSChandler Carruth // Filter out empty names and names containing null bytes, those can't be in 49362d4215bSChandler Carruth // our table. 49462d4215bSChandler Carruth if (funcName.empty() || funcName.find('\0') != StringRef::npos) 49521abdf98SMichael Zolotukhin return StringRef(); 49662d4215bSChandler Carruth 49762d4215bSChandler Carruth // Check for \01 prefix that is used to mangle __asm declarations and 49862d4215bSChandler Carruth // strip it if present. 499cde33036SDavid Majnemer return GlobalValue::getRealLinkageName(funcName); 50021abdf98SMichael Zolotukhin } 50121abdf98SMichael Zolotukhin 50221abdf98SMichael Zolotukhin bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, 50321abdf98SMichael Zolotukhin LibFunc::Func &F) const { 5049a72cd7bSMehdi Amini StringRef const *Start = &StandardNames[0]; 5059a72cd7bSMehdi Amini StringRef const *End = &StandardNames[LibFunc::NumLibFuncs]; 50621abdf98SMichael Zolotukhin 50721abdf98SMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 50821abdf98SMichael Zolotukhin if (funcName.empty()) 50921abdf98SMichael Zolotukhin return false; 51021abdf98SMichael Zolotukhin 5119a72cd7bSMehdi Amini StringRef const *I = std::lower_bound( 5129a72cd7bSMehdi Amini Start, End, funcName, [](StringRef LHS, StringRef RHS) { 5139a72cd7bSMehdi Amini return LHS < RHS; 514d3b76a3bSMichael Zolotukhin }); 51562d4215bSChandler Carruth if (I != End && *I == funcName) { 51662d4215bSChandler Carruth F = (LibFunc::Func)(I - Start); 51762d4215bSChandler Carruth return true; 51862d4215bSChandler Carruth } 51962d4215bSChandler Carruth return false; 52062d4215bSChandler Carruth } 52162d4215bSChandler Carruth 522d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, 523d765a82bSAhmed Bougacha LibFunc::Func F, 524d765a82bSAhmed Bougacha const DataLayout *DL) const { 525d765a82bSAhmed Bougacha LLVMContext &Ctx = FTy.getContext(); 526d765a82bSAhmed Bougacha Type *PCharTy = Type::getInt8PtrTy(Ctx); 527d765a82bSAhmed Bougacha Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr; 528d765a82bSAhmed Bougacha auto IsSizeTTy = [SizeTTy](Type *Ty) { 529d765a82bSAhmed Bougacha return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); 530d765a82bSAhmed Bougacha }; 531d765a82bSAhmed Bougacha unsigned NumParams = FTy.getNumParams(); 532d765a82bSAhmed Bougacha 533d765a82bSAhmed Bougacha switch (F) { 534d765a82bSAhmed Bougacha case LibFunc::strlen: 535d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 536d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 537d765a82bSAhmed Bougacha 538d765a82bSAhmed Bougacha case LibFunc::strchr: 539d765a82bSAhmed Bougacha case LibFunc::strrchr: 540d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 541d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 542d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy()); 543d765a82bSAhmed Bougacha 544d765a82bSAhmed Bougacha case LibFunc::strtol: 545d765a82bSAhmed Bougacha case LibFunc::strtod: 546d765a82bSAhmed Bougacha case LibFunc::strtof: 547d765a82bSAhmed Bougacha case LibFunc::strtoul: 548d765a82bSAhmed Bougacha case LibFunc::strtoll: 549d765a82bSAhmed Bougacha case LibFunc::strtold: 550d765a82bSAhmed Bougacha case LibFunc::strtoull: 551d765a82bSAhmed Bougacha return ((NumParams == 2 || NumParams == 3) && 552d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 553d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 554d765a82bSAhmed Bougacha case LibFunc::strcat: 555d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 556d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 557d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType()); 558d765a82bSAhmed Bougacha 559d765a82bSAhmed Bougacha case LibFunc::strncat: 560d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 561d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 562d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType() && 563d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 564d765a82bSAhmed Bougacha 565d765a82bSAhmed Bougacha case LibFunc::strcpy_chk: 566d765a82bSAhmed Bougacha case LibFunc::stpcpy_chk: 567d765a82bSAhmed Bougacha --NumParams; 568d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 569d765a82bSAhmed Bougacha return false; 570b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 571d765a82bSAhmed Bougacha case LibFunc::strcpy: 572d765a82bSAhmed Bougacha case LibFunc::stpcpy: 573d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && 574d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 575d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy); 576d765a82bSAhmed Bougacha 577d765a82bSAhmed Bougacha case LibFunc::strncpy_chk: 578d765a82bSAhmed Bougacha case LibFunc::stpncpy_chk: 579d765a82bSAhmed Bougacha --NumParams; 580d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 581d765a82bSAhmed Bougacha return false; 582b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 583d765a82bSAhmed Bougacha case LibFunc::strncpy: 584d765a82bSAhmed Bougacha case LibFunc::stpncpy: 585d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 586d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 587d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy && 588d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 589d765a82bSAhmed Bougacha 590d765a82bSAhmed Bougacha case LibFunc::strxfrm: 591d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 592d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 593d765a82bSAhmed Bougacha 594d765a82bSAhmed Bougacha case LibFunc::strcmp: 595d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && 596d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 597d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 598d765a82bSAhmed Bougacha 599d765a82bSAhmed Bougacha case LibFunc::strncmp: 600d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 601d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 602d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 603d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 604d765a82bSAhmed Bougacha 605d765a82bSAhmed Bougacha case LibFunc::strspn: 606d765a82bSAhmed Bougacha case LibFunc::strcspn: 607d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 608d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 609d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 610d765a82bSAhmed Bougacha 611d765a82bSAhmed Bougacha case LibFunc::strcoll: 612d765a82bSAhmed Bougacha case LibFunc::strcasecmp: 613d765a82bSAhmed Bougacha case LibFunc::strncasecmp: 614d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 615d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 616d765a82bSAhmed Bougacha 617d765a82bSAhmed Bougacha case LibFunc::strstr: 618d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 619d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 620d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 621d765a82bSAhmed Bougacha 622d765a82bSAhmed Bougacha case LibFunc::strpbrk: 623d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 624d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 625d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 626d765a82bSAhmed Bougacha 627d765a82bSAhmed Bougacha case LibFunc::strtok: 628d765a82bSAhmed Bougacha case LibFunc::strtok_r: 629d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 630d765a82bSAhmed Bougacha case LibFunc::scanf: 631d765a82bSAhmed Bougacha case LibFunc::setbuf: 632d765a82bSAhmed Bougacha case LibFunc::setvbuf: 633d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 634d765a82bSAhmed Bougacha case LibFunc::strdup: 635d765a82bSAhmed Bougacha case LibFunc::strndup: 636d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 637d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 6389cc0bca2SDavide Italiano case LibFunc::sscanf: 639d765a82bSAhmed Bougacha case LibFunc::stat: 640d765a82bSAhmed Bougacha case LibFunc::statvfs: 641d765a82bSAhmed Bougacha case LibFunc::sprintf: 642d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 643d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 644d765a82bSAhmed Bougacha case LibFunc::snprintf: 645d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 646d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 647d765a82bSAhmed Bougacha case LibFunc::setitimer: 648d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 649d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 650d765a82bSAhmed Bougacha case LibFunc::system: 651d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 652d765a82bSAhmed Bougacha case LibFunc::malloc: 653d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 654d765a82bSAhmed Bougacha case LibFunc::memcmp: 655d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 656d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 657d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy(32)); 658d765a82bSAhmed Bougacha 659d765a82bSAhmed Bougacha case LibFunc::memchr: 660d765a82bSAhmed Bougacha case LibFunc::memrchr: 661d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 662d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32) && 663d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy() && 664d765a82bSAhmed Bougacha FTy.getReturnType()->isPointerTy()); 665d765a82bSAhmed Bougacha case LibFunc::modf: 666d765a82bSAhmed Bougacha case LibFunc::modff: 667d765a82bSAhmed Bougacha case LibFunc::modfl: 668d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 669d765a82bSAhmed Bougacha 670d765a82bSAhmed Bougacha case LibFunc::memcpy_chk: 671d765a82bSAhmed Bougacha case LibFunc::memmove_chk: 672d765a82bSAhmed Bougacha --NumParams; 673d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 674d765a82bSAhmed Bougacha return false; 675b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 676d765a82bSAhmed Bougacha case LibFunc::memcpy: 677b99d1cc7SAndrew Kaylor case LibFunc::mempcpy: 678d765a82bSAhmed Bougacha case LibFunc::memmove: 679d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 680d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 681d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 682d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 683d765a82bSAhmed Bougacha 684d765a82bSAhmed Bougacha case LibFunc::memset_chk: 685d765a82bSAhmed Bougacha --NumParams; 686d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 687d765a82bSAhmed Bougacha return false; 688b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 689d765a82bSAhmed Bougacha case LibFunc::memset: 690d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 691d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 692d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 693d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 694d765a82bSAhmed Bougacha 695d765a82bSAhmed Bougacha case LibFunc::memccpy: 696d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 697d765a82bSAhmed Bougacha case LibFunc::memalign: 698d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 699d765a82bSAhmed Bougacha case LibFunc::realloc: 700d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 701d765a82bSAhmed Bougacha FTy.getReturnType()->isPointerTy()); 702d765a82bSAhmed Bougacha case LibFunc::read: 703d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 704d765a82bSAhmed Bougacha case LibFunc::rewind: 705d765a82bSAhmed Bougacha case LibFunc::rmdir: 706d765a82bSAhmed Bougacha case LibFunc::remove: 707d765a82bSAhmed Bougacha case LibFunc::realpath: 708d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 709d765a82bSAhmed Bougacha case LibFunc::rename: 710d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 711d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 712d765a82bSAhmed Bougacha case LibFunc::readlink: 713d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 714d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 715d765a82bSAhmed Bougacha case LibFunc::write: 716d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 717d765a82bSAhmed Bougacha case LibFunc::bcopy: 718d765a82bSAhmed Bougacha case LibFunc::bcmp: 719d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 720d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 721d765a82bSAhmed Bougacha case LibFunc::bzero: 722d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 723d765a82bSAhmed Bougacha case LibFunc::calloc: 724d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 7251fe3f1caSAhmed Bougacha 7261fe3f1caSAhmed Bougacha case LibFunc::atof: 727d765a82bSAhmed Bougacha case LibFunc::atoi: 728d765a82bSAhmed Bougacha case LibFunc::atol: 729d765a82bSAhmed Bougacha case LibFunc::atoll: 7301fe3f1caSAhmed Bougacha case LibFunc::ferror: 7311fe3f1caSAhmed Bougacha case LibFunc::getenv: 7321fe3f1caSAhmed Bougacha case LibFunc::getpwnam: 7331fe3f1caSAhmed Bougacha case LibFunc::pclose: 7341fe3f1caSAhmed Bougacha case LibFunc::perror: 7351fe3f1caSAhmed Bougacha case LibFunc::printf: 7361fe3f1caSAhmed Bougacha case LibFunc::puts: 7371fe3f1caSAhmed Bougacha case LibFunc::uname: 7381fe3f1caSAhmed Bougacha case LibFunc::under_IO_getc: 7391fe3f1caSAhmed Bougacha case LibFunc::unlink: 7401fe3f1caSAhmed Bougacha case LibFunc::unsetenv: 741d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 7421fe3f1caSAhmed Bougacha 7431fe3f1caSAhmed Bougacha case LibFunc::chmod: 7441fe3f1caSAhmed Bougacha case LibFunc::chown: 7451fe3f1caSAhmed Bougacha case LibFunc::clearerr: 7461fe3f1caSAhmed Bougacha case LibFunc::closedir: 7471fe3f1caSAhmed Bougacha case LibFunc::ctermid: 7481fe3f1caSAhmed Bougacha case LibFunc::fclose: 7491fe3f1caSAhmed Bougacha case LibFunc::feof: 7501fe3f1caSAhmed Bougacha case LibFunc::fflush: 7511fe3f1caSAhmed Bougacha case LibFunc::fgetc: 7521fe3f1caSAhmed Bougacha case LibFunc::fileno: 7531fe3f1caSAhmed Bougacha case LibFunc::flockfile: 7541fe3f1caSAhmed Bougacha case LibFunc::free: 7551fe3f1caSAhmed Bougacha case LibFunc::fseek: 756201b97f5SAhmed Bougacha case LibFunc::fseeko64: 7571fe3f1caSAhmed Bougacha case LibFunc::fseeko: 7581fe3f1caSAhmed Bougacha case LibFunc::fsetpos: 7591fe3f1caSAhmed Bougacha case LibFunc::ftell: 760201b97f5SAhmed Bougacha case LibFunc::ftello64: 7611fe3f1caSAhmed Bougacha case LibFunc::ftello: 7621fe3f1caSAhmed Bougacha case LibFunc::ftrylockfile: 7631fe3f1caSAhmed Bougacha case LibFunc::funlockfile: 7641fe3f1caSAhmed Bougacha case LibFunc::getc: 7651fe3f1caSAhmed Bougacha case LibFunc::getc_unlocked: 7661fe3f1caSAhmed Bougacha case LibFunc::getlogin_r: 7671fe3f1caSAhmed Bougacha case LibFunc::mkdir: 7681fe3f1caSAhmed Bougacha case LibFunc::mktime: 7691fe3f1caSAhmed Bougacha case LibFunc::times: 7701fe3f1caSAhmed Bougacha return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); 7711fe3f1caSAhmed Bougacha 772d765a82bSAhmed Bougacha case LibFunc::access: 773d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 774d765a82bSAhmed Bougacha case LibFunc::fopen: 775d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 776d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 777d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 778d765a82bSAhmed Bougacha case LibFunc::fdopen: 779d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 780d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 781d765a82bSAhmed Bougacha case LibFunc::fputc: 782d765a82bSAhmed Bougacha case LibFunc::fstat: 783d765a82bSAhmed Bougacha case LibFunc::frexp: 784d765a82bSAhmed Bougacha case LibFunc::frexpf: 785d765a82bSAhmed Bougacha case LibFunc::frexpl: 786d765a82bSAhmed Bougacha case LibFunc::fstatvfs: 787d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 788d765a82bSAhmed Bougacha case LibFunc::fgets: 789d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 790d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 791d765a82bSAhmed Bougacha case LibFunc::fread: 792d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 793d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 794d765a82bSAhmed Bougacha case LibFunc::fwrite: 795d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && 796d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 797d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 798d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy() && 799d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 800d765a82bSAhmed Bougacha case LibFunc::fputs: 801d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 802d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 803d765a82bSAhmed Bougacha case LibFunc::fscanf: 804d765a82bSAhmed Bougacha case LibFunc::fprintf: 805d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 806d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 807d765a82bSAhmed Bougacha case LibFunc::fgetpos: 808d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 809d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 810d765a82bSAhmed Bougacha case LibFunc::gets: 811d765a82bSAhmed Bougacha case LibFunc::getchar: 812d765a82bSAhmed Bougacha case LibFunc::getitimer: 813d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 814d765a82bSAhmed Bougacha case LibFunc::ungetc: 815d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 816d765a82bSAhmed Bougacha case LibFunc::utime: 817d765a82bSAhmed Bougacha case LibFunc::utimes: 818d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 819d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 820d765a82bSAhmed Bougacha case LibFunc::putc: 821d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 822d765a82bSAhmed Bougacha case LibFunc::pread: 823d765a82bSAhmed Bougacha case LibFunc::pwrite: 824d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); 825d765a82bSAhmed Bougacha case LibFunc::popen: 826d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 827d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 828d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 829d765a82bSAhmed Bougacha case LibFunc::vscanf: 830d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 831d765a82bSAhmed Bougacha case LibFunc::vsscanf: 832d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 833d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 834d765a82bSAhmed Bougacha case LibFunc::vfscanf: 835d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 836d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 837d765a82bSAhmed Bougacha case LibFunc::valloc: 838d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 839d765a82bSAhmed Bougacha case LibFunc::vprintf: 840d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 841d765a82bSAhmed Bougacha case LibFunc::vfprintf: 842d765a82bSAhmed Bougacha case LibFunc::vsprintf: 843d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 844d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 845d765a82bSAhmed Bougacha case LibFunc::vsnprintf: 846d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 847d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 848d765a82bSAhmed Bougacha case LibFunc::open: 849d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 850d765a82bSAhmed Bougacha case LibFunc::opendir: 851d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && 852d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 853d765a82bSAhmed Bougacha case LibFunc::tmpfile: 854d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 855d765a82bSAhmed Bougacha case LibFunc::htonl: 856d765a82bSAhmed Bougacha case LibFunc::htons: 857d765a82bSAhmed Bougacha case LibFunc::ntohl: 858d765a82bSAhmed Bougacha case LibFunc::ntohs: 859d765a82bSAhmed Bougacha case LibFunc::lstat: 860d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 861d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 862d765a82bSAhmed Bougacha case LibFunc::lchown: 863d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 864d765a82bSAhmed Bougacha case LibFunc::qsort: 865d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); 866d765a82bSAhmed Bougacha case LibFunc::dunder_strdup: 867d765a82bSAhmed Bougacha case LibFunc::dunder_strndup: 868d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 869d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 870d765a82bSAhmed Bougacha case LibFunc::dunder_strtok_r: 871d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 872d765a82bSAhmed Bougacha case LibFunc::under_IO_putc: 873d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 874d765a82bSAhmed Bougacha case LibFunc::dunder_isoc99_scanf: 875d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 876d765a82bSAhmed Bougacha case LibFunc::stat64: 877d765a82bSAhmed Bougacha case LibFunc::lstat64: 878d765a82bSAhmed Bougacha case LibFunc::statvfs64: 87979dcc274SMichael Kuperstein return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 880d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 881d765a82bSAhmed Bougacha case LibFunc::dunder_isoc99_sscanf: 88279dcc274SMichael Kuperstein return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 883d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 884d765a82bSAhmed Bougacha case LibFunc::fopen64: 885d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 886d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 887d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 888d765a82bSAhmed Bougacha case LibFunc::tmpfile64: 889d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 890d765a82bSAhmed Bougacha case LibFunc::fstat64: 891d765a82bSAhmed Bougacha case LibFunc::fstatvfs64: 892d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 893d765a82bSAhmed Bougacha case LibFunc::open64: 894d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 895d765a82bSAhmed Bougacha case LibFunc::gettimeofday: 896d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 897d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 898d765a82bSAhmed Bougacha 899d765a82bSAhmed Bougacha case LibFunc::Znwj: // new(unsigned int); 900d765a82bSAhmed Bougacha case LibFunc::Znwm: // new(unsigned long); 901d765a82bSAhmed Bougacha case LibFunc::Znaj: // new[](unsigned int); 902d765a82bSAhmed Bougacha case LibFunc::Znam: // new[](unsigned long); 903d765a82bSAhmed Bougacha case LibFunc::msvc_new_int: // new(unsigned int); 904d765a82bSAhmed Bougacha case LibFunc::msvc_new_longlong: // new(unsigned long long); 905d765a82bSAhmed Bougacha case LibFunc::msvc_new_array_int: // new[](unsigned int); 906d765a82bSAhmed Bougacha case LibFunc::msvc_new_array_longlong: // new[](unsigned long long); 907d765a82bSAhmed Bougacha return (NumParams == 1); 908d765a82bSAhmed Bougacha 909d765a82bSAhmed Bougacha case LibFunc::memset_pattern16: 910d765a82bSAhmed Bougacha return (!FTy.isVarArg() && NumParams == 3 && 911d765a82bSAhmed Bougacha isa<PointerType>(FTy.getParamType(0)) && 912d765a82bSAhmed Bougacha isa<PointerType>(FTy.getParamType(1)) && 913d765a82bSAhmed Bougacha isa<IntegerType>(FTy.getParamType(2))); 914d765a82bSAhmed Bougacha 915d765a82bSAhmed Bougacha // int __nvvm_reflect(const char *); 916d765a82bSAhmed Bougacha case LibFunc::nvvm_reflect: 917d765a82bSAhmed Bougacha return (NumParams == 1 && isa<PointerType>(FTy.getParamType(0))); 918d765a82bSAhmed Bougacha 919d765a82bSAhmed Bougacha case LibFunc::sin: 920d765a82bSAhmed Bougacha case LibFunc::sinf: 921d765a82bSAhmed Bougacha case LibFunc::sinl: 922d765a82bSAhmed Bougacha case LibFunc::cos: 923d765a82bSAhmed Bougacha case LibFunc::cosf: 924d765a82bSAhmed Bougacha case LibFunc::cosl: 925b62692e2SDavid Majnemer case LibFunc::tan: 926b62692e2SDavid Majnemer case LibFunc::tanf: 927b62692e2SDavid Majnemer case LibFunc::tanl: 928d765a82bSAhmed Bougacha case LibFunc::exp: 929d765a82bSAhmed Bougacha case LibFunc::expf: 930d765a82bSAhmed Bougacha case LibFunc::expl: 931d765a82bSAhmed Bougacha case LibFunc::exp2: 932d765a82bSAhmed Bougacha case LibFunc::exp2f: 933d765a82bSAhmed Bougacha case LibFunc::exp2l: 934d765a82bSAhmed Bougacha case LibFunc::log: 935d765a82bSAhmed Bougacha case LibFunc::logf: 936d765a82bSAhmed Bougacha case LibFunc::logl: 937d765a82bSAhmed Bougacha case LibFunc::log10: 938d765a82bSAhmed Bougacha case LibFunc::log10f: 939d765a82bSAhmed Bougacha case LibFunc::log10l: 940d765a82bSAhmed Bougacha case LibFunc::log2: 941d765a82bSAhmed Bougacha case LibFunc::log2f: 942d765a82bSAhmed Bougacha case LibFunc::log2l: 943d765a82bSAhmed Bougacha case LibFunc::fabs: 944d765a82bSAhmed Bougacha case LibFunc::fabsf: 945d765a82bSAhmed Bougacha case LibFunc::fabsl: 946d765a82bSAhmed Bougacha case LibFunc::floor: 947d765a82bSAhmed Bougacha case LibFunc::floorf: 948d765a82bSAhmed Bougacha case LibFunc::floorl: 949d765a82bSAhmed Bougacha case LibFunc::ceil: 950d765a82bSAhmed Bougacha case LibFunc::ceilf: 951d765a82bSAhmed Bougacha case LibFunc::ceill: 952d765a82bSAhmed Bougacha case LibFunc::trunc: 953d765a82bSAhmed Bougacha case LibFunc::truncf: 954d765a82bSAhmed Bougacha case LibFunc::truncl: 955d765a82bSAhmed Bougacha case LibFunc::rint: 956d765a82bSAhmed Bougacha case LibFunc::rintf: 957d765a82bSAhmed Bougacha case LibFunc::rintl: 958d765a82bSAhmed Bougacha case LibFunc::nearbyint: 959d765a82bSAhmed Bougacha case LibFunc::nearbyintf: 960d765a82bSAhmed Bougacha case LibFunc::nearbyintl: 961d765a82bSAhmed Bougacha case LibFunc::round: 962d765a82bSAhmed Bougacha case LibFunc::roundf: 963d765a82bSAhmed Bougacha case LibFunc::roundl: 964d765a82bSAhmed Bougacha case LibFunc::sqrt: 965d765a82bSAhmed Bougacha case LibFunc::sqrtf: 966d765a82bSAhmed Bougacha case LibFunc::sqrtl: 967d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && 968d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 969d765a82bSAhmed Bougacha 970d765a82bSAhmed Bougacha case LibFunc::fmin: 971d765a82bSAhmed Bougacha case LibFunc::fminf: 972d765a82bSAhmed Bougacha case LibFunc::fminl: 973d765a82bSAhmed Bougacha case LibFunc::fmax: 974d765a82bSAhmed Bougacha case LibFunc::fmaxf: 975d765a82bSAhmed Bougacha case LibFunc::fmaxl: 976d765a82bSAhmed Bougacha case LibFunc::copysign: 977d765a82bSAhmed Bougacha case LibFunc::copysignf: 978d765a82bSAhmed Bougacha case LibFunc::copysignl: 979d765a82bSAhmed Bougacha case LibFunc::pow: 980d765a82bSAhmed Bougacha case LibFunc::powf: 981d765a82bSAhmed Bougacha case LibFunc::powl: 982d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 983d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 984d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(1)); 985d765a82bSAhmed Bougacha 986d765a82bSAhmed Bougacha case LibFunc::ffs: 987d765a82bSAhmed Bougacha case LibFunc::ffsl: 988d765a82bSAhmed Bougacha case LibFunc::ffsll: 98904949fafSSanjay Patel return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 99004949fafSSanjay Patel FTy.getParamType(0)->isIntegerTy()); 99104949fafSSanjay Patel 992d765a82bSAhmed Bougacha case LibFunc::isdigit: 993d765a82bSAhmed Bougacha case LibFunc::isascii: 994d765a82bSAhmed Bougacha case LibFunc::toascii: 995d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 99604949fafSSanjay Patel FTy.getReturnType() == FTy.getParamType(0)); 997d765a82bSAhmed Bougacha 998d765a82bSAhmed Bougacha case LibFunc::fls: 999d765a82bSAhmed Bougacha case LibFunc::flsl: 1000d765a82bSAhmed Bougacha case LibFunc::flsll: 1001d765a82bSAhmed Bougacha case LibFunc::abs: 1002d765a82bSAhmed Bougacha case LibFunc::labs: 1003d765a82bSAhmed Bougacha case LibFunc::llabs: 1004d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && 1005d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1006d765a82bSAhmed Bougacha 1007d765a82bSAhmed Bougacha case LibFunc::cxa_atexit: 1008d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && 1009d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1010d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 1011d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1012d765a82bSAhmed Bougacha 1013d765a82bSAhmed Bougacha case LibFunc::sinpi: 1014d765a82bSAhmed Bougacha case LibFunc::cospi: 1015d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && 1016d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1017d765a82bSAhmed Bougacha 1018d765a82bSAhmed Bougacha case LibFunc::sinpif: 1019d765a82bSAhmed Bougacha case LibFunc::cospif: 1020d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && 1021d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1022d765a82bSAhmed Bougacha 1023d765a82bSAhmed Bougacha default: 1024d765a82bSAhmed Bougacha // Assume the other functions are correct. 1025d765a82bSAhmed Bougacha // FIXME: It'd be really nice to cover them all. 1026d765a82bSAhmed Bougacha return true; 1027d765a82bSAhmed Bougacha } 1028d765a82bSAhmed Bougacha } 1029d765a82bSAhmed Bougacha 1030d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 1031d765a82bSAhmed Bougacha LibFunc::Func &F) const { 1032d765a82bSAhmed Bougacha const DataLayout *DL = 1033d765a82bSAhmed Bougacha FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; 1034d765a82bSAhmed Bougacha return getLibFunc(FDecl.getName(), F) && 1035d765a82bSAhmed Bougacha isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); 1036d765a82bSAhmed Bougacha } 1037d765a82bSAhmed Bougacha 1038c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() { 103962d4215bSChandler Carruth memset(AvailableArray, 0, sizeof(AvailableArray)); 104062d4215bSChandler Carruth } 1041b98f63dbSChandler Carruth 1042e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { 10439a72cd7bSMehdi Amini return LHS.ScalarFnName < RHS.ScalarFnName; 1044e8f2551fSMichael Zolotukhin } 1045e8f2551fSMichael Zolotukhin 1046e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { 10479a72cd7bSMehdi Amini return LHS.VectorFnName < RHS.VectorFnName; 1048e8f2551fSMichael Zolotukhin } 1049e8f2551fSMichael Zolotukhin 1050e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { 10519a72cd7bSMehdi Amini return LHS.ScalarFnName < S; 1052e8f2551fSMichael Zolotukhin } 1053e8f2551fSMichael Zolotukhin 1054e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { 10559a72cd7bSMehdi Amini return LHS.VectorFnName < S; 1056e8f2551fSMichael Zolotukhin } 1057e8f2551fSMichael Zolotukhin 1058e8f2551fSMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { 1059e8f2551fSMichael Zolotukhin VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end()); 1060e8f2551fSMichael Zolotukhin std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName); 1061e8f2551fSMichael Zolotukhin 1062e8f2551fSMichael Zolotukhin ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end()); 1063e8f2551fSMichael Zolotukhin std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName); 1064e8f2551fSMichael Zolotukhin } 1065e8f2551fSMichael Zolotukhin 10666d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( 10676d8a2aa9SMichael Zolotukhin enum VectorLibrary VecLib) { 10686d8a2aa9SMichael Zolotukhin switch (VecLib) { 10696d8a2aa9SMichael Zolotukhin case Accelerate: { 10706d8a2aa9SMichael Zolotukhin const VecDesc VecFuncs[] = { 1071de63aaceSMichael Zolotukhin // Floating-Point Arithmetic and Auxiliary Functions 1072de63aaceSMichael Zolotukhin {"ceilf", "vceilf", 4}, 10736d8a2aa9SMichael Zolotukhin {"fabsf", "vfabsf", 4}, 10746d8a2aa9SMichael Zolotukhin {"llvm.fabs.f32", "vfabsf", 4}, 1075de63aaceSMichael Zolotukhin {"floorf", "vfloorf", 4}, 1076de63aaceSMichael Zolotukhin {"sqrtf", "vsqrtf", 4}, 1077de63aaceSMichael Zolotukhin {"llvm.sqrt.f32", "vsqrtf", 4}, 1078de63aaceSMichael Zolotukhin 1079de63aaceSMichael Zolotukhin // Exponential and Logarithmic Functions 1080de63aaceSMichael Zolotukhin {"expf", "vexpf", 4}, 1081de63aaceSMichael Zolotukhin {"llvm.exp.f32", "vexpf", 4}, 1082de63aaceSMichael Zolotukhin {"expm1f", "vexpm1f", 4}, 1083de63aaceSMichael Zolotukhin {"logf", "vlogf", 4}, 1084de63aaceSMichael Zolotukhin {"llvm.log.f32", "vlogf", 4}, 1085de63aaceSMichael Zolotukhin {"log1pf", "vlog1pf", 4}, 1086de63aaceSMichael Zolotukhin {"log10f", "vlog10f", 4}, 1087de63aaceSMichael Zolotukhin {"llvm.log10.f32", "vlog10f", 4}, 1088de63aaceSMichael Zolotukhin {"logbf", "vlogbf", 4}, 1089de63aaceSMichael Zolotukhin 1090de63aaceSMichael Zolotukhin // Trigonometric Functions 1091de63aaceSMichael Zolotukhin {"sinf", "vsinf", 4}, 1092de63aaceSMichael Zolotukhin {"llvm.sin.f32", "vsinf", 4}, 1093de63aaceSMichael Zolotukhin {"cosf", "vcosf", 4}, 1094de63aaceSMichael Zolotukhin {"llvm.cos.f32", "vcosf", 4}, 1095de63aaceSMichael Zolotukhin {"tanf", "vtanf", 4}, 1096de63aaceSMichael Zolotukhin {"asinf", "vasinf", 4}, 1097de63aaceSMichael Zolotukhin {"acosf", "vacosf", 4}, 1098de63aaceSMichael Zolotukhin {"atanf", "vatanf", 4}, 1099de63aaceSMichael Zolotukhin 1100de63aaceSMichael Zolotukhin // Hyperbolic Functions 1101de63aaceSMichael Zolotukhin {"sinhf", "vsinhf", 4}, 1102de63aaceSMichael Zolotukhin {"coshf", "vcoshf", 4}, 1103de63aaceSMichael Zolotukhin {"tanhf", "vtanhf", 4}, 1104de63aaceSMichael Zolotukhin {"asinhf", "vasinhf", 4}, 1105de63aaceSMichael Zolotukhin {"acoshf", "vacoshf", 4}, 1106de63aaceSMichael Zolotukhin {"atanhf", "vatanhf", 4}, 11076d8a2aa9SMichael Zolotukhin }; 11086d8a2aa9SMichael Zolotukhin addVectorizableFunctions(VecFuncs); 11096d8a2aa9SMichael Zolotukhin break; 11106d8a2aa9SMichael Zolotukhin } 1111a6669a1eSMatt Masten case SVML: { 1112a6669a1eSMatt Masten const VecDesc VecFuncs[] = { 1113a6669a1eSMatt Masten {"sin", "__svml_sin2", 2}, 1114a6669a1eSMatt Masten {"sin", "__svml_sin4", 4}, 1115a6669a1eSMatt Masten {"sin", "__svml_sin8", 8}, 1116a6669a1eSMatt Masten 1117a6669a1eSMatt Masten {"sinf", "__svml_sinf4", 4}, 1118a6669a1eSMatt Masten {"sinf", "__svml_sinf8", 8}, 1119a6669a1eSMatt Masten {"sinf", "__svml_sinf16", 16}, 1120a6669a1eSMatt Masten 1121a6669a1eSMatt Masten {"cos", "__svml_cos2", 2}, 1122a6669a1eSMatt Masten {"cos", "__svml_cos4", 4}, 1123a6669a1eSMatt Masten {"cos", "__svml_cos8", 8}, 1124a6669a1eSMatt Masten 1125a6669a1eSMatt Masten {"cosf", "__svml_cosf4", 4}, 1126a6669a1eSMatt Masten {"cosf", "__svml_cosf8", 8}, 1127a6669a1eSMatt Masten {"cosf", "__svml_cosf16", 16}, 1128a6669a1eSMatt Masten 1129a6669a1eSMatt Masten {"pow", "__svml_pow2", 2}, 1130a6669a1eSMatt Masten {"pow", "__svml_pow4", 4}, 1131a6669a1eSMatt Masten {"pow", "__svml_pow8", 8}, 1132a6669a1eSMatt Masten 1133a6669a1eSMatt Masten {"powf", "__svml_powf4", 4}, 1134a6669a1eSMatt Masten {"powf", "__svml_powf8", 8}, 1135a6669a1eSMatt Masten {"powf", "__svml_powf16", 16}, 1136a6669a1eSMatt Masten 1137a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow2", 2}, 1138a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow4", 4}, 1139a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow8", 8}, 1140a6669a1eSMatt Masten 1141a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf4", 4}, 1142a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf8", 8}, 1143a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf16", 16}, 1144a6669a1eSMatt Masten 1145a6669a1eSMatt Masten {"exp", "__svml_exp2", 2}, 1146a6669a1eSMatt Masten {"exp", "__svml_exp4", 4}, 1147a6669a1eSMatt Masten {"exp", "__svml_exp8", 8}, 1148a6669a1eSMatt Masten 1149a6669a1eSMatt Masten {"expf", "__svml_expf4", 4}, 1150a6669a1eSMatt Masten {"expf", "__svml_expf8", 8}, 1151a6669a1eSMatt Masten {"expf", "__svml_expf16", 16}, 1152a6669a1eSMatt Masten 1153a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp2", 2}, 1154a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp4", 4}, 1155a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp8", 8}, 1156a6669a1eSMatt Masten 1157a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf4", 4}, 1158a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf8", 8}, 1159a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf16", 16}, 1160a6669a1eSMatt Masten 1161a6669a1eSMatt Masten {"log", "__svml_log2", 2}, 1162a6669a1eSMatt Masten {"log", "__svml_log4", 4}, 1163a6669a1eSMatt Masten {"log", "__svml_log8", 8}, 1164a6669a1eSMatt Masten 1165a6669a1eSMatt Masten {"logf", "__svml_logf4", 4}, 1166a6669a1eSMatt Masten {"logf", "__svml_logf8", 8}, 1167a6669a1eSMatt Masten {"logf", "__svml_logf16", 16}, 1168a6669a1eSMatt Masten 1169a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log2", 2}, 1170a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log4", 4}, 1171a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log8", 8}, 1172a6669a1eSMatt Masten 1173a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf4", 4}, 1174a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf8", 8}, 1175a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf16", 16}, 1176a6669a1eSMatt Masten }; 1177a6669a1eSMatt Masten addVectorizableFunctions(VecFuncs); 1178a6669a1eSMatt Masten break; 1179a6669a1eSMatt Masten } 11806d8a2aa9SMichael Zolotukhin case NoLibrary: 11816d8a2aa9SMichael Zolotukhin break; 11826d8a2aa9SMichael Zolotukhin } 11836d8a2aa9SMichael Zolotukhin } 11846d8a2aa9SMichael Zolotukhin 1185e8f2551fSMichael Zolotukhin bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { 1186e8f2551fSMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 1187e8f2551fSMichael Zolotukhin if (funcName.empty()) 1188e8f2551fSMichael Zolotukhin return false; 1189e8f2551fSMichael Zolotukhin 1190e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1191e8f2551fSMichael Zolotukhin VectorDescs.begin(), VectorDescs.end(), funcName, 1192e8f2551fSMichael Zolotukhin compareWithScalarFnName); 1193e8f2551fSMichael Zolotukhin return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; 1194e8f2551fSMichael Zolotukhin } 1195e8f2551fSMichael Zolotukhin 1196e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, 1197e8f2551fSMichael Zolotukhin unsigned VF) const { 1198e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1199e8f2551fSMichael Zolotukhin if (F.empty()) 1200e8f2551fSMichael Zolotukhin return F; 1201e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1202e8f2551fSMichael Zolotukhin VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName); 1203e8f2551fSMichael Zolotukhin while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { 1204e8f2551fSMichael Zolotukhin if (I->VectorizationFactor == VF) 1205e8f2551fSMichael Zolotukhin return I->VectorFnName; 1206e8f2551fSMichael Zolotukhin ++I; 1207e8f2551fSMichael Zolotukhin } 1208e8f2551fSMichael Zolotukhin return StringRef(); 1209e8f2551fSMichael Zolotukhin } 1210e8f2551fSMichael Zolotukhin 1211e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F, 1212e8f2551fSMichael Zolotukhin unsigned &VF) const { 1213e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1214e8f2551fSMichael Zolotukhin if (F.empty()) 1215e8f2551fSMichael Zolotukhin return F; 1216e8f2551fSMichael Zolotukhin 1217e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1218e8f2551fSMichael Zolotukhin ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName); 1219e8f2551fSMichael Zolotukhin if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F) 1220e8f2551fSMichael Zolotukhin return StringRef(); 1221e8f2551fSMichael Zolotukhin VF = I->VectorizationFactor; 1222e8f2551fSMichael Zolotukhin return I->ScalarFnName; 1223e8f2551fSMichael Zolotukhin } 1224e8f2551fSMichael Zolotukhin 1225164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Module &M, 1226164a2aa6SChandler Carruth ModuleAnalysisManager &) { 1227c0291865SChandler Carruth if (PresetInfoImpl) 1228c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1229c0291865SChandler Carruth 1230c0291865SChandler Carruth return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple()))); 1231c0291865SChandler Carruth } 1232c0291865SChandler Carruth 1233164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Function &F, 1234164a2aa6SChandler Carruth FunctionAnalysisManager &) { 1235c0291865SChandler Carruth if (PresetInfoImpl) 1236c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1237c0291865SChandler Carruth 1238c0291865SChandler Carruth return TargetLibraryInfo( 1239c0291865SChandler Carruth lookupInfoImpl(Triple(F.getParent()->getTargetTriple()))); 1240c0291865SChandler Carruth } 1241c0291865SChandler Carruth 1242c321e534SBenjamin Kramer TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) { 1243c0291865SChandler Carruth std::unique_ptr<TargetLibraryInfoImpl> &Impl = 1244c0291865SChandler Carruth Impls[T.normalize()]; 1245c0291865SChandler Carruth if (!Impl) 1246c0291865SChandler Carruth Impl.reset(new TargetLibraryInfoImpl(T)); 1247c0291865SChandler Carruth 1248c0291865SChandler Carruth return *Impl; 1249c0291865SChandler Carruth } 1250c0291865SChandler Carruth 1251c0291865SChandler Carruth 1252b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() 1253c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) { 1254b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1255b98f63dbSChandler Carruth } 1256b98f63dbSChandler Carruth 1257b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) 1258c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) { 1259b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1260b98f63dbSChandler Carruth } 1261b98f63dbSChandler Carruth 1262b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( 1263c0291865SChandler Carruth const TargetLibraryInfoImpl &TLIImpl) 1264c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) { 1265b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1266b98f63dbSChandler Carruth } 1267b98f63dbSChandler Carruth 1268*dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key; 1269df0cd726SNAKAMURA Takumi 1270b98f63dbSChandler Carruth // Register the basic pass. 1271b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", 1272b98f63dbSChandler Carruth "Target Library Information", false, true) 1273b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0; 1274b98f63dbSChandler Carruth 1275b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {} 1276