1 //===-- llvm/Target/TargetLibraryInfo.h - Library information ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TARGET_TARGETLIBRARYINFO_H
11 #define LLVM_TARGET_TARGETLIBRARYINFO_H
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/Pass.h"
21 /// int _IO_getc(_IO_FILE * __fp);
23 /// int _IO_putc(int __c, _IO_FILE * __fp);
25 /// void operator delete[](void*);
27 /// void operator delete[](void*, nothrow);
29 /// void operator delete[](void*, unsigned int);
31 /// void operator delete[](void*, unsigned long);
33 /// void operator delete(void*);
35 /// void operator delete(void*, nothrow);
37 /// void operator delete(void*, unsigned int);
39 /// void operator delete(void*, unsigned long);
41 /// void *new[](unsigned int);
43 /// void *new[](unsigned int, nothrow);
45 /// void *new[](unsigned long);
47 /// void *new[](unsigned long, nothrow);
49 /// void *new(unsigned int);
51 /// void *new(unsigned int, nothrow);
53 /// void *new(unsigned long);
55 /// void *new(unsigned long, nothrow);
57 /// double __cospi(double x);
59 /// float __cospif(float x);
61 /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
63 /// void __cxa_guard_abort(guard_t *guard);
64 /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
66 /// int __cxa_guard_acquire(guard_t *guard);
68 /// void __cxa_guard_release(guard_t *guard);
70 /// int __isoc99_scanf (const char *format, ...)
72 /// int __isoc99_sscanf(const char *s, const char *format, ...)
74 /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
76 /// double __sincospi_stret(double x);
78 /// float __sincospif_stret(float x);
80 /// double __sinpi(double x);
82 /// float __sinpif(float x);
84 /// double __sqrt_finite(double x);
86 /// float __sqrt_finite(float x);
88 /// long double __sqrt_finite(long double x);
90 /// char * __strdup(const char *s);
92 /// char *__strndup(const char *s, size_t n);
94 /// char * __strtok_r(char *s, const char *delim, char **save_ptr);
98 /// int access(const char *path, int amode);
100 /// double acos(double x);
102 /// float acosf(float x);
104 /// double acosh(double x);
106 /// float acoshf(float x);
108 /// long double acoshl(long double x);
110 /// long double acosl(long double x);
112 /// double asin(double x);
114 /// float asinf(float x);
116 /// double asinh(double x);
118 /// float asinhf(float x);
120 /// long double asinhl(long double x);
122 /// long double asinl(long double x);
124 /// double atan(double x);
126 /// double atan2(double y, double x);
128 /// float atan2f(float y, float x);
130 /// long double atan2l(long double y, long double x);
132 /// float atanf(float x);
134 /// double atanh(double x);
136 /// float atanhf(float x);
138 /// long double atanhl(long double x);
140 /// long double atanl(long double x);
142 /// double atof(const char *str);
144 /// int atoi(const char *str);
146 /// long atol(const char *str);
148 /// long long atoll(const char *nptr);
150 /// int bcmp(const void *s1, const void *s2, size_t n);
152 /// void bcopy(const void *s1, void *s2, size_t n);
154 /// void bzero(void *s, size_t n);
156 /// void *calloc(size_t count, size_t size);
158 /// double cbrt(double x);
160 /// float cbrtf(float x);
162 /// long double cbrtl(long double x);
164 /// double ceil(double x);
166 /// float ceilf(float x);
168 /// long double ceill(long double x);
170 /// int chmod(const char *path, mode_t mode);
172 /// int chown(const char *path, uid_t owner, gid_t group);
174 /// void clearerr(FILE *stream);
176 /// int closedir(DIR *dirp);
178 /// double copysign(double x, double y);
180 /// float copysignf(float x, float y);
182 /// long double copysignl(long double x, long double y);
184 /// double cos(double x);
186 /// float cosf(float x);
188 /// double cosh(double x);
190 /// float coshf(float x);
192 /// long double coshl(long double x);
194 /// long double cosl(long double x);
196 /// char *ctermid(char *s);
198 /// double exp(double x);
200 /// double exp10(double x);
202 /// float exp10f(float x);
204 /// long double exp10l(long double x);
206 /// double exp2(double x);
208 /// float exp2f(float x);
210 /// long double exp2l(long double x);
212 /// float expf(float x);
214 /// long double expl(long double x);
216 /// double expm1(double x);
218 /// float expm1f(float x);
220 /// long double expm1l(long double x);
222 /// double fabs(double x);
224 /// float fabsf(float x);
226 /// long double fabsl(long double x);
228 /// int fclose(FILE *stream);
230 /// FILE *fdopen(int fildes, const char *mode);
232 /// int feof(FILE *stream);
234 /// int ferror(FILE *stream);
236 /// int fflush(FILE *stream);
240 /// int ffsl(long int i);
242 /// int ffsll(long long int i);
244 /// int fgetc(FILE *stream);
246 /// int fgetpos(FILE *stream, fpos_t *pos);
248 /// char *fgets(char *s, int n, FILE *stream);
250 /// int fileno(FILE *stream);
252 /// int fiprintf(FILE *stream, const char *format, ...);
254 /// void flockfile(FILE *file);
256 /// double floor(double x);
258 /// float floorf(float x);
260 /// long double floorl(long double x);
262 /// double fmax(double x, double y);
264 /// float fmaxf(float x, float y);
266 /// long double fmaxl(long double x, long double y);
268 /// double fmin(double x, double y);
270 /// float fminf(float x, float y);
272 /// long double fminl(long double x, long double y);
274 /// double fmod(double x, double y);
276 /// float fmodf(float x, float y);
278 /// long double fmodl(long double x, long double y);
280 /// FILE *fopen(const char *filename, const char *mode);
282 /// FILE *fopen64(const char *filename, const char *opentype)
284 /// int fprintf(FILE *stream, const char *format, ...);
286 /// int fputc(int c, FILE *stream);
288 /// int fputs(const char *s, FILE *stream);
290 /// size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
292 /// void free(void *ptr);
294 /// double frexp(double num, int *exp);
296 /// float frexpf(float num, int *exp);
298 /// long double frexpl(long double num, int *exp);
300 /// int fscanf(FILE *stream, const char *format, ... );
302 /// int fseek(FILE *stream, long offset, int whence);
304 /// int fseeko(FILE *stream, off_t offset, int whence);
306 /// int fseeko64(FILE *stream, off64_t offset, int whence)
308 /// int fsetpos(FILE *stream, const fpos_t *pos);
310 /// int fstat(int fildes, struct stat *buf);
312 /// int fstat64(int filedes, struct stat64 *buf)
314 /// int fstatvfs(int fildes, struct statvfs *buf);
316 /// int fstatvfs64(int fildes, struct statvfs64 *buf);
318 /// long ftell(FILE *stream);
320 /// off_t ftello(FILE *stream);
322 /// off64_t ftello64(FILE *stream)
324 /// int ftrylockfile(FILE *file);
326 /// void funlockfile(FILE *file);
328 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
331 /// int getc(FILE *stream);
333 /// int getc_unlocked(FILE *stream);
335 /// int getchar(void);
337 /// char *getenv(const char *name);
339 /// int getitimer(int which, struct itimerval *value);
341 /// int getlogin_r(char *name, size_t namesize);
343 /// struct passwd *getpwnam(const char *name);
345 /// char *gets(char *s);
347 /// int gettimeofday(struct timeval *tp, void *tzp);
349 /// uint32_t htonl(uint32_t hostlong);
351 /// uint16_t htons(uint16_t hostshort);
353 /// int iprintf(const char *format, ...);
355 /// int isascii(int c);
357 /// int isdigit(int c);
359 /// long int labs(long int j);
361 /// int lchown(const char *path, uid_t owner, gid_t group);
363 /// double ldexp(double x, int n);
365 /// float ldexpf(float x, int n);
367 /// long double ldexpl(long double x, int n);
369 /// long long int llabs(long long int j);
371 /// double log(double x);
373 /// double log10(double x);
375 /// float log10f(float x);
377 /// long double log10l(long double x);
379 /// double log1p(double x);
381 /// float log1pf(float x);
383 /// long double log1pl(long double x);
385 /// double log2(double x);
387 /// float log2f(float x);
389 /// double long double log2l(long double x);
391 /// double logb(double x);
393 /// float logbf(float x);
395 /// long double logbl(long double x);
397 /// float logf(float x);
399 /// long double logl(long double x);
401 /// int lstat(const char *path, struct stat *buf);
403 /// int lstat64(const char *path, struct stat64 *buf);
405 /// void *malloc(size_t size);
407 /// void *memalign(size_t boundary, size_t size);
409 /// void *memccpy(void *s1, const void *s2, int c, size_t n);
411 /// void *memchr(const void *s, int c, size_t n);
413 /// int memcmp(const void *s1, const void *s2, size_t n);
415 /// void *memcpy(void *s1, const void *s2, size_t n);
417 /// void *memmove(void *s1, const void *s2, size_t n);
419 // void *memrchr(const void *s, int c, size_t n);
421 /// void *memset(void *b, int c, size_t len);
423 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
425 /// int mkdir(const char *path, mode_t mode);
427 /// time_t mktime(struct tm *timeptr);
429 /// double modf(double x, double *iptr);
431 /// float modff(float, float *iptr);
433 /// long double modfl(long double value, long double *iptr);
435 /// double nearbyint(double x);
437 /// float nearbyintf(float x);
439 /// long double nearbyintl(long double x);
441 /// uint32_t ntohl(uint32_t netlong);
443 /// uint16_t ntohs(uint16_t netshort);
445 /// int open(const char *path, int oflag, ... );
447 /// int open64(const char *filename, int flags[, mode_t mode])
449 /// DIR *opendir(const char *dirname);
451 /// int pclose(FILE *stream);
453 /// void perror(const char *s);
455 /// FILE *popen(const char *command, const char *mode);
457 /// int posix_memalign(void **memptr, size_t alignment, size_t size);
459 /// double pow(double x, double y);
461 /// float powf(float x, float y);
463 /// long double powl(long double x, long double y);
465 /// ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
467 /// int printf(const char *format, ...);
469 /// int putc(int c, FILE *stream);
471 /// int putchar(int c);
473 /// int puts(const char *s);
475 /// ssize_t pwrite(int fildes, const void *buf, size_t nbyte,
478 /// void qsort(void *base, size_t nel, size_t width,
479 /// int (*compar)(const void *, const void *));
481 /// ssize_t read(int fildes, void *buf, size_t nbyte);
483 /// ssize_t readlink(const char *path, char *buf, size_t bufsize);
485 /// void *realloc(void *ptr, size_t size);
487 /// void *reallocf(void *ptr, size_t size);
489 /// char *realpath(const char *file_name, char *resolved_name);
491 /// int remove(const char *path);
493 /// int rename(const char *old, const char *new);
495 /// void rewind(FILE *stream);
497 /// double rint(double x);
499 /// float rintf(float x);
501 /// long double rintl(long double x);
503 /// int rmdir(const char *path);
505 /// double round(double x);
507 /// float roundf(float x);
509 /// long double roundl(long double x);
511 /// int scanf(const char *restrict format, ... );
513 /// void setbuf(FILE *stream, char *buf);
515 /// int setitimer(int which, const struct itimerval *value,
516 /// struct itimerval *ovalue);
518 /// int setvbuf(FILE *stream, char *buf, int type, size_t size);
520 /// double sin(double x);
522 /// float sinf(float x);
524 /// double sinh(double x);
526 /// float sinhf(float x);
528 /// long double sinhl(long double x);
530 /// long double sinl(long double x);
532 /// int siprintf(char *str, const char *format, ...);
534 /// int snprintf(char *s, size_t n, const char *format, ...);
536 /// int sprintf(char *str, const char *format, ...);
538 /// double sqrt(double x);
540 /// float sqrtf(float x);
542 /// long double sqrtl(long double x);
544 /// int sscanf(const char *s, const char *format, ... );
546 /// int stat(const char *path, struct stat *buf);
548 /// int stat64(const char *path, struct stat64 *buf);
550 /// int statvfs(const char *path, struct statvfs *buf);
552 /// int statvfs64(const char *path, struct statvfs64 *buf)
554 /// char *stpcpy(char *s1, const char *s2);
556 /// char *stpncpy(char *s1, const char *s2, size_t n);
558 /// int strcasecmp(const char *s1, const char *s2);
560 /// char *strcat(char *s1, const char *s2);
562 /// char *strchr(const char *s, int c);
564 /// int strcmp(const char *s1, const char *s2);
566 /// int strcoll(const char *s1, const char *s2);
568 /// char *strcpy(char *s1, const char *s2);
570 /// size_t strcspn(const char *s1, const char *s2);
572 /// char *strdup(const char *s1);
574 /// size_t strlen(const char *s);
576 /// int strncasecmp(const char *s1, const char *s2, size_t n);
578 /// char *strncat(char *s1, const char *s2, size_t n);
580 /// int strncmp(const char *s1, const char *s2, size_t n);
582 /// char *strncpy(char *s1, const char *s2, size_t n);
584 /// char *strndup(const char *s1, size_t n);
586 /// size_t strnlen(const char *s, size_t maxlen);
588 /// char *strpbrk(const char *s1, const char *s2);
590 /// char *strrchr(const char *s, int c);
592 /// size_t strspn(const char *s1, const char *s2);
594 /// char *strstr(const char *s1, const char *s2);
596 /// double strtod(const char *nptr, char **endptr);
598 /// float strtof(const char *nptr, char **endptr);
600 // char *strtok(char *s1, const char *s2);
602 // char *strtok_r(char *s, const char *sep, char **lasts);
604 /// long int strtol(const char *nptr, char **endptr, int base);
606 /// long double strtold(const char *nptr, char **endptr);
608 /// long long int strtoll(const char *nptr, char **endptr, int base);
610 /// unsigned long int strtoul(const char *nptr, char **endptr, int base);
612 /// unsigned long long int strtoull(const char *nptr, char **endptr,
615 /// size_t strxfrm(char *s1, const char *s2, size_t n);
617 /// int system(const char *command);
619 /// double tan(double x);
621 /// float tanf(float x);
623 /// double tanh(double x);
625 /// float tanhf(float x);
627 /// long double tanhl(long double x);
629 /// long double tanl(long double x);
631 /// clock_t times(struct tms *buffer);
633 /// FILE *tmpfile(void);
635 /// FILE *tmpfile64(void)
637 /// int toascii(int c);
639 /// double trunc(double x);
641 /// float truncf(float x);
643 /// long double truncl(long double x);
645 /// int uname(struct utsname *name);
647 /// int ungetc(int c, FILE *stream);
649 /// int unlink(const char *path);
651 /// int unsetenv(const char *name);
653 /// int utime(const char *path, const struct utimbuf *times);
655 /// int utimes(const char *path, const struct timeval times[2]);
657 /// void *valloc(size_t size);
659 /// int vfprintf(FILE *stream, const char *format, va_list ap);
661 /// int vfscanf(FILE *stream, const char *format, va_list arg);
663 /// int vprintf(const char *restrict format, va_list ap);
665 /// int vscanf(const char *format, va_list arg);
667 /// int vsnprintf(char *s, size_t n, const char *format, va_list ap);
669 /// int vsprintf(char *s, const char *format, va_list ap);
671 /// int vsscanf(const char *s, const char *format, va_list arg);
673 /// ssize_t write(int fildes, const void *buf, size_t nbyte);
680 /// TargetLibraryInfo - This immutable pass captures information about what
681 /// library functions are available for the current target, and allows a
682 /// frontend to disable optimizations through -fno-builtin etc.
683 class TargetLibraryInfo : public ImmutablePass {
684 virtual void anchor();
685 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
686 llvm::DenseMap<unsigned, std::string> CustomNames;
687 static const char* StandardNames[LibFunc::NumLibFuncs];
689 enum AvailabilityState {
690 StandardName = 3, // (memset to all ones)
692 Unavailable = 0 // (memset to all zeros)
694 void setState(LibFunc::Func F, AvailabilityState State) {
695 AvailableArray[F/4] &= ~(3 << 2*(F&3));
696 AvailableArray[F/4] |= State << 2*(F&3);
698 AvailabilityState getState(LibFunc::Func F) const {
699 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
705 TargetLibraryInfo(const Triple &T);
706 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
708 /// getLibFunc - Search for a particular function name. If it is one of the
709 /// known library functions, return true and set F to the corresponding value.
710 bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
712 /// has - This function is used by optimizations that want to match on or form
713 /// a given library function.
714 bool has(LibFunc::Func F) const {
715 return getState(F) != Unavailable;
718 /// hasOptimizedCodeGen - Return true if the function is both available as
719 /// a builtin and a candidate for optimized code generation.
720 bool hasOptimizedCodeGen(LibFunc::Func F) const {
721 if (getState(F) == Unavailable)
725 case LibFunc::copysign: case LibFunc::copysignf: case LibFunc::copysignl:
726 case LibFunc::fabs: case LibFunc::fabsf: case LibFunc::fabsl:
727 case LibFunc::sin: case LibFunc::sinf: case LibFunc::sinl:
728 case LibFunc::cos: case LibFunc::cosf: case LibFunc::cosl:
729 case LibFunc::sqrt: case LibFunc::sqrtf: case LibFunc::sqrtl:
730 case LibFunc::sqrt_finite: case LibFunc::sqrtf_finite:
731 case LibFunc::sqrtl_finite:
732 case LibFunc::fmax: case LibFunc::fmaxf: case LibFunc::fmaxl:
733 case LibFunc::fmin: case LibFunc::fminf: case LibFunc::fminl:
734 case LibFunc::floor: case LibFunc::floorf: case LibFunc::floorl:
735 case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
736 case LibFunc::ceil: case LibFunc::ceilf: case LibFunc::ceill:
737 case LibFunc::rint: case LibFunc::rintf: case LibFunc::rintl:
738 case LibFunc::round: case LibFunc::roundf: case LibFunc::roundl:
739 case LibFunc::trunc: case LibFunc::truncf: case LibFunc::truncl:
740 case LibFunc::log2: case LibFunc::log2f: case LibFunc::log2l:
741 case LibFunc::exp2: case LibFunc::exp2f: case LibFunc::exp2l:
742 case LibFunc::memcmp: case LibFunc::strcmp: case LibFunc::strcpy:
743 case LibFunc::stpcpy: case LibFunc::strlen: case LibFunc::strnlen:
744 case LibFunc::memchr:
750 StringRef getName(LibFunc::Func F) const {
751 AvailabilityState State = getState(F);
752 if (State == Unavailable)
754 if (State == StandardName)
755 return StandardNames[F];
756 assert(State == CustomName);
757 return CustomNames.find(F)->second;
760 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
761 /// ban use of specific library functions.
762 void setUnavailable(LibFunc::Func F) {
763 setState(F, Unavailable);
766 void setAvailable(LibFunc::Func F) {
767 setState(F, StandardName);
770 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
771 if (StandardNames[F] != Name) {
772 setState(F, CustomName);
773 CustomNames[F] = Name;
774 assert(CustomNames.find(F) != CustomNames.end());
776 setState(F, StandardName);
780 /// disableAllFunctions - This disables all builtins, which is used for
781 /// options like -fno-builtin.
782 void disableAllFunctions();
785 } // end namespace llvm