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" 1605da2fe5SReid 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"), 2793a9a8a8SFlorian Hahn clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM, 2893a9a8a8SFlorian Hahn "Darwin_libsystem_m", "Darwin libsystem_m"), 2957cdc52cSVenkataramanan Kumar clEnumValN(TargetLibraryInfoImpl::LIBMVEC_X86, "LIBMVEC-X86", 3057cdc52cSVenkataramanan Kumar "GLIBC Vector Math library"), 31fe97754aSNemanja Ivanovic clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV", 32fe97754aSNemanja Ivanovic "IBM MASS vector library"), 33a6669a1eSMatt Masten clEnumValN(TargetLibraryInfoImpl::SVML, "SVML", 347459398aSJoel Jones "Intel SVML library"))); 356d8a2aa9SMichael Zolotukhin 3670434770SBenjamin Kramer StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = 3770434770SBenjamin Kramer { 38cd3d25a2SJan Wen Voung #define TLI_DEFINE_STRING 39cd3d25a2SJan Wen Voung #include "llvm/Analysis/TargetLibraryInfo.def" 4062d4215bSChandler Carruth }; 4162d4215bSChandler Carruth 4262d4215bSChandler Carruth static bool hasSinCosPiStret(const Triple &T) { 4362d4215bSChandler Carruth // Only Darwin variants have _stret versions of combined trig functions. 4462d4215bSChandler Carruth if (!T.isOSDarwin()) 4562d4215bSChandler Carruth return false; 4662d4215bSChandler Carruth 4762d4215bSChandler Carruth // The ABI is rather complicated on x86, so don't do anything special there. 4862d4215bSChandler Carruth if (T.getArch() == Triple::x86) 4962d4215bSChandler Carruth return false; 5062d4215bSChandler Carruth 5162d4215bSChandler Carruth if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) 5262d4215bSChandler Carruth return false; 5362d4215bSChandler Carruth 5462d4215bSChandler Carruth if (T.isiOS() && T.isOSVersionLT(7, 0)) 5562d4215bSChandler Carruth return false; 5662d4215bSChandler Carruth 5762d4215bSChandler Carruth return true; 5862d4215bSChandler Carruth } 5962d4215bSChandler Carruth 608e16d733SClement Courbet static bool hasBcmp(const Triple &TT) { 618e16d733SClement Courbet // Posix removed support from bcmp() in 2001, but the glibc and several 628e16d733SClement Courbet // implementations of the libc still have it. 638e16d733SClement Courbet if (TT.isOSLinux()) 648e16d733SClement Courbet return TT.isGNUEnvironment() || TT.isMusl(); 658e16d733SClement Courbet // Both NetBSD and OpenBSD are planning to remove the function. Windows does 668e16d733SClement Courbet // not have it. 678d5c2803SAlex Lorenz return TT.isOSFreeBSD() || TT.isOSSolaris(); 688e16d733SClement Courbet } 698e16d733SClement Courbet 70c5fda0e6SYuanfang Chen static bool isCallingConvCCompatible(CallingConv::ID CC, StringRef TT, 71c5fda0e6SYuanfang Chen FunctionType *FuncTy) { 72c5fda0e6SYuanfang Chen switch (CC) { 73c5fda0e6SYuanfang Chen default: 74c5fda0e6SYuanfang Chen return false; 75c5fda0e6SYuanfang Chen case llvm::CallingConv::C: 76c5fda0e6SYuanfang Chen return true; 77c5fda0e6SYuanfang Chen case llvm::CallingConv::ARM_APCS: 78c5fda0e6SYuanfang Chen case llvm::CallingConv::ARM_AAPCS: 79c5fda0e6SYuanfang Chen case llvm::CallingConv::ARM_AAPCS_VFP: { 80c5fda0e6SYuanfang Chen 81c5fda0e6SYuanfang Chen // The iOS ABI diverges from the standard in some cases, so for now don't 82c5fda0e6SYuanfang Chen // try to simplify those calls. 83c5fda0e6SYuanfang Chen if (Triple(TT).isiOS()) 84c5fda0e6SYuanfang Chen return false; 85c5fda0e6SYuanfang Chen 86c5fda0e6SYuanfang Chen if (!FuncTy->getReturnType()->isPointerTy() && 87c5fda0e6SYuanfang Chen !FuncTy->getReturnType()->isIntegerTy() && 88c5fda0e6SYuanfang Chen !FuncTy->getReturnType()->isVoidTy()) 89c5fda0e6SYuanfang Chen return false; 90c5fda0e6SYuanfang Chen 91c5fda0e6SYuanfang Chen for (auto *Param : FuncTy->params()) { 92c5fda0e6SYuanfang Chen if (!Param->isPointerTy() && !Param->isIntegerTy()) 93c5fda0e6SYuanfang Chen return false; 94c5fda0e6SYuanfang Chen } 95c5fda0e6SYuanfang Chen return true; 96c5fda0e6SYuanfang Chen } 97c5fda0e6SYuanfang Chen } 98c5fda0e6SYuanfang Chen return false; 99c5fda0e6SYuanfang Chen } 100c5fda0e6SYuanfang Chen 101c5fda0e6SYuanfang Chen bool TargetLibraryInfoImpl::isCallingConvCCompatible(CallBase *CI) { 102c5fda0e6SYuanfang Chen return ::isCallingConvCCompatible(CI->getCallingConv(), 103c5fda0e6SYuanfang Chen CI->getModule()->getTargetTriple(), 104c5fda0e6SYuanfang Chen CI->getFunctionType()); 105c5fda0e6SYuanfang Chen } 106c5fda0e6SYuanfang Chen 107c5fda0e6SYuanfang Chen bool TargetLibraryInfoImpl::isCallingConvCCompatible(Function *F) { 108c5fda0e6SYuanfang Chen return ::isCallingConvCCompatible(F->getCallingConv(), 109c5fda0e6SYuanfang Chen F->getParent()->getTargetTriple(), 110c5fda0e6SYuanfang Chen F->getFunctionType()); 111c5fda0e6SYuanfang Chen } 112c5fda0e6SYuanfang Chen 113600d24b4SSanjay Patel /// Initialize the set of available library functions based on the specified 114600d24b4SSanjay Patel /// target triple. This should be carefully written so that a missing target 115600d24b4SSanjay Patel /// triple gets a sane set of defaults. 116c0291865SChandler Carruth static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, 11770434770SBenjamin Kramer ArrayRef<StringLiteral> StandardNames) { 11862d4215bSChandler Carruth // Verify that the StandardNames array is in alphabetical order. 1191647ff6eSGeorgii Rymar assert( 1201647ff6eSGeorgii Rymar llvm::is_sorted(StandardNames, 1211647ff6eSGeorgii Rymar [](StringRef LHS, StringRef RHS) { return LHS < RHS; }) && 122e30b8ca1SCraig Topper "TargetLibraryInfoImpl function names must be sorted"); 12362d4215bSChandler Carruth 124ca22d427SDavid Bolvansky // Set IO unlocked variants as unavailable 125ca22d427SDavid Bolvansky // Set them as available per system below 126*623cf3dfSRyan Prichard TLI.setUnavailable(LibFunc_getc_unlocked); 127ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_getchar_unlocked); 128ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_putc_unlocked); 129ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_putchar_unlocked); 130ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fputc_unlocked); 131ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fgetc_unlocked); 132ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fread_unlocked); 133ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fwrite_unlocked); 134ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fputs_unlocked); 135ca22d427SDavid Bolvansky TLI.setUnavailable(LibFunc_fgets_unlocked); 136ca22d427SDavid Bolvansky 1376af8e6c3SMarcin Koscielnicki bool ShouldExtI32Param = false, ShouldExtI32Return = false, 1386af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = false; 1396af8e6c3SMarcin Koscielnicki // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and 1406af8e6c3SMarcin Koscielnicki // returns corresponding to C-level ints and unsigned ints. 1413e92df3eSFangrui Song if (T.isPPC64() || T.getArch() == Triple::sparcv9 || 1423e92df3eSFangrui Song T.getArch() == Triple::systemz) { 1436af8e6c3SMarcin Koscielnicki ShouldExtI32Param = true; 1446af8e6c3SMarcin Koscielnicki ShouldExtI32Return = true; 1456af8e6c3SMarcin Koscielnicki } 1466af8e6c3SMarcin Koscielnicki // Mips, on the other hand, needs signext on i32 parameters corresponding 1476af8e6c3SMarcin Koscielnicki // to both signed and unsigned ints. 14885e200e9SAlexander Richardson if (T.isMIPS()) { 1496af8e6c3SMarcin Koscielnicki ShouldSignExtI32Param = true; 1506af8e6c3SMarcin Koscielnicki } 1516af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Param(ShouldExtI32Param); 1526af8e6c3SMarcin Koscielnicki TLI.setShouldExtI32Return(ShouldExtI32Return); 1536af8e6c3SMarcin Koscielnicki TLI.setShouldSignExtI32Param(ShouldSignExtI32Param); 1546af8e6c3SMarcin Koscielnicki 1559c54ee43SBjorn Pettersson // Let's assume by default that the size of int is 32 bits, unless the target 1569c54ee43SBjorn Pettersson // is a 16-bit architecture because then it most likely is 16 bits. If that 1579c54ee43SBjorn Pettersson // isn't true for a target those defaults should be overridden below. 1589c54ee43SBjorn Pettersson TLI.setIntSize(T.isArch16Bit() ? 16 : 32); 1599c54ee43SBjorn Pettersson 160314deab9SYaxun (Sam) Liu if (T.isAMDGPU()) 161c26b3940STim Renouf TLI.disableAllFunctions(); 16278fd4f08SNicolai Hahnle 163ef72cdedSDavid Bolvansky // There are no library implementations of memcpy and memset for AMD gpus and 16462d4215bSChandler Carruth // these can be difficult to lower in the backend. 165314deab9SYaxun (Sam) Liu if (T.isAMDGPU()) { 166d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memcpy); 167d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset); 168d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 1692662351eSJoseph Huber TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared); 1702662351eSJoseph Huber TLI.setAvailable(llvm::LibFunc___kmpc_free_shared); 17162d4215bSChandler Carruth return; 17262d4215bSChandler Carruth } 17362d4215bSChandler Carruth 17462d4215bSChandler Carruth // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. 1758b40366bSTim Northover // All versions of watchOS support it. 17662d4215bSChandler Carruth if (T.isMacOSX()) { 177ca22d427SDavid Bolvansky // available IO unlocked variants on Mac OS X 178ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getc_unlocked); 179ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getchar_unlocked); 180ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putc_unlocked); 181ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putchar_unlocked); 182ca22d427SDavid Bolvansky 18362d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 5)) 184d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 18562d4215bSChandler Carruth } else if (T.isiOS()) { 18662d4215bSChandler Carruth if (T.isOSVersionLT(3, 0)) 187d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 1888b40366bSTim Northover } else if (!T.isWatchOS()) { 189d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memset_pattern16); 19062d4215bSChandler Carruth } 19162d4215bSChandler Carruth 19262d4215bSChandler Carruth if (!hasSinCosPiStret(T)) { 193d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpi); 194d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sinpif); 195d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospi); 196d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_cospif); 197d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospi_stret); 198d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_sincospif_stret); 19962d4215bSChandler Carruth } 20062d4215bSChandler Carruth 2018e16d733SClement Courbet if (!hasBcmp(T)) 2028e16d733SClement Courbet TLI.setUnavailable(LibFunc_bcmp); 2038e16d733SClement Courbet 20462d4215bSChandler Carruth if (T.isMacOSX() && T.getArch() == Triple::x86 && 20562d4215bSChandler Carruth !T.isMacOSXVersionLT(10, 7)) { 20662d4215bSChandler Carruth // x86-32 OSX has a scheme where fwrite and fputs (and some other functions 20762d4215bSChandler Carruth // we don't care about) have two versions; on recent OSX, the one we want 20862d4215bSChandler Carruth // has a $UNIX2003 suffix. The two implementations are identical except 20962d4215bSChandler Carruth // for the return value in some edge cases. However, we don't want to 21062d4215bSChandler Carruth // generate code that depends on the old symbols. 211d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003"); 212d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003"); 21362d4215bSChandler Carruth } 21462d4215bSChandler Carruth 215b4f9991fSAlon Zakai // iprintf and friends are only available on XCore, TCE, and Emscripten. 216b4f9991fSAlon Zakai if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce && 217b4f9991fSAlon Zakai T.getOS() != Triple::Emscripten) { 218d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_iprintf); 219d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_siprintf); 220d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fiprintf); 22162d4215bSChandler Carruth } 22262d4215bSChandler Carruth 223b4f9991fSAlon Zakai // __small_printf and friends are only available on Emscripten. 224b4f9991fSAlon Zakai if (T.getOS() != Triple::Emscripten) { 225b4f9991fSAlon Zakai TLI.setUnavailable(LibFunc_small_printf); 226b4f9991fSAlon Zakai TLI.setUnavailable(LibFunc_small_sprintf); 227b4f9991fSAlon Zakai TLI.setUnavailable(LibFunc_small_fprintf); 228b4f9991fSAlon Zakai } 229b4f9991fSAlon Zakai 23062d4215bSChandler Carruth if (T.isOSWindows() && !T.isOSCygMing()) { 2314b86c474SEvandro Menezes // XXX: The earliest documentation available at the moment is for VS2015/VC19: 2324b86c474SEvandro Menezes // https://docs.microsoft.com/en-us/cpp/c-runtime-library/floating-point-support?view=vs-2015 2334b86c474SEvandro Menezes // XXX: In order to use an MSVCRT older than VC19, 2344b86c474SEvandro Menezes // the specific library version must be explicit in the target triple, 2354b86c474SEvandro Menezes // e.g., x86_64-pc-windows-msvc18. 2364b86c474SEvandro Menezes bool hasPartialC99 = true; 2374b86c474SEvandro Menezes if (T.isKnownWindowsMSVCEnvironment()) { 2384b86c474SEvandro Menezes unsigned Major, Minor, Micro; 2394b86c474SEvandro Menezes T.getEnvironmentVersion(Major, Minor, Micro); 2404b86c474SEvandro Menezes hasPartialC99 = (Major == 0 || Major >= 19); 2414b86c474SEvandro Menezes } 2424b86c474SEvandro Menezes 243f4a36959SEvandro Menezes // Latest targets support C89 math functions, in part. 244f4a36959SEvandro Menezes bool isARM = (T.getArch() == Triple::aarch64 || 245f4a36959SEvandro Menezes T.getArch() == Triple::arm); 246f4a36959SEvandro Menezes bool hasPartialFloat = (isARM || 2474b86c474SEvandro Menezes T.getArch() == Triple::x86_64); 2484b86c474SEvandro Menezes 249f4a36959SEvandro Menezes // Win32 does not support float C89 math functions, in general. 2504b86c474SEvandro Menezes if (!hasPartialFloat) { 251e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_acosf); 252e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_asinf); 253e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_atan2f); 254f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_atanf); 255e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_ceilf); 256e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_cosf); 257e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_coshf); 258e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_expf); 259e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_floorf); 260e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_fmodf); 261e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_log10f); 262f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_logf); 263e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_modff); 264e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_powf); 2652470d298SEhud Katz TLI.setUnavailable(LibFunc_remainderf); 266e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_sinf); 267e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_sinhf); 268e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_sqrtf); 269e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_tanf); 270e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_tanhf); 271e5bb58b1SEvandro Menezes } 272f4a36959SEvandro Menezes if (!isARM) 2734b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_fabsf); 274e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_frexpf); 275e5bb58b1SEvandro Menezes TLI.setUnavailable(LibFunc_ldexpf); 276e5bb58b1SEvandro Menezes 277f4a36959SEvandro Menezes // Win32 does not support long double C89 math functions. 27898f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acosl); 27998f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_asinl); 28098f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_atan2l); 281f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_atanl); 28298f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ceill); 28398f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_cosl); 28498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_coshl); 28598f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_expl); 28698f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fabsl); 28798f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_floorl); 28898f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_fmodl); 28998f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_frexpl); 29098f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_ldexpl); 2914b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log10l); 292f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_logl); 29398f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_modfl); 29498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_powl); 2952470d298SEhud Katz TLI.setUnavailable(LibFunc_remainderl); 29698f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sinl); 29798f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sinhl); 29898f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_sqrtl); 29998f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_tanl); 30098f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_tanhl); 30162d4215bSChandler Carruth 302e5bb58b1SEvandro Menezes // Win32 does not fully support C99 math functions. 3034b86c474SEvandro Menezes if (!hasPartialC99) { 30498f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_acosh); 3054b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_acoshf); 306f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_asinh); 3074b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_asinhf); 308f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_atanh); 3094b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_atanhf); 310f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_cabs, "_cabs"); 3114b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cabsf); 312f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_cbrt); 3134b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cbrtf); 314f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_copysign, "_copysign"); 315f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_copysignf, "_copysignf"); 316f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_exp2); 3174b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_exp2f); 318f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_expm1); 3194b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_expm1f); 320f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmax); 321f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmaxf); 322f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmin); 323f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fminf); 324f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_log1p); 3254b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log1pf); 326f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_log2); 3274b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log2f); 328f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_logb, "_logb"); 329f4a36959SEvandro Menezes if (hasPartialFloat) 330f4a36959SEvandro Menezes TLI.setAvailableWithName(LibFunc_logbf, "_logbf"); 331f4a36959SEvandro Menezes else 3324b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_logbf); 333f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_rint); 3344b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_rintf); 335f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_round); 3364b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_roundf); 337f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_trunc); 33898f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_truncf); 339f4a36959SEvandro Menezes } 3404b86c474SEvandro Menezes 3414b86c474SEvandro Menezes // Win32 does not support long double C99 math functions. 3424b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_acoshl); 3434b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_asinhl); 3444b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_atanhl); 3454b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cabsl); 3464b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_cbrtl); 347f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_copysignl); 3484b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_exp2l); 3494b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_expm1l); 350f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fmaxl); 351f4a36959SEvandro Menezes TLI.setUnavailable(LibFunc_fminl); 3524b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log1pl); 3534b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_log2l); 3544b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_logbl); 3554b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_nearbyintl); 3564b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_rintl); 3574b86c474SEvandro Menezes TLI.setUnavailable(LibFunc_roundl); 35898f356cdSEvandro Menezes TLI.setUnavailable(LibFunc_truncl); 35998f356cdSEvandro Menezes 360e5bb58b1SEvandro Menezes // Win32 does not support these functions, but 361e5bb58b1SEvandro Menezes // they are generally available on POSIX-compliant systems. 362d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_access); 363c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_chmod); 364c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_closedir); 365c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_fdopen); 366c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_fileno); 367c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_fseeko); 368c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_fstat); 369c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_ftello); 370c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_gettimeofday); 371c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_memccpy); 372c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_mkdir); 373c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_open); 374c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_opendir); 375c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_pclose); 376c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_popen); 377c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_read); 378c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_rmdir); 379c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_stat); 380c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_strcasecmp); 381c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_strncasecmp); 382c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_unlink); 383c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_utime); 384c5638a71SMartin Storsjö TLI.setUnavailable(LibFunc_write); 385c5638a71SMartin Storsjö } 386c5638a71SMartin Storsjö 387c5638a71SMartin Storsjö if (T.isOSWindows() && !T.isWindowsCygwinEnvironment()) { 388c5638a71SMartin Storsjö // These functions aren't available in either MSVC or MinGW environments. 389d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcmp); 390d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bcopy); 391d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_bzero); 392d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_chown); 393d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ctermid); 394d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffs); 395d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flockfile); 396d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs); 397d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftrylockfile); 398d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_funlockfile); 399d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getitimer); 400d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getlogin_r); 401d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_getpwnam); 402d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htonl); 403d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_htons); 404d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lchown); 405d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat); 406d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohl); 407d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ntohs); 408d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pread); 409d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_pwrite); 410d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_readlink); 411d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_realpath); 412d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_setitimer); 413d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs); 414d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpcpy); 415d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stpncpy); 416d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_times); 417d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_uname); 418d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_unsetenv); 419d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_utimes); 42062d4215bSChandler Carruth } 42162d4215bSChandler Carruth 42262d4215bSChandler Carruth switch (T.getOS()) { 42362d4215bSChandler Carruth case Triple::MacOSX: 42462d4215bSChandler Carruth // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 42562d4215bSChandler Carruth // and their names are __exp10 and __exp10f. exp10l is not available on 42662d4215bSChandler Carruth // OS X or iOS. 427d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 42862d4215bSChandler Carruth if (T.isMacOSXVersionLT(10, 9)) { 429d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 430d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 43162d4215bSChandler Carruth } else { 432d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 433d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 43462d4215bSChandler Carruth } 43562d4215bSChandler Carruth break; 43662d4215bSChandler Carruth case Triple::IOS: 43789a6eefeSTim Northover case Triple::TvOS: 4388b40366bSTim Northover case Triple::WatchOS: 439d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 440ab1bcda8SJim Lin if (!T.isWatchOS() && 441ab1bcda8SJim Lin (T.isOSVersionLT(7, 0) || (T.isOSVersionLT(9, 0) && T.isX86()))) { 442d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 443d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 44462d4215bSChandler Carruth } else { 445d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10, "__exp10"); 446d21529faSDavid L. Jones TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f"); 44762d4215bSChandler Carruth } 44862d4215bSChandler Carruth break; 44962d4215bSChandler Carruth case Triple::Linux: 45062d4215bSChandler Carruth // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely 45162d4215bSChandler Carruth // buggy prior to glibc version 2.18. Until this version is widely deployed 45262d4215bSChandler Carruth // or we have a reasonable detection strategy, we cannot use exp10 reliably 45362d4215bSChandler Carruth // on Linux. 45462d4215bSChandler Carruth // 45562d4215bSChandler Carruth // Fall through to disable all of them. 456cd1d5aafSJustin Bogner LLVM_FALLTHROUGH; 45762d4215bSChandler Carruth default: 458d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10); 459d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10f); 460d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_exp10l); 46162d4215bSChandler Carruth } 46262d4215bSChandler Carruth 46362d4215bSChandler Carruth // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and 46462d4215bSChandler Carruth // Linux (GLIBC): 46562d4215bSChandler Carruth // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html 46683b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c 46762d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html 46862d4215bSChandler Carruth switch (T.getOS()) { 46962d4215bSChandler Carruth case Triple::Darwin: 47062d4215bSChandler Carruth case Triple::MacOSX: 47162d4215bSChandler Carruth case Triple::IOS: 47289a6eefeSTim Northover case Triple::TvOS: 4738b40366bSTim Northover case Triple::WatchOS: 47462d4215bSChandler Carruth case Triple::FreeBSD: 47562d4215bSChandler Carruth case Triple::Linux: 47662d4215bSChandler Carruth break; 47762d4215bSChandler Carruth default: 478d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsl); 47962d4215bSChandler Carruth } 48062d4215bSChandler Carruth 48162d4215bSChandler Carruth // ffsll is available on at least FreeBSD and Linux (GLIBC): 48283b34816SDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c 48362d4215bSChandler Carruth // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html 48462d4215bSChandler Carruth switch (T.getOS()) { 48589a6eefeSTim Northover case Triple::Darwin: 48689a6eefeSTim Northover case Triple::MacOSX: 48789a6eefeSTim Northover case Triple::IOS: 48889a6eefeSTim Northover case Triple::TvOS: 48989a6eefeSTim Northover case Triple::WatchOS: 49062d4215bSChandler Carruth case Triple::FreeBSD: 49162d4215bSChandler Carruth case Triple::Linux: 49262d4215bSChandler Carruth break; 49362d4215bSChandler Carruth default: 494d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ffsll); 49562d4215bSChandler Carruth } 49662d4215bSChandler Carruth 497bfd3082eSDavide Italiano // The following functions are available on at least FreeBSD: 498bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/fls.c 499bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c 500bfd3082eSDavide Italiano // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c 501bfd3082eSDavide Italiano if (!T.isOSFreeBSD()) { 502d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fls); 503d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsl); 504d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_flsll); 505bfd3082eSDavide Italiano } 506bfd3082eSDavide Italiano 507e3a5fc6dSEli Friedman // The following functions are only available on GNU/Linux (using glibc). 508e3a5fc6dSEli Friedman // Linux variants without glibc (eg: bionic, musl) may have some subset. 509e3a5fc6dSEli Friedman if (!T.isOSLinux() || !T.isGNUEnvironment()) { 510d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strdup); 511d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_strtok_r); 512d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_scanf); 513d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf); 514d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_getc); 515d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_under_IO_putc); 516e3a5fc6dSEli Friedman // But, Android and musl have memalign. 517e3a5fc6dSEli Friedman if (!T.isAndroid() && !T.isMusl()) 518d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_memalign); 519d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fopen64); 520d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fseeko64); 521d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstat64); 522d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_fstatvfs64); 523d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_ftello64); 524d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_lstat64); 525d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_open64); 526d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_stat64); 527d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_statvfs64); 528d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_tmpfile64); 52952149f03SSanjay Patel 53052149f03SSanjay Patel // Relaxed math functions are included in math-finite.h on Linux (GLIBC). 5316d15c4deSserge-sans-paille // Note that math-finite.h is no longer supported by top-of-tree GLIBC, 5326d15c4deSserge-sans-paille // so we keep these functions around just so that they're recognized by 5336d15c4deSserge-sans-paille // the ConstantFolder. 53452149f03SSanjay Patel TLI.setUnavailable(LibFunc_acos_finite); 53552149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosf_finite); 53652149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosl_finite); 53752149f03SSanjay Patel TLI.setUnavailable(LibFunc_acosh_finite); 53852149f03SSanjay Patel TLI.setUnavailable(LibFunc_acoshf_finite); 53952149f03SSanjay Patel TLI.setUnavailable(LibFunc_acoshl_finite); 54052149f03SSanjay Patel TLI.setUnavailable(LibFunc_asin_finite); 54152149f03SSanjay Patel TLI.setUnavailable(LibFunc_asinf_finite); 54252149f03SSanjay Patel TLI.setUnavailable(LibFunc_asinl_finite); 54352149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2_finite); 54452149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2f_finite); 54552149f03SSanjay Patel TLI.setUnavailable(LibFunc_atan2l_finite); 54652149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanh_finite); 54752149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanhf_finite); 54852149f03SSanjay Patel TLI.setUnavailable(LibFunc_atanhl_finite); 54952149f03SSanjay Patel TLI.setUnavailable(LibFunc_cosh_finite); 55052149f03SSanjay Patel TLI.setUnavailable(LibFunc_coshf_finite); 55152149f03SSanjay Patel TLI.setUnavailable(LibFunc_coshl_finite); 55252149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10_finite); 55352149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10f_finite); 55452149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp10l_finite); 55552149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2_finite); 55652149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2f_finite); 55752149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp2l_finite); 55852149f03SSanjay Patel TLI.setUnavailable(LibFunc_exp_finite); 55952149f03SSanjay Patel TLI.setUnavailable(LibFunc_expf_finite); 56052149f03SSanjay Patel TLI.setUnavailable(LibFunc_expl_finite); 56152149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10_finite); 56252149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10f_finite); 56352149f03SSanjay Patel TLI.setUnavailable(LibFunc_log10l_finite); 56452149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2_finite); 56552149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2f_finite); 56652149f03SSanjay Patel TLI.setUnavailable(LibFunc_log2l_finite); 56752149f03SSanjay Patel TLI.setUnavailable(LibFunc_log_finite); 56852149f03SSanjay Patel TLI.setUnavailable(LibFunc_logf_finite); 56952149f03SSanjay Patel TLI.setUnavailable(LibFunc_logl_finite); 57052149f03SSanjay Patel TLI.setUnavailable(LibFunc_pow_finite); 57152149f03SSanjay Patel TLI.setUnavailable(LibFunc_powf_finite); 57252149f03SSanjay Patel TLI.setUnavailable(LibFunc_powl_finite); 57352149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinh_finite); 57452149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinhf_finite); 57552149f03SSanjay Patel TLI.setUnavailable(LibFunc_sinhl_finite); 57662d4215bSChandler Carruth } 5776d8a2aa9SMichael Zolotukhin 578c1078872SMartin Storsjo if ((T.isOSLinux() && T.isGNUEnvironment()) || 579c1078872SMartin Storsjo (T.isAndroid() && !T.isAndroidVersionLT(28))) { 580ca22d427SDavid Bolvansky // available IO unlocked variants on GNU/Linux and Android P or later 581ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getc_unlocked); 582ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_getchar_unlocked); 583ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putc_unlocked); 584ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_putchar_unlocked); 585ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fputc_unlocked); 586ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fgetc_unlocked); 587ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fread_unlocked); 588ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fwrite_unlocked); 589ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fputs_unlocked); 590ca22d427SDavid Bolvansky TLI.setAvailable(LibFunc_fgets_unlocked); 591ca22d427SDavid Bolvansky } 592ca22d427SDavid Bolvansky 59358481663SNathan Lanza if (T.isAndroid() && T.isAndroidVersionLT(21)) { 59458481663SNathan Lanza TLI.setUnavailable(LibFunc_stpcpy); 59558481663SNathan Lanza TLI.setUnavailable(LibFunc_stpncpy); 59658481663SNathan Lanza } 59758481663SNathan Lanza 59851132881SJustin Lebar // As currently implemented in clang, NVPTX code has no standard library to 59951132881SJustin Lebar // speak of. Headers provide a standard-ish library implementation, but many 60051132881SJustin Lebar // of the signatures are wrong -- for example, many libm functions are not 60151132881SJustin Lebar // extern "C". 60251132881SJustin Lebar // 60351132881SJustin Lebar // libdevice, an IR library provided by nvidia, is linked in by the front-end, 60451132881SJustin Lebar // but only used functions are provided to llvm. Moreover, most of the 60551132881SJustin Lebar // functions in libdevice don't map precisely to standard library functions. 60651132881SJustin Lebar // 60751132881SJustin Lebar // FIXME: Having no standard library prevents e.g. many fastmath 60851132881SJustin Lebar // optimizations, so this situation should be fixed. 609ae272d71SDavid Majnemer if (T.isNVPTX()) { 61051132881SJustin Lebar TLI.disableAllFunctions(); 611d21529faSDavid L. Jones TLI.setAvailable(LibFunc_nvvm_reflect); 612f40a2c3bSJohannes Doerfert TLI.setAvailable(llvm::LibFunc_malloc); 613f40a2c3bSJohannes Doerfert TLI.setAvailable(llvm::LibFunc_free); 614f40a2c3bSJohannes Doerfert 615f40a2c3bSJohannes Doerfert // TODO: We could enable the following two according to [0] but we haven't 616f40a2c3bSJohannes Doerfert // done an evaluation wrt. the performance implications. 617f40a2c3bSJohannes Doerfert // [0] 618f40a2c3bSJohannes Doerfert // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations 619f40a2c3bSJohannes Doerfert // 620f40a2c3bSJohannes Doerfert // TLI.setAvailable(llvm::LibFunc_memcpy); 621f40a2c3bSJohannes Doerfert // TLI.setAvailable(llvm::LibFunc_memset); 622f40a2c3bSJohannes Doerfert 6232662351eSJoseph Huber TLI.setAvailable(llvm::LibFunc___kmpc_alloc_shared); 6242662351eSJoseph Huber TLI.setAvailable(llvm::LibFunc___kmpc_free_shared); 625ae272d71SDavid Majnemer } else { 626d21529faSDavid L. Jones TLI.setUnavailable(LibFunc_nvvm_reflect); 627ae272d71SDavid Majnemer } 62851132881SJustin Lebar 62999a0aa07SShimin Cui // These vec_malloc/free routines are only available on AIX. 63099a0aa07SShimin Cui if (!T.isOSAIX()) { 63199a0aa07SShimin Cui TLI.setUnavailable(LibFunc_vec_calloc); 63299a0aa07SShimin Cui TLI.setUnavailable(LibFunc_vec_malloc); 63399a0aa07SShimin Cui TLI.setUnavailable(LibFunc_vec_realloc); 63499a0aa07SShimin Cui TLI.setUnavailable(LibFunc_vec_free); 63599a0aa07SShimin Cui } 63699a0aa07SShimin Cui 637ed03d948SMehdi Amini TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); 63862d4215bSChandler Carruth } 63962d4215bSChandler Carruth 640c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl() { 64162d4215bSChandler Carruth // Default to everything being available. 64262d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 64362d4215bSChandler Carruth 64462d4215bSChandler Carruth initialize(*this, Triple(), StandardNames); 64562d4215bSChandler Carruth } 64662d4215bSChandler Carruth 6477459398aSJoel Jones TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) { 64862d4215bSChandler Carruth // Default to everything being available. 64962d4215bSChandler Carruth memset(AvailableArray, -1, sizeof(AvailableArray)); 65062d4215bSChandler Carruth 65162d4215bSChandler Carruth initialize(*this, T, StandardNames); 65262d4215bSChandler Carruth } 65362d4215bSChandler Carruth 654c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) 6557459398aSJoel Jones : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), 6565ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 6579c54ee43SBjorn Pettersson ShouldSignExtI32Param(TLI.ShouldSignExtI32Param), 6589c54ee43SBjorn Pettersson SizeOfInt(TLI.SizeOfInt) { 65962d4215bSChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 660ed03d948SMehdi Amini VectorDescs = TLI.VectorDescs; 661ed03d948SMehdi Amini ScalarDescs = TLI.ScalarDescs; 6628ca43224SChandler Carruth } 6638ca43224SChandler Carruth 664c0291865SChandler Carruth TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) 6657459398aSJoel Jones : CustomNames(std::move(TLI.CustomNames)), 6665ae2c526SMarcin Koscielnicki ShouldExtI32Param(TLI.ShouldExtI32Param), 6675ae2c526SMarcin Koscielnicki ShouldExtI32Return(TLI.ShouldExtI32Return), 6689c54ee43SBjorn Pettersson ShouldSignExtI32Param(TLI.ShouldSignExtI32Param), 6699c54ee43SBjorn Pettersson SizeOfInt(TLI.SizeOfInt) { 6708ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 6718ca43224SChandler Carruth AvailableArray); 672ed03d948SMehdi Amini VectorDescs = TLI.VectorDescs; 673ed03d948SMehdi Amini ScalarDescs = TLI.ScalarDescs; 6748ca43224SChandler Carruth } 6758ca43224SChandler Carruth 676c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { 67762d4215bSChandler Carruth CustomNames = TLI.CustomNames; 6785ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 6795ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 6805ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 6819c54ee43SBjorn Pettersson SizeOfInt = TLI.SizeOfInt; 6828ca43224SChandler Carruth memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); 6838ca43224SChandler Carruth return *this; 6848ca43224SChandler Carruth } 6858ca43224SChandler Carruth 686c0291865SChandler Carruth TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { 6878ca43224SChandler Carruth CustomNames = std::move(TLI.CustomNames); 6885ae2c526SMarcin Koscielnicki ShouldExtI32Param = TLI.ShouldExtI32Param; 6895ae2c526SMarcin Koscielnicki ShouldExtI32Return = TLI.ShouldExtI32Return; 6905ae2c526SMarcin Koscielnicki ShouldSignExtI32Param = TLI.ShouldSignExtI32Param; 6919c54ee43SBjorn Pettersson SizeOfInt = TLI.SizeOfInt; 6928ca43224SChandler Carruth std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), 6938ca43224SChandler Carruth AvailableArray); 6948ca43224SChandler Carruth return *this; 69562d4215bSChandler Carruth } 69662d4215bSChandler Carruth 69721abdf98SMichael Zolotukhin static StringRef sanitizeFunctionName(StringRef funcName) { 69862d4215bSChandler Carruth // Filter out empty names and names containing null bytes, those can't be in 69962d4215bSChandler Carruth // our table. 70062d4215bSChandler Carruth if (funcName.empty() || funcName.find('\0') != StringRef::npos) 70121abdf98SMichael Zolotukhin return StringRef(); 70262d4215bSChandler Carruth 70362d4215bSChandler Carruth // Check for \01 prefix that is used to mangle __asm declarations and 70462d4215bSChandler Carruth // strip it if present. 7056f0ecca3SPeter Collingbourne return GlobalValue::dropLLVMManglingEscape(funcName); 70621abdf98SMichael Zolotukhin } 70721abdf98SMichael Zolotukhin 708d5e60669SBenjamin Kramer bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName, LibFunc &F) const { 70921abdf98SMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 71021abdf98SMichael Zolotukhin if (funcName.empty()) 71121abdf98SMichael Zolotukhin return false; 71221abdf98SMichael Zolotukhin 713d5e60669SBenjamin Kramer const auto *Start = std::begin(StandardNames); 714d5e60669SBenjamin Kramer const auto *End = std::end(StandardNames); 715d5e60669SBenjamin Kramer const auto *I = std::lower_bound(Start, End, funcName); 71662d4215bSChandler Carruth if (I != End && *I == funcName) { 717d21529faSDavid L. Jones F = (LibFunc)(I - Start); 71862d4215bSChandler Carruth return true; 71962d4215bSChandler Carruth } 72062d4215bSChandler Carruth return false; 72162d4215bSChandler Carruth } 72262d4215bSChandler Carruth 723d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy, 724d21529faSDavid L. Jones LibFunc F, 725d765a82bSAhmed Bougacha const DataLayout *DL) const { 726d765a82bSAhmed Bougacha LLVMContext &Ctx = FTy.getContext(); 7276913812aSFangrui Song Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AddressSpace=*/0) : nullptr; 728d765a82bSAhmed Bougacha auto IsSizeTTy = [SizeTTy](Type *Ty) { 729d765a82bSAhmed Bougacha return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy(); 730d765a82bSAhmed Bougacha }; 731d765a82bSAhmed Bougacha unsigned NumParams = FTy.getNumParams(); 732d765a82bSAhmed Bougacha 733d765a82bSAhmed Bougacha switch (F) { 734c3bed1e8SCalixte Denizet case LibFunc_execl: 735c3bed1e8SCalixte Denizet case LibFunc_execlp: 7368f07efc7SCalixte Denizet case LibFunc_execle: 737c3bed1e8SCalixte Denizet return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 738c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 739c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 740c3bed1e8SCalixte Denizet case LibFunc_execv: 741c3bed1e8SCalixte Denizet case LibFunc_execvp: 742c3bed1e8SCalixte Denizet return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 743c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 744c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 745c3bed1e8SCalixte Denizet case LibFunc_execvP: 746c3bed1e8SCalixte Denizet case LibFunc_execvpe: 747c3bed1e8SCalixte Denizet case LibFunc_execve: 748c3bed1e8SCalixte Denizet return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 749c3bed1e8SCalixte Denizet FTy.getParamType(1)->isPointerTy() && 750c3bed1e8SCalixte Denizet FTy.getParamType(2)->isPointerTy() && 751c3bed1e8SCalixte Denizet FTy.getReturnType()->isIntegerTy(32)); 752f8c9ceb1SGeorge Burgess IV case LibFunc_strlen_chk: 753f8c9ceb1SGeorge Burgess IV --NumParams; 754f8c9ceb1SGeorge Burgess IV if (!IsSizeTTy(FTy.getParamType(NumParams))) 755f8c9ceb1SGeorge Burgess IV return false; 756f8c9ceb1SGeorge Burgess IV LLVM_FALLTHROUGH; 757d21529faSDavid L. Jones case LibFunc_strlen: 758d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 759d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 760d765a82bSAhmed Bougacha 761d21529faSDavid L. Jones case LibFunc_strchr: 762d21529faSDavid L. Jones case LibFunc_strrchr: 763d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 764d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 765d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy()); 766d765a82bSAhmed Bougacha 767d21529faSDavid L. Jones case LibFunc_strtol: 768d21529faSDavid L. Jones case LibFunc_strtod: 769d21529faSDavid L. Jones case LibFunc_strtof: 770d21529faSDavid L. Jones case LibFunc_strtoul: 771d21529faSDavid L. Jones case LibFunc_strtoll: 772d21529faSDavid L. Jones case LibFunc_strtold: 773d21529faSDavid L. Jones case LibFunc_strtoull: 774d765a82bSAhmed Bougacha return ((NumParams == 2 || NumParams == 3) && 775d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 776d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 777abb2a93cSErik Pilkington case LibFunc_strcat_chk: 778abb2a93cSErik Pilkington --NumParams; 779abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 780abb2a93cSErik Pilkington return false; 781abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 782d21529faSDavid L. Jones case LibFunc_strcat: 783d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 784d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 785d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType()); 786d765a82bSAhmed Bougacha 787abb2a93cSErik Pilkington case LibFunc_strncat_chk: 788abb2a93cSErik Pilkington --NumParams; 789abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 790abb2a93cSErik Pilkington return false; 791abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 792d21529faSDavid L. Jones case LibFunc_strncat: 793d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 794d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 795d765a82bSAhmed Bougacha FTy.getParamType(1) == FTy.getReturnType() && 7967bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 797d765a82bSAhmed Bougacha 798d21529faSDavid L. Jones case LibFunc_strcpy_chk: 799d21529faSDavid L. Jones case LibFunc_stpcpy_chk: 800d765a82bSAhmed Bougacha --NumParams; 801d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 802d765a82bSAhmed Bougacha return false; 803b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 804d21529faSDavid L. Jones case LibFunc_strcpy: 805d21529faSDavid L. Jones case LibFunc_stpcpy: 806d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) && 807d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 808b26d6758SAlex Richardson FTy.getParamType(0)->isPointerTy()); 809d765a82bSAhmed Bougacha 810abb2a93cSErik Pilkington case LibFunc_strlcat_chk: 811abb2a93cSErik Pilkington case LibFunc_strlcpy_chk: 812abb2a93cSErik Pilkington --NumParams; 813abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 814abb2a93cSErik Pilkington return false; 815abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 816abb2a93cSErik Pilkington case LibFunc_strlcat: 817abb2a93cSErik Pilkington case LibFunc_strlcpy: 818abb2a93cSErik Pilkington return NumParams == 3 && IsSizeTTy(FTy.getReturnType()) && 819abb2a93cSErik Pilkington FTy.getParamType(0)->isPointerTy() && 820abb2a93cSErik Pilkington FTy.getParamType(1)->isPointerTy() && 821abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(2)); 822abb2a93cSErik Pilkington 823d21529faSDavid L. Jones case LibFunc_strncpy_chk: 824d21529faSDavid L. Jones case LibFunc_stpncpy_chk: 825d765a82bSAhmed Bougacha --NumParams; 826d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 827d765a82bSAhmed Bougacha return false; 828b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 829d21529faSDavid L. Jones case LibFunc_strncpy: 830d21529faSDavid L. Jones case LibFunc_stpncpy: 831d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 832d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 833b26d6758SAlex Richardson FTy.getParamType(0)->isPointerTy() && 8347bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 835d765a82bSAhmed Bougacha 836d21529faSDavid L. Jones case LibFunc_strxfrm: 837d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 838d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 839d765a82bSAhmed Bougacha 840d21529faSDavid L. Jones case LibFunc_strcmp: 841d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) && 842d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 843d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 844d765a82bSAhmed Bougacha 845d21529faSDavid L. Jones case LibFunc_strncmp: 846d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 847d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 848d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 8497bd3fb15SIgor Laevsky IsSizeTTy(FTy.getParamType(2))); 850d765a82bSAhmed Bougacha 851d21529faSDavid L. Jones case LibFunc_strspn: 852d21529faSDavid L. Jones case LibFunc_strcspn: 853d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 854d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1) && 855d765a82bSAhmed Bougacha FTy.getReturnType()->isIntegerTy()); 856d765a82bSAhmed Bougacha 857d21529faSDavid L. Jones case LibFunc_strcoll: 858d21529faSDavid L. Jones case LibFunc_strcasecmp: 859d21529faSDavid L. Jones case LibFunc_strncasecmp: 860d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 861d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 862d765a82bSAhmed Bougacha 863d21529faSDavid L. Jones case LibFunc_strstr: 864d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 865d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 866d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 867d765a82bSAhmed Bougacha 868d21529faSDavid L. Jones case LibFunc_strpbrk: 869d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 870d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 871d765a82bSAhmed Bougacha FTy.getParamType(0) == FTy.getParamType(1)); 872d765a82bSAhmed Bougacha 873d21529faSDavid L. Jones case LibFunc_strtok: 874d21529faSDavid L. Jones case LibFunc_strtok_r: 875d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 876d21529faSDavid L. Jones case LibFunc_scanf: 877d21529faSDavid L. Jones case LibFunc_setbuf: 878d21529faSDavid L. Jones case LibFunc_setvbuf: 879d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 880d21529faSDavid L. Jones case LibFunc_strdup: 881d21529faSDavid L. Jones case LibFunc_strndup: 882d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 883d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 884d21529faSDavid L. Jones case LibFunc_sscanf: 885d21529faSDavid L. Jones case LibFunc_stat: 886d21529faSDavid L. Jones case LibFunc_statvfs: 887d21529faSDavid L. Jones case LibFunc_siprintf: 888b4f9991fSAlon Zakai case LibFunc_small_sprintf: 889d21529faSDavid L. Jones case LibFunc_sprintf: 890d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 8910d7c3775SMartin Storsjo FTy.getParamType(1)->isPointerTy() && 8920d7c3775SMartin Storsjo FTy.getReturnType()->isIntegerTy(32)); 893abb2a93cSErik Pilkington 894abb2a93cSErik Pilkington case LibFunc_sprintf_chk: 895abb2a93cSErik Pilkington return NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 896abb2a93cSErik Pilkington FTy.getParamType(1)->isIntegerTy(32) && 897abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(2)) && 898abb2a93cSErik Pilkington FTy.getParamType(3)->isPointerTy() && 899abb2a93cSErik Pilkington FTy.getReturnType()->isIntegerTy(32); 900abb2a93cSErik Pilkington 901d21529faSDavid L. Jones case LibFunc_snprintf: 9027f555577SSanjay Patel return NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 9037f555577SSanjay Patel IsSizeTTy(FTy.getParamType(1)) && 9040d7c3775SMartin Storsjo FTy.getParamType(2)->isPointerTy() && 9057f555577SSanjay Patel FTy.getReturnType()->isIntegerTy(32); 906abb2a93cSErik Pilkington 907abb2a93cSErik Pilkington case LibFunc_snprintf_chk: 908abb2a93cSErik Pilkington return NumParams == 5 && FTy.getParamType(0)->isPointerTy() && 909abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(1)) && 910abb2a93cSErik Pilkington FTy.getParamType(2)->isIntegerTy(32) && 911abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(3)) && 912abb2a93cSErik Pilkington FTy.getParamType(4)->isPointerTy() && 913abb2a93cSErik Pilkington FTy.getReturnType()->isIntegerTy(32); 914abb2a93cSErik Pilkington 915d21529faSDavid L. Jones case LibFunc_setitimer: 916d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 917d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 918d21529faSDavid L. Jones case LibFunc_system: 919d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 9202662351eSJoseph Huber case LibFunc___kmpc_alloc_shared: 921d21529faSDavid L. Jones case LibFunc_malloc: 92299a0aa07SShimin Cui case LibFunc_vec_malloc: 923d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 924d21529faSDavid L. Jones case LibFunc_memcmp: 9256b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 9266b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 9276b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 928d765a82bSAhmed Bougacha 929d21529faSDavid L. Jones case LibFunc_memchr: 930d21529faSDavid L. Jones case LibFunc_memrchr: 9316b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isPointerTy() && 9326b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 933d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy(32) && 9346b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 935d21529faSDavid L. Jones case LibFunc_modf: 936d21529faSDavid L. Jones case LibFunc_modff: 937d21529faSDavid L. Jones case LibFunc_modfl: 938d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 939d765a82bSAhmed Bougacha 940d21529faSDavid L. Jones case LibFunc_memcpy_chk: 94186429c4eSDávid Bolvanský case LibFunc_mempcpy_chk: 942d21529faSDavid L. Jones case LibFunc_memmove_chk: 943d765a82bSAhmed Bougacha --NumParams; 944d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 945d765a82bSAhmed Bougacha return false; 946b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 947d21529faSDavid L. Jones case LibFunc_memcpy: 948d21529faSDavid L. Jones case LibFunc_mempcpy: 949d21529faSDavid L. Jones case LibFunc_memmove: 950d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 951d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 952d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 953d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 954d765a82bSAhmed Bougacha 955d21529faSDavid L. Jones case LibFunc_memset_chk: 956d765a82bSAhmed Bougacha --NumParams; 957d765a82bSAhmed Bougacha if (!IsSizeTTy(FTy.getParamType(NumParams))) 958d765a82bSAhmed Bougacha return false; 959b03fd12cSJustin Bogner LLVM_FALLTHROUGH; 960d21529faSDavid L. Jones case LibFunc_memset: 961d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) && 962d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 963d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 964d765a82bSAhmed Bougacha IsSizeTTy(FTy.getParamType(2))); 965d765a82bSAhmed Bougacha 966abb2a93cSErik Pilkington case LibFunc_memccpy_chk: 967abb2a93cSErik Pilkington --NumParams; 968abb2a93cSErik Pilkington if (!IsSizeTTy(FTy.getParamType(NumParams))) 969abb2a93cSErik Pilkington return false; 970abb2a93cSErik Pilkington LLVM_FALLTHROUGH; 971d21529faSDavid L. Jones case LibFunc_memccpy: 972d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy()); 973d21529faSDavid L. Jones case LibFunc_memalign: 974d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 975d21529faSDavid L. Jones case LibFunc_realloc: 976d21529faSDavid L. Jones case LibFunc_reallocf: 97799a0aa07SShimin Cui case LibFunc_vec_realloc: 978b26d6758SAlex Richardson return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 9796b9be1dbSAhmed Bougacha FTy.getParamType(0) == FTy.getReturnType() && 9806b9be1dbSAhmed Bougacha IsSizeTTy(FTy.getParamType(1))); 981d21529faSDavid L. Jones case LibFunc_read: 982d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 983d21529faSDavid L. Jones case LibFunc_rewind: 984d21529faSDavid L. Jones case LibFunc_rmdir: 985d21529faSDavid L. Jones case LibFunc_remove: 986d21529faSDavid L. Jones case LibFunc_realpath: 987d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 988d21529faSDavid L. Jones case LibFunc_rename: 989d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 990d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 991d21529faSDavid L. Jones case LibFunc_readlink: 992d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 993d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 994d21529faSDavid L. Jones case LibFunc_write: 995d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 996c0955edfSUday Bondhugula case LibFunc_aligned_alloc: 997c0955edfSUday Bondhugula return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 998d21529faSDavid L. Jones case LibFunc_bcopy: 999d21529faSDavid L. Jones case LibFunc_bcmp: 1000d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1001d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1002d21529faSDavid L. Jones case LibFunc_bzero: 1003d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1004d21529faSDavid L. Jones case LibFunc_calloc: 100599a0aa07SShimin Cui case LibFunc_vec_calloc: 10067414bbebSSanjay Patel return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 10077414bbebSSanjay Patel FTy.getParamType(0) == FTy.getParamType(1)); 10081fe3f1caSAhmed Bougacha 1009d21529faSDavid L. Jones case LibFunc_atof: 1010d21529faSDavid L. Jones case LibFunc_atoi: 1011d21529faSDavid L. Jones case LibFunc_atol: 1012d21529faSDavid L. Jones case LibFunc_atoll: 1013d21529faSDavid L. Jones case LibFunc_ferror: 1014d21529faSDavid L. Jones case LibFunc_getenv: 1015d21529faSDavid L. Jones case LibFunc_getpwnam: 1016d21529faSDavid L. Jones case LibFunc_iprintf: 1017b4f9991fSAlon Zakai case LibFunc_small_printf: 1018d21529faSDavid L. Jones case LibFunc_pclose: 1019d21529faSDavid L. Jones case LibFunc_perror: 1020d21529faSDavid L. Jones case LibFunc_printf: 1021d21529faSDavid L. Jones case LibFunc_puts: 1022d21529faSDavid L. Jones case LibFunc_uname: 1023d21529faSDavid L. Jones case LibFunc_under_IO_getc: 1024d21529faSDavid L. Jones case LibFunc_unlink: 1025d21529faSDavid L. Jones case LibFunc_unsetenv: 1026d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 10271fe3f1caSAhmed Bougacha 1028d21529faSDavid L. Jones case LibFunc_access: 1029d21529faSDavid L. Jones case LibFunc_chmod: 1030d21529faSDavid L. Jones case LibFunc_chown: 1031d21529faSDavid L. Jones case LibFunc_clearerr: 1032d21529faSDavid L. Jones case LibFunc_closedir: 1033d21529faSDavid L. Jones case LibFunc_ctermid: 1034d21529faSDavid L. Jones case LibFunc_fclose: 1035d21529faSDavid L. Jones case LibFunc_feof: 1036d21529faSDavid L. Jones case LibFunc_fflush: 1037d21529faSDavid L. Jones case LibFunc_fgetc: 1038ca22d427SDavid Bolvansky case LibFunc_fgetc_unlocked: 1039d21529faSDavid L. Jones case LibFunc_fileno: 1040d21529faSDavid L. Jones case LibFunc_flockfile: 1041d21529faSDavid L. Jones case LibFunc_free: 1042d21529faSDavid L. Jones case LibFunc_fseek: 1043d21529faSDavid L. Jones case LibFunc_fseeko64: 1044d21529faSDavid L. Jones case LibFunc_fseeko: 1045d21529faSDavid L. Jones case LibFunc_fsetpos: 1046d21529faSDavid L. Jones case LibFunc_ftell: 1047d21529faSDavid L. Jones case LibFunc_ftello64: 1048d21529faSDavid L. Jones case LibFunc_ftello: 1049d21529faSDavid L. Jones case LibFunc_ftrylockfile: 1050d21529faSDavid L. Jones case LibFunc_funlockfile: 1051d21529faSDavid L. Jones case LibFunc_getc: 1052d21529faSDavid L. Jones case LibFunc_getc_unlocked: 1053d21529faSDavid L. Jones case LibFunc_getlogin_r: 1054d21529faSDavid L. Jones case LibFunc_mkdir: 1055d21529faSDavid L. Jones case LibFunc_mktime: 1056d21529faSDavid L. Jones case LibFunc_times: 105799a0aa07SShimin Cui case LibFunc_vec_free: 10581fe3f1caSAhmed Bougacha return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); 1059754eb1c2SJoseph Huber case LibFunc___kmpc_free_shared: 1060754eb1c2SJoseph Huber return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1061754eb1c2SJoseph Huber IsSizeTTy(FTy.getParamType(1))); 10621fe3f1caSAhmed Bougacha 1063d21529faSDavid L. Jones case LibFunc_fopen: 1064d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1065d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1066d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1067c3bed1e8SCalixte Denizet case LibFunc_fork: 1068c3bed1e8SCalixte Denizet return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32)); 1069d21529faSDavid L. Jones case LibFunc_fdopen: 1070d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1071d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1072d21529faSDavid L. Jones case LibFunc_fputc: 1073ca22d427SDavid Bolvansky case LibFunc_fputc_unlocked: 1074d21529faSDavid L. Jones case LibFunc_fstat: 1075d21529faSDavid L. Jones case LibFunc_frexp: 1076d21529faSDavid L. Jones case LibFunc_frexpf: 1077d21529faSDavid L. Jones case LibFunc_frexpl: 1078d21529faSDavid L. Jones case LibFunc_fstatvfs: 1079d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1080d21529faSDavid L. Jones case LibFunc_fgets: 1081ca22d427SDavid Bolvansky case LibFunc_fgets_unlocked: 1082d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1083d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1084d21529faSDavid L. Jones case LibFunc_fread: 1085ca22d427SDavid Bolvansky case LibFunc_fread_unlocked: 1086d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 1087d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 1088d21529faSDavid L. Jones case LibFunc_fwrite: 1089ca22d427SDavid Bolvansky case LibFunc_fwrite_unlocked: 1090d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() && 1091d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1092d765a82bSAhmed Bougacha FTy.getParamType(1)->isIntegerTy() && 1093d765a82bSAhmed Bougacha FTy.getParamType(2)->isIntegerTy() && 1094d765a82bSAhmed Bougacha FTy.getParamType(3)->isPointerTy()); 1095d21529faSDavid L. Jones case LibFunc_fputs: 1096ca22d427SDavid Bolvansky case LibFunc_fputs_unlocked: 1097d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1098d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1099d21529faSDavid L. Jones case LibFunc_fscanf: 1100d21529faSDavid L. Jones case LibFunc_fiprintf: 1101b4f9991fSAlon Zakai case LibFunc_small_fprintf: 1102d21529faSDavid L. Jones case LibFunc_fprintf: 11036b9be1dbSAhmed Bougacha return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() && 11046b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1105d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1106d21529faSDavid L. Jones case LibFunc_fgetpos: 1107d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1108d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1109d21529faSDavid L. Jones case LibFunc_getchar: 1110ca22d427SDavid Bolvansky case LibFunc_getchar_unlocked: 11116b9be1dbSAhmed Bougacha return (NumParams == 0 && FTy.getReturnType()->isIntegerTy()); 1112d21529faSDavid L. Jones case LibFunc_gets: 1113b26d6758SAlex Richardson return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1114d21529faSDavid L. Jones case LibFunc_getitimer: 1115d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1116d21529faSDavid L. Jones case LibFunc_ungetc: 1117d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1118d21529faSDavid L. Jones case LibFunc_utime: 1119d21529faSDavid L. Jones case LibFunc_utimes: 1120d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1121d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1122d21529faSDavid L. Jones case LibFunc_putc: 1123ca22d427SDavid Bolvansky case LibFunc_putc_unlocked: 1124d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1125d21529faSDavid L. Jones case LibFunc_pread: 1126d21529faSDavid L. Jones case LibFunc_pwrite: 1127d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(1)->isPointerTy()); 1128d21529faSDavid L. Jones case LibFunc_popen: 1129d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1130d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1131d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1132d21529faSDavid L. Jones case LibFunc_vscanf: 1133d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1134d21529faSDavid L. Jones case LibFunc_vsscanf: 1135d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1136d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1137d21529faSDavid L. Jones case LibFunc_vfscanf: 1138d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() && 1139d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1140d21529faSDavid L. Jones case LibFunc_valloc: 1141d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1142d21529faSDavid L. Jones case LibFunc_vprintf: 1143d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1144d21529faSDavid L. Jones case LibFunc_vfprintf: 1145d21529faSDavid L. Jones case LibFunc_vsprintf: 1146d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() && 1147d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1148abb2a93cSErik Pilkington case LibFunc_vsprintf_chk: 1149abb2a93cSErik Pilkington return NumParams == 5 && FTy.getParamType(0)->isPointerTy() && 1150abb2a93cSErik Pilkington FTy.getParamType(1)->isIntegerTy(32) && 1151abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(2)) && FTy.getParamType(3)->isPointerTy(); 1152d21529faSDavid L. Jones case LibFunc_vsnprintf: 1153d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() && 1154d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1155abb2a93cSErik Pilkington case LibFunc_vsnprintf_chk: 1156abb2a93cSErik Pilkington return NumParams == 6 && FTy.getParamType(0)->isPointerTy() && 1157abb2a93cSErik Pilkington FTy.getParamType(2)->isIntegerTy(32) && 1158abb2a93cSErik Pilkington IsSizeTTy(FTy.getParamType(3)) && FTy.getParamType(4)->isPointerTy(); 1159d21529faSDavid L. Jones case LibFunc_open: 1160d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1161d21529faSDavid L. Jones case LibFunc_opendir: 1162d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy() && 1163d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 1164d21529faSDavid L. Jones case LibFunc_tmpfile: 1165d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1166d21529faSDavid L. Jones case LibFunc_htonl: 1167d21529faSDavid L. Jones case LibFunc_ntohl: 11686b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 11696b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1170d21529faSDavid L. Jones case LibFunc_htons: 1171d21529faSDavid L. Jones case LibFunc_ntohs: 11726b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) && 11736b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1174d21529faSDavid L. Jones case LibFunc_lstat: 1175d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1176d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1177d21529faSDavid L. Jones case LibFunc_lchown: 1178d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 1179d21529faSDavid L. Jones case LibFunc_qsort: 1180d765a82bSAhmed Bougacha return (NumParams == 4 && FTy.getParamType(3)->isPointerTy()); 1181d21529faSDavid L. Jones case LibFunc_dunder_strdup: 1182d21529faSDavid L. Jones case LibFunc_dunder_strndup: 1183d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() && 1184d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy()); 1185d21529faSDavid L. Jones case LibFunc_dunder_strtok_r: 1186d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getParamType(1)->isPointerTy()); 1187d21529faSDavid L. Jones case LibFunc_under_IO_putc: 1188d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1189d21529faSDavid L. Jones case LibFunc_dunder_isoc99_scanf: 1190d765a82bSAhmed Bougacha return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy()); 1191d21529faSDavid L. Jones case LibFunc_stat64: 1192d21529faSDavid L. Jones case LibFunc_lstat64: 1193d21529faSDavid L. Jones case LibFunc_statvfs64: 119479dcc274SMichael Kuperstein return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1195d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1196d21529faSDavid L. Jones case LibFunc_dunder_isoc99_sscanf: 119779dcc274SMichael Kuperstein return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() && 1198d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1199d21529faSDavid L. Jones case LibFunc_fopen64: 1200d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy() && 1201d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1202d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1203d21529faSDavid L. Jones case LibFunc_tmpfile64: 1204d765a82bSAhmed Bougacha return (FTy.getReturnType()->isPointerTy()); 1205d21529faSDavid L. Jones case LibFunc_fstat64: 1206d21529faSDavid L. Jones case LibFunc_fstatvfs64: 1207d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(1)->isPointerTy()); 1208d21529faSDavid L. Jones case LibFunc_open64: 1209d765a82bSAhmed Bougacha return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy()); 1210d21529faSDavid L. Jones case LibFunc_gettimeofday: 1211d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() && 1212d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy()); 1213d765a82bSAhmed Bougacha 12146b9be1dbSAhmed Bougacha // new(unsigned int); 1215d21529faSDavid L. Jones case LibFunc_Znwj: 12166b9be1dbSAhmed Bougacha // new(unsigned long); 1217d21529faSDavid L. Jones case LibFunc_Znwm: 12186b9be1dbSAhmed Bougacha // new[](unsigned int); 1219d21529faSDavid L. Jones case LibFunc_Znaj: 12206b9be1dbSAhmed Bougacha // new[](unsigned long); 1221d21529faSDavid L. Jones case LibFunc_Znam: 12226b9be1dbSAhmed Bougacha // new(unsigned int); 1223d21529faSDavid L. Jones case LibFunc_msvc_new_int: 12246b9be1dbSAhmed Bougacha // new(unsigned long long); 1225d21529faSDavid L. Jones case LibFunc_msvc_new_longlong: 12266b9be1dbSAhmed Bougacha // new[](unsigned int); 1227d21529faSDavid L. Jones case LibFunc_msvc_new_array_int: 12286b9be1dbSAhmed Bougacha // new[](unsigned long long); 1229d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong: 12306b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); 12316b9be1dbSAhmed Bougacha 12326b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 1233d21529faSDavid L. Jones case LibFunc_ZnwjRKSt9nothrow_t: 12346b9be1dbSAhmed Bougacha // new(unsigned long, nothrow); 1235d21529faSDavid L. Jones case LibFunc_ZnwmRKSt9nothrow_t: 12366b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 1237d21529faSDavid L. Jones case LibFunc_ZnajRKSt9nothrow_t: 12386b9be1dbSAhmed Bougacha // new[](unsigned long, nothrow); 1239d21529faSDavid L. Jones case LibFunc_ZnamRKSt9nothrow_t: 12406b9be1dbSAhmed Bougacha // new(unsigned int, nothrow); 1241d21529faSDavid L. Jones case LibFunc_msvc_new_int_nothrow: 12426b9be1dbSAhmed Bougacha // new(unsigned long long, nothrow); 1243d21529faSDavid L. Jones case LibFunc_msvc_new_longlong_nothrow: 12446b9be1dbSAhmed Bougacha // new[](unsigned int, nothrow); 1245d21529faSDavid L. Jones case LibFunc_msvc_new_array_int_nothrow: 12466b9be1dbSAhmed Bougacha // new[](unsigned long long, nothrow); 1247d21529faSDavid L. Jones case LibFunc_msvc_new_array_longlong_nothrow: 124896bbec79SEric Fiselier // new(unsigned int, align_val_t) 124996bbec79SEric Fiselier case LibFunc_ZnwjSt11align_val_t: 125096bbec79SEric Fiselier // new(unsigned long, align_val_t) 125196bbec79SEric Fiselier case LibFunc_ZnwmSt11align_val_t: 125296bbec79SEric Fiselier // new[](unsigned int, align_val_t) 125396bbec79SEric Fiselier case LibFunc_ZnajSt11align_val_t: 125496bbec79SEric Fiselier // new[](unsigned long, align_val_t) 125596bbec79SEric Fiselier case LibFunc_ZnamSt11align_val_t: 12566b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); 12576b9be1dbSAhmed Bougacha 125896bbec79SEric Fiselier // new(unsigned int, align_val_t, nothrow) 125996bbec79SEric Fiselier case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t: 126096bbec79SEric Fiselier // new(unsigned long, align_val_t, nothrow) 126196bbec79SEric Fiselier case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t: 126296bbec79SEric Fiselier // new[](unsigned int, align_val_t, nothrow) 126396bbec79SEric Fiselier case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t: 126496bbec79SEric Fiselier // new[](unsigned long, align_val_t, nothrow) 126596bbec79SEric Fiselier case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t: 126696bbec79SEric Fiselier return (NumParams == 3 && FTy.getReturnType()->isPointerTy()); 126796bbec79SEric Fiselier 12686b9be1dbSAhmed Bougacha // void operator delete[](void*); 1269d21529faSDavid L. Jones case LibFunc_ZdaPv: 12706b9be1dbSAhmed Bougacha // void operator delete(void*); 1271d21529faSDavid L. Jones case LibFunc_ZdlPv: 12726b9be1dbSAhmed Bougacha // void operator delete[](void*); 1273d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32: 12746b9be1dbSAhmed Bougacha // void operator delete[](void*); 1275d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64: 12766b9be1dbSAhmed Bougacha // void operator delete(void*); 1277d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32: 12786b9be1dbSAhmed Bougacha // void operator delete(void*); 1279d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64: 12806b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 12816b9be1dbSAhmed Bougacha 12826b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1283d21529faSDavid L. Jones case LibFunc_ZdaPvRKSt9nothrow_t: 12846b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1285d21529faSDavid L. Jones case LibFunc_ZdaPvj: 12866b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long); 1287d21529faSDavid L. Jones case LibFunc_ZdaPvm: 12886b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1289d21529faSDavid L. Jones case LibFunc_ZdlPvRKSt9nothrow_t: 12906b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1291d21529faSDavid L. Jones case LibFunc_ZdlPvj: 12926b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long); 1293d21529faSDavid L. Jones case LibFunc_ZdlPvm: 129496bbec79SEric Fiselier // void operator delete(void*, align_val_t) 129596bbec79SEric Fiselier case LibFunc_ZdlPvSt11align_val_t: 129696bbec79SEric Fiselier // void operator delete[](void*, align_val_t) 129796bbec79SEric Fiselier case LibFunc_ZdaPvSt11align_val_t: 12986b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned int); 1299d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_int: 13006b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1301d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr32_nothrow: 13026b9be1dbSAhmed Bougacha // void operator delete[](void*, unsigned long long); 1303d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_longlong: 13046b9be1dbSAhmed Bougacha // void operator delete[](void*, nothrow); 1305d21529faSDavid L. Jones case LibFunc_msvc_delete_array_ptr64_nothrow: 13066b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned int); 1307d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_int: 13086b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1309d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr32_nothrow: 13106b9be1dbSAhmed Bougacha // void operator delete(void*, unsigned long long); 1311d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_longlong: 13126b9be1dbSAhmed Bougacha // void operator delete(void*, nothrow); 1313d21529faSDavid L. Jones case LibFunc_msvc_delete_ptr64_nothrow: 13146b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); 1315d765a82bSAhmed Bougacha 131696bbec79SEric Fiselier // void operator delete(void*, align_val_t, nothrow) 131796bbec79SEric Fiselier case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t: 131896bbec79SEric Fiselier // void operator delete[](void*, align_val_t, nothrow) 131996bbec79SEric Fiselier case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t: 13206bc2b042SHiroshi Yamauchi // void operator delete(void*, unsigned int, align_val_t) 13216bc2b042SHiroshi Yamauchi case LibFunc_ZdlPvjSt11align_val_t: 13226bc2b042SHiroshi Yamauchi // void operator delete(void*, unsigned long, align_val_t) 13236bc2b042SHiroshi Yamauchi case LibFunc_ZdlPvmSt11align_val_t: 13246bc2b042SHiroshi Yamauchi // void operator delete[](void*, unsigned int, align_val_t); 13256bc2b042SHiroshi Yamauchi case LibFunc_ZdaPvjSt11align_val_t: 13266bc2b042SHiroshi Yamauchi // void operator delete[](void*, unsigned long, align_val_t); 13276bc2b042SHiroshi Yamauchi case LibFunc_ZdaPvmSt11align_val_t: 132896bbec79SEric Fiselier return (NumParams == 3 && FTy.getParamType(0)->isPointerTy()); 132996bbec79SEric Fiselier 1330c4250941SGui Andrade // void __atomic_load(size_t, void *, void *, int) 1331c4250941SGui Andrade case LibFunc_atomic_load: 1332c4250941SGui Andrade // void __atomic_store(size_t, void *, void *, int) 1333c4250941SGui Andrade case LibFunc_atomic_store: 1334c4250941SGui Andrade return (NumParams == 4 && FTy.getParamType(0)->isIntegerTy() && 1335c4250941SGui Andrade FTy.getParamType(1)->isPointerTy() && 1336c4250941SGui Andrade FTy.getParamType(2)->isPointerTy() && 1337c4250941SGui Andrade FTy.getParamType(3)->isIntegerTy()); 1338c4250941SGui Andrade 1339d21529faSDavid L. Jones case LibFunc_memset_pattern16: 1340d765a82bSAhmed Bougacha return (!FTy.isVarArg() && NumParams == 3 && 13416b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 13426b9be1dbSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 13436b9be1dbSAhmed Bougacha FTy.getParamType(2)->isIntegerTy()); 1344d765a82bSAhmed Bougacha 1345d21529faSDavid L. Jones case LibFunc_cxa_guard_abort: 1346d21529faSDavid L. Jones case LibFunc_cxa_guard_acquire: 1347d21529faSDavid L. Jones case LibFunc_cxa_guard_release: 1348d21529faSDavid L. Jones case LibFunc_nvvm_reflect: 13496b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); 1350d765a82bSAhmed Bougacha 1351d21529faSDavid L. Jones case LibFunc_sincospi_stret: 1352d21529faSDavid L. Jones case LibFunc_sincospif_stret: 13536b9be1dbSAhmed Bougacha return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy()); 13546b9be1dbSAhmed Bougacha 1355d21529faSDavid L. Jones case LibFunc_acos: 13563cd8c16dSAndrew Kaylor case LibFunc_acos_finite: 1357d21529faSDavid L. Jones case LibFunc_acosf: 13583cd8c16dSAndrew Kaylor case LibFunc_acosf_finite: 1359d21529faSDavid L. Jones case LibFunc_acosh: 13603cd8c16dSAndrew Kaylor case LibFunc_acosh_finite: 1361d21529faSDavid L. Jones case LibFunc_acoshf: 13623cd8c16dSAndrew Kaylor case LibFunc_acoshf_finite: 1363d21529faSDavid L. Jones case LibFunc_acoshl: 13643cd8c16dSAndrew Kaylor case LibFunc_acoshl_finite: 1365d21529faSDavid L. Jones case LibFunc_acosl: 13663cd8c16dSAndrew Kaylor case LibFunc_acosl_finite: 1367d21529faSDavid L. Jones case LibFunc_asin: 13683cd8c16dSAndrew Kaylor case LibFunc_asin_finite: 1369d21529faSDavid L. Jones case LibFunc_asinf: 13703cd8c16dSAndrew Kaylor case LibFunc_asinf_finite: 1371d21529faSDavid L. Jones case LibFunc_asinh: 1372d21529faSDavid L. Jones case LibFunc_asinhf: 1373d21529faSDavid L. Jones case LibFunc_asinhl: 1374d21529faSDavid L. Jones case LibFunc_asinl: 13753cd8c16dSAndrew Kaylor case LibFunc_asinl_finite: 1376d21529faSDavid L. Jones case LibFunc_atan: 1377d21529faSDavid L. Jones case LibFunc_atanf: 1378d21529faSDavid L. Jones case LibFunc_atanh: 13793cd8c16dSAndrew Kaylor case LibFunc_atanh_finite: 1380d21529faSDavid L. Jones case LibFunc_atanhf: 13813cd8c16dSAndrew Kaylor case LibFunc_atanhf_finite: 1382d21529faSDavid L. Jones case LibFunc_atanhl: 13833cd8c16dSAndrew Kaylor case LibFunc_atanhl_finite: 1384d21529faSDavid L. Jones case LibFunc_atanl: 1385d21529faSDavid L. Jones case LibFunc_cbrt: 1386d21529faSDavid L. Jones case LibFunc_cbrtf: 1387d21529faSDavid L. Jones case LibFunc_cbrtl: 1388d21529faSDavid L. Jones case LibFunc_ceil: 1389d21529faSDavid L. Jones case LibFunc_ceilf: 1390d21529faSDavid L. Jones case LibFunc_ceill: 1391d21529faSDavid L. Jones case LibFunc_cos: 1392d21529faSDavid L. Jones case LibFunc_cosf: 1393d21529faSDavid L. Jones case LibFunc_cosh: 13943cd8c16dSAndrew Kaylor case LibFunc_cosh_finite: 1395d21529faSDavid L. Jones case LibFunc_coshf: 13963cd8c16dSAndrew Kaylor case LibFunc_coshf_finite: 1397d21529faSDavid L. Jones case LibFunc_coshl: 13983cd8c16dSAndrew Kaylor case LibFunc_coshl_finite: 1399d21529faSDavid L. Jones case LibFunc_cosl: 1400d21529faSDavid L. Jones case LibFunc_exp10: 14013cd8c16dSAndrew Kaylor case LibFunc_exp10_finite: 1402d21529faSDavid L. Jones case LibFunc_exp10f: 14033cd8c16dSAndrew Kaylor case LibFunc_exp10f_finite: 1404d21529faSDavid L. Jones case LibFunc_exp10l: 14053cd8c16dSAndrew Kaylor case LibFunc_exp10l_finite: 1406d21529faSDavid L. Jones case LibFunc_exp2: 14073cd8c16dSAndrew Kaylor case LibFunc_exp2_finite: 1408d21529faSDavid L. Jones case LibFunc_exp2f: 14093cd8c16dSAndrew Kaylor case LibFunc_exp2f_finite: 1410d21529faSDavid L. Jones case LibFunc_exp2l: 14113cd8c16dSAndrew Kaylor case LibFunc_exp2l_finite: 1412d21529faSDavid L. Jones case LibFunc_exp: 14133cd8c16dSAndrew Kaylor case LibFunc_exp_finite: 1414d21529faSDavid L. Jones case LibFunc_expf: 14153cd8c16dSAndrew Kaylor case LibFunc_expf_finite: 1416d21529faSDavid L. Jones case LibFunc_expl: 14173cd8c16dSAndrew Kaylor case LibFunc_expl_finite: 1418d21529faSDavid L. Jones case LibFunc_expm1: 1419d21529faSDavid L. Jones case LibFunc_expm1f: 1420d21529faSDavid L. Jones case LibFunc_expm1l: 1421d21529faSDavid L. Jones case LibFunc_fabs: 1422d21529faSDavid L. Jones case LibFunc_fabsf: 1423d21529faSDavid L. Jones case LibFunc_fabsl: 1424d21529faSDavid L. Jones case LibFunc_floor: 1425d21529faSDavid L. Jones case LibFunc_floorf: 1426d21529faSDavid L. Jones case LibFunc_floorl: 1427d21529faSDavid L. Jones case LibFunc_log10: 14283cd8c16dSAndrew Kaylor case LibFunc_log10_finite: 1429d21529faSDavid L. Jones case LibFunc_log10f: 14303cd8c16dSAndrew Kaylor case LibFunc_log10f_finite: 1431d21529faSDavid L. Jones case LibFunc_log10l: 14323cd8c16dSAndrew Kaylor case LibFunc_log10l_finite: 1433d21529faSDavid L. Jones case LibFunc_log1p: 1434d21529faSDavid L. Jones case LibFunc_log1pf: 1435d21529faSDavid L. Jones case LibFunc_log1pl: 1436d21529faSDavid L. Jones case LibFunc_log2: 14373cd8c16dSAndrew Kaylor case LibFunc_log2_finite: 1438d21529faSDavid L. Jones case LibFunc_log2f: 14393cd8c16dSAndrew Kaylor case LibFunc_log2f_finite: 1440d21529faSDavid L. Jones case LibFunc_log2l: 14413cd8c16dSAndrew Kaylor case LibFunc_log2l_finite: 1442d21529faSDavid L. Jones case LibFunc_log: 14433cd8c16dSAndrew Kaylor case LibFunc_log_finite: 1444d21529faSDavid L. Jones case LibFunc_logb: 1445d21529faSDavid L. Jones case LibFunc_logbf: 1446d21529faSDavid L. Jones case LibFunc_logbl: 1447d21529faSDavid L. Jones case LibFunc_logf: 14483cd8c16dSAndrew Kaylor case LibFunc_logf_finite: 1449d21529faSDavid L. Jones case LibFunc_logl: 14503cd8c16dSAndrew Kaylor case LibFunc_logl_finite: 1451d21529faSDavid L. Jones case LibFunc_nearbyint: 1452d21529faSDavid L. Jones case LibFunc_nearbyintf: 1453d21529faSDavid L. Jones case LibFunc_nearbyintl: 1454d21529faSDavid L. Jones case LibFunc_rint: 1455d21529faSDavid L. Jones case LibFunc_rintf: 1456d21529faSDavid L. Jones case LibFunc_rintl: 1457d21529faSDavid L. Jones case LibFunc_round: 1458d21529faSDavid L. Jones case LibFunc_roundf: 1459d21529faSDavid L. Jones case LibFunc_roundl: 14604d20e31fSSerge Pavlov case LibFunc_roundeven: 14614d20e31fSSerge Pavlov case LibFunc_roundevenf: 14624d20e31fSSerge Pavlov case LibFunc_roundevenl: 1463d21529faSDavid L. Jones case LibFunc_sin: 1464d21529faSDavid L. Jones case LibFunc_sinf: 1465d21529faSDavid L. Jones case LibFunc_sinh: 14663cd8c16dSAndrew Kaylor case LibFunc_sinh_finite: 1467d21529faSDavid L. Jones case LibFunc_sinhf: 14683cd8c16dSAndrew Kaylor case LibFunc_sinhf_finite: 1469d21529faSDavid L. Jones case LibFunc_sinhl: 14703cd8c16dSAndrew Kaylor case LibFunc_sinhl_finite: 1471d21529faSDavid L. Jones case LibFunc_sinl: 1472d21529faSDavid L. Jones case LibFunc_sqrt: 1473d21529faSDavid L. Jones case LibFunc_sqrt_finite: 1474d21529faSDavid L. Jones case LibFunc_sqrtf: 1475d21529faSDavid L. Jones case LibFunc_sqrtf_finite: 1476d21529faSDavid L. Jones case LibFunc_sqrtl: 1477d21529faSDavid L. Jones case LibFunc_sqrtl_finite: 1478d21529faSDavid L. Jones case LibFunc_tan: 1479d21529faSDavid L. Jones case LibFunc_tanf: 1480d21529faSDavid L. Jones case LibFunc_tanh: 1481d21529faSDavid L. Jones case LibFunc_tanhf: 1482d21529faSDavid L. Jones case LibFunc_tanhl: 1483d21529faSDavid L. Jones case LibFunc_tanl: 1484d21529faSDavid L. Jones case LibFunc_trunc: 1485d21529faSDavid L. Jones case LibFunc_truncf: 1486d21529faSDavid L. Jones case LibFunc_truncl: 1487d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() && 1488d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1489d765a82bSAhmed Bougacha 1490d21529faSDavid L. Jones case LibFunc_atan2: 14913cd8c16dSAndrew Kaylor case LibFunc_atan2_finite: 1492d21529faSDavid L. Jones case LibFunc_atan2f: 14933cd8c16dSAndrew Kaylor case LibFunc_atan2f_finite: 1494d21529faSDavid L. Jones case LibFunc_atan2l: 14953cd8c16dSAndrew Kaylor case LibFunc_atan2l_finite: 1496d21529faSDavid L. Jones case LibFunc_fmin: 1497d21529faSDavid L. Jones case LibFunc_fminf: 1498d21529faSDavid L. Jones case LibFunc_fminl: 1499d21529faSDavid L. Jones case LibFunc_fmax: 1500d21529faSDavid L. Jones case LibFunc_fmaxf: 1501d21529faSDavid L. Jones case LibFunc_fmaxl: 1502d21529faSDavid L. Jones case LibFunc_fmod: 1503d21529faSDavid L. Jones case LibFunc_fmodf: 1504d21529faSDavid L. Jones case LibFunc_fmodl: 15052470d298SEhud Katz case LibFunc_remainder: 15062470d298SEhud Katz case LibFunc_remainderf: 15072470d298SEhud Katz case LibFunc_remainderl: 1508d21529faSDavid L. Jones case LibFunc_copysign: 1509d21529faSDavid L. Jones case LibFunc_copysignf: 1510d21529faSDavid L. Jones case LibFunc_copysignl: 1511d21529faSDavid L. Jones case LibFunc_pow: 15123cd8c16dSAndrew Kaylor case LibFunc_pow_finite: 1513d21529faSDavid L. Jones case LibFunc_powf: 15143cd8c16dSAndrew Kaylor case LibFunc_powf_finite: 1515d21529faSDavid L. Jones case LibFunc_powl: 15163cd8c16dSAndrew Kaylor case LibFunc_powl_finite: 1517d765a82bSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 1518d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 1519d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(1)); 1520d765a82bSAhmed Bougacha 1521d21529faSDavid L. Jones case LibFunc_ldexp: 1522d21529faSDavid L. Jones case LibFunc_ldexpf: 1523d21529faSDavid L. Jones case LibFunc_ldexpl: 15246b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() && 15256b9be1dbSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0) && 15269c54ee43SBjorn Pettersson FTy.getParamType(1)->isIntegerTy(getIntSize())); 15276b9be1dbSAhmed Bougacha 1528d21529faSDavid L. Jones case LibFunc_ffs: 1529d21529faSDavid L. Jones case LibFunc_ffsl: 1530d21529faSDavid L. Jones case LibFunc_ffsll: 1531d21529faSDavid L. Jones case LibFunc_fls: 1532d21529faSDavid L. Jones case LibFunc_flsl: 1533d21529faSDavid L. Jones case LibFunc_flsll: 153404949fafSSanjay Patel return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 153504949fafSSanjay Patel FTy.getParamType(0)->isIntegerTy()); 153604949fafSSanjay Patel 1537d21529faSDavid L. Jones case LibFunc_isdigit: 1538d21529faSDavid L. Jones case LibFunc_isascii: 1539d21529faSDavid L. Jones case LibFunc_toascii: 1540d21529faSDavid L. Jones case LibFunc_putchar: 1541ca22d427SDavid Bolvansky case LibFunc_putchar_unlocked: 1542d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) && 154304949fafSSanjay Patel FTy.getReturnType() == FTy.getParamType(0)); 1544d765a82bSAhmed Bougacha 1545d21529faSDavid L. Jones case LibFunc_abs: 1546d21529faSDavid L. Jones case LibFunc_labs: 1547d21529faSDavid L. Jones case LibFunc_llabs: 1548d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() && 1549d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1550d765a82bSAhmed Bougacha 1551d21529faSDavid L. Jones case LibFunc_cxa_atexit: 1552d765a82bSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() && 1553d765a82bSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1554d765a82bSAhmed Bougacha FTy.getParamType(1)->isPointerTy() && 1555d765a82bSAhmed Bougacha FTy.getParamType(2)->isPointerTy()); 1556d765a82bSAhmed Bougacha 1557d21529faSDavid L. Jones case LibFunc_sinpi: 1558d21529faSDavid L. Jones case LibFunc_cospi: 1559d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() && 1560d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1561d765a82bSAhmed Bougacha 1562d21529faSDavid L. Jones case LibFunc_sinpif: 1563d21529faSDavid L. Jones case LibFunc_cospif: 1564d765a82bSAhmed Bougacha return (NumParams == 1 && FTy.getReturnType()->isFloatTy() && 1565d765a82bSAhmed Bougacha FTy.getReturnType() == FTy.getParamType(0)); 1566d765a82bSAhmed Bougacha 1567d21529faSDavid L. Jones case LibFunc_strnlen: 15686b9be1dbSAhmed Bougacha return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) && 1569b26d6758SAlex Richardson FTy.getParamType(0)->isPointerTy() && 1570b26d6758SAlex Richardson IsSizeTTy(FTy.getParamType(1))); 15716b9be1dbSAhmed Bougacha 1572d21529faSDavid L. Jones case LibFunc_posix_memalign: 15736b9be1dbSAhmed Bougacha return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && 15746b9be1dbSAhmed Bougacha FTy.getParamType(0)->isPointerTy() && 1575b26d6758SAlex Richardson IsSizeTTy(FTy.getParamType(1)) && IsSizeTTy(FTy.getParamType(2))); 15766b9be1dbSAhmed Bougacha 157760b40b8fSMatthias Braun case LibFunc_wcslen: 157860b40b8fSMatthias Braun return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() && 157960b40b8fSMatthias Braun FTy.getReturnType()->isIntegerTy()); 158060b40b8fSMatthias Braun 15812ff24731SHal Finkel case LibFunc_cabs: 15822ff24731SHal Finkel case LibFunc_cabsf: 15832ff24731SHal Finkel case LibFunc_cabsl: { 15842ff24731SHal Finkel Type* RetTy = FTy.getReturnType(); 15852ff24731SHal Finkel if (!RetTy->isFloatingPointTy()) 15862ff24731SHal Finkel return false; 15872ff24731SHal Finkel 15882ff24731SHal Finkel // NOTE: These prototypes are target specific and currently support 15892ff24731SHal Finkel // "complex" passed as an array or discrete real & imaginary parameters. 15902ff24731SHal Finkel // Add other calling conventions to enable libcall optimizations. 15912ff24731SHal Finkel if (NumParams == 1) 15922ff24731SHal Finkel return (FTy.getParamType(0)->isArrayTy() && 15932ff24731SHal Finkel FTy.getParamType(0)->getArrayNumElements() == 2 && 15942ff24731SHal Finkel FTy.getParamType(0)->getArrayElementType() == RetTy); 15952ff24731SHal Finkel else if (NumParams == 2) 15962ff24731SHal Finkel return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy); 15972ff24731SHal Finkel else 15982ff24731SHal Finkel return false; 15992ff24731SHal Finkel } 16006b9be1dbSAhmed Bougacha case LibFunc::NumLibFuncs: 16013b705ef7SEvandro Menezes case LibFunc::NotLibFunc: 160286b680a3SAhmed Bougacha break; 1603d765a82bSAhmed Bougacha } 16046b9be1dbSAhmed Bougacha 160586b680a3SAhmed Bougacha llvm_unreachable("Invalid libfunc"); 1606d765a82bSAhmed Bougacha } 1607d765a82bSAhmed Bougacha 1608d765a82bSAhmed Bougacha bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl, 1609d21529faSDavid L. Jones LibFunc &F) const { 161076ea748dSPhilip Reames // Intrinsics don't overlap w/libcalls; if our module has a large number of 161176ea748dSPhilip Reames // intrinsics, this ends up being an interesting compile time win since we 161276ea748dSPhilip Reames // avoid string normalization and comparison. 161376ea748dSPhilip Reames if (FDecl.isIntrinsic()) return false; 161476ea748dSPhilip Reames 1615d765a82bSAhmed Bougacha const DataLayout *DL = 1616d765a82bSAhmed Bougacha FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr; 1617d765a82bSAhmed Bougacha return getLibFunc(FDecl.getName(), F) && 1618d765a82bSAhmed Bougacha isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL); 1619d765a82bSAhmed Bougacha } 1620d765a82bSAhmed Bougacha 1621c0291865SChandler Carruth void TargetLibraryInfoImpl::disableAllFunctions() { 162262d4215bSChandler Carruth memset(AvailableArray, 0, sizeof(AvailableArray)); 162362d4215bSChandler Carruth } 1624b98f63dbSChandler Carruth 1625e8f2551fSMichael Zolotukhin static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) { 16269a72cd7bSMehdi Amini return LHS.ScalarFnName < RHS.ScalarFnName; 1627e8f2551fSMichael Zolotukhin } 1628e8f2551fSMichael Zolotukhin 1629e8f2551fSMichael Zolotukhin static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) { 16309a72cd7bSMehdi Amini return LHS.VectorFnName < RHS.VectorFnName; 1631e8f2551fSMichael Zolotukhin } 1632e8f2551fSMichael Zolotukhin 1633e8f2551fSMichael Zolotukhin static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) { 16349a72cd7bSMehdi Amini return LHS.ScalarFnName < S; 1635e8f2551fSMichael Zolotukhin } 1636e8f2551fSMichael Zolotukhin 1637ed03d948SMehdi Amini void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) { 1638f76e83bfSKazu Hirata llvm::append_range(VectorDescs, Fns); 16390cac726aSFangrui Song llvm::sort(VectorDescs, compareByScalarFnName); 1640e8f2551fSMichael Zolotukhin 1641f76e83bfSKazu Hirata llvm::append_range(ScalarDescs, Fns); 16420cac726aSFangrui Song llvm::sort(ScalarDescs, compareByVectorFnName); 1643e8f2551fSMichael Zolotukhin } 1644e8f2551fSMichael Zolotukhin 16456d8a2aa9SMichael Zolotukhin void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib( 1646ed03d948SMehdi Amini enum VectorLibrary VecLib) { 16476d8a2aa9SMichael Zolotukhin switch (VecLib) { 16486d8a2aa9SMichael Zolotukhin case Accelerate: { 16496d8a2aa9SMichael Zolotukhin const VecDesc VecFuncs[] = { 1650820b9031SNemanja Ivanovic #define TLI_DEFINE_ACCELERATE_VECFUNCS 1651820b9031SNemanja Ivanovic #include "llvm/Analysis/VecFuncs.def" 16526d8a2aa9SMichael Zolotukhin }; 1653ed03d948SMehdi Amini addVectorizableFunctions(VecFuncs); 16546d8a2aa9SMichael Zolotukhin break; 16556d8a2aa9SMichael Zolotukhin } 165693a9a8a8SFlorian Hahn case DarwinLibSystemM: { 165793a9a8a8SFlorian Hahn const VecDesc VecFuncs[] = { 165893a9a8a8SFlorian Hahn #define TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS 165993a9a8a8SFlorian Hahn #include "llvm/Analysis/VecFuncs.def" 166093a9a8a8SFlorian Hahn }; 166193a9a8a8SFlorian Hahn addVectorizableFunctions(VecFuncs); 166293a9a8a8SFlorian Hahn break; 166393a9a8a8SFlorian Hahn } 166457cdc52cSVenkataramanan Kumar case LIBMVEC_X86: { 166557cdc52cSVenkataramanan Kumar const VecDesc VecFuncs[] = { 166657cdc52cSVenkataramanan Kumar #define TLI_DEFINE_LIBMVEC_X86_VECFUNCS 166757cdc52cSVenkataramanan Kumar #include "llvm/Analysis/VecFuncs.def" 166857cdc52cSVenkataramanan Kumar }; 166957cdc52cSVenkataramanan Kumar addVectorizableFunctions(VecFuncs); 167057cdc52cSVenkataramanan Kumar break; 167157cdc52cSVenkataramanan Kumar } 1672fe97754aSNemanja Ivanovic case MASSV: { 1673fe97754aSNemanja Ivanovic const VecDesc VecFuncs[] = { 1674fe97754aSNemanja Ivanovic #define TLI_DEFINE_MASSV_VECFUNCS 1675fe97754aSNemanja Ivanovic #include "llvm/Analysis/VecFuncs.def" 1676fe97754aSNemanja Ivanovic }; 1677ed03d948SMehdi Amini addVectorizableFunctions(VecFuncs); 1678fe97754aSNemanja Ivanovic break; 1679fe97754aSNemanja Ivanovic } 1680a6669a1eSMatt Masten case SVML: { 1681a6669a1eSMatt Masten const VecDesc VecFuncs[] = { 1682820b9031SNemanja Ivanovic #define TLI_DEFINE_SVML_VECFUNCS 1683820b9031SNemanja Ivanovic #include "llvm/Analysis/VecFuncs.def" 1684a6669a1eSMatt Masten }; 1685ed03d948SMehdi Amini addVectorizableFunctions(VecFuncs); 1686a6669a1eSMatt Masten break; 1687a6669a1eSMatt Masten } 1688ed03d948SMehdi Amini case NoLibrary: 16896d8a2aa9SMichael Zolotukhin break; 16906d8a2aa9SMichael Zolotukhin } 16916d8a2aa9SMichael Zolotukhin } 16926d8a2aa9SMichael Zolotukhin 1693ed03d948SMehdi Amini bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const { 1694e8f2551fSMichael Zolotukhin funcName = sanitizeFunctionName(funcName); 1695ed03d948SMehdi Amini if (funcName.empty()) 1696e8f2551fSMichael Zolotukhin return false; 1697e8f2551fSMichael Zolotukhin 1698cecc4352SFangrui Song std::vector<VecDesc>::const_iterator I = 1699cecc4352SFangrui Song llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName); 1700e8f2551fSMichael Zolotukhin return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName; 1701e8f2551fSMichael Zolotukhin } 1702e8f2551fSMichael Zolotukhin 170301b87444SDavid Sherwood StringRef 170401b87444SDavid Sherwood TargetLibraryInfoImpl::getVectorizedFunction(StringRef F, 170501b87444SDavid Sherwood const ElementCount &VF) const { 1706e8f2551fSMichael Zolotukhin F = sanitizeFunctionName(F); 1707ed03d948SMehdi Amini if (F.empty()) 1708e8f2551fSMichael Zolotukhin return F; 1709cecc4352SFangrui Song std::vector<VecDesc>::const_iterator I = 1710cecc4352SFangrui Song llvm::lower_bound(VectorDescs, F, compareWithScalarFnName); 1711e8f2551fSMichael Zolotukhin while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) { 1712e8f2551fSMichael Zolotukhin if (I->VectorizationFactor == VF) 1713e8f2551fSMichael Zolotukhin return I->VectorFnName; 1714e8f2551fSMichael Zolotukhin ++I; 1715e8f2551fSMichael Zolotukhin } 1716e8f2551fSMichael Zolotukhin return StringRef(); 1717e8f2551fSMichael Zolotukhin } 1718e8f2551fSMichael Zolotukhin 1719878ab6dfSTeresa Johnson TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F, 1720164a2aa6SChandler Carruth FunctionAnalysisManager &) { 1721878ab6dfSTeresa Johnson if (!BaselineInfoImpl) 1722878ab6dfSTeresa Johnson BaselineInfoImpl = 1723878ab6dfSTeresa Johnson TargetLibraryInfoImpl(Triple(F.getParent()->getTargetTriple())); 1724878ab6dfSTeresa Johnson return TargetLibraryInfo(*BaselineInfoImpl, &F); 1725c0291865SChandler Carruth } 1726c0291865SChandler Carruth 172750ec0b5dSMatthias Braun unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const { 172850ec0b5dSMatthias Braun if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>( 172950ec0b5dSMatthias Braun M.getModuleFlag("wchar_size"))) 173050ec0b5dSMatthias Braun return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue(); 1731cc603ee3SMatthias Braun return 0; 173250ec0b5dSMatthias Braun } 1733c0291865SChandler Carruth 1734b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass() 1735878ab6dfSTeresa Johnson : ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) { 1736b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1737b98f63dbSChandler Carruth } 1738b98f63dbSChandler Carruth 1739b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T) 1740878ab6dfSTeresa Johnson : ImmutablePass(ID), TLA(TargetLibraryInfoImpl(T)) { 1741b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1742b98f63dbSChandler Carruth } 1743b98f63dbSChandler Carruth 1744b98f63dbSChandler Carruth TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass( 1745c0291865SChandler Carruth const TargetLibraryInfoImpl &TLIImpl) 1746878ab6dfSTeresa Johnson : ImmutablePass(ID), TLA(TLIImpl) { 1747b98f63dbSChandler Carruth initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); 1748b98f63dbSChandler Carruth } 1749b98f63dbSChandler Carruth 1750dab4eae2SChandler Carruth AnalysisKey TargetLibraryAnalysis::Key; 1751df0cd726SNAKAMURA Takumi 1752b98f63dbSChandler Carruth // Register the basic pass. 1753b98f63dbSChandler Carruth INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo", 1754b98f63dbSChandler Carruth "Target Library Information", false, true) 1755b98f63dbSChandler Carruth char TargetLibraryInfoWrapperPass::ID = 0; 1756b98f63dbSChandler Carruth 1757b98f63dbSChandler Carruth void TargetLibraryInfoWrapperPass::anchor() {} 1758d6de5f12SFrancesco Petrogalli 175901b87444SDavid Sherwood void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF, 176001b87444SDavid Sherwood ElementCount &FixedVF, 176101b87444SDavid Sherwood ElementCount &ScalableVF) const { 1762d6de5f12SFrancesco Petrogalli ScalarF = sanitizeFunctionName(ScalarF); 176301b87444SDavid Sherwood // Use '0' here because a type of the form <vscale x 1 x ElTy> is not the 176401b87444SDavid Sherwood // same as a scalar. 176501b87444SDavid Sherwood ScalableVF = ElementCount::getScalable(0); 176601b87444SDavid Sherwood FixedVF = ElementCount::getFixed(1); 1767ed03d948SMehdi Amini if (ScalarF.empty()) 176801b87444SDavid Sherwood return; 1769d6de5f12SFrancesco Petrogalli 1770d6de5f12SFrancesco Petrogalli std::vector<VecDesc>::const_iterator I = 1771d6de5f12SFrancesco Petrogalli llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName); 1772d6de5f12SFrancesco Petrogalli while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) { 177301b87444SDavid Sherwood ElementCount *VF = 177401b87444SDavid Sherwood I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF; 177501b87444SDavid Sherwood if (ElementCount::isKnownGT(I->VectorizationFactor, *VF)) 177601b87444SDavid Sherwood *VF = I->VectorizationFactor; 1777d6de5f12SFrancesco Petrogalli ++I; 1778d6de5f12SFrancesco Petrogalli } 1779d6de5f12SFrancesco Petrogalli } 1780