Home | History | Annotate | Download | only in Target
      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/Target/TargetLibraryInfo.h"
     15 #include "llvm/ADT/Triple.h"
     16 using namespace llvm;
     17 
     18 // Register the default implementation.
     19 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
     20                 "Target Library Information", false, true)
     21 char TargetLibraryInfo::ID = 0;
     22 
     23 void TargetLibraryInfo::anchor() { }
     24 
     25 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
     26   {
     27     "_IO_getc",
     28     "_IO_putc",
     29     "_ZdaPv",
     30     "_ZdaPvRKSt9nothrow_t",
     31     "_ZdlPv",
     32     "_ZdlPvRKSt9nothrow_t",
     33     "_Znaj",
     34     "_ZnajRKSt9nothrow_t",
     35     "_Znam",
     36     "_ZnamRKSt9nothrow_t",
     37     "_Znwj",
     38     "_ZnwjRKSt9nothrow_t",
     39     "_Znwm",
     40     "_ZnwmRKSt9nothrow_t",
     41     "__cospi",
     42     "__cospif",
     43     "__cxa_atexit",
     44     "__cxa_guard_abort",
     45     "__cxa_guard_acquire",
     46     "__cxa_guard_release",
     47     "__isoc99_scanf",
     48     "__isoc99_sscanf",
     49     "__memcpy_chk",
     50     "__sincospi_stret",
     51     "__sincospif_stret",
     52     "__sinpi",
     53     "__sinpif",
     54     "__sqrt_finite",
     55     "__sqrtf_finite",
     56     "__sqrtl_finite",
     57     "__strdup",
     58     "__strndup",
     59     "__strtok_r",
     60     "abs",
     61     "access",
     62     "acos",
     63     "acosf",
     64     "acosh",
     65     "acoshf",
     66     "acoshl",
     67     "acosl",
     68     "asin",
     69     "asinf",
     70     "asinh",
     71     "asinhf",
     72     "asinhl",
     73     "asinl",
     74     "atan",
     75     "atan2",
     76     "atan2f",
     77     "atan2l",
     78     "atanf",
     79     "atanh",
     80     "atanhf",
     81     "atanhl",
     82     "atanl",
     83     "atof",
     84     "atoi",
     85     "atol",
     86     "atoll",
     87     "bcmp",
     88     "bcopy",
     89     "bzero",
     90     "calloc",
     91     "cbrt",
     92     "cbrtf",
     93     "cbrtl",
     94     "ceil",
     95     "ceilf",
     96     "ceill",
     97     "chmod",
     98     "chown",
     99     "clearerr",
    100     "closedir",
    101     "copysign",
    102     "copysignf",
    103     "copysignl",
    104     "cos",
    105     "cosf",
    106     "cosh",
    107     "coshf",
    108     "coshl",
    109     "cosl",
    110     "ctermid",
    111     "exp",
    112     "exp10",
    113     "exp10f",
    114     "exp10l",
    115     "exp2",
    116     "exp2f",
    117     "exp2l",
    118     "expf",
    119     "expl",
    120     "expm1",
    121     "expm1f",
    122     "expm1l",
    123     "fabs",
    124     "fabsf",
    125     "fabsl",
    126     "fclose",
    127     "fdopen",
    128     "feof",
    129     "ferror",
    130     "fflush",
    131     "ffs",
    132     "ffsl",
    133     "ffsll",
    134     "fgetc",
    135     "fgetpos",
    136     "fgets",
    137     "fileno",
    138     "fiprintf",
    139     "flockfile",
    140     "floor",
    141     "floorf",
    142     "floorl",
    143     "fmax",
    144     "fmaxf",
    145     "fmaxl",
    146     "fmin",
    147     "fminf",
    148     "fminl",
    149     "fmod",
    150     "fmodf",
    151     "fmodl",
    152     "fopen",
    153     "fopen64",
    154     "fprintf",
    155     "fputc",
    156     "fputs",
    157     "fread",
    158     "free",
    159     "frexp",
    160     "frexpf",
    161     "frexpl",
    162     "fscanf",
    163     "fseek",
    164     "fseeko",
    165     "fseeko64",
    166     "fsetpos",
    167     "fstat",
    168     "fstat64",
    169     "fstatvfs",
    170     "fstatvfs64",
    171     "ftell",
    172     "ftello",
    173     "ftello64",
    174     "ftrylockfile",
    175     "funlockfile",
    176     "fwrite",
    177     "getc",
    178     "getc_unlocked",
    179     "getchar",
    180     "getenv",
    181     "getitimer",
    182     "getlogin_r",
    183     "getpwnam",
    184     "gets",
    185     "gettimeofday",
    186     "htonl",
    187     "htons",
    188     "iprintf",
    189     "isascii",
    190     "isdigit",
    191     "labs",
    192     "lchown",
    193     "ldexp",
    194     "ldexpf",
    195     "ldexpl",
    196     "llabs",
    197     "log",
    198     "log10",
    199     "log10f",
    200     "log10l",
    201     "log1p",
    202     "log1pf",
    203     "log1pl",
    204     "log2",
    205     "log2f",
    206     "log2l",
    207     "logb",
    208     "logbf",
    209     "logbl",
    210     "logf",
    211     "logl",
    212     "lstat",
    213     "lstat64",
    214     "malloc",
    215     "memalign",
    216     "memccpy",
    217     "memchr",
    218     "memcmp",
    219     "memcpy",
    220     "memmove",
    221     "memrchr",
    222     "memset",
    223     "memset_pattern16",
    224     "mkdir",
    225     "mktime",
    226     "modf",
    227     "modff",
    228     "modfl",
    229     "nearbyint",
    230     "nearbyintf",
    231     "nearbyintl",
    232     "ntohl",
    233     "ntohs",
    234     "open",
    235     "open64",
    236     "opendir",
    237     "pclose",
    238     "perror",
    239     "popen",
    240     "posix_memalign",
    241     "pow",
    242     "powf",
    243     "powl",
    244     "pread",
    245     "printf",
    246     "putc",
    247     "putchar",
    248     "puts",
    249     "pwrite",
    250     "qsort",
    251     "read",
    252     "readlink",
    253     "realloc",
    254     "reallocf",
    255     "realpath",
    256     "remove",
    257     "rename",
    258     "rewind",
    259     "rint",
    260     "rintf",
    261     "rintl",
    262     "rmdir",
    263     "round",
    264     "roundf",
    265     "roundl",
    266     "scanf",
    267     "setbuf",
    268     "setitimer",
    269     "setvbuf",
    270     "sin",
    271     "sinf",
    272     "sinh",
    273     "sinhf",
    274     "sinhl",
    275     "sinl",
    276     "siprintf",
    277     "snprintf",
    278     "sprintf",
    279     "sqrt",
    280     "sqrtf",
    281     "sqrtl",
    282     "sscanf",
    283     "stat",
    284     "stat64",
    285     "statvfs",
    286     "statvfs64",
    287     "stpcpy",
    288     "stpncpy",
    289     "strcasecmp",
    290     "strcat",
    291     "strchr",
    292     "strcmp",
    293     "strcoll",
    294     "strcpy",
    295     "strcspn",
    296     "strdup",
    297     "strlen",
    298     "strncasecmp",
    299     "strncat",
    300     "strncmp",
    301     "strncpy",
    302     "strndup",
    303     "strnlen",
    304     "strpbrk",
    305     "strrchr",
    306     "strspn",
    307     "strstr",
    308     "strtod",
    309     "strtof",
    310     "strtok",
    311     "strtok_r",
    312     "strtol",
    313     "strtold",
    314     "strtoll",
    315     "strtoul",
    316     "strtoull",
    317     "strxfrm",
    318     "system",
    319     "tan",
    320     "tanf",
    321     "tanh",
    322     "tanhf",
    323     "tanhl",
    324     "tanl",
    325     "times",
    326     "tmpfile",
    327     "tmpfile64",
    328     "toascii",
    329     "trunc",
    330     "truncf",
    331     "truncl",
    332     "uname",
    333     "ungetc",
    334     "unlink",
    335     "unsetenv",
    336     "utime",
    337     "utimes",
    338     "valloc",
    339     "vfprintf",
    340     "vfscanf",
    341     "vprintf",
    342     "vscanf",
    343     "vsnprintf",
    344     "vsprintf",
    345     "vsscanf",
    346     "write"
    347   };
    348 
    349 static bool hasSinCosPiStret(const Triple &T) {
    350   // Only Darwin variants have _stret versions of combined trig functions.
    351   if (!T.isMacOSX() && T.getOS() != Triple::IOS)
    352     return false;
    353 
    354   // The ABI is rather complicated on x86, so don't do anything special there.
    355   if (T.getArch() == Triple::x86)
    356     return false;
    357 
    358   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
    359     return false;
    360 
    361   if (T.getOS() == Triple::IOS && T.isOSVersionLT(7, 0))
    362     return false;
    363 
    364   return true;
    365 }
    366 
    367 /// initialize - Initialize the set of available library functions based on the
    368 /// specified target triple.  This should be carefully written so that a missing
    369 /// target triple gets a sane set of defaults.
    370 static void initialize(TargetLibraryInfo &TLI, const Triple &T,
    371                        const char **StandardNames) {
    372   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
    373 
    374 #ifndef NDEBUG
    375   // Verify that the StandardNames array is in alphabetical order.
    376   for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) {
    377     if (strcmp(StandardNames[F-1], StandardNames[F]) >= 0)
    378       llvm_unreachable("TargetLibraryInfo function names must be sorted");
    379   }
    380 #endif // !NDEBUG
    381 
    382   // There are no library implementations of mempcy and memset for r600 and
    383   // these can be difficult to lower in the backend.
    384   if (T.getArch() == Triple::r600) {
    385     TLI.setUnavailable(LibFunc::memcpy);
    386     TLI.setUnavailable(LibFunc::memset);
    387     TLI.setUnavailable(LibFunc::memset_pattern16);
    388     return;
    389   }
    390 
    391   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
    392   if (T.isMacOSX()) {
    393     if (T.isMacOSXVersionLT(10, 5))
    394       TLI.setUnavailable(LibFunc::memset_pattern16);
    395   } else if (T.isiOS()) {
    396     if (T.isOSVersionLT(3, 0))
    397       TLI.setUnavailable(LibFunc::memset_pattern16);
    398   } else {
    399     TLI.setUnavailable(LibFunc::memset_pattern16);
    400   }
    401 
    402   if (!hasSinCosPiStret(T)) {
    403     TLI.setUnavailable(LibFunc::sinpi);
    404     TLI.setUnavailable(LibFunc::sinpif);
    405     TLI.setUnavailable(LibFunc::cospi);
    406     TLI.setUnavailable(LibFunc::cospif);
    407     TLI.setUnavailable(LibFunc::sincospi_stret);
    408     TLI.setUnavailable(LibFunc::sincospif_stret);
    409   }
    410 
    411   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
    412       !T.isMacOSXVersionLT(10, 7)) {
    413     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
    414     // we don't care about) have two versions; on recent OSX, the one we want
    415     // has a $UNIX2003 suffix. The two implementations are identical except
    416     // for the return value in some edge cases.  However, we don't want to
    417     // generate code that depends on the old symbols.
    418     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
    419     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
    420   }
    421 
    422   // iprintf and friends are only available on XCore and TCE.
    423   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
    424     TLI.setUnavailable(LibFunc::iprintf);
    425     TLI.setUnavailable(LibFunc::siprintf);
    426     TLI.setUnavailable(LibFunc::fiprintf);
    427   }
    428 
    429   if (T.isKnownWindowsMSVCEnvironment()) {
    430     // Win32 does not support long double
    431     TLI.setUnavailable(LibFunc::acosl);
    432     TLI.setUnavailable(LibFunc::asinl);
    433     TLI.setUnavailable(LibFunc::atanl);
    434     TLI.setUnavailable(LibFunc::atan2l);
    435     TLI.setUnavailable(LibFunc::ceill);
    436     TLI.setUnavailable(LibFunc::copysignl);
    437     TLI.setUnavailable(LibFunc::cosl);
    438     TLI.setUnavailable(LibFunc::coshl);
    439     TLI.setUnavailable(LibFunc::expl);
    440     TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
    441     TLI.setUnavailable(LibFunc::fabsl);
    442     TLI.setUnavailable(LibFunc::floorl);
    443     TLI.setUnavailable(LibFunc::fmaxl);
    444     TLI.setUnavailable(LibFunc::fminl);
    445     TLI.setUnavailable(LibFunc::fmodl);
    446     TLI.setUnavailable(LibFunc::frexpl);
    447     TLI.setUnavailable(LibFunc::ldexpf);
    448     TLI.setUnavailable(LibFunc::ldexpl);
    449     TLI.setUnavailable(LibFunc::logl);
    450     TLI.setUnavailable(LibFunc::modfl);
    451     TLI.setUnavailable(LibFunc::powl);
    452     TLI.setUnavailable(LibFunc::sinl);
    453     TLI.setUnavailable(LibFunc::sinhl);
    454     TLI.setUnavailable(LibFunc::sqrtl);
    455     TLI.setUnavailable(LibFunc::tanl);
    456     TLI.setUnavailable(LibFunc::tanhl);
    457 
    458     // Win32 only has C89 math
    459     TLI.setUnavailable(LibFunc::acosh);
    460     TLI.setUnavailable(LibFunc::acoshf);
    461     TLI.setUnavailable(LibFunc::acoshl);
    462     TLI.setUnavailable(LibFunc::asinh);
    463     TLI.setUnavailable(LibFunc::asinhf);
    464     TLI.setUnavailable(LibFunc::asinhl);
    465     TLI.setUnavailable(LibFunc::atanh);
    466     TLI.setUnavailable(LibFunc::atanhf);
    467     TLI.setUnavailable(LibFunc::atanhl);
    468     TLI.setUnavailable(LibFunc::cbrt);
    469     TLI.setUnavailable(LibFunc::cbrtf);
    470     TLI.setUnavailable(LibFunc::cbrtl);
    471     TLI.setUnavailable(LibFunc::exp2);
    472     TLI.setUnavailable(LibFunc::exp2f);
    473     TLI.setUnavailable(LibFunc::exp2l);
    474     TLI.setUnavailable(LibFunc::expm1);
    475     TLI.setUnavailable(LibFunc::expm1f);
    476     TLI.setUnavailable(LibFunc::expm1l);
    477     TLI.setUnavailable(LibFunc::log2);
    478     TLI.setUnavailable(LibFunc::log2f);
    479     TLI.setUnavailable(LibFunc::log2l);
    480     TLI.setUnavailable(LibFunc::log1p);
    481     TLI.setUnavailable(LibFunc::log1pf);
    482     TLI.setUnavailable(LibFunc::log1pl);
    483     TLI.setUnavailable(LibFunc::logb);
    484     TLI.setUnavailable(LibFunc::logbf);
    485     TLI.setUnavailable(LibFunc::logbl);
    486     TLI.setUnavailable(LibFunc::nearbyint);
    487     TLI.setUnavailable(LibFunc::nearbyintf);
    488     TLI.setUnavailable(LibFunc::nearbyintl);
    489     TLI.setUnavailable(LibFunc::rint);
    490     TLI.setUnavailable(LibFunc::rintf);
    491     TLI.setUnavailable(LibFunc::rintl);
    492     TLI.setUnavailable(LibFunc::round);
    493     TLI.setUnavailable(LibFunc::roundf);
    494     TLI.setUnavailable(LibFunc::roundl);
    495     TLI.setUnavailable(LibFunc::trunc);
    496     TLI.setUnavailable(LibFunc::truncf);
    497     TLI.setUnavailable(LibFunc::truncl);
    498 
    499     // Win32 provides some C99 math with mangled names
    500     TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
    501 
    502     if (T.getArch() == Triple::x86) {
    503       // Win32 on x86 implements single-precision math functions as macros
    504       TLI.setUnavailable(LibFunc::acosf);
    505       TLI.setUnavailable(LibFunc::asinf);
    506       TLI.setUnavailable(LibFunc::atanf);
    507       TLI.setUnavailable(LibFunc::atan2f);
    508       TLI.setUnavailable(LibFunc::ceilf);
    509       TLI.setUnavailable(LibFunc::copysignf);
    510       TLI.setUnavailable(LibFunc::cosf);
    511       TLI.setUnavailable(LibFunc::coshf);
    512       TLI.setUnavailable(LibFunc::expf);
    513       TLI.setUnavailable(LibFunc::floorf);
    514       TLI.setUnavailable(LibFunc::fminf);
    515       TLI.setUnavailable(LibFunc::fmaxf);
    516       TLI.setUnavailable(LibFunc::fmodf);
    517       TLI.setUnavailable(LibFunc::logf);
    518       TLI.setUnavailable(LibFunc::powf);
    519       TLI.setUnavailable(LibFunc::sinf);
    520       TLI.setUnavailable(LibFunc::sinhf);
    521       TLI.setUnavailable(LibFunc::sqrtf);
    522       TLI.setUnavailable(LibFunc::tanf);
    523       TLI.setUnavailable(LibFunc::tanhf);
    524     }
    525 
    526     // Win32 does *not* provide provide these functions, but they are
    527     // generally available on POSIX-compliant systems:
    528     TLI.setUnavailable(LibFunc::access);
    529     TLI.setUnavailable(LibFunc::bcmp);
    530     TLI.setUnavailable(LibFunc::bcopy);
    531     TLI.setUnavailable(LibFunc::bzero);
    532     TLI.setUnavailable(LibFunc::chmod);
    533     TLI.setUnavailable(LibFunc::chown);
    534     TLI.setUnavailable(LibFunc::closedir);
    535     TLI.setUnavailable(LibFunc::ctermid);
    536     TLI.setUnavailable(LibFunc::fdopen);
    537     TLI.setUnavailable(LibFunc::ffs);
    538     TLI.setUnavailable(LibFunc::fileno);
    539     TLI.setUnavailable(LibFunc::flockfile);
    540     TLI.setUnavailable(LibFunc::fseeko);
    541     TLI.setUnavailable(LibFunc::fstat);
    542     TLI.setUnavailable(LibFunc::fstatvfs);
    543     TLI.setUnavailable(LibFunc::ftello);
    544     TLI.setUnavailable(LibFunc::ftrylockfile);
    545     TLI.setUnavailable(LibFunc::funlockfile);
    546     TLI.setUnavailable(LibFunc::getc_unlocked);
    547     TLI.setUnavailable(LibFunc::getitimer);
    548     TLI.setUnavailable(LibFunc::getlogin_r);
    549     TLI.setUnavailable(LibFunc::getpwnam);
    550     TLI.setUnavailable(LibFunc::gettimeofday);
    551     TLI.setUnavailable(LibFunc::htonl);
    552     TLI.setUnavailable(LibFunc::htons);
    553     TLI.setUnavailable(LibFunc::lchown);
    554     TLI.setUnavailable(LibFunc::lstat);
    555     TLI.setUnavailable(LibFunc::memccpy);
    556     TLI.setUnavailable(LibFunc::mkdir);
    557     TLI.setUnavailable(LibFunc::ntohl);
    558     TLI.setUnavailable(LibFunc::ntohs);
    559     TLI.setUnavailable(LibFunc::open);
    560     TLI.setUnavailable(LibFunc::opendir);
    561     TLI.setUnavailable(LibFunc::pclose);
    562     TLI.setUnavailable(LibFunc::popen);
    563     TLI.setUnavailable(LibFunc::pread);
    564     TLI.setUnavailable(LibFunc::pwrite);
    565     TLI.setUnavailable(LibFunc::read);
    566     TLI.setUnavailable(LibFunc::readlink);
    567     TLI.setUnavailable(LibFunc::realpath);
    568     TLI.setUnavailable(LibFunc::rmdir);
    569     TLI.setUnavailable(LibFunc::setitimer);
    570     TLI.setUnavailable(LibFunc::stat);
    571     TLI.setUnavailable(LibFunc::statvfs);
    572     TLI.setUnavailable(LibFunc::stpcpy);
    573     TLI.setUnavailable(LibFunc::stpncpy);
    574     TLI.setUnavailable(LibFunc::strcasecmp);
    575     TLI.setUnavailable(LibFunc::strncasecmp);
    576     TLI.setUnavailable(LibFunc::times);
    577     TLI.setUnavailable(LibFunc::uname);
    578     TLI.setUnavailable(LibFunc::unlink);
    579     TLI.setUnavailable(LibFunc::unsetenv);
    580     TLI.setUnavailable(LibFunc::utime);
    581     TLI.setUnavailable(LibFunc::utimes);
    582     TLI.setUnavailable(LibFunc::write);
    583 
    584     // Win32 does *not* provide provide these functions, but they are
    585     // specified by C99:
    586     TLI.setUnavailable(LibFunc::atoll);
    587     TLI.setUnavailable(LibFunc::frexpf);
    588     TLI.setUnavailable(LibFunc::llabs);
    589   }
    590 
    591   switch (T.getOS()) {
    592   case Triple::MacOSX:
    593     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
    594     // and their names are __exp10 and __exp10f. exp10l is not available on
    595     // OS X or iOS.
    596     TLI.setUnavailable(LibFunc::exp10l);
    597     if (T.isMacOSXVersionLT(10, 9)) {
    598       TLI.setUnavailable(LibFunc::exp10);
    599       TLI.setUnavailable(LibFunc::exp10f);
    600     } else {
    601       TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
    602       TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
    603     }
    604     break;
    605   case Triple::IOS:
    606     TLI.setUnavailable(LibFunc::exp10l);
    607     if (T.isOSVersionLT(7, 0)) {
    608       TLI.setUnavailable(LibFunc::exp10);
    609       TLI.setUnavailable(LibFunc::exp10f);
    610     } else {
    611       TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
    612       TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
    613     }
    614     break;
    615   case Triple::Linux:
    616     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
    617     // buggy prior to glibc version 2.18. Until this version is widely deployed
    618     // or we have a reasonable detection strategy, we cannot use exp10 reliably
    619     // on Linux.
    620     //
    621     // Fall through to disable all of them.
    622   default:
    623     TLI.setUnavailable(LibFunc::exp10);
    624     TLI.setUnavailable(LibFunc::exp10f);
    625     TLI.setUnavailable(LibFunc::exp10l);
    626   }
    627 
    628   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
    629   // Linux (GLIBC):
    630   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
    631   // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsl.c
    632   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
    633   switch (T.getOS()) {
    634   case Triple::Darwin:
    635   case Triple::MacOSX:
    636   case Triple::IOS:
    637   case Triple::FreeBSD:
    638   case Triple::Linux:
    639     break;
    640   default:
    641     TLI.setUnavailable(LibFunc::ffsl);
    642   }
    643 
    644   // ffsll is available on at least FreeBSD and Linux (GLIBC):
    645   // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsll.c
    646   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
    647   switch (T.getOS()) {
    648   case Triple::FreeBSD:
    649   case Triple::Linux:
    650     break;
    651   default:
    652     TLI.setUnavailable(LibFunc::ffsll);
    653   }
    654 
    655   // The following functions are available on at least Linux:
    656   if (!T.isOSLinux()) {
    657     TLI.setUnavailable(LibFunc::dunder_strdup);
    658     TLI.setUnavailable(LibFunc::dunder_strtok_r);
    659     TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
    660     TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
    661     TLI.setUnavailable(LibFunc::under_IO_getc);
    662     TLI.setUnavailable(LibFunc::under_IO_putc);
    663     TLI.setUnavailable(LibFunc::memalign);
    664     TLI.setUnavailable(LibFunc::fopen64);
    665     TLI.setUnavailable(LibFunc::fseeko64);
    666     TLI.setUnavailable(LibFunc::fstat64);
    667     TLI.setUnavailable(LibFunc::fstatvfs64);
    668     TLI.setUnavailable(LibFunc::ftello64);
    669     TLI.setUnavailable(LibFunc::lstat64);
    670     TLI.setUnavailable(LibFunc::open64);
    671     TLI.setUnavailable(LibFunc::stat64);
    672     TLI.setUnavailable(LibFunc::statvfs64);
    673     TLI.setUnavailable(LibFunc::tmpfile64);
    674   }
    675 }
    676 
    677 
    678 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
    679   // Default to everything being available.
    680   memset(AvailableArray, -1, sizeof(AvailableArray));
    681 
    682   initialize(*this, Triple(), StandardNames);
    683 }
    684 
    685 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
    686   // Default to everything being available.
    687   memset(AvailableArray, -1, sizeof(AvailableArray));
    688 
    689   initialize(*this, T, StandardNames);
    690 }
    691 
    692 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
    693   : ImmutablePass(ID) {
    694   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
    695   CustomNames = TLI.CustomNames;
    696 }
    697 
    698 namespace {
    699 struct StringComparator {
    700   /// Compare two strings and return true if LHS is lexicographically less than
    701   /// RHS. Requires that RHS doesn't contain any zero bytes.
    702   bool operator()(const char *LHS, StringRef RHS) const {
    703     // Compare prefixes with strncmp. If prefixes match we know that LHS is
    704     // greater or equal to RHS as RHS can't contain any '\0'.
    705     return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;
    706   }
    707 
    708   // Provided for compatibility with MSVC's debug mode.
    709   bool operator()(StringRef LHS, const char *RHS) const { return LHS < RHS; }
    710   bool operator()(StringRef LHS, StringRef RHS) const { return LHS < RHS; }
    711   bool operator()(const char *LHS, const char *RHS) const {
    712     return std::strcmp(LHS, RHS) < 0;
    713   }
    714 };
    715 }
    716 
    717 bool TargetLibraryInfo::getLibFunc(StringRef funcName,
    718                                    LibFunc::Func &F) const {
    719   const char **Start = &StandardNames[0];
    720   const char **End = &StandardNames[LibFunc::NumLibFuncs];
    721 
    722   // Filter out empty names and names containing null bytes, those can't be in
    723   // our table.
    724   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
    725     return false;
    726 
    727   // Check for \01 prefix that is used to mangle __asm declarations and
    728   // strip it if present.
    729   if (funcName.front() == '\01')
    730     funcName = funcName.substr(1);
    731   const char **I = std::lower_bound(Start, End, funcName, StringComparator());
    732   if (I != End && *I == funcName) {
    733     F = (LibFunc::Func)(I - Start);
    734     return true;
    735   }
    736   return false;
    737 }
    738 
    739 /// disableAllFunctions - This disables all builtins, which is used for options
    740 /// like -fno-builtin.
    741 void TargetLibraryInfo::disableAllFunctions() {
    742   memset(AvailableArray, 0, sizeof(AvailableArray));
    743 }
    744