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

Generated by: LCOV version 1.13