LLVM API Documentation

TargetLibraryInfo.cpp
Go to the documentation of this file.
00001 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the TargetLibraryInfo class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Target/TargetLibraryInfo.h"
00015 #include "llvm/ADT/Triple.h"
00016 using namespace llvm;
00017 
00018 // Register the default implementation.
00019 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
00020                 "Target Library Information", false, true)
00021 char TargetLibraryInfo::ID = 0;
00022 
00023 void TargetLibraryInfo::anchor() { }
00024 
00025 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
00026   {
00027     "_IO_getc",
00028     "_IO_putc",
00029     "_ZdaPv",
00030     "_ZdaPvRKSt9nothrow_t",
00031     "_ZdlPv",
00032     "_ZdlPvRKSt9nothrow_t",
00033     "_Znaj",
00034     "_ZnajRKSt9nothrow_t",
00035     "_Znam",
00036     "_ZnamRKSt9nothrow_t",
00037     "_Znwj",
00038     "_ZnwjRKSt9nothrow_t",
00039     "_Znwm",
00040     "_ZnwmRKSt9nothrow_t",
00041     "__cospi",
00042     "__cospif",
00043     "__cxa_atexit",
00044     "__cxa_guard_abort",
00045     "__cxa_guard_acquire",
00046     "__cxa_guard_release",
00047     "__isoc99_scanf",
00048     "__isoc99_sscanf",
00049     "__memcpy_chk",
00050     "__sincospi_stret",
00051     "__sincospif_stret",
00052     "__sinpi",
00053     "__sinpif",
00054     "__sqrt_finite",
00055     "__sqrtf_finite",
00056     "__sqrtl_finite",
00057     "__strdup",
00058     "__strndup",
00059     "__strtok_r",
00060     "abs",
00061     "access",
00062     "acos",
00063     "acosf",
00064     "acosh",
00065     "acoshf",
00066     "acoshl",
00067     "acosl",
00068     "asin",
00069     "asinf",
00070     "asinh",
00071     "asinhf",
00072     "asinhl",
00073     "asinl",
00074     "atan",
00075     "atan2",
00076     "atan2f",
00077     "atan2l",
00078     "atanf",
00079     "atanh",
00080     "atanhf",
00081     "atanhl",
00082     "atanl",
00083     "atof",
00084     "atoi",
00085     "atol",
00086     "atoll",
00087     "bcmp",
00088     "bcopy",
00089     "bzero",
00090     "calloc",
00091     "cbrt",
00092     "cbrtf",
00093     "cbrtl",
00094     "ceil",
00095     "ceilf",
00096     "ceill",
00097     "chmod",
00098     "chown",
00099     "clearerr",
00100     "closedir",
00101     "copysign",
00102     "copysignf",
00103     "copysignl",
00104     "cos",
00105     "cosf",
00106     "cosh",
00107     "coshf",
00108     "coshl",
00109     "cosl",
00110     "ctermid",
00111     "exp",
00112     "exp10",
00113     "exp10f",
00114     "exp10l",
00115     "exp2",
00116     "exp2f",
00117     "exp2l",
00118     "expf",
00119     "expl",
00120     "expm1",
00121     "expm1f",
00122     "expm1l",
00123     "fabs",
00124     "fabsf",
00125     "fabsl",
00126     "fclose",
00127     "fdopen",
00128     "feof",
00129     "ferror",
00130     "fflush",
00131     "ffs",
00132     "ffsl",
00133     "ffsll",
00134     "fgetc",
00135     "fgetpos",
00136     "fgets",
00137     "fileno",
00138     "fiprintf",
00139     "flockfile",
00140     "floor",
00141     "floorf",
00142     "floorl",
00143     "fmax",
00144     "fmaxf",
00145     "fmaxl",
00146     "fmin",
00147     "fminf",
00148     "fminl",
00149     "fmod",
00150     "fmodf",
00151     "fmodl",
00152     "fopen",
00153     "fopen64",
00154     "fprintf",
00155     "fputc",
00156     "fputs",
00157     "fread",
00158     "free",
00159     "frexp",
00160     "frexpf",
00161     "frexpl",
00162     "fscanf",
00163     "fseek",
00164     "fseeko",
00165     "fseeko64",
00166     "fsetpos",
00167     "fstat",
00168     "fstat64",
00169     "fstatvfs",
00170     "fstatvfs64",
00171     "ftell",
00172     "ftello",
00173     "ftello64",
00174     "ftrylockfile",
00175     "funlockfile",
00176     "fwrite",
00177     "getc",
00178     "getc_unlocked",
00179     "getchar",
00180     "getenv",
00181     "getitimer",
00182     "getlogin_r",
00183     "getpwnam",
00184     "gets",
00185     "gettimeofday",
00186     "htonl",
00187     "htons",
00188     "iprintf",
00189     "isascii",
00190     "isdigit",
00191     "labs",
00192     "lchown",
00193     "ldexp",
00194     "ldexpf",
00195     "ldexpl",
00196     "llabs",
00197     "log",
00198     "log10",
00199     "log10f",
00200     "log10l",
00201     "log1p",
00202     "log1pf",
00203     "log1pl",
00204     "log2",
00205     "log2f",
00206     "log2l",
00207     "logb",
00208     "logbf",
00209     "logbl",
00210     "logf",
00211     "logl",
00212     "lstat",
00213     "lstat64",
00214     "malloc",
00215     "memalign",
00216     "memccpy",
00217     "memchr",
00218     "memcmp",
00219     "memcpy",
00220     "memmove",
00221     "memrchr",
00222     "memset",
00223     "memset_pattern16",
00224     "mkdir",
00225     "mktime",
00226     "modf",
00227     "modff",
00228     "modfl",
00229     "nearbyint",
00230     "nearbyintf",
00231     "nearbyintl",
00232     "ntohl",
00233     "ntohs",
00234     "open",
00235     "open64",
00236     "opendir",
00237     "pclose",
00238     "perror",
00239     "popen",
00240     "posix_memalign",
00241     "pow",
00242     "powf",
00243     "powl",
00244     "pread",
00245     "printf",
00246     "putc",
00247     "putchar",
00248     "puts",
00249     "pwrite",
00250     "qsort",
00251     "read",
00252     "readlink",
00253     "realloc",
00254     "reallocf",
00255     "realpath",
00256     "remove",
00257     "rename",
00258     "rewind",
00259     "rint",
00260     "rintf",
00261     "rintl",
00262     "rmdir",
00263     "round",
00264     "roundf",
00265     "roundl",
00266     "scanf",
00267     "setbuf",
00268     "setitimer",
00269     "setvbuf",
00270     "sin",
00271     "sinf",
00272     "sinh",
00273     "sinhf",
00274     "sinhl",
00275     "sinl",
00276     "siprintf",
00277     "snprintf",
00278     "sprintf",
00279     "sqrt",
00280     "sqrtf",
00281     "sqrtl",
00282     "sscanf",
00283     "stat",
00284     "stat64",
00285     "statvfs",
00286     "statvfs64",
00287     "stpcpy",
00288     "stpncpy",
00289     "strcasecmp",
00290     "strcat",
00291     "strchr",
00292     "strcmp",
00293     "strcoll",
00294     "strcpy",
00295     "strcspn",
00296     "strdup",
00297     "strlen",
00298     "strncasecmp",
00299     "strncat",
00300     "strncmp",
00301     "strncpy",
00302     "strndup",
00303     "strnlen",
00304     "strpbrk",
00305     "strrchr",
00306     "strspn",
00307     "strstr",
00308     "strtod",
00309     "strtof",
00310     "strtok",
00311     "strtok_r",
00312     "strtol",
00313     "strtold",
00314     "strtoll",
00315     "strtoul",
00316     "strtoull",
00317     "strxfrm",
00318     "system",
00319     "tan",
00320     "tanf",
00321     "tanh",
00322     "tanhf",
00323     "tanhl",
00324     "tanl",
00325     "times",
00326     "tmpfile",
00327     "tmpfile64",
00328     "toascii",
00329     "trunc",
00330     "truncf",
00331     "truncl",
00332     "uname",
00333     "ungetc",
00334     "unlink",
00335     "unsetenv",
00336     "utime",
00337     "utimes",
00338     "valloc",
00339     "vfprintf",
00340     "vfscanf",
00341     "vprintf",
00342     "vscanf",
00343     "vsnprintf",
00344     "vsprintf",
00345     "vsscanf",
00346     "write"
00347   };
00348 
00349 static bool hasSinCosPiStret(const Triple &T) {
00350   // Only Darwin variants have _stret versions of combined trig functions.
00351   if (!T.isMacOSX() && T.getOS() != Triple::IOS)
00352     return false;
00353 
00354   // The ABI is rather complicated on x86, so don't do anything special there.
00355   if (T.getArch() == Triple::x86)
00356     return false;
00357 
00358   if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
00359     return false;
00360 
00361   if (T.getOS() == Triple::IOS && T.isOSVersionLT(7, 0))
00362     return false;
00363 
00364   return true;
00365 }
00366 
00367 /// initialize - Initialize the set of available library functions based on the
00368 /// specified target triple.  This should be carefully written so that a missing
00369 /// target triple gets a sane set of defaults.
00370 static void initialize(TargetLibraryInfo &TLI, const Triple &T,
00371                        const char **StandardNames) {
00372   initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry());
00373 
00374 #ifndef NDEBUG
00375   // Verify that the StandardNames array is in alphabetical order.
00376   for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) {
00377     if (strcmp(StandardNames[F-1], StandardNames[F]) >= 0)
00378       llvm_unreachable("TargetLibraryInfo function names must be sorted");
00379   }
00380 #endif // !NDEBUG
00381 
00382   // There are no library implementations of mempcy and memset for r600 and
00383   // these can be difficult to lower in the backend.
00384   if (T.getArch() == Triple::r600) {
00385     TLI.setUnavailable(LibFunc::memcpy);
00386     TLI.setUnavailable(LibFunc::memset);
00387     TLI.setUnavailable(LibFunc::memset_pattern16);
00388     return;
00389   }
00390 
00391   // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
00392   if (T.isMacOSX()) {
00393     if (T.isMacOSXVersionLT(10, 5))
00394       TLI.setUnavailable(LibFunc::memset_pattern16);
00395   } else if (T.isiOS()) {
00396     if (T.isOSVersionLT(3, 0))
00397       TLI.setUnavailable(LibFunc::memset_pattern16);
00398   } else {
00399     TLI.setUnavailable(LibFunc::memset_pattern16);
00400   }
00401 
00402   if (!hasSinCosPiStret(T)) {
00403     TLI.setUnavailable(LibFunc::sinpi);
00404     TLI.setUnavailable(LibFunc::sinpif);
00405     TLI.setUnavailable(LibFunc::cospi);
00406     TLI.setUnavailable(LibFunc::cospif);
00407     TLI.setUnavailable(LibFunc::sincospi_stret);
00408     TLI.setUnavailable(LibFunc::sincospif_stret);
00409   }
00410 
00411   if (T.isMacOSX() && T.getArch() == Triple::x86 &&
00412       !T.isMacOSXVersionLT(10, 7)) {
00413     // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
00414     // we don't care about) have two versions; on recent OSX, the one we want
00415     // has a $UNIX2003 suffix. The two implementations are identical except
00416     // for the return value in some edge cases.  However, we don't want to
00417     // generate code that depends on the old symbols.
00418     TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
00419     TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
00420   }
00421 
00422   // iprintf and friends are only available on XCore and TCE.
00423   if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
00424     TLI.setUnavailable(LibFunc::iprintf);
00425     TLI.setUnavailable(LibFunc::siprintf);
00426     TLI.setUnavailable(LibFunc::fiprintf);
00427   }
00428 
00429   if (T.isOSWindows() && !T.isOSCygMing()) {
00430     // Win32 does not support long double
00431     TLI.setUnavailable(LibFunc::acosl);
00432     TLI.setUnavailable(LibFunc::asinl);
00433     TLI.setUnavailable(LibFunc::atanl);
00434     TLI.setUnavailable(LibFunc::atan2l);
00435     TLI.setUnavailable(LibFunc::ceill);
00436     TLI.setUnavailable(LibFunc::copysignl);
00437     TLI.setUnavailable(LibFunc::cosl);
00438     TLI.setUnavailable(LibFunc::coshl);
00439     TLI.setUnavailable(LibFunc::expl);
00440     TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
00441     TLI.setUnavailable(LibFunc::fabsl);
00442     TLI.setUnavailable(LibFunc::floorl);
00443     TLI.setUnavailable(LibFunc::fmaxl);
00444     TLI.setUnavailable(LibFunc::fminl);
00445     TLI.setUnavailable(LibFunc::fmodl);
00446     TLI.setUnavailable(LibFunc::frexpl);
00447     TLI.setUnavailable(LibFunc::ldexpf);
00448     TLI.setUnavailable(LibFunc::ldexpl);
00449     TLI.setUnavailable(LibFunc::logl);
00450     TLI.setUnavailable(LibFunc::modfl);
00451     TLI.setUnavailable(LibFunc::powl);
00452     TLI.setUnavailable(LibFunc::sinl);
00453     TLI.setUnavailable(LibFunc::sinhl);
00454     TLI.setUnavailable(LibFunc::sqrtl);
00455     TLI.setUnavailable(LibFunc::tanl);
00456     TLI.setUnavailable(LibFunc::tanhl);
00457 
00458     // Win32 only has C89 math
00459     TLI.setUnavailable(LibFunc::acosh);
00460     TLI.setUnavailable(LibFunc::acoshf);
00461     TLI.setUnavailable(LibFunc::acoshl);
00462     TLI.setUnavailable(LibFunc::asinh);
00463     TLI.setUnavailable(LibFunc::asinhf);
00464     TLI.setUnavailable(LibFunc::asinhl);
00465     TLI.setUnavailable(LibFunc::atanh);
00466     TLI.setUnavailable(LibFunc::atanhf);
00467     TLI.setUnavailable(LibFunc::atanhl);
00468     TLI.setUnavailable(LibFunc::cbrt);
00469     TLI.setUnavailable(LibFunc::cbrtf);
00470     TLI.setUnavailable(LibFunc::cbrtl);
00471     TLI.setUnavailable(LibFunc::exp2);
00472     TLI.setUnavailable(LibFunc::exp2f);
00473     TLI.setUnavailable(LibFunc::exp2l);
00474     TLI.setUnavailable(LibFunc::expm1);
00475     TLI.setUnavailable(LibFunc::expm1f);
00476     TLI.setUnavailable(LibFunc::expm1l);
00477     TLI.setUnavailable(LibFunc::log2);
00478     TLI.setUnavailable(LibFunc::log2f);
00479     TLI.setUnavailable(LibFunc::log2l);
00480     TLI.setUnavailable(LibFunc::log1p);
00481     TLI.setUnavailable(LibFunc::log1pf);
00482     TLI.setUnavailable(LibFunc::log1pl);
00483     TLI.setUnavailable(LibFunc::logb);
00484     TLI.setUnavailable(LibFunc::logbf);
00485     TLI.setUnavailable(LibFunc::logbl);
00486     TLI.setUnavailable(LibFunc::nearbyint);
00487     TLI.setUnavailable(LibFunc::nearbyintf);
00488     TLI.setUnavailable(LibFunc::nearbyintl);
00489     TLI.setUnavailable(LibFunc::rint);
00490     TLI.setUnavailable(LibFunc::rintf);
00491     TLI.setUnavailable(LibFunc::rintl);
00492     TLI.setUnavailable(LibFunc::round);
00493     TLI.setUnavailable(LibFunc::roundf);
00494     TLI.setUnavailable(LibFunc::roundl);
00495     TLI.setUnavailable(LibFunc::trunc);
00496     TLI.setUnavailable(LibFunc::truncf);
00497     TLI.setUnavailable(LibFunc::truncl);
00498 
00499     // Win32 provides some C99 math with mangled names
00500     TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
00501 
00502     if (T.getArch() == Triple::x86) {
00503       // Win32 on x86 implements single-precision math functions as macros
00504       TLI.setUnavailable(LibFunc::acosf);
00505       TLI.setUnavailable(LibFunc::asinf);
00506       TLI.setUnavailable(LibFunc::atanf);
00507       TLI.setUnavailable(LibFunc::atan2f);
00508       TLI.setUnavailable(LibFunc::ceilf);
00509       TLI.setUnavailable(LibFunc::copysignf);
00510       TLI.setUnavailable(LibFunc::cosf);
00511       TLI.setUnavailable(LibFunc::coshf);
00512       TLI.setUnavailable(LibFunc::expf);
00513       TLI.setUnavailable(LibFunc::floorf);
00514       TLI.setUnavailable(LibFunc::fminf);
00515       TLI.setUnavailable(LibFunc::fmaxf);
00516       TLI.setUnavailable(LibFunc::fmodf);
00517       TLI.setUnavailable(LibFunc::logf);
00518       TLI.setUnavailable(LibFunc::powf);
00519       TLI.setUnavailable(LibFunc::sinf);
00520       TLI.setUnavailable(LibFunc::sinhf);
00521       TLI.setUnavailable(LibFunc::sqrtf);
00522       TLI.setUnavailable(LibFunc::tanf);
00523       TLI.setUnavailable(LibFunc::tanhf);
00524     }
00525 
00526     // Win32 does *not* provide provide these functions, but they are
00527     // generally available on POSIX-compliant systems:
00528     TLI.setUnavailable(LibFunc::access);
00529     TLI.setUnavailable(LibFunc::bcmp);
00530     TLI.setUnavailable(LibFunc::bcopy);
00531     TLI.setUnavailable(LibFunc::bzero);
00532     TLI.setUnavailable(LibFunc::chmod);
00533     TLI.setUnavailable(LibFunc::chown);
00534     TLI.setUnavailable(LibFunc::closedir);
00535     TLI.setUnavailable(LibFunc::ctermid);
00536     TLI.setUnavailable(LibFunc::fdopen);
00537     TLI.setUnavailable(LibFunc::ffs);
00538     TLI.setUnavailable(LibFunc::fileno);
00539     TLI.setUnavailable(LibFunc::flockfile);
00540     TLI.setUnavailable(LibFunc::fseeko);
00541     TLI.setUnavailable(LibFunc::fstat);
00542     TLI.setUnavailable(LibFunc::fstatvfs);
00543     TLI.setUnavailable(LibFunc::ftello);
00544     TLI.setUnavailable(LibFunc::ftrylockfile);
00545     TLI.setUnavailable(LibFunc::funlockfile);
00546     TLI.setUnavailable(LibFunc::getc_unlocked);
00547     TLI.setUnavailable(LibFunc::getitimer);
00548     TLI.setUnavailable(LibFunc::getlogin_r);
00549     TLI.setUnavailable(LibFunc::getpwnam);
00550     TLI.setUnavailable(LibFunc::gettimeofday);
00551     TLI.setUnavailable(LibFunc::htonl);
00552     TLI.setUnavailable(LibFunc::htons);
00553     TLI.setUnavailable(LibFunc::lchown);
00554     TLI.setUnavailable(LibFunc::lstat);
00555     TLI.setUnavailable(LibFunc::memccpy);
00556     TLI.setUnavailable(LibFunc::mkdir);
00557     TLI.setUnavailable(LibFunc::ntohl);
00558     TLI.setUnavailable(LibFunc::ntohs);
00559     TLI.setUnavailable(LibFunc::open);
00560     TLI.setUnavailable(LibFunc::opendir);
00561     TLI.setUnavailable(LibFunc::pclose);
00562     TLI.setUnavailable(LibFunc::popen);
00563     TLI.setUnavailable(LibFunc::pread);
00564     TLI.setUnavailable(LibFunc::pwrite);
00565     TLI.setUnavailable(LibFunc::read);
00566     TLI.setUnavailable(LibFunc::readlink);
00567     TLI.setUnavailable(LibFunc::realpath);
00568     TLI.setUnavailable(LibFunc::rmdir);
00569     TLI.setUnavailable(LibFunc::setitimer);
00570     TLI.setUnavailable(LibFunc::stat);
00571     TLI.setUnavailable(LibFunc::statvfs);
00572     TLI.setUnavailable(LibFunc::stpcpy);
00573     TLI.setUnavailable(LibFunc::stpncpy);
00574     TLI.setUnavailable(LibFunc::strcasecmp);
00575     TLI.setUnavailable(LibFunc::strncasecmp);
00576     TLI.setUnavailable(LibFunc::times);
00577     TLI.setUnavailable(LibFunc::uname);
00578     TLI.setUnavailable(LibFunc::unlink);
00579     TLI.setUnavailable(LibFunc::unsetenv);
00580     TLI.setUnavailable(LibFunc::utime);
00581     TLI.setUnavailable(LibFunc::utimes);
00582     TLI.setUnavailable(LibFunc::write);
00583 
00584     // Win32 does *not* provide provide these functions, but they are
00585     // specified by C99:
00586     TLI.setUnavailable(LibFunc::atoll);
00587     TLI.setUnavailable(LibFunc::frexpf);
00588     TLI.setUnavailable(LibFunc::llabs);
00589   }
00590 
00591   switch (T.getOS()) {
00592   case Triple::MacOSX:
00593     // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
00594     // and their names are __exp10 and __exp10f. exp10l is not available on
00595     // OS X or iOS.
00596     TLI.setUnavailable(LibFunc::exp10l);
00597     if (T.isMacOSXVersionLT(10, 9)) {
00598       TLI.setUnavailable(LibFunc::exp10);
00599       TLI.setUnavailable(LibFunc::exp10f);
00600     } else {
00601       TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
00602       TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
00603     }
00604     break;
00605   case Triple::IOS:
00606     TLI.setUnavailable(LibFunc::exp10l);
00607     if (T.isOSVersionLT(7, 0)) {
00608       TLI.setUnavailable(LibFunc::exp10);
00609       TLI.setUnavailable(LibFunc::exp10f);
00610     } else {
00611       TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
00612       TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
00613     }
00614     break;
00615   case Triple::Linux:
00616     // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
00617     // buggy prior to glibc version 2.18. Until this version is widely deployed
00618     // or we have a reasonable detection strategy, we cannot use exp10 reliably
00619     // on Linux.
00620     //
00621     // Fall through to disable all of them.
00622   default:
00623     TLI.setUnavailable(LibFunc::exp10);
00624     TLI.setUnavailable(LibFunc::exp10f);
00625     TLI.setUnavailable(LibFunc::exp10l);
00626   }
00627 
00628   // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
00629   // Linux (GLIBC):
00630   // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
00631   // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsl.c
00632   // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
00633   switch (T.getOS()) {
00634   case Triple::Darwin:
00635   case Triple::MacOSX:
00636   case Triple::IOS:
00637   case Triple::FreeBSD:
00638   case Triple::Linux:
00639     break;
00640   default:
00641     TLI.setUnavailable(LibFunc::ffsl);
00642   }
00643 
00644   // ffsll is available on at least FreeBSD and Linux (GLIBC):
00645   // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsll.c
00646   // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
00647   switch (T.getOS()) {
00648   case Triple::FreeBSD:
00649   case Triple::Linux:
00650     break;
00651   default:
00652     TLI.setUnavailable(LibFunc::ffsll);
00653   }
00654 
00655   // The following functions are available on at least Linux:
00656   if (!T.isOSLinux()) {
00657     TLI.setUnavailable(LibFunc::dunder_strdup);
00658     TLI.setUnavailable(LibFunc::dunder_strtok_r);
00659     TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
00660     TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
00661     TLI.setUnavailable(LibFunc::under_IO_getc);
00662     TLI.setUnavailable(LibFunc::under_IO_putc);
00663     TLI.setUnavailable(LibFunc::memalign);
00664     TLI.setUnavailable(LibFunc::fopen64);
00665     TLI.setUnavailable(LibFunc::fseeko64);
00666     TLI.setUnavailable(LibFunc::fstat64);
00667     TLI.setUnavailable(LibFunc::fstatvfs64);
00668     TLI.setUnavailable(LibFunc::ftello64);
00669     TLI.setUnavailable(LibFunc::lstat64);
00670     TLI.setUnavailable(LibFunc::open64);
00671     TLI.setUnavailable(LibFunc::stat64);
00672     TLI.setUnavailable(LibFunc::statvfs64);
00673     TLI.setUnavailable(LibFunc::tmpfile64);
00674   }
00675 }
00676 
00677 
00678 TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) {
00679   // Default to everything being available.
00680   memset(AvailableArray, -1, sizeof(AvailableArray));
00681 
00682   initialize(*this, Triple(), StandardNames);
00683 }
00684 
00685 TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) {
00686   // Default to everything being available.
00687   memset(AvailableArray, -1, sizeof(AvailableArray));
00688   
00689   initialize(*this, T, StandardNames);
00690 }
00691 
00692 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
00693   : ImmutablePass(ID) {
00694   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
00695   CustomNames = TLI.CustomNames;
00696 }
00697 
00698 namespace {
00699 struct StringComparator {
00700   /// Compare two strings and return true if LHS is lexicographically less than
00701   /// RHS. Requires that RHS doesn't contain any zero bytes.
00702   bool operator()(const char *LHS, StringRef RHS) const {
00703     // Compare prefixes with strncmp. If prefixes match we know that LHS is
00704     // greater or equal to RHS as RHS can't contain any '\0'.
00705     return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;
00706   }
00707 
00708   // Provided for compatibility with MSVC's debug mode.
00709   bool operator()(StringRef LHS, const char *RHS) const { return LHS < RHS; }
00710   bool operator()(StringRef LHS, StringRef RHS) const { return LHS < RHS; }
00711   bool operator()(const char *LHS, const char *RHS) const {
00712     return std::strcmp(LHS, RHS) < 0;
00713   }
00714 };
00715 }
00716 
00717 bool TargetLibraryInfo::getLibFunc(StringRef funcName,
00718                                    LibFunc::Func &F) const {
00719   const char **Start = &StandardNames[0];
00720   const char **End = &StandardNames[LibFunc::NumLibFuncs];
00721 
00722   // Filter out empty names and names containing null bytes, those can't be in
00723   // our table.
00724   if (funcName.empty() || funcName.find('\0') != StringRef::npos)
00725     return false;
00726 
00727   // Check for \01 prefix that is used to mangle __asm declarations and
00728   // strip it if present.
00729   if (funcName.front() == '\01')
00730     funcName = funcName.substr(1);
00731   const char **I = std::lower_bound(Start, End, funcName, StringComparator());
00732   if (I != End && *I == funcName) {
00733     F = (LibFunc::Func)(I - Start);
00734     return true;
00735   }
00736   return false;
00737 }
00738 
00739 /// disableAllFunctions - This disables all builtins, which is used for options
00740 /// like -fno-builtin.
00741 void TargetLibraryInfo::disableAllFunctions() {
00742   memset(AvailableArray, 0, sizeof(AvailableArray));
00743 }