LCOV - code coverage report
Current view: top level - lib/Analysis - TargetLibraryInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 413 444 93.0 %
Date: 2018-02-21 17:27:13 Functions: 28 34 82.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the TargetLibraryInfo class.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/Analysis/TargetLibraryInfo.h"
      15             : #include "llvm/ADT/Triple.h"
      16             : #include "llvm/IR/Constants.h"
      17             : #include "llvm/Support/CommandLine.h"
      18             : using namespace llvm;
      19             : 
      20       97193 : static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
      21       97193 :     "vector-library", cl::Hidden, cl::desc("Vector functions library"),
      22      194386 :     cl::init(TargetLibraryInfoImpl::NoLibrary),
      23      485965 :     cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
      24             :                           "No vector functions library"),
      25             :                clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
      26             :                           "Accelerate framework"),
      27             :                clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
      28       97193 :                           "Intel SVML library")));
      29             : 
      30             : StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
      31             : #define TLI_DEFINE_STRING
      32             : #include "llvm/Analysis/TargetLibraryInfo.def"
      33             : };
      34             : 
      35       45246 : static bool hasSinCosPiStret(const Triple &T) {
      36             :   // Only Darwin variants have _stret versions of combined trig functions.
      37             :   if (!T.isOSDarwin())
      38             :     return false;
      39             : 
      40             :   // The ABI is rather complicated on x86, so don't do anything special there.
      41        4790 :   if (T.getArch() == Triple::x86)
      42             :     return false;
      43             : 
      44        3354 :   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
      45             :     return false;
      46             : 
      47         722 :   if (T.isiOS() && T.isOSVersionLT(7, 0))
      48             :     return false;
      49             : 
      50             :   return true;
      51             : }
      52             : 
      53             : /// Initialize the set of available library functions based on the specified
      54             : /// target triple. This should be carefully written so that a missing target
      55             : /// triple gets a sane set of defaults.
      56       45962 : static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
      57             :                        ArrayRef<StringRef> StandardNames) {
      58             :   // Verify that the StandardNames array is in alphabetical order.
      59             :   assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
      60             :                         [](StringRef LHS, StringRef RHS) {
      61             :                           return LHS < RHS;
      62             :                         }) &&
      63             :          "TargetLibraryInfoImpl function names must be sorted");
      64             : 
      65             :   bool ShouldExtI32Param = false, ShouldExtI32Return = false,
      66             :        ShouldSignExtI32Param = false;
      67             :   // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
      68             :   // returns corresponding to C-level ints and unsigned ints.
      69       91060 :   if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
      70       89141 :       T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
      71             :     ShouldExtI32Param = true;
      72             :     ShouldExtI32Return = true;
      73             :   }
      74             :   // Mips, on the other hand, needs signext on i32 parameters corresponding
      75             :   // to both signed and unsigned ints.
      76       45835 :   if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
      77       91484 :       T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
      78             :     ShouldSignExtI32Param = true;
      79             :   }
      80             :   TLI.setShouldExtI32Param(ShouldExtI32Param);
      81             :   TLI.setShouldExtI32Return(ShouldExtI32Return);
      82             :   TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
      83             : 
      84       45962 :   if (T.getArch() == Triple::r600 ||
      85             :       T.getArch() == Triple::amdgcn) {
      86             :     TLI.setUnavailable(LibFunc_ldexp);
      87             :     TLI.setUnavailable(LibFunc_ldexpf);
      88             :     TLI.setUnavailable(LibFunc_ldexpl);
      89             :     TLI.setUnavailable(LibFunc_exp10);
      90             :     TLI.setUnavailable(LibFunc_exp10f);
      91             :     TLI.setUnavailable(LibFunc_exp10l);
      92             :     TLI.setUnavailable(LibFunc_log10);
      93             :     TLI.setUnavailable(LibFunc_log10f);
      94             :     TLI.setUnavailable(LibFunc_log10l);
      95             :   }
      96             : 
      97             :   // There are no library implementations of mempcy and memset for AMD gpus and
      98             :   // these can be difficult to lower in the backend.
      99       45962 :   if (T.getArch() == Triple::r600 ||
     100             :       T.getArch() == Triple::amdgcn) {
     101             :     TLI.setUnavailable(LibFunc_memcpy);
     102             :     TLI.setUnavailable(LibFunc_memset);
     103             :     TLI.setUnavailable(LibFunc_memset_pattern16);
     104             :     return;
     105             :   }
     106             : 
     107             :   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
     108             :   // All versions of watchOS support it.
     109             :   if (T.isMacOSX()) {
     110        4030 :     if (T.isMacOSXVersionLT(10, 5))
     111             :       TLI.setUnavailable(LibFunc_memset_pattern16);
     112             :   } else if (T.isiOS()) {
     113         730 :     if (T.isOSVersionLT(3, 0))
     114             :       TLI.setUnavailable(LibFunc_memset_pattern16);
     115       40485 :   } else if (!T.isWatchOS()) {
     116             :     TLI.setUnavailable(LibFunc_memset_pattern16);
     117             :   }
     118             : 
     119       45246 :   if (!hasSinCosPiStret(T)) {
     120             :     TLI.setUnavailable(LibFunc_sinpi);
     121             :     TLI.setUnavailable(LibFunc_sinpif);
     122             :     TLI.setUnavailable(LibFunc_cospi);
     123             :     TLI.setUnavailable(LibFunc_cospif);
     124             :     TLI.setUnavailable(LibFunc_sincospi_stret);
     125             :     TLI.setUnavailable(LibFunc_sincospif_stret);
     126             :   }
     127             : 
     128        4708 :   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
     129         677 :       !T.isMacOSXVersionLT(10, 7)) {
     130             :     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
     131             :     // we don't care about) have two versions; on recent OSX, the one we want
     132             :     // has a $UNIX2003 suffix. The two implementations are identical except
     133             :     // for the return value in some edge cases.  However, we don't want to
     134             :     // generate code that depends on the old symbols.
     135          40 :     TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
     136          40 :     TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
     137             :   }
     138             : 
     139             :   // iprintf and friends are only available on XCore and TCE.
     140       45246 :   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
     141             :     TLI.setUnavailable(LibFunc_iprintf);
     142             :     TLI.setUnavailable(LibFunc_siprintf);
     143             :     TLI.setUnavailable(LibFunc_fiprintf);
     144             :   }
     145             : 
     146       45246 :   if (T.isOSWindows() && !T.isOSCygMing()) {
     147             :     // Win32 does not support long double
     148             :     TLI.setUnavailable(LibFunc_acosl);
     149             :     TLI.setUnavailable(LibFunc_asinl);
     150             :     TLI.setUnavailable(LibFunc_atanl);
     151             :     TLI.setUnavailable(LibFunc_atan2l);
     152             :     TLI.setUnavailable(LibFunc_ceill);
     153             :     TLI.setUnavailable(LibFunc_copysignl);
     154             :     TLI.setUnavailable(LibFunc_cosl);
     155             :     TLI.setUnavailable(LibFunc_coshl);
     156             :     TLI.setUnavailable(LibFunc_expl);
     157             :     TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf
     158             :     TLI.setUnavailable(LibFunc_fabsl);
     159             :     TLI.setUnavailable(LibFunc_floorl);
     160             :     TLI.setUnavailable(LibFunc_fmaxl);
     161             :     TLI.setUnavailable(LibFunc_fminl);
     162             :     TLI.setUnavailable(LibFunc_fmodl);
     163             :     TLI.setUnavailable(LibFunc_frexpl);
     164             :     TLI.setUnavailable(LibFunc_ldexpf);
     165             :     TLI.setUnavailable(LibFunc_ldexpl);
     166             :     TLI.setUnavailable(LibFunc_logl);
     167             :     TLI.setUnavailable(LibFunc_modfl);
     168             :     TLI.setUnavailable(LibFunc_powl);
     169             :     TLI.setUnavailable(LibFunc_sinl);
     170             :     TLI.setUnavailable(LibFunc_sinhl);
     171             :     TLI.setUnavailable(LibFunc_sqrtl);
     172             :     TLI.setUnavailable(LibFunc_tanl);
     173             :     TLI.setUnavailable(LibFunc_tanhl);
     174             : 
     175             :     // Win32 only has C89 math
     176             :     TLI.setUnavailable(LibFunc_acosh);
     177             :     TLI.setUnavailable(LibFunc_acoshf);
     178             :     TLI.setUnavailable(LibFunc_acoshl);
     179             :     TLI.setUnavailable(LibFunc_asinh);
     180             :     TLI.setUnavailable(LibFunc_asinhf);
     181             :     TLI.setUnavailable(LibFunc_asinhl);
     182             :     TLI.setUnavailable(LibFunc_atanh);
     183             :     TLI.setUnavailable(LibFunc_atanhf);
     184             :     TLI.setUnavailable(LibFunc_atanhl);
     185             :     TLI.setUnavailable(LibFunc_cabs);
     186             :     TLI.setUnavailable(LibFunc_cabsf);
     187             :     TLI.setUnavailable(LibFunc_cabsl);
     188             :     TLI.setUnavailable(LibFunc_cbrt);
     189             :     TLI.setUnavailable(LibFunc_cbrtf);
     190             :     TLI.setUnavailable(LibFunc_cbrtl);
     191             :     TLI.setUnavailable(LibFunc_exp2);
     192             :     TLI.setUnavailable(LibFunc_exp2f);
     193             :     TLI.setUnavailable(LibFunc_exp2l);
     194             :     TLI.setUnavailable(LibFunc_expm1);
     195             :     TLI.setUnavailable(LibFunc_expm1f);
     196             :     TLI.setUnavailable(LibFunc_expm1l);
     197             :     TLI.setUnavailable(LibFunc_log2);
     198             :     TLI.setUnavailable(LibFunc_log2f);
     199             :     TLI.setUnavailable(LibFunc_log2l);
     200             :     TLI.setUnavailable(LibFunc_log1p);
     201             :     TLI.setUnavailable(LibFunc_log1pf);
     202             :     TLI.setUnavailable(LibFunc_log1pl);
     203             :     TLI.setUnavailable(LibFunc_logb);
     204             :     TLI.setUnavailable(LibFunc_logbf);
     205             :     TLI.setUnavailable(LibFunc_logbl);
     206             :     TLI.setUnavailable(LibFunc_nearbyint);
     207             :     TLI.setUnavailable(LibFunc_nearbyintf);
     208             :     TLI.setUnavailable(LibFunc_nearbyintl);
     209             :     TLI.setUnavailable(LibFunc_rint);
     210             :     TLI.setUnavailable(LibFunc_rintf);
     211             :     TLI.setUnavailable(LibFunc_rintl);
     212             :     TLI.setUnavailable(LibFunc_round);
     213             :     TLI.setUnavailable(LibFunc_roundf);
     214             :     TLI.setUnavailable(LibFunc_roundl);
     215             :     TLI.setUnavailable(LibFunc_trunc);
     216             :     TLI.setUnavailable(LibFunc_truncf);
     217             :     TLI.setUnavailable(LibFunc_truncl);
     218             : 
     219             :     // Win32 provides some C99 math with mangled names
     220        1187 :     TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
     221             : 
     222        1187 :     if (T.getArch() == Triple::x86) {
     223             :       // Win32 on x86 implements single-precision math functions as macros
     224             :       TLI.setUnavailable(LibFunc_acosf);
     225             :       TLI.setUnavailable(LibFunc_asinf);
     226             :       TLI.setUnavailable(LibFunc_atanf);
     227             :       TLI.setUnavailable(LibFunc_atan2f);
     228             :       TLI.setUnavailable(LibFunc_ceilf);
     229             :       TLI.setUnavailable(LibFunc_copysignf);
     230             :       TLI.setUnavailable(LibFunc_cosf);
     231             :       TLI.setUnavailable(LibFunc_coshf);
     232             :       TLI.setUnavailable(LibFunc_expf);
     233             :       TLI.setUnavailable(LibFunc_floorf);
     234             :       TLI.setUnavailable(LibFunc_fminf);
     235             :       TLI.setUnavailable(LibFunc_fmaxf);
     236             :       TLI.setUnavailable(LibFunc_fmodf);
     237             :       TLI.setUnavailable(LibFunc_logf);
     238             :       TLI.setUnavailable(LibFunc_log10f);
     239             :       TLI.setUnavailable(LibFunc_modff);
     240             :       TLI.setUnavailable(LibFunc_powf);
     241             :       TLI.setUnavailable(LibFunc_sinf);
     242             :       TLI.setUnavailable(LibFunc_sinhf);
     243             :       TLI.setUnavailable(LibFunc_sqrtf);
     244             :       TLI.setUnavailable(LibFunc_tanf);
     245             :       TLI.setUnavailable(LibFunc_tanhf);
     246             :     }
     247             : 
     248             :     // Win32 does *not* provide provide these functions, but they are
     249             :     // generally available on POSIX-compliant systems:
     250             :     TLI.setUnavailable(LibFunc_access);
     251             :     TLI.setUnavailable(LibFunc_bcmp);
     252             :     TLI.setUnavailable(LibFunc_bcopy);
     253             :     TLI.setUnavailable(LibFunc_bzero);
     254             :     TLI.setUnavailable(LibFunc_chmod);
     255             :     TLI.setUnavailable(LibFunc_chown);
     256             :     TLI.setUnavailable(LibFunc_closedir);
     257             :     TLI.setUnavailable(LibFunc_ctermid);
     258             :     TLI.setUnavailable(LibFunc_fdopen);
     259             :     TLI.setUnavailable(LibFunc_ffs);
     260             :     TLI.setUnavailable(LibFunc_fileno);
     261             :     TLI.setUnavailable(LibFunc_flockfile);
     262             :     TLI.setUnavailable(LibFunc_fseeko);
     263             :     TLI.setUnavailable(LibFunc_fstat);
     264             :     TLI.setUnavailable(LibFunc_fstatvfs);
     265             :     TLI.setUnavailable(LibFunc_ftello);
     266             :     TLI.setUnavailable(LibFunc_ftrylockfile);
     267             :     TLI.setUnavailable(LibFunc_funlockfile);
     268             :     TLI.setUnavailable(LibFunc_getc_unlocked);
     269             :     TLI.setUnavailable(LibFunc_getitimer);
     270             :     TLI.setUnavailable(LibFunc_getlogin_r);
     271             :     TLI.setUnavailable(LibFunc_getpwnam);
     272             :     TLI.setUnavailable(LibFunc_gettimeofday);
     273             :     TLI.setUnavailable(LibFunc_htonl);
     274             :     TLI.setUnavailable(LibFunc_htons);
     275             :     TLI.setUnavailable(LibFunc_lchown);
     276             :     TLI.setUnavailable(LibFunc_lstat);
     277             :     TLI.setUnavailable(LibFunc_memccpy);
     278             :     TLI.setUnavailable(LibFunc_mkdir);
     279             :     TLI.setUnavailable(LibFunc_ntohl);
     280             :     TLI.setUnavailable(LibFunc_ntohs);
     281             :     TLI.setUnavailable(LibFunc_open);
     282             :     TLI.setUnavailable(LibFunc_opendir);
     283             :     TLI.setUnavailable(LibFunc_pclose);
     284             :     TLI.setUnavailable(LibFunc_popen);
     285             :     TLI.setUnavailable(LibFunc_pread);
     286             :     TLI.setUnavailable(LibFunc_pwrite);
     287             :     TLI.setUnavailable(LibFunc_read);
     288             :     TLI.setUnavailable(LibFunc_readlink);
     289             :     TLI.setUnavailable(LibFunc_realpath);
     290             :     TLI.setUnavailable(LibFunc_rmdir);
     291             :     TLI.setUnavailable(LibFunc_setitimer);
     292             :     TLI.setUnavailable(LibFunc_stat);
     293             :     TLI.setUnavailable(LibFunc_statvfs);
     294             :     TLI.setUnavailable(LibFunc_stpcpy);
     295             :     TLI.setUnavailable(LibFunc_stpncpy);
     296             :     TLI.setUnavailable(LibFunc_strcasecmp);
     297             :     TLI.setUnavailable(LibFunc_strncasecmp);
     298             :     TLI.setUnavailable(LibFunc_times);
     299             :     TLI.setUnavailable(LibFunc_uname);
     300             :     TLI.setUnavailable(LibFunc_unlink);
     301             :     TLI.setUnavailable(LibFunc_unsetenv);
     302             :     TLI.setUnavailable(LibFunc_utime);
     303             :     TLI.setUnavailable(LibFunc_utimes);
     304             :     TLI.setUnavailable(LibFunc_write);
     305             : 
     306             :     // Win32 does *not* provide provide these functions, but they are
     307             :     // specified by C99:
     308             :     TLI.setUnavailable(LibFunc_atoll);
     309             :     TLI.setUnavailable(LibFunc_frexpf);
     310             :     TLI.setUnavailable(LibFunc_llabs);
     311             :   }
     312             : 
     313       45246 :   switch (T.getOS()) {
     314             :   case Triple::MacOSX:
     315             :     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
     316             :     // and their names are __exp10 and __exp10f. exp10l is not available on
     317             :     // OS X or iOS.
     318             :     TLI.setUnavailable(LibFunc_exp10l);
     319         872 :     if (T.isMacOSXVersionLT(10, 9)) {
     320             :       TLI.setUnavailable(LibFunc_exp10);
     321             :       TLI.setUnavailable(LibFunc_exp10f);
     322             :     } else {
     323         438 :       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
     324         438 :       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
     325             :     }
     326             :     break;
     327             :   case Triple::IOS:
     328             :   case Triple::TvOS:
     329             :   case Triple::WatchOS:
     330             :     TLI.setUnavailable(LibFunc_exp10l);
     331         968 :     if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
     332         376 :                            (T.isOSVersionLT(9, 0) &&
     333         331 :                             (T.getArch() == Triple::x86 ||
     334             :                              T.getArch() == Triple::x86_64)))) {
     335             :       TLI.setUnavailable(LibFunc_exp10);
     336             :       TLI.setUnavailable(LibFunc_exp10f);
     337             :     } else {
     338         235 :       TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
     339         235 :       TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
     340             :     }
     341             :     break;
     342             :   case Triple::Linux:
     343             :     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
     344             :     // buggy prior to glibc version 2.18. Until this version is widely deployed
     345             :     // or we have a reasonable detection strategy, we cannot use exp10 reliably
     346             :     // on Linux.
     347             :     //
     348             :     // Fall through to disable all of them.
     349             :     LLVM_FALLTHROUGH;
     350             :   default:
     351             :     TLI.setUnavailable(LibFunc_exp10);
     352             :     TLI.setUnavailable(LibFunc_exp10f);
     353             :     TLI.setUnavailable(LibFunc_exp10l);
     354             :   }
     355             : 
     356             :   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
     357             :   // Linux (GLIBC):
     358             :   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
     359             :   // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
     360             :   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
     361       45246 :   switch (T.getOS()) {
     362             :   case Triple::Darwin:
     363             :   case Triple::MacOSX:
     364             :   case Triple::IOS:
     365             :   case Triple::TvOS:
     366             :   case Triple::WatchOS:
     367             :   case Triple::FreeBSD:
     368             :   case Triple::Linux:
     369             :     break;
     370             :   default:
     371             :     TLI.setUnavailable(LibFunc_ffsl);
     372             :   }
     373             : 
     374             :   // ffsll is available on at least FreeBSD and Linux (GLIBC):
     375             :   // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
     376             :   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
     377       45246 :   switch (T.getOS()) {
     378             :   case Triple::Darwin:
     379             :   case Triple::MacOSX:
     380             :   case Triple::IOS:
     381             :   case Triple::TvOS:
     382             :   case Triple::WatchOS:
     383             :   case Triple::FreeBSD:
     384             :   case Triple::Linux:
     385             :     break;
     386             :   default:
     387             :     TLI.setUnavailable(LibFunc_ffsll);
     388             :   }
     389             : 
     390             :   // The following functions are available on at least FreeBSD:
     391             :   // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
     392             :   // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
     393             :   // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
     394       45246 :   if (!T.isOSFreeBSD()) {
     395             :     TLI.setUnavailable(LibFunc_fls);
     396             :     TLI.setUnavailable(LibFunc_flsl);
     397             :     TLI.setUnavailable(LibFunc_flsll);
     398             :   }
     399             : 
     400             :   // The following functions are available on Linux,
     401             :   // but Android uses bionic instead of glibc.
     402       59090 :   if (!T.isOSLinux() || T.isAndroid()) {
     403             :     TLI.setUnavailable(LibFunc_dunder_strdup);
     404             :     TLI.setUnavailable(LibFunc_dunder_strtok_r);
     405             :     TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
     406             :     TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
     407             :     TLI.setUnavailable(LibFunc_under_IO_getc);
     408             :     TLI.setUnavailable(LibFunc_under_IO_putc);
     409             :     // But, Android has memalign.
     410       31542 :     if (!T.isAndroid())
     411             :       TLI.setUnavailable(LibFunc_memalign);
     412             :     TLI.setUnavailable(LibFunc_fopen64);
     413             :     TLI.setUnavailable(LibFunc_fseeko64);
     414             :     TLI.setUnavailable(LibFunc_fstat64);
     415             :     TLI.setUnavailable(LibFunc_fstatvfs64);
     416             :     TLI.setUnavailable(LibFunc_ftello64);
     417             :     TLI.setUnavailable(LibFunc_lstat64);
     418             :     TLI.setUnavailable(LibFunc_open64);
     419             :     TLI.setUnavailable(LibFunc_stat64);
     420             :     TLI.setUnavailable(LibFunc_statvfs64);
     421             :     TLI.setUnavailable(LibFunc_tmpfile64);
     422             : 
     423             :     // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
     424             :     TLI.setUnavailable(LibFunc_acos_finite);
     425             :     TLI.setUnavailable(LibFunc_acosf_finite);
     426             :     TLI.setUnavailable(LibFunc_acosl_finite);
     427             :     TLI.setUnavailable(LibFunc_acosh_finite);
     428             :     TLI.setUnavailable(LibFunc_acoshf_finite);
     429             :     TLI.setUnavailable(LibFunc_acoshl_finite);
     430             :     TLI.setUnavailable(LibFunc_asin_finite);
     431             :     TLI.setUnavailable(LibFunc_asinf_finite);
     432             :     TLI.setUnavailable(LibFunc_asinl_finite);
     433             :     TLI.setUnavailable(LibFunc_atan2_finite);
     434             :     TLI.setUnavailable(LibFunc_atan2f_finite);
     435             :     TLI.setUnavailable(LibFunc_atan2l_finite);
     436             :     TLI.setUnavailable(LibFunc_atanh_finite);
     437             :     TLI.setUnavailable(LibFunc_atanhf_finite);
     438             :     TLI.setUnavailable(LibFunc_atanhl_finite);
     439             :     TLI.setUnavailable(LibFunc_cosh_finite);
     440             :     TLI.setUnavailable(LibFunc_coshf_finite);
     441             :     TLI.setUnavailable(LibFunc_coshl_finite);
     442             :     TLI.setUnavailable(LibFunc_exp10_finite);
     443             :     TLI.setUnavailable(LibFunc_exp10f_finite);
     444             :     TLI.setUnavailable(LibFunc_exp10l_finite);
     445             :     TLI.setUnavailable(LibFunc_exp2_finite);
     446             :     TLI.setUnavailable(LibFunc_exp2f_finite);
     447             :     TLI.setUnavailable(LibFunc_exp2l_finite);
     448             :     TLI.setUnavailable(LibFunc_exp_finite);
     449             :     TLI.setUnavailable(LibFunc_expf_finite);
     450             :     TLI.setUnavailable(LibFunc_expl_finite);
     451             :     TLI.setUnavailable(LibFunc_log10_finite);
     452             :     TLI.setUnavailable(LibFunc_log10f_finite);
     453             :     TLI.setUnavailable(LibFunc_log10l_finite);
     454             :     TLI.setUnavailable(LibFunc_log2_finite);
     455             :     TLI.setUnavailable(LibFunc_log2f_finite);
     456             :     TLI.setUnavailable(LibFunc_log2l_finite);
     457             :     TLI.setUnavailable(LibFunc_log_finite);
     458             :     TLI.setUnavailable(LibFunc_logf_finite);
     459             :     TLI.setUnavailable(LibFunc_logl_finite);
     460             :     TLI.setUnavailable(LibFunc_pow_finite);
     461             :     TLI.setUnavailable(LibFunc_powf_finite);
     462             :     TLI.setUnavailable(LibFunc_powl_finite);
     463             :     TLI.setUnavailable(LibFunc_sinh_finite);
     464             :     TLI.setUnavailable(LibFunc_sinhf_finite);
     465             :     TLI.setUnavailable(LibFunc_sinhl_finite);
     466             :   }
     467             : 
     468             :   // As currently implemented in clang, NVPTX code has no standard library to
     469             :   // speak of.  Headers provide a standard-ish library implementation, but many
     470             :   // of the signatures are wrong -- for example, many libm functions are not
     471             :   // extern "C".
     472             :   //
     473             :   // libdevice, an IR library provided by nvidia, is linked in by the front-end,
     474             :   // but only used functions are provided to llvm.  Moreover, most of the
     475             :   // functions in libdevice don't map precisely to standard library functions.
     476             :   //
     477             :   // FIXME: Having no standard library prevents e.g. many fastmath
     478             :   // optimizations, so this situation should be fixed.
     479             :   if (T.isNVPTX()) {
     480         182 :     TLI.disableAllFunctions();
     481             :     TLI.setAvailable(LibFunc_nvvm_reflect);
     482             :   } else {
     483             :     TLI.setUnavailable(LibFunc_nvvm_reflect);
     484             :   }
     485             : 
     486       45246 :   TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
     487             : }
     488             : 
     489        4858 : TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
     490             :   // Default to everything being available.
     491        4858 :   memset(AvailableArray, -1, sizeof(AvailableArray));
     492             : 
     493        9716 :   initialize(*this, Triple(), StandardNames);
     494        4858 : }
     495             : 
     496       41105 : TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
     497             :   // Default to everything being available.
     498       41105 :   memset(AvailableArray, -1, sizeof(AvailableArray));
     499             : 
     500       41105 :   initialize(*this, T, StandardNames);
     501       41105 : }
     502             : 
     503       50253 : TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
     504       50253 :     : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
     505       50253 :       ShouldExtI32Return(TLI.ShouldExtI32Return),
     506      201012 :       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
     507       50253 :   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
     508       50253 :   VectorDescs = TLI.VectorDescs;
     509       50253 :   ScalarDescs = TLI.ScalarDescs;
     510       50253 : }
     511             : 
     512         128 : TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
     513             :     : CustomNames(std::move(TLI.CustomNames)),
     514         128 :       ShouldExtI32Param(TLI.ShouldExtI32Param),
     515         128 :       ShouldExtI32Return(TLI.ShouldExtI32Return),
     516         384 :       ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
     517         256 :   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
     518             :             AvailableArray);
     519         128 :   VectorDescs = TLI.VectorDescs;
     520         128 :   ScalarDescs = TLI.ScalarDescs;
     521         128 : }
     522             : 
     523           0 : TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
     524           0 :   CustomNames = TLI.CustomNames;
     525           0 :   ShouldExtI32Param = TLI.ShouldExtI32Param;
     526           0 :   ShouldExtI32Return = TLI.ShouldExtI32Return;
     527           0 :   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
     528           0 :   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
     529           0 :   return *this;
     530             : }
     531             : 
     532           0 : TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
     533           0 :   CustomNames = std::move(TLI.CustomNames);
     534           0 :   ShouldExtI32Param = TLI.ShouldExtI32Param;
     535           0 :   ShouldExtI32Return = TLI.ShouldExtI32Return;
     536           0 :   ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
     537           0 :   std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
     538             :             AvailableArray);
     539           0 :   return *this;
     540             : }
     541             : 
     542    23847518 : static StringRef sanitizeFunctionName(StringRef funcName) {
     543             :   // Filter out empty names and names containing null bytes, those can't be in
     544             :   // our table.
     545    23847518 :   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
     546          80 :     return StringRef();
     547             : 
     548             :   // Check for \01 prefix that is used to mangle __asm declarations and
     549             :   // strip it if present.
     550    23847438 :   return GlobalValue::dropLLVMManglingEscape(funcName);
     551             : }
     552             : 
     553    23845691 : bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
     554             :                                        LibFunc &F) const {
     555             :   StringRef const *Start = &StandardNames[0];
     556             :   StringRef const *End = &StandardNames[NumLibFuncs];
     557             : 
     558    23845691 :   funcName = sanitizeFunctionName(funcName);
     559    23845691 :   if (funcName.empty())
     560             :     return false;
     561             : 
     562             :   StringRef const *I = std::lower_bound(
     563             :       Start, End, funcName, [](StringRef LHS, StringRef RHS) {
     564             :         return LHS < RHS;
     565   206904588 :       });
     566    23845612 :   if (I != End && *I == funcName) {
     567      588080 :     F = (LibFunc)(I - Start);
     568      588080 :     return true;
     569             :   }
     570             :   return false;
     571             : }
     572             : 
     573      210581 : bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
     574             :                                                    LibFunc F,
     575             :                                                    const DataLayout *DL) const {
     576      210581 :   LLVMContext &Ctx = FTy.getContext();
     577      210581 :   Type *PCharTy = Type::getInt8PtrTy(Ctx);
     578      210581 :   Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
     579             :   auto IsSizeTTy = [SizeTTy](Type *Ty) {
     580        1827 :     return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
     581             :   };
     582      210581 :   unsigned NumParams = FTy.getNumParams();
     583             : 
     584      210581 :   switch (F) {
     585       29942 :   case LibFunc_strlen:
     586       89816 :     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
     587             :             FTy.getReturnType()->isIntegerTy());
     588             : 
     589        1069 :   case LibFunc_strchr:
     590             :   case LibFunc_strrchr:
     591        3185 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     592        2128 :             FTy.getParamType(0) == FTy.getReturnType() &&
     593             :             FTy.getParamType(1)->isIntegerTy());
     594             : 
     595         735 :   case LibFunc_strtol:
     596             :   case LibFunc_strtod:
     597             :   case LibFunc_strtof:
     598             :   case LibFunc_strtoul:
     599             :   case LibFunc_strtoll:
     600             :   case LibFunc_strtold:
     601             :   case LibFunc_strtoull:
     602        1449 :     return ((NumParams == 2 || NumParams == 3) &&
     603        1449 :             FTy.getParamType(0)->isPointerTy() &&
     604             :             FTy.getParamType(1)->isPointerTy());
     605          50 :   case LibFunc_strcat:
     606         141 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     607          93 :             FTy.getParamType(0) == FTy.getReturnType() &&
     608             :             FTy.getParamType(1) == FTy.getReturnType());
     609             : 
     610          48 :   case LibFunc_strncat:
     611         135 :     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
     612          41 :             FTy.getParamType(0) == FTy.getReturnType() &&
     613          89 :             FTy.getParamType(1) == FTy.getReturnType() &&
     614             :             IsSizeTTy(FTy.getParamType(2)));
     615             : 
     616          78 :   case LibFunc_strcpy_chk:
     617             :   case LibFunc_stpcpy_chk:
     618          78 :     --NumParams;
     619         156 :     if (!IsSizeTTy(FTy.getParamType(NumParams)))
     620             :       return false;
     621             :     LLVM_FALLTHROUGH;
     622             :   case LibFunc_strcpy:
     623             :   case LibFunc_stpcpy:
     624        3565 :     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
     625        2372 :             FTy.getParamType(0) == FTy.getParamType(1) &&
     626             :             FTy.getParamType(0) == PCharTy);
     627             : 
     628          18 :   case LibFunc_strncpy_chk:
     629             :   case LibFunc_stpncpy_chk:
     630          18 :     --NumParams;
     631          36 :     if (!IsSizeTTy(FTy.getParamType(NumParams)))
     632             :       return false;
     633             :     LLVM_FALLTHROUGH;
     634             :   case LibFunc_strncpy:
     635             :   case LibFunc_stpncpy:
     636         269 :     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
     637          87 :             FTy.getParamType(0) == FTy.getParamType(1) &&
     638         180 :             FTy.getParamType(0) == PCharTy &&
     639             :             IsSizeTTy(FTy.getParamType(2)));
     640             : 
     641           9 :   case LibFunc_strxfrm:
     642          21 :     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
     643             :             FTy.getParamType(1)->isPointerTy());
     644             : 
     645        1742 :   case LibFunc_strcmp:
     646        5200 :     return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
     647        5206 :             FTy.getParamType(0)->isPointerTy() &&
     648             :             FTy.getParamType(0) == FTy.getParamType(1));
     649             : 
     650         952 :   case LibFunc_strncmp:
     651        2833 :     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
     652        1886 :             FTy.getParamType(0)->isPointerTy() &&
     653        1895 :             FTy.getParamType(0) == FTy.getParamType(1) &&
     654             :             IsSizeTTy(FTy.getParamType(2)));
     655             : 
     656          70 :   case LibFunc_strspn:
     657             :   case LibFunc_strcspn:
     658         192 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
     659         134 :             FTy.getParamType(0) == FTy.getParamType(1) &&
     660             :             FTy.getReturnType()->isIntegerTy());
     661             : 
     662         631 :   case LibFunc_strcoll:
     663             :   case LibFunc_strcasecmp:
     664             :   case LibFunc_strncasecmp:
     665        1875 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     666             :             FTy.getParamType(1)->isPointerTy());
     667             : 
     668         546 :   case LibFunc_strstr:
     669        1627 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     670        1087 :             FTy.getParamType(0)->isPointerTy() &&
     671             :             FTy.getParamType(1)->isPointerTy());
     672             : 
     673          32 :   case LibFunc_strpbrk:
     674          87 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
     675          59 :             FTy.getReturnType() == FTy.getParamType(0) &&
     676             :             FTy.getParamType(0) == FTy.getParamType(1));
     677             : 
     678          18 :   case LibFunc_strtok:
     679             :   case LibFunc_strtok_r:
     680          30 :     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
     681          27 :   case LibFunc_scanf:
     682             :   case LibFunc_setbuf:
     683             :   case LibFunc_setvbuf:
     684          45 :     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
     685          70 :   case LibFunc_strdup:
     686             :   case LibFunc_strndup:
     687         198 :     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
     688             :             FTy.getParamType(0)->isPointerTy());
     689         171 :   case LibFunc_sscanf:
     690             :   case LibFunc_stat:
     691             :   case LibFunc_statvfs:
     692             :   case LibFunc_siprintf:
     693             :   case LibFunc_sprintf:
     694         489 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     695             :             FTy.getParamType(1)->isPointerTy());
     696         913 :   case LibFunc_snprintf:
     697        2733 :     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
     698             :             FTy.getParamType(2)->isPointerTy());
     699          77 :   case LibFunc_setitimer:
     700         225 :     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
     701             :             FTy.getParamType(2)->isPointerTy());
     702          11 :   case LibFunc_system:
     703          19 :     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
     704         228 :   case LibFunc_malloc:
     705         432 :     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
     706        3395 :   case LibFunc_memcmp:
     707       10165 :     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
     708       10169 :             FTy.getParamType(0)->isPointerTy() &&
     709             :             FTy.getParamType(1)->isPointerTy());
     710             : 
     711         101 :   case LibFunc_memchr:
     712             :   case LibFunc_memrchr:
     713         291 :     return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
     714          97 :             FTy.getReturnType() == FTy.getParamType(0) &&
     715         294 :             FTy.getParamType(1)->isIntegerTy(32) &&
     716          96 :             IsSizeTTy(FTy.getParamType(2)));
     717          27 :   case LibFunc_modf:
     718             :   case LibFunc_modff:
     719             :   case LibFunc_modfl:
     720          45 :     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
     721             : 
     722          72 :   case LibFunc_memcpy_chk:
     723             :   case LibFunc_memmove_chk:
     724          72 :     --NumParams;
     725         144 :     if (!IsSizeTTy(FTy.getParamType(NumParams)))
     726             :       return false;
     727             :     LLVM_FALLTHROUGH;
     728             :   case LibFunc_memcpy:
     729             :   case LibFunc_mempcpy:
     730             :   case LibFunc_memmove:
     731         395 :     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
     732         129 :             FTy.getParamType(0)->isPointerTy() &&
     733         279 :             FTy.getParamType(1)->isPointerTy() &&
     734             :             IsSizeTTy(FTy.getParamType(2)));
     735             : 
     736         166 :   case LibFunc_memset_chk:
     737         166 :     --NumParams;
     738         332 :     if (!IsSizeTTy(FTy.getParamType(NumParams)))
     739             :       return false;
     740             :     LLVM_FALLTHROUGH;
     741             :   case LibFunc_memset:
     742         544 :     return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
     743         180 :             FTy.getParamType(0)->isPointerTy() &&
     744         369 :             FTy.getParamType(1)->isIntegerTy() &&
     745             :             IsSizeTTy(FTy.getParamType(2)));
     746             : 
     747           9 :   case LibFunc_memccpy:
     748          15 :     return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
     749           8 :   case LibFunc_memalign:
     750          16 :     return (FTy.getReturnType()->isPointerTy());
     751          27 :   case LibFunc_realloc:
     752             :   case LibFunc_reallocf:
     753          63 :     return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
     754          48 :             FTy.getParamType(0) == FTy.getReturnType() &&
     755             :             IsSizeTTy(FTy.getParamType(1)));
     756         164 :   case LibFunc_read:
     757         320 :     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
     758         502 :   case LibFunc_rewind:
     759             :   case LibFunc_rmdir:
     760             :   case LibFunc_remove:
     761             :   case LibFunc_realpath:
     762         992 :     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
     763           9 :   case LibFunc_rename:
     764          21 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     765             :             FTy.getParamType(1)->isPointerTy());
     766           9 :   case LibFunc_readlink:
     767          21 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     768             :             FTy.getParamType(1)->isPointerTy());
     769         240 :   case LibFunc_write:
     770         472 :     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
     771          24 :   case LibFunc_bcopy:
     772             :   case LibFunc_bcmp:
     773          60 :     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
     774             :             FTy.getParamType(1)->isPointerTy());
     775           9 :   case LibFunc_bzero:
     776          15 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
     777          84 :   case LibFunc_calloc:
     778         165 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
     779             : 
     780       11196 :   case LibFunc_atof:
     781             :   case LibFunc_atoi:
     782             :   case LibFunc_atol:
     783             :   case LibFunc_atoll:
     784             :   case LibFunc_ferror:
     785             :   case LibFunc_getenv:
     786             :   case LibFunc_getpwnam:
     787             :   case LibFunc_iprintf:
     788             :   case LibFunc_pclose:
     789             :   case LibFunc_perror:
     790             :   case LibFunc_printf:
     791             :   case LibFunc_puts:
     792             :   case LibFunc_uname:
     793             :   case LibFunc_under_IO_getc:
     794             :   case LibFunc_unlink:
     795             :   case LibFunc_unsetenv:
     796       22304 :     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
     797             : 
     798        9341 :   case LibFunc_access:
     799             :   case LibFunc_chmod:
     800             :   case LibFunc_chown:
     801             :   case LibFunc_clearerr:
     802             :   case LibFunc_closedir:
     803             :   case LibFunc_ctermid:
     804             :   case LibFunc_fclose:
     805             :   case LibFunc_feof:
     806             :   case LibFunc_fflush:
     807             :   case LibFunc_fgetc:
     808             :   case LibFunc_fileno:
     809             :   case LibFunc_flockfile:
     810             :   case LibFunc_free:
     811             :   case LibFunc_fseek:
     812             :   case LibFunc_fseeko64:
     813             :   case LibFunc_fseeko:
     814             :   case LibFunc_fsetpos:
     815             :   case LibFunc_ftell:
     816             :   case LibFunc_ftello64:
     817             :   case LibFunc_ftello:
     818             :   case LibFunc_ftrylockfile:
     819             :   case LibFunc_funlockfile:
     820             :   case LibFunc_getc:
     821             :   case LibFunc_getc_unlocked:
     822             :   case LibFunc_getlogin_r:
     823             :   case LibFunc_mkdir:
     824             :   case LibFunc_mktime:
     825             :   case LibFunc_times:
     826       18600 :     return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
     827             : 
     828         450 :   case LibFunc_fopen:
     829        1341 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     830         897 :             FTy.getParamType(0)->isPointerTy() &&
     831             :             FTy.getParamType(1)->isPointerTy());
     832         102 :   case LibFunc_fdopen:
     833         300 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     834             :             FTy.getParamType(1)->isPointerTy());
     835         448 :   case LibFunc_fputc:
     836             :   case LibFunc_fstat:
     837             :   case LibFunc_frexp:
     838             :   case LibFunc_frexpf:
     839             :   case LibFunc_frexpl:
     840             :   case LibFunc_fstatvfs:
     841         878 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     842          28 :   case LibFunc_fgets:
     843          78 :     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
     844             :             FTy.getParamType(2)->isPointerTy());
     845         124 :   case LibFunc_fread:
     846         366 :     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
     847             :             FTy.getParamType(3)->isPointerTy());
     848         390 :   case LibFunc_fwrite:
     849        1161 :     return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
     850         387 :             FTy.getParamType(0)->isPointerTy() &&
     851         387 :             FTy.getParamType(1)->isIntegerTy() &&
     852         777 :             FTy.getParamType(2)->isIntegerTy() &&
     853             :             FTy.getParamType(3)->isPointerTy());
     854         391 :   case LibFunc_fputs:
     855        1167 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     856             :             FTy.getParamType(1)->isPointerTy());
     857        3137 :   case LibFunc_fscanf:
     858             :   case LibFunc_fiprintf:
     859             :   case LibFunc_fprintf:
     860        9323 :     return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
     861        6236 :             FTy.getParamType(0)->isPointerTy() &&
     862             :             FTy.getParamType(1)->isPointerTy());
     863           9 :   case LibFunc_fgetpos:
     864          21 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     865             :             FTy.getParamType(1)->isPointerTy());
     866           9 :   case LibFunc_getchar:
     867          18 :     return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
     868           9 :   case LibFunc_gets:
     869          15 :     return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
     870           9 :   case LibFunc_getitimer:
     871          15 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     872           9 :   case LibFunc_ungetc:
     873          15 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     874          18 :   case LibFunc_utime:
     875             :   case LibFunc_utimes:
     876          42 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
     877             :             FTy.getParamType(1)->isPointerTy());
     878           9 :   case LibFunc_putc:
     879          15 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     880          18 :   case LibFunc_pread:
     881             :   case LibFunc_pwrite:
     882          30 :     return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
     883          38 :   case LibFunc_popen:
     884         105 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     885          73 :             FTy.getParamType(0)->isPointerTy() &&
     886             :             FTy.getParamType(1)->isPointerTy());
     887           9 :   case LibFunc_vscanf:
     888          15 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     889           9 :   case LibFunc_vsscanf:
     890          21 :     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
     891             :             FTy.getParamType(2)->isPointerTy());
     892           9 :   case LibFunc_vfscanf:
     893          21 :     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
     894             :             FTy.getParamType(2)->isPointerTy());
     895           9 :   case LibFunc_valloc:
     896          18 :     return (FTy.getReturnType()->isPointerTy());
     897          71 :   case LibFunc_vprintf:
     898         139 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
     899         259 :   case LibFunc_vfprintf:
     900             :   case LibFunc_vsprintf:
     901         765 :     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
     902             :             FTy.getParamType(1)->isPointerTy());
     903           9 :   case LibFunc_vsnprintf:
     904          21 :     return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
     905             :             FTy.getParamType(2)->isPointerTy());
     906          10 :   case LibFunc_open:
     907          17 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
     908          48 :   case LibFunc_opendir:
     909         138 :     return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
     910             :             FTy.getParamType(0)->isPointerTy());
     911           9 :   case LibFunc_tmpfile:
     912          18 :     return (FTy.getReturnType()->isPointerTy());
     913           5 :   case LibFunc_htonl:
     914             :   case LibFunc_ntohl:
     915          11 :     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
     916           3 :             FTy.getReturnType() == FTy.getParamType(0));
     917           4 :   case LibFunc_htons:
     918             :   case LibFunc_ntohs:
     919           8 :     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
     920           2 :             FTy.getReturnType() == FTy.getParamType(0));
     921           9 :   case LibFunc_lstat:
     922          21 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
     923             :             FTy.getParamType(1)->isPointerTy());
     924           9 :   case LibFunc_lchown:
     925          15 :     return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
     926           9 :   case LibFunc_qsort:
     927          15 :     return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
     928           3 :   case LibFunc_dunder_strdup:
     929             :   case LibFunc_dunder_strndup:
     930           7 :     return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
     931             :             FTy.getParamType(0)->isPointerTy());
     932           1 :   case LibFunc_dunder_strtok_r:
     933           2 :     return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
     934           1 :   case LibFunc_under_IO_putc:
     935           2 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     936           1 :   case LibFunc_dunder_isoc99_scanf:
     937           2 :     return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
     938          25 :   case LibFunc_stat64:
     939             :   case LibFunc_lstat64:
     940             :   case LibFunc_statvfs64:
     941          61 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
     942             :             FTy.getParamType(1)->isPointerTy());
     943           1 :   case LibFunc_dunder_isoc99_sscanf:
     944           3 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
     945             :             FTy.getParamType(1)->isPointerTy());
     946           1 :   case LibFunc_fopen64:
     947           3 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
     948           2 :             FTy.getParamType(0)->isPointerTy() &&
     949             :             FTy.getParamType(1)->isPointerTy());
     950           8 :   case LibFunc_tmpfile64:
     951          16 :     return (FTy.getReturnType()->isPointerTy());
     952          16 :   case LibFunc_fstat64:
     953             :   case LibFunc_fstatvfs64:
     954          28 :     return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
     955           8 :   case LibFunc_open64:
     956          14 :     return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
     957        1233 :   case LibFunc_gettimeofday:
     958        3693 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
     959             :             FTy.getParamType(1)->isPointerTy());
     960             : 
     961             :   // new(unsigned int);
     962        3122 :   case LibFunc_Znwj:
     963             :   // new(unsigned long);
     964             :   case LibFunc_Znwm:
     965             :   // new[](unsigned int);
     966             :   case LibFunc_Znaj:
     967             :   // new[](unsigned long);
     968             :   case LibFunc_Znam:
     969             :   // new(unsigned int);
     970             :   case LibFunc_msvc_new_int:
     971             :   // new(unsigned long long);
     972             :   case LibFunc_msvc_new_longlong:
     973             :   // new[](unsigned int);
     974             :   case LibFunc_msvc_new_array_int:
     975             :   // new[](unsigned long long);
     976             :   case LibFunc_msvc_new_array_longlong:
     977        6232 :     return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
     978             : 
     979             :   // new(unsigned int, nothrow);
     980          19 :   case LibFunc_ZnwjRKSt9nothrow_t:
     981             :   // new(unsigned long, nothrow);
     982             :   case LibFunc_ZnwmRKSt9nothrow_t:
     983             :   // new[](unsigned int, nothrow);
     984             :   case LibFunc_ZnajRKSt9nothrow_t:
     985             :   // new[](unsigned long, nothrow);
     986             :   case LibFunc_ZnamRKSt9nothrow_t:
     987             :   // new(unsigned int, nothrow);
     988             :   case LibFunc_msvc_new_int_nothrow:
     989             :   // new(unsigned long long, nothrow);
     990             :   case LibFunc_msvc_new_longlong_nothrow:
     991             :   // new[](unsigned int, nothrow);
     992             :   case LibFunc_msvc_new_array_int_nothrow:
     993             :   // new[](unsigned long long, nothrow);
     994             :   case LibFunc_msvc_new_array_longlong_nothrow:
     995          30 :     return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
     996             : 
     997             :   // void operator delete[](void*);
     998      115757 :   case LibFunc_ZdaPv:
     999             :   // void operator delete(void*);
    1000             :   case LibFunc_ZdlPv:
    1001             :   // void operator delete[](void*);
    1002             :   case LibFunc_msvc_delete_array_ptr32:
    1003             :   // void operator delete[](void*);
    1004             :   case LibFunc_msvc_delete_array_ptr64:
    1005             :   // void operator delete(void*);
    1006             :   case LibFunc_msvc_delete_ptr32:
    1007             :   // void operator delete(void*);
    1008             :   case LibFunc_msvc_delete_ptr64:
    1009      231508 :     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
    1010             : 
    1011             :   // void operator delete[](void*, nothrow);
    1012          40 :   case LibFunc_ZdaPvRKSt9nothrow_t:
    1013             :   // void operator delete[](void*, unsigned int);
    1014             :   case LibFunc_ZdaPvj:
    1015             :   // void operator delete[](void*, unsigned long);
    1016             :   case LibFunc_ZdaPvm:
    1017             :   // void operator delete(void*, nothrow);
    1018             :   case LibFunc_ZdlPvRKSt9nothrow_t:
    1019             :   // void operator delete(void*, unsigned int);
    1020             :   case LibFunc_ZdlPvj:
    1021             :   // void operator delete(void*, unsigned long);
    1022             :   case LibFunc_ZdlPvm:
    1023             :   // void operator delete[](void*, unsigned int);
    1024             :   case LibFunc_msvc_delete_array_ptr32_int:
    1025             :   // void operator delete[](void*, nothrow);
    1026             :   case LibFunc_msvc_delete_array_ptr32_nothrow:
    1027             :   // void operator delete[](void*, unsigned long long);
    1028             :   case LibFunc_msvc_delete_array_ptr64_longlong:
    1029             :   // void operator delete[](void*, nothrow);
    1030             :   case LibFunc_msvc_delete_array_ptr64_nothrow:
    1031             :   // void operator delete(void*, unsigned int);
    1032             :   case LibFunc_msvc_delete_ptr32_int:
    1033             :   // void operator delete(void*, nothrow);
    1034             :   case LibFunc_msvc_delete_ptr32_nothrow:
    1035             :   // void operator delete(void*, unsigned long long);
    1036             :   case LibFunc_msvc_delete_ptr64_longlong:
    1037             :   // void operator delete(void*, nothrow);
    1038             :   case LibFunc_msvc_delete_ptr64_nothrow:
    1039          66 :     return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
    1040             : 
    1041             :   case LibFunc_memset_pattern16:
    1042          38 :     return (!FTy.isVarArg() && NumParams == 3 &&
    1043          38 :             FTy.getParamType(0)->isPointerTy() &&
    1044          40 :             FTy.getParamType(1)->isPointerTy() &&
    1045             :             FTy.getParamType(2)->isIntegerTy());
    1046             : 
    1047        1279 :   case LibFunc_cxa_guard_abort:
    1048             :   case LibFunc_cxa_guard_acquire:
    1049             :   case LibFunc_cxa_guard_release:
    1050             :   case LibFunc_nvvm_reflect:
    1051        2555 :     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
    1052             : 
    1053          38 :   case LibFunc_sincospi_stret:
    1054             :   case LibFunc_sincospif_stret:
    1055          38 :     return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
    1056             : 
    1057        7341 :   case LibFunc_acos:
    1058             :   case LibFunc_acos_finite:
    1059             :   case LibFunc_acosf:
    1060             :   case LibFunc_acosf_finite:
    1061             :   case LibFunc_acosh:
    1062             :   case LibFunc_acosh_finite:
    1063             :   case LibFunc_acoshf:
    1064             :   case LibFunc_acoshf_finite:
    1065             :   case LibFunc_acoshl:
    1066             :   case LibFunc_acoshl_finite:
    1067             :   case LibFunc_acosl:
    1068             :   case LibFunc_acosl_finite:
    1069             :   case LibFunc_asin:
    1070             :   case LibFunc_asin_finite:
    1071             :   case LibFunc_asinf:
    1072             :   case LibFunc_asinf_finite:
    1073             :   case LibFunc_asinh:
    1074             :   case LibFunc_asinhf:
    1075             :   case LibFunc_asinhl:
    1076             :   case LibFunc_asinl:
    1077             :   case LibFunc_asinl_finite:
    1078             :   case LibFunc_atan:
    1079             :   case LibFunc_atanf:
    1080             :   case LibFunc_atanh:
    1081             :   case LibFunc_atanh_finite:
    1082             :   case LibFunc_atanhf:
    1083             :   case LibFunc_atanhf_finite:
    1084             :   case LibFunc_atanhl:
    1085             :   case LibFunc_atanhl_finite:
    1086             :   case LibFunc_atanl:
    1087             :   case LibFunc_cbrt:
    1088             :   case LibFunc_cbrtf:
    1089             :   case LibFunc_cbrtl:
    1090             :   case LibFunc_ceil:
    1091             :   case LibFunc_ceilf:
    1092             :   case LibFunc_ceill:
    1093             :   case LibFunc_cos:
    1094             :   case LibFunc_cosf:
    1095             :   case LibFunc_cosh:
    1096             :   case LibFunc_cosh_finite:
    1097             :   case LibFunc_coshf:
    1098             :   case LibFunc_coshf_finite:
    1099             :   case LibFunc_coshl:
    1100             :   case LibFunc_coshl_finite:
    1101             :   case LibFunc_cosl:
    1102             :   case LibFunc_exp10:
    1103             :   case LibFunc_exp10_finite:
    1104             :   case LibFunc_exp10f:
    1105             :   case LibFunc_exp10f_finite:
    1106             :   case LibFunc_exp10l:
    1107             :   case LibFunc_exp10l_finite:
    1108             :   case LibFunc_exp2:
    1109             :   case LibFunc_exp2_finite:
    1110             :   case LibFunc_exp2f:
    1111             :   case LibFunc_exp2f_finite:
    1112             :   case LibFunc_exp2l:
    1113             :   case LibFunc_exp2l_finite:
    1114             :   case LibFunc_exp:
    1115             :   case LibFunc_exp_finite:
    1116             :   case LibFunc_expf:
    1117             :   case LibFunc_expf_finite:
    1118             :   case LibFunc_expl:
    1119             :   case LibFunc_expl_finite:
    1120             :   case LibFunc_expm1:
    1121             :   case LibFunc_expm1f:
    1122             :   case LibFunc_expm1l:
    1123             :   case LibFunc_fabs:
    1124             :   case LibFunc_fabsf:
    1125             :   case LibFunc_fabsl:
    1126             :   case LibFunc_floor:
    1127             :   case LibFunc_floorf:
    1128             :   case LibFunc_floorl:
    1129             :   case LibFunc_log10:
    1130             :   case LibFunc_log10_finite:
    1131             :   case LibFunc_log10f:
    1132             :   case LibFunc_log10f_finite:
    1133             :   case LibFunc_log10l:
    1134             :   case LibFunc_log10l_finite:
    1135             :   case LibFunc_log1p:
    1136             :   case LibFunc_log1pf:
    1137             :   case LibFunc_log1pl:
    1138             :   case LibFunc_log2:
    1139             :   case LibFunc_log2_finite:
    1140             :   case LibFunc_log2f:
    1141             :   case LibFunc_log2f_finite:
    1142             :   case LibFunc_log2l:
    1143             :   case LibFunc_log2l_finite:
    1144             :   case LibFunc_log:
    1145             :   case LibFunc_log_finite:
    1146             :   case LibFunc_logb:
    1147             :   case LibFunc_logbf:
    1148             :   case LibFunc_logbl:
    1149             :   case LibFunc_logf:
    1150             :   case LibFunc_logf_finite:
    1151             :   case LibFunc_logl:
    1152             :   case LibFunc_logl_finite:
    1153             :   case LibFunc_nearbyint:
    1154             :   case LibFunc_nearbyintf:
    1155             :   case LibFunc_nearbyintl:
    1156             :   case LibFunc_rint:
    1157             :   case LibFunc_rintf:
    1158             :   case LibFunc_rintl:
    1159             :   case LibFunc_round:
    1160             :   case LibFunc_roundf:
    1161             :   case LibFunc_roundl:
    1162             :   case LibFunc_sin:
    1163             :   case LibFunc_sinf:
    1164             :   case LibFunc_sinh:
    1165             :   case LibFunc_sinh_finite:
    1166             :   case LibFunc_sinhf:
    1167             :   case LibFunc_sinhf_finite:
    1168             :   case LibFunc_sinhl:
    1169             :   case LibFunc_sinhl_finite:
    1170             :   case LibFunc_sinl:
    1171             :   case LibFunc_sqrt:
    1172             :   case LibFunc_sqrt_finite:
    1173             :   case LibFunc_sqrtf:
    1174             :   case LibFunc_sqrtf_finite:
    1175             :   case LibFunc_sqrtl:
    1176             :   case LibFunc_sqrtl_finite:
    1177             :   case LibFunc_tan:
    1178             :   case LibFunc_tanf:
    1179             :   case LibFunc_tanh:
    1180             :   case LibFunc_tanhf:
    1181             :   case LibFunc_tanhl:
    1182             :   case LibFunc_tanl:
    1183             :   case LibFunc_trunc:
    1184             :   case LibFunc_truncf:
    1185             :   case LibFunc_truncl:
    1186       14178 :     return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
    1187             :             FTy.getReturnType() == FTy.getParamType(0));
    1188             : 
    1189        1804 :   case LibFunc_atan2:
    1190             :   case LibFunc_atan2_finite:
    1191             :   case LibFunc_atan2f:
    1192             :   case LibFunc_atan2f_finite:
    1193             :   case LibFunc_atan2l:
    1194             :   case LibFunc_atan2l_finite:
    1195             :   case LibFunc_fmin:
    1196             :   case LibFunc_fminf:
    1197             :   case LibFunc_fminl:
    1198             :   case LibFunc_fmax:
    1199             :   case LibFunc_fmaxf:
    1200             :   case LibFunc_fmaxl:
    1201             :   case LibFunc_fmod:
    1202             :   case LibFunc_fmodf:
    1203             :   case LibFunc_fmodl:
    1204             :   case LibFunc_copysign:
    1205             :   case LibFunc_copysignf:
    1206             :   case LibFunc_copysignl:
    1207             :   case LibFunc_pow:
    1208             :   case LibFunc_pow_finite:
    1209             :   case LibFunc_powf:
    1210             :   case LibFunc_powf_finite:
    1211             :   case LibFunc_powl:
    1212             :   case LibFunc_powl_finite:
    1213        3476 :     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
    1214        3540 :             FTy.getReturnType() == FTy.getParamType(0) &&
    1215             :             FTy.getReturnType() == FTy.getParamType(1));
    1216             : 
    1217          92 :   case LibFunc_ldexp:
    1218             :   case LibFunc_ldexpf:
    1219             :   case LibFunc_ldexpl:
    1220         166 :     return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
    1221         175 :             FTy.getReturnType() == FTy.getParamType(0) &&
    1222          83 :             FTy.getParamType(1)->isIntegerTy(32));
    1223             : 
    1224         375 :   case LibFunc_ffs:
    1225             :   case LibFunc_ffsl:
    1226             :   case LibFunc_ffsll:
    1227             :   case LibFunc_fls:
    1228             :   case LibFunc_flsl:
    1229             :   case LibFunc_flsll:
    1230        1099 :     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
    1231         362 :             FTy.getParamType(0)->isIntegerTy());
    1232             : 
    1233        1265 :   case LibFunc_isdigit:
    1234             :   case LibFunc_isascii:
    1235             :   case LibFunc_toascii:
    1236             :   case LibFunc_putchar:
    1237        3761 :     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
    1238        1248 :             FTy.getReturnType() == FTy.getParamType(0));
    1239             : 
    1240          48 :   case LibFunc_abs:
    1241             :   case LibFunc_labs:
    1242             :   case LibFunc_llabs:
    1243         126 :     return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
    1244             :             FTy.getReturnType() == FTy.getParamType(0));
    1245             : 
    1246        7647 :   case LibFunc_cxa_atexit:
    1247       22938 :     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
    1248        7646 :             FTy.getParamType(0)->isPointerTy() &&
    1249       15293 :             FTy.getParamType(1)->isPointerTy() &&
    1250             :             FTy.getParamType(2)->isPointerTy());
    1251             : 
    1252          92 :   case LibFunc_sinpi:
    1253             :   case LibFunc_cospi:
    1254         268 :     return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
    1255             :             FTy.getReturnType() == FTy.getParamType(0));
    1256             : 
    1257          70 :   case LibFunc_sinpif:
    1258             :   case LibFunc_cospif:
    1259         202 :     return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
    1260             :             FTy.getReturnType() == FTy.getParamType(0));
    1261             : 
    1262          22 :   case LibFunc_strnlen:
    1263          57 :     return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
    1264          41 :             FTy.getParamType(0) == PCharTy &&
    1265             :             FTy.getParamType(1) == SizeTTy);
    1266             : 
    1267           9 :   case LibFunc_posix_memalign:
    1268          18 :     return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
    1269          12 :             FTy.getParamType(0)->isPointerTy() &&
    1270          15 :             FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
    1271             : 
    1272         389 :   case LibFunc_wcslen:
    1273        1161 :     return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
    1274             :             FTy.getReturnType()->isIntegerTy());
    1275             : 
    1276          42 :   case LibFunc_cabs:
    1277             :   case LibFunc_cabsf:
    1278             :   case LibFunc_cabsl: {
    1279          42 :     Type* RetTy = FTy.getReturnType();
    1280             :     if (!RetTy->isFloatingPointTy())
    1281             :       return false;
    1282             : 
    1283             :     // NOTE: These prototypes are target specific and currently support
    1284             :     // "complex" passed as an array or discrete real & imaginary parameters.
    1285             :     // Add other calling conventions to enable libcall optimizations.
    1286          39 :     if (NumParams == 1)
    1287          21 :       return (FTy.getParamType(0)->isArrayTy() &&
    1288          42 :               FTy.getParamType(0)->getArrayNumElements() == 2 &&
    1289          21 :               FTy.getParamType(0)->getArrayElementType() == RetTy);
    1290          18 :     else if (NumParams == 2)
    1291          36 :       return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
    1292             :     else
    1293             :       return false;
    1294             :   }
    1295             :   case LibFunc::NumLibFuncs:
    1296             :     break;
    1297             :   }
    1298             : 
    1299           0 :   llvm_unreachable("Invalid libfunc");
    1300             : }
    1301             : 
    1302     9389091 : bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
    1303             :                                        LibFunc &F) const {
    1304             :   const DataLayout *DL =
    1305     9389091 :       FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
    1306     9599671 :   return getLibFunc(FDecl.getName(), F) &&
    1307     9810253 :          isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
    1308             : }
    1309             : 
    1310        4188 : void TargetLibraryInfoImpl::disableAllFunctions() {
    1311        4188 :   memset(AvailableArray, 0, sizeof(AvailableArray));
    1312        4188 : }
    1313             : 
    1314         975 : static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
    1315         975 :   return LHS.ScalarFnName < RHS.ScalarFnName;
    1316             : }
    1317             : 
    1318        1052 : static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
    1319        1052 :   return LHS.VectorFnName < RHS.VectorFnName;
    1320             : }
    1321             : 
    1322        1464 : static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
    1323        1464 :   return LHS.ScalarFnName < S;
    1324             : }
    1325             : 
    1326           0 : static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
    1327           0 :   return LHS.VectorFnName < S;
    1328             : }
    1329             : 
    1330           3 : void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
    1331           3 :   VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
    1332             :   std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
    1333             : 
    1334           3 :   ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
    1335             :   std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
    1336           3 : }
    1337             : 
    1338       45245 : void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
    1339             :     enum VectorLibrary VecLib) {
    1340       45245 :   switch (VecLib) {
    1341           1 :   case Accelerate: {
    1342             :     const VecDesc VecFuncs[] = {
    1343             :         // Floating-Point Arithmetic and Auxiliary Functions
    1344             :         {"ceilf", "vceilf", 4},
    1345             :         {"fabsf", "vfabsf", 4},
    1346             :         {"llvm.fabs.f32", "vfabsf", 4},
    1347             :         {"floorf", "vfloorf", 4},
    1348             :         {"sqrtf", "vsqrtf", 4},
    1349             :         {"llvm.sqrt.f32", "vsqrtf", 4},
    1350             : 
    1351             :         // Exponential and Logarithmic Functions
    1352             :         {"expf", "vexpf", 4},
    1353             :         {"llvm.exp.f32", "vexpf", 4},
    1354             :         {"expm1f", "vexpm1f", 4},
    1355             :         {"logf", "vlogf", 4},
    1356             :         {"llvm.log.f32", "vlogf", 4},
    1357             :         {"log1pf", "vlog1pf", 4},
    1358             :         {"log10f", "vlog10f", 4},
    1359             :         {"llvm.log10.f32", "vlog10f", 4},
    1360             :         {"logbf", "vlogbf", 4},
    1361             : 
    1362             :         // Trigonometric Functions
    1363             :         {"sinf", "vsinf", 4},
    1364             :         {"llvm.sin.f32", "vsinf", 4},
    1365             :         {"cosf", "vcosf", 4},
    1366             :         {"llvm.cos.f32", "vcosf", 4},
    1367             :         {"tanf", "vtanf", 4},
    1368             :         {"asinf", "vasinf", 4},
    1369             :         {"acosf", "vacosf", 4},
    1370             :         {"atanf", "vatanf", 4},
    1371             : 
    1372             :         // Hyperbolic Functions
    1373             :         {"sinhf", "vsinhf", 4},
    1374             :         {"coshf", "vcoshf", 4},
    1375             :         {"tanhf", "vtanhf", 4},
    1376             :         {"asinhf", "vasinhf", 4},
    1377             :         {"acoshf", "vacoshf", 4},
    1378             :         {"atanhf", "vatanhf", 4},
    1379          29 :     };
    1380           1 :     addVectorizableFunctions(VecFuncs);
    1381             :     break;
    1382             :   }
    1383           2 :   case SVML: {
    1384             :     const VecDesc VecFuncs[] = {
    1385             :         {"sin", "__svml_sin2", 2},
    1386             :         {"sin", "__svml_sin4", 4},
    1387             :         {"sin", "__svml_sin8", 8},
    1388             : 
    1389             :         {"sinf", "__svml_sinf4", 4},
    1390             :         {"sinf", "__svml_sinf8", 8},
    1391             :         {"sinf", "__svml_sinf16", 16},
    1392             : 
    1393             :         {"cos", "__svml_cos2", 2},
    1394             :         {"cos", "__svml_cos4", 4},
    1395             :         {"cos", "__svml_cos8", 8},
    1396             : 
    1397             :         {"cosf", "__svml_cosf4", 4},
    1398             :         {"cosf", "__svml_cosf8", 8},
    1399             :         {"cosf", "__svml_cosf16", 16},
    1400             : 
    1401             :         {"pow", "__svml_pow2", 2},
    1402             :         {"pow", "__svml_pow4", 4},
    1403             :         {"pow", "__svml_pow8", 8},
    1404             : 
    1405             :         {"powf", "__svml_powf4", 4},
    1406             :         {"powf", "__svml_powf8", 8},
    1407             :         {"powf", "__svml_powf16", 16},
    1408             : 
    1409             :         { "__pow_finite", "__svml_pow2", 2 },
    1410             :         { "__pow_finite", "__svml_pow4", 4 },
    1411             :         { "__pow_finite", "__svml_pow8", 8 },
    1412             : 
    1413             :         { "__powf_finite", "__svml_powf4", 4 },
    1414             :         { "__powf_finite", "__svml_powf8", 8 },
    1415             :         { "__powf_finite", "__svml_powf16", 16 },
    1416             : 
    1417             :         {"llvm.pow.f64", "__svml_pow2", 2},
    1418             :         {"llvm.pow.f64", "__svml_pow4", 4},
    1419             :         {"llvm.pow.f64", "__svml_pow8", 8},
    1420             : 
    1421             :         {"llvm.pow.f32", "__svml_powf4", 4},
    1422             :         {"llvm.pow.f32", "__svml_powf8", 8},
    1423             :         {"llvm.pow.f32", "__svml_powf16", 16},
    1424             : 
    1425             :         {"exp", "__svml_exp2", 2},
    1426             :         {"exp", "__svml_exp4", 4},
    1427             :         {"exp", "__svml_exp8", 8},
    1428             : 
    1429             :         {"expf", "__svml_expf4", 4},
    1430             :         {"expf", "__svml_expf8", 8},
    1431             :         {"expf", "__svml_expf16", 16},
    1432             : 
    1433             :         { "__exp_finite", "__svml_exp2", 2 },
    1434             :         { "__exp_finite", "__svml_exp4", 4 },
    1435             :         { "__exp_finite", "__svml_exp8", 8 },
    1436             : 
    1437             :         { "__expf_finite", "__svml_expf4", 4 },
    1438             :         { "__expf_finite", "__svml_expf8", 8 },
    1439             :         { "__expf_finite", "__svml_expf16", 16 },
    1440             : 
    1441             :         {"llvm.exp.f64", "__svml_exp2", 2},
    1442             :         {"llvm.exp.f64", "__svml_exp4", 4},
    1443             :         {"llvm.exp.f64", "__svml_exp8", 8},
    1444             : 
    1445             :         {"llvm.exp.f32", "__svml_expf4", 4},
    1446             :         {"llvm.exp.f32", "__svml_expf8", 8},
    1447             :         {"llvm.exp.f32", "__svml_expf16", 16},
    1448             : 
    1449             :         {"log", "__svml_log2", 2},
    1450             :         {"log", "__svml_log4", 4},
    1451             :         {"log", "__svml_log8", 8},
    1452             : 
    1453             :         {"logf", "__svml_logf4", 4},
    1454             :         {"logf", "__svml_logf8", 8},
    1455             :         {"logf", "__svml_logf16", 16},
    1456             : 
    1457             :         { "__log_finite", "__svml_log2", 2 },
    1458             :         { "__log_finite", "__svml_log4", 4 },
    1459             :         { "__log_finite", "__svml_log8", 8 },
    1460             : 
    1461             :         { "__logf_finite", "__svml_logf4", 4 },
    1462             :         { "__logf_finite", "__svml_logf8", 8 },
    1463             :         { "__logf_finite", "__svml_logf16", 16 },
    1464             : 
    1465             :         {"llvm.log.f64", "__svml_log2", 2},
    1466             :         {"llvm.log.f64", "__svml_log4", 4},
    1467             :         {"llvm.log.f64", "__svml_log8", 8},
    1468             : 
    1469             :         {"llvm.log.f32", "__svml_logf4", 4},
    1470             :         {"llvm.log.f32", "__svml_logf8", 8},
    1471             :         {"llvm.log.f32", "__svml_logf16", 16},
    1472         132 :     };
    1473           2 :     addVectorizableFunctions(VecFuncs);
    1474             :     break;
    1475             :   }
    1476             :   case NoLibrary:
    1477             :     break;
    1478             :   }
    1479       45245 : }
    1480             : 
    1481        1427 : bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
    1482        1427 :   funcName = sanitizeFunctionName(funcName);
    1483        1427 :   if (funcName.empty())
    1484             :     return false;
    1485             : 
    1486             :   std::vector<VecDesc>::const_iterator I = std::lower_bound(
    1487             :       VectorDescs.begin(), VectorDescs.end(), funcName,
    1488        1427 :       compareWithScalarFnName);
    1489        1427 :   return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
    1490             : }
    1491             : 
    1492         400 : StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
    1493             :                                                        unsigned VF) const {
    1494         400 :   F = sanitizeFunctionName(F);
    1495         400 :   if (F.empty())
    1496           0 :     return F;
    1497             :   std::vector<VecDesc>::const_iterator I = std::lower_bound(
    1498         400 :       VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
    1499         557 :   while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
    1500         345 :     if (I->VectorizationFactor == VF)
    1501         188 :       return I->VectorFnName;
    1502             :     ++I;
    1503             :   }
    1504         212 :   return StringRef();
    1505             : }
    1506             : 
    1507           0 : StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
    1508             :                                                        unsigned &VF) const {
    1509           0 :   F = sanitizeFunctionName(F);
    1510           0 :   if (F.empty())
    1511           0 :     return F;
    1512             : 
    1513             :   std::vector<VecDesc>::const_iterator I = std::lower_bound(
    1514           0 :       ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
    1515           0 :   if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
    1516           0 :     return StringRef();
    1517           0 :   VF = I->VectorizationFactor;
    1518           0 :   return I->ScalarFnName;
    1519             : }
    1520             : 
    1521         255 : TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
    1522             :                                              ModuleAnalysisManager &) {
    1523         255 :   if (PresetInfoImpl)
    1524             :     return TargetLibraryInfo(*PresetInfoImpl);
    1525             : 
    1526         468 :   return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
    1527             : }
    1528             : 
    1529        2201 : TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
    1530             :                                              FunctionAnalysisManager &) {
    1531        2201 :   if (PresetInfoImpl)
    1532             :     return TargetLibraryInfo(*PresetInfoImpl);
    1533             : 
    1534             :   return TargetLibraryInfo(
    1535        5919 :       lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
    1536             : }
    1537             : 
    1538        2207 : TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
    1539             :   std::unique_ptr<TargetLibraryInfoImpl> &Impl =
    1540        4414 :       Impls[T.normalize()];
    1541        2207 :   if (!Impl)
    1542         825 :     Impl.reset(new TargetLibraryInfoImpl(T));
    1543             : 
    1544        2207 :   return *Impl;
    1545             : }
    1546             : 
    1547         107 : unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
    1548         108 :   if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
    1549             :       M.getModuleFlag("wchar_size")))
    1550         106 :     return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
    1551             :   return 0;
    1552             : }
    1553             : 
    1554        4817 : TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
    1555        4817 :     : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
    1556        4817 :   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
    1557        4817 : }
    1558             : 
    1559           0 : TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
    1560           0 :     : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
    1561           0 :   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
    1562           0 : }
    1563             : 
    1564       50189 : TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
    1565       50189 :     const TargetLibraryInfoImpl &TLIImpl)
    1566       50189 :     : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
    1567       50189 :   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
    1568       50189 : }
    1569             : 
    1570             : AnalysisKey TargetLibraryAnalysis::Key;
    1571             : 
    1572             : // Register the basic pass.
    1573     3216937 : INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
    1574             :                 "Target Library Information", false, true)
    1575             : char TargetLibraryInfoWrapperPass::ID = 0;
    1576             : 
    1577      291579 : void TargetLibraryInfoWrapperPass::anchor() {}

Generated by: LCOV version 1.13