162d4215bSChandler Carruth //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==// 262d4215bSChandler Carruth // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 662d4215bSChandler Carruth // 762d4215bSChandler Carruth //===----------------------------------------------------------------------===// 862d4215bSChandler Carruth // 962d4215bSChandler Carruth // This file implements the TargetLibraryInfo class. 1062d4215bSChandler Carruth // 1162d4215bSChandler Carruth //===----------------------------------------------------------------------===// 1262d4215bSChandler Carruth 1362d4215bSChandler Carruth #include "llvm/Analysis/TargetLibraryInfo.h" 1462d4215bSChandler Carruth #include "llvm/ADT/Triple.h" 1550ec0b5dSMatthias Braun #include "llvm/IR/Constants.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", 277459398aSJoel Jones "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 52600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified 53600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target 54600d24b4SSanjay Patel /// 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 64ca22d427SDavid Bolvansky // Set IO unlocked variants as unavailable 65ca22d427SDavid Bolvansky // Set them as available per system below 66ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_getchar_unlocked); 67ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_putc_unlocked); 68ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_putchar_unlocked); 69ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fputc_unlocked); 70ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fgetc_unlocked); 71ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fread_unlocked); 72ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fwrite_unlocked); 73ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fputs_unlocked); 74ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fgets_unlocked); 75ca22d427SDavid Bolvansky 766af8e6c3SMarcin Koscielnicki bool ShouldExtI32Param = false, ShouldExtI32Return = false, 776af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = false; 786af8e6c3SMarcin Koscielnicki // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and 796af8e6c3SMarcin Koscielnicki // returns corresponding to C-level ints and unsigned ints. 806af8e6c3SMarcin Koscielnicki if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le || 816af8e6c3SMarcin Koscielnicki T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) { 826af8e6c3SMarcin Koscielnicki ShouldExtI32Param = true; 836af8e6c3SMarcin Koscielnicki ShouldExtI32Return = true; 846af8e6c3SMarcin Koscielnicki } 856af8e6c3SMarcin Koscielnicki // Mips, on the other hand, needs signext on i32 parameters corresponding 866af8e6c3SMarcin Koscielnicki // to both signed and unsigned ints. 8785e200e9SAlexander Richardson if (T.isMIPS()) { 886af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = true; 896af8e6c3SMarcin Koscielnicki } 906af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Param(ShouldExtI32Param); 916af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Return(ShouldExtI32Return); 926af8e6c3SMarcin Koscielnicki TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); 936af8e6c3SMarcin Koscielnicki 9478fd4f08SNicolai Hahnle if (T.getArch() == Triple::r600 || 9578fd4f08SNicolai Hahnle T.getArch() == Triple::amdgcn) { 96d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexp); 97d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexpf); 98d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexpl); 99d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 100d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 101d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 102d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10); 103d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10f); 104d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10l); 10578fd4f08SNicolai Hahnle } 10678fd4f08SNicolai Hahnle 10762d4215bSChandler Carruth // There are no library implementations of mempcy and memset for AMD gpus and 10862d4215bSChandler Carruth // these can be difficult to lower in the backend. 10962d4215bSChandler Carruth if (T.getArch() == Triple::r600 || 11005532995SDan Gohman T.getArch() == Triple::amdgcn) { 111d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memcpy); 112d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset); 113d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 11462d4215bSChandler Carruth return; 11562d4215bSChandler Carruth } 11662d4215bSChandler Carruth 11762d4215bSChandler Carruth // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. 1188b40366bSTim Northover // All versions of watchOS support it. 11962d4215bSChandler Carruth if (T.isMacOSX()) { 120ca22d427SDavid Bolvansky // available IO unlocked variants on Mac OS X 121ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getc_unlocked); 122ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getchar_unlocked); 123ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putc_unlocked); 124ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putchar_unlocked); 125ca22d427SDavid Bolvansky 12662d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 5)) 127d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 12862d4215bSChandler Carruth } else if (T.isiOS()) { 12962d4215bSChandler Carruth if (T.isOSVersionLT(3, 0)) 130d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 1318b40366bSTim Northover } else if (!T.isWatchOS()) { 132d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 13362d4215bSChandler Carruth } 13462d4215bSChandler Carruth 13562d4215bSChandler Carruth if (!hasSinCosPiStret(T)) { 136d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpi); 137d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpif); 138d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospi); 139d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospif); 140d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospi_stret); 141d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospif_stret); 14262d4215bSChandler Carruth } 14362d4215bSChandler Carruth 14462d4215bSChandler Carruth if (T.isMacOSX() && T.getArch() == Triple::x86 && 14562d4215bSChandler Carruth !T.isMacOSXVersionLT(10, 7)) { 14662d4215bSChandler Carruth // x86-32 OSX has a scheme where fwrite and fputs (and some other functions 14762d4215bSChandler Carruth // we don't care about) have two versions; on recent OSX, the one we want 14862d4215bSChandler Carruth // has a $UNIX2003 suffix. The two implementations are identical except 14962d4215bSChandler Carruth // for the return value in some edge cases. However, we don't want to 15062d4215bSChandler Carruth // generate code that depends on the old symbols. 151d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003"); 152d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003"); 15362d4215bSChandler Carruth } 15462d4215bSChandler Carruth 15562d4215bSChandler Carruth // iprintf and friends are only available on XCore and TCE. 15662d4215bSChandler Carruth if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { 157d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_iprintf); 158d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_siprintf); 159d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fiprintf); 16062d4215bSChandler Carruth } 16162d4215bSChandler Carruth 16262d4215bSChandler Carruth if (T.isOSWindows() && !T.isOSCygMing()) { 163*98f356cdSEvandro Menezes // Win32 does not support long double 164*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acosl); 165*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_asinl); 166*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atanl); 167*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atan2l); 168*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ceill); 169*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_copysignl); 170*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cosl); 171*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_coshl); 172*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_expl); 173*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf 174*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fabsl); 175*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_floorl); 176*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fmaxl); 177*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fminl); 178*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fmodl); 179*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_frexpl); 180*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ldexpf); 181*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ldexpl); 182*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_logl); 183*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_modfl); 184*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_powl); 185*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sinl); 186*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sinhl); 187*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sqrtl); 188*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_tanl); 189*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_tanhl); 19062d4215bSChandler Carruth 191*98f356cdSEvandro Menezes // Win32 only has C89 math 192*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acosh); 193*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acoshf); 194*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acoshl); 195*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_asinh); 196*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_asinhf); 197*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_asinhl); 198*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atanh); 199*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atanhf); 200*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atanhl); 201*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cabs); 202*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cabsf); 203*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cabsl); 204*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cbrt); 205*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cbrtf); 206*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cbrtl); 207*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_exp2); 208*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_exp2f); 209*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_exp2l); 210*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_expm1); 211*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_expm1f); 212*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_expm1l); 213*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_log2); 214*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_log2f); 215*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_log2l); 216*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_log1p); 217*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_log1pf); 218*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_log1pl); 219*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_logb); 220*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_logbf); 221*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_logbl); 222*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_nearbyint); 223*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_nearbyintf); 224*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_nearbyintl); 225*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_rint); 226*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_rintf); 227*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_rintl); 228*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_round); 229*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_roundf); 230*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_roundl); 231*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_trunc); 232*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_truncf); 233*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_truncl); 234*98f356cdSEvandro Menezes 235*98f356cdSEvandro Menezes // Win32 provides some C99 math with mangled names 236*98f356cdSEvandro Menezes TLI.setAvailableWithName(LibFunc_copysign, "_copysign"); 237*98f356cdSEvandro Menezes 238*98f356cdSEvandro Menezes if (T.getArch() == Triple::x86) { 239*98f356cdSEvandro Menezes // Win32 on x86 implements single-precision math functions as macros 240d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_acosf); 241d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_asinf); 242d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atanf); 243d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atan2f); 244d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ceilf); 245*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_copysignf); 246d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cosf); 247d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_coshf); 248d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_expf); 249d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_floorf); 250*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fminf); 251*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fmaxf); 252d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fmodf); 253d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_logf); 254d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10f); 255d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_modff); 256d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_powf); 257d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinf); 258d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinhf); 259d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sqrtf); 260d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tanf); 261d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tanhf); 26262d4215bSChandler Carruth } 26362d4215bSChandler Carruth 264*98f356cdSEvandro Menezes // Win32 does *not* provide these functions, but they are 26562d4215bSChandler Carruth // generally available on POSIX-compliant systems: 266d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_access); 267d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcmp); 268d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcopy); 269d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bzero); 270d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chmod); 271d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chown); 272d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_closedir); 273d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ctermid); 274d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fdopen); 275d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffs); 276d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fileno); 277d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flockfile); 278d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko); 279d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat); 280d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs); 281d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello); 282d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftrylockfile); 283d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_funlockfile); 284d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getitimer); 285d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getlogin_r); 286d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getpwnam); 287d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_gettimeofday); 288d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htonl); 289d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htons); 290d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lchown); 291d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat); 292d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memccpy); 293d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_mkdir); 294d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohl); 295d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohs); 296d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open); 297d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_opendir); 298d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pclose); 299d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_popen); 300d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pread); 301d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pwrite); 302d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_read); 303d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_readlink); 304d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_realpath); 305d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_rmdir); 306d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_setitimer); 307d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat); 308d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs); 309d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpcpy); 310d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpncpy); 311d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_strcasecmp); 312d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_strncasecmp); 313d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_times); 314d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_uname); 315d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unlink); 316d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unsetenv); 317d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utime); 318d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utimes); 319d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_write); 320*98f356cdSEvandro Menezes 321*98f356cdSEvandro Menezes // Win32 does *not* provide provide these functions, but they are 322*98f356cdSEvandro Menezes // specified by C99: 323*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atoll); 324*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_frexpf); 325*98f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_llabs); 32662d4215bSChandler Carruth } 32762d4215bSChandler Carruth 32862d4215bSChandler Carruth switch (T.getOS()) { 32962d4215bSChandler Carruth case Triple::MacOSX: 33062d4215bSChandler Carruth // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 33162d4215bSChandler Carruth // and their names are __exp10 and __exp10f. exp10l is not available on 33262d4215bSChandler Carruth // OS X or iOS. 333d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 33462d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 9)) { 335d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 336d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 33762d4215bSChandler Carruth } else { 338d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 339d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 34062d4215bSChandler Carruth } 34162d4215bSChandler Carruth break; 34262d4215bSChandler Carruth case Triple::IOS: 34389a6eefeSTim Northover case Triple::TvOS: 3448b40366bSTim Northover case Triple::WatchOS: 345d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 3468b40366bSTim Northover if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) || 3478b40366bSTim Northover (T.isOSVersionLT(9, 0) && 3488b40366bSTim Northover (T.getArch() == Triple::x86 || 3498b40366bSTim Northover T.getArch() == Triple::x86_64)))) { 350d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 351d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 35262d4215bSChandler Carruth } else { 353d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 354d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 35562d4215bSChandler Carruth } 35662d4215bSChandler Carruth break; 35762d4215bSChandler Carruth case Triple::Linux: 35862d4215bSChandler Carruth // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely 35962d4215bSChandler Carruth // buggy prior to glibc version 2.18. Until this version is widely deployed 36062d4215bSChandler Carruth // or we have a reasonable detection strategy, we cannot use exp10 reliably 36162d4215bSChandler Carruth // on Linux. 36262d4215bSChandler Carruth // 36362d4215bSChandler Carruth // Fall through to disable all of them. 364cd1d5aafSJustin Bogner LLVM_FALLTHROUGH; 36562d4215bSChandler Carruth default: 366d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 367d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 368d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 36962d4215bSChandler Carruth } 37062d4215bSChandler Carruth 37162d4215bSChandler Carruth // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and 37262d4215bSChandler Carruth // Linux (GLIBC): 37362d4215bSChandler Carruth // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html 37483b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c 37562d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html 37662d4215bSChandler Carruth switch (T.getOS()) { 37762d4215bSChandler Carruth case Triple::Darwin: 37862d4215bSChandler Carruth case Triple::MacOSX: 37962d4215bSChandler Carruth case Triple::IOS: 38089a6eefeSTim Northover case Triple::TvOS: 3818b40366bSTim Northover case Triple::WatchOS: 38262d4215bSChandler Carruth case Triple::FreeBSD: 38362d4215bSChandler Carruth case Triple::Linux: 38462d4215bSChandler Carruth break; 38562d4215bSChandler Carruth default: 386d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsl); 38762d4215bSChandler Carruth } 38862d4215bSChandler Carruth 38962d4215bSChandler Carruth // ffsll is available on at least FreeBSD and Linux (GLIBC): 39083b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c 39162d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html 39262d4215bSChandler Carruth switch (T.getOS()) { 39389a6eefeSTim Northover case Triple::Darwin: 39489a6eefeSTim Northover case Triple::MacOSX: 39589a6eefeSTim Northover case Triple::IOS: 39689a6eefeSTim Northover case Triple::TvOS: 39789a6eefeSTim Northover case Triple::WatchOS: 39862d4215bSChandler Carruth case Triple::FreeBSD: 39962d4215bSChandler Carruth case Triple::Linux: 40062d4215bSChandler Carruth break; 40162d4215bSChandler Carruth default: 402d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsll); 40362d4215bSChandler Carruth } 40462d4215bSChandler Carruth 405bfd3082eSDavide Italiano // The following functions are available on at least FreeBSD: 406bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/fls.c 407bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c 408bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c 409bfd3082eSDavide Italiano if (!T.isOSFreeBSD()) { 410d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fls); 411d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsl); 412d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsll); 413bfd3082eSDavide Italiano } 414bfd3082eSDavide Italiano 415e3a5fc6dSEli Friedman // The following functions are only available on GNU/Linux (using glibc). 416e3a5fc6dSEli Friedman // Linux variants without glibc (eg: bionic, musl) may have some subset. 417e3a5fc6dSEli Friedman if (!T.isOSLinux() || !T.isGNUEnvironment()) { 418d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strdup); 419d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strtok_r); 420d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_scanf); 421d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf); 422d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_getc); 423d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_putc); 424e3a5fc6dSEli Friedman // But, Android and musl have memalign. 425e3a5fc6dSEli Friedman if (!T.isAndroid() && !T.isMusl()) 426d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memalign); 427d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fopen64); 428d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko64); 429d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat64); 430d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs64); 431d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello64); 432d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat64); 433d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open64); 434d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat64); 435d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs64); 436d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tmpfile64); 43752149f03SSanjay Patel 43852149f03SSanjay Patel // Relaxed math functions are included in math-finite.h on Linux (GLIBC). 43952149f03SSanjay Patel TLI.setUnavailable(LibFunc_acos_finite); 44052149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosf_finite); 44152149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosl_finite); 44252149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosh_finite); 44352149f03SSanjay Patel TLI.setUnavailable(LibFunc_acoshf_finite); 44452149f03SSanjay Patel TLI.setUnavailable(LibFunc_acoshl_finite); 44552149f03SSanjay Patel TLI.setUnavailable(LibFunc_asin_finite); 44652149f03SSanjay Patel TLI.setUnavailable(LibFunc_asinf_finite); 44752149f03SSanjay Patel TLI.setUnavailable(LibFunc_asinl_finite); 44852149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2_finite); 44952149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2f_finite); 45052149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2l_finite); 45152149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanh_finite); 45252149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanhf_finite); 45352149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanhl_finite); 45452149f03SSanjay Patel TLI.setUnavailable(LibFunc_cosh_finite); 45552149f03SSanjay Patel TLI.setUnavailable(LibFunc_coshf_finite); 45652149f03SSanjay Patel TLI.setUnavailable(LibFunc_coshl_finite); 45752149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10_finite); 45852149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10f_finite); 45952149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10l_finite); 46052149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2_finite); 46152149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2f_finite); 46252149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2l_finite); 46352149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp_finite); 46452149f03SSanjay Patel TLI.setUnavailable(LibFunc_expf_finite); 46552149f03SSanjay Patel TLI.setUnavailable(LibFunc_expl_finite); 46652149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10_finite); 46752149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10f_finite); 46852149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10l_finite); 46952149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2_finite); 47052149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2f_finite); 47152149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2l_finite); 47252149f03SSanjay Patel TLI.setUnavailable(LibFunc_log_finite); 47352149f03SSanjay Patel TLI.setUnavailable(LibFunc_logf_finite); 47452149f03SSanjay Patel TLI.setUnavailable(LibFunc_logl_finite); 47552149f03SSanjay Patel TLI.setUnavailable(LibFunc_pow_finite); 47652149f03SSanjay Patel TLI.setUnavailable(LibFunc_powf_finite); 47752149f03SSanjay Patel TLI.setUnavailable(LibFunc_powl_finite); 47852149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinh_finite); 47952149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinhf_finite); 48052149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinhl_finite); 48162d4215bSChandler Carruth } 4826d8a2aa9SMichael Zolotukhin 483c1078872SMartin Storsjo if ((T.isOSLinux() && T.isGNUEnvironment()) || 484c1078872SMartin Storsjo (T.isAndroid() && !T.isAndroidVersionLT(28))) { 485ca22d427SDavid Bolvansky // available IO unlocked variants on GNU/Linux and Android P or later 486ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getc_unlocked); 487ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getchar_unlocked); 488ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putc_unlocked); 489ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putchar_unlocked); 490ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fputc_unlocked); 491ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fgetc_unlocked); 492ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fread_unlocked); 493ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fwrite_unlocked); 494ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fputs_unlocked); 495ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fgets_unlocked); 496ca22d427SDavid Bolvansky } 497ca22d427SDavid Bolvansky 49851132881SJustin Lebar // As currently implemented in clang, NVPTX code has no standard library to 49951132881SJustin Lebar // speak of. Headers provide a standard-ish library implementation, but many 50051132881SJustin Lebar // of the signatures are wrong -- for example, many libm functions are not 50151132881SJustin Lebar // extern "C". 50251132881SJustin Lebar // 50351132881SJustin Lebar // libdevice, an IR library provided by nvidia, is linked in by the front-end, 50451132881SJustin Lebar // but only used functions are provided to llvm. Moreover, most of the 50551132881SJustin Lebar // functions in libdevice don't map precisely to standard library functions. 50651132881SJustin Lebar // 50751132881SJustin Lebar // FIXME: Having no standard library prevents e.g. many fastmath 50851132881SJustin Lebar // optimizations, so this situation should be fixed. 509ae272d71SDavid Majnemer if (T.isNVPTX()) { 51051132881SJustin Lebar TLI.disableAllFunctions(); 511d21529faSDavid L. Jones TLI.setAvailable(LibFunc_nvvm_reflect); 512ae272d71SDavid Majnemer } else { 513d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nvvm_reflect); 514ae272d71SDavid Majnemer } 51551132881SJustin Lebar 5166d8a2aa9SMichael Zolotukhin TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); 51762d4215bSChandler Carruth } 51862d4215bSChandler Carruth 519c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() { 52062d4215bSChandler Carruth // Default to everything being available. 52162d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 52262d4215bSChandler Carruth 52362d4215bSChandler Carruth initialize(*this, Triple(), StandardNames); 52462d4215bSChandler Carruth } 52562d4215bSChandler Carruth 5267459398aSJoel Jones TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { 52762d4215bSChandler Carruth // Default to everything being available. 52862d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 52962d4215bSChandler Carruth 53062d4215bSChandler Carruth initialize(*this, T, StandardNames); 53162d4215bSChandler Carruth } 53262d4215bSChandler Carruth 533c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) 5347459398aSJoel Jones : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), 5355ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 5365ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 53762d4215bSChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 538e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 539e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 5408ca43224SChandler Carruth } 5418ca43224SChandler Carruth 542c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) 5437459398aSJoel Jones : CustomNames(std::move(TLI.CustomNames)), 5445ae2c526SMarcin Koscielnicki ShouldExtI32Param(TLI.ShouldExtI32Param), 5455ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 5465ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 5478ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 5488ca43224SChandler Carruth AvailableArray); 549e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 550e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 5518ca43224SChandler Carruth } 5528ca43224SChandler Carruth 553c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { 55462d4215bSChandler Carruth CustomNames = TLI.CustomNames; 5555ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 5565ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 5575ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 5588ca43224SChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 5598ca43224SChandler Carruth return *this; 5608ca43224SChandler Carruth } 5618ca43224SChandler Carruth 562c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { 5638ca43224SChandler Carruth CustomNames = std::move(TLI.CustomNames); 5645ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 5655ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 5665ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 5678ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 5688ca43224SChandler Carruth AvailableArray); 5698ca43224SChandler Carruth return *this; 57062d4215bSChandler Carruth } 57162d4215bSChandler Carruth 57221abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) { 57362d4215bSChandler Carruth // Filter out empty names and names containing null bytes, those can't be in 57462d4215bSChandler Carruth // our table. 57562d4215bSChandler Carruth if (funcName.empty() || funcName.find('\0') != StringRef::npos) 57621abdf98SMichael Zolotukhin return StringRef(); 57762d4215bSChandler Carruth 57862d4215bSChandler Carruth // Check for \01 prefix that is used to mangle __asm declarations and 57962d4215bSChandler Carruth // strip it if present. 5806f0ecca3SPeter Collingbourne return GlobalValue::dropLLVMManglingEscape(funcName); 58121abdf98SMichael Zolotukhin } 58221abdf98SMichael Zolotukhin 58321abdf98SMichael Zolotukhin bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, 584d21529faSDavid L. Jones LibFunc &F) const { 5859a72cd7bSMehdi Amini StringRef const *Start = &StandardNames[0]; 586d21529faSDavid L. Jones StringRef const *End = &StandardNames[NumLibFuncs]; 58721abdf98SMichael Zolotukhin 58821abdf98SMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 58921abdf98SMichael Zolotukhin if (funcName.empty()) 59021abdf98SMichael Zolotukhin return false; 59121abdf98SMichael Zolotukhin 5929a72cd7bSMehdi Amini StringRef const *I = std::lower_bound( 5939a72cd7bSMehdi Amini Start, End, funcName, [](StringRef LHS, StringRef RHS) { 5949a72cd7bSMehdi Amini return LHS < RHS; 595d3b76a3bSMichael Zolotukhin }); 59662d4215bSChandler Carruth if (I != End && *I == funcName) { 597d21529faSDavid L. Jones F = (LibFunc)(I - Start); 59862d4215bSChandler Carruth return true; 59962d4215bSChandler Carruth } 60062d4215bSChandler Carruth return false; 60162d4215bSChandler Carruth } 60262d4215bSChandler Carruth 603d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, 604d21529faSDavid L. Jones LibFunc F, 605d765a82bSAhmed Bougacha const DataLayout *DL) const { 606d765a82bSAhmed Bougacha LLVMContext &Ctx = FTy.getContext(); 607d765a82bSAhmed Bougacha Type *PCharTy = Type::getInt8PtrTy(Ctx); 608d765a82bSAhmed Bougacha Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr; 609d765a82bSAhmed Bougacha auto IsSizeTTy = [SizeTTy](Type *Ty) { 610d765a82bSAhmed Bougacha return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); 611d765a82bSAhmed Bougacha }; 612d765a82bSAhmed Bougacha unsigned NumParams = FTy.getNumParams(); 613d765a82bSAhmed Bougacha 614d765a82bSAhmed Bougacha switch (F) { 615c3bed1e8SCalixte Denizet case LibFunc_execl: 616c3bed1e8SCalixte Denizet case LibFunc_execlp: 6178f07efc7SCalixte Denizet case LibFunc_execle: 618c3bed1e8SCalixte Denizet return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 619c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 620c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 621c3bed1e8SCalixte Denizet case LibFunc_execv: 622c3bed1e8SCalixte Denizet case LibFunc_execvp: 623c3bed1e8SCalixte Denizet return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 624c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 625c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 626c3bed1e8SCalixte Denizet case LibFunc_execvP: 627c3bed1e8SCalixte Denizet case LibFunc_execvpe: 628c3bed1e8SCalixte Denizet case LibFunc_execve: 629c3bed1e8SCalixte Denizet return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 630c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 631c3bed1e8SCalixte Denizet FTy.getParamType(2)->isPointerTy() && 632c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 633d21529faSDavid L. Jones case LibFunc_strlen: 634d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 635d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 636d765a82bSAhmed Bougacha 637d21529faSDavid L. Jones case LibFunc_strchr: 638d21529faSDavid L. Jones case LibFunc_strrchr: 639d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 640d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 641d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy()); 642d765a82bSAhmed Bougacha 643d21529faSDavid L. Jones case LibFunc_strtol: 644d21529faSDavid L. Jones case LibFunc_strtod: 645d21529faSDavid L. Jones case LibFunc_strtof: 646d21529faSDavid L. Jones case LibFunc_strtoul: 647d21529faSDavid L. Jones case LibFunc_strtoll: 648d21529faSDavid L. Jones case LibFunc_strtold: 649d21529faSDavid L. Jones case LibFunc_strtoull: 650d765a82bSAhmed Bougacha return ((NumParams == 2 || NumParams == 3) && 651d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 652d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 653d21529faSDavid L. Jones case LibFunc_strcat: 654d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 655d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 656d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType()); 657d765a82bSAhmed Bougacha 658d21529faSDavid L. Jones case LibFunc_strncat: 659d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 660d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 661d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType() && 6627bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 663d765a82bSAhmed Bougacha 664d21529faSDavid L. Jones case LibFunc_strcpy_chk: 665d21529faSDavid L. Jones case LibFunc_stpcpy_chk: 666d765a82bSAhmed Bougacha --NumParams; 667d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 668d765a82bSAhmed Bougacha return false; 669b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 670d21529faSDavid L. Jones case LibFunc_strcpy: 671d21529faSDavid L. Jones case LibFunc_stpcpy: 672d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && 673d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 674d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy); 675d765a82bSAhmed Bougacha 676d21529faSDavid L. Jones case LibFunc_strncpy_chk: 677d21529faSDavid L. Jones case LibFunc_stpncpy_chk: 678d765a82bSAhmed Bougacha --NumParams; 679d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 680d765a82bSAhmed Bougacha return false; 681b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 682d21529faSDavid L. Jones case LibFunc_strncpy: 683d21529faSDavid L. Jones case LibFunc_stpncpy: 684d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 685d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 686d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy && 6877bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 688d765a82bSAhmed Bougacha 689d21529faSDavid L. Jones case LibFunc_strxfrm: 690d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 691d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 692d765a82bSAhmed Bougacha 693d21529faSDavid L. Jones case LibFunc_strcmp: 694d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && 695d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 696d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 697d765a82bSAhmed Bougacha 698d21529faSDavid L. Jones case LibFunc_strncmp: 699d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 700d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 701d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 7027bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 703d765a82bSAhmed Bougacha 704d21529faSDavid L. Jones case LibFunc_strspn: 705d21529faSDavid L. Jones case LibFunc_strcspn: 706d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 707d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 708d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 709d765a82bSAhmed Bougacha 710d21529faSDavid L. Jones case LibFunc_strcoll: 711d21529faSDavid L. Jones case LibFunc_strcasecmp: 712d21529faSDavid L. Jones case LibFunc_strncasecmp: 713d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 714d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 715d765a82bSAhmed Bougacha 716d21529faSDavid L. Jones case LibFunc_strstr: 717d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 718d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 719d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 720d765a82bSAhmed Bougacha 721d21529faSDavid L. Jones case LibFunc_strpbrk: 722d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 723d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 724d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 725d765a82bSAhmed Bougacha 726d21529faSDavid L. Jones case LibFunc_strtok: 727d21529faSDavid L. Jones case LibFunc_strtok_r: 728d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 729d21529faSDavid L. Jones case LibFunc_scanf: 730d21529faSDavid L. Jones case LibFunc_setbuf: 731d21529faSDavid L. Jones case LibFunc_setvbuf: 732d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 733d21529faSDavid L. Jones case LibFunc_strdup: 734d21529faSDavid L. Jones case LibFunc_strndup: 735d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 736d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 737d21529faSDavid L. Jones case LibFunc_sscanf: 738d21529faSDavid L. Jones case LibFunc_stat: 739d21529faSDavid L. Jones case LibFunc_statvfs: 740d21529faSDavid L. Jones case LibFunc_siprintf: 741d21529faSDavid L. Jones case LibFunc_sprintf: 742d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 7430d7c3775SMartin Storsjo FTy.getParamType(1)->isPointerTy() && 7440d7c3775SMartin Storsjo FTy.getReturnType()->isIntegerTy(32)); 745d21529faSDavid L. Jones case LibFunc_snprintf: 746d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 7470d7c3775SMartin Storsjo FTy.getParamType(2)->isPointerTy() && 7480d7c3775SMartin Storsjo FTy.getReturnType()->isIntegerTy(32)); 749d21529faSDavid L. Jones case LibFunc_setitimer: 750d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 751d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 752d21529faSDavid L. Jones case LibFunc_system: 753d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 754d21529faSDavid L. Jones case LibFunc_malloc: 755d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 756d21529faSDavid L. Jones case LibFunc_memcmp: 7576b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 7586b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 7596b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 760d765a82bSAhmed Bougacha 761d21529faSDavid L. Jones case LibFunc_memchr: 762d21529faSDavid L. Jones case LibFunc_memrchr: 7636b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 7646b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 765d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32) && 7666b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 767d21529faSDavid L. Jones case LibFunc_modf: 768d21529faSDavid L. Jones case LibFunc_modff: 769d21529faSDavid L. Jones case LibFunc_modfl: 770d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 771d765a82bSAhmed Bougacha 772d21529faSDavid L. Jones case LibFunc_memcpy_chk: 773d21529faSDavid L. Jones case LibFunc_memmove_chk: 774d765a82bSAhmed Bougacha --NumParams; 775d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 776d765a82bSAhmed Bougacha return false; 777b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 778d21529faSDavid L. Jones case LibFunc_memcpy: 779d21529faSDavid L. Jones case LibFunc_mempcpy: 780d21529faSDavid L. Jones case LibFunc_memmove: 781d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 782d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 783d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 784d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 785d765a82bSAhmed Bougacha 786d21529faSDavid L. Jones case LibFunc_memset_chk: 787d765a82bSAhmed Bougacha --NumParams; 788d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 789d765a82bSAhmed Bougacha return false; 790b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 791d21529faSDavid L. Jones case LibFunc_memset: 792d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 793d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 794d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 795d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 796d765a82bSAhmed Bougacha 797d21529faSDavid L. Jones case LibFunc_memccpy: 798d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 799d21529faSDavid L. Jones case LibFunc_memalign: 800d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 801d21529faSDavid L. Jones case LibFunc_realloc: 802d21529faSDavid L. Jones case LibFunc_reallocf: 8036b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == PCharTy && 8046b9be1dbSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 8056b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(1))); 806d21529faSDavid L. Jones case LibFunc_read: 807d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 808d21529faSDavid L. Jones case LibFunc_rewind: 809d21529faSDavid L. Jones case LibFunc_rmdir: 810d21529faSDavid L. Jones case LibFunc_remove: 811d21529faSDavid L. Jones case LibFunc_realpath: 812d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 813d21529faSDavid L. Jones case LibFunc_rename: 814d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 815d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 816d21529faSDavid L. Jones case LibFunc_readlink: 817d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 818d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 819d21529faSDavid L. Jones case LibFunc_write: 820d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 821d21529faSDavid L. Jones case LibFunc_bcopy: 822d21529faSDavid L. Jones case LibFunc_bcmp: 823d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 824d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 825d21529faSDavid L. Jones case LibFunc_bzero: 826d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 827d21529faSDavid L. Jones case LibFunc_calloc: 828d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 8291fe3f1caSAhmed Bougacha 830d21529faSDavid L. Jones case LibFunc_atof: 831d21529faSDavid L. Jones case LibFunc_atoi: 832d21529faSDavid L. Jones case LibFunc_atol: 833d21529faSDavid L. Jones case LibFunc_atoll: 834d21529faSDavid L. Jones case LibFunc_ferror: 835d21529faSDavid L. Jones case LibFunc_getenv: 836d21529faSDavid L. Jones case LibFunc_getpwnam: 837d21529faSDavid L. Jones case LibFunc_iprintf: 838d21529faSDavid L. Jones case LibFunc_pclose: 839d21529faSDavid L. Jones case LibFunc_perror: 840d21529faSDavid L. Jones case LibFunc_printf: 841d21529faSDavid L. Jones case LibFunc_puts: 842d21529faSDavid L. Jones case LibFunc_uname: 843d21529faSDavid L. Jones case LibFunc_under_IO_getc: 844d21529faSDavid L. Jones case LibFunc_unlink: 845d21529faSDavid L. Jones case LibFunc_unsetenv: 846d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 8471fe3f1caSAhmed Bougacha 848d21529faSDavid L. Jones case LibFunc_access: 849d21529faSDavid L. Jones case LibFunc_chmod: 850d21529faSDavid L. Jones case LibFunc_chown: 851d21529faSDavid L. Jones case LibFunc_clearerr: 852d21529faSDavid L. Jones case LibFunc_closedir: 853d21529faSDavid L. Jones case LibFunc_ctermid: 854d21529faSDavid L. Jones case LibFunc_fclose: 855d21529faSDavid L. Jones case LibFunc_feof: 856d21529faSDavid L. Jones case LibFunc_fflush: 857d21529faSDavid L. Jones case LibFunc_fgetc: 858ca22d427SDavid Bolvansky case LibFunc_fgetc_unlocked: 859d21529faSDavid L. Jones case LibFunc_fileno: 860d21529faSDavid L. Jones case LibFunc_flockfile: 861d21529faSDavid L. Jones case LibFunc_free: 862d21529faSDavid L. Jones case LibFunc_fseek: 863d21529faSDavid L. Jones case LibFunc_fseeko64: 864d21529faSDavid L. Jones case LibFunc_fseeko: 865d21529faSDavid L. Jones case LibFunc_fsetpos: 866d21529faSDavid L. Jones case LibFunc_ftell: 867d21529faSDavid L. Jones case LibFunc_ftello64: 868d21529faSDavid L. Jones case LibFunc_ftello: 869d21529faSDavid L. Jones case LibFunc_ftrylockfile: 870d21529faSDavid L. Jones case LibFunc_funlockfile: 871d21529faSDavid L. Jones case LibFunc_getc: 872d21529faSDavid L. Jones case LibFunc_getc_unlocked: 873d21529faSDavid L. Jones case LibFunc_getlogin_r: 874d21529faSDavid L. Jones case LibFunc_mkdir: 875d21529faSDavid L. Jones case LibFunc_mktime: 876d21529faSDavid L. Jones case LibFunc_times: 8771fe3f1caSAhmed Bougacha return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); 8781fe3f1caSAhmed Bougacha 879d21529faSDavid L. Jones case LibFunc_fopen: 880d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 881d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 882d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 883c3bed1e8SCalixte Denizet case LibFunc_fork: 884c3bed1e8SCalixte Denizet return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32)); 885d21529faSDavid L. Jones case LibFunc_fdopen: 886d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 887d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 888d21529faSDavid L. Jones case LibFunc_fputc: 889ca22d427SDavid Bolvansky case LibFunc_fputc_unlocked: 890d21529faSDavid L. Jones case LibFunc_fstat: 891d21529faSDavid L. Jones case LibFunc_frexp: 892d21529faSDavid L. Jones case LibFunc_frexpf: 893d21529faSDavid L. Jones case LibFunc_frexpl: 894d21529faSDavid L. Jones case LibFunc_fstatvfs: 895d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 896d21529faSDavid L. Jones case LibFunc_fgets: 897ca22d427SDavid Bolvansky case LibFunc_fgets_unlocked: 898d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 899d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 900d21529faSDavid L. Jones case LibFunc_fread: 901ca22d427SDavid Bolvansky case LibFunc_fread_unlocked: 902d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 903d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 904d21529faSDavid L. Jones case LibFunc_fwrite: 905ca22d427SDavid Bolvansky case LibFunc_fwrite_unlocked: 906d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && 907d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 908d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 909d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy() && 910d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 911d21529faSDavid L. Jones case LibFunc_fputs: 912ca22d427SDavid Bolvansky case LibFunc_fputs_unlocked: 913d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 914d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 915d21529faSDavid L. Jones case LibFunc_fscanf: 916d21529faSDavid L. Jones case LibFunc_fiprintf: 917d21529faSDavid L. Jones case LibFunc_fprintf: 9186b9be1dbSAhmed Bougacha return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() && 9196b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 920d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 921d21529faSDavid L. Jones case LibFunc_fgetpos: 922d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 923d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 924d21529faSDavid L. Jones case LibFunc_getchar: 925ca22d427SDavid Bolvansky case LibFunc_getchar_unlocked: 9266b9be1dbSAhmed Bougacha return (NumParams == 0 && FTy.getReturnType()->isIntegerTy()); 927d21529faSDavid L. Jones case LibFunc_gets: 9286b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0) == PCharTy); 929d21529faSDavid L. Jones case LibFunc_getitimer: 930d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 931d21529faSDavid L. Jones case LibFunc_ungetc: 932d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 933d21529faSDavid L. Jones case LibFunc_utime: 934d21529faSDavid L. Jones case LibFunc_utimes: 935d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 936d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 937d21529faSDavid L. Jones case LibFunc_putc: 938ca22d427SDavid Bolvansky case LibFunc_putc_unlocked: 939d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 940d21529faSDavid L. Jones case LibFunc_pread: 941d21529faSDavid L. Jones case LibFunc_pwrite: 942d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); 943d21529faSDavid L. Jones case LibFunc_popen: 944d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 945d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 946d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 947d21529faSDavid L. Jones case LibFunc_vscanf: 948d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 949d21529faSDavid L. Jones case LibFunc_vsscanf: 950d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 951d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 952d21529faSDavid L. Jones case LibFunc_vfscanf: 953d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 954d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 955d21529faSDavid L. Jones case LibFunc_valloc: 956d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 957d21529faSDavid L. Jones case LibFunc_vprintf: 958d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 959d21529faSDavid L. Jones case LibFunc_vfprintf: 960d21529faSDavid L. Jones case LibFunc_vsprintf: 961d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 962d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 963d21529faSDavid L. Jones case LibFunc_vsnprintf: 964d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 965d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 966d21529faSDavid L. Jones case LibFunc_open: 967d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 968d21529faSDavid L. Jones case LibFunc_opendir: 969d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && 970d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 971d21529faSDavid L. Jones case LibFunc_tmpfile: 972d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 973d21529faSDavid L. Jones case LibFunc_htonl: 974d21529faSDavid L. Jones case LibFunc_ntohl: 9756b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 9766b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 977d21529faSDavid L. Jones case LibFunc_htons: 978d21529faSDavid L. Jones case LibFunc_ntohs: 9796b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) && 9806b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 981d21529faSDavid L. Jones case LibFunc_lstat: 982d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 983d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 984d21529faSDavid L. Jones case LibFunc_lchown: 985d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 986d21529faSDavid L. Jones case LibFunc_qsort: 987d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); 988d21529faSDavid L. Jones case LibFunc_dunder_strdup: 989d21529faSDavid L. Jones case LibFunc_dunder_strndup: 990d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 991d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 992d21529faSDavid L. Jones case LibFunc_dunder_strtok_r: 993d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 994d21529faSDavid L. Jones case LibFunc_under_IO_putc: 995d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 996d21529faSDavid L. Jones case LibFunc_dunder_isoc99_scanf: 997d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 998d21529faSDavid L. Jones case LibFunc_stat64: 999d21529faSDavid L. Jones case LibFunc_lstat64: 1000d21529faSDavid L. Jones case LibFunc_statvfs64: 100179dcc274SMichael Kuperstein return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1002d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1003d21529faSDavid L. Jones case LibFunc_dunder_isoc99_sscanf: 100479dcc274SMichael Kuperstein return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1005d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1006d21529faSDavid L. Jones case LibFunc_fopen64: 1007d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1008d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1009d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1010d21529faSDavid L. Jones case LibFunc_tmpfile64: 1011d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1012d21529faSDavid L. Jones case LibFunc_fstat64: 1013d21529faSDavid L. Jones case LibFunc_fstatvfs64: 1014d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1015d21529faSDavid L. Jones case LibFunc_open64: 1016d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1017d21529faSDavid L. Jones case LibFunc_gettimeofday: 1018d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1019d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1020d765a82bSAhmed Bougacha 10216b9be1dbSAhmed Bougacha // new(unsigned int); 1022d21529faSDavid L. Jones case LibFunc_Znwj: 10236b9be1dbSAhmed Bougacha // new(unsigned long); 1024d21529faSDavid L. Jones case LibFunc_Znwm: 10256b9be1dbSAhmed Bougacha // new[](unsigned int); 1026d21529faSDavid L. Jones case LibFunc_Znaj: 10276b9be1dbSAhmed Bougacha // new[](unsigned long); 1028d21529faSDavid L. Jones case LibFunc_Znam: 10296b9be1dbSAhmed Bougacha // new(unsigned int); 1030d21529faSDavid L. Jones case LibFunc_msvc_new_int: 10316b9be1dbSAhmed Bougacha // new(unsigned long long); 1032d21529faSDavid L. Jones case LibFunc_msvc_new_longlong: 10336b9be1dbSAhmed Bougacha // new[](unsigned int); 1034d21529faSDavid L. Jones case LibFunc_msvc_new_array_int: 10356b9be1dbSAhmed Bougacha // new[](unsigned long long); 1036d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong: 10376b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 10386b9be1dbSAhmed Bougacha 10396b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 1040d21529faSDavid L. Jones case LibFunc_ZnwjRKSt9nothrow_t: 10416b9be1dbSAhmed Bougacha // new(unsigned long, nothrow); 1042d21529faSDavid L. Jones case LibFunc_ZnwmRKSt9nothrow_t: 10436b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 1044d21529faSDavid L. Jones case LibFunc_ZnajRKSt9nothrow_t: 10456b9be1dbSAhmed Bougacha // new[](unsigned long, nothrow); 1046d21529faSDavid L. Jones case LibFunc_ZnamRKSt9nothrow_t: 10476b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 1048d21529faSDavid L. Jones case LibFunc_msvc_new_int_nothrow: 10496b9be1dbSAhmed Bougacha // new(unsigned long long, nothrow); 1050d21529faSDavid L. Jones case LibFunc_msvc_new_longlong_nothrow: 10516b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 1052d21529faSDavid L. Jones case LibFunc_msvc_new_array_int_nothrow: 10536b9be1dbSAhmed Bougacha // new[](unsigned long long, nothrow); 1054d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong_nothrow: 105596bbec79SEric Fiselier // new(unsigned int, align_val_t) 105696bbec79SEric Fiselier case LibFunc_ZnwjSt11align_val_t: 105796bbec79SEric Fiselier // new(unsigned long, align_val_t) 105896bbec79SEric Fiselier case LibFunc_ZnwmSt11align_val_t: 105996bbec79SEric Fiselier // new[](unsigned int, align_val_t) 106096bbec79SEric Fiselier case LibFunc_ZnajSt11align_val_t: 106196bbec79SEric Fiselier // new[](unsigned long, align_val_t) 106296bbec79SEric Fiselier case LibFunc_ZnamSt11align_val_t: 10636b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 10646b9be1dbSAhmed Bougacha 106596bbec79SEric Fiselier // new(unsigned int, align_val_t, nothrow) 106696bbec79SEric Fiselier case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: 106796bbec79SEric Fiselier // new(unsigned long, align_val_t, nothrow) 106896bbec79SEric Fiselier case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: 106996bbec79SEric Fiselier // new[](unsigned int, align_val_t, nothrow) 107096bbec79SEric Fiselier case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: 107196bbec79SEric Fiselier // new[](unsigned long, align_val_t, nothrow) 107296bbec79SEric Fiselier case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: 107396bbec79SEric Fiselier return (NumParams == 3 && FTy.getReturnType()->isPointerTy()); 107496bbec79SEric Fiselier 10756b9be1dbSAhmed Bougacha // void operator delete[](void*); 1076d21529faSDavid L. Jones case LibFunc_ZdaPv: 10776b9be1dbSAhmed Bougacha // void operator delete(void*); 1078d21529faSDavid L. Jones case LibFunc_ZdlPv: 10796b9be1dbSAhmed Bougacha // void operator delete[](void*); 1080d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32: 10816b9be1dbSAhmed Bougacha // void operator delete[](void*); 1082d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64: 10836b9be1dbSAhmed Bougacha // void operator delete(void*); 1084d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32: 10856b9be1dbSAhmed Bougacha // void operator delete(void*); 1086d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64: 10876b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 10886b9be1dbSAhmed Bougacha 10896b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1090d21529faSDavid L. Jones case LibFunc_ZdaPvRKSt9nothrow_t: 10916b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1092d21529faSDavid L. Jones case LibFunc_ZdaPvj: 10936b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long); 1094d21529faSDavid L. Jones case LibFunc_ZdaPvm: 10956b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1096d21529faSDavid L. Jones case LibFunc_ZdlPvRKSt9nothrow_t: 10976b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1098d21529faSDavid L. Jones case LibFunc_ZdlPvj: 10996b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long); 1100d21529faSDavid L. Jones case LibFunc_ZdlPvm: 110196bbec79SEric Fiselier // void operator delete(void*, align_val_t) 110296bbec79SEric Fiselier case LibFunc_ZdlPvSt11align_val_t: 110396bbec79SEric Fiselier // void operator delete[](void*, align_val_t) 110496bbec79SEric Fiselier case LibFunc_ZdaPvSt11align_val_t: 11056b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1106d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_int: 11076b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1108d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_nothrow: 11096b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long long); 1110d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_longlong: 11116b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1112d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_nothrow: 11136b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1114d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_int: 11156b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1116d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_nothrow: 11176b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long long); 1118d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_longlong: 11196b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1120d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_nothrow: 11216b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1122d765a82bSAhmed Bougacha 112396bbec79SEric Fiselier // void operator delete(void*, align_val_t, nothrow) 112496bbec79SEric Fiselier case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t: 112596bbec79SEric Fiselier // void operator delete[](void*, align_val_t, nothrow) 112696bbec79SEric Fiselier case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t: 112796bbec79SEric Fiselier return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 112896bbec79SEric Fiselier 1129d21529faSDavid L. Jones case LibFunc_memset_pattern16: 1130d765a82bSAhmed Bougacha return (!FTy.isVarArg() && NumParams == 3 && 11316b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 11326b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 11336b9be1dbSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 1134d765a82bSAhmed Bougacha 1135d21529faSDavid L. Jones case LibFunc_cxa_guard_abort: 1136d21529faSDavid L. Jones case LibFunc_cxa_guard_acquire: 1137d21529faSDavid L. Jones case LibFunc_cxa_guard_release: 1138d21529faSDavid L. Jones case LibFunc_nvvm_reflect: 11396b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1140d765a82bSAhmed Bougacha 1141d21529faSDavid L. Jones case LibFunc_sincospi_stret: 1142d21529faSDavid L. Jones case LibFunc_sincospif_stret: 11436b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy()); 11446b9be1dbSAhmed Bougacha 1145d21529faSDavid L. Jones case LibFunc_acos: 11463cd8c16dSAndrew Kaylor case LibFunc_acos_finite: 1147d21529faSDavid L. Jones case LibFunc_acosf: 11483cd8c16dSAndrew Kaylor case LibFunc_acosf_finite: 1149d21529faSDavid L. Jones case LibFunc_acosh: 11503cd8c16dSAndrew Kaylor case LibFunc_acosh_finite: 1151d21529faSDavid L. Jones case LibFunc_acoshf: 11523cd8c16dSAndrew Kaylor case LibFunc_acoshf_finite: 1153d21529faSDavid L. Jones case LibFunc_acoshl: 11543cd8c16dSAndrew Kaylor case LibFunc_acoshl_finite: 1155d21529faSDavid L. Jones case LibFunc_acosl: 11563cd8c16dSAndrew Kaylor case LibFunc_acosl_finite: 1157d21529faSDavid L. Jones case LibFunc_asin: 11583cd8c16dSAndrew Kaylor case LibFunc_asin_finite: 1159d21529faSDavid L. Jones case LibFunc_asinf: 11603cd8c16dSAndrew Kaylor case LibFunc_asinf_finite: 1161d21529faSDavid L. Jones case LibFunc_asinh: 1162d21529faSDavid L. Jones case LibFunc_asinhf: 1163d21529faSDavid L. Jones case LibFunc_asinhl: 1164d21529faSDavid L. Jones case LibFunc_asinl: 11653cd8c16dSAndrew Kaylor case LibFunc_asinl_finite: 1166d21529faSDavid L. Jones case LibFunc_atan: 1167d21529faSDavid L. Jones case LibFunc_atanf: 1168d21529faSDavid L. Jones case LibFunc_atanh: 11693cd8c16dSAndrew Kaylor case LibFunc_atanh_finite: 1170d21529faSDavid L. Jones case LibFunc_atanhf: 11713cd8c16dSAndrew Kaylor case LibFunc_atanhf_finite: 1172d21529faSDavid L. Jones case LibFunc_atanhl: 11733cd8c16dSAndrew Kaylor case LibFunc_atanhl_finite: 1174d21529faSDavid L. Jones case LibFunc_atanl: 1175d21529faSDavid L. Jones case LibFunc_cbrt: 1176d21529faSDavid L. Jones case LibFunc_cbrtf: 1177d21529faSDavid L. Jones case LibFunc_cbrtl: 1178d21529faSDavid L. Jones case LibFunc_ceil: 1179d21529faSDavid L. Jones case LibFunc_ceilf: 1180d21529faSDavid L. Jones case LibFunc_ceill: 1181d21529faSDavid L. Jones case LibFunc_cos: 1182d21529faSDavid L. Jones case LibFunc_cosf: 1183d21529faSDavid L. Jones case LibFunc_cosh: 11843cd8c16dSAndrew Kaylor case LibFunc_cosh_finite: 1185d21529faSDavid L. Jones case LibFunc_coshf: 11863cd8c16dSAndrew Kaylor case LibFunc_coshf_finite: 1187d21529faSDavid L. Jones case LibFunc_coshl: 11883cd8c16dSAndrew Kaylor case LibFunc_coshl_finite: 1189d21529faSDavid L. Jones case LibFunc_cosl: 1190d21529faSDavid L. Jones case LibFunc_exp10: 11913cd8c16dSAndrew Kaylor case LibFunc_exp10_finite: 1192d21529faSDavid L. Jones case LibFunc_exp10f: 11933cd8c16dSAndrew Kaylor case LibFunc_exp10f_finite: 1194d21529faSDavid L. Jones case LibFunc_exp10l: 11953cd8c16dSAndrew Kaylor case LibFunc_exp10l_finite: 1196d21529faSDavid L. Jones case LibFunc_exp2: 11973cd8c16dSAndrew Kaylor case LibFunc_exp2_finite: 1198d21529faSDavid L. Jones case LibFunc_exp2f: 11993cd8c16dSAndrew Kaylor case LibFunc_exp2f_finite: 1200d21529faSDavid L. Jones case LibFunc_exp2l: 12013cd8c16dSAndrew Kaylor case LibFunc_exp2l_finite: 1202d21529faSDavid L. Jones case LibFunc_exp: 12033cd8c16dSAndrew Kaylor case LibFunc_exp_finite: 1204d21529faSDavid L. Jones case LibFunc_expf: 12053cd8c16dSAndrew Kaylor case LibFunc_expf_finite: 1206d21529faSDavid L. Jones case LibFunc_expl: 12073cd8c16dSAndrew Kaylor case LibFunc_expl_finite: 1208d21529faSDavid L. Jones case LibFunc_expm1: 1209d21529faSDavid L. Jones case LibFunc_expm1f: 1210d21529faSDavid L. Jones case LibFunc_expm1l: 1211d21529faSDavid L. Jones case LibFunc_fabs: 1212d21529faSDavid L. Jones case LibFunc_fabsf: 1213d21529faSDavid L. Jones case LibFunc_fabsl: 1214d21529faSDavid L. Jones case LibFunc_floor: 1215d21529faSDavid L. Jones case LibFunc_floorf: 1216d21529faSDavid L. Jones case LibFunc_floorl: 1217d21529faSDavid L. Jones case LibFunc_log10: 12183cd8c16dSAndrew Kaylor case LibFunc_log10_finite: 1219d21529faSDavid L. Jones case LibFunc_log10f: 12203cd8c16dSAndrew Kaylor case LibFunc_log10f_finite: 1221d21529faSDavid L. Jones case LibFunc_log10l: 12223cd8c16dSAndrew Kaylor case LibFunc_log10l_finite: 1223d21529faSDavid L. Jones case LibFunc_log1p: 1224d21529faSDavid L. Jones case LibFunc_log1pf: 1225d21529faSDavid L. Jones case LibFunc_log1pl: 1226d21529faSDavid L. Jones case LibFunc_log2: 12273cd8c16dSAndrew Kaylor case LibFunc_log2_finite: 1228d21529faSDavid L. Jones case LibFunc_log2f: 12293cd8c16dSAndrew Kaylor case LibFunc_log2f_finite: 1230d21529faSDavid L. Jones case LibFunc_log2l: 12313cd8c16dSAndrew Kaylor case LibFunc_log2l_finite: 1232d21529faSDavid L. Jones case LibFunc_log: 12333cd8c16dSAndrew Kaylor case LibFunc_log_finite: 1234d21529faSDavid L. Jones case LibFunc_logb: 1235d21529faSDavid L. Jones case LibFunc_logbf: 1236d21529faSDavid L. Jones case LibFunc_logbl: 1237d21529faSDavid L. Jones case LibFunc_logf: 12383cd8c16dSAndrew Kaylor case LibFunc_logf_finite: 1239d21529faSDavid L. Jones case LibFunc_logl: 12403cd8c16dSAndrew Kaylor case LibFunc_logl_finite: 1241d21529faSDavid L. Jones case LibFunc_nearbyint: 1242d21529faSDavid L. Jones case LibFunc_nearbyintf: 1243d21529faSDavid L. Jones case LibFunc_nearbyintl: 1244d21529faSDavid L. Jones case LibFunc_rint: 1245d21529faSDavid L. Jones case LibFunc_rintf: 1246d21529faSDavid L. Jones case LibFunc_rintl: 1247d21529faSDavid L. Jones case LibFunc_round: 1248d21529faSDavid L. Jones case LibFunc_roundf: 1249d21529faSDavid L. Jones case LibFunc_roundl: 1250d21529faSDavid L. Jones case LibFunc_sin: 1251d21529faSDavid L. Jones case LibFunc_sinf: 1252d21529faSDavid L. Jones case LibFunc_sinh: 12533cd8c16dSAndrew Kaylor case LibFunc_sinh_finite: 1254d21529faSDavid L. Jones case LibFunc_sinhf: 12553cd8c16dSAndrew Kaylor case LibFunc_sinhf_finite: 1256d21529faSDavid L. Jones case LibFunc_sinhl: 12573cd8c16dSAndrew Kaylor case LibFunc_sinhl_finite: 1258d21529faSDavid L. Jones case LibFunc_sinl: 1259d21529faSDavid L. Jones case LibFunc_sqrt: 1260d21529faSDavid L. Jones case LibFunc_sqrt_finite: 1261d21529faSDavid L. Jones case LibFunc_sqrtf: 1262d21529faSDavid L. Jones case LibFunc_sqrtf_finite: 1263d21529faSDavid L. Jones case LibFunc_sqrtl: 1264d21529faSDavid L. Jones case LibFunc_sqrtl_finite: 1265d21529faSDavid L. Jones case LibFunc_tan: 1266d21529faSDavid L. Jones case LibFunc_tanf: 1267d21529faSDavid L. Jones case LibFunc_tanh: 1268d21529faSDavid L. Jones case LibFunc_tanhf: 1269d21529faSDavid L. Jones case LibFunc_tanhl: 1270d21529faSDavid L. Jones case LibFunc_tanl: 1271d21529faSDavid L. Jones case LibFunc_trunc: 1272d21529faSDavid L. Jones case LibFunc_truncf: 1273d21529faSDavid L. Jones case LibFunc_truncl: 1274d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && 1275d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1276d765a82bSAhmed Bougacha 1277d21529faSDavid L. Jones case LibFunc_atan2: 12783cd8c16dSAndrew Kaylor case LibFunc_atan2_finite: 1279d21529faSDavid L. Jones case LibFunc_atan2f: 12803cd8c16dSAndrew Kaylor case LibFunc_atan2f_finite: 1281d21529faSDavid L. Jones case LibFunc_atan2l: 12823cd8c16dSAndrew Kaylor case LibFunc_atan2l_finite: 1283d21529faSDavid L. Jones case LibFunc_fmin: 1284d21529faSDavid L. Jones case LibFunc_fminf: 1285d21529faSDavid L. Jones case LibFunc_fminl: 1286d21529faSDavid L. Jones case LibFunc_fmax: 1287d21529faSDavid L. Jones case LibFunc_fmaxf: 1288d21529faSDavid L. Jones case LibFunc_fmaxl: 1289d21529faSDavid L. Jones case LibFunc_fmod: 1290d21529faSDavid L. Jones case LibFunc_fmodf: 1291d21529faSDavid L. Jones case LibFunc_fmodl: 1292d21529faSDavid L. Jones case LibFunc_copysign: 1293d21529faSDavid L. Jones case LibFunc_copysignf: 1294d21529faSDavid L. Jones case LibFunc_copysignl: 1295d21529faSDavid L. Jones case LibFunc_pow: 12963cd8c16dSAndrew Kaylor case LibFunc_pow_finite: 1297d21529faSDavid L. Jones case LibFunc_powf: 12983cd8c16dSAndrew Kaylor case LibFunc_powf_finite: 1299d21529faSDavid L. Jones case LibFunc_powl: 13003cd8c16dSAndrew Kaylor case LibFunc_powl_finite: 1301d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 1302d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 1303d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(1)); 1304d765a82bSAhmed Bougacha 1305d21529faSDavid L. Jones case LibFunc_ldexp: 1306d21529faSDavid L. Jones case LibFunc_ldexpf: 1307d21529faSDavid L. Jones case LibFunc_ldexpl: 13086b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 13096b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 13106b9be1dbSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32)); 13116b9be1dbSAhmed Bougacha 1312d21529faSDavid L. Jones case LibFunc_ffs: 1313d21529faSDavid L. Jones case LibFunc_ffsl: 1314d21529faSDavid L. Jones case LibFunc_ffsll: 1315d21529faSDavid L. Jones case LibFunc_fls: 1316d21529faSDavid L. Jones case LibFunc_flsl: 1317d21529faSDavid L. Jones case LibFunc_flsll: 131804949fafSSanjay Patel return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 131904949fafSSanjay Patel FTy.getParamType(0)->isIntegerTy()); 132004949fafSSanjay Patel 1321d21529faSDavid L. Jones case LibFunc_isdigit: 1322d21529faSDavid L. Jones case LibFunc_isascii: 1323d21529faSDavid L. Jones case LibFunc_toascii: 1324d21529faSDavid L. Jones case LibFunc_putchar: 1325ca22d427SDavid Bolvansky case LibFunc_putchar_unlocked: 1326d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 132704949fafSSanjay Patel FTy.getReturnType() == FTy.getParamType(0)); 1328d765a82bSAhmed Bougacha 1329d21529faSDavid L. Jones case LibFunc_abs: 1330d21529faSDavid L. Jones case LibFunc_labs: 1331d21529faSDavid L. Jones case LibFunc_llabs: 1332d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && 1333d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1334d765a82bSAhmed Bougacha 1335d21529faSDavid L. Jones case LibFunc_cxa_atexit: 1336d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && 1337d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1338d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 1339d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1340d765a82bSAhmed Bougacha 1341d21529faSDavid L. Jones case LibFunc_sinpi: 1342d21529faSDavid L. Jones case LibFunc_cospi: 1343d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && 1344d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1345d765a82bSAhmed Bougacha 1346d21529faSDavid L. Jones case LibFunc_sinpif: 1347d21529faSDavid L. Jones case LibFunc_cospif: 1348d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && 1349d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1350d765a82bSAhmed Bougacha 1351d21529faSDavid L. Jones case LibFunc_strnlen: 13526b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) && 13536b9be1dbSAhmed Bougacha FTy.getParamType(0) == PCharTy && 13546b9be1dbSAhmed Bougacha FTy.getParamType(1) == SizeTTy); 13556b9be1dbSAhmed Bougacha 1356d21529faSDavid L. Jones case LibFunc_posix_memalign: 13576b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 13586b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 13596b9be1dbSAhmed Bougacha FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy); 13606b9be1dbSAhmed Bougacha 136160b40b8fSMatthias Braun case LibFunc_wcslen: 136260b40b8fSMatthias Braun return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 136360b40b8fSMatthias Braun FTy.getReturnType()->isIntegerTy()); 136460b40b8fSMatthias Braun 13652ff24731SHal Finkel case LibFunc_cabs: 13662ff24731SHal Finkel case LibFunc_cabsf: 13672ff24731SHal Finkel case LibFunc_cabsl: { 13682ff24731SHal Finkel Type* RetTy = FTy.getReturnType(); 13692ff24731SHal Finkel if (!RetTy->isFloatingPointTy()) 13702ff24731SHal Finkel return false; 13712ff24731SHal Finkel 13722ff24731SHal Finkel // NOTE: These prototypes are target specific and currently support 13732ff24731SHal Finkel // "complex" passed as an array or discrete real & imaginary parameters. 13742ff24731SHal Finkel // Add other calling conventions to enable libcall optimizations. 13752ff24731SHal Finkel if (NumParams == 1) 13762ff24731SHal Finkel return (FTy.getParamType(0)->isArrayTy() && 13772ff24731SHal Finkel FTy.getParamType(0)->getArrayNumElements() == 2 && 13782ff24731SHal Finkel FTy.getParamType(0)->getArrayElementType() == RetTy); 13792ff24731SHal Finkel else if (NumParams == 2) 13802ff24731SHal Finkel return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy); 13812ff24731SHal Finkel else 13822ff24731SHal Finkel return false; 13832ff24731SHal Finkel } 13846b9be1dbSAhmed Bougacha case LibFunc::NumLibFuncs: 138586b680a3SAhmed Bougacha break; 1386d765a82bSAhmed Bougacha } 13876b9be1dbSAhmed Bougacha 138886b680a3SAhmed Bougacha llvm_unreachable("Invalid libfunc"); 1389d765a82bSAhmed Bougacha } 1390d765a82bSAhmed Bougacha 1391d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 1392d21529faSDavid L. Jones LibFunc &F) const { 1393d765a82bSAhmed Bougacha const DataLayout *DL = 1394d765a82bSAhmed Bougacha FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; 1395d765a82bSAhmed Bougacha return getLibFunc(FDecl.getName(), F) && 1396d765a82bSAhmed Bougacha isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); 1397d765a82bSAhmed Bougacha } 1398d765a82bSAhmed Bougacha 1399c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() { 140062d4215bSChandler Carruth memset(AvailableArray, 0, sizeof(AvailableArray)); 140162d4215bSChandler Carruth } 1402b98f63dbSChandler Carruth 1403e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { 14049a72cd7bSMehdi Amini return LHS.ScalarFnName < RHS.ScalarFnName; 1405e8f2551fSMichael Zolotukhin } 1406e8f2551fSMichael Zolotukhin 1407e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { 14089a72cd7bSMehdi Amini return LHS.VectorFnName < RHS.VectorFnName; 1409e8f2551fSMichael Zolotukhin } 1410e8f2551fSMichael Zolotukhin 1411e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { 14129a72cd7bSMehdi Amini return LHS.ScalarFnName < S; 1413e8f2551fSMichael Zolotukhin } 1414e8f2551fSMichael Zolotukhin 1415e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { 14169a72cd7bSMehdi Amini return LHS.VectorFnName < S; 1417e8f2551fSMichael Zolotukhin } 1418e8f2551fSMichael Zolotukhin 1419e8f2551fSMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { 1420e8f2551fSMichael Zolotukhin VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end()); 14210cac726aSFangrui Song llvm::sort(VectorDescs, compareByScalarFnName); 1422e8f2551fSMichael Zolotukhin 1423e8f2551fSMichael Zolotukhin ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end()); 14240cac726aSFangrui Song llvm::sort(ScalarDescs, compareByVectorFnName); 1425e8f2551fSMichael Zolotukhin } 1426e8f2551fSMichael Zolotukhin 14276d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( 14286d8a2aa9SMichael Zolotukhin enum VectorLibrary VecLib) { 14296d8a2aa9SMichael Zolotukhin switch (VecLib) { 14306d8a2aa9SMichael Zolotukhin case Accelerate: { 14316d8a2aa9SMichael Zolotukhin const VecDesc VecFuncs[] = { 1432de63aaceSMichael Zolotukhin // Floating-Point Arithmetic and Auxiliary Functions 1433de63aaceSMichael Zolotukhin {"ceilf", "vceilf", 4}, 14346d8a2aa9SMichael Zolotukhin {"fabsf", "vfabsf", 4}, 14356d8a2aa9SMichael Zolotukhin {"llvm.fabs.f32", "vfabsf", 4}, 1436de63aaceSMichael Zolotukhin {"floorf", "vfloorf", 4}, 1437de63aaceSMichael Zolotukhin {"sqrtf", "vsqrtf", 4}, 1438de63aaceSMichael Zolotukhin {"llvm.sqrt.f32", "vsqrtf", 4}, 1439de63aaceSMichael Zolotukhin 1440de63aaceSMichael Zolotukhin // Exponential and Logarithmic Functions 1441de63aaceSMichael Zolotukhin {"expf", "vexpf", 4}, 1442de63aaceSMichael Zolotukhin {"llvm.exp.f32", "vexpf", 4}, 1443de63aaceSMichael Zolotukhin {"expm1f", "vexpm1f", 4}, 1444de63aaceSMichael Zolotukhin {"logf", "vlogf", 4}, 1445de63aaceSMichael Zolotukhin {"llvm.log.f32", "vlogf", 4}, 1446de63aaceSMichael Zolotukhin {"log1pf", "vlog1pf", 4}, 1447de63aaceSMichael Zolotukhin {"log10f", "vlog10f", 4}, 1448de63aaceSMichael Zolotukhin {"llvm.log10.f32", "vlog10f", 4}, 1449de63aaceSMichael Zolotukhin {"logbf", "vlogbf", 4}, 1450de63aaceSMichael Zolotukhin 1451de63aaceSMichael Zolotukhin // Trigonometric Functions 1452de63aaceSMichael Zolotukhin {"sinf", "vsinf", 4}, 1453de63aaceSMichael Zolotukhin {"llvm.sin.f32", "vsinf", 4}, 1454de63aaceSMichael Zolotukhin {"cosf", "vcosf", 4}, 1455de63aaceSMichael Zolotukhin {"llvm.cos.f32", "vcosf", 4}, 1456de63aaceSMichael Zolotukhin {"tanf", "vtanf", 4}, 1457de63aaceSMichael Zolotukhin {"asinf", "vasinf", 4}, 1458de63aaceSMichael Zolotukhin {"acosf", "vacosf", 4}, 1459de63aaceSMichael Zolotukhin {"atanf", "vatanf", 4}, 1460de63aaceSMichael Zolotukhin 1461de63aaceSMichael Zolotukhin // Hyperbolic Functions 1462de63aaceSMichael Zolotukhin {"sinhf", "vsinhf", 4}, 1463de63aaceSMichael Zolotukhin {"coshf", "vcoshf", 4}, 1464de63aaceSMichael Zolotukhin {"tanhf", "vtanhf", 4}, 1465de63aaceSMichael Zolotukhin {"asinhf", "vasinhf", 4}, 1466de63aaceSMichael Zolotukhin {"acoshf", "vacoshf", 4}, 1467de63aaceSMichael Zolotukhin {"atanhf", "vatanhf", 4}, 14686d8a2aa9SMichael Zolotukhin }; 14696d8a2aa9SMichael Zolotukhin addVectorizableFunctions(VecFuncs); 14706d8a2aa9SMichael Zolotukhin break; 14716d8a2aa9SMichael Zolotukhin } 1472a6669a1eSMatt Masten case SVML: { 1473a6669a1eSMatt Masten const VecDesc VecFuncs[] = { 1474a6669a1eSMatt Masten {"sin", "__svml_sin2", 2}, 1475a6669a1eSMatt Masten {"sin", "__svml_sin4", 4}, 1476a6669a1eSMatt Masten {"sin", "__svml_sin8", 8}, 1477a6669a1eSMatt Masten 1478a6669a1eSMatt Masten {"sinf", "__svml_sinf4", 4}, 1479a6669a1eSMatt Masten {"sinf", "__svml_sinf8", 8}, 1480a6669a1eSMatt Masten {"sinf", "__svml_sinf16", 16}, 1481a6669a1eSMatt Masten 14824b1205b4SSanjay Patel {"llvm.sin.f64", "__svml_sin2", 2}, 14834b1205b4SSanjay Patel {"llvm.sin.f64", "__svml_sin4", 4}, 14844b1205b4SSanjay Patel {"llvm.sin.f64", "__svml_sin8", 8}, 14854b1205b4SSanjay Patel 14864b1205b4SSanjay Patel {"llvm.sin.f32", "__svml_sinf4", 4}, 14874b1205b4SSanjay Patel {"llvm.sin.f32", "__svml_sinf8", 8}, 14884b1205b4SSanjay Patel {"llvm.sin.f32", "__svml_sinf16", 16}, 14894b1205b4SSanjay Patel 1490a6669a1eSMatt Masten {"cos", "__svml_cos2", 2}, 1491a6669a1eSMatt Masten {"cos", "__svml_cos4", 4}, 1492a6669a1eSMatt Masten {"cos", "__svml_cos8", 8}, 1493a6669a1eSMatt Masten 1494a6669a1eSMatt Masten {"cosf", "__svml_cosf4", 4}, 1495a6669a1eSMatt Masten {"cosf", "__svml_cosf8", 8}, 1496a6669a1eSMatt Masten {"cosf", "__svml_cosf16", 16}, 1497a6669a1eSMatt Masten 14984b1205b4SSanjay Patel {"llvm.cos.f64", "__svml_cos2", 2}, 14994b1205b4SSanjay Patel {"llvm.cos.f64", "__svml_cos4", 4}, 15004b1205b4SSanjay Patel {"llvm.cos.f64", "__svml_cos8", 8}, 15014b1205b4SSanjay Patel 15024b1205b4SSanjay Patel {"llvm.cos.f32", "__svml_cosf4", 4}, 15034b1205b4SSanjay Patel {"llvm.cos.f32", "__svml_cosf8", 8}, 15044b1205b4SSanjay Patel {"llvm.cos.f32", "__svml_cosf16", 16}, 15054b1205b4SSanjay Patel 1506a6669a1eSMatt Masten {"pow", "__svml_pow2", 2}, 1507a6669a1eSMatt Masten {"pow", "__svml_pow4", 4}, 1508a6669a1eSMatt Masten {"pow", "__svml_pow8", 8}, 1509a6669a1eSMatt Masten 1510a6669a1eSMatt Masten {"powf", "__svml_powf4", 4}, 1511a6669a1eSMatt Masten {"powf", "__svml_powf8", 8}, 1512a6669a1eSMatt Masten {"powf", "__svml_powf16", 16}, 1513a6669a1eSMatt Masten 1514b01e94eeSAndrew Kaylor { "__pow_finite", "__svml_pow2", 2 }, 1515b01e94eeSAndrew Kaylor { "__pow_finite", "__svml_pow4", 4 }, 1516b01e94eeSAndrew Kaylor { "__pow_finite", "__svml_pow8", 8 }, 1517b01e94eeSAndrew Kaylor 1518b01e94eeSAndrew Kaylor { "__powf_finite", "__svml_powf4", 4 }, 1519b01e94eeSAndrew Kaylor { "__powf_finite", "__svml_powf8", 8 }, 1520b01e94eeSAndrew Kaylor { "__powf_finite", "__svml_powf16", 16 }, 1521b01e94eeSAndrew Kaylor 1522a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow2", 2}, 1523a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow4", 4}, 1524a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow8", 8}, 1525a6669a1eSMatt Masten 1526a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf4", 4}, 1527a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf8", 8}, 1528a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf16", 16}, 1529a6669a1eSMatt Masten 1530a6669a1eSMatt Masten {"exp", "__svml_exp2", 2}, 1531a6669a1eSMatt Masten {"exp", "__svml_exp4", 4}, 1532a6669a1eSMatt Masten {"exp", "__svml_exp8", 8}, 1533a6669a1eSMatt Masten 1534a6669a1eSMatt Masten {"expf", "__svml_expf4", 4}, 1535a6669a1eSMatt Masten {"expf", "__svml_expf8", 8}, 1536a6669a1eSMatt Masten {"expf", "__svml_expf16", 16}, 1537a6669a1eSMatt Masten 1538b01e94eeSAndrew Kaylor { "__exp_finite", "__svml_exp2", 2 }, 1539b01e94eeSAndrew Kaylor { "__exp_finite", "__svml_exp4", 4 }, 1540b01e94eeSAndrew Kaylor { "__exp_finite", "__svml_exp8", 8 }, 1541b01e94eeSAndrew Kaylor 1542b01e94eeSAndrew Kaylor { "__expf_finite", "__svml_expf4", 4 }, 1543b01e94eeSAndrew Kaylor { "__expf_finite", "__svml_expf8", 8 }, 1544b01e94eeSAndrew Kaylor { "__expf_finite", "__svml_expf16", 16 }, 1545b01e94eeSAndrew Kaylor 1546a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp2", 2}, 1547a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp4", 4}, 1548a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp8", 8}, 1549a6669a1eSMatt Masten 1550a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf4", 4}, 1551a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf8", 8}, 1552a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf16", 16}, 1553a6669a1eSMatt Masten 1554a6669a1eSMatt Masten {"log", "__svml_log2", 2}, 1555a6669a1eSMatt Masten {"log", "__svml_log4", 4}, 1556a6669a1eSMatt Masten {"log", "__svml_log8", 8}, 1557a6669a1eSMatt Masten 1558a6669a1eSMatt Masten {"logf", "__svml_logf4", 4}, 1559a6669a1eSMatt Masten {"logf", "__svml_logf8", 8}, 1560a6669a1eSMatt Masten {"logf", "__svml_logf16", 16}, 1561a6669a1eSMatt Masten 1562b01e94eeSAndrew Kaylor { "__log_finite", "__svml_log2", 2 }, 1563b01e94eeSAndrew Kaylor { "__log_finite", "__svml_log4", 4 }, 1564b01e94eeSAndrew Kaylor { "__log_finite", "__svml_log8", 8 }, 1565b01e94eeSAndrew Kaylor 1566b01e94eeSAndrew Kaylor { "__logf_finite", "__svml_logf4", 4 }, 1567b01e94eeSAndrew Kaylor { "__logf_finite", "__svml_logf8", 8 }, 1568b01e94eeSAndrew Kaylor { "__logf_finite", "__svml_logf16", 16 }, 1569b01e94eeSAndrew Kaylor 1570a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log2", 2}, 1571a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log4", 4}, 1572a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log8", 8}, 1573a6669a1eSMatt Masten 1574a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf4", 4}, 1575a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf8", 8}, 1576a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf16", 16}, 1577a6669a1eSMatt Masten }; 1578a6669a1eSMatt Masten addVectorizableFunctions(VecFuncs); 1579a6669a1eSMatt Masten break; 1580a6669a1eSMatt Masten } 15816d8a2aa9SMichael Zolotukhin case NoLibrary: 15826d8a2aa9SMichael Zolotukhin break; 15836d8a2aa9SMichael Zolotukhin } 15846d8a2aa9SMichael Zolotukhin } 15856d8a2aa9SMichael Zolotukhin 1586e8f2551fSMichael Zolotukhin bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { 1587e8f2551fSMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 1588e8f2551fSMichael Zolotukhin if (funcName.empty()) 1589e8f2551fSMichael Zolotukhin return false; 1590e8f2551fSMichael Zolotukhin 1591e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1592e8f2551fSMichael Zolotukhin VectorDescs.begin(), VectorDescs.end(), funcName, 1593e8f2551fSMichael Zolotukhin compareWithScalarFnName); 1594e8f2551fSMichael Zolotukhin return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; 1595e8f2551fSMichael Zolotukhin } 1596e8f2551fSMichael Zolotukhin 1597e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, 1598e8f2551fSMichael Zolotukhin unsigned VF) const { 1599e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1600e8f2551fSMichael Zolotukhin if (F.empty()) 1601e8f2551fSMichael Zolotukhin return F; 1602e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1603e8f2551fSMichael Zolotukhin VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName); 1604e8f2551fSMichael Zolotukhin while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { 1605e8f2551fSMichael Zolotukhin if (I->VectorizationFactor == VF) 1606e8f2551fSMichael Zolotukhin return I->VectorFnName; 1607e8f2551fSMichael Zolotukhin ++I; 1608e8f2551fSMichael Zolotukhin } 1609e8f2551fSMichael Zolotukhin return StringRef(); 1610e8f2551fSMichael Zolotukhin } 1611e8f2551fSMichael Zolotukhin 1612e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F, 1613e8f2551fSMichael Zolotukhin unsigned &VF) const { 1614e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1615e8f2551fSMichael Zolotukhin if (F.empty()) 1616e8f2551fSMichael Zolotukhin return F; 1617e8f2551fSMichael Zolotukhin 1618e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1619e8f2551fSMichael Zolotukhin ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName); 1620e8f2551fSMichael Zolotukhin if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F) 1621e8f2551fSMichael Zolotukhin return StringRef(); 1622e8f2551fSMichael Zolotukhin VF = I->VectorizationFactor; 1623e8f2551fSMichael Zolotukhin return I->ScalarFnName; 1624e8f2551fSMichael Zolotukhin } 1625e8f2551fSMichael Zolotukhin 1626164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Module &M, 1627164a2aa6SChandler Carruth ModuleAnalysisManager &) { 1628c0291865SChandler Carruth if (PresetInfoImpl) 1629c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1630c0291865SChandler Carruth 1631c0291865SChandler Carruth return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple()))); 1632c0291865SChandler Carruth } 1633c0291865SChandler Carruth 1634164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Function &F, 1635164a2aa6SChandler Carruth FunctionAnalysisManager &) { 1636c0291865SChandler Carruth if (PresetInfoImpl) 1637c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1638c0291865SChandler Carruth 1639c0291865SChandler Carruth return TargetLibraryInfo( 1640c0291865SChandler Carruth lookupInfoImpl(Triple(F.getParent()->getTargetTriple()))); 1641c0291865SChandler Carruth } 1642c0291865SChandler Carruth 1643c321e534SBenjamin Kramer TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) { 1644c0291865SChandler Carruth std::unique_ptr<TargetLibraryInfoImpl> &Impl = 1645c0291865SChandler Carruth Impls[T.normalize()]; 1646c0291865SChandler Carruth if (!Impl) 1647c0291865SChandler Carruth Impl.reset(new TargetLibraryInfoImpl(T)); 1648c0291865SChandler Carruth 1649c0291865SChandler Carruth return *Impl; 1650c0291865SChandler Carruth } 1651c0291865SChandler Carruth 165250ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const { 165350ec0b5dSMatthias Braun if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>( 165450ec0b5dSMatthias Braun M.getModuleFlag("wchar_size"))) 165550ec0b5dSMatthias Braun return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue(); 1656cc603ee3SMatthias Braun return 0; 165750ec0b5dSMatthias Braun } 1658c0291865SChandler Carruth 1659b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() 1660c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) { 1661b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1662b98f63dbSChandler Carruth } 1663b98f63dbSChandler Carruth 1664b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) 1665c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) { 1666b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1667b98f63dbSChandler Carruth } 1668b98f63dbSChandler Carruth 1669b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( 1670c0291865SChandler Carruth const TargetLibraryInfoImpl &TLIImpl) 1671c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) { 1672b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1673b98f63dbSChandler Carruth } 1674b98f63dbSChandler Carruth 1675dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key; 1676df0cd726SNAKAMURA Takumi 1677b98f63dbSChandler Carruth // Register the basic pass. 1678b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", 1679b98f63dbSChandler Carruth "Target Library Information", false, true) 1680b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0; 1681b98f63dbSChandler Carruth 1682b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {} 1683