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