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" 16*05da2fe5SReid Kleckner #include "llvm/InitializePasses.h" 176d8a2aa9SMichael Zolotukhin #include "llvm/Support/CommandLine.h" 1862d4215bSChandler Carruth using namespace llvm; 1962d4215bSChandler Carruth 206d8a2aa9SMichael Zolotukhin static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary( 216d8a2aa9SMichael Zolotukhin "vector-library", cl::Hidden, cl::desc("Vector functions library"), 226d8a2aa9SMichael Zolotukhin cl::init(TargetLibraryInfoImpl::NoLibrary), 236d8a2aa9SMichael Zolotukhin cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none", 246d8a2aa9SMichael Zolotukhin "No vector functions library"), 256d8a2aa9SMichael Zolotukhin clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate", 266d8a2aa9SMichael Zolotukhin "Accelerate framework"), 27fe97754aSNemanja Ivanovic clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV", 28fe97754aSNemanja Ivanovic "IBM MASS vector library"), 29a6669a1eSMatt Masten clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", 307459398aSJoel Jones "Intel SVML library"))); 316d8a2aa9SMichael Zolotukhin 3270434770SBenjamin Kramer StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = 3370434770SBenjamin Kramer { 34cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING 35cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def" 3662d4215bSChandler Carruth }; 3762d4215bSChandler Carruth 3862d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) { 3962d4215bSChandler Carruth // Only Darwin variants have _stret versions of combined trig functions. 4062d4215bSChandler Carruth if (!T.isOSDarwin()) 4162d4215bSChandler Carruth return false; 4262d4215bSChandler Carruth 4362d4215bSChandler Carruth // The ABI is rather complicated on x86, so don't do anything special there. 4462d4215bSChandler Carruth if (T.getArch() == Triple::x86) 4562d4215bSChandler Carruth return false; 4662d4215bSChandler Carruth 4762d4215bSChandler Carruth if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) 4862d4215bSChandler Carruth return false; 4962d4215bSChandler Carruth 5062d4215bSChandler Carruth if (T.isiOS() && T.isOSVersionLT(7, 0)) 5162d4215bSChandler Carruth return false; 5262d4215bSChandler Carruth 5362d4215bSChandler Carruth return true; 5462d4215bSChandler Carruth } 5562d4215bSChandler Carruth 568e16d733SClement Courbet static bool hasBcmp(const Triple &TT) { 578e16d733SClement Courbet // Posix removed support from bcmp() in 2001, but the glibc and several 588e16d733SClement Courbet // implementations of the libc still have it. 598e16d733SClement Courbet if (TT.isOSLinux()) 608e16d733SClement Courbet return TT.isGNUEnvironment() || TT.isMusl(); 618e16d733SClement Courbet // Both NetBSD and OpenBSD are planning to remove the function. Windows does 628e16d733SClement Courbet // not have it. 638d5c2803SAlex Lorenz return TT.isOSFreeBSD() || TT.isOSSolaris(); 648e16d733SClement Courbet } 658e16d733SClement Courbet 66600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified 67600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target 68600d24b4SSanjay Patel /// triple gets a sane set of defaults. 69c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, 7070434770SBenjamin Kramer ArrayRef<StringLiteral> StandardNames) { 7162d4215bSChandler Carruth // Verify that the StandardNames array is in alphabetical order. 72e30b8ca1SCraig Topper assert(std::is_sorted(StandardNames.begin(), StandardNames.end(), 739a72cd7bSMehdi Amini [](StringRef LHS, StringRef RHS) { 749a72cd7bSMehdi Amini return LHS < RHS; 75e30b8ca1SCraig Topper }) && 76e30b8ca1SCraig Topper "TargetLibraryInfoImpl function names must be sorted"); 7762d4215bSChandler Carruth 78ca22d427SDavid Bolvansky // Set IO unlocked variants as unavailable 79ca22d427SDavid Bolvansky // Set them as available per system below 80ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_getchar_unlocked); 81ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_putc_unlocked); 82ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_putchar_unlocked); 83ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fputc_unlocked); 84ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fgetc_unlocked); 85ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fread_unlocked); 86ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fwrite_unlocked); 87ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fputs_unlocked); 88ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fgets_unlocked); 89ca22d427SDavid Bolvansky 906af8e6c3SMarcin Koscielnicki bool ShouldExtI32Param = false, ShouldExtI32Return = false, 916af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = false; 926af8e6c3SMarcin Koscielnicki // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and 936af8e6c3SMarcin Koscielnicki // returns corresponding to C-level ints and unsigned ints. 943e92df3eSFangrui Song if (T.isPPC64() || T.getArch() == Triple::sparcv9 || 953e92df3eSFangrui Song T.getArch() == Triple::systemz) { 966af8e6c3SMarcin Koscielnicki ShouldExtI32Param = true; 976af8e6c3SMarcin Koscielnicki ShouldExtI32Return = true; 986af8e6c3SMarcin Koscielnicki } 996af8e6c3SMarcin Koscielnicki // Mips, on the other hand, needs signext on i32 parameters corresponding 1006af8e6c3SMarcin Koscielnicki // to both signed and unsigned ints. 10185e200e9SAlexander Richardson if (T.isMIPS()) { 1026af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = true; 1036af8e6c3SMarcin Koscielnicki } 1046af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Param(ShouldExtI32Param); 1056af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Return(ShouldExtI32Return); 1066af8e6c3SMarcin Koscielnicki TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); 1076af8e6c3SMarcin Koscielnicki 10878fd4f08SNicolai Hahnle if (T.getArch() == Triple::r600 || 109c26b3940STim Renouf T.getArch() == Triple::amdgcn) 110c26b3940STim Renouf TLI.disableAllFunctions(); 11178fd4f08SNicolai Hahnle 112ef72cdedSDavid Bolvansky // There are no library implementations of memcpy and memset for AMD gpus and 11362d4215bSChandler Carruth // these can be difficult to lower in the backend. 11462d4215bSChandler Carruth if (T.getArch() == Triple::r600 || 11505532995SDan Gohman T.getArch() == Triple::amdgcn) { 116d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memcpy); 117d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset); 118d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 11962d4215bSChandler Carruth return; 12062d4215bSChandler Carruth } 12162d4215bSChandler Carruth 12262d4215bSChandler Carruth // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. 1238b40366bSTim Northover // All versions of watchOS support it. 12462d4215bSChandler Carruth if (T.isMacOSX()) { 125ca22d427SDavid Bolvansky // available IO unlocked variants on Mac OS X 126ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getc_unlocked); 127ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getchar_unlocked); 128ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putc_unlocked); 129ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putchar_unlocked); 130ca22d427SDavid Bolvansky 13162d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 5)) 132d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 13362d4215bSChandler Carruth } else if (T.isiOS()) { 13462d4215bSChandler Carruth if (T.isOSVersionLT(3, 0)) 135d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 1368b40366bSTim Northover } else if (!T.isWatchOS()) { 137d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 13862d4215bSChandler Carruth } 13962d4215bSChandler Carruth 14062d4215bSChandler Carruth if (!hasSinCosPiStret(T)) { 141d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpi); 142d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpif); 143d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospi); 144d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospif); 145d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospi_stret); 146d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospif_stret); 14762d4215bSChandler Carruth } 14862d4215bSChandler Carruth 1498e16d733SClement Courbet if (!hasBcmp(T)) 1508e16d733SClement Courbet TLI.setUnavailable(LibFunc_bcmp); 1518e16d733SClement Courbet 15262d4215bSChandler Carruth if (T.isMacOSX() && T.getArch() == Triple::x86 && 15362d4215bSChandler Carruth !T.isMacOSXVersionLT(10, 7)) { 15462d4215bSChandler Carruth // x86-32 OSX has a scheme where fwrite and fputs (and some other functions 15562d4215bSChandler Carruth // we don't care about) have two versions; on recent OSX, the one we want 15662d4215bSChandler Carruth // has a $UNIX2003 suffix. The two implementations are identical except 15762d4215bSChandler Carruth // for the return value in some edge cases. However, we don't want to 15862d4215bSChandler Carruth // generate code that depends on the old symbols. 159d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003"); 160d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003"); 16162d4215bSChandler Carruth } 16262d4215bSChandler Carruth 163b4f9991fSAlon Zakai // iprintf and friends are only available on XCore, TCE, and Emscripten. 164b4f9991fSAlon Zakai if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce && 165b4f9991fSAlon Zakai T.getOS() != Triple::Emscripten) { 166d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_iprintf); 167d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_siprintf); 168d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fiprintf); 16962d4215bSChandler Carruth } 17062d4215bSChandler Carruth 171b4f9991fSAlon Zakai // __small_printf and friends are only available on Emscripten. 172b4f9991fSAlon Zakai if (T.getOS() != Triple::Emscripten) { 173b4f9991fSAlon Zakai TLI.setUnavailable(LibFunc_small_printf); 174b4f9991fSAlon Zakai TLI.setUnavailable(LibFunc_small_sprintf); 175b4f9991fSAlon Zakai TLI.setUnavailable(LibFunc_small_fprintf); 176b4f9991fSAlon Zakai } 177b4f9991fSAlon Zakai 17862d4215bSChandler Carruth if (T.isOSWindows() && !T.isOSCygMing()) { 1794b86c474SEvandro Menezes // XXX: The earliest documentation available at the moment is for VS2015/VC19: 1804b86c474SEvandro Menezes // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015 1814b86c474SEvandro Menezes // XXX: In order to use an MSVCRT older than VC19, 1824b86c474SEvandro Menezes // the specific library version must be explicit in the target triple, 1834b86c474SEvandro Menezes // e.g., x86_64-pc-windows-msvc18. 1844b86c474SEvandro Menezes bool hasPartialC99 = true; 1854b86c474SEvandro Menezes if (T.isKnownWindowsMSVCEnvironment()) { 1864b86c474SEvandro Menezes unsigned Major, Minor, Micro; 1874b86c474SEvandro Menezes T.getEnvironmentVersion(Major, Minor, Micro); 1884b86c474SEvandro Menezes hasPartialC99 = (Major == 0 || Major >= 19); 1894b86c474SEvandro Menezes } 1904b86c474SEvandro Menezes 191f4a36959SEvandro Menezes // Latest targets support C89 math functions, in part. 192f4a36959SEvandro Menezes bool isARM = (T.getArch() == Triple::aarch64 || 193f4a36959SEvandro Menezes T.getArch() == Triple::arm); 194f4a36959SEvandro Menezes bool hasPartialFloat = (isARM || 1954b86c474SEvandro Menezes T.getArch() == Triple::x86_64); 1964b86c474SEvandro Menezes 197f4a36959SEvandro Menezes // Win32 does not support float C89 math functions, in general. 1984b86c474SEvandro Menezes if (!hasPartialFloat) { 199e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_acosf); 200e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_asinf); 201e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_atan2f); 202f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_atanf); 203e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_ceilf); 204e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_cosf); 205e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_coshf); 206e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_expf); 207e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_floorf); 208e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_fmodf); 209e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_log10f); 210f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_logf); 211e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_modff); 212e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_powf); 213e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_sinf); 214e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_sinhf); 215e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_sqrtf); 216e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_tanf); 217e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_tanhf); 218e5bb58b1SEvandro Menezes } 219f4a36959SEvandro Menezes if (!isARM) 2204b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_fabsf); 221e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_frexpf); 222e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_ldexpf); 223e5bb58b1SEvandro Menezes 224f4a36959SEvandro Menezes // Win32 does not support long double C89 math functions. 22598f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acosl); 22698f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_asinl); 22798f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atan2l); 228f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_atanl); 22998f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ceill); 23098f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cosl); 23198f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_coshl); 23298f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_expl); 23398f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fabsl); 23498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_floorl); 23598f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fmodl); 23698f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_frexpl); 23798f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ldexpl); 2384b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log10l); 239f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_logl); 24098f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_modfl); 24198f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_powl); 24298f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sinl); 24398f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sinhl); 24498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sqrtl); 24598f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_tanl); 24698f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_tanhl); 24762d4215bSChandler Carruth 248e5bb58b1SEvandro Menezes // Win32 does not fully support C99 math functions. 2494b86c474SEvandro Menezes if (!hasPartialC99) { 25098f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acosh); 2514b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_acoshf); 252f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_asinh); 2534b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_asinhf); 254f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_atanh); 2554b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_atanhf); 256f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_cabs, "_cabs"); 2574b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cabsf); 258f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_cbrt); 2594b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cbrtf); 260f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_copysign, "_copysign"); 261f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf"); 262f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_exp2); 2634b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_exp2f); 264f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_expm1); 2654b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_expm1f); 266f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmax); 267f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmaxf); 268f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmin); 269f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fminf); 270f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_log1p); 2714b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log1pf); 272f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_log2); 2734b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log2f); 274f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_logb, "_logb"); 275f4a36959SEvandro Menezes if (hasPartialFloat) 276f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_logbf, "_logbf"); 277f4a36959SEvandro Menezes else 2784b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_logbf); 279f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_rint); 2804b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_rintf); 281f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_round); 2824b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_roundf); 283f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_trunc); 28498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_truncf); 285f4a36959SEvandro Menezes } 2864b86c474SEvandro Menezes 2874b86c474SEvandro Menezes // Win32 does not support long double C99 math functions. 2884b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_acoshl); 2894b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_asinhl); 2904b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_atanhl); 2914b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cabsl); 2924b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cbrtl); 293f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_copysignl); 2944b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_exp2l); 2954b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_expm1l); 296f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmaxl); 297f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fminl); 2984b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log1pl); 2994b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log2l); 3004b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_logbl); 3014b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_nearbyintl); 3024b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_rintl); 3034b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_roundl); 30498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_truncl); 30598f356cdSEvandro Menezes 306e5bb58b1SEvandro Menezes // Win32 does not support these functions, but 307e5bb58b1SEvandro Menezes // they are generally available on POSIX-compliant systems. 308d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_access); 309d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcmp); 310d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcopy); 311d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bzero); 312d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chmod); 313d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chown); 314d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_closedir); 315d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ctermid); 316d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fdopen); 317d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffs); 318d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fileno); 319d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flockfile); 320d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko); 321d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat); 322d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs); 323d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello); 324d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftrylockfile); 325d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_funlockfile); 326d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getitimer); 327d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getlogin_r); 328d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getpwnam); 329d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_gettimeofday); 330d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htonl); 331d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htons); 332d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lchown); 333d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat); 334d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memccpy); 335d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_mkdir); 336d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohl); 337d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohs); 338d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open); 339d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_opendir); 340d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pclose); 341d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_popen); 342d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pread); 343d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pwrite); 344d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_read); 345d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_readlink); 346d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_realpath); 347d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_rmdir); 348d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_setitimer); 349d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat); 350d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs); 351d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpcpy); 352d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpncpy); 353d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_strcasecmp); 354d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_strncasecmp); 355d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_times); 356d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_uname); 357d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unlink); 358d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unsetenv); 359d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utime); 360d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utimes); 361d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_write); 36262d4215bSChandler Carruth } 36362d4215bSChandler Carruth 36462d4215bSChandler Carruth switch (T.getOS()) { 36562d4215bSChandler Carruth case Triple::MacOSX: 36662d4215bSChandler Carruth // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 36762d4215bSChandler Carruth // and their names are __exp10 and __exp10f. exp10l is not available on 36862d4215bSChandler Carruth // OS X or iOS. 369d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 37062d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 9)) { 371d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 372d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 37362d4215bSChandler Carruth } else { 374d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 375d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 37662d4215bSChandler Carruth } 37762d4215bSChandler Carruth break; 37862d4215bSChandler Carruth case Triple::IOS: 37989a6eefeSTim Northover case Triple::TvOS: 3808b40366bSTim Northover case Triple::WatchOS: 381d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 3828b40366bSTim Northover if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) || 3838b40366bSTim Northover (T.isOSVersionLT(9, 0) && 3848b40366bSTim Northover (T.getArch() == Triple::x86 || 3858b40366bSTim Northover T.getArch() == Triple::x86_64)))) { 386d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 387d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 38862d4215bSChandler Carruth } else { 389d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 390d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 39162d4215bSChandler Carruth } 39262d4215bSChandler Carruth break; 39362d4215bSChandler Carruth case Triple::Linux: 39462d4215bSChandler Carruth // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely 39562d4215bSChandler Carruth // buggy prior to glibc version 2.18. Until this version is widely deployed 39662d4215bSChandler Carruth // or we have a reasonable detection strategy, we cannot use exp10 reliably 39762d4215bSChandler Carruth // on Linux. 39862d4215bSChandler Carruth // 39962d4215bSChandler Carruth // Fall through to disable all of them. 400cd1d5aafSJustin Bogner LLVM_FALLTHROUGH; 40162d4215bSChandler Carruth default: 402d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 403d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 404d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 40562d4215bSChandler Carruth } 40662d4215bSChandler Carruth 40762d4215bSChandler Carruth // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and 40862d4215bSChandler Carruth // Linux (GLIBC): 40962d4215bSChandler Carruth // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html 41083b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c 41162d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html 41262d4215bSChandler Carruth switch (T.getOS()) { 41362d4215bSChandler Carruth case Triple::Darwin: 41462d4215bSChandler Carruth case Triple::MacOSX: 41562d4215bSChandler Carruth case Triple::IOS: 41689a6eefeSTim Northover case Triple::TvOS: 4178b40366bSTim Northover case Triple::WatchOS: 41862d4215bSChandler Carruth case Triple::FreeBSD: 41962d4215bSChandler Carruth case Triple::Linux: 42062d4215bSChandler Carruth break; 42162d4215bSChandler Carruth default: 422d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsl); 42362d4215bSChandler Carruth } 42462d4215bSChandler Carruth 42562d4215bSChandler Carruth // ffsll is available on at least FreeBSD and Linux (GLIBC): 42683b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c 42762d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html 42862d4215bSChandler Carruth switch (T.getOS()) { 42989a6eefeSTim Northover case Triple::Darwin: 43089a6eefeSTim Northover case Triple::MacOSX: 43189a6eefeSTim Northover case Triple::IOS: 43289a6eefeSTim Northover case Triple::TvOS: 43389a6eefeSTim Northover case Triple::WatchOS: 43462d4215bSChandler Carruth case Triple::FreeBSD: 43562d4215bSChandler Carruth case Triple::Linux: 43662d4215bSChandler Carruth break; 43762d4215bSChandler Carruth default: 438d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsll); 43962d4215bSChandler Carruth } 44062d4215bSChandler Carruth 441bfd3082eSDavide Italiano // The following functions are available on at least FreeBSD: 442bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/fls.c 443bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c 444bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c 445bfd3082eSDavide Italiano if (!T.isOSFreeBSD()) { 446d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fls); 447d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsl); 448d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsll); 449bfd3082eSDavide Italiano } 450bfd3082eSDavide Italiano 451e3a5fc6dSEli Friedman // The following functions are only available on GNU/Linux (using glibc). 452e3a5fc6dSEli Friedman // Linux variants without glibc (eg: bionic, musl) may have some subset. 453e3a5fc6dSEli Friedman if (!T.isOSLinux() || !T.isGNUEnvironment()) { 454d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strdup); 455d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strtok_r); 456d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_scanf); 457d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf); 458d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_getc); 459d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_putc); 460e3a5fc6dSEli Friedman // But, Android and musl have memalign. 461e3a5fc6dSEli Friedman if (!T.isAndroid() && !T.isMusl()) 462d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memalign); 463d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fopen64); 464d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko64); 465d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat64); 466d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs64); 467d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello64); 468d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat64); 469d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open64); 470d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat64); 471d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs64); 472d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tmpfile64); 47352149f03SSanjay Patel 47452149f03SSanjay Patel // Relaxed math functions are included in math-finite.h on Linux (GLIBC). 47552149f03SSanjay Patel TLI.setUnavailable(LibFunc_acos_finite); 47652149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosf_finite); 47752149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosl_finite); 47852149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosh_finite); 47952149f03SSanjay Patel TLI.setUnavailable(LibFunc_acoshf_finite); 48052149f03SSanjay Patel TLI.setUnavailable(LibFunc_acoshl_finite); 48152149f03SSanjay Patel TLI.setUnavailable(LibFunc_asin_finite); 48252149f03SSanjay Patel TLI.setUnavailable(LibFunc_asinf_finite); 48352149f03SSanjay Patel TLI.setUnavailable(LibFunc_asinl_finite); 48452149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2_finite); 48552149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2f_finite); 48652149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2l_finite); 48752149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanh_finite); 48852149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanhf_finite); 48952149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanhl_finite); 49052149f03SSanjay Patel TLI.setUnavailable(LibFunc_cosh_finite); 49152149f03SSanjay Patel TLI.setUnavailable(LibFunc_coshf_finite); 49252149f03SSanjay Patel TLI.setUnavailable(LibFunc_coshl_finite); 49352149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10_finite); 49452149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10f_finite); 49552149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10l_finite); 49652149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2_finite); 49752149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2f_finite); 49852149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2l_finite); 49952149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp_finite); 50052149f03SSanjay Patel TLI.setUnavailable(LibFunc_expf_finite); 50152149f03SSanjay Patel TLI.setUnavailable(LibFunc_expl_finite); 50252149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10_finite); 50352149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10f_finite); 50452149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10l_finite); 50552149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2_finite); 50652149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2f_finite); 50752149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2l_finite); 50852149f03SSanjay Patel TLI.setUnavailable(LibFunc_log_finite); 50952149f03SSanjay Patel TLI.setUnavailable(LibFunc_logf_finite); 51052149f03SSanjay Patel TLI.setUnavailable(LibFunc_logl_finite); 51152149f03SSanjay Patel TLI.setUnavailable(LibFunc_pow_finite); 51252149f03SSanjay Patel TLI.setUnavailable(LibFunc_powf_finite); 51352149f03SSanjay Patel TLI.setUnavailable(LibFunc_powl_finite); 51452149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinh_finite); 51552149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinhf_finite); 51652149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinhl_finite); 51762d4215bSChandler Carruth } 5186d8a2aa9SMichael Zolotukhin 519c1078872SMartin Storsjo if ((T.isOSLinux() && T.isGNUEnvironment()) || 520c1078872SMartin Storsjo (T.isAndroid() && !T.isAndroidVersionLT(28))) { 521ca22d427SDavid Bolvansky // available IO unlocked variants on GNU/Linux and Android P or later 522ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getc_unlocked); 523ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getchar_unlocked); 524ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putc_unlocked); 525ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putchar_unlocked); 526ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fputc_unlocked); 527ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fgetc_unlocked); 528ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fread_unlocked); 529ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fwrite_unlocked); 530ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fputs_unlocked); 531ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fgets_unlocked); 532ca22d427SDavid Bolvansky } 533ca22d427SDavid Bolvansky 53451132881SJustin Lebar // As currently implemented in clang, NVPTX code has no standard library to 53551132881SJustin Lebar // speak of. Headers provide a standard-ish library implementation, but many 53651132881SJustin Lebar // of the signatures are wrong -- for example, many libm functions are not 53751132881SJustin Lebar // extern "C". 53851132881SJustin Lebar // 53951132881SJustin Lebar // libdevice, an IR library provided by nvidia, is linked in by the front-end, 54051132881SJustin Lebar // but only used functions are provided to llvm. Moreover, most of the 54151132881SJustin Lebar // functions in libdevice don't map precisely to standard library functions. 54251132881SJustin Lebar // 54351132881SJustin Lebar // FIXME: Having no standard library prevents e.g. many fastmath 54451132881SJustin Lebar // optimizations, so this situation should be fixed. 545ae272d71SDavid Majnemer if (T.isNVPTX()) { 54651132881SJustin Lebar TLI.disableAllFunctions(); 547d21529faSDavid L. Jones TLI.setAvailable(LibFunc_nvvm_reflect); 548ae272d71SDavid Majnemer } else { 549d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nvvm_reflect); 550ae272d71SDavid Majnemer } 55151132881SJustin Lebar 5526d8a2aa9SMichael Zolotukhin TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); 55362d4215bSChandler Carruth } 55462d4215bSChandler Carruth 555c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() { 55662d4215bSChandler Carruth // Default to everything being available. 55762d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 55862d4215bSChandler Carruth 55962d4215bSChandler Carruth initialize(*this, Triple(), StandardNames); 56062d4215bSChandler Carruth } 56162d4215bSChandler Carruth 5627459398aSJoel Jones TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { 56362d4215bSChandler Carruth // Default to everything being available. 56462d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 56562d4215bSChandler Carruth 56662d4215bSChandler Carruth initialize(*this, T, StandardNames); 56762d4215bSChandler Carruth } 56862d4215bSChandler Carruth 569c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) 5707459398aSJoel Jones : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), 5715ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 5725ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 57362d4215bSChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 574e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 575e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 5768ca43224SChandler Carruth } 5778ca43224SChandler Carruth 578c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) 5797459398aSJoel Jones : CustomNames(std::move(TLI.CustomNames)), 5805ae2c526SMarcin Koscielnicki ShouldExtI32Param(TLI.ShouldExtI32Param), 5815ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 5825ae2c526SMarcin Koscielnicki ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) { 5838ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 5848ca43224SChandler Carruth AvailableArray); 585e8f2551fSMichael Zolotukhin VectorDescs = TLI.VectorDescs; 586e8f2551fSMichael Zolotukhin ScalarDescs = TLI.ScalarDescs; 5878ca43224SChandler Carruth } 5888ca43224SChandler Carruth 589c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { 59062d4215bSChandler Carruth CustomNames = TLI.CustomNames; 5915ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 5925ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 5935ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 5948ca43224SChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 5958ca43224SChandler Carruth return *this; 5968ca43224SChandler Carruth } 5978ca43224SChandler Carruth 598c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { 5998ca43224SChandler Carruth CustomNames = std::move(TLI.CustomNames); 6005ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 6015ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 6025ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 6038ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 6048ca43224SChandler Carruth AvailableArray); 6058ca43224SChandler Carruth return *this; 60662d4215bSChandler Carruth } 60762d4215bSChandler Carruth 60821abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) { 60962d4215bSChandler Carruth // Filter out empty names and names containing null bytes, those can't be in 61062d4215bSChandler Carruth // our table. 61162d4215bSChandler Carruth if (funcName.empty() || funcName.find('\0') != StringRef::npos) 61221abdf98SMichael Zolotukhin return StringRef(); 61362d4215bSChandler Carruth 61462d4215bSChandler Carruth // Check for \01 prefix that is used to mangle __asm declarations and 61562d4215bSChandler Carruth // strip it if present. 6166f0ecca3SPeter Collingbourne return GlobalValue::dropLLVMManglingEscape(funcName); 61721abdf98SMichael Zolotukhin } 61821abdf98SMichael Zolotukhin 619d5e60669SBenjamin Kramer bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const { 62021abdf98SMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 62121abdf98SMichael Zolotukhin if (funcName.empty()) 62221abdf98SMichael Zolotukhin return false; 62321abdf98SMichael Zolotukhin 624d5e60669SBenjamin Kramer const auto *Start = std::begin(StandardNames); 625d5e60669SBenjamin Kramer const auto *End = std::end(StandardNames); 626d5e60669SBenjamin Kramer const auto *I = std::lower_bound(Start, End, funcName); 62762d4215bSChandler Carruth if (I != End && *I == funcName) { 628d21529faSDavid L. Jones F = (LibFunc)(I - Start); 62962d4215bSChandler Carruth return true; 63062d4215bSChandler Carruth } 63162d4215bSChandler Carruth return false; 63262d4215bSChandler Carruth } 63362d4215bSChandler Carruth 634d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, 635d21529faSDavid L. Jones LibFunc F, 636d765a82bSAhmed Bougacha const DataLayout *DL) const { 637d765a82bSAhmed Bougacha LLVMContext &Ctx = FTy.getContext(); 638d765a82bSAhmed Bougacha Type *PCharTy = Type::getInt8PtrTy(Ctx); 639d765a82bSAhmed Bougacha Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr; 640d765a82bSAhmed Bougacha auto IsSizeTTy = [SizeTTy](Type *Ty) { 641d765a82bSAhmed Bougacha return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); 642d765a82bSAhmed Bougacha }; 643d765a82bSAhmed Bougacha unsigned NumParams = FTy.getNumParams(); 644d765a82bSAhmed Bougacha 645d765a82bSAhmed Bougacha switch (F) { 646c3bed1e8SCalixte Denizet case LibFunc_execl: 647c3bed1e8SCalixte Denizet case LibFunc_execlp: 6488f07efc7SCalixte Denizet case LibFunc_execle: 649c3bed1e8SCalixte Denizet return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 650c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 651c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 652c3bed1e8SCalixte Denizet case LibFunc_execv: 653c3bed1e8SCalixte Denizet case LibFunc_execvp: 654c3bed1e8SCalixte Denizet return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 655c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 656c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 657c3bed1e8SCalixte Denizet case LibFunc_execvP: 658c3bed1e8SCalixte Denizet case LibFunc_execvpe: 659c3bed1e8SCalixte Denizet case LibFunc_execve: 660c3bed1e8SCalixte Denizet return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 661c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 662c3bed1e8SCalixte Denizet FTy.getParamType(2)->isPointerTy() && 663c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 664d21529faSDavid L. Jones case LibFunc_strlen: 665d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 666d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 667d765a82bSAhmed Bougacha 668d21529faSDavid L. Jones case LibFunc_strchr: 669d21529faSDavid L. Jones case LibFunc_strrchr: 670d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 671d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 672d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy()); 673d765a82bSAhmed Bougacha 674d21529faSDavid L. Jones case LibFunc_strtol: 675d21529faSDavid L. Jones case LibFunc_strtod: 676d21529faSDavid L. Jones case LibFunc_strtof: 677d21529faSDavid L. Jones case LibFunc_strtoul: 678d21529faSDavid L. Jones case LibFunc_strtoll: 679d21529faSDavid L. Jones case LibFunc_strtold: 680d21529faSDavid L. Jones case LibFunc_strtoull: 681d765a82bSAhmed Bougacha return ((NumParams == 2 || NumParams == 3) && 682d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 683d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 684abb2a93cSErik Pilkington case LibFunc_strcat_chk: 685abb2a93cSErik Pilkington --NumParams; 686abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 687abb2a93cSErik Pilkington return false; 688abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 689d21529faSDavid L. Jones case LibFunc_strcat: 690d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 691d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 692d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType()); 693d765a82bSAhmed Bougacha 694abb2a93cSErik Pilkington case LibFunc_strncat_chk: 695abb2a93cSErik Pilkington --NumParams; 696abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 697abb2a93cSErik Pilkington return false; 698abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 699d21529faSDavid L. Jones case LibFunc_strncat: 700d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 701d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 702d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType() && 7037bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 704d765a82bSAhmed Bougacha 705d21529faSDavid L. Jones case LibFunc_strcpy_chk: 706d21529faSDavid L. Jones case LibFunc_stpcpy_chk: 707d765a82bSAhmed Bougacha --NumParams; 708d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 709d765a82bSAhmed Bougacha return false; 710b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 711d21529faSDavid L. Jones case LibFunc_strcpy: 712d21529faSDavid L. Jones case LibFunc_stpcpy: 713d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && 714d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 715d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy); 716d765a82bSAhmed Bougacha 717abb2a93cSErik Pilkington case LibFunc_strlcat_chk: 718abb2a93cSErik Pilkington case LibFunc_strlcpy_chk: 719abb2a93cSErik Pilkington --NumParams; 720abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 721abb2a93cSErik Pilkington return false; 722abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 723abb2a93cSErik Pilkington case LibFunc_strlcat: 724abb2a93cSErik Pilkington case LibFunc_strlcpy: 725abb2a93cSErik Pilkington return NumParams == 3 && IsSizeTTy(FTy.getReturnType()) && 726abb2a93cSErik Pilkington FTy.getParamType(0)->isPointerTy() && 727abb2a93cSErik Pilkington FTy.getParamType(1)->isPointerTy() && 728abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(2)); 729abb2a93cSErik Pilkington 730d21529faSDavid L. Jones case LibFunc_strncpy_chk: 731d21529faSDavid L. Jones case LibFunc_stpncpy_chk: 732d765a82bSAhmed Bougacha --NumParams; 733d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 734d765a82bSAhmed Bougacha return false; 735b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 736d21529faSDavid L. Jones case LibFunc_strncpy: 737d21529faSDavid L. Jones case LibFunc_stpncpy: 738d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 739d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 740d765a82bSAhmed Bougacha FTy.getParamType(0) == PCharTy && 7417bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 742d765a82bSAhmed Bougacha 743d21529faSDavid L. Jones case LibFunc_strxfrm: 744d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 745d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 746d765a82bSAhmed Bougacha 747d21529faSDavid L. Jones case LibFunc_strcmp: 748d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && 749d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 750d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 751d765a82bSAhmed Bougacha 752d21529faSDavid L. Jones case LibFunc_strncmp: 753d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 754d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 755d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 7567bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 757d765a82bSAhmed Bougacha 758d21529faSDavid L. Jones case LibFunc_strspn: 759d21529faSDavid L. Jones case LibFunc_strcspn: 760d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 761d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 762d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 763d765a82bSAhmed Bougacha 764d21529faSDavid L. Jones case LibFunc_strcoll: 765d21529faSDavid L. Jones case LibFunc_strcasecmp: 766d21529faSDavid L. Jones case LibFunc_strncasecmp: 767d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 768d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 769d765a82bSAhmed Bougacha 770d21529faSDavid L. Jones case LibFunc_strstr: 771d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 772d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 773d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 774d765a82bSAhmed Bougacha 775d21529faSDavid L. Jones case LibFunc_strpbrk: 776d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 777d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 778d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 779d765a82bSAhmed Bougacha 780d21529faSDavid L. Jones case LibFunc_strtok: 781d21529faSDavid L. Jones case LibFunc_strtok_r: 782d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 783d21529faSDavid L. Jones case LibFunc_scanf: 784d21529faSDavid L. Jones case LibFunc_setbuf: 785d21529faSDavid L. Jones case LibFunc_setvbuf: 786d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 787d21529faSDavid L. Jones case LibFunc_strdup: 788d21529faSDavid L. Jones case LibFunc_strndup: 789d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 790d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 791d21529faSDavid L. Jones case LibFunc_sscanf: 792d21529faSDavid L. Jones case LibFunc_stat: 793d21529faSDavid L. Jones case LibFunc_statvfs: 794d21529faSDavid L. Jones case LibFunc_siprintf: 795b4f9991fSAlon Zakai case LibFunc_small_sprintf: 796d21529faSDavid L. Jones case LibFunc_sprintf: 797d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 7980d7c3775SMartin Storsjo FTy.getParamType(1)->isPointerTy() && 7990d7c3775SMartin Storsjo FTy.getReturnType()->isIntegerTy(32)); 800abb2a93cSErik Pilkington 801abb2a93cSErik Pilkington case LibFunc_sprintf_chk: 802abb2a93cSErik Pilkington return NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 803abb2a93cSErik Pilkington FTy.getParamType(1)->isIntegerTy(32) && 804abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(2)) && 805abb2a93cSErik Pilkington FTy.getParamType(3)->isPointerTy() && 806abb2a93cSErik Pilkington FTy.getReturnType()->isIntegerTy(32); 807abb2a93cSErik Pilkington 808d21529faSDavid L. Jones case LibFunc_snprintf: 809d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 8100d7c3775SMartin Storsjo FTy.getParamType(2)->isPointerTy() && 8110d7c3775SMartin Storsjo FTy.getReturnType()->isIntegerTy(32)); 812abb2a93cSErik Pilkington 813abb2a93cSErik Pilkington case LibFunc_snprintf_chk: 814abb2a93cSErik Pilkington return NumParams == 5 && FTy.getParamType(0)->isPointerTy() && 815abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(1)) && 816abb2a93cSErik Pilkington FTy.getParamType(2)->isIntegerTy(32) && 817abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(3)) && 818abb2a93cSErik Pilkington FTy.getParamType(4)->isPointerTy() && 819abb2a93cSErik Pilkington FTy.getReturnType()->isIntegerTy(32); 820abb2a93cSErik Pilkington 821d21529faSDavid L. Jones case LibFunc_setitimer: 822d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 823d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 824d21529faSDavid L. Jones case LibFunc_system: 825d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 826d21529faSDavid L. Jones case LibFunc_malloc: 827d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 828d21529faSDavid L. Jones case LibFunc_memcmp: 8296b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 8306b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 8316b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 832d765a82bSAhmed Bougacha 833d21529faSDavid L. Jones case LibFunc_memchr: 834d21529faSDavid L. Jones case LibFunc_memrchr: 8356b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 8366b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 837d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32) && 8386b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 839d21529faSDavid L. Jones case LibFunc_modf: 840d21529faSDavid L. Jones case LibFunc_modff: 841d21529faSDavid L. Jones case LibFunc_modfl: 842d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 843d765a82bSAhmed Bougacha 844d21529faSDavid L. Jones case LibFunc_memcpy_chk: 845d21529faSDavid L. Jones case LibFunc_memmove_chk: 846d765a82bSAhmed Bougacha --NumParams; 847d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 848d765a82bSAhmed Bougacha return false; 849b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 850d21529faSDavid L. Jones case LibFunc_memcpy: 851d21529faSDavid L. Jones case LibFunc_mempcpy: 852d21529faSDavid L. Jones case LibFunc_memmove: 853d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 854d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 855d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 856d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 857d765a82bSAhmed Bougacha 858d21529faSDavid L. Jones case LibFunc_memset_chk: 859d765a82bSAhmed Bougacha --NumParams; 860d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 861d765a82bSAhmed Bougacha return false; 862b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 863d21529faSDavid L. Jones case LibFunc_memset: 864d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 865d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 866d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 867d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 868d765a82bSAhmed Bougacha 869abb2a93cSErik Pilkington case LibFunc_memccpy_chk: 870abb2a93cSErik Pilkington --NumParams; 871abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 872abb2a93cSErik Pilkington return false; 873abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 874d21529faSDavid L. Jones case LibFunc_memccpy: 875d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 876d21529faSDavid L. Jones case LibFunc_memalign: 877d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 878d21529faSDavid L. Jones case LibFunc_realloc: 879d21529faSDavid L. Jones case LibFunc_reallocf: 8806b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == PCharTy && 8816b9be1dbSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 8826b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(1))); 883d21529faSDavid L. Jones case LibFunc_read: 884d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 885d21529faSDavid L. Jones case LibFunc_rewind: 886d21529faSDavid L. Jones case LibFunc_rmdir: 887d21529faSDavid L. Jones case LibFunc_remove: 888d21529faSDavid L. Jones case LibFunc_realpath: 889d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 890d21529faSDavid L. Jones case LibFunc_rename: 891d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 892d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 893d21529faSDavid L. Jones case LibFunc_readlink: 894d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 895d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 896d21529faSDavid L. Jones case LibFunc_write: 897d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 898d21529faSDavid L. Jones case LibFunc_bcopy: 899d21529faSDavid L. Jones case LibFunc_bcmp: 900d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 901d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 902d21529faSDavid L. Jones case LibFunc_bzero: 903d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 904d21529faSDavid L. Jones case LibFunc_calloc: 905d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 9061fe3f1caSAhmed Bougacha 907d21529faSDavid L. Jones case LibFunc_atof: 908d21529faSDavid L. Jones case LibFunc_atoi: 909d21529faSDavid L. Jones case LibFunc_atol: 910d21529faSDavid L. Jones case LibFunc_atoll: 911d21529faSDavid L. Jones case LibFunc_ferror: 912d21529faSDavid L. Jones case LibFunc_getenv: 913d21529faSDavid L. Jones case LibFunc_getpwnam: 914d21529faSDavid L. Jones case LibFunc_iprintf: 915b4f9991fSAlon Zakai case LibFunc_small_printf: 916d21529faSDavid L. Jones case LibFunc_pclose: 917d21529faSDavid L. Jones case LibFunc_perror: 918d21529faSDavid L. Jones case LibFunc_printf: 919d21529faSDavid L. Jones case LibFunc_puts: 920d21529faSDavid L. Jones case LibFunc_uname: 921d21529faSDavid L. Jones case LibFunc_under_IO_getc: 922d21529faSDavid L. Jones case LibFunc_unlink: 923d21529faSDavid L. Jones case LibFunc_unsetenv: 924d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 9251fe3f1caSAhmed Bougacha 926d21529faSDavid L. Jones case LibFunc_access: 927d21529faSDavid L. Jones case LibFunc_chmod: 928d21529faSDavid L. Jones case LibFunc_chown: 929d21529faSDavid L. Jones case LibFunc_clearerr: 930d21529faSDavid L. Jones case LibFunc_closedir: 931d21529faSDavid L. Jones case LibFunc_ctermid: 932d21529faSDavid L. Jones case LibFunc_fclose: 933d21529faSDavid L. Jones case LibFunc_feof: 934d21529faSDavid L. Jones case LibFunc_fflush: 935d21529faSDavid L. Jones case LibFunc_fgetc: 936ca22d427SDavid Bolvansky case LibFunc_fgetc_unlocked: 937d21529faSDavid L. Jones case LibFunc_fileno: 938d21529faSDavid L. Jones case LibFunc_flockfile: 939d21529faSDavid L. Jones case LibFunc_free: 940d21529faSDavid L. Jones case LibFunc_fseek: 941d21529faSDavid L. Jones case LibFunc_fseeko64: 942d21529faSDavid L. Jones case LibFunc_fseeko: 943d21529faSDavid L. Jones case LibFunc_fsetpos: 944d21529faSDavid L. Jones case LibFunc_ftell: 945d21529faSDavid L. Jones case LibFunc_ftello64: 946d21529faSDavid L. Jones case LibFunc_ftello: 947d21529faSDavid L. Jones case LibFunc_ftrylockfile: 948d21529faSDavid L. Jones case LibFunc_funlockfile: 949d21529faSDavid L. Jones case LibFunc_getc: 950d21529faSDavid L. Jones case LibFunc_getc_unlocked: 951d21529faSDavid L. Jones case LibFunc_getlogin_r: 952d21529faSDavid L. Jones case LibFunc_mkdir: 953d21529faSDavid L. Jones case LibFunc_mktime: 954d21529faSDavid L. Jones case LibFunc_times: 9551fe3f1caSAhmed Bougacha return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); 9561fe3f1caSAhmed Bougacha 957d21529faSDavid L. Jones case LibFunc_fopen: 958d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 959d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 960d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 961c3bed1e8SCalixte Denizet case LibFunc_fork: 962c3bed1e8SCalixte Denizet return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32)); 963d21529faSDavid L. Jones case LibFunc_fdopen: 964d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 965d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 966d21529faSDavid L. Jones case LibFunc_fputc: 967ca22d427SDavid Bolvansky case LibFunc_fputc_unlocked: 968d21529faSDavid L. Jones case LibFunc_fstat: 969d21529faSDavid L. Jones case LibFunc_frexp: 970d21529faSDavid L. Jones case LibFunc_frexpf: 971d21529faSDavid L. Jones case LibFunc_frexpl: 972d21529faSDavid L. Jones case LibFunc_fstatvfs: 973d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 974d21529faSDavid L. Jones case LibFunc_fgets: 975ca22d427SDavid Bolvansky case LibFunc_fgets_unlocked: 976d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 977d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 978d21529faSDavid L. Jones case LibFunc_fread: 979ca22d427SDavid Bolvansky case LibFunc_fread_unlocked: 980d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 981d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 982d21529faSDavid L. Jones case LibFunc_fwrite: 983ca22d427SDavid Bolvansky case LibFunc_fwrite_unlocked: 984d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && 985d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 986d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 987d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy() && 988d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 989d21529faSDavid L. Jones case LibFunc_fputs: 990ca22d427SDavid Bolvansky case LibFunc_fputs_unlocked: 991d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 992d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 993d21529faSDavid L. Jones case LibFunc_fscanf: 994d21529faSDavid L. Jones case LibFunc_fiprintf: 995b4f9991fSAlon Zakai case LibFunc_small_fprintf: 996d21529faSDavid L. Jones case LibFunc_fprintf: 9976b9be1dbSAhmed Bougacha return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() && 9986b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 999d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1000d21529faSDavid L. Jones case LibFunc_fgetpos: 1001d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1002d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1003d21529faSDavid L. Jones case LibFunc_getchar: 1004ca22d427SDavid Bolvansky case LibFunc_getchar_unlocked: 10056b9be1dbSAhmed Bougacha return (NumParams == 0 && FTy.getReturnType()->isIntegerTy()); 1006d21529faSDavid L. Jones case LibFunc_gets: 10076b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0) == PCharTy); 1008d21529faSDavid L. Jones case LibFunc_getitimer: 1009d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1010d21529faSDavid L. Jones case LibFunc_ungetc: 1011d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1012d21529faSDavid L. Jones case LibFunc_utime: 1013d21529faSDavid L. Jones case LibFunc_utimes: 1014d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1015d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1016d21529faSDavid L. Jones case LibFunc_putc: 1017ca22d427SDavid Bolvansky case LibFunc_putc_unlocked: 1018d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1019d21529faSDavid L. Jones case LibFunc_pread: 1020d21529faSDavid L. Jones case LibFunc_pwrite: 1021d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); 1022d21529faSDavid L. Jones case LibFunc_popen: 1023d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1024d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1025d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1026d21529faSDavid L. Jones case LibFunc_vscanf: 1027d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1028d21529faSDavid L. Jones case LibFunc_vsscanf: 1029d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1030d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1031d21529faSDavid L. Jones case LibFunc_vfscanf: 1032d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1033d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1034d21529faSDavid L. Jones case LibFunc_valloc: 1035d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1036d21529faSDavid L. Jones case LibFunc_vprintf: 1037d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1038d21529faSDavid L. Jones case LibFunc_vfprintf: 1039d21529faSDavid L. Jones case LibFunc_vsprintf: 1040d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1041d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1042abb2a93cSErik Pilkington case LibFunc_vsprintf_chk: 1043abb2a93cSErik Pilkington return NumParams == 5 && FTy.getParamType(0)->isPointerTy() && 1044abb2a93cSErik Pilkington FTy.getParamType(1)->isIntegerTy(32) && 1045abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(2)) && FTy.getParamType(3)->isPointerTy(); 1046d21529faSDavid L. Jones case LibFunc_vsnprintf: 1047d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 1048d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1049abb2a93cSErik Pilkington case LibFunc_vsnprintf_chk: 1050abb2a93cSErik Pilkington return NumParams == 6 && FTy.getParamType(0)->isPointerTy() && 1051abb2a93cSErik Pilkington FTy.getParamType(2)->isIntegerTy(32) && 1052abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(3)) && FTy.getParamType(4)->isPointerTy(); 1053d21529faSDavid L. Jones case LibFunc_open: 1054d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1055d21529faSDavid L. Jones case LibFunc_opendir: 1056d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && 1057d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 1058d21529faSDavid L. Jones case LibFunc_tmpfile: 1059d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1060d21529faSDavid L. Jones case LibFunc_htonl: 1061d21529faSDavid L. Jones case LibFunc_ntohl: 10626b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 10636b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1064d21529faSDavid L. Jones case LibFunc_htons: 1065d21529faSDavid L. Jones case LibFunc_ntohs: 10666b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) && 10676b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1068d21529faSDavid L. Jones case LibFunc_lstat: 1069d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1070d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1071d21529faSDavid L. Jones case LibFunc_lchown: 1072d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 1073d21529faSDavid L. Jones case LibFunc_qsort: 1074d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); 1075d21529faSDavid L. Jones case LibFunc_dunder_strdup: 1076d21529faSDavid L. Jones case LibFunc_dunder_strndup: 1077d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 1078d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 1079d21529faSDavid L. Jones case LibFunc_dunder_strtok_r: 1080d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 1081d21529faSDavid L. Jones case LibFunc_under_IO_putc: 1082d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1083d21529faSDavid L. Jones case LibFunc_dunder_isoc99_scanf: 1084d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 1085d21529faSDavid L. Jones case LibFunc_stat64: 1086d21529faSDavid L. Jones case LibFunc_lstat64: 1087d21529faSDavid L. Jones case LibFunc_statvfs64: 108879dcc274SMichael Kuperstein return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1089d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1090d21529faSDavid L. Jones case LibFunc_dunder_isoc99_sscanf: 109179dcc274SMichael Kuperstein return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1092d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1093d21529faSDavid L. Jones case LibFunc_fopen64: 1094d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1095d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1096d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1097d21529faSDavid L. Jones case LibFunc_tmpfile64: 1098d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1099d21529faSDavid L. Jones case LibFunc_fstat64: 1100d21529faSDavid L. Jones case LibFunc_fstatvfs64: 1101d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1102d21529faSDavid L. Jones case LibFunc_open64: 1103d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1104d21529faSDavid L. Jones case LibFunc_gettimeofday: 1105d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1106d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1107d765a82bSAhmed Bougacha 11086b9be1dbSAhmed Bougacha // new(unsigned int); 1109d21529faSDavid L. Jones case LibFunc_Znwj: 11106b9be1dbSAhmed Bougacha // new(unsigned long); 1111d21529faSDavid L. Jones case LibFunc_Znwm: 11126b9be1dbSAhmed Bougacha // new[](unsigned int); 1113d21529faSDavid L. Jones case LibFunc_Znaj: 11146b9be1dbSAhmed Bougacha // new[](unsigned long); 1115d21529faSDavid L. Jones case LibFunc_Znam: 11166b9be1dbSAhmed Bougacha // new(unsigned int); 1117d21529faSDavid L. Jones case LibFunc_msvc_new_int: 11186b9be1dbSAhmed Bougacha // new(unsigned long long); 1119d21529faSDavid L. Jones case LibFunc_msvc_new_longlong: 11206b9be1dbSAhmed Bougacha // new[](unsigned int); 1121d21529faSDavid L. Jones case LibFunc_msvc_new_array_int: 11226b9be1dbSAhmed Bougacha // new[](unsigned long long); 1123d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong: 11246b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 11256b9be1dbSAhmed Bougacha 11266b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 1127d21529faSDavid L. Jones case LibFunc_ZnwjRKSt9nothrow_t: 11286b9be1dbSAhmed Bougacha // new(unsigned long, nothrow); 1129d21529faSDavid L. Jones case LibFunc_ZnwmRKSt9nothrow_t: 11306b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 1131d21529faSDavid L. Jones case LibFunc_ZnajRKSt9nothrow_t: 11326b9be1dbSAhmed Bougacha // new[](unsigned long, nothrow); 1133d21529faSDavid L. Jones case LibFunc_ZnamRKSt9nothrow_t: 11346b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 1135d21529faSDavid L. Jones case LibFunc_msvc_new_int_nothrow: 11366b9be1dbSAhmed Bougacha // new(unsigned long long, nothrow); 1137d21529faSDavid L. Jones case LibFunc_msvc_new_longlong_nothrow: 11386b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 1139d21529faSDavid L. Jones case LibFunc_msvc_new_array_int_nothrow: 11406b9be1dbSAhmed Bougacha // new[](unsigned long long, nothrow); 1141d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong_nothrow: 114296bbec79SEric Fiselier // new(unsigned int, align_val_t) 114396bbec79SEric Fiselier case LibFunc_ZnwjSt11align_val_t: 114496bbec79SEric Fiselier // new(unsigned long, align_val_t) 114596bbec79SEric Fiselier case LibFunc_ZnwmSt11align_val_t: 114696bbec79SEric Fiselier // new[](unsigned int, align_val_t) 114796bbec79SEric Fiselier case LibFunc_ZnajSt11align_val_t: 114896bbec79SEric Fiselier // new[](unsigned long, align_val_t) 114996bbec79SEric Fiselier case LibFunc_ZnamSt11align_val_t: 11506b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 11516b9be1dbSAhmed Bougacha 115296bbec79SEric Fiselier // new(unsigned int, align_val_t, nothrow) 115396bbec79SEric Fiselier case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: 115496bbec79SEric Fiselier // new(unsigned long, align_val_t, nothrow) 115596bbec79SEric Fiselier case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: 115696bbec79SEric Fiselier // new[](unsigned int, align_val_t, nothrow) 115796bbec79SEric Fiselier case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: 115896bbec79SEric Fiselier // new[](unsigned long, align_val_t, nothrow) 115996bbec79SEric Fiselier case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: 116096bbec79SEric Fiselier return (NumParams == 3 && FTy.getReturnType()->isPointerTy()); 116196bbec79SEric Fiselier 11626b9be1dbSAhmed Bougacha // void operator delete[](void*); 1163d21529faSDavid L. Jones case LibFunc_ZdaPv: 11646b9be1dbSAhmed Bougacha // void operator delete(void*); 1165d21529faSDavid L. Jones case LibFunc_ZdlPv: 11666b9be1dbSAhmed Bougacha // void operator delete[](void*); 1167d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32: 11686b9be1dbSAhmed Bougacha // void operator delete[](void*); 1169d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64: 11706b9be1dbSAhmed Bougacha // void operator delete(void*); 1171d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32: 11726b9be1dbSAhmed Bougacha // void operator delete(void*); 1173d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64: 11746b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 11756b9be1dbSAhmed Bougacha 11766b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1177d21529faSDavid L. Jones case LibFunc_ZdaPvRKSt9nothrow_t: 11786b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1179d21529faSDavid L. Jones case LibFunc_ZdaPvj: 11806b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long); 1181d21529faSDavid L. Jones case LibFunc_ZdaPvm: 11826b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1183d21529faSDavid L. Jones case LibFunc_ZdlPvRKSt9nothrow_t: 11846b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1185d21529faSDavid L. Jones case LibFunc_ZdlPvj: 11866b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long); 1187d21529faSDavid L. Jones case LibFunc_ZdlPvm: 118896bbec79SEric Fiselier // void operator delete(void*, align_val_t) 118996bbec79SEric Fiselier case LibFunc_ZdlPvSt11align_val_t: 119096bbec79SEric Fiselier // void operator delete[](void*, align_val_t) 119196bbec79SEric Fiselier case LibFunc_ZdaPvSt11align_val_t: 11926b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1193d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_int: 11946b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1195d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_nothrow: 11966b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long long); 1197d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_longlong: 11986b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1199d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_nothrow: 12006b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1201d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_int: 12026b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1203d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_nothrow: 12046b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long long); 1205d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_longlong: 12066b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1207d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_nothrow: 12086b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1209d765a82bSAhmed Bougacha 121096bbec79SEric Fiselier // void operator delete(void*, align_val_t, nothrow) 121196bbec79SEric Fiselier case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t: 121296bbec79SEric Fiselier // void operator delete[](void*, align_val_t, nothrow) 121396bbec79SEric Fiselier case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t: 121496bbec79SEric Fiselier return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 121596bbec79SEric Fiselier 1216d21529faSDavid L. Jones case LibFunc_memset_pattern16: 1217d765a82bSAhmed Bougacha return (!FTy.isVarArg() && NumParams == 3 && 12186b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 12196b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 12206b9be1dbSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 1221d765a82bSAhmed Bougacha 1222d21529faSDavid L. Jones case LibFunc_cxa_guard_abort: 1223d21529faSDavid L. Jones case LibFunc_cxa_guard_acquire: 1224d21529faSDavid L. Jones case LibFunc_cxa_guard_release: 1225d21529faSDavid L. Jones case LibFunc_nvvm_reflect: 12266b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1227d765a82bSAhmed Bougacha 1228d21529faSDavid L. Jones case LibFunc_sincospi_stret: 1229d21529faSDavid L. Jones case LibFunc_sincospif_stret: 12306b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy()); 12316b9be1dbSAhmed Bougacha 1232d21529faSDavid L. Jones case LibFunc_acos: 12333cd8c16dSAndrew Kaylor case LibFunc_acos_finite: 1234d21529faSDavid L. Jones case LibFunc_acosf: 12353cd8c16dSAndrew Kaylor case LibFunc_acosf_finite: 1236d21529faSDavid L. Jones case LibFunc_acosh: 12373cd8c16dSAndrew Kaylor case LibFunc_acosh_finite: 1238d21529faSDavid L. Jones case LibFunc_acoshf: 12393cd8c16dSAndrew Kaylor case LibFunc_acoshf_finite: 1240d21529faSDavid L. Jones case LibFunc_acoshl: 12413cd8c16dSAndrew Kaylor case LibFunc_acoshl_finite: 1242d21529faSDavid L. Jones case LibFunc_acosl: 12433cd8c16dSAndrew Kaylor case LibFunc_acosl_finite: 1244d21529faSDavid L. Jones case LibFunc_asin: 12453cd8c16dSAndrew Kaylor case LibFunc_asin_finite: 1246d21529faSDavid L. Jones case LibFunc_asinf: 12473cd8c16dSAndrew Kaylor case LibFunc_asinf_finite: 1248d21529faSDavid L. Jones case LibFunc_asinh: 1249d21529faSDavid L. Jones case LibFunc_asinhf: 1250d21529faSDavid L. Jones case LibFunc_asinhl: 1251d21529faSDavid L. Jones case LibFunc_asinl: 12523cd8c16dSAndrew Kaylor case LibFunc_asinl_finite: 1253d21529faSDavid L. Jones case LibFunc_atan: 1254d21529faSDavid L. Jones case LibFunc_atanf: 1255d21529faSDavid L. Jones case LibFunc_atanh: 12563cd8c16dSAndrew Kaylor case LibFunc_atanh_finite: 1257d21529faSDavid L. Jones case LibFunc_atanhf: 12583cd8c16dSAndrew Kaylor case LibFunc_atanhf_finite: 1259d21529faSDavid L. Jones case LibFunc_atanhl: 12603cd8c16dSAndrew Kaylor case LibFunc_atanhl_finite: 1261d21529faSDavid L. Jones case LibFunc_atanl: 1262d21529faSDavid L. Jones case LibFunc_cbrt: 1263d21529faSDavid L. Jones case LibFunc_cbrtf: 1264d21529faSDavid L. Jones case LibFunc_cbrtl: 1265d21529faSDavid L. Jones case LibFunc_ceil: 1266d21529faSDavid L. Jones case LibFunc_ceilf: 1267d21529faSDavid L. Jones case LibFunc_ceill: 1268d21529faSDavid L. Jones case LibFunc_cos: 1269d21529faSDavid L. Jones case LibFunc_cosf: 1270d21529faSDavid L. Jones case LibFunc_cosh: 12713cd8c16dSAndrew Kaylor case LibFunc_cosh_finite: 1272d21529faSDavid L. Jones case LibFunc_coshf: 12733cd8c16dSAndrew Kaylor case LibFunc_coshf_finite: 1274d21529faSDavid L. Jones case LibFunc_coshl: 12753cd8c16dSAndrew Kaylor case LibFunc_coshl_finite: 1276d21529faSDavid L. Jones case LibFunc_cosl: 1277d21529faSDavid L. Jones case LibFunc_exp10: 12783cd8c16dSAndrew Kaylor case LibFunc_exp10_finite: 1279d21529faSDavid L. Jones case LibFunc_exp10f: 12803cd8c16dSAndrew Kaylor case LibFunc_exp10f_finite: 1281d21529faSDavid L. Jones case LibFunc_exp10l: 12823cd8c16dSAndrew Kaylor case LibFunc_exp10l_finite: 1283d21529faSDavid L. Jones case LibFunc_exp2: 12843cd8c16dSAndrew Kaylor case LibFunc_exp2_finite: 1285d21529faSDavid L. Jones case LibFunc_exp2f: 12863cd8c16dSAndrew Kaylor case LibFunc_exp2f_finite: 1287d21529faSDavid L. Jones case LibFunc_exp2l: 12883cd8c16dSAndrew Kaylor case LibFunc_exp2l_finite: 1289d21529faSDavid L. Jones case LibFunc_exp: 12903cd8c16dSAndrew Kaylor case LibFunc_exp_finite: 1291d21529faSDavid L. Jones case LibFunc_expf: 12923cd8c16dSAndrew Kaylor case LibFunc_expf_finite: 1293d21529faSDavid L. Jones case LibFunc_expl: 12943cd8c16dSAndrew Kaylor case LibFunc_expl_finite: 1295d21529faSDavid L. Jones case LibFunc_expm1: 1296d21529faSDavid L. Jones case LibFunc_expm1f: 1297d21529faSDavid L. Jones case LibFunc_expm1l: 1298d21529faSDavid L. Jones case LibFunc_fabs: 1299d21529faSDavid L. Jones case LibFunc_fabsf: 1300d21529faSDavid L. Jones case LibFunc_fabsl: 1301d21529faSDavid L. Jones case LibFunc_floor: 1302d21529faSDavid L. Jones case LibFunc_floorf: 1303d21529faSDavid L. Jones case LibFunc_floorl: 1304d21529faSDavid L. Jones case LibFunc_log10: 13053cd8c16dSAndrew Kaylor case LibFunc_log10_finite: 1306d21529faSDavid L. Jones case LibFunc_log10f: 13073cd8c16dSAndrew Kaylor case LibFunc_log10f_finite: 1308d21529faSDavid L. Jones case LibFunc_log10l: 13093cd8c16dSAndrew Kaylor case LibFunc_log10l_finite: 1310d21529faSDavid L. Jones case LibFunc_log1p: 1311d21529faSDavid L. Jones case LibFunc_log1pf: 1312d21529faSDavid L. Jones case LibFunc_log1pl: 1313d21529faSDavid L. Jones case LibFunc_log2: 13143cd8c16dSAndrew Kaylor case LibFunc_log2_finite: 1315d21529faSDavid L. Jones case LibFunc_log2f: 13163cd8c16dSAndrew Kaylor case LibFunc_log2f_finite: 1317d21529faSDavid L. Jones case LibFunc_log2l: 13183cd8c16dSAndrew Kaylor case LibFunc_log2l_finite: 1319d21529faSDavid L. Jones case LibFunc_log: 13203cd8c16dSAndrew Kaylor case LibFunc_log_finite: 1321d21529faSDavid L. Jones case LibFunc_logb: 1322d21529faSDavid L. Jones case LibFunc_logbf: 1323d21529faSDavid L. Jones case LibFunc_logbl: 1324d21529faSDavid L. Jones case LibFunc_logf: 13253cd8c16dSAndrew Kaylor case LibFunc_logf_finite: 1326d21529faSDavid L. Jones case LibFunc_logl: 13273cd8c16dSAndrew Kaylor case LibFunc_logl_finite: 1328d21529faSDavid L. Jones case LibFunc_nearbyint: 1329d21529faSDavid L. Jones case LibFunc_nearbyintf: 1330d21529faSDavid L. Jones case LibFunc_nearbyintl: 1331d21529faSDavid L. Jones case LibFunc_rint: 1332d21529faSDavid L. Jones case LibFunc_rintf: 1333d21529faSDavid L. Jones case LibFunc_rintl: 1334d21529faSDavid L. Jones case LibFunc_round: 1335d21529faSDavid L. Jones case LibFunc_roundf: 1336d21529faSDavid L. Jones case LibFunc_roundl: 1337d21529faSDavid L. Jones case LibFunc_sin: 1338d21529faSDavid L. Jones case LibFunc_sinf: 1339d21529faSDavid L. Jones case LibFunc_sinh: 13403cd8c16dSAndrew Kaylor case LibFunc_sinh_finite: 1341d21529faSDavid L. Jones case LibFunc_sinhf: 13423cd8c16dSAndrew Kaylor case LibFunc_sinhf_finite: 1343d21529faSDavid L. Jones case LibFunc_sinhl: 13443cd8c16dSAndrew Kaylor case LibFunc_sinhl_finite: 1345d21529faSDavid L. Jones case LibFunc_sinl: 1346d21529faSDavid L. Jones case LibFunc_sqrt: 1347d21529faSDavid L. Jones case LibFunc_sqrt_finite: 1348d21529faSDavid L. Jones case LibFunc_sqrtf: 1349d21529faSDavid L. Jones case LibFunc_sqrtf_finite: 1350d21529faSDavid L. Jones case LibFunc_sqrtl: 1351d21529faSDavid L. Jones case LibFunc_sqrtl_finite: 1352d21529faSDavid L. Jones case LibFunc_tan: 1353d21529faSDavid L. Jones case LibFunc_tanf: 1354d21529faSDavid L. Jones case LibFunc_tanh: 1355d21529faSDavid L. Jones case LibFunc_tanhf: 1356d21529faSDavid L. Jones case LibFunc_tanhl: 1357d21529faSDavid L. Jones case LibFunc_tanl: 1358d21529faSDavid L. Jones case LibFunc_trunc: 1359d21529faSDavid L. Jones case LibFunc_truncf: 1360d21529faSDavid L. Jones case LibFunc_truncl: 1361d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && 1362d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1363d765a82bSAhmed Bougacha 1364d21529faSDavid L. Jones case LibFunc_atan2: 13653cd8c16dSAndrew Kaylor case LibFunc_atan2_finite: 1366d21529faSDavid L. Jones case LibFunc_atan2f: 13673cd8c16dSAndrew Kaylor case LibFunc_atan2f_finite: 1368d21529faSDavid L. Jones case LibFunc_atan2l: 13693cd8c16dSAndrew Kaylor case LibFunc_atan2l_finite: 1370d21529faSDavid L. Jones case LibFunc_fmin: 1371d21529faSDavid L. Jones case LibFunc_fminf: 1372d21529faSDavid L. Jones case LibFunc_fminl: 1373d21529faSDavid L. Jones case LibFunc_fmax: 1374d21529faSDavid L. Jones case LibFunc_fmaxf: 1375d21529faSDavid L. Jones case LibFunc_fmaxl: 1376d21529faSDavid L. Jones case LibFunc_fmod: 1377d21529faSDavid L. Jones case LibFunc_fmodf: 1378d21529faSDavid L. Jones case LibFunc_fmodl: 1379d21529faSDavid L. Jones case LibFunc_copysign: 1380d21529faSDavid L. Jones case LibFunc_copysignf: 1381d21529faSDavid L. Jones case LibFunc_copysignl: 1382d21529faSDavid L. Jones case LibFunc_pow: 13833cd8c16dSAndrew Kaylor case LibFunc_pow_finite: 1384d21529faSDavid L. Jones case LibFunc_powf: 13853cd8c16dSAndrew Kaylor case LibFunc_powf_finite: 1386d21529faSDavid L. Jones case LibFunc_powl: 13873cd8c16dSAndrew Kaylor case LibFunc_powl_finite: 1388d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 1389d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 1390d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(1)); 1391d765a82bSAhmed Bougacha 1392d21529faSDavid L. Jones case LibFunc_ldexp: 1393d21529faSDavid L. Jones case LibFunc_ldexpf: 1394d21529faSDavid L. Jones case LibFunc_ldexpl: 13956b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 13966b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 13976b9be1dbSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32)); 13986b9be1dbSAhmed Bougacha 1399d21529faSDavid L. Jones case LibFunc_ffs: 1400d21529faSDavid L. Jones case LibFunc_ffsl: 1401d21529faSDavid L. Jones case LibFunc_ffsll: 1402d21529faSDavid L. Jones case LibFunc_fls: 1403d21529faSDavid L. Jones case LibFunc_flsl: 1404d21529faSDavid L. Jones case LibFunc_flsll: 140504949fafSSanjay Patel return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 140604949fafSSanjay Patel FTy.getParamType(0)->isIntegerTy()); 140704949fafSSanjay Patel 1408d21529faSDavid L. Jones case LibFunc_isdigit: 1409d21529faSDavid L. Jones case LibFunc_isascii: 1410d21529faSDavid L. Jones case LibFunc_toascii: 1411d21529faSDavid L. Jones case LibFunc_putchar: 1412ca22d427SDavid Bolvansky case LibFunc_putchar_unlocked: 1413d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 141404949fafSSanjay Patel FTy.getReturnType() == FTy.getParamType(0)); 1415d765a82bSAhmed Bougacha 1416d21529faSDavid L. Jones case LibFunc_abs: 1417d21529faSDavid L. Jones case LibFunc_labs: 1418d21529faSDavid L. Jones case LibFunc_llabs: 1419d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && 1420d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1421d765a82bSAhmed Bougacha 1422d21529faSDavid L. Jones case LibFunc_cxa_atexit: 1423d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && 1424d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1425d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 1426d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1427d765a82bSAhmed Bougacha 1428d21529faSDavid L. Jones case LibFunc_sinpi: 1429d21529faSDavid L. Jones case LibFunc_cospi: 1430d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && 1431d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1432d765a82bSAhmed Bougacha 1433d21529faSDavid L. Jones case LibFunc_sinpif: 1434d21529faSDavid L. Jones case LibFunc_cospif: 1435d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && 1436d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1437d765a82bSAhmed Bougacha 1438d21529faSDavid L. Jones case LibFunc_strnlen: 14396b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) && 14406b9be1dbSAhmed Bougacha FTy.getParamType(0) == PCharTy && 14416b9be1dbSAhmed Bougacha FTy.getParamType(1) == SizeTTy); 14426b9be1dbSAhmed Bougacha 1443d21529faSDavid L. Jones case LibFunc_posix_memalign: 14446b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 14456b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 14466b9be1dbSAhmed Bougacha FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy); 14476b9be1dbSAhmed Bougacha 144860b40b8fSMatthias Braun case LibFunc_wcslen: 144960b40b8fSMatthias Braun return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 145060b40b8fSMatthias Braun FTy.getReturnType()->isIntegerTy()); 145160b40b8fSMatthias Braun 14522ff24731SHal Finkel case LibFunc_cabs: 14532ff24731SHal Finkel case LibFunc_cabsf: 14542ff24731SHal Finkel case LibFunc_cabsl: { 14552ff24731SHal Finkel Type* RetTy = FTy.getReturnType(); 14562ff24731SHal Finkel if (!RetTy->isFloatingPointTy()) 14572ff24731SHal Finkel return false; 14582ff24731SHal Finkel 14592ff24731SHal Finkel // NOTE: These prototypes are target specific and currently support 14602ff24731SHal Finkel // "complex" passed as an array or discrete real & imaginary parameters. 14612ff24731SHal Finkel // Add other calling conventions to enable libcall optimizations. 14622ff24731SHal Finkel if (NumParams == 1) 14632ff24731SHal Finkel return (FTy.getParamType(0)->isArrayTy() && 14642ff24731SHal Finkel FTy.getParamType(0)->getArrayNumElements() == 2 && 14652ff24731SHal Finkel FTy.getParamType(0)->getArrayElementType() == RetTy); 14662ff24731SHal Finkel else if (NumParams == 2) 14672ff24731SHal Finkel return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy); 14682ff24731SHal Finkel else 14692ff24731SHal Finkel return false; 14702ff24731SHal Finkel } 14716b9be1dbSAhmed Bougacha case LibFunc::NumLibFuncs: 14723b705ef7SEvandro Menezes case LibFunc::NotLibFunc: 147386b680a3SAhmed Bougacha break; 1474d765a82bSAhmed Bougacha } 14756b9be1dbSAhmed Bougacha 147686b680a3SAhmed Bougacha llvm_unreachable("Invalid libfunc"); 1477d765a82bSAhmed Bougacha } 1478d765a82bSAhmed Bougacha 1479d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 1480d21529faSDavid L. Jones LibFunc &F) const { 148176ea748dSPhilip Reames // Intrinsics don't overlap w/libcalls; if our module has a large number of 148276ea748dSPhilip Reames // intrinsics, this ends up being an interesting compile time win since we 148376ea748dSPhilip Reames // avoid string normalization and comparison. 148476ea748dSPhilip Reames if (FDecl.isIntrinsic()) return false; 148576ea748dSPhilip Reames 1486d765a82bSAhmed Bougacha const DataLayout *DL = 1487d765a82bSAhmed Bougacha FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; 1488d765a82bSAhmed Bougacha return getLibFunc(FDecl.getName(), F) && 1489d765a82bSAhmed Bougacha isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); 1490d765a82bSAhmed Bougacha } 1491d765a82bSAhmed Bougacha 1492c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() { 149362d4215bSChandler Carruth memset(AvailableArray, 0, sizeof(AvailableArray)); 149462d4215bSChandler Carruth } 1495b98f63dbSChandler Carruth 1496e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { 14979a72cd7bSMehdi Amini return LHS.ScalarFnName < RHS.ScalarFnName; 1498e8f2551fSMichael Zolotukhin } 1499e8f2551fSMichael Zolotukhin 1500e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { 15019a72cd7bSMehdi Amini return LHS.VectorFnName < RHS.VectorFnName; 1502e8f2551fSMichael Zolotukhin } 1503e8f2551fSMichael Zolotukhin 1504e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { 15059a72cd7bSMehdi Amini return LHS.ScalarFnName < S; 1506e8f2551fSMichael Zolotukhin } 1507e8f2551fSMichael Zolotukhin 1508e8f2551fSMichael Zolotukhin static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) { 15099a72cd7bSMehdi Amini return LHS.VectorFnName < S; 1510e8f2551fSMichael Zolotukhin } 1511e8f2551fSMichael Zolotukhin 1512e8f2551fSMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { 1513e8f2551fSMichael Zolotukhin VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end()); 15140cac726aSFangrui Song llvm::sort(VectorDescs, compareByScalarFnName); 1515e8f2551fSMichael Zolotukhin 1516e8f2551fSMichael Zolotukhin ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end()); 15170cac726aSFangrui Song llvm::sort(ScalarDescs, compareByVectorFnName); 1518e8f2551fSMichael Zolotukhin } 1519e8f2551fSMichael Zolotukhin 15206d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( 15216d8a2aa9SMichael Zolotukhin enum VectorLibrary VecLib) { 15226d8a2aa9SMichael Zolotukhin switch (VecLib) { 15236d8a2aa9SMichael Zolotukhin case Accelerate: { 15246d8a2aa9SMichael Zolotukhin const VecDesc VecFuncs[] = { 1525820b9031SNemanja Ivanovic #define TLI_DEFINE_ACCELERATE_VECFUNCS 1526820b9031SNemanja Ivanovic #include "llvm/Analysis/VecFuncs.def" 15276d8a2aa9SMichael Zolotukhin }; 15286d8a2aa9SMichael Zolotukhin addVectorizableFunctions(VecFuncs); 15296d8a2aa9SMichael Zolotukhin break; 15306d8a2aa9SMichael Zolotukhin } 1531fe97754aSNemanja Ivanovic case MASSV: { 1532fe97754aSNemanja Ivanovic const VecDesc VecFuncs[] = { 1533fe97754aSNemanja Ivanovic #define TLI_DEFINE_MASSV_VECFUNCS 1534fe97754aSNemanja Ivanovic #include "llvm/Analysis/VecFuncs.def" 1535fe97754aSNemanja Ivanovic }; 1536fe97754aSNemanja Ivanovic addVectorizableFunctions(VecFuncs); 1537fe97754aSNemanja Ivanovic break; 1538fe97754aSNemanja Ivanovic } 1539a6669a1eSMatt Masten case SVML: { 1540a6669a1eSMatt Masten const VecDesc VecFuncs[] = { 1541820b9031SNemanja Ivanovic #define TLI_DEFINE_SVML_VECFUNCS 1542820b9031SNemanja Ivanovic #include "llvm/Analysis/VecFuncs.def" 1543a6669a1eSMatt Masten }; 1544a6669a1eSMatt Masten addVectorizableFunctions(VecFuncs); 1545a6669a1eSMatt Masten break; 1546a6669a1eSMatt Masten } 15476d8a2aa9SMichael Zolotukhin case NoLibrary: 15486d8a2aa9SMichael Zolotukhin break; 15496d8a2aa9SMichael Zolotukhin } 15506d8a2aa9SMichael Zolotukhin } 15516d8a2aa9SMichael Zolotukhin 1552e8f2551fSMichael Zolotukhin bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { 1553e8f2551fSMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 1554e8f2551fSMichael Zolotukhin if (funcName.empty()) 1555e8f2551fSMichael Zolotukhin return false; 1556e8f2551fSMichael Zolotukhin 1557cecc4352SFangrui Song std::vector<VecDesc>::const_iterator I = 1558cecc4352SFangrui Song llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName); 1559e8f2551fSMichael Zolotukhin return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; 1560e8f2551fSMichael Zolotukhin } 1561e8f2551fSMichael Zolotukhin 1562e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, 1563e8f2551fSMichael Zolotukhin unsigned VF) const { 1564e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1565e8f2551fSMichael Zolotukhin if (F.empty()) 1566e8f2551fSMichael Zolotukhin return F; 1567cecc4352SFangrui Song std::vector<VecDesc>::const_iterator I = 1568cecc4352SFangrui Song llvm::lower_bound(VectorDescs, F, compareWithScalarFnName); 1569e8f2551fSMichael Zolotukhin while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { 1570e8f2551fSMichael Zolotukhin if (I->VectorizationFactor == VF) 1571e8f2551fSMichael Zolotukhin return I->VectorFnName; 1572e8f2551fSMichael Zolotukhin ++I; 1573e8f2551fSMichael Zolotukhin } 1574e8f2551fSMichael Zolotukhin return StringRef(); 1575e8f2551fSMichael Zolotukhin } 1576e8f2551fSMichael Zolotukhin 1577e8f2551fSMichael Zolotukhin StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F, 1578e8f2551fSMichael Zolotukhin unsigned &VF) const { 1579e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1580e8f2551fSMichael Zolotukhin if (F.empty()) 1581e8f2551fSMichael Zolotukhin return F; 1582e8f2551fSMichael Zolotukhin 1583cecc4352SFangrui Song std::vector<VecDesc>::const_iterator I = 1584cecc4352SFangrui Song llvm::lower_bound(ScalarDescs, F, compareWithVectorFnName); 1585e8f2551fSMichael Zolotukhin if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F) 1586e8f2551fSMichael Zolotukhin return StringRef(); 1587e8f2551fSMichael Zolotukhin VF = I->VectorizationFactor; 1588e8f2551fSMichael Zolotukhin return I->ScalarFnName; 1589e8f2551fSMichael Zolotukhin } 1590e8f2551fSMichael Zolotukhin 1591164a2aa6SChandler Carruth TargetLibraryInfo TargetLibraryAnalysis::run(Function &F, 1592164a2aa6SChandler Carruth FunctionAnalysisManager &) { 1593c0291865SChandler Carruth if (PresetInfoImpl) 1594c0291865SChandler Carruth return TargetLibraryInfo(*PresetInfoImpl); 1595c0291865SChandler Carruth 1596c0291865SChandler Carruth return TargetLibraryInfo( 1597c0291865SChandler Carruth lookupInfoImpl(Triple(F.getParent()->getTargetTriple()))); 1598c0291865SChandler Carruth } 1599c0291865SChandler Carruth 1600c321e534SBenjamin Kramer TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) { 1601c0291865SChandler Carruth std::unique_ptr<TargetLibraryInfoImpl> &Impl = 1602c0291865SChandler Carruth Impls[T.normalize()]; 1603c0291865SChandler Carruth if (!Impl) 1604c0291865SChandler Carruth Impl.reset(new TargetLibraryInfoImpl(T)); 1605c0291865SChandler Carruth 1606c0291865SChandler Carruth return *Impl; 1607c0291865SChandler Carruth } 1608c0291865SChandler Carruth 160950ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const { 161050ec0b5dSMatthias Braun if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>( 161150ec0b5dSMatthias Braun M.getModuleFlag("wchar_size"))) 161250ec0b5dSMatthias Braun return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue(); 1613cc603ee3SMatthias Braun return 0; 161450ec0b5dSMatthias Braun } 1615c0291865SChandler Carruth 1616b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() 1617c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) { 1618b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1619b98f63dbSChandler Carruth } 1620b98f63dbSChandler Carruth 1621b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) 1622c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) { 1623b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1624b98f63dbSChandler Carruth } 1625b98f63dbSChandler Carruth 1626b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( 1627c0291865SChandler Carruth const TargetLibraryInfoImpl &TLIImpl) 1628c0291865SChandler Carruth : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) { 1629b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1630b98f63dbSChandler Carruth } 1631b98f63dbSChandler Carruth 1632dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key; 1633df0cd726SNAKAMURA Takumi 1634b98f63dbSChandler Carruth // Register the basic pass. 1635b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", 1636b98f63dbSChandler Carruth "Target Library Information", false, true) 1637b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0; 1638b98f63dbSChandler Carruth 1639b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {} 1640