162d4215bSChandler Carruth //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==// 262d4215bSChandler Carruth // 362d4215bSChandler Carruth // The LLVM Compiler Infrastructure 462d4215bSChandler Carruth // 562d4215bSChandler Carruth // This file is distributed under the University of Illinois Open Source 662d4215bSChandler Carruth // License. See LICENSE.TXT for details. 762d4215bSChandler Carruth // 862d4215bSChandler Carruth //===----------------------------------------------------------------------===// 962d4215bSChandler Carruth // 1062d4215bSChandler Carruth // This file implements the TargetLibraryInfo class. 1162d4215bSChandler Carruth // 1262d4215bSChandler Carruth //===----------------------------------------------------------------------===// 1362d4215bSChandler Carruth 1462d4215bSChandler Carruth #include "llvm/Analysis/TargetLibraryInfo.h" 1562d4215bSChandler Carruth #include "llvm/ADT/Triple.h" 166d8a2aa9SMichael Zolotukhin #include "llvm/Support/CommandLine.h" 1762d4215bSChandler Carruth using namespace llvm; 1862d4215bSChandler Carruth 196d8a2aa9SMichael Zolotukhin static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary( 206d8a2aa9SMichael Zolotukhin "vector-library", cl::Hidden, cl::desc("Vector functions library"), 216d8a2aa9SMichael Zolotukhin cl::init(TargetLibraryInfoImpl::NoLibrary), 226d8a2aa9SMichael Zolotukhin cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", 236d8a2aa9SMichael Zolotukhin "No vector functions library"), 246d8a2aa9SMichael Zolotukhin clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", 256d8a2aa9SMichael Zolotukhin "Accelerate framework"), 26a6669a1eSMatt Masten clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", 27732afdd0SMehdi Amini "Intel SVML library"))); 286d8a2aa9SMichael Zolotukhin 299a72cd7bSMehdi Amini StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = { 30cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING 31cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def" 3262d4215bSChandler Carruth }; 3362d4215bSChandler Carruth 3462d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) { 3562d4215bSChandler Carruth // Only Darwin variants have _stret versions of combined trig functions. 3662d4215bSChandler Carruth if (!T.isOSDarwin()) 3762d4215bSChandler Carruth return false; 3862d4215bSChandler Carruth 3962d4215bSChandler Carruth // The ABI is rather complicated on x86, so don't do anything special there. 4062d4215bSChandler Carruth if (T.getArch() == Triple::x86) 4162d4215bSChandler Carruth return false; 4262d4215bSChandler Carruth 4362d4215bSChandler Carruth if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) 4462d4215bSChandler Carruth return false; 4562d4215bSChandler Carruth 4662d4215bSChandler Carruth if (T.isiOS() && T.isOSVersionLT(7, 0)) 4762d4215bSChandler Carruth return false; 4862d4215bSChandler Carruth 4962d4215bSChandler Carruth return true; 5062d4215bSChandler Carruth } 5162d4215bSChandler Carruth 5262d4215bSChandler Carruth /// initialize - Initialize the set of available library functions based on the 5362d4215bSChandler Carruth /// specified target triple. This should be carefully written so that a missing 5462d4215bSChandler Carruth /// target triple gets a sane set of defaults. 55c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, 569a72cd7bSMehdi Amini ArrayRef<StringRef> StandardNames) { 5762d4215bSChandler Carruth // Verify that the StandardNames array is in alphabetical order. 58e30b8ca1SCraig Topper assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), 599a72cd7bSMehdi Amini [](StringRef LHS, StringRef RHS) { 609a72cd7bSMehdi Amini return LHS < RHS; 61e30b8ca1SCraig Topper }) && 62e30b8ca1SCraig Topper "TargetLibraryInfoImpl function names must be sorted"); 6362d4215bSChandler Carruth 646af8e6c3SMarcin Koscielnicki bool ShouldExtI32Param = false, ShouldExtI32Return = false, 656af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = false; 666af8e6c3SMarcin Koscielnicki // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and 676af8e6c3SMarcin Koscielnicki // returns corresponding to C-level ints and unsigned ints. 686af8e6c3SMarcin Koscielnicki if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le || 696af8e6c3SMarcin Koscielnicki T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) { 706af8e6c3SMarcin Koscielnicki ShouldExtI32Param = true; 716af8e6c3SMarcin Koscielnicki ShouldExtI32Return = true; 726af8e6c3SMarcin Koscielnicki } 736af8e6c3SMarcin Koscielnicki // Mips, on the other hand, needs signext on i32 parameters corresponding 746af8e6c3SMarcin Koscielnicki // to both signed and unsigned ints. 756af8e6c3SMarcin Koscielnicki if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel || 766af8e6c3SMarcin Koscielnicki T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) { 776af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = true; 786af8e6c3SMarcin Koscielnicki } 796af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Param(ShouldExtI32Param); 806af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Return(ShouldExtI32Return); 816af8e6c3SMarcin Koscielnicki TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); 826af8e6c3SMarcin Koscielnicki 8378fd4f08SNicolai Hahnle if (T.getArch() == Triple::r600 || 8478fd4f08SNicolai Hahnle T.getArch() == Triple::amdgcn) { 85d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexp); 86d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexpf); 87d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexpl); 88d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 89d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 90d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 91d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10); 92d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10f); 93d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10l); 9478fd4f08SNicolai Hahnle } 9578fd4f08SNicolai Hahnle 9662d4215bSChandler Carruth // There are no library implementations of mempcy and memset for AMD gpus and 9762d4215bSChandler Carruth // these can be difficult to lower in the backend. 9862d4215bSChandler Carruth if (T.getArch() == Triple::r600 || 9905532995SDan Gohman T.getArch() == Triple::amdgcn) { 100d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memcpy); 101d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset); 102d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 10362d4215bSChandler Carruth return; 10462d4215bSChandler Carruth } 10562d4215bSChandler Carruth 10662d4215bSChandler Carruth // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. 1078b40366bSTim Northover // All versions of watchOS support it. 10862d4215bSChandler Carruth if (T.isMacOSX()) { 10962d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 5)) 110d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 11162d4215bSChandler Carruth } else if (T.isiOS()) { 11262d4215bSChandler Carruth if (T.isOSVersionLT(3, 0)) 113d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 1148b40366bSTim Northover } else if (!T.isWatchOS()) { 115d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 11662d4215bSChandler Carruth } 11762d4215bSChandler Carruth 11862d4215bSChandler Carruth if (!hasSinCosPiStret(T)) { 119d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpi); 120d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpif); 121d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospi); 122d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospif); 123d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospi_stret); 124d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospif_stret); 12562d4215bSChandler Carruth } 12662d4215bSChandler Carruth 12762d4215bSChandler Carruth if (T.isMacOSX() && T.getArch() == Triple::x86 && 12862d4215bSChandler Carruth !T.isMacOSXVersionLT(10, 7)) { 12962d4215bSChandler Carruth // x86-32 OSX has a scheme where fwrite and fputs (and some other functions 13062d4215bSChandler Carruth // we don't care about) have two versions; on recent OSX, the one we want 13162d4215bSChandler Carruth // has a $UNIX2003 suffix. The two implementations are identical except 13262d4215bSChandler Carruth // for the return value in some edge cases. However, we don't want to 13362d4215bSChandler Carruth // generate code that depends on the old symbols. 134d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003"); 135d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003"); 13662d4215bSChandler Carruth } 13762d4215bSChandler Carruth 13862d4215bSChandler Carruth // iprintf and friends are only available on XCore and TCE. 13962d4215bSChandler Carruth if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { 140d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_iprintf); 141d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_siprintf); 142d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fiprintf); 14362d4215bSChandler Carruth } 14462d4215bSChandler Carruth 14562d4215bSChandler Carruth if (T.isOSWindows() && !T.isOSCygMing()) { 14662d4215bSChandler Carruth // Win32 does not support long double 147d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_acosl); 148d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_asinl); 149d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atanl); 150d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atan2l); 151d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ceill); 152d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_copysignl); 153d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cosl); 154d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_coshl); 155d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_expl); 156d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf 157d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fabsl); 158d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_floorl); 159d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fmaxl); 160d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fminl); 161d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fmodl); 162d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_frexpl); 163d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexpf); 164d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ldexpl); 165d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_logl); 166d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_modfl); 167d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_powl); 168d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinl); 169d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinhl); 170d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sqrtl); 171d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tanl); 172d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tanhl); 17362d4215bSChandler Carruth 17462d4215bSChandler Carruth // Win32 only has C89 math 175d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_acosh); 176d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_acoshf); 177d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_acoshl); 178d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_asinh); 179d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_asinhf); 180d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_asinhl); 181d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atanh); 182d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atanhf); 183d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atanhl); 184d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cbrt); 185d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cbrtf); 186d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cbrtl); 187d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp2); 188d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp2f); 189d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp2l); 190d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_expm1); 191d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_expm1f); 192d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_expm1l); 193d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log2); 194d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log2f); 195d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log2l); 196d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log1p); 197d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log1pf); 198d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log1pl); 199d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_logb); 200d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_logbf); 201d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_logbl); 202d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nearbyint); 203d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nearbyintf); 204d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nearbyintl); 205d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_rint); 206d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_rintf); 207d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_rintl); 208d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_round); 209d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_roundf); 210d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_roundl); 211d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_trunc); 212d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_truncf); 213d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_truncl); 21462d4215bSChandler Carruth 21562d4215bSChandler Carruth // Win32 provides some C99 math with mangled names 216d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_copysign, "_copysign"); 21762d4215bSChandler Carruth 21862d4215bSChandler Carruth if (T.getArch() == Triple::x86) { 21962d4215bSChandler Carruth // Win32 on x86 implements single-precision math functions as macros 220d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_acosf); 221d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_asinf); 222d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atanf); 223d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atan2f); 224d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ceilf); 225d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_copysignf); 226d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cosf); 227d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_coshf); 228d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_expf); 229d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_floorf); 230d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fminf); 231d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fmaxf); 232d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fmodf); 233d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_logf); 234d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_log10f); 235d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_modff); 236d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_powf); 237d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinf); 238d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinhf); 239d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sqrtf); 240d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tanf); 241d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tanhf); 24262d4215bSChandler Carruth } 24362d4215bSChandler Carruth 2443cd8c16dSAndrew Kaylor // These definitions are due to math-finite.h header on Linux 2453cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_acos_finite); 2463cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_acosf_finite); 2473cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_acosl_finite); 2483cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_acosh_finite); 2493cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_acoshf_finite); 2503cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_acoshl_finite); 2513cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_asin_finite); 2523cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_asinf_finite); 2533cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_asinl_finite); 2543cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_atan2_finite); 2553cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_atan2f_finite); 2563cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_atan2l_finite); 2573cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_atanh_finite); 2583cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_atanhf_finite); 2593cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_atanhl_finite); 2603cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_cosh_finite); 2613cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_coshf_finite); 2623cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_coshl_finite); 2633cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp10_finite); 2643cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp10f_finite); 2653cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp10l_finite); 2663cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp2_finite); 2673cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp2f_finite); 2683cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp2l_finite); 2693cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_exp_finite); 2703cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_expf_finite); 2713cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_expl_finite); 2723cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log10_finite); 2733cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log10f_finite); 2743cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log10l_finite); 2753cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log2_finite); 2763cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log2f_finite); 2773cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log2l_finite); 2783cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_log_finite); 2793cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_logf_finite); 2803cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_logl_finite); 2813cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_pow_finite); 2823cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_powf_finite); 2833cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_powl_finite); 2843cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_sinh_finite); 2853cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_sinhf_finite); 2863cd8c16dSAndrew Kaylor TLI.setUnavailable(LibFunc_sinhl_finite); 2873cd8c16dSAndrew Kaylor 28862d4215bSChandler Carruth // Win32 does *not* provide provide these functions, but they are 28962d4215bSChandler Carruth // generally available on POSIX-compliant systems: 290d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_access); 291d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcmp); 292d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcopy); 293d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bzero); 294d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chmod); 295d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chown); 296d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_closedir); 297d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ctermid); 298d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fdopen); 299d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffs); 300d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fileno); 301d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flockfile); 302d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko); 303d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat); 304d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs); 305d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello); 306d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftrylockfile); 307d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_funlockfile); 308d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getc_unlocked); 309d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getitimer); 310d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getlogin_r); 311d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getpwnam); 312d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_gettimeofday); 313d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htonl); 314d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htons); 315d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lchown); 316d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat); 317d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memccpy); 318d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_mkdir); 319d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohl); 320d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohs); 321d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open); 322d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_opendir); 323d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pclose); 324d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_popen); 325d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pread); 326d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pwrite); 327d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_read); 328d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_readlink); 329d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_realpath); 330d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_rmdir); 331d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_setitimer); 332d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat); 333d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs); 334d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpcpy); 335d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpncpy); 336d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_strcasecmp); 337d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_strncasecmp); 338d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_times); 339d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_uname); 340d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unlink); 341d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unsetenv); 342d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utime); 343d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utimes); 344d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_write); 34562d4215bSChandler Carruth 34662d4215bSChandler Carruth // Win32 does *not* provide provide these functions, but they are 34762d4215bSChandler Carruth // specified by C99: 348d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_atoll); 349d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_frexpf); 350d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_llabs); 35162d4215bSChandler Carruth } 35262d4215bSChandler Carruth 35362d4215bSChandler Carruth switch (T.getOS()) { 35462d4215bSChandler Carruth case Triple::MacOSX: 35562d4215bSChandler Carruth // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 35662d4215bSChandler Carruth // and their names are __exp10 and __exp10f. exp10l is not available on 35762d4215bSChandler Carruth // OS X or iOS. 358d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 35962d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 9)) { 360d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 361d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 36262d4215bSChandler Carruth } else { 363d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 364d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 36562d4215bSChandler Carruth } 36662d4215bSChandler Carruth break; 36762d4215bSChandler Carruth case Triple::IOS: 36889a6eefeSTim Northover case Triple::TvOS: 3698b40366bSTim Northover case Triple::WatchOS: 370d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 3718b40366bSTim Northover if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) || 3728b40366bSTim Northover (T.isOSVersionLT(9, 0) && 3738b40366bSTim Northover (T.getArch() == Triple::x86 || 3748b40366bSTim Northover T.getArch() == Triple::x86_64)))) { 375d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 376d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 37762d4215bSChandler Carruth } else { 378d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 379d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 38062d4215bSChandler Carruth } 38162d4215bSChandler Carruth break; 38262d4215bSChandler Carruth case Triple::Linux: 38362d4215bSChandler Carruth // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely 38462d4215bSChandler Carruth // buggy prior to glibc version 2.18. Until this version is widely deployed 38562d4215bSChandler Carruth // or we have a reasonable detection strategy, we cannot use exp10 reliably 38662d4215bSChandler Carruth // on Linux. 38762d4215bSChandler Carruth // 38862d4215bSChandler Carruth // Fall through to disable all of them. 389cd1d5aafSJustin Bogner LLVM_FALLTHROUGH; 39062d4215bSChandler Carruth default: 391d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 392d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 393d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 39462d4215bSChandler Carruth } 39562d4215bSChandler Carruth 39662d4215bSChandler Carruth // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and 39762d4215bSChandler Carruth // Linux (GLIBC): 39862d4215bSChandler Carruth // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html 39983b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c 40062d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html 40162d4215bSChandler Carruth switch (T.getOS()) { 40262d4215bSChandler Carruth case Triple::Darwin: 40362d4215bSChandler Carruth case Triple::MacOSX: 40462d4215bSChandler Carruth case Triple::IOS: 40589a6eefeSTim Northover case Triple::TvOS: 4068b40366bSTim Northover case Triple::WatchOS: 40762d4215bSChandler Carruth case Triple::FreeBSD: 40862d4215bSChandler Carruth case Triple::Linux: 40962d4215bSChandler Carruth break; 41062d4215bSChandler Carruth default: 411d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsl); 41262d4215bSChandler Carruth } 41362d4215bSChandler Carruth 41462d4215bSChandler Carruth // ffsll is available on at least FreeBSD and Linux (GLIBC): 41583b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c 41662d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html 41762d4215bSChandler Carruth switch (T.getOS()) { 41889a6eefeSTim Northover case Triple::Darwin: 41989a6eefeSTim Northover case Triple::MacOSX: 42089a6eefeSTim Northover case Triple::IOS: 42189a6eefeSTim Northover case Triple::TvOS: 42289a6eefeSTim Northover case Triple::WatchOS: 42362d4215bSChandler Carruth case Triple::FreeBSD: 42462d4215bSChandler Carruth case Triple::Linux: 42562d4215bSChandler Carruth break; 42662d4215bSChandler Carruth default: 427d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsll); 42862d4215bSChandler Carruth } 42962d4215bSChandler Carruth 430bfd3082eSDavide Italiano // The following functions are available on at least FreeBSD: 431bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/fls.c 432bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c 433bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c 434bfd3082eSDavide Italiano if (!T.isOSFreeBSD()) { 435d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fls); 436d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsl); 437d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsll); 438bfd3082eSDavide Italiano } 439bfd3082eSDavide Italiano 44062d4215bSChandler Carruth // The following functions are available on at least Linux: 44162d4215bSChandler Carruth if (!T.isOSLinux()) { 442d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strdup); 443d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strtok_r); 444d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_scanf); 445d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf); 446d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_getc); 447d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_putc); 448d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memalign); 449d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fopen64); 450d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko64); 451d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat64); 452d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs64); 453d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello64); 454d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat64); 455d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open64); 456d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat64); 457d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs64); 458d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tmpfile64); 45962d4215bSChandler Carruth } 4606d8a2aa9SMichael Zolotukhin 46151132881SJustin Lebar // As currently implemented in clang, NVPTX code has no standard library to 46251132881SJustin Lebar // speak of. Headers provide a standard-ish library implementation, but many 46351132881SJustin Lebar // of the signatures are wrong -- for example, many libm functions are not 46451132881SJustin Lebar // extern "C". 46551132881SJustin Lebar // 46651132881SJustin Lebar // libdevice, an IR library provided by nvidia, is linked in by the front-end, 46751132881SJustin Lebar // but only used functions are provided to llvm. Moreover, most of the 46851132881SJustin Lebar // functions in libdevice don't map precisely to standard library functions. 46951132881SJustin Lebar // 47051132881SJustin Lebar // FIXME: Having no standard library prevents e.g. many fastmath 47151132881SJustin Lebar // optimizations, so this situation should be fixed. 472ae272d71SDavid Majnemer if (T.isNVPTX()) { 47351132881SJustin Lebar TLI.disableAllFunctions(); 474d21529faSDavid L. Jones TLI.setAvailable(LibFunc_nvvm_reflect); 475ae272d71SDavid Majnemer } else { 476d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nvvm_reflect); 477ae272d71SDavid Majnemer } 47851132881SJustin Lebar 4796d8a2aa9SMichael Zolotukhin TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); 48062d4215bSChandler Carruth } 48162d4215bSChandler Carruth 482c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() { 48362d4215bSChandler Carruth // Default to everything being available. 48462d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 48562d4215bSChandler Carruth 48662d4215bSChandler Carruth initialize(*this, Triple(), StandardNames); 48762d4215bSChandler Carruth } 48862d4215bSChandler Carruth 489c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { 49062d4215bSChandler Carruth // Default to everything being available. 49162d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 49262d4215bSChandler Carruth 49362d4215bSChandler Carruth initialize(*this, T, StandardNames); 49462d4215bSChandler Carruth } 49562d4215bSChandler Carruth 496c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) 4975ae2c526SMarcin Koscielnicki : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), 4985ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 4995ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 50062d4215bSChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 501e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 502e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 5038ca43224SChandler Carruth } 5048ca43224SChandler Carruth 505c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) 5065ae2c526SMarcin Koscielnicki : CustomNames(std::move(TLI.CustomNames)), 5075ae2c526SMarcin Koscielnicki ShouldExtI32Param(TLI.ShouldExtI32Param), 5085ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 5095ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 5108ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 5118ca43224SChandler Carruth AvailableArray); 512e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 513e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 5148ca43224SChandler Carruth } 5158ca43224SChandler Carruth 516c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { 51762d4215bSChandler Carruth CustomNames = TLI.CustomNames; 5185ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 5195ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 5205ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 5218ca43224SChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 5228ca43224SChandler Carruth return *this; 5238ca43224SChandler Carruth } 5248ca43224SChandler Carruth 525c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { 5268ca43224SChandler Carruth CustomNames = std::move(TLI.CustomNames); 5275ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 5285ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 5295ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 5308ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 5318ca43224SChandler Carruth AvailableArray); 5328ca43224SChandler Carruth return *this; 53362d4215bSChandler Carruth } 53462d4215bSChandler Carruth 53521abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) { 53662d4215bSChandler Carruth // Filter out empty names and names containing null bytes, those can't be in 53762d4215bSChandler Carruth // our table. 53862d4215bSChandler Carruth if (funcName.empty() || funcName.find('\0') != StringRef::npos) 53921abdf98SMichael Zolotukhin return StringRef(); 54062d4215bSChandler Carruth 54162d4215bSChandler Carruth // Check for \01 prefix that is used to mangle __asm declarations and 54262d4215bSChandler Carruth // strip it if present. 543cde33036SDavid Majnemer return GlobalValue::getRealLinkageName(funcName); 54421abdf98SMichael Zolotukhin } 54521abdf98SMichael Zolotukhin 54621abdf98SMichael Zolotukhin bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, 547d21529faSDavid L. Jones LibFunc &F) const { 5489a72cd7bSMehdi Amini StringRef const *Start = &StandardNames[0]; 549d21529faSDavid L. Jones StringRef const *End = &StandardNames[NumLibFuncs]; 55021abdf98SMichael Zolotukhin 55121abdf98SMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 55221abdf98SMichael Zolotukhin if (funcName.empty()) 55321abdf98SMichael Zolotukhin return false; 55421abdf98SMichael Zolotukhin 5559a72cd7bSMehdi Amini StringRef const *I = std::lower_bound( 5569a72cd7bSMehdi Amini Start, End, funcName, [](StringRef LHS, StringRef RHS) { 5579a72cd7bSMehdi Amini return LHS < RHS; 558d3b76a3bSMichael Zolotukhin }); 55962d4215bSChandler Carruth if (I != End && *I == funcName) { 560d21529faSDavid L. Jones F = (LibFunc)(I - Start); 56162d4215bSChandler Carruth return true; 56262d4215bSChandler Carruth } 56362d4215bSChandler Carruth return false; 56462d4215bSChandler Carruth } 56562d4215bSChandler Carruth 566d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, 567d21529faSDavid L. Jones LibFunc F, 568d765a82bSAhmed Bougacha const DataLayout *DL) const { 569d765a82bSAhmed Bougacha LLVMContext &Ctx = FTy.getContext(); 570d765a82bSAhmed Bougacha Type *PCharTy = Type::getInt8PtrTy(Ctx); 571d765a82bSAhmed Bougacha Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr; 572d765a82bSAhmed Bougacha auto IsSizeTTy = [SizeTTy](Type *Ty) { 573d765a82bSAhmed Bougacha return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); 574d765a82bSAhmed Bougacha }; 575d765a82bSAhmed Bougacha unsigned NumParams = FTy.getNumParams(); 576d765a82bSAhmed Bougacha 577d765a82bSAhmed Bougacha switch (F) { 578d21529faSDavid L. Jones case LibFunc_strlen: 579d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 580d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 581d765a82bSAhmed Bougacha 582d21529faSDavid L. Jones case LibFunc_strchr: 583d21529faSDavid L. Jones case LibFunc_strrchr: 584d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 585d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 586d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy()); 587d765a82bSAhmed Bougacha 588d21529faSDavid L. Jones case LibFunc_strtol: 589d21529faSDavid L. Jones case LibFunc_strtod: 590d21529faSDavid L. Jones case LibFunc_strtof: 591d21529faSDavid L. Jones case LibFunc_strtoul: 592d21529faSDavid L. Jones case LibFunc_strtoll: 593d21529faSDavid L. Jones case LibFunc_strtold: 594d21529faSDavid L. Jones case LibFunc_strtoull: 595d765a82bSAhmed Bougacha return ((NumParams == 2 || NumParams == 3) && 596d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 597d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 598d21529faSDavid L. Jones case LibFunc_strcat: 599d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 600d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 601d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType()); 602d765a82bSAhmed Bougacha 603d21529faSDavid L. Jones case LibFunc_strncat: 604d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 605d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 606d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType() && 607d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 608d765a82bSAhmed Bougacha 609d21529faSDavid L. Jones case LibFunc_strcpy_chk: 610d21529faSDavid L. Jones case LibFunc_stpcpy_chk: 611d765a82bSAhmed Bougacha --NumParams; 612d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 613d765a82bSAhmed Bougacha return false; 614b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 615d21529faSDavid L. Jones case LibFunc_strcpy: 616d21529faSDavid L. Jones case LibFunc_stpcpy: 617d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && 618d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 619d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy); 620d765a82bSAhmed Bougacha 621d21529faSDavid L. Jones case LibFunc_strncpy_chk: 622d21529faSDavid L. Jones case LibFunc_stpncpy_chk: 623d765a82bSAhmed Bougacha --NumParams; 624d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 625d765a82bSAhmed Bougacha return false; 626b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 627d21529faSDavid L. Jones case LibFunc_strncpy: 628d21529faSDavid L. Jones case LibFunc_stpncpy: 629d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 630d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 631d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy && 632d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 633d765a82bSAhmed Bougacha 634d21529faSDavid L. Jones case LibFunc_strxfrm: 635d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 636d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 637d765a82bSAhmed Bougacha 638d21529faSDavid L. Jones case LibFunc_strcmp: 639d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && 640d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 641d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 642d765a82bSAhmed Bougacha 643d21529faSDavid L. Jones case LibFunc_strncmp: 644d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 645d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 646d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 647d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 648d765a82bSAhmed Bougacha 649d21529faSDavid L. Jones case LibFunc_strspn: 650d21529faSDavid L. Jones case LibFunc_strcspn: 651d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 652d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 653d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 654d765a82bSAhmed Bougacha 655d21529faSDavid L. Jones case LibFunc_strcoll: 656d21529faSDavid L. Jones case LibFunc_strcasecmp: 657d21529faSDavid L. Jones case LibFunc_strncasecmp: 658d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 659d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 660d765a82bSAhmed Bougacha 661d21529faSDavid L. Jones case LibFunc_strstr: 662d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 663d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 664d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 665d765a82bSAhmed Bougacha 666d21529faSDavid L. Jones case LibFunc_strpbrk: 667d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 668d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 669d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 670d765a82bSAhmed Bougacha 671d21529faSDavid L. Jones case LibFunc_strtok: 672d21529faSDavid L. Jones case LibFunc_strtok_r: 673d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 674d21529faSDavid L. Jones case LibFunc_scanf: 675d21529faSDavid L. Jones case LibFunc_setbuf: 676d21529faSDavid L. Jones case LibFunc_setvbuf: 677d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 678d21529faSDavid L. Jones case LibFunc_strdup: 679d21529faSDavid L. Jones case LibFunc_strndup: 680d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 681d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 682d21529faSDavid L. Jones case LibFunc_sscanf: 683d21529faSDavid L. Jones case LibFunc_stat: 684d21529faSDavid L. Jones case LibFunc_statvfs: 685d21529faSDavid L. Jones case LibFunc_siprintf: 686d21529faSDavid L. Jones case LibFunc_sprintf: 687d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 688d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 689d21529faSDavid L. Jones case LibFunc_snprintf: 690d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 691d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 692d21529faSDavid L. Jones case LibFunc_setitimer: 693d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 694d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 695d21529faSDavid L. Jones case LibFunc_system: 696d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 697d21529faSDavid L. Jones case LibFunc_malloc: 698d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 699d21529faSDavid L. Jones case LibFunc_memcmp: 7006b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 7016b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 7026b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 703d765a82bSAhmed Bougacha 704d21529faSDavid L. Jones case LibFunc_memchr: 705d21529faSDavid L. Jones case LibFunc_memrchr: 7066b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 7076b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 708d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32) && 7096b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 710d21529faSDavid L. Jones case LibFunc_modf: 711d21529faSDavid L. Jones case LibFunc_modff: 712d21529faSDavid L. Jones case LibFunc_modfl: 713d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 714d765a82bSAhmed Bougacha 715d21529faSDavid L. Jones case LibFunc_memcpy_chk: 716d21529faSDavid L. Jones case LibFunc_memmove_chk: 717d765a82bSAhmed Bougacha --NumParams; 718d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 719d765a82bSAhmed Bougacha return false; 720b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 721d21529faSDavid L. Jones case LibFunc_memcpy: 722d21529faSDavid L. Jones case LibFunc_mempcpy: 723d21529faSDavid L. Jones case LibFunc_memmove: 724d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 725d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 726d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 727d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 728d765a82bSAhmed Bougacha 729d21529faSDavid L. Jones case LibFunc_memset_chk: 730d765a82bSAhmed Bougacha --NumParams; 731d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 732d765a82bSAhmed Bougacha return false; 733b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 734d21529faSDavid L. Jones case LibFunc_memset: 735d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 736d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 737d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 738d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 739d765a82bSAhmed Bougacha 740d21529faSDavid L. Jones case LibFunc_memccpy: 741d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 742d21529faSDavid L. Jones case LibFunc_memalign: 743d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 744d21529faSDavid L. Jones case LibFunc_realloc: 745d21529faSDavid L. Jones case LibFunc_reallocf: 7466b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == PCharTy && 7476b9be1dbSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 7486b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(1))); 749d21529faSDavid L. Jones case LibFunc_read: 750d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 751d21529faSDavid L. Jones case LibFunc_rewind: 752d21529faSDavid L. Jones case LibFunc_rmdir: 753d21529faSDavid L. Jones case LibFunc_remove: 754d21529faSDavid L. Jones case LibFunc_realpath: 755d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 756d21529faSDavid L. Jones case LibFunc_rename: 757d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 758d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 759d21529faSDavid L. Jones case LibFunc_readlink: 760d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 761d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 762d21529faSDavid L. Jones case LibFunc_write: 763d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 764d21529faSDavid L. Jones case LibFunc_bcopy: 765d21529faSDavid L. Jones case LibFunc_bcmp: 766d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 767d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 768d21529faSDavid L. Jones case LibFunc_bzero: 769d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 770d21529faSDavid L. Jones case LibFunc_calloc: 771d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 7721fe3f1caSAhmed Bougacha 773d21529faSDavid L. Jones case LibFunc_atof: 774d21529faSDavid L. Jones case LibFunc_atoi: 775d21529faSDavid L. Jones case LibFunc_atol: 776d21529faSDavid L. Jones case LibFunc_atoll: 777d21529faSDavid L. Jones case LibFunc_ferror: 778d21529faSDavid L. Jones case LibFunc_getenv: 779d21529faSDavid L. Jones case LibFunc_getpwnam: 780d21529faSDavid L. Jones case LibFunc_iprintf: 781d21529faSDavid L. Jones case LibFunc_pclose: 782d21529faSDavid L. Jones case LibFunc_perror: 783d21529faSDavid L. Jones case LibFunc_printf: 784d21529faSDavid L. Jones case LibFunc_puts: 785d21529faSDavid L. Jones case LibFunc_uname: 786d21529faSDavid L. Jones case LibFunc_under_IO_getc: 787d21529faSDavid L. Jones case LibFunc_unlink: 788d21529faSDavid L. Jones case LibFunc_unsetenv: 789d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 7901fe3f1caSAhmed Bougacha 791d21529faSDavid L. Jones case LibFunc_access: 792d21529faSDavid L. Jones case LibFunc_chmod: 793d21529faSDavid L. Jones case LibFunc_chown: 794d21529faSDavid L. Jones case LibFunc_clearerr: 795d21529faSDavid L. Jones case LibFunc_closedir: 796d21529faSDavid L. Jones case LibFunc_ctermid: 797d21529faSDavid L. Jones case LibFunc_fclose: 798d21529faSDavid L. Jones case LibFunc_feof: 799d21529faSDavid L. Jones case LibFunc_fflush: 800d21529faSDavid L. Jones case LibFunc_fgetc: 801d21529faSDavid L. Jones case LibFunc_fileno: 802d21529faSDavid L. Jones case LibFunc_flockfile: 803d21529faSDavid L. Jones case LibFunc_free: 804d21529faSDavid L. Jones case LibFunc_fseek: 805d21529faSDavid L. Jones case LibFunc_fseeko64: 806d21529faSDavid L. Jones case LibFunc_fseeko: 807d21529faSDavid L. Jones case LibFunc_fsetpos: 808d21529faSDavid L. Jones case LibFunc_ftell: 809d21529faSDavid L. Jones case LibFunc_ftello64: 810d21529faSDavid L. Jones case LibFunc_ftello: 811d21529faSDavid L. Jones case LibFunc_ftrylockfile: 812d21529faSDavid L. Jones case LibFunc_funlockfile: 813d21529faSDavid L. Jones case LibFunc_getc: 814d21529faSDavid L. Jones case LibFunc_getc_unlocked: 815d21529faSDavid L. Jones case LibFunc_getlogin_r: 816d21529faSDavid L. Jones case LibFunc_mkdir: 817d21529faSDavid L. Jones case LibFunc_mktime: 818d21529faSDavid L. Jones case LibFunc_times: 8191fe3f1caSAhmed Bougacha return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); 8201fe3f1caSAhmed Bougacha 821d21529faSDavid L. Jones case LibFunc_fopen: 822d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 823d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 824d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 825d21529faSDavid L. Jones case LibFunc_fdopen: 826d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 827d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 828d21529faSDavid L. Jones case LibFunc_fputc: 829d21529faSDavid L. Jones case LibFunc_fstat: 830d21529faSDavid L. Jones case LibFunc_frexp: 831d21529faSDavid L. Jones case LibFunc_frexpf: 832d21529faSDavid L. Jones case LibFunc_frexpl: 833d21529faSDavid L. Jones case LibFunc_fstatvfs: 834d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 835d21529faSDavid L. Jones case LibFunc_fgets: 836d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 837d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 838d21529faSDavid L. Jones case LibFunc_fread: 839d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 840d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 841d21529faSDavid L. Jones case LibFunc_fwrite: 842d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && 843d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 844d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 845d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy() && 846d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 847d21529faSDavid L. Jones case LibFunc_fputs: 848d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 849d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 850d21529faSDavid L. Jones case LibFunc_fscanf: 851d21529faSDavid L. Jones case LibFunc_fiprintf: 852d21529faSDavid L. Jones case LibFunc_fprintf: 8536b9be1dbSAhmed Bougacha return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() && 8546b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 855d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 856d21529faSDavid L. Jones case LibFunc_fgetpos: 857d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 858d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 859d21529faSDavid L. Jones case LibFunc_getchar: 8606b9be1dbSAhmed Bougacha return (NumParams == 0 && FTy.getReturnType()->isIntegerTy()); 861d21529faSDavid L. Jones case LibFunc_gets: 8626b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0) == PCharTy); 863d21529faSDavid L. Jones case LibFunc_getitimer: 864d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 865d21529faSDavid L. Jones case LibFunc_ungetc: 866d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 867d21529faSDavid L. Jones case LibFunc_utime: 868d21529faSDavid L. Jones case LibFunc_utimes: 869d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 870d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 871d21529faSDavid L. Jones case LibFunc_putc: 872d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 873d21529faSDavid L. Jones case LibFunc_pread: 874d21529faSDavid L. Jones case LibFunc_pwrite: 875d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); 876d21529faSDavid L. Jones case LibFunc_popen: 877d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 878d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 879d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 880d21529faSDavid L. Jones case LibFunc_vscanf: 881d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 882d21529faSDavid L. Jones case LibFunc_vsscanf: 883d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 884d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 885d21529faSDavid L. Jones case LibFunc_vfscanf: 886d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 887d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 888d21529faSDavid L. Jones case LibFunc_valloc: 889d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 890d21529faSDavid L. Jones case LibFunc_vprintf: 891d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 892d21529faSDavid L. Jones case LibFunc_vfprintf: 893d21529faSDavid L. Jones case LibFunc_vsprintf: 894d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 895d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 896d21529faSDavid L. Jones case LibFunc_vsnprintf: 897d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 898d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 899d21529faSDavid L. Jones case LibFunc_open: 900d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 901d21529faSDavid L. Jones case LibFunc_opendir: 902d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && 903d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 904d21529faSDavid L. Jones case LibFunc_tmpfile: 905d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 906d21529faSDavid L. Jones case LibFunc_htonl: 907d21529faSDavid L. Jones case LibFunc_ntohl: 9086b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 9096b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 910d21529faSDavid L. Jones case LibFunc_htons: 911d21529faSDavid L. Jones case LibFunc_ntohs: 9126b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) && 9136b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 914d21529faSDavid L. Jones case LibFunc_lstat: 915d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 916d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 917d21529faSDavid L. Jones case LibFunc_lchown: 918d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 919d21529faSDavid L. Jones case LibFunc_qsort: 920d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); 921d21529faSDavid L. Jones case LibFunc_dunder_strdup: 922d21529faSDavid L. Jones case LibFunc_dunder_strndup: 923d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 924d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 925d21529faSDavid L. Jones case LibFunc_dunder_strtok_r: 926d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 927d21529faSDavid L. Jones case LibFunc_under_IO_putc: 928d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 929d21529faSDavid L. Jones case LibFunc_dunder_isoc99_scanf: 930d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 931d21529faSDavid L. Jones case LibFunc_stat64: 932d21529faSDavid L. Jones case LibFunc_lstat64: 933d21529faSDavid L. Jones case LibFunc_statvfs64: 93479dcc274SMichael Kuperstein return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 935d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 936d21529faSDavid L. Jones case LibFunc_dunder_isoc99_sscanf: 93779dcc274SMichael Kuperstein return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 938d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 939d21529faSDavid L. Jones case LibFunc_fopen64: 940d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 941d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 942d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 943d21529faSDavid L. Jones case LibFunc_tmpfile64: 944d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 945d21529faSDavid L. Jones case LibFunc_fstat64: 946d21529faSDavid L. Jones case LibFunc_fstatvfs64: 947d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 948d21529faSDavid L. Jones case LibFunc_open64: 949d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 950d21529faSDavid L. Jones case LibFunc_gettimeofday: 951d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 952d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 953d765a82bSAhmed Bougacha 9546b9be1dbSAhmed Bougacha // new(unsigned int); 955d21529faSDavid L. Jones case LibFunc_Znwj: 9566b9be1dbSAhmed Bougacha // new(unsigned long); 957d21529faSDavid L. Jones case LibFunc_Znwm: 9586b9be1dbSAhmed Bougacha // new[](unsigned int); 959d21529faSDavid L. Jones case LibFunc_Znaj: 9606b9be1dbSAhmed Bougacha // new[](unsigned long); 961d21529faSDavid L. Jones case LibFunc_Znam: 9626b9be1dbSAhmed Bougacha // new(unsigned int); 963d21529faSDavid L. Jones case LibFunc_msvc_new_int: 9646b9be1dbSAhmed Bougacha // new(unsigned long long); 965d21529faSDavid L. Jones case LibFunc_msvc_new_longlong: 9666b9be1dbSAhmed Bougacha // new[](unsigned int); 967d21529faSDavid L. Jones case LibFunc_msvc_new_array_int: 9686b9be1dbSAhmed Bougacha // new[](unsigned long long); 969d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong: 9706b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 9716b9be1dbSAhmed Bougacha 9726b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 973d21529faSDavid L. Jones case LibFunc_ZnwjRKSt9nothrow_t: 9746b9be1dbSAhmed Bougacha // new(unsigned long, nothrow); 975d21529faSDavid L. Jones case LibFunc_ZnwmRKSt9nothrow_t: 9766b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 977d21529faSDavid L. Jones case LibFunc_ZnajRKSt9nothrow_t: 9786b9be1dbSAhmed Bougacha // new[](unsigned long, nothrow); 979d21529faSDavid L. Jones case LibFunc_ZnamRKSt9nothrow_t: 9806b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 981d21529faSDavid L. Jones case LibFunc_msvc_new_int_nothrow: 9826b9be1dbSAhmed Bougacha // new(unsigned long long, nothrow); 983d21529faSDavid L. Jones case LibFunc_msvc_new_longlong_nothrow: 9846b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 985d21529faSDavid L. Jones case LibFunc_msvc_new_array_int_nothrow: 9866b9be1dbSAhmed Bougacha // new[](unsigned long long, nothrow); 987d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong_nothrow: 9886b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 9896b9be1dbSAhmed Bougacha 9906b9be1dbSAhmed Bougacha // void operator delete[](void*); 991d21529faSDavid L. Jones case LibFunc_ZdaPv: 9926b9be1dbSAhmed Bougacha // void operator delete(void*); 993d21529faSDavid L. Jones case LibFunc_ZdlPv: 9946b9be1dbSAhmed Bougacha // void operator delete[](void*); 995d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32: 9966b9be1dbSAhmed Bougacha // void operator delete[](void*); 997d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64: 9986b9be1dbSAhmed Bougacha // void operator delete(void*); 999d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32: 10006b9be1dbSAhmed Bougacha // void operator delete(void*); 1001d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64: 10026b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 10036b9be1dbSAhmed Bougacha 10046b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1005d21529faSDavid L. Jones case LibFunc_ZdaPvRKSt9nothrow_t: 10066b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1007d21529faSDavid L. Jones case LibFunc_ZdaPvj: 10086b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long); 1009d21529faSDavid L. Jones case LibFunc_ZdaPvm: 10106b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1011d21529faSDavid L. Jones case LibFunc_ZdlPvRKSt9nothrow_t: 10126b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1013d21529faSDavid L. Jones case LibFunc_ZdlPvj: 10146b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long); 1015d21529faSDavid L. Jones case LibFunc_ZdlPvm: 10166b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1017d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_int: 10186b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1019d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_nothrow: 10206b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long long); 1021d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_longlong: 10226b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1023d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_nothrow: 10246b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1025d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_int: 10266b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1027d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_nothrow: 10286b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long long); 1029d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_longlong: 10306b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1031d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_nothrow: 10326b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1033d765a82bSAhmed Bougacha 1034d21529faSDavid L. Jones case LibFunc_memset_pattern16: 1035d765a82bSAhmed Bougacha return (!FTy.isVarArg() && NumParams == 3 && 10366b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 10376b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 10386b9be1dbSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 1039d765a82bSAhmed Bougacha 1040d21529faSDavid L. Jones case LibFunc_cxa_guard_abort: 1041d21529faSDavid L. Jones case LibFunc_cxa_guard_acquire: 1042d21529faSDavid L. Jones case LibFunc_cxa_guard_release: 1043d21529faSDavid L. Jones case LibFunc_nvvm_reflect: 10446b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1045d765a82bSAhmed Bougacha 1046d21529faSDavid L. Jones case LibFunc_sincospi_stret: 1047d21529faSDavid L. Jones case LibFunc_sincospif_stret: 10486b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy()); 10496b9be1dbSAhmed Bougacha 1050d21529faSDavid L. Jones case LibFunc_acos: 10513cd8c16dSAndrew Kaylor case LibFunc_acos_finite: 1052d21529faSDavid L. Jones case LibFunc_acosf: 10533cd8c16dSAndrew Kaylor case LibFunc_acosf_finite: 1054d21529faSDavid L. Jones case LibFunc_acosh: 10553cd8c16dSAndrew Kaylor case LibFunc_acosh_finite: 1056d21529faSDavid L. Jones case LibFunc_acoshf: 10573cd8c16dSAndrew Kaylor case LibFunc_acoshf_finite: 1058d21529faSDavid L. Jones case LibFunc_acoshl: 10593cd8c16dSAndrew Kaylor case LibFunc_acoshl_finite: 1060d21529faSDavid L. Jones case LibFunc_acosl: 10613cd8c16dSAndrew Kaylor case LibFunc_acosl_finite: 1062d21529faSDavid L. Jones case LibFunc_asin: 10633cd8c16dSAndrew Kaylor case LibFunc_asin_finite: 1064d21529faSDavid L. Jones case LibFunc_asinf: 10653cd8c16dSAndrew Kaylor case LibFunc_asinf_finite: 1066d21529faSDavid L. Jones case LibFunc_asinh: 1067d21529faSDavid L. Jones case LibFunc_asinhf: 1068d21529faSDavid L. Jones case LibFunc_asinhl: 1069d21529faSDavid L. Jones case LibFunc_asinl: 10703cd8c16dSAndrew Kaylor case LibFunc_asinl_finite: 1071d21529faSDavid L. Jones case LibFunc_atan: 1072d21529faSDavid L. Jones case LibFunc_atanf: 1073d21529faSDavid L. Jones case LibFunc_atanh: 10743cd8c16dSAndrew Kaylor case LibFunc_atanh_finite: 1075d21529faSDavid L. Jones case LibFunc_atanhf: 10763cd8c16dSAndrew Kaylor case LibFunc_atanhf_finite: 1077d21529faSDavid L. Jones case LibFunc_atanhl: 10783cd8c16dSAndrew Kaylor case LibFunc_atanhl_finite: 1079d21529faSDavid L. Jones case LibFunc_atanl: 1080d21529faSDavid L. Jones case LibFunc_cbrt: 1081d21529faSDavid L. Jones case LibFunc_cbrtf: 1082d21529faSDavid L. Jones case LibFunc_cbrtl: 1083d21529faSDavid L. Jones case LibFunc_ceil: 1084d21529faSDavid L. Jones case LibFunc_ceilf: 1085d21529faSDavid L. Jones case LibFunc_ceill: 1086d21529faSDavid L. Jones case LibFunc_cos: 1087d21529faSDavid L. Jones case LibFunc_cosf: 1088d21529faSDavid L. Jones case LibFunc_cosh: 10893cd8c16dSAndrew Kaylor case LibFunc_cosh_finite: 1090d21529faSDavid L. Jones case LibFunc_coshf: 10913cd8c16dSAndrew Kaylor case LibFunc_coshf_finite: 1092d21529faSDavid L. Jones case LibFunc_coshl: 10933cd8c16dSAndrew Kaylor case LibFunc_coshl_finite: 1094d21529faSDavid L. Jones case LibFunc_cosl: 1095d21529faSDavid L. Jones case LibFunc_exp10: 10963cd8c16dSAndrew Kaylor case LibFunc_exp10_finite: 1097d21529faSDavid L. Jones case LibFunc_exp10f: 10983cd8c16dSAndrew Kaylor case LibFunc_exp10f_finite: 1099d21529faSDavid L. Jones case LibFunc_exp10l: 11003cd8c16dSAndrew Kaylor case LibFunc_exp10l_finite: 1101d21529faSDavid L. Jones case LibFunc_exp2: 11023cd8c16dSAndrew Kaylor case LibFunc_exp2_finite: 1103d21529faSDavid L. Jones case LibFunc_exp2f: 11043cd8c16dSAndrew Kaylor case LibFunc_exp2f_finite: 1105d21529faSDavid L. Jones case LibFunc_exp2l: 11063cd8c16dSAndrew Kaylor case LibFunc_exp2l_finite: 1107d21529faSDavid L. Jones case LibFunc_exp: 11083cd8c16dSAndrew Kaylor case LibFunc_exp_finite: 1109d21529faSDavid L. Jones case LibFunc_expf: 11103cd8c16dSAndrew Kaylor case LibFunc_expf_finite: 1111d21529faSDavid L. Jones case LibFunc_expl: 11123cd8c16dSAndrew Kaylor case LibFunc_expl_finite: 1113d21529faSDavid L. Jones case LibFunc_expm1: 1114d21529faSDavid L. Jones case LibFunc_expm1f: 1115d21529faSDavid L. Jones case LibFunc_expm1l: 1116d21529faSDavid L. Jones case LibFunc_fabs: 1117d21529faSDavid L. Jones case LibFunc_fabsf: 1118d21529faSDavid L. Jones case LibFunc_fabsl: 1119d21529faSDavid L. Jones case LibFunc_floor: 1120d21529faSDavid L. Jones case LibFunc_floorf: 1121d21529faSDavid L. Jones case LibFunc_floorl: 1122d21529faSDavid L. Jones case LibFunc_log10: 11233cd8c16dSAndrew Kaylor case LibFunc_log10_finite: 1124d21529faSDavid L. Jones case LibFunc_log10f: 11253cd8c16dSAndrew Kaylor case LibFunc_log10f_finite: 1126d21529faSDavid L. Jones case LibFunc_log10l: 11273cd8c16dSAndrew Kaylor case LibFunc_log10l_finite: 1128d21529faSDavid L. Jones case LibFunc_log1p: 1129d21529faSDavid L. Jones case LibFunc_log1pf: 1130d21529faSDavid L. Jones case LibFunc_log1pl: 1131d21529faSDavid L. Jones case LibFunc_log2: 11323cd8c16dSAndrew Kaylor case LibFunc_log2_finite: 1133d21529faSDavid L. Jones case LibFunc_log2f: 11343cd8c16dSAndrew Kaylor case LibFunc_log2f_finite: 1135d21529faSDavid L. Jones case LibFunc_log2l: 11363cd8c16dSAndrew Kaylor case LibFunc_log2l_finite: 1137d21529faSDavid L. Jones case LibFunc_log: 11383cd8c16dSAndrew Kaylor case LibFunc_log_finite: 1139d21529faSDavid L. Jones case LibFunc_logb: 1140d21529faSDavid L. Jones case LibFunc_logbf: 1141d21529faSDavid L. Jones case LibFunc_logbl: 1142d21529faSDavid L. Jones case LibFunc_logf: 11433cd8c16dSAndrew Kaylor case LibFunc_logf_finite: 1144d21529faSDavid L. Jones case LibFunc_logl: 11453cd8c16dSAndrew Kaylor case LibFunc_logl_finite: 1146d21529faSDavid L. Jones case LibFunc_nearbyint: 1147d21529faSDavid L. Jones case LibFunc_nearbyintf: 1148d21529faSDavid L. Jones case LibFunc_nearbyintl: 1149d21529faSDavid L. Jones case LibFunc_rint: 1150d21529faSDavid L. Jones case LibFunc_rintf: 1151d21529faSDavid L. Jones case LibFunc_rintl: 1152d21529faSDavid L. Jones case LibFunc_round: 1153d21529faSDavid L. Jones case LibFunc_roundf: 1154d21529faSDavid L. Jones case LibFunc_roundl: 1155d21529faSDavid L. Jones case LibFunc_sin: 1156d21529faSDavid L. Jones case LibFunc_sinf: 1157d21529faSDavid L. Jones case LibFunc_sinh: 11583cd8c16dSAndrew Kaylor case LibFunc_sinh_finite: 1159d21529faSDavid L. Jones case LibFunc_sinhf: 11603cd8c16dSAndrew Kaylor case LibFunc_sinhf_finite: 1161d21529faSDavid L. Jones case LibFunc_sinhl: 11623cd8c16dSAndrew Kaylor case LibFunc_sinhl_finite: 1163d21529faSDavid L. Jones case LibFunc_sinl: 1164d21529faSDavid L. Jones case LibFunc_sqrt: 1165d21529faSDavid L. Jones case LibFunc_sqrt_finite: 1166d21529faSDavid L. Jones case LibFunc_sqrtf: 1167d21529faSDavid L. Jones case LibFunc_sqrtf_finite: 1168d21529faSDavid L. Jones case LibFunc_sqrtl: 1169d21529faSDavid L. Jones case LibFunc_sqrtl_finite: 1170d21529faSDavid L. Jones case LibFunc_tan: 1171d21529faSDavid L. Jones case LibFunc_tanf: 1172d21529faSDavid L. Jones case LibFunc_tanh: 1173d21529faSDavid L. Jones case LibFunc_tanhf: 1174d21529faSDavid L. Jones case LibFunc_tanhl: 1175d21529faSDavid L. Jones case LibFunc_tanl: 1176d21529faSDavid L. Jones case LibFunc_trunc: 1177d21529faSDavid L. Jones case LibFunc_truncf: 1178d21529faSDavid L. Jones case LibFunc_truncl: 1179d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && 1180d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1181d765a82bSAhmed Bougacha 1182d21529faSDavid L. Jones case LibFunc_atan2: 11833cd8c16dSAndrew Kaylor case LibFunc_atan2_finite: 1184d21529faSDavid L. Jones case LibFunc_atan2f: 11853cd8c16dSAndrew Kaylor case LibFunc_atan2f_finite: 1186d21529faSDavid L. Jones case LibFunc_atan2l: 11873cd8c16dSAndrew Kaylor case LibFunc_atan2l_finite: 1188d21529faSDavid L. Jones case LibFunc_fmin: 1189d21529faSDavid L. Jones case LibFunc_fminf: 1190d21529faSDavid L. Jones case LibFunc_fminl: 1191d21529faSDavid L. Jones case LibFunc_fmax: 1192d21529faSDavid L. Jones case LibFunc_fmaxf: 1193d21529faSDavid L. Jones case LibFunc_fmaxl: 1194d21529faSDavid L. Jones case LibFunc_fmod: 1195d21529faSDavid L. Jones case LibFunc_fmodf: 1196d21529faSDavid L. Jones case LibFunc_fmodl: 1197d21529faSDavid L. Jones case LibFunc_copysign: 1198d21529faSDavid L. Jones case LibFunc_copysignf: 1199d21529faSDavid L. Jones case LibFunc_copysignl: 1200d21529faSDavid L. Jones case LibFunc_pow: 12013cd8c16dSAndrew Kaylor case LibFunc_pow_finite: 1202d21529faSDavid L. Jones case LibFunc_powf: 12033cd8c16dSAndrew Kaylor case LibFunc_powf_finite: 1204d21529faSDavid L. Jones case LibFunc_powl: 12053cd8c16dSAndrew Kaylor case LibFunc_powl_finite: 1206d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 1207d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 1208d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(1)); 1209d765a82bSAhmed Bougacha 1210d21529faSDavid L. Jones case LibFunc_ldexp: 1211d21529faSDavid L. Jones case LibFunc_ldexpf: 1212d21529faSDavid L. Jones case LibFunc_ldexpl: 12136b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 12146b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 12156b9be1dbSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32)); 12166b9be1dbSAhmed Bougacha 1217d21529faSDavid L. Jones case LibFunc_ffs: 1218d21529faSDavid L. Jones case LibFunc_ffsl: 1219d21529faSDavid L. Jones case LibFunc_ffsll: 1220d21529faSDavid L. Jones case LibFunc_fls: 1221d21529faSDavid L. Jones case LibFunc_flsl: 1222d21529faSDavid L. Jones case LibFunc_flsll: 122304949fafSSanjay Patel return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 122404949fafSSanjay Patel FTy.getParamType(0)->isIntegerTy()); 122504949fafSSanjay Patel 1226d21529faSDavid L. Jones case LibFunc_isdigit: 1227d21529faSDavid L. Jones case LibFunc_isascii: 1228d21529faSDavid L. Jones case LibFunc_toascii: 1229d21529faSDavid L. Jones case LibFunc_putchar: 1230d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 123104949fafSSanjay Patel FTy.getReturnType() == FTy.getParamType(0)); 1232d765a82bSAhmed Bougacha 1233d21529faSDavid L. Jones case LibFunc_abs: 1234d21529faSDavid L. Jones case LibFunc_labs: 1235d21529faSDavid L. Jones case LibFunc_llabs: 1236d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && 1237d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1238d765a82bSAhmed Bougacha 1239d21529faSDavid L. Jones case LibFunc_cxa_atexit: 1240d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && 1241d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1242d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 1243d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1244d765a82bSAhmed Bougacha 1245d21529faSDavid L. Jones case LibFunc_sinpi: 1246d21529faSDavid L. Jones case LibFunc_cospi: 1247d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && 1248d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1249d765a82bSAhmed Bougacha 1250d21529faSDavid L. Jones case LibFunc_sinpif: 1251d21529faSDavid L. Jones case LibFunc_cospif: 1252d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && 1253d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1254d765a82bSAhmed Bougacha 1255d21529faSDavid L. Jones case LibFunc_strnlen: 12566b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) && 12576b9be1dbSAhmed Bougacha FTy.getParamType(0) == PCharTy && 12586b9be1dbSAhmed Bougacha FTy.getParamType(1) == SizeTTy); 12596b9be1dbSAhmed Bougacha 1260d21529faSDavid L. Jones case LibFunc_posix_memalign: 12616b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 12626b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 12636b9be1dbSAhmed Bougacha FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy); 12646b9be1dbSAhmed Bougacha 126560b40b8fSMatthias Braun case LibFunc_wcslen: 126660b40b8fSMatthias Braun return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 126760b40b8fSMatthias Braun FTy.getReturnType()->isIntegerTy()); 126860b40b8fSMatthias Braun 12696b9be1dbSAhmed Bougacha case LibFunc::NumLibFuncs: 127086b680a3SAhmed Bougacha break; 1271d765a82bSAhmed Bougacha } 12726b9be1dbSAhmed Bougacha 127386b680a3SAhmed Bougacha llvm_unreachable("Invalid libfunc"); 1274d765a82bSAhmed Bougacha } 1275d765a82bSAhmed Bougacha 1276d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 1277d21529faSDavid L. Jones LibFunc &F) const { 1278d765a82bSAhmed Bougacha const DataLayout *DL = 1279d765a82bSAhmed Bougacha FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; 1280d765a82bSAhmed Bougacha return getLibFunc(FDecl.getName(), F) && 1281d765a82bSAhmed Bougacha isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); 1282d765a82bSAhmed Bougacha } 1283d765a82bSAhmed Bougacha 1284c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() { 128562d4215bSChandler Carruth memset(AvailableArray, 0, sizeof(AvailableArray)); 128662d4215bSChandler Carruth } 1287b98f63dbSChandler Carruth 1288e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { 12899a72cd7bSMehdi Amini return LHS.ScalarFnName < RHS.ScalarFnName; 1290e8f2551fSMichael Zolotukhin } 1291e8f2551fSMichael Zolotukhin 1292e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { 12939a72cd7bSMehdi Amini return LHS.VectorFnName < RHS.VectorFnName; 1294e8f2551fSMichael Zolotukhin } 1295e8f2551fSMichael Zolotukhin 1296e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { 12979a72cd7bSMehdi Amini return LHS.ScalarFnName < S; 1298e8f2551fSMichael Zolotukhin } 1299e8f2551fSMichael Zolotukhin 1300e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { 13019a72cd7bSMehdi Amini return LHS.VectorFnName < S; 1302e8f2551fSMichael Zolotukhin } 1303e8f2551fSMichael Zolotukhin 1304e8f2551fSMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { 1305e8f2551fSMichael Zolotukhin VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end()); 1306e8f2551fSMichael Zolotukhin std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName); 1307e8f2551fSMichael Zolotukhin 1308e8f2551fSMichael Zolotukhin ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end()); 1309e8f2551fSMichael Zolotukhin std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName); 1310e8f2551fSMichael Zolotukhin } 1311e8f2551fSMichael Zolotukhin 13126d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( 13136d8a2aa9SMichael Zolotukhin enum VectorLibrary VecLib) { 13146d8a2aa9SMichael Zolotukhin switch (VecLib) { 13156d8a2aa9SMichael Zolotukhin case Accelerate: { 13166d8a2aa9SMichael Zolotukhin const VecDesc VecFuncs[] = { 1317de63aaceSMichael Zolotukhin // Floating-Point Arithmetic and Auxiliary Functions 1318de63aaceSMichael Zolotukhin {"ceilf", "vceilf", 4}, 13196d8a2aa9SMichael Zolotukhin {"fabsf", "vfabsf", 4}, 13206d8a2aa9SMichael Zolotukhin {"llvm.fabs.f32", "vfabsf", 4}, 1321de63aaceSMichael Zolotukhin {"floorf", "vfloorf", 4}, 1322de63aaceSMichael Zolotukhin {"sqrtf", "vsqrtf", 4}, 1323de63aaceSMichael Zolotukhin {"llvm.sqrt.f32", "vsqrtf", 4}, 1324de63aaceSMichael Zolotukhin 1325de63aaceSMichael Zolotukhin // Exponential and Logarithmic Functions 1326de63aaceSMichael Zolotukhin {"expf", "vexpf", 4}, 1327de63aaceSMichael Zolotukhin {"llvm.exp.f32", "vexpf", 4}, 1328de63aaceSMichael Zolotukhin {"expm1f", "vexpm1f", 4}, 1329de63aaceSMichael Zolotukhin {"logf", "vlogf", 4}, 1330de63aaceSMichael Zolotukhin {"llvm.log.f32", "vlogf", 4}, 1331de63aaceSMichael Zolotukhin {"log1pf", "vlog1pf", 4}, 1332de63aaceSMichael Zolotukhin {"log10f", "vlog10f", 4}, 1333de63aaceSMichael Zolotukhin {"llvm.log10.f32", "vlog10f", 4}, 1334de63aaceSMichael Zolotukhin {"logbf", "vlogbf", 4}, 1335de63aaceSMichael Zolotukhin 1336de63aaceSMichael Zolotukhin // Trigonometric Functions 1337de63aaceSMichael Zolotukhin {"sinf", "vsinf", 4}, 1338de63aaceSMichael Zolotukhin {"llvm.sin.f32", "vsinf", 4}, 1339de63aaceSMichael Zolotukhin {"cosf", "vcosf", 4}, 1340de63aaceSMichael Zolotukhin {"llvm.cos.f32", "vcosf", 4}, 1341de63aaceSMichael Zolotukhin {"tanf", "vtanf", 4}, 1342de63aaceSMichael Zolotukhin {"asinf", "vasinf", 4}, 1343de63aaceSMichael Zolotukhin {"acosf", "vacosf", 4}, 1344de63aaceSMichael Zolotukhin {"atanf", "vatanf", 4}, 1345de63aaceSMichael Zolotukhin 1346de63aaceSMichael Zolotukhin // Hyperbolic Functions 1347de63aaceSMichael Zolotukhin {"sinhf", "vsinhf", 4}, 1348de63aaceSMichael Zolotukhin {"coshf", "vcoshf", 4}, 1349de63aaceSMichael Zolotukhin {"tanhf", "vtanhf", 4}, 1350de63aaceSMichael Zolotukhin {"asinhf", "vasinhf", 4}, 1351de63aaceSMichael Zolotukhin {"acoshf", "vacoshf", 4}, 1352de63aaceSMichael Zolotukhin {"atanhf", "vatanhf", 4}, 13536d8a2aa9SMichael Zolotukhin }; 13546d8a2aa9SMichael Zolotukhin addVectorizableFunctions(VecFuncs); 13556d8a2aa9SMichael Zolotukhin break; 13566d8a2aa9SMichael Zolotukhin } 1357a6669a1eSMatt Masten case SVML: { 1358a6669a1eSMatt Masten const VecDesc VecFuncs[] = { 1359a6669a1eSMatt Masten {"sin", "__svml_sin2", 2}, 1360a6669a1eSMatt Masten {"sin", "__svml_sin4", 4}, 1361a6669a1eSMatt Masten {"sin", "__svml_sin8", 8}, 1362a6669a1eSMatt Masten 1363a6669a1eSMatt Masten {"sinf", "__svml_sinf4", 4}, 1364a6669a1eSMatt Masten {"sinf", "__svml_sinf8", 8}, 1365a6669a1eSMatt Masten {"sinf", "__svml_sinf16", 16}, 1366a6669a1eSMatt Masten 1367a6669a1eSMatt Masten {"cos", "__svml_cos2", 2}, 1368a6669a1eSMatt Masten {"cos", "__svml_cos4", 4}, 1369a6669a1eSMatt Masten {"cos", "__svml_cos8", 8}, 1370a6669a1eSMatt Masten 1371a6669a1eSMatt Masten {"cosf", "__svml_cosf4", 4}, 1372a6669a1eSMatt Masten {"cosf", "__svml_cosf8", 8}, 1373a6669a1eSMatt Masten {"cosf", "__svml_cosf16", 16}, 1374a6669a1eSMatt Masten 1375a6669a1eSMatt Masten {"pow", "__svml_pow2", 2}, 1376a6669a1eSMatt Masten {"pow", "__svml_pow4", 4}, 1377a6669a1eSMatt Masten {"pow", "__svml_pow8", 8}, 1378a6669a1eSMatt Masten 1379a6669a1eSMatt Masten {"powf", "__svml_powf4", 4}, 1380a6669a1eSMatt Masten {"powf", "__svml_powf8", 8}, 1381a6669a1eSMatt Masten {"powf", "__svml_powf16", 16}, 1382a6669a1eSMatt Masten 1383*b01e94eeSAndrew Kaylor { "__pow_finite", "__svml_pow2", 2 }, 1384*b01e94eeSAndrew Kaylor { "__pow_finite", "__svml_pow4", 4 }, 1385*b01e94eeSAndrew Kaylor { "__pow_finite", "__svml_pow8", 8 }, 1386*b01e94eeSAndrew Kaylor 1387*b01e94eeSAndrew Kaylor { "__powf_finite", "__svml_powf4", 4 }, 1388*b01e94eeSAndrew Kaylor { "__powf_finite", "__svml_powf8", 8 }, 1389*b01e94eeSAndrew Kaylor { "__powf_finite", "__svml_powf16", 16 }, 1390*b01e94eeSAndrew Kaylor 1391a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow2", 2}, 1392a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow4", 4}, 1393a6669a1eSMatt Masten {"llvm.pow.f64", "__svml_pow8", 8}, 1394a6669a1eSMatt Masten 1395a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf4", 4}, 1396a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf8", 8}, 1397a6669a1eSMatt Masten {"llvm.pow.f32", "__svml_powf16", 16}, 1398a6669a1eSMatt Masten 1399a6669a1eSMatt Masten {"exp", "__svml_exp2", 2}, 1400a6669a1eSMatt Masten {"exp", "__svml_exp4", 4}, 1401a6669a1eSMatt Masten {"exp", "__svml_exp8", 8}, 1402a6669a1eSMatt Masten 1403a6669a1eSMatt Masten {"expf", "__svml_expf4", 4}, 1404a6669a1eSMatt Masten {"expf", "__svml_expf8", 8}, 1405a6669a1eSMatt Masten {"expf", "__svml_expf16", 16}, 1406a6669a1eSMatt Masten 1407*b01e94eeSAndrew Kaylor { "__exp_finite", "__svml_exp2", 2 }, 1408*b01e94eeSAndrew Kaylor { "__exp_finite", "__svml_exp4", 4 }, 1409*b01e94eeSAndrew Kaylor { "__exp_finite", "__svml_exp8", 8 }, 1410*b01e94eeSAndrew Kaylor 1411*b01e94eeSAndrew Kaylor { "__expf_finite", "__svml_expf4", 4 }, 1412*b01e94eeSAndrew Kaylor { "__expf_finite", "__svml_expf8", 8 }, 1413*b01e94eeSAndrew Kaylor { "__expf_finite", "__svml_expf16", 16 }, 1414*b01e94eeSAndrew Kaylor 1415a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp2", 2}, 1416a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp4", 4}, 1417a6669a1eSMatt Masten {"llvm.exp.f64", "__svml_exp8", 8}, 1418a6669a1eSMatt Masten 1419a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf4", 4}, 1420a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf8", 8}, 1421a6669a1eSMatt Masten {"llvm.exp.f32", "__svml_expf16", 16}, 1422a6669a1eSMatt Masten 1423a6669a1eSMatt Masten {"log", "__svml_log2", 2}, 1424a6669a1eSMatt Masten {"log", "__svml_log4", 4}, 1425a6669a1eSMatt Masten {"log", "__svml_log8", 8}, 1426a6669a1eSMatt Masten 1427a6669a1eSMatt Masten {"logf", "__svml_logf4", 4}, 1428a6669a1eSMatt Masten {"logf", "__svml_logf8", 8}, 1429a6669a1eSMatt Masten {"logf", "__svml_logf16", 16}, 1430a6669a1eSMatt Masten 1431*b01e94eeSAndrew Kaylor { "__log_finite", "__svml_log2", 2 }, 1432*b01e94eeSAndrew Kaylor { "__log_finite", "__svml_log4", 4 }, 1433*b01e94eeSAndrew Kaylor { "__log_finite", "__svml_log8", 8 }, 1434*b01e94eeSAndrew Kaylor 1435*b01e94eeSAndrew Kaylor { "__logf_finite", "__svml_logf4", 4 }, 1436*b01e94eeSAndrew Kaylor { "__logf_finite", "__svml_logf8", 8 }, 1437*b01e94eeSAndrew Kaylor { "__logf_finite", "__svml_logf16", 16 }, 1438*b01e94eeSAndrew Kaylor 1439a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log2", 2}, 1440a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log4", 4}, 1441a6669a1eSMatt Masten {"llvm.log.f64", "__svml_log8", 8}, 1442a6669a1eSMatt Masten 1443a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf4", 4}, 1444a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf8", 8}, 1445a6669a1eSMatt Masten {"llvm.log.f32", "__svml_logf16", 16}, 1446a6669a1eSMatt Masten }; 1447a6669a1eSMatt Masten addVectorizableFunctions(VecFuncs); 1448a6669a1eSMatt Masten break; 1449a6669a1eSMatt Masten } 14506d8a2aa9SMichael Zolotukhin case NoLibrary: 14516d8a2aa9SMichael Zolotukhin break; 14526d8a2aa9SMichael Zolotukhin } 14536d8a2aa9SMichael Zolotukhin } 14546d8a2aa9SMichael Zolotukhin 1455e8f2551fSMichael Zolotukhin bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { 1456e8f2551fSMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 1457e8f2551fSMichael Zolotukhin if (funcName.empty()) 1458e8f2551fSMichael Zolotukhin return false; 1459e8f2551fSMichael Zolotukhin 1460e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1461e8f2551fSMichael Zolotukhin VectorDescs.begin(), VectorDescs.end(), funcName, 1462e8f2551fSMichael Zolotukhin compareWithScalarFnName); 1463e8f2551fSMichael Zolotukhin return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; 1464e8f2551fSMichael Zolotukhin } 1465e8f2551fSMichael Zolotukhin 1466e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, 1467e8f2551fSMichael Zolotukhin unsigned VF) const { 1468e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1469e8f2551fSMichael Zolotukhin if (F.empty()) 1470e8f2551fSMichael Zolotukhin return F; 1471e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1472e8f2551fSMichael Zolotukhin VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName); 1473e8f2551fSMichael Zolotukhin while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { 1474e8f2551fSMichael Zolotukhin if (I->VectorizationFactor == VF) 1475e8f2551fSMichael Zolotukhin return I->VectorFnName; 1476e8f2551fSMichael Zolotukhin ++I; 1477e8f2551fSMichael Zolotukhin } 1478e8f2551fSMichael Zolotukhin return StringRef(); 1479e8f2551fSMichael Zolotukhin } 1480e8f2551fSMichael Zolotukhin 1481e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F, 1482e8f2551fSMichael Zolotukhin unsigned &VF) const { 1483e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1484e8f2551fSMichael Zolotukhin if (F.empty()) 1485e8f2551fSMichael Zolotukhin return F; 1486e8f2551fSMichael Zolotukhin 1487e8f2551fSMichael Zolotukhin std::vector<VecDesc>::const_iterator I = std::lower_bound( 1488e8f2551fSMichael Zolotukhin ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName); 1489e8f2551fSMichael Zolotukhin if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F) 1490e8f2551fSMichael Zolotukhin return StringRef(); 1491e8f2551fSMichael Zolotukhin VF = I->VectorizationFactor; 1492e8f2551fSMichael Zolotukhin return I->ScalarFnName; 1493e8f2551fSMichael Zolotukhin } 1494e8f2551fSMichael Zolotukhin 1495164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Module &M, 1496164a2aa6SChandler Carruth ModuleAnalysisManager &) { 1497c0291865SChandler Carruth if (PresetInfoImpl) 1498c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1499c0291865SChandler Carruth 1500c0291865SChandler Carruth return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple()))); 1501c0291865SChandler Carruth } 1502c0291865SChandler Carruth 1503164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Function &F, 1504164a2aa6SChandler Carruth FunctionAnalysisManager &) { 1505c0291865SChandler Carruth if (PresetInfoImpl) 1506c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1507c0291865SChandler Carruth 1508c0291865SChandler Carruth return TargetLibraryInfo( 1509c0291865SChandler Carruth lookupInfoImpl(Triple(F.getParent()->getTargetTriple()))); 1510c0291865SChandler Carruth } 1511c0291865SChandler Carruth 1512c321e534SBenjamin Kramer TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) { 1513c0291865SChandler Carruth std::unique_ptr<TargetLibraryInfoImpl> &Impl = 1514c0291865SChandler Carruth Impls[T.normalize()]; 1515c0291865SChandler Carruth if (!Impl) 1516c0291865SChandler Carruth Impl.reset(new TargetLibraryInfoImpl(T)); 1517c0291865SChandler Carruth 1518c0291865SChandler Carruth return *Impl; 1519c0291865SChandler Carruth } 1520c0291865SChandler Carruth 1521c0291865SChandler Carruth 1522b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() 1523c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) { 1524b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1525b98f63dbSChandler Carruth } 1526b98f63dbSChandler Carruth 1527b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) 1528c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) { 1529b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1530b98f63dbSChandler Carruth } 1531b98f63dbSChandler Carruth 1532b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( 1533c0291865SChandler Carruth const TargetLibraryInfoImpl &TLIImpl) 1534c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) { 1535b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1536b98f63dbSChandler Carruth } 1537b98f63dbSChandler Carruth 1538dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key; 1539df0cd726SNAKAMURA Takumi 1540b98f63dbSChandler Carruth // Register the basic pass. 1541b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", 1542b98f63dbSChandler Carruth "Target Library Information", false, true) 1543b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0; 1544b98f63dbSChandler Carruth 1545b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {} 1546