OSDN Git Service

Update aosp/master LLVM for rebase to r230699.
[android-x86/external-llvm.git] / include / llvm / Analysis / TargetLibraryInfo.h
1 //===-- TargetLibraryInfo.h - Library information ---------------*- C++ -*-===//
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 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
11 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/Pass.h"
19
20 // BEGIN ANDROID-SPECIFIC
21 #ifdef WIN32
22 #ifdef fseeko
23 #undef fseeko
24 #endif
25 #ifdef ftello
26 #undef ftello
27 #endif
28 #endif  // WIN32
29 // END ANDROID-SPECIFIC
30
31 namespace llvm {
32 class PreservedAnalyses;
33
34   namespace LibFunc {
35     enum Func {
36       /// int _IO_getc(_IO_FILE * __fp);
37       under_IO_getc,
38       /// int _IO_putc(int __c, _IO_FILE * __fp);
39       under_IO_putc,
40       /// void operator delete[](void*);
41       ZdaPv,
42       /// void operator delete[](void*, nothrow);
43       ZdaPvRKSt9nothrow_t,
44       /// void operator delete[](void*, unsigned int);
45       ZdaPvj,
46       /// void operator delete[](void*, unsigned long);
47       ZdaPvm,
48       /// void operator delete(void*);
49       ZdlPv,
50       /// void operator delete(void*, nothrow);
51       ZdlPvRKSt9nothrow_t,
52       /// void operator delete(void*, unsigned int);
53       ZdlPvj,
54       /// void operator delete(void*, unsigned long);
55       ZdlPvm,
56       /// void *new[](unsigned int);
57       Znaj,
58       /// void *new[](unsigned int, nothrow);
59       ZnajRKSt9nothrow_t,
60       /// void *new[](unsigned long);
61       Znam,
62       /// void *new[](unsigned long, nothrow);
63       ZnamRKSt9nothrow_t,
64       /// void *new(unsigned int);
65       Znwj,
66       /// void *new(unsigned int, nothrow);
67       ZnwjRKSt9nothrow_t,
68       /// void *new(unsigned long);
69       Znwm,
70       /// void *new(unsigned long, nothrow);
71       ZnwmRKSt9nothrow_t,
72       /// double __cospi(double x);
73       cospi,
74       /// float __cospif(float x);
75       cospif,
76       /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
77       cxa_atexit,
78       /// void __cxa_guard_abort(guard_t *guard);
79       /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
80       cxa_guard_abort,
81       /// int __cxa_guard_acquire(guard_t *guard);
82       cxa_guard_acquire,
83       /// void __cxa_guard_release(guard_t *guard);
84       cxa_guard_release,
85       /// int __isoc99_scanf (const char *format, ...)
86       dunder_isoc99_scanf,
87       /// int __isoc99_sscanf(const char *s, const char *format, ...)
88       dunder_isoc99_sscanf,
89       /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
90       memcpy_chk,
91       /// void *__memmove_chk(void *s1, const void *s2, size_t n,
92       ///                     size_t s1size);
93       memmove_chk,
94       /// void *__memset_chk(void *s, char v, size_t n, size_t s1size);
95       memset_chk,
96       /// double __sincospi_stret(double x);
97       sincospi_stret,
98       /// float __sincospif_stret(float x);
99       sincospif_stret,
100       /// double __sinpi(double x);
101       sinpi,
102       /// float __sinpif(float x);
103       sinpif,
104       /// double __sqrt_finite(double x);
105       sqrt_finite,
106       /// float __sqrt_finite(float x);
107       sqrtf_finite,
108       /// long double __sqrt_finite(long double x);
109       sqrtl_finite,
110       /// char *__stpcpy_chk(char *s1, const char *s2, size_t s1size);
111       stpcpy_chk,
112       /// char *__stpncpy_chk(char *s1, const char *s2, size_t n,
113       ///                     size_t s1size);
114       stpncpy_chk,
115       /// char *__strcpy_chk(char *s1, const char *s2, size_t s1size);
116       strcpy_chk,
117       /// char * __strdup(const char *s);
118       dunder_strdup,
119       /// char *__strncpy_chk(char *s1, const char *s2, size_t n,
120       ///                     size_t s1size);
121       strncpy_chk,
122       /// char *__strndup(const char *s, size_t n);
123       dunder_strndup,
124       /// char * __strtok_r(char *s, const char *delim, char **save_ptr);
125       dunder_strtok_r,
126       /// int abs(int j);
127       abs,
128       /// int access(const char *path, int amode);
129       access,
130       /// double acos(double x);
131       acos,
132       /// float acosf(float x);
133       acosf,
134       /// double acosh(double x);
135       acosh,
136       /// float acoshf(float x);
137       acoshf,
138       /// long double acoshl(long double x);
139       acoshl,
140       /// long double acosl(long double x);
141       acosl,
142       /// double asin(double x);
143       asin,
144       /// float asinf(float x);
145       asinf,
146       /// double asinh(double x);
147       asinh,
148       /// float asinhf(float x);
149       asinhf,
150       /// long double asinhl(long double x);
151       asinhl,
152       /// long double asinl(long double x);
153       asinl,
154       /// double atan(double x);
155       atan,
156       /// double atan2(double y, double x);
157       atan2,
158       /// float atan2f(float y, float x);
159       atan2f,
160       /// long double atan2l(long double y, long double x);
161       atan2l,
162       /// float atanf(float x);
163       atanf,
164       /// double atanh(double x);
165       atanh,
166       /// float atanhf(float x);
167       atanhf,
168       /// long double atanhl(long double x);
169       atanhl,
170       /// long double atanl(long double x);
171       atanl,
172       /// double atof(const char *str);
173       atof,
174       /// int atoi(const char *str);
175       atoi,
176       /// long atol(const char *str);
177       atol,
178       /// long long atoll(const char *nptr);
179       atoll,
180       /// int bcmp(const void *s1, const void *s2, size_t n);
181       bcmp,
182       /// void bcopy(const void *s1, void *s2, size_t n);
183       bcopy,
184       /// void bzero(void *s, size_t n);
185       bzero,
186       /// void *calloc(size_t count, size_t size);
187       calloc,
188       /// double cbrt(double x);
189       cbrt,
190       /// float cbrtf(float x);
191       cbrtf,
192       /// long double cbrtl(long double x);
193       cbrtl,
194       /// double ceil(double x);
195       ceil,
196       /// float ceilf(float x);
197       ceilf,
198       /// long double ceill(long double x);
199       ceill,
200       /// int chmod(const char *path, mode_t mode);
201       chmod,
202       /// int chown(const char *path, uid_t owner, gid_t group);
203       chown,
204       /// void clearerr(FILE *stream);
205       clearerr,
206       /// int closedir(DIR *dirp);
207       closedir,
208       /// double copysign(double x, double y);
209       copysign,
210       /// float copysignf(float x, float y);
211       copysignf,
212       /// long double copysignl(long double x, long double y);
213       copysignl,
214       /// double cos(double x);
215       cos,
216       /// float cosf(float x);
217       cosf,
218       /// double cosh(double x);
219       cosh,
220       /// float coshf(float x);
221       coshf,
222       /// long double coshl(long double x);
223       coshl,
224       /// long double cosl(long double x);
225       cosl,
226       /// char *ctermid(char *s);
227       ctermid,
228       /// double exp(double x);
229       exp,
230       /// double exp10(double x);
231       exp10,
232       /// float exp10f(float x);
233       exp10f,
234       /// long double exp10l(long double x);
235       exp10l,
236       /// double exp2(double x);
237       exp2,
238       /// float exp2f(float x);
239       exp2f,
240       /// long double exp2l(long double x);
241       exp2l,
242       /// float expf(float x);
243       expf,
244       /// long double expl(long double x);
245       expl,
246       /// double expm1(double x);
247       expm1,
248       /// float expm1f(float x);
249       expm1f,
250       /// long double expm1l(long double x);
251       expm1l,
252       /// double fabs(double x);
253       fabs,
254       /// float fabsf(float x);
255       fabsf,
256       /// long double fabsl(long double x);
257       fabsl,
258       /// int fclose(FILE *stream);
259       fclose,
260       /// FILE *fdopen(int fildes, const char *mode);
261       fdopen,
262       /// int feof(FILE *stream);
263       feof,
264       /// int ferror(FILE *stream);
265       ferror,
266       /// int fflush(FILE *stream);
267       fflush,
268       /// int ffs(int i);
269       ffs,
270       /// int ffsl(long int i);
271       ffsl,
272       /// int ffsll(long long int i);
273       ffsll,
274       /// int fgetc(FILE *stream);
275       fgetc,
276       /// int fgetpos(FILE *stream, fpos_t *pos);
277       fgetpos,
278       /// char *fgets(char *s, int n, FILE *stream);
279       fgets,
280       /// int fileno(FILE *stream);
281       fileno,
282       /// int fiprintf(FILE *stream, const char *format, ...);
283       fiprintf,
284       /// void flockfile(FILE *file);
285       flockfile,
286       /// double floor(double x);
287       floor,
288       /// float floorf(float x);
289       floorf,
290       /// long double floorl(long double x);
291       floorl,
292       /// double fmax(double x, double y);
293       fmax,
294       /// float fmaxf(float x, float y);
295       fmaxf,
296       /// long double fmaxl(long double x, long double y);
297       fmaxl,
298       /// double fmin(double x, double y);
299       fmin,
300       /// float fminf(float x, float y);
301       fminf,
302       /// long double fminl(long double x, long double y);
303       fminl,
304       /// double fmod(double x, double y);
305       fmod,
306       /// float fmodf(float x, float y);
307       fmodf,
308       /// long double fmodl(long double x, long double y);
309       fmodl,
310       /// FILE *fopen(const char *filename, const char *mode);
311       fopen,
312       /// FILE *fopen64(const char *filename, const char *opentype)
313       fopen64,
314       /// int fprintf(FILE *stream, const char *format, ...);
315       fprintf,
316       /// int fputc(int c, FILE *stream);
317       fputc,
318       /// int fputs(const char *s, FILE *stream);
319       fputs,
320       /// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
321       fread,
322       /// void free(void *ptr);
323       free,
324       /// double frexp(double num, int *exp);
325       frexp,
326       /// float frexpf(float num, int *exp);
327       frexpf,
328       /// long double frexpl(long double num, int *exp);
329       frexpl,
330       /// int fscanf(FILE *stream, const char *format, ... );
331       fscanf,
332       /// int fseek(FILE *stream, long offset, int whence);
333       fseek,
334       /// int fseeko(FILE *stream, off_t offset, int whence);
335       fseeko,
336       /// int fseeko64(FILE *stream, off64_t offset, int whence)
337       fseeko64,
338       /// int fsetpos(FILE *stream, const fpos_t *pos);
339       fsetpos,
340       /// int fstat(int fildes, struct stat *buf);
341       fstat,
342       /// int fstat64(int filedes, struct stat64 *buf)
343       fstat64,
344       /// int fstatvfs(int fildes, struct statvfs *buf);
345       fstatvfs,
346       /// int fstatvfs64(int fildes, struct statvfs64 *buf);
347       fstatvfs64,
348       /// long ftell(FILE *stream);
349       ftell,
350       /// off_t ftello(FILE *stream);
351       ftello,
352       /// off64_t ftello64(FILE *stream)
353       ftello64,
354       /// int ftrylockfile(FILE *file);
355       ftrylockfile,
356       /// void funlockfile(FILE *file);
357       funlockfile,
358       /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
359       /// FILE *stream);
360       fwrite,
361       /// int getc(FILE *stream);
362       getc,
363       /// int getc_unlocked(FILE *stream);
364       getc_unlocked,
365       /// int getchar(void);
366       getchar,
367       /// char *getenv(const char *name);
368       getenv,
369       /// int getitimer(int which, struct itimerval *value);
370       getitimer,
371       /// int getlogin_r(char *name, size_t namesize);
372       getlogin_r,
373       /// struct passwd *getpwnam(const char *name);
374       getpwnam,
375       /// char *gets(char *s);
376       gets,
377       /// int gettimeofday(struct timeval *tp, void *tzp);
378       gettimeofday,
379       /// uint32_t htonl(uint32_t hostlong);
380       htonl,
381       /// uint16_t htons(uint16_t hostshort);
382       htons,
383       /// int iprintf(const char *format, ...);
384       iprintf,
385       /// int isascii(int c);
386       isascii,
387       /// int isdigit(int c);
388       isdigit,
389       /// long int labs(long int j);
390       labs,
391       /// int lchown(const char *path, uid_t owner, gid_t group);
392       lchown,
393       /// double ldexp(double x, int n);
394       ldexp,
395       /// float ldexpf(float x, int n);
396       ldexpf,
397       /// long double ldexpl(long double x, int n);
398       ldexpl,
399       /// long long int llabs(long long int j);
400       llabs,
401       /// double log(double x);
402       log,
403       /// double log10(double x);
404       log10,
405       /// float log10f(float x);
406       log10f,
407       /// long double log10l(long double x);
408       log10l,
409       /// double log1p(double x);
410       log1p,
411       /// float log1pf(float x);
412       log1pf,
413       /// long double log1pl(long double x);
414       log1pl,
415       /// double log2(double x);
416       log2,
417       /// float log2f(float x);
418       log2f,
419       /// double long double log2l(long double x);
420       log2l,
421       /// double logb(double x);
422       logb,
423       /// float logbf(float x);
424       logbf,
425       /// long double logbl(long double x);
426       logbl,
427       /// float logf(float x);
428       logf,
429       /// long double logl(long double x);
430       logl,
431       /// int lstat(const char *path, struct stat *buf);
432       lstat,
433       /// int lstat64(const char *path, struct stat64 *buf);
434       lstat64,
435       /// void *malloc(size_t size);
436       malloc,
437       /// void *memalign(size_t boundary, size_t size);
438       memalign,
439       /// void *memccpy(void *s1, const void *s2, int c, size_t n);
440       memccpy,
441       /// void *memchr(const void *s, int c, size_t n);
442       memchr,
443       /// int memcmp(const void *s1, const void *s2, size_t n);
444       memcmp,
445       /// void *memcpy(void *s1, const void *s2, size_t n);
446       memcpy,
447       /// void *memmove(void *s1, const void *s2, size_t n);
448       memmove,
449       // void *memrchr(const void *s, int c, size_t n);
450       memrchr,
451       /// void *memset(void *b, int c, size_t len);
452       memset,
453       /// void memset_pattern16(void *b, const void *pattern16, size_t len);
454       memset_pattern16,
455       /// int mkdir(const char *path, mode_t mode);
456       mkdir,
457       /// time_t mktime(struct tm *timeptr);
458       mktime,
459       /// double modf(double x, double *iptr);
460       modf,
461       /// float modff(float, float *iptr);
462       modff,
463       /// long double modfl(long double value, long double *iptr);
464       modfl,
465       /// double nearbyint(double x);
466       nearbyint,
467       /// float nearbyintf(float x);
468       nearbyintf,
469       /// long double nearbyintl(long double x);
470       nearbyintl,
471       /// uint32_t ntohl(uint32_t netlong);
472       ntohl,
473       /// uint16_t ntohs(uint16_t netshort);
474       ntohs,
475       /// int open(const char *path, int oflag, ... );
476       open,
477       /// int open64(const char *filename, int flags[, mode_t mode])
478       open64,
479       /// DIR *opendir(const char *dirname);
480       opendir,
481       /// int pclose(FILE *stream);
482       pclose,
483       /// void perror(const char *s);
484       perror,
485       /// FILE *popen(const char *command, const char *mode);
486       popen,
487       /// int posix_memalign(void **memptr, size_t alignment, size_t size);
488       posix_memalign,
489       /// double pow(double x, double y);
490       pow,
491       /// float powf(float x, float y);
492       powf,
493       /// long double powl(long double x, long double y);
494       powl,
495       /// ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
496       pread,
497       /// int printf(const char *format, ...);
498       printf,
499       /// int putc(int c, FILE *stream);
500       putc,
501       /// int putchar(int c);
502       putchar,
503       /// int puts(const char *s);
504       puts,
505       /// ssize_t pwrite(int fildes, const void *buf, size_t nbyte,
506       ///                off_t offset);
507       pwrite,
508       /// void qsort(void *base, size_t nel, size_t width,
509       ///            int (*compar)(const void *, const void *));
510       qsort,
511       /// ssize_t read(int fildes, void *buf, size_t nbyte);
512       read,
513       /// ssize_t readlink(const char *path, char *buf, size_t bufsize);
514       readlink,
515       /// void *realloc(void *ptr, size_t size);
516       realloc,
517       /// void *reallocf(void *ptr, size_t size);
518       reallocf,
519       /// char *realpath(const char *file_name, char *resolved_name);
520       realpath,
521       /// int remove(const char *path);
522       remove,
523       /// int rename(const char *old, const char *new);
524       rename,
525       /// void rewind(FILE *stream);
526       rewind,
527       /// double rint(double x);
528       rint,
529       /// float rintf(float x);
530       rintf,
531       /// long double rintl(long double x);
532       rintl,
533       /// int rmdir(const char *path);
534       rmdir,
535       /// double round(double x);
536       round,
537       /// float roundf(float x);
538       roundf,
539       /// long double roundl(long double x);
540       roundl,
541       /// int scanf(const char *restrict format, ... );
542       scanf,
543       /// void setbuf(FILE *stream, char *buf);
544       setbuf,
545       /// int setitimer(int which, const struct itimerval *value,
546       ///               struct itimerval *ovalue);
547       setitimer,
548       /// int setvbuf(FILE *stream, char *buf, int type, size_t size);
549       setvbuf,
550       /// double sin(double x);
551       sin,
552       /// float sinf(float x);
553       sinf,
554       /// double sinh(double x);
555       sinh,
556       /// float sinhf(float x);
557       sinhf,
558       /// long double sinhl(long double x);
559       sinhl,
560       /// long double sinl(long double x);
561       sinl,
562       /// int siprintf(char *str, const char *format, ...);
563       siprintf,
564       /// int snprintf(char *s, size_t n, const char *format, ...);
565       snprintf,
566       /// int sprintf(char *str, const char *format, ...);
567       sprintf,
568       /// double sqrt(double x);
569       sqrt,
570       /// float sqrtf(float x);
571       sqrtf,
572       /// long double sqrtl(long double x);
573       sqrtl,
574       /// int sscanf(const char *s, const char *format, ... );
575       sscanf,
576       /// int stat(const char *path, struct stat *buf);
577       stat,
578       /// int stat64(const char *path, struct stat64 *buf);
579       stat64,
580       /// int statvfs(const char *path, struct statvfs *buf);
581       statvfs,
582       /// int statvfs64(const char *path, struct statvfs64 *buf)
583       statvfs64,
584       /// char *stpcpy(char *s1, const char *s2);
585       stpcpy,
586       /// char *stpncpy(char *s1, const char *s2, size_t n);
587       stpncpy,
588       /// int strcasecmp(const char *s1, const char *s2);
589       strcasecmp,
590       /// char *strcat(char *s1, const char *s2);
591       strcat,
592       /// char *strchr(const char *s, int c);
593       strchr,
594       /// int strcmp(const char *s1, const char *s2);
595       strcmp,
596       /// int strcoll(const char *s1, const char *s2);
597       strcoll,
598       /// char *strcpy(char *s1, const char *s2);
599       strcpy,
600       /// size_t strcspn(const char *s1, const char *s2);
601       strcspn,
602       /// char *strdup(const char *s1);
603       strdup,
604       /// size_t strlen(const char *s);
605       strlen,
606       /// int strncasecmp(const char *s1, const char *s2, size_t n);
607       strncasecmp,
608       /// char *strncat(char *s1, const char *s2, size_t n);
609       strncat,
610       /// int strncmp(const char *s1, const char *s2, size_t n);
611       strncmp,
612       /// char *strncpy(char *s1, const char *s2, size_t n);
613       strncpy,
614       /// char *strndup(const char *s1, size_t n);
615       strndup,
616       /// size_t strnlen(const char *s, size_t maxlen);
617       strnlen,
618       /// char *strpbrk(const char *s1, const char *s2);
619       strpbrk,
620       /// char *strrchr(const char *s, int c);
621       strrchr,
622       /// size_t strspn(const char *s1, const char *s2);
623       strspn,
624       /// char *strstr(const char *s1, const char *s2);
625       strstr,
626       /// double strtod(const char *nptr, char **endptr);
627       strtod,
628       /// float strtof(const char *nptr, char **endptr);
629       strtof,
630       // char *strtok(char *s1, const char *s2);
631       strtok,
632       // char *strtok_r(char *s, const char *sep, char **lasts);
633       strtok_r,
634       /// long int strtol(const char *nptr, char **endptr, int base);
635       strtol,
636       /// long double strtold(const char *nptr, char **endptr);
637       strtold,
638       /// long long int strtoll(const char *nptr, char **endptr, int base);
639       strtoll,
640       /// unsigned long int strtoul(const char *nptr, char **endptr, int base);
641       strtoul,
642       /// unsigned long long int strtoull(const char *nptr, char **endptr,
643       ///                                 int base);
644       strtoull,
645       /// size_t strxfrm(char *s1, const char *s2, size_t n);
646       strxfrm,
647       /// int system(const char *command);
648       system,
649       /// double tan(double x);
650       tan,
651       /// float tanf(float x);
652       tanf,
653       /// double tanh(double x);
654       tanh,
655       /// float tanhf(float x);
656       tanhf,
657       /// long double tanhl(long double x);
658       tanhl,
659       /// long double tanl(long double x);
660       tanl,
661       /// clock_t times(struct tms *buffer);
662       times,
663       /// FILE *tmpfile(void);
664       tmpfile,
665       /// FILE *tmpfile64(void)
666       tmpfile64,
667       /// int toascii(int c);
668       toascii,
669       /// double trunc(double x);
670       trunc,
671       /// float truncf(float x);
672       truncf,
673       /// long double truncl(long double x);
674       truncl,
675       /// int uname(struct utsname *name);
676       uname,
677       /// int ungetc(int c, FILE *stream);
678       ungetc,
679       /// int unlink(const char *path);
680       unlink,
681       /// int unsetenv(const char *name);
682       unsetenv,
683       /// int utime(const char *path, const struct utimbuf *times);
684       utime,
685       /// int utimes(const char *path, const struct timeval times[2]);
686       utimes,
687       /// void *valloc(size_t size);
688       valloc,
689       /// int vfprintf(FILE *stream, const char *format, va_list ap);
690       vfprintf,
691       /// int vfscanf(FILE *stream, const char *format, va_list arg);
692       vfscanf,
693       /// int vprintf(const char *restrict format, va_list ap);
694       vprintf,
695       /// int vscanf(const char *format, va_list arg);
696       vscanf,
697       /// int vsnprintf(char *s, size_t n, const char *format, va_list ap);
698       vsnprintf,
699       /// int vsprintf(char *s, const char *format, va_list ap);
700       vsprintf,
701       /// int vsscanf(const char *s, const char *format, va_list arg);
702       vsscanf,
703       /// ssize_t write(int fildes, const void *buf, size_t nbyte);
704       write,
705
706       NumLibFuncs
707     };
708   }
709
710 /// \brief Implementation of the target library information.
711 ///
712 /// This class constructs tables that hold the target library information and
713 /// make it available. However, it is somewhat expensive to compute and only
714 /// depends on the triple. So users typicaly interact with the \c
715 /// TargetLibraryInfo wrapper below.
716 class TargetLibraryInfoImpl {
717   friend class TargetLibraryInfo;
718
719   unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
720   llvm::DenseMap<unsigned, std::string> CustomNames;
721   static const char* StandardNames[LibFunc::NumLibFuncs];
722
723   enum AvailabilityState {
724     StandardName = 3, // (memset to all ones)
725     CustomName = 1,
726     Unavailable = 0  // (memset to all zeros)
727   };
728   void setState(LibFunc::Func F, AvailabilityState State) {
729     AvailableArray[F/4] &= ~(3 << 2*(F&3));
730     AvailableArray[F/4] |= State << 2*(F&3);
731   }
732   AvailabilityState getState(LibFunc::Func F) const {
733     return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
734   }
735
736 public:
737   TargetLibraryInfoImpl();
738   explicit TargetLibraryInfoImpl(const Triple &T);
739
740   // Provide value semantics.
741   TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI);
742   TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI);
743   TargetLibraryInfoImpl &operator=(const TargetLibraryInfoImpl &TLI);
744   TargetLibraryInfoImpl &operator=(TargetLibraryInfoImpl &&TLI);
745
746   /// \brief Searches for a particular function name.
747   ///
748   /// If it is one of the known library functions, return true and set F to the
749   /// corresponding value.
750   bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
751
752   /// \brief Forces a function to be marked as unavailable.
753   void setUnavailable(LibFunc::Func F) {
754     setState(F, Unavailable);
755   }
756
757   /// \brief Forces a function to be marked as available.
758   void setAvailable(LibFunc::Func F) {
759     setState(F, StandardName);
760   }
761
762   /// \brief Forces a function to be marked as available and provide an
763   /// alternate name that must be used.
764   void setAvailableWithName(LibFunc::Func F, StringRef Name) {
765     if (StandardNames[F] != Name) {
766       setState(F, CustomName);
767       CustomNames[F] = Name;
768       assert(CustomNames.find(F) != CustomNames.end());
769     } else {
770       setState(F, StandardName);
771     }
772   }
773
774   /// \brief Disables all builtins.
775   ///
776   /// This can be used for options like -fno-builtin.
777   void disableAllFunctions();
778 };
779
780 /// \brief Provides information about what library functions are available for
781 /// the current target.
782 ///
783 /// This both allows optimizations to handle them specially and frontends to
784 /// disable such optimizations through -fno-builtin etc.
785 class TargetLibraryInfo {
786   friend class TargetLibraryAnalysis;
787   friend class TargetLibraryInfoWrapperPass;
788
789   const TargetLibraryInfoImpl *Impl;
790
791 public:
792   explicit TargetLibraryInfo(const TargetLibraryInfoImpl &Impl) : Impl(&Impl) {}
793
794   // Provide value semantics.
795   TargetLibraryInfo(const TargetLibraryInfo &TLI) : Impl(TLI.Impl) {}
796   TargetLibraryInfo(TargetLibraryInfo &&TLI) : Impl(TLI.Impl) {}
797   TargetLibraryInfo &operator=(const TargetLibraryInfo &TLI) {
798     Impl = TLI.Impl;
799     return *this;
800   }
801   TargetLibraryInfo &operator=(TargetLibraryInfo &&TLI) {
802     Impl = TLI.Impl;
803     return *this;
804   }
805
806   /// \brief Searches for a particular function name.
807   ///
808   /// If it is one of the known library functions, return true and set F to the
809   /// corresponding value.
810   bool getLibFunc(StringRef funcName, LibFunc::Func &F) const {
811     return Impl->getLibFunc(funcName, F);
812   }
813
814   /// \brief Tests wether a library function is available.
815   bool has(LibFunc::Func F) const {
816     return Impl->getState(F) != TargetLibraryInfoImpl::Unavailable;
817   }
818
819   /// \brief Tests if the function is both available and a candidate for
820   /// optimized code generation.
821   bool hasOptimizedCodeGen(LibFunc::Func F) const {
822     if (Impl->getState(F) == TargetLibraryInfoImpl::Unavailable)
823       return false;
824     switch (F) {
825     default: break;
826     case LibFunc::copysign:  case LibFunc::copysignf:  case LibFunc::copysignl:
827     case LibFunc::fabs:      case LibFunc::fabsf:      case LibFunc::fabsl:
828     case LibFunc::sin:       case LibFunc::sinf:       case LibFunc::sinl:
829     case LibFunc::cos:       case LibFunc::cosf:       case LibFunc::cosl:
830     case LibFunc::sqrt:      case LibFunc::sqrtf:      case LibFunc::sqrtl:
831     case LibFunc::sqrt_finite: case LibFunc::sqrtf_finite:
832                                                   case LibFunc::sqrtl_finite:
833     case LibFunc::fmax:      case LibFunc::fmaxf:      case LibFunc::fmaxl:
834     case LibFunc::fmin:      case LibFunc::fminf:      case LibFunc::fminl:
835     case LibFunc::floor:     case LibFunc::floorf:     case LibFunc::floorl:
836     case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
837     case LibFunc::ceil:      case LibFunc::ceilf:      case LibFunc::ceill:
838     case LibFunc::rint:      case LibFunc::rintf:      case LibFunc::rintl:
839     case LibFunc::round:     case LibFunc::roundf:     case LibFunc::roundl:
840     case LibFunc::trunc:     case LibFunc::truncf:     case LibFunc::truncl:
841     case LibFunc::log2:      case LibFunc::log2f:      case LibFunc::log2l:
842     case LibFunc::exp2:      case LibFunc::exp2f:      case LibFunc::exp2l:
843     case LibFunc::memcmp:    case LibFunc::strcmp:     case LibFunc::strcpy:
844     case LibFunc::stpcpy:    case LibFunc::strlen:     case LibFunc::strnlen:
845     case LibFunc::memchr:
846       return true;
847     }
848     return false;
849   }
850
851   StringRef getName(LibFunc::Func F) const {
852     auto State = Impl->getState(F);
853     if (State == TargetLibraryInfoImpl::Unavailable)
854       return StringRef();
855     if (State == TargetLibraryInfoImpl::StandardName)
856       return Impl->StandardNames[F];
857     assert(State == TargetLibraryInfoImpl::CustomName);
858     return Impl->CustomNames.find(F)->second;
859   }
860
861   /// \brief Handle invalidation from the pass manager.
862   ///
863   /// If we try to invalidate this info, just return false. It cannot become
864   /// invalid even if the module changes.
865   bool invalidate(Module &, const PreservedAnalyses &) { return false; }
866 };
867
868 /// \brief Analysis pass providing the \c TargetLibraryInfo.
869 ///
870 /// Note that this pass's result cannot be invalidated, it is immutable for the
871 /// life of the module.
872 class TargetLibraryAnalysis {
873 public:
874   typedef TargetLibraryInfo Result;
875
876   /// \brief Opaque, unique identifier for this analysis pass.
877   static void *ID() { return (void *)&PassID; }
878
879   /// \brief Default construct the library analysis.
880   ///
881   /// This will use the module's triple to construct the library info for that
882   /// module.
883   TargetLibraryAnalysis() {}
884
885   /// \brief Construct a library analysis with preset info.
886   ///
887   /// This will directly copy the preset info into the result without
888   /// consulting the module's triple.
889   TargetLibraryAnalysis(TargetLibraryInfoImpl PresetInfoImpl)
890       : PresetInfoImpl(std::move(PresetInfoImpl)) {}
891
892   // Move semantics. We spell out the constructors for MSVC.
893   TargetLibraryAnalysis(TargetLibraryAnalysis &&Arg)
894       : PresetInfoImpl(std::move(Arg.PresetInfoImpl)), Impls(std::move(Arg.Impls)) {}
895   TargetLibraryAnalysis &operator=(TargetLibraryAnalysis &&RHS) {
896     PresetInfoImpl = std::move(RHS.PresetInfoImpl);
897     Impls = std::move(RHS.Impls);
898     return *this;
899   }
900
901   TargetLibraryInfo run(Module &M);
902   TargetLibraryInfo run(Function &F);
903
904   /// \brief Provide access to a name for this pass for debugging purposes.
905   static StringRef name() { return "TargetLibraryAnalysis"; }
906
907 private:
908   static char PassID;
909
910   Optional<TargetLibraryInfoImpl> PresetInfoImpl;
911
912   StringMap<std::unique_ptr<TargetLibraryInfoImpl>> Impls;
913
914   TargetLibraryInfoImpl &lookupInfoImpl(Triple T);
915 };
916
917 class TargetLibraryInfoWrapperPass : public ImmutablePass {
918   TargetLibraryInfoImpl TLIImpl;
919   TargetLibraryInfo TLI;
920
921   virtual void anchor();
922
923 public:
924   static char ID;
925   TargetLibraryInfoWrapperPass();
926   explicit TargetLibraryInfoWrapperPass(const Triple &T);
927   explicit TargetLibraryInfoWrapperPass(const TargetLibraryInfoImpl &TLI);
928
929   TargetLibraryInfo &getTLI() { return TLI; }
930   const TargetLibraryInfo &getTLI() const { return TLI; }
931 };
932
933 } // end namespace llvm
934
935 #endif