LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetLibraryInfo.cpp
Go to the documentation of this file.
1 //===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
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 // This file implements the TargetLibraryInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/Triple.h"
16 using namespace llvm;
17 
18 // Register the default implementation.
19 INITIALIZE_PASS(TargetLibraryInfo, "targetlibinfo",
20  "Target Library Information", false, true)
21 char TargetLibraryInfo::ID = 0;
22 
23 void TargetLibraryInfo::anchor() { }
24 
25 const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
26  {
27  "_IO_getc",
28  "_IO_putc",
29  "_ZdaPv",
30  "_ZdaPvRKSt9nothrow_t",
31  "_ZdlPv",
32  "_ZdlPvRKSt9nothrow_t",
33  "_Znaj",
34  "_ZnajRKSt9nothrow_t",
35  "_Znam",
36  "_ZnamRKSt9nothrow_t",
37  "_Znwj",
38  "_ZnwjRKSt9nothrow_t",
39  "_Znwm",
40  "_ZnwmRKSt9nothrow_t",
41  "__cospi",
42  "__cospif",
43  "__cxa_atexit",
44  "__cxa_guard_abort",
45  "__cxa_guard_acquire",
46  "__cxa_guard_release",
47  "__isoc99_scanf",
48  "__isoc99_sscanf",
49  "__memcpy_chk",
50  "__sincospi_stret",
51  "__sincospi_stretf",
52  "__sinpi",
53  "__sinpif",
54  "__sqrt_finite",
55  "__sqrtf_finite",
56  "__sqrtl_finite",
57  "__strdup",
58  "__strndup",
59  "__strtok_r",
60  "abs",
61  "access",
62  "acos",
63  "acosf",
64  "acosh",
65  "acoshf",
66  "acoshl",
67  "acosl",
68  "asin",
69  "asinf",
70  "asinh",
71  "asinhf",
72  "asinhl",
73  "asinl",
74  "atan",
75  "atan2",
76  "atan2f",
77  "atan2l",
78  "atanf",
79  "atanh",
80  "atanhf",
81  "atanhl",
82  "atanl",
83  "atof",
84  "atoi",
85  "atol",
86  "atoll",
87  "bcmp",
88  "bcopy",
89  "bzero",
90  "calloc",
91  "cbrt",
92  "cbrtf",
93  "cbrtl",
94  "ceil",
95  "ceilf",
96  "ceill",
97  "chmod",
98  "chown",
99  "clearerr",
100  "closedir",
101  "copysign",
102  "copysignf",
103  "copysignl",
104  "cos",
105  "cosf",
106  "cosh",
107  "coshf",
108  "coshl",
109  "cosl",
110  "ctermid",
111  "exp",
112  "exp10",
113  "exp10f",
114  "exp10l",
115  "exp2",
116  "exp2f",
117  "exp2l",
118  "expf",
119  "expl",
120  "expm1",
121  "expm1f",
122  "expm1l",
123  "fabs",
124  "fabsf",
125  "fabsl",
126  "fclose",
127  "fdopen",
128  "feof",
129  "ferror",
130  "fflush",
131  "ffs",
132  "ffsl",
133  "ffsll",
134  "fgetc",
135  "fgetpos",
136  "fgets",
137  "fileno",
138  "fiprintf",
139  "flockfile",
140  "floor",
141  "floorf",
142  "floorl",
143  "fmod",
144  "fmodf",
145  "fmodl",
146  "fopen",
147  "fopen64",
148  "fprintf",
149  "fputc",
150  "fputs",
151  "fread",
152  "free",
153  "frexp",
154  "frexpf",
155  "frexpl",
156  "fscanf",
157  "fseek",
158  "fseeko",
159  "fseeko64",
160  "fsetpos",
161  "fstat",
162  "fstat64",
163  "fstatvfs",
164  "fstatvfs64",
165  "ftell",
166  "ftello",
167  "ftello64",
168  "ftrylockfile",
169  "funlockfile",
170  "fwrite",
171  "getc",
172  "getc_unlocked",
173  "getchar",
174  "getenv",
175  "getitimer",
176  "getlogin_r",
177  "getpwnam",
178  "gets",
179  "gettimeofday",
180  "htonl",
181  "htons",
182  "iprintf",
183  "isascii",
184  "isdigit",
185  "labs",
186  "lchown",
187  "llabs",
188  "log",
189  "log10",
190  "log10f",
191  "log10l",
192  "log1p",
193  "log1pf",
194  "log1pl",
195  "log2",
196  "log2f",
197  "log2l",
198  "logb",
199  "logbf",
200  "logbl",
201  "logf",
202  "logl",
203  "lstat",
204  "lstat64",
205  "malloc",
206  "memalign",
207  "memccpy",
208  "memchr",
209  "memcmp",
210  "memcpy",
211  "memmove",
212  "memrchr",
213  "memset",
214  "memset_pattern16",
215  "mkdir",
216  "mktime",
217  "modf",
218  "modff",
219  "modfl",
220  "nearbyint",
221  "nearbyintf",
222  "nearbyintl",
223  "ntohl",
224  "ntohs",
225  "open",
226  "open64",
227  "opendir",
228  "pclose",
229  "perror",
230  "popen",
231  "posix_memalign",
232  "pow",
233  "powf",
234  "powl",
235  "pread",
236  "printf",
237  "putc",
238  "putchar",
239  "puts",
240  "pwrite",
241  "qsort",
242  "read",
243  "readlink",
244  "realloc",
245  "reallocf",
246  "realpath",
247  "remove",
248  "rename",
249  "rewind",
250  "rint",
251  "rintf",
252  "rintl",
253  "rmdir",
254  "round",
255  "roundf",
256  "roundl",
257  "scanf",
258  "setbuf",
259  "setitimer",
260  "setvbuf",
261  "sin",
262  "sinf",
263  "sinh",
264  "sinhf",
265  "sinhl",
266  "sinl",
267  "siprintf",
268  "snprintf",
269  "sprintf",
270  "sqrt",
271  "sqrtf",
272  "sqrtl",
273  "sscanf",
274  "stat",
275  "stat64",
276  "statvfs",
277  "statvfs64",
278  "stpcpy",
279  "stpncpy",
280  "strcasecmp",
281  "strcat",
282  "strchr",
283  "strcmp",
284  "strcoll",
285  "strcpy",
286  "strcspn",
287  "strdup",
288  "strlen",
289  "strncasecmp",
290  "strncat",
291  "strncmp",
292  "strncpy",
293  "strndup",
294  "strnlen",
295  "strpbrk",
296  "strrchr",
297  "strspn",
298  "strstr",
299  "strtod",
300  "strtof",
301  "strtok",
302  "strtok_r",
303  "strtol",
304  "strtold",
305  "strtoll",
306  "strtoul",
307  "strtoull",
308  "strxfrm",
309  "system",
310  "tan",
311  "tanf",
312  "tanh",
313  "tanhf",
314  "tanhl",
315  "tanl",
316  "times",
317  "tmpfile",
318  "tmpfile64",
319  "toascii",
320  "trunc",
321  "truncf",
322  "truncl",
323  "uname",
324  "ungetc",
325  "unlink",
326  "unsetenv",
327  "utime",
328  "utimes",
329  "valloc",
330  "vfprintf",
331  "vfscanf",
332  "vprintf",
333  "vscanf",
334  "vsnprintf",
335  "vsprintf",
336  "vsscanf",
337  "write"
338  };
339 
340 static bool hasSinCosPiStret(const Triple &T) {
341  // Only Darwin variants have _stret versions of combined trig functions.
342  if (!T.isMacOSX() && T.getOS() != Triple::IOS)
343  return false;
344 
345  // The ABI is rather complicated on x86, so don't do anything special there.
346  if (T.getArch() == Triple::x86)
347  return false;
348 
349  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
350  return false;
351 
352  if (T.getOS() == Triple::IOS && T.isOSVersionLT(7, 0))
353  return false;
354 
355  return true;
356 }
357 
358 /// initialize - Initialize the set of available library functions based on the
359 /// specified target triple. This should be carefully written so that a missing
360 /// target triple gets a sane set of defaults.
361 static void initialize(TargetLibraryInfo &TLI, const Triple &T,
362  const char **StandardNames) {
364 
365 #ifndef NDEBUG
366  // Verify that the StandardNames array is in alphabetical order.
367  for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) {
368  if (strcmp(StandardNames[F-1], StandardNames[F]) >= 0)
369  llvm_unreachable("TargetLibraryInfo function names must be sorted");
370  }
371 #endif // !NDEBUG
372 
373  // memset_pattern16 is only available on iOS 3.0 and Mac OS/X 10.5 and later.
374  if (T.isMacOSX()) {
375  if (T.isMacOSXVersionLT(10, 5))
377  } else if (T.isiOS()) {
378  if (T.isOSVersionLT(3, 0))
380  } else {
382  }
383 
384  if (!hasSinCosPiStret(T)) {
391  }
392 
393  if (T.isMacOSX() && T.getArch() == Triple::x86 &&
394  !T.isMacOSXVersionLT(10, 7)) {
395  // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
396  // we don't care about) have two versions; on recent OSX, the one we want
397  // has a $UNIX2003 suffix. The two implementations are identical except
398  // for the return value in some edge cases. However, we don't want to
399  // generate code that depends on the old symbols.
400  TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
401  TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
402  }
403 
404  // iprintf and friends are only available on XCore and TCE.
405  if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
409  }
410 
411  if (T.getOS() == Triple::Win32) {
412  // Win32 does not support long double
422  TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
435 
436  // Win32 only has C89 math
479 
480  // Win32 provides some C99 math with mangled names
481  TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
482 
483  if (T.getArch() == Triple::x86) {
484  // Win32 on x86 implements single-precision math functions as macros
503  }
504 
505  // Win32 does *not* provide provide these functions, but they are
506  // generally available on POSIX-compliant systems:
562 
563  // Win32 does *not* provide provide these functions, but they are
564  // specified by C99:
568  }
569 
570  // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
571  // Linux (GLIBC):
572  // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
573  // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsl.c
574  // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
575  switch (T.getOS()) {
576  case Triple::Darwin:
577  case Triple::MacOSX:
578  case Triple::IOS:
579  case Triple::FreeBSD:
580  case Triple::Linux:
581  break;
582  default:
584  }
585 
586  // ffsll is available on at least FreeBSD and Linux (GLIBC):
587  // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsll.c
588  // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
589  switch (T.getOS()) {
590  case Triple::FreeBSD:
591  case Triple::Linux:
592  break;
593  default:
595  }
596 
597  // The following functions are available on at least Linux:
598  if (!T.isOSLinux()) {
616  }
617 }
618 
619 
621  // Default to everything being available.
622  memset(AvailableArray, -1, sizeof(AvailableArray));
623 
624  initialize(*this, Triple(), StandardNames);
625 }
626 
628  // Default to everything being available.
629  memset(AvailableArray, -1, sizeof(AvailableArray));
630 
631  initialize(*this, T, StandardNames);
632 }
633 
635  : ImmutablePass(ID) {
636  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
637  CustomNames = TLI.CustomNames;
638 }
639 
640 namespace {
641 struct StringComparator {
642  /// Compare two strings and return true if LHS is lexicographically less than
643  /// RHS. Requires that RHS doesn't contain any zero bytes.
644  bool operator()(const char *LHS, StringRef RHS) const {
645  // Compare prefixes with strncmp. If prefixes match we know that LHS is
646  // greater or equal to RHS as RHS can't contain any '\0'.
647  return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;
648  }
649 
650  // Provided for compatibility with MSVC's debug mode.
651  bool operator()(StringRef LHS, const char *RHS) const { return LHS < RHS; }
652  bool operator()(StringRef LHS, StringRef RHS) const { return LHS < RHS; }
653  bool operator()(const char *LHS, const char *RHS) const {
654  return std::strcmp(LHS, RHS) < 0;
655  }
656 };
657 }
658 
660  LibFunc::Func &F) const {
661  const char **Start = &StandardNames[0];
662  const char **End = &StandardNames[LibFunc::NumLibFuncs];
663 
664  // Filter out empty names and names containing null bytes, those can't be in
665  // our table.
666  if (funcName.empty() || funcName.find('\0') != StringRef::npos)
667  return false;
668 
669  // Check for \01 prefix that is used to mangle __asm declarations and
670  // strip it if present.
671  if (funcName.front() == '\01')
672  funcName = funcName.substr(1);
673  const char **I = std::lower_bound(Start, End, funcName, StringComparator());
674  if (I != End && *I == funcName) {
675  F = (LibFunc::Func)(I - Start);
676  return true;
677  }
678  return false;
679 }
680 
681 /// disableAllFunctions - This disables all builtins, which is used for options
682 /// like -fno-builtin.
684  memset(AvailableArray, 0, sizeof(AvailableArray));
685 }
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
Definition: Triple.h:178
void flockfile(FILE *file);
int strcmp(const char *s1, const char *s2);
int fseeko(FILE *stream, off_t offset, int whence);
int uname(struct utsname *name);
static PassRegistry * getPassRegistry()
void bcopy(const void *s1, void *s2, size_t n);
int fstatvfs64(int fildes, struct statvfs64 *buf);
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
int chmod(const char *path, mode_t mode);
long double tanl(long double x);
int fstat(int fildes, struct stat *buf);
FILE *tmpfile64(void)
off64_t ftello64(FILE *stream)
double rint(double x);
int fstat64(int filedes, struct stat64 *buf)
void funlockfile(FILE *file);
FILE *fdopen(int fildes, const char *mode);.
long double copysignl(long double x, long double y);
int strncasecmp(const char *s1, const char *s2, size_t n);
void setUnavailable(LibFunc::Func F)
long double rintl(long double x);
size_t find(char C, size_t From=0) const
Definition: StringRef.h:233
long double truncl(long double x);
int lstat64(const char *path, struct stat64 *buf);
int open(const char *path, int oflag, ... );
float truncf(float x);
DIR *opendir(const char *dirname);.
float cbrtf(float x);
long double sinl(long double x);
void setAvailableWithName(LibFunc::Func F, StringRef Name)
float exp2f(float x);
StringRef substr(size_t Start, size_t N=npos) const
Definition: StringRef.h:392
float expf(float x);
char *ctermid(char *s);
double __sinpi(double x);
long double logbl(long double x);
long double expl(long double x);
double nearbyint(double x);
F(f)
int ffs(int i);
float atan2f(float y, float x);
int __isoc99_sscanf(const char *s, const char *format, ...)
ssize_t read(int fildes, void *buf, size_t nbyte);
double log1p(double x);
long double nearbyintl(long double x);
double trunc(double x);
float sqrtf(float x);
long double roundl(long double x);
long double coshl(long double x);
bool isMacOSX() const
Definition: Triple.h:303
long double fabsl(long double x);
int access(const char *path, int amode);
long double frexpl(long double num, int *exp);
long double cosl(long double x);
double round(double x);
int ftrylockfile(FILE *file);
long double asinl(long double x);
uint32_t ntohl(uint32_t netlong);
int _IO_getc(_IO_FILE * __fp);
bool getLibFunc(StringRef funcName, LibFunc::Func &F) const
double __sincospi_stret(double x);
off_t ftello(FILE *stream);
#define llvm_unreachable(msg)
double copysign(double x, double y);
float atanf(float x);
int closedir(DIR *dirp);
float sinhf(float x);
long double acoshl(long double x);
int gettimeofday(struct timeval *tp, void *tzp);
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
unsigned isMacOSXVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
Definition: Triple.h:288
int statvfs(const char *path, struct statvfs *buf);
bool isOSLinux() const
Tests whether the OS is Linux.
Definition: Triple.h:338
long long atoll(const char *nptr);
ssize_t readlink(const char *path, char *buf, size_t bufsize);
const char * data() const
Definition: StringRef.h:107
long double asinhl(long double x);
char *stpncpy(char *s1, const char *s2, size_t n);
double exp10(double x);
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:172
double log2(double x);
float fmodf(float x, float y);
int ffsl(long int i);
int rmdir(const char *path);
float log2f(float x);
void memset_pattern16(void *b, const void *pattern16, size_t len);
float tanhf(float x);
bool isiOS() const
Is this an iOS triple.
Definition: Triple.h:308
char *realpath(const char *file_name, char *resolved_name);
float floorf(float x);
long double sinhl(long double x);
float ceilf(float x);
int pclose(FILE *stream);
long double cbrtl(long double x);
int lstat(const char *path, struct stat *buf);
long double floorl(long double x);
uint16_t ntohs(uint16_t netshort);
int getitimer(int which, struct itimerval *value);
static void initialize(TargetLibraryInfo &TLI, const Triple &T, const char **StandardNames)
float exp10f(float x);
int fstatvfs(int fildes, struct statvfs *buf);
int bcmp(const void *s1, const void *s2, size_t n);
float cosf(float x);
float logf(float x);
float roundf(float x);
long double exp10l(long double x);
float rintf(float x);
int utimes(const char *path, const struct timeval times[2]);
int fseeko64(FILE *stream, off64_t offset, int whence)
float fabsf(float x);
int unlink(const char *path);
float __sincospi_stretf(float x);
float tanf(float x);
float frexpf(float num, int *exp);
float nearbyintf(float x);
int _IO_putc(int __c, _IO_FILE * __fp);
uint16_t htons(uint16_t hostshort);
float atanhf(float x);
int mkdir(const char *path, mode_t mode);
float asinhf(float x);
FILE *fopen64(const char *filename, const char *opentype)
long double expm1l(long double x);
int stat(const char *path, struct stat *buf);
int fputs(const char *s, FILE *stream);
clock_t times(struct tms *buffer);
int stat64(const char *path, struct stat64 *buf);
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:153
char * __strdup(const char *s);
float expm1f(float x);
int getc_unlocked(FILE *stream);
int chown(const char *path, uid_t owner, gid_t group);
static bool hasSinCosPiStret(const Triple &T)
long double tanhl(long double x);
float coshf(float x);
int fiprintf(FILE *stream, const char *format, ...);
float logbf(float x);
double atanh(double x);
struct passwd *getpwnam(const char *name);
long double atan2l(long double y, long double x);
double cbrt(double x);
void *memccpy(void *s1, const void *s2, int c, size_t n);
long double atanl(long double x);
char *stpcpy(char *s1, const char *s2);
int ffsll(long long int i);
double long double log2l(long double x);
long double logl(long double x);
int open64(const char *filename, int flags[, mode_t mode])
long double log1pl(long double x);
float powf(float x, float y);
FILE *popen(const char *command, const char *mode);.
int statvfs64(const char *path, struct statvfs64 *buf)
long double acosl(long double x);
bool isOSVersionLT(unsigned Major, unsigned Minor=0, unsigned Micro=0) const
Definition: Triple.h:270
ssize_t write(int fildes, const void *buf, size_t nbyte);
long double atanhl(long double x);
double __cospi(double x);
double expm1(double x);
double asinh(double x);
long double ceill(long double x);
int unsetenv(const char *name);
static const size_t npos
Definition: StringRef.h:45
double logb(double x);
int utime(const char *path, const struct utimbuf *times);
void initializeTargetLibraryInfoPass(PassRegistry &)
char * __strtok_r(char *s, const char *delim, char **save_ptr);
void bzero(void *s, size_t n);
#define I(x, y, z)
Definition: MD5.cpp:54
long double fmodl(long double x, long double y);
long double modfl(long double value, long double *iptr);
float acosf(float x);
long long int llabs(long long int j);
int strcasecmp(const char *s1, const char *s2);
int getlogin_r(char *name, size_t namesize);
int fileno(FILE *stream);
char front() const
front - Get the first character in the string.
Definition: StringRef.h:116
float sinf(float x);
float acoshf(float x);
int lchown(const char *path, uid_t owner, gid_t group);
double acosh(double x);
long double exp2l(long double x);
double exp2(double x);
void *memalign(size_t boundary, size_t size);
float __sinpif(float x);
int siprintf(char *str, const char *format, ...);
float log1pf(float x);
int __isoc99_scanf (const char *format, ...)
int strncmp(const char *s1, const char *s2, size_t n);
long double powl(long double x, long double y);
float copysignf(float x, float y);
uint32_t htonl(uint32_t hostlong);
int iprintf(const char *format, ...);
float __cospif(float x);
float asinf(float x);
long double sqrtl(long double x);
bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:110