LLVM API Documentation

TargetLibraryInfo.h
Go to the documentation of this file.
00001 //===-- TargetLibraryInfo.h - Library information ---------------*- C++ -*-===//
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 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
00011 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
00012 
00013 #include "llvm/ADT/DenseMap.h"
00014 #include "llvm/ADT/Optional.h"
00015 #include "llvm/ADT/Triple.h"
00016 #include "llvm/IR/Function.h"
00017 #include "llvm/IR/Module.h"
00018 #include "llvm/Pass.h"
00019 
00020 namespace llvm {
00021 class PreservedAnalyses;
00022 
00023   namespace LibFunc {
00024     enum Func {
00025       /// int _IO_getc(_IO_FILE * __fp);
00026       under_IO_getc,
00027       /// int _IO_putc(int __c, _IO_FILE * __fp);
00028       under_IO_putc,
00029       /// void operator delete[](void*);
00030       ZdaPv,
00031       /// void operator delete[](void*, nothrow);
00032       ZdaPvRKSt9nothrow_t,
00033       /// void operator delete[](void*, unsigned int);
00034       ZdaPvj,
00035       /// void operator delete[](void*, unsigned long);
00036       ZdaPvm,
00037       /// void operator delete(void*);
00038       ZdlPv,
00039       /// void operator delete(void*, nothrow);
00040       ZdlPvRKSt9nothrow_t,
00041       /// void operator delete(void*, unsigned int);
00042       ZdlPvj,
00043       /// void operator delete(void*, unsigned long);
00044       ZdlPvm,
00045       /// void *new[](unsigned int);
00046       Znaj,
00047       /// void *new[](unsigned int, nothrow);
00048       ZnajRKSt9nothrow_t,
00049       /// void *new[](unsigned long);
00050       Znam,
00051       /// void *new[](unsigned long, nothrow);
00052       ZnamRKSt9nothrow_t,
00053       /// void *new(unsigned int);
00054       Znwj,
00055       /// void *new(unsigned int, nothrow);
00056       ZnwjRKSt9nothrow_t,
00057       /// void *new(unsigned long);
00058       Znwm,
00059       /// void *new(unsigned long, nothrow);
00060       ZnwmRKSt9nothrow_t,
00061       /// double __cospi(double x);
00062       cospi,
00063       /// float __cospif(float x);
00064       cospif,
00065       /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
00066       cxa_atexit,
00067       /// void __cxa_guard_abort(guard_t *guard);
00068       /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
00069       cxa_guard_abort,
00070       /// int __cxa_guard_acquire(guard_t *guard);
00071       cxa_guard_acquire,
00072       /// void __cxa_guard_release(guard_t *guard);
00073       cxa_guard_release,
00074       /// int __isoc99_scanf (const char *format, ...)
00075       dunder_isoc99_scanf,
00076       /// int __isoc99_sscanf(const char *s, const char *format, ...)
00077       dunder_isoc99_sscanf,
00078       /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
00079       memcpy_chk,
00080       /// void *__memmove_chk(void *s1, const void *s2, size_t n,
00081       ///                     size_t s1size);
00082       memmove_chk,
00083       /// void *__memset_chk(void *s, char v, size_t n, size_t s1size);
00084       memset_chk,
00085       /// double __sincospi_stret(double x);
00086       sincospi_stret,
00087       /// float __sincospif_stret(float x);
00088       sincospif_stret,
00089       /// double __sinpi(double x);
00090       sinpi,
00091       /// float __sinpif(float x);
00092       sinpif,
00093       /// double __sqrt_finite(double x);
00094       sqrt_finite,
00095       /// float __sqrt_finite(float x);
00096       sqrtf_finite,
00097       /// long double __sqrt_finite(long double x);
00098       sqrtl_finite,
00099       /// char *__stpcpy_chk(char *s1, const char *s2, size_t s1size);
00100       stpcpy_chk,
00101       /// char *__stpncpy_chk(char *s1, const char *s2, size_t n,
00102       ///                     size_t s1size);
00103       stpncpy_chk,
00104       /// char *__strcpy_chk(char *s1, const char *s2, size_t s1size);
00105       strcpy_chk,
00106       /// char * __strdup(const char *s);
00107       dunder_strdup,
00108       /// char *__strncpy_chk(char *s1, const char *s2, size_t n,
00109       ///                     size_t s1size);
00110       strncpy_chk,
00111       /// char *__strndup(const char *s, size_t n);
00112       dunder_strndup,
00113       /// char * __strtok_r(char *s, const char *delim, char **save_ptr);
00114       dunder_strtok_r,
00115       /// int abs(int j);
00116       abs,
00117       /// int access(const char *path, int amode);
00118       access,
00119       /// double acos(double x);
00120       acos,
00121       /// float acosf(float x);
00122       acosf,
00123       /// double acosh(double x);
00124       acosh,
00125       /// float acoshf(float x);
00126       acoshf,
00127       /// long double acoshl(long double x);
00128       acoshl,
00129       /// long double acosl(long double x);
00130       acosl,
00131       /// double asin(double x);
00132       asin,
00133       /// float asinf(float x);
00134       asinf,
00135       /// double asinh(double x);
00136       asinh,
00137       /// float asinhf(float x);
00138       asinhf,
00139       /// long double asinhl(long double x);
00140       asinhl,
00141       /// long double asinl(long double x);
00142       asinl,
00143       /// double atan(double x);
00144       atan,
00145       /// double atan2(double y, double x);
00146       atan2,
00147       /// float atan2f(float y, float x);
00148       atan2f,
00149       /// long double atan2l(long double y, long double x);
00150       atan2l,
00151       /// float atanf(float x);
00152       atanf,
00153       /// double atanh(double x);
00154       atanh,
00155       /// float atanhf(float x);
00156       atanhf,
00157       /// long double atanhl(long double x);
00158       atanhl,
00159       /// long double atanl(long double x);
00160       atanl,
00161       /// double atof(const char *str);
00162       atof,
00163       /// int atoi(const char *str);
00164       atoi,
00165       /// long atol(const char *str);
00166       atol,
00167       /// long long atoll(const char *nptr);
00168       atoll,
00169       /// int bcmp(const void *s1, const void *s2, size_t n);
00170       bcmp,
00171       /// void bcopy(const void *s1, void *s2, size_t n);
00172       bcopy,
00173       /// void bzero(void *s, size_t n);
00174       bzero,
00175       /// void *calloc(size_t count, size_t size);
00176       calloc,
00177       /// double cbrt(double x);
00178       cbrt,
00179       /// float cbrtf(float x);
00180       cbrtf,
00181       /// long double cbrtl(long double x);
00182       cbrtl,
00183       /// double ceil(double x);
00184       ceil,
00185       /// float ceilf(float x);
00186       ceilf,
00187       /// long double ceill(long double x);
00188       ceill,
00189       /// int chmod(const char *path, mode_t mode);
00190       chmod,
00191       /// int chown(const char *path, uid_t owner, gid_t group);
00192       chown,
00193       /// void clearerr(FILE *stream);
00194       clearerr,
00195       /// int closedir(DIR *dirp);
00196       closedir,
00197       /// double copysign(double x, double y);
00198       copysign,
00199       /// float copysignf(float x, float y);
00200       copysignf,
00201       /// long double copysignl(long double x, long double y);
00202       copysignl,
00203       /// double cos(double x);
00204       cos,
00205       /// float cosf(float x);
00206       cosf,
00207       /// double cosh(double x);
00208       cosh,
00209       /// float coshf(float x);
00210       coshf,
00211       /// long double coshl(long double x);
00212       coshl,
00213       /// long double cosl(long double x);
00214       cosl,
00215       /// char *ctermid(char *s);
00216       ctermid,
00217       /// double exp(double x);
00218       exp,
00219       /// double exp10(double x);
00220       exp10,
00221       /// float exp10f(float x);
00222       exp10f,
00223       /// long double exp10l(long double x);
00224       exp10l,
00225       /// double exp2(double x);
00226       exp2,
00227       /// float exp2f(float x);
00228       exp2f,
00229       /// long double exp2l(long double x);
00230       exp2l,
00231       /// float expf(float x);
00232       expf,
00233       /// long double expl(long double x);
00234       expl,
00235       /// double expm1(double x);
00236       expm1,
00237       /// float expm1f(float x);
00238       expm1f,
00239       /// long double expm1l(long double x);
00240       expm1l,
00241       /// double fabs(double x);
00242       fabs,
00243       /// float fabsf(float x);
00244       fabsf,
00245       /// long double fabsl(long double x);
00246       fabsl,
00247       /// int fclose(FILE *stream);
00248       fclose,
00249       /// FILE *fdopen(int fildes, const char *mode);
00250       fdopen,
00251       /// int feof(FILE *stream);
00252       feof,
00253       /// int ferror(FILE *stream);
00254       ferror,
00255       /// int fflush(FILE *stream);
00256       fflush,
00257       /// int ffs(int i);
00258       ffs,
00259       /// int ffsl(long int i);
00260       ffsl,
00261       /// int ffsll(long long int i);
00262       ffsll,
00263       /// int fgetc(FILE *stream);
00264       fgetc,
00265       /// int fgetpos(FILE *stream, fpos_t *pos);
00266       fgetpos,
00267       /// char *fgets(char *s, int n, FILE *stream);
00268       fgets,
00269       /// int fileno(FILE *stream);
00270       fileno,
00271       /// int fiprintf(FILE *stream, const char *format, ...);
00272       fiprintf,
00273       /// void flockfile(FILE *file);
00274       flockfile,
00275       /// double floor(double x);
00276       floor,
00277       /// float floorf(float x);
00278       floorf,
00279       /// long double floorl(long double x);
00280       floorl,
00281       /// double fmax(double x, double y);
00282       fmax,
00283       /// float fmaxf(float x, float y);
00284       fmaxf,
00285       /// long double fmaxl(long double x, long double y);
00286       fmaxl,
00287       /// double fmin(double x, double y);
00288       fmin,
00289       /// float fminf(float x, float y);
00290       fminf,
00291       /// long double fminl(long double x, long double y);
00292       fminl,
00293       /// double fmod(double x, double y);
00294       fmod,
00295       /// float fmodf(float x, float y);
00296       fmodf,
00297       /// long double fmodl(long double x, long double y);
00298       fmodl,
00299       /// FILE *fopen(const char *filename, const char *mode);
00300       fopen,
00301       /// FILE *fopen64(const char *filename, const char *opentype)
00302       fopen64,
00303       /// int fprintf(FILE *stream, const char *format, ...);
00304       fprintf,
00305       /// int fputc(int c, FILE *stream);
00306       fputc,
00307       /// int fputs(const char *s, FILE *stream);
00308       fputs,
00309       /// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
00310       fread,
00311       /// void free(void *ptr);
00312       free,
00313       /// double frexp(double num, int *exp);
00314       frexp,
00315       /// float frexpf(float num, int *exp);
00316       frexpf,
00317       /// long double frexpl(long double num, int *exp);
00318       frexpl,
00319       /// int fscanf(FILE *stream, const char *format, ... );
00320       fscanf,
00321       /// int fseek(FILE *stream, long offset, int whence);
00322       fseek,
00323       /// int fseeko(FILE *stream, off_t offset, int whence);
00324       fseeko,
00325       /// int fseeko64(FILE *stream, off64_t offset, int whence)
00326       fseeko64,
00327       /// int fsetpos(FILE *stream, const fpos_t *pos);
00328       fsetpos,
00329       /// int fstat(int fildes, struct stat *buf);
00330       fstat,
00331       /// int fstat64(int filedes, struct stat64 *buf)
00332       fstat64,
00333       /// int fstatvfs(int fildes, struct statvfs *buf);
00334       fstatvfs,
00335       /// int fstatvfs64(int fildes, struct statvfs64 *buf);
00336       fstatvfs64,
00337       /// long ftell(FILE *stream);
00338       ftell,
00339       /// off_t ftello(FILE *stream);
00340       ftello,
00341       /// off64_t ftello64(FILE *stream)
00342       ftello64,
00343       /// int ftrylockfile(FILE *file);
00344       ftrylockfile,
00345       /// void funlockfile(FILE *file);
00346       funlockfile,
00347       /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
00348       /// FILE *stream);
00349       fwrite,
00350       /// int getc(FILE *stream);
00351       getc,
00352       /// int getc_unlocked(FILE *stream);
00353       getc_unlocked,
00354       /// int getchar(void);
00355       getchar,
00356       /// char *getenv(const char *name);
00357       getenv,
00358       /// int getitimer(int which, struct itimerval *value);
00359       getitimer,
00360       /// int getlogin_r(char *name, size_t namesize);
00361       getlogin_r,
00362       /// struct passwd *getpwnam(const char *name);
00363       getpwnam,
00364       /// char *gets(char *s);
00365       gets,
00366       /// int gettimeofday(struct timeval *tp, void *tzp);
00367       gettimeofday,
00368       /// uint32_t htonl(uint32_t hostlong);
00369       htonl,
00370       /// uint16_t htons(uint16_t hostshort);
00371       htons,
00372       /// int iprintf(const char *format, ...);
00373       iprintf,
00374       /// int isascii(int c);
00375       isascii,
00376       /// int isdigit(int c);
00377       isdigit,
00378       /// long int labs(long int j);
00379       labs,
00380       /// int lchown(const char *path, uid_t owner, gid_t group);
00381       lchown,
00382       /// double ldexp(double x, int n);
00383       ldexp,
00384       /// float ldexpf(float x, int n);
00385       ldexpf,
00386       /// long double ldexpl(long double x, int n);
00387       ldexpl,
00388       /// long long int llabs(long long int j);
00389       llabs,
00390       /// double log(double x);
00391       log,
00392       /// double log10(double x);
00393       log10,
00394       /// float log10f(float x);
00395       log10f,
00396       /// long double log10l(long double x);
00397       log10l,
00398       /// double log1p(double x);
00399       log1p,
00400       /// float log1pf(float x);
00401       log1pf,
00402       /// long double log1pl(long double x);
00403       log1pl,
00404       /// double log2(double x);
00405       log2,
00406       /// float log2f(float x);
00407       log2f,
00408       /// double long double log2l(long double x);
00409       log2l,
00410       /// double logb(double x);
00411       logb,
00412       /// float logbf(float x);
00413       logbf,
00414       /// long double logbl(long double x);
00415       logbl,
00416       /// float logf(float x);
00417       logf,
00418       /// long double logl(long double x);
00419       logl,
00420       /// int lstat(const char *path, struct stat *buf);
00421       lstat,
00422       /// int lstat64(const char *path, struct stat64 *buf);
00423       lstat64,
00424       /// void *malloc(size_t size);
00425       malloc,
00426       /// void *memalign(size_t boundary, size_t size);
00427       memalign,
00428       /// void *memccpy(void *s1, const void *s2, int c, size_t n);
00429       memccpy,
00430       /// void *memchr(const void *s, int c, size_t n);
00431       memchr,
00432       /// int memcmp(const void *s1, const void *s2, size_t n);
00433       memcmp,
00434       /// void *memcpy(void *s1, const void *s2, size_t n);
00435       memcpy,
00436       /// void *memmove(void *s1, const void *s2, size_t n);
00437       memmove,
00438       // void *memrchr(const void *s, int c, size_t n);
00439       memrchr,
00440       /// void *memset(void *b, int c, size_t len);
00441       memset,
00442       /// void memset_pattern16(void *b, const void *pattern16, size_t len);
00443       memset_pattern16,
00444       /// int mkdir(const char *path, mode_t mode);
00445       mkdir,
00446       /// time_t mktime(struct tm *timeptr);
00447       mktime,
00448       /// double modf(double x, double *iptr);
00449       modf,
00450       /// float modff(float, float *iptr);
00451       modff,
00452       /// long double modfl(long double value, long double *iptr);
00453       modfl,
00454       /// double nearbyint(double x);
00455       nearbyint,
00456       /// float nearbyintf(float x);
00457       nearbyintf,
00458       /// long double nearbyintl(long double x);
00459       nearbyintl,
00460       /// uint32_t ntohl(uint32_t netlong);
00461       ntohl,
00462       /// uint16_t ntohs(uint16_t netshort);
00463       ntohs,
00464       /// int open(const char *path, int oflag, ... );
00465       open,
00466       /// int open64(const char *filename, int flags[, mode_t mode])
00467       open64,
00468       /// DIR *opendir(const char *dirname);
00469       opendir,
00470       /// int pclose(FILE *stream);
00471       pclose,
00472       /// void perror(const char *s);
00473       perror,
00474       /// FILE *popen(const char *command, const char *mode);
00475       popen,
00476       /// int posix_memalign(void **memptr, size_t alignment, size_t size);
00477       posix_memalign,
00478       /// double pow(double x, double y);
00479       pow,
00480       /// float powf(float x, float y);
00481       powf,
00482       /// long double powl(long double x, long double y);
00483       powl,
00484       /// ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
00485       pread,
00486       /// int printf(const char *format, ...);
00487       printf,
00488       /// int putc(int c, FILE *stream);
00489       putc,
00490       /// int putchar(int c);
00491       putchar,
00492       /// int puts(const char *s);
00493       puts,
00494       /// ssize_t pwrite(int fildes, const void *buf, size_t nbyte,
00495       ///                off_t offset);
00496       pwrite,
00497       /// void qsort(void *base, size_t nel, size_t width,
00498       ///            int (*compar)(const void *, const void *));
00499       qsort,
00500       /// ssize_t read(int fildes, void *buf, size_t nbyte);
00501       read,
00502       /// ssize_t readlink(const char *path, char *buf, size_t bufsize);
00503       readlink,
00504       /// void *realloc(void *ptr, size_t size);
00505       realloc,
00506       /// void *reallocf(void *ptr, size_t size);
00507       reallocf,
00508       /// char *realpath(const char *file_name, char *resolved_name);
00509       realpath,
00510       /// int remove(const char *path);
00511       remove,
00512       /// int rename(const char *old, const char *new);
00513       rename,
00514       /// void rewind(FILE *stream);
00515       rewind,
00516       /// double rint(double x);
00517       rint,
00518       /// float rintf(float x);
00519       rintf,
00520       /// long double rintl(long double x);
00521       rintl,
00522       /// int rmdir(const char *path);
00523       rmdir,
00524       /// double round(double x);
00525       round,
00526       /// float roundf(float x);
00527       roundf,
00528       /// long double roundl(long double x);
00529       roundl,
00530       /// int scanf(const char *restrict format, ... );
00531       scanf,
00532       /// void setbuf(FILE *stream, char *buf);
00533       setbuf,
00534       /// int setitimer(int which, const struct itimerval *value,
00535       ///               struct itimerval *ovalue);
00536       setitimer,
00537       /// int setvbuf(FILE *stream, char *buf, int type, size_t size);
00538       setvbuf,
00539       /// double sin(double x);
00540       sin,
00541       /// float sinf(float x);
00542       sinf,
00543       /// double sinh(double x);
00544       sinh,
00545       /// float sinhf(float x);
00546       sinhf,
00547       /// long double sinhl(long double x);
00548       sinhl,
00549       /// long double sinl(long double x);
00550       sinl,
00551       /// int siprintf(char *str, const char *format, ...);
00552       siprintf,
00553       /// int snprintf(char *s, size_t n, const char *format, ...);
00554       snprintf,
00555       /// int sprintf(char *str, const char *format, ...);
00556       sprintf,
00557       /// double sqrt(double x);
00558       sqrt,
00559       /// float sqrtf(float x);
00560       sqrtf,
00561       /// long double sqrtl(long double x);
00562       sqrtl,
00563       /// int sscanf(const char *s, const char *format, ... );
00564       sscanf,
00565       /// int stat(const char *path, struct stat *buf);
00566       stat,
00567       /// int stat64(const char *path, struct stat64 *buf);
00568       stat64,
00569       /// int statvfs(const char *path, struct statvfs *buf);
00570       statvfs,
00571       /// int statvfs64(const char *path, struct statvfs64 *buf)
00572       statvfs64,
00573       /// char *stpcpy(char *s1, const char *s2);
00574       stpcpy,
00575       /// char *stpncpy(char *s1, const char *s2, size_t n);
00576       stpncpy,
00577       /// int strcasecmp(const char *s1, const char *s2);
00578       strcasecmp,
00579       /// char *strcat(char *s1, const char *s2);
00580       strcat,
00581       /// char *strchr(const char *s, int c);
00582       strchr,
00583       /// int strcmp(const char *s1, const char *s2);
00584       strcmp,
00585       /// int strcoll(const char *s1, const char *s2);
00586       strcoll,
00587       /// char *strcpy(char *s1, const char *s2);
00588       strcpy,
00589       /// size_t strcspn(const char *s1, const char *s2);
00590       strcspn,
00591       /// char *strdup(const char *s1);
00592       strdup,
00593       /// size_t strlen(const char *s);
00594       strlen,
00595       /// int strncasecmp(const char *s1, const char *s2, size_t n);
00596       strncasecmp,
00597       /// char *strncat(char *s1, const char *s2, size_t n);
00598       strncat,
00599       /// int strncmp(const char *s1, const char *s2, size_t n);
00600       strncmp,
00601       /// char *strncpy(char *s1, const char *s2, size_t n);
00602       strncpy,
00603       /// char *strndup(const char *s1, size_t n);
00604       strndup,
00605       /// size_t strnlen(const char *s, size_t maxlen);
00606       strnlen,
00607       /// char *strpbrk(const char *s1, const char *s2);
00608       strpbrk,
00609       /// char *strrchr(const char *s, int c);
00610       strrchr,
00611       /// size_t strspn(const char *s1, const char *s2);
00612       strspn,
00613       /// char *strstr(const char *s1, const char *s2);
00614       strstr,
00615       /// double strtod(const char *nptr, char **endptr);
00616       strtod,
00617       /// float strtof(const char *nptr, char **endptr);
00618       strtof,
00619       // char *strtok(char *s1, const char *s2);
00620       strtok,
00621       // char *strtok_r(char *s, const char *sep, char **lasts);
00622       strtok_r,
00623       /// long int strtol(const char *nptr, char **endptr, int base);
00624       strtol,
00625       /// long double strtold(const char *nptr, char **endptr);
00626       strtold,
00627       /// long long int strtoll(const char *nptr, char **endptr, int base);
00628       strtoll,
00629       /// unsigned long int strtoul(const char *nptr, char **endptr, int base);
00630       strtoul,
00631       /// unsigned long long int strtoull(const char *nptr, char **endptr,
00632       ///                                 int base);
00633       strtoull,
00634       /// size_t strxfrm(char *s1, const char *s2, size_t n);
00635       strxfrm,
00636       /// int system(const char *command);
00637       system,
00638       /// double tan(double x);
00639       tan,
00640       /// float tanf(float x);
00641       tanf,
00642       /// double tanh(double x);
00643       tanh,
00644       /// float tanhf(float x);
00645       tanhf,
00646       /// long double tanhl(long double x);
00647       tanhl,
00648       /// long double tanl(long double x);
00649       tanl,
00650       /// clock_t times(struct tms *buffer);
00651       times,
00652       /// FILE *tmpfile(void);
00653       tmpfile,
00654       /// FILE *tmpfile64(void)
00655       tmpfile64,
00656       /// int toascii(int c);
00657       toascii,
00658       /// double trunc(double x);
00659       trunc,
00660       /// float truncf(float x);
00661       truncf,
00662       /// long double truncl(long double x);
00663       truncl,
00664       /// int uname(struct utsname *name);
00665       uname,
00666       /// int ungetc(int c, FILE *stream);
00667       ungetc,
00668       /// int unlink(const char *path);
00669       unlink,
00670       /// int unsetenv(const char *name);
00671       unsetenv,
00672       /// int utime(const char *path, const struct utimbuf *times);
00673       utime,
00674       /// int utimes(const char *path, const struct timeval times[2]);
00675       utimes,
00676       /// void *valloc(size_t size);
00677       valloc,
00678       /// int vfprintf(FILE *stream, const char *format, va_list ap);
00679       vfprintf,
00680       /// int vfscanf(FILE *stream, const char *format, va_list arg);
00681       vfscanf,
00682       /// int vprintf(const char *restrict format, va_list ap);
00683       vprintf,
00684       /// int vscanf(const char *format, va_list arg);
00685       vscanf,
00686       /// int vsnprintf(char *s, size_t n, const char *format, va_list ap);
00687       vsnprintf,
00688       /// int vsprintf(char *s, const char *format, va_list ap);
00689       vsprintf,
00690       /// int vsscanf(const char *s, const char *format, va_list arg);
00691       vsscanf,
00692       /// ssize_t write(int fildes, const void *buf, size_t nbyte);
00693       write,
00694 
00695       NumLibFuncs
00696     };
00697   }
00698 
00699 /// \brief Implementation of the target library information.
00700 ///
00701 /// This class constructs tables that hold the target library information and
00702 /// make it available. However, it is somewhat expensive to compute and only
00703 /// depends on the triple. So users typicaly interact with the \c
00704 /// TargetLibraryInfo wrapper below.
00705 class TargetLibraryInfoImpl {
00706   friend class TargetLibraryInfo;
00707 
00708   unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
00709   llvm::DenseMap<unsigned, std::string> CustomNames;
00710   static const char* StandardNames[LibFunc::NumLibFuncs];
00711 
00712   enum AvailabilityState {
00713     StandardName = 3, // (memset to all ones)
00714     CustomName = 1,
00715     Unavailable = 0  // (memset to all zeros)
00716   };
00717   void setState(LibFunc::Func F, AvailabilityState State) {
00718     AvailableArray[F/4] &= ~(3 << 2*(F&3));
00719     AvailableArray[F/4] |= State << 2*(F&3);
00720   }
00721   AvailabilityState getState(LibFunc::Func F) const {
00722     return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
00723   }
00724 
00725 public:
00726   TargetLibraryInfoImpl();
00727   explicit TargetLibraryInfoImpl(const Triple &T);
00728 
00729   // Provide value semantics.
00730   TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI);
00731   TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI);
00732   TargetLibraryInfoImpl &operator=(const TargetLibraryInfoImpl &TLI);
00733   TargetLibraryInfoImpl &operator=(TargetLibraryInfoImpl &&TLI);
00734 
00735   /// \brief Searches for a particular function name.
00736   ///
00737   /// If it is one of the known library functions, return true and set F to the
00738   /// corresponding value.
00739   bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
00740 
00741   /// \brief Forces a function to be marked as unavailable.
00742   void setUnavailable(LibFunc::Func F) {
00743     setState(F, Unavailable);
00744   }
00745 
00746   /// \brief Forces a function to be marked as available.
00747   void setAvailable(LibFunc::Func F) {
00748     setState(F, StandardName);
00749   }
00750 
00751   /// \brief Forces a function to be marked as available and provide an
00752   /// alternate name that must be used.
00753   void setAvailableWithName(LibFunc::Func F, StringRef Name) {
00754     if (StandardNames[F] != Name) {
00755       setState(F, CustomName);
00756       CustomNames[F] = Name;
00757       assert(CustomNames.find(F) != CustomNames.end());
00758     } else {
00759       setState(F, StandardName);
00760     }
00761   }
00762 
00763   /// \brief Disables all builtins.
00764   ///
00765   /// This can be used for options like -fno-builtin.
00766   void disableAllFunctions();
00767 };
00768 
00769 /// \brief Provides information about what library functions are available for
00770 /// the current target.
00771 ///
00772 /// This both allows optimizations to handle them specially and frontends to
00773 /// disable such optimizations through -fno-builtin etc.
00774 class TargetLibraryInfo {
00775   friend class TargetLibraryAnalysis;
00776   friend class TargetLibraryInfoWrapperPass;
00777 
00778   const TargetLibraryInfoImpl *Impl;
00779 
00780 public:
00781   explicit TargetLibraryInfo(const TargetLibraryInfoImpl &Impl) : Impl(&Impl) {}
00782 
00783   // Provide value semantics.
00784   TargetLibraryInfo(const TargetLibraryInfo &TLI) : Impl(TLI.Impl) {}
00785   TargetLibraryInfo(TargetLibraryInfo &&TLI) : Impl(TLI.Impl) {}
00786   TargetLibraryInfo &operator=(const TargetLibraryInfo &TLI) {
00787     Impl = TLI.Impl;
00788     return *this;
00789   }
00790   TargetLibraryInfo &operator=(TargetLibraryInfo &&TLI) {
00791     Impl = TLI.Impl;
00792     return *this;
00793   }
00794 
00795   /// \brief Searches for a particular function name.
00796   ///
00797   /// If it is one of the known library functions, return true and set F to the
00798   /// corresponding value.
00799   bool getLibFunc(StringRef funcName, LibFunc::Func &F) const {
00800     return Impl->getLibFunc(funcName, F);
00801   }
00802 
00803   /// \brief Tests wether a library function is available.
00804   bool has(LibFunc::Func F) const {
00805     return Impl->getState(F) != TargetLibraryInfoImpl::Unavailable;
00806   }
00807 
00808   /// \brief Tests if the function is both available and a candidate for
00809   /// optimized code generation.
00810   bool hasOptimizedCodeGen(LibFunc::Func F) const {
00811     if (Impl->getState(F) == TargetLibraryInfoImpl::Unavailable)
00812       return false;
00813     switch (F) {
00814     default: break;
00815     case LibFunc::copysign:  case LibFunc::copysignf:  case LibFunc::copysignl:
00816     case LibFunc::fabs:      case LibFunc::fabsf:      case LibFunc::fabsl:
00817     case LibFunc::sin:       case LibFunc::sinf:       case LibFunc::sinl:
00818     case LibFunc::cos:       case LibFunc::cosf:       case LibFunc::cosl:
00819     case LibFunc::sqrt:      case LibFunc::sqrtf:      case LibFunc::sqrtl:
00820     case LibFunc::sqrt_finite: case LibFunc::sqrtf_finite:
00821                                                   case LibFunc::sqrtl_finite:
00822     case LibFunc::fmax:      case LibFunc::fmaxf:      case LibFunc::fmaxl:
00823     case LibFunc::fmin:      case LibFunc::fminf:      case LibFunc::fminl:
00824     case LibFunc::floor:     case LibFunc::floorf:     case LibFunc::floorl:
00825     case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
00826     case LibFunc::ceil:      case LibFunc::ceilf:      case LibFunc::ceill:
00827     case LibFunc::rint:      case LibFunc::rintf:      case LibFunc::rintl:
00828     case LibFunc::round:     case LibFunc::roundf:     case LibFunc::roundl:
00829     case LibFunc::trunc:     case LibFunc::truncf:     case LibFunc::truncl:
00830     case LibFunc::log2:      case LibFunc::log2f:      case LibFunc::log2l:
00831     case LibFunc::exp2:      case LibFunc::exp2f:      case LibFunc::exp2l:
00832     case LibFunc::memcmp:    case LibFunc::strcmp:     case LibFunc::strcpy:
00833     case LibFunc::stpcpy:    case LibFunc::strlen:     case LibFunc::strnlen:
00834     case LibFunc::memchr:
00835       return true;
00836     }
00837     return false;
00838   }
00839 
00840   StringRef getName(LibFunc::Func F) const {
00841     auto State = Impl->getState(F);
00842     if (State == TargetLibraryInfoImpl::Unavailable)
00843       return StringRef();
00844     if (State == TargetLibraryInfoImpl::StandardName)
00845       return Impl->StandardNames[F];
00846     assert(State == TargetLibraryInfoImpl::CustomName);
00847     return Impl->CustomNames.find(F)->second;
00848   }
00849 
00850   /// \brief Handle invalidation from the pass manager.
00851   ///
00852   /// If we try to invalidate this info, just return false. It cannot become
00853   /// invalid even if the module changes.
00854   bool invalidate(Module &, const PreservedAnalyses &) { return false; }
00855 };
00856 
00857 /// \brief Analysis pass providing the \c TargetLibraryInfo.
00858 ///
00859 /// Note that this pass's result cannot be invalidated, it is immutable for the
00860 /// life of the module.
00861 class TargetLibraryAnalysis {
00862 public:
00863   typedef TargetLibraryInfo Result;
00864 
00865   /// \brief Opaque, unique identifier for this analysis pass.
00866   static void *ID() { return (void *)&PassID; }
00867 
00868   /// \brief Default construct the library analysis.
00869   ///
00870   /// This will use the module's triple to construct the library info for that
00871   /// module.
00872   TargetLibraryAnalysis() {}
00873 
00874   /// \brief Construct a library analysis with preset info.
00875   ///
00876   /// This will directly copy the preset info into the result without
00877   /// consulting the module's triple.
00878   TargetLibraryAnalysis(TargetLibraryInfoImpl PresetInfoImpl)
00879       : PresetInfoImpl(std::move(PresetInfoImpl)) {}
00880 
00881   // Move semantics. We spell out the constructors for MSVC.
00882   TargetLibraryAnalysis(TargetLibraryAnalysis &&Arg)
00883       : PresetInfoImpl(std::move(Arg.PresetInfoImpl)), Impls(std::move(Arg.Impls)) {}
00884   TargetLibraryAnalysis &operator=(TargetLibraryAnalysis &&RHS) {
00885     PresetInfoImpl = std::move(RHS.PresetInfoImpl);
00886     Impls = std::move(RHS.Impls);
00887     return *this;
00888   }
00889 
00890   TargetLibraryInfo run(Module &M);
00891   TargetLibraryInfo run(Function &F);
00892 
00893   /// \brief Provide access to a name for this pass for debugging purposes.
00894   static StringRef name() { return "TargetLibraryAnalysis"; }
00895 
00896 private:
00897   static char PassID;
00898 
00899   Optional<TargetLibraryInfoImpl> PresetInfoImpl;
00900 
00901   StringMap<std::unique_ptr<TargetLibraryInfoImpl>> Impls;
00902 
00903   TargetLibraryInfoImpl &lookupInfoImpl(Triple T);
00904 };
00905 
00906 class TargetLibraryInfoWrapperPass : public ImmutablePass {
00907   TargetLibraryInfoImpl TLIImpl;
00908   TargetLibraryInfo TLI;
00909 
00910   virtual void anchor();
00911 
00912 public:
00913   static char ID;
00914   TargetLibraryInfoWrapperPass();
00915   explicit TargetLibraryInfoWrapperPass(const Triple &T);
00916   explicit TargetLibraryInfoWrapperPass(const TargetLibraryInfoImpl &TLI);
00917 
00918   TargetLibraryInfo &getTLI() { return TLI; }
00919   const TargetLibraryInfo &getTLI() const { return TLI; }
00920 };
00921 
00922 } // end namespace llvm
00923 
00924 #endif