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

Generated by: LCOV version 1.13