]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
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 | ||
14 | #include "llvm/Target/TargetLibraryInfo.h" | |
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 | { | |
970d7e83 LB |
27 | "_IO_getc", |
28 | "_IO_putc", | |
223e47cc | 29 | "_ZdaPv", |
1a4d82fc | 30 | "_ZdaPvRKSt9nothrow_t", |
85aaf69f SL |
31 | "_ZdaPvj", |
32 | "_ZdaPvm", | |
223e47cc | 33 | "_ZdlPv", |
1a4d82fc | 34 | "_ZdlPvRKSt9nothrow_t", |
85aaf69f SL |
35 | "_ZdlPvj", |
36 | "_ZdlPvm", | |
223e47cc LB |
37 | "_Znaj", |
38 | "_ZnajRKSt9nothrow_t", | |
39 | "_Znam", | |
40 | "_ZnamRKSt9nothrow_t", | |
41 | "_Znwj", | |
42 | "_ZnwjRKSt9nothrow_t", | |
43 | "_Znwm", | |
44 | "_ZnwmRKSt9nothrow_t", | |
1a4d82fc JJ |
45 | "__cospi", |
46 | "__cospif", | |
223e47cc LB |
47 | "__cxa_atexit", |
48 | "__cxa_guard_abort", | |
49 | "__cxa_guard_acquire", | |
50 | "__cxa_guard_release", | |
970d7e83 LB |
51 | "__isoc99_scanf", |
52 | "__isoc99_sscanf", | |
223e47cc | 53 | "__memcpy_chk", |
85aaf69f SL |
54 | "__memmove_chk", |
55 | "__memset_chk", | |
1a4d82fc JJ |
56 | "__sincospi_stret", |
57 | "__sincospif_stret", | |
58 | "__sinpi", | |
59 | "__sinpif", | |
60 | "__sqrt_finite", | |
61 | "__sqrtf_finite", | |
62 | "__sqrtl_finite", | |
85aaf69f SL |
63 | "__stpcpy_chk", |
64 | "__stpncpy_chk", | |
65 | "__strcpy_chk", | |
970d7e83 | 66 | "__strdup", |
85aaf69f | 67 | "__strncpy_chk", |
970d7e83 LB |
68 | "__strndup", |
69 | "__strtok_r", | |
70 | "abs", | |
71 | "access", | |
223e47cc LB |
72 | "acos", |
73 | "acosf", | |
74 | "acosh", | |
75 | "acoshf", | |
76 | "acoshl", | |
77 | "acosl", | |
78 | "asin", | |
79 | "asinf", | |
80 | "asinh", | |
81 | "asinhf", | |
82 | "asinhl", | |
83 | "asinl", | |
84 | "atan", | |
85 | "atan2", | |
86 | "atan2f", | |
87 | "atan2l", | |
88 | "atanf", | |
89 | "atanh", | |
90 | "atanhf", | |
91 | "atanhl", | |
92 | "atanl", | |
970d7e83 LB |
93 | "atof", |
94 | "atoi", | |
95 | "atol", | |
96 | "atoll", | |
97 | "bcmp", | |
98 | "bcopy", | |
99 | "bzero", | |
223e47cc LB |
100 | "calloc", |
101 | "cbrt", | |
102 | "cbrtf", | |
103 | "cbrtl", | |
104 | "ceil", | |
105 | "ceilf", | |
106 | "ceill", | |
970d7e83 LB |
107 | "chmod", |
108 | "chown", | |
109 | "clearerr", | |
110 | "closedir", | |
223e47cc LB |
111 | "copysign", |
112 | "copysignf", | |
113 | "copysignl", | |
114 | "cos", | |
115 | "cosf", | |
116 | "cosh", | |
117 | "coshf", | |
118 | "coshl", | |
119 | "cosl", | |
970d7e83 | 120 | "ctermid", |
223e47cc LB |
121 | "exp", |
122 | "exp10", | |
123 | "exp10f", | |
124 | "exp10l", | |
125 | "exp2", | |
126 | "exp2f", | |
127 | "exp2l", | |
128 | "expf", | |
129 | "expl", | |
130 | "expm1", | |
131 | "expm1f", | |
132 | "expm1l", | |
133 | "fabs", | |
134 | "fabsf", | |
135 | "fabsl", | |
970d7e83 LB |
136 | "fclose", |
137 | "fdopen", | |
138 | "feof", | |
139 | "ferror", | |
140 | "fflush", | |
141 | "ffs", | |
142 | "ffsl", | |
143 | "ffsll", | |
144 | "fgetc", | |
145 | "fgetpos", | |
146 | "fgets", | |
147 | "fileno", | |
223e47cc | 148 | "fiprintf", |
970d7e83 | 149 | "flockfile", |
223e47cc LB |
150 | "floor", |
151 | "floorf", | |
152 | "floorl", | |
1a4d82fc JJ |
153 | "fmax", |
154 | "fmaxf", | |
155 | "fmaxl", | |
156 | "fmin", | |
157 | "fminf", | |
158 | "fminl", | |
223e47cc LB |
159 | "fmod", |
160 | "fmodf", | |
161 | "fmodl", | |
970d7e83 LB |
162 | "fopen", |
163 | "fopen64", | |
164 | "fprintf", | |
223e47cc LB |
165 | "fputc", |
166 | "fputs", | |
970d7e83 | 167 | "fread", |
223e47cc | 168 | "free", |
970d7e83 LB |
169 | "frexp", |
170 | "frexpf", | |
171 | "frexpl", | |
172 | "fscanf", | |
173 | "fseek", | |
174 | "fseeko", | |
175 | "fseeko64", | |
176 | "fsetpos", | |
177 | "fstat", | |
178 | "fstat64", | |
179 | "fstatvfs", | |
180 | "fstatvfs64", | |
181 | "ftell", | |
182 | "ftello", | |
183 | "ftello64", | |
184 | "ftrylockfile", | |
185 | "funlockfile", | |
223e47cc | 186 | "fwrite", |
970d7e83 LB |
187 | "getc", |
188 | "getc_unlocked", | |
189 | "getchar", | |
190 | "getenv", | |
191 | "getitimer", | |
192 | "getlogin_r", | |
193 | "getpwnam", | |
194 | "gets", | |
1a4d82fc | 195 | "gettimeofday", |
970d7e83 LB |
196 | "htonl", |
197 | "htons", | |
223e47cc | 198 | "iprintf", |
970d7e83 LB |
199 | "isascii", |
200 | "isdigit", | |
c34b1796 AL |
201 | "je_mallocx", |
202 | "je_sdallocx", | |
970d7e83 LB |
203 | "labs", |
204 | "lchown", | |
1a4d82fc JJ |
205 | "ldexp", |
206 | "ldexpf", | |
207 | "ldexpl", | |
970d7e83 | 208 | "llabs", |
223e47cc LB |
209 | "log", |
210 | "log10", | |
211 | "log10f", | |
212 | "log10l", | |
213 | "log1p", | |
214 | "log1pf", | |
215 | "log1pl", | |
216 | "log2", | |
217 | "log2f", | |
218 | "log2l", | |
219 | "logb", | |
220 | "logbf", | |
221 | "logbl", | |
222 | "logf", | |
223 | "logl", | |
970d7e83 LB |
224 | "lstat", |
225 | "lstat64", | |
223e47cc | 226 | "malloc", |
970d7e83 LB |
227 | "memalign", |
228 | "memccpy", | |
223e47cc LB |
229 | "memchr", |
230 | "memcmp", | |
231 | "memcpy", | |
232 | "memmove", | |
970d7e83 | 233 | "memrchr", |
223e47cc LB |
234 | "memset", |
235 | "memset_pattern16", | |
970d7e83 LB |
236 | "mkdir", |
237 | "mktime", | |
238 | "modf", | |
239 | "modff", | |
240 | "modfl", | |
223e47cc LB |
241 | "nearbyint", |
242 | "nearbyintf", | |
243 | "nearbyintl", | |
970d7e83 LB |
244 | "ntohl", |
245 | "ntohs", | |
246 | "open", | |
247 | "open64", | |
248 | "opendir", | |
249 | "pclose", | |
250 | "perror", | |
251 | "popen", | |
223e47cc LB |
252 | "posix_memalign", |
253 | "pow", | |
254 | "powf", | |
255 | "powl", | |
970d7e83 LB |
256 | "pread", |
257 | "printf", | |
258 | "putc", | |
223e47cc LB |
259 | "putchar", |
260 | "puts", | |
970d7e83 LB |
261 | "pwrite", |
262 | "qsort", | |
263 | "read", | |
264 | "readlink", | |
223e47cc LB |
265 | "realloc", |
266 | "reallocf", | |
970d7e83 LB |
267 | "realpath", |
268 | "remove", | |
269 | "rename", | |
270 | "rewind", | |
223e47cc LB |
271 | "rint", |
272 | "rintf", | |
273 | "rintl", | |
970d7e83 | 274 | "rmdir", |
223e47cc LB |
275 | "round", |
276 | "roundf", | |
277 | "roundl", | |
970d7e83 LB |
278 | "scanf", |
279 | "setbuf", | |
280 | "setitimer", | |
281 | "setvbuf", | |
223e47cc LB |
282 | "sin", |
283 | "sinf", | |
284 | "sinh", | |
285 | "sinhf", | |
286 | "sinhl", | |
287 | "sinl", | |
288 | "siprintf", | |
970d7e83 LB |
289 | "snprintf", |
290 | "sprintf", | |
223e47cc LB |
291 | "sqrt", |
292 | "sqrtf", | |
293 | "sqrtl", | |
970d7e83 LB |
294 | "sscanf", |
295 | "stat", | |
296 | "stat64", | |
297 | "statvfs", | |
298 | "statvfs64", | |
299 | "stpcpy", | |
300 | "stpncpy", | |
301 | "strcasecmp", | |
223e47cc LB |
302 | "strcat", |
303 | "strchr", | |
970d7e83 LB |
304 | "strcmp", |
305 | "strcoll", | |
223e47cc | 306 | "strcpy", |
970d7e83 | 307 | "strcspn", |
223e47cc LB |
308 | "strdup", |
309 | "strlen", | |
970d7e83 | 310 | "strncasecmp", |
223e47cc LB |
311 | "strncat", |
312 | "strncmp", | |
313 | "strncpy", | |
314 | "strndup", | |
315 | "strnlen", | |
970d7e83 LB |
316 | "strpbrk", |
317 | "strrchr", | |
318 | "strspn", | |
319 | "strstr", | |
320 | "strtod", | |
321 | "strtof", | |
322 | "strtok", | |
323 | "strtok_r", | |
324 | "strtol", | |
325 | "strtold", | |
326 | "strtoll", | |
327 | "strtoul", | |
328 | "strtoull", | |
329 | "strxfrm", | |
330 | "system", | |
223e47cc LB |
331 | "tan", |
332 | "tanf", | |
333 | "tanh", | |
334 | "tanhf", | |
335 | "tanhl", | |
336 | "tanl", | |
970d7e83 LB |
337 | "times", |
338 | "tmpfile", | |
339 | "tmpfile64", | |
340 | "toascii", | |
223e47cc LB |
341 | "trunc", |
342 | "truncf", | |
343 | "truncl", | |
970d7e83 LB |
344 | "uname", |
345 | "ungetc", | |
346 | "unlink", | |
347 | "unsetenv", | |
348 | "utime", | |
349 | "utimes", | |
350 | "valloc", | |
351 | "vfprintf", | |
352 | "vfscanf", | |
353 | "vprintf", | |
354 | "vscanf", | |
355 | "vsnprintf", | |
356 | "vsprintf", | |
357 | "vsscanf", | |
358 | "write" | |
223e47cc LB |
359 | }; |
360 | ||
1a4d82fc JJ |
361 | static bool hasSinCosPiStret(const Triple &T) { |
362 | // Only Darwin variants have _stret versions of combined trig functions. | |
85aaf69f | 363 | if (!T.isOSDarwin()) |
1a4d82fc JJ |
364 | return false; |
365 | ||
366 | // The ABI is rather complicated on x86, so don't do anything special there. | |
367 | if (T.getArch() == Triple::x86) | |
368 | return false; | |
369 | ||
370 | if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9)) | |
371 | return false; | |
372 | ||
85aaf69f | 373 | if (T.isiOS() && T.isOSVersionLT(7, 0)) |
1a4d82fc JJ |
374 | return false; |
375 | ||
376 | return true; | |
377 | } | |
378 | ||
223e47cc LB |
379 | /// initialize - Initialize the set of available library functions based on the |
380 | /// specified target triple. This should be carefully written so that a missing | |
381 | /// target triple gets a sane set of defaults. | |
382 | static void initialize(TargetLibraryInfo &TLI, const Triple &T, | |
383 | const char **StandardNames) { | |
384 | initializeTargetLibraryInfoPass(*PassRegistry::getPassRegistry()); | |
385 | ||
386 | #ifndef NDEBUG | |
387 | // Verify that the StandardNames array is in alphabetical order. | |
388 | for (unsigned F = 1; F < LibFunc::NumLibFuncs; ++F) { | |
389 | if (strcmp(StandardNames[F-1], StandardNames[F]) >= 0) | |
390 | llvm_unreachable("TargetLibraryInfo function names must be sorted"); | |
391 | } | |
392 | #endif // !NDEBUG | |
1a4d82fc | 393 | |
85aaf69f | 394 | // There are no library implementations of mempcy and memset for AMD gpus and |
1a4d82fc | 395 | // these can be difficult to lower in the backend. |
85aaf69f SL |
396 | if (T.getArch() == Triple::r600 || |
397 | T.getArch() == Triple::amdgcn) { | |
1a4d82fc JJ |
398 | TLI.setUnavailable(LibFunc::memcpy); |
399 | TLI.setUnavailable(LibFunc::memset); | |
400 | TLI.setUnavailable(LibFunc::memset_pattern16); | |
401 | return; | |
402 | } | |
403 | ||
404 | // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later. | |
223e47cc LB |
405 | if (T.isMacOSX()) { |
406 | if (T.isMacOSXVersionLT(10, 5)) | |
407 | TLI.setUnavailable(LibFunc::memset_pattern16); | |
1a4d82fc | 408 | } else if (T.isiOS()) { |
223e47cc LB |
409 | if (T.isOSVersionLT(3, 0)) |
410 | TLI.setUnavailable(LibFunc::memset_pattern16); | |
411 | } else { | |
412 | TLI.setUnavailable(LibFunc::memset_pattern16); | |
413 | } | |
414 | ||
1a4d82fc JJ |
415 | if (!hasSinCosPiStret(T)) { |
416 | TLI.setUnavailable(LibFunc::sinpi); | |
417 | TLI.setUnavailable(LibFunc::sinpif); | |
418 | TLI.setUnavailable(LibFunc::cospi); | |
419 | TLI.setUnavailable(LibFunc::cospif); | |
420 | TLI.setUnavailable(LibFunc::sincospi_stret); | |
421 | TLI.setUnavailable(LibFunc::sincospif_stret); | |
422 | } | |
423 | ||
223e47cc LB |
424 | if (T.isMacOSX() && T.getArch() == Triple::x86 && |
425 | !T.isMacOSXVersionLT(10, 7)) { | |
426 | // x86-32 OSX has a scheme where fwrite and fputs (and some other functions | |
427 | // we don't care about) have two versions; on recent OSX, the one we want | |
428 | // has a $UNIX2003 suffix. The two implementations are identical except | |
429 | // for the return value in some edge cases. However, we don't want to | |
430 | // generate code that depends on the old symbols. | |
431 | TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003"); | |
432 | TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003"); | |
433 | } | |
434 | ||
435 | // iprintf and friends are only available on XCore and TCE. | |
436 | if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) { | |
437 | TLI.setUnavailable(LibFunc::iprintf); | |
438 | TLI.setUnavailable(LibFunc::siprintf); | |
439 | TLI.setUnavailable(LibFunc::fiprintf); | |
440 | } | |
441 | ||
1a4d82fc | 442 | if (T.isOSWindows() && !T.isOSCygMing()) { |
223e47cc LB |
443 | // Win32 does not support long double |
444 | TLI.setUnavailable(LibFunc::acosl); | |
445 | TLI.setUnavailable(LibFunc::asinl); | |
446 | TLI.setUnavailable(LibFunc::atanl); | |
447 | TLI.setUnavailable(LibFunc::atan2l); | |
448 | TLI.setUnavailable(LibFunc::ceill); | |
449 | TLI.setUnavailable(LibFunc::copysignl); | |
450 | TLI.setUnavailable(LibFunc::cosl); | |
451 | TLI.setUnavailable(LibFunc::coshl); | |
452 | TLI.setUnavailable(LibFunc::expl); | |
453 | TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf | |
454 | TLI.setUnavailable(LibFunc::fabsl); | |
455 | TLI.setUnavailable(LibFunc::floorl); | |
1a4d82fc JJ |
456 | TLI.setUnavailable(LibFunc::fmaxl); |
457 | TLI.setUnavailable(LibFunc::fminl); | |
223e47cc | 458 | TLI.setUnavailable(LibFunc::fmodl); |
970d7e83 | 459 | TLI.setUnavailable(LibFunc::frexpl); |
1a4d82fc JJ |
460 | TLI.setUnavailable(LibFunc::ldexpf); |
461 | TLI.setUnavailable(LibFunc::ldexpl); | |
223e47cc | 462 | TLI.setUnavailable(LibFunc::logl); |
970d7e83 | 463 | TLI.setUnavailable(LibFunc::modfl); |
223e47cc LB |
464 | TLI.setUnavailable(LibFunc::powl); |
465 | TLI.setUnavailable(LibFunc::sinl); | |
466 | TLI.setUnavailable(LibFunc::sinhl); | |
467 | TLI.setUnavailable(LibFunc::sqrtl); | |
468 | TLI.setUnavailable(LibFunc::tanl); | |
469 | TLI.setUnavailable(LibFunc::tanhl); | |
470 | ||
471 | // Win32 only has C89 math | |
472 | TLI.setUnavailable(LibFunc::acosh); | |
473 | TLI.setUnavailable(LibFunc::acoshf); | |
474 | TLI.setUnavailable(LibFunc::acoshl); | |
475 | TLI.setUnavailable(LibFunc::asinh); | |
476 | TLI.setUnavailable(LibFunc::asinhf); | |
477 | TLI.setUnavailable(LibFunc::asinhl); | |
478 | TLI.setUnavailable(LibFunc::atanh); | |
479 | TLI.setUnavailable(LibFunc::atanhf); | |
480 | TLI.setUnavailable(LibFunc::atanhl); | |
481 | TLI.setUnavailable(LibFunc::cbrt); | |
482 | TLI.setUnavailable(LibFunc::cbrtf); | |
483 | TLI.setUnavailable(LibFunc::cbrtl); | |
223e47cc LB |
484 | TLI.setUnavailable(LibFunc::exp2); |
485 | TLI.setUnavailable(LibFunc::exp2f); | |
486 | TLI.setUnavailable(LibFunc::exp2l); | |
487 | TLI.setUnavailable(LibFunc::expm1); | |
488 | TLI.setUnavailable(LibFunc::expm1f); | |
489 | TLI.setUnavailable(LibFunc::expm1l); | |
490 | TLI.setUnavailable(LibFunc::log2); | |
491 | TLI.setUnavailable(LibFunc::log2f); | |
492 | TLI.setUnavailable(LibFunc::log2l); | |
493 | TLI.setUnavailable(LibFunc::log1p); | |
494 | TLI.setUnavailable(LibFunc::log1pf); | |
495 | TLI.setUnavailable(LibFunc::log1pl); | |
496 | TLI.setUnavailable(LibFunc::logb); | |
497 | TLI.setUnavailable(LibFunc::logbf); | |
498 | TLI.setUnavailable(LibFunc::logbl); | |
499 | TLI.setUnavailable(LibFunc::nearbyint); | |
500 | TLI.setUnavailable(LibFunc::nearbyintf); | |
501 | TLI.setUnavailable(LibFunc::nearbyintl); | |
502 | TLI.setUnavailable(LibFunc::rint); | |
503 | TLI.setUnavailable(LibFunc::rintf); | |
504 | TLI.setUnavailable(LibFunc::rintl); | |
505 | TLI.setUnavailable(LibFunc::round); | |
506 | TLI.setUnavailable(LibFunc::roundf); | |
507 | TLI.setUnavailable(LibFunc::roundl); | |
508 | TLI.setUnavailable(LibFunc::trunc); | |
509 | TLI.setUnavailable(LibFunc::truncf); | |
510 | TLI.setUnavailable(LibFunc::truncl); | |
511 | ||
512 | // Win32 provides some C99 math with mangled names | |
513 | TLI.setAvailableWithName(LibFunc::copysign, "_copysign"); | |
514 | ||
515 | if (T.getArch() == Triple::x86) { | |
516 | // Win32 on x86 implements single-precision math functions as macros | |
517 | TLI.setUnavailable(LibFunc::acosf); | |
518 | TLI.setUnavailable(LibFunc::asinf); | |
519 | TLI.setUnavailable(LibFunc::atanf); | |
520 | TLI.setUnavailable(LibFunc::atan2f); | |
521 | TLI.setUnavailable(LibFunc::ceilf); | |
522 | TLI.setUnavailable(LibFunc::copysignf); | |
523 | TLI.setUnavailable(LibFunc::cosf); | |
524 | TLI.setUnavailable(LibFunc::coshf); | |
525 | TLI.setUnavailable(LibFunc::expf); | |
526 | TLI.setUnavailable(LibFunc::floorf); | |
1a4d82fc JJ |
527 | TLI.setUnavailable(LibFunc::fminf); |
528 | TLI.setUnavailable(LibFunc::fmaxf); | |
223e47cc LB |
529 | TLI.setUnavailable(LibFunc::fmodf); |
530 | TLI.setUnavailable(LibFunc::logf); | |
531 | TLI.setUnavailable(LibFunc::powf); | |
532 | TLI.setUnavailable(LibFunc::sinf); | |
533 | TLI.setUnavailable(LibFunc::sinhf); | |
534 | TLI.setUnavailable(LibFunc::sqrtf); | |
535 | TLI.setUnavailable(LibFunc::tanf); | |
536 | TLI.setUnavailable(LibFunc::tanhf); | |
537 | } | |
970d7e83 LB |
538 | |
539 | // Win32 does *not* provide provide these functions, but they are | |
540 | // generally available on POSIX-compliant systems: | |
541 | TLI.setUnavailable(LibFunc::access); | |
542 | TLI.setUnavailable(LibFunc::bcmp); | |
543 | TLI.setUnavailable(LibFunc::bcopy); | |
544 | TLI.setUnavailable(LibFunc::bzero); | |
545 | TLI.setUnavailable(LibFunc::chmod); | |
546 | TLI.setUnavailable(LibFunc::chown); | |
547 | TLI.setUnavailable(LibFunc::closedir); | |
548 | TLI.setUnavailable(LibFunc::ctermid); | |
549 | TLI.setUnavailable(LibFunc::fdopen); | |
550 | TLI.setUnavailable(LibFunc::ffs); | |
551 | TLI.setUnavailable(LibFunc::fileno); | |
552 | TLI.setUnavailable(LibFunc::flockfile); | |
553 | TLI.setUnavailable(LibFunc::fseeko); | |
554 | TLI.setUnavailable(LibFunc::fstat); | |
555 | TLI.setUnavailable(LibFunc::fstatvfs); | |
556 | TLI.setUnavailable(LibFunc::ftello); | |
557 | TLI.setUnavailable(LibFunc::ftrylockfile); | |
558 | TLI.setUnavailable(LibFunc::funlockfile); | |
559 | TLI.setUnavailable(LibFunc::getc_unlocked); | |
560 | TLI.setUnavailable(LibFunc::getitimer); | |
561 | TLI.setUnavailable(LibFunc::getlogin_r); | |
562 | TLI.setUnavailable(LibFunc::getpwnam); | |
1a4d82fc | 563 | TLI.setUnavailable(LibFunc::gettimeofday); |
970d7e83 LB |
564 | TLI.setUnavailable(LibFunc::htonl); |
565 | TLI.setUnavailable(LibFunc::htons); | |
566 | TLI.setUnavailable(LibFunc::lchown); | |
567 | TLI.setUnavailable(LibFunc::lstat); | |
568 | TLI.setUnavailable(LibFunc::memccpy); | |
569 | TLI.setUnavailable(LibFunc::mkdir); | |
570 | TLI.setUnavailable(LibFunc::ntohl); | |
571 | TLI.setUnavailable(LibFunc::ntohs); | |
572 | TLI.setUnavailable(LibFunc::open); | |
573 | TLI.setUnavailable(LibFunc::opendir); | |
574 | TLI.setUnavailable(LibFunc::pclose); | |
575 | TLI.setUnavailable(LibFunc::popen); | |
576 | TLI.setUnavailable(LibFunc::pread); | |
577 | TLI.setUnavailable(LibFunc::pwrite); | |
578 | TLI.setUnavailable(LibFunc::read); | |
579 | TLI.setUnavailable(LibFunc::readlink); | |
580 | TLI.setUnavailable(LibFunc::realpath); | |
581 | TLI.setUnavailable(LibFunc::rmdir); | |
582 | TLI.setUnavailable(LibFunc::setitimer); | |
583 | TLI.setUnavailable(LibFunc::stat); | |
584 | TLI.setUnavailable(LibFunc::statvfs); | |
585 | TLI.setUnavailable(LibFunc::stpcpy); | |
586 | TLI.setUnavailable(LibFunc::stpncpy); | |
587 | TLI.setUnavailable(LibFunc::strcasecmp); | |
588 | TLI.setUnavailable(LibFunc::strncasecmp); | |
589 | TLI.setUnavailable(LibFunc::times); | |
590 | TLI.setUnavailable(LibFunc::uname); | |
591 | TLI.setUnavailable(LibFunc::unlink); | |
592 | TLI.setUnavailable(LibFunc::unsetenv); | |
593 | TLI.setUnavailable(LibFunc::utime); | |
594 | TLI.setUnavailable(LibFunc::utimes); | |
595 | TLI.setUnavailable(LibFunc::write); | |
596 | ||
597 | // Win32 does *not* provide provide these functions, but they are | |
598 | // specified by C99: | |
599 | TLI.setUnavailable(LibFunc::atoll); | |
600 | TLI.setUnavailable(LibFunc::frexpf); | |
601 | TLI.setUnavailable(LibFunc::llabs); | |
602 | } | |
603 | ||
1a4d82fc JJ |
604 | switch (T.getOS()) { |
605 | case Triple::MacOSX: | |
606 | // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0 | |
607 | // and their names are __exp10 and __exp10f. exp10l is not available on | |
608 | // OS X or iOS. | |
609 | TLI.setUnavailable(LibFunc::exp10l); | |
610 | if (T.isMacOSXVersionLT(10, 9)) { | |
611 | TLI.setUnavailable(LibFunc::exp10); | |
612 | TLI.setUnavailable(LibFunc::exp10f); | |
613 | } else { | |
614 | TLI.setAvailableWithName(LibFunc::exp10, "__exp10"); | |
615 | TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f"); | |
616 | } | |
617 | break; | |
618 | case Triple::IOS: | |
619 | TLI.setUnavailable(LibFunc::exp10l); | |
620 | if (T.isOSVersionLT(7, 0)) { | |
621 | TLI.setUnavailable(LibFunc::exp10); | |
622 | TLI.setUnavailable(LibFunc::exp10f); | |
623 | } else { | |
624 | TLI.setAvailableWithName(LibFunc::exp10, "__exp10"); | |
625 | TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f"); | |
626 | } | |
627 | break; | |
628 | case Triple::Linux: | |
629 | // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely | |
630 | // buggy prior to glibc version 2.18. Until this version is widely deployed | |
631 | // or we have a reasonable detection strategy, we cannot use exp10 reliably | |
632 | // on Linux. | |
633 | // | |
634 | // Fall through to disable all of them. | |
635 | default: | |
636 | TLI.setUnavailable(LibFunc::exp10); | |
637 | TLI.setUnavailable(LibFunc::exp10f); | |
638 | TLI.setUnavailable(LibFunc::exp10l); | |
639 | } | |
640 | ||
970d7e83 LB |
641 | // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and |
642 | // Linux (GLIBC): | |
643 | // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html | |
644 | // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsl.c | |
645 | // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html | |
646 | switch (T.getOS()) { | |
647 | case Triple::Darwin: | |
648 | case Triple::MacOSX: | |
649 | case Triple::IOS: | |
650 | case Triple::FreeBSD: | |
651 | case Triple::Linux: | |
652 | break; | |
653 | default: | |
654 | TLI.setUnavailable(LibFunc::ffsl); | |
655 | } | |
656 | ||
657 | // ffsll is available on at least FreeBSD and Linux (GLIBC): | |
658 | // http://svn.freebsd.org/base/user/eri/pf45/head/lib/libc/string/ffsll.c | |
659 | // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html | |
660 | switch (T.getOS()) { | |
661 | case Triple::FreeBSD: | |
662 | case Triple::Linux: | |
663 | break; | |
664 | default: | |
665 | TLI.setUnavailable(LibFunc::ffsll); | |
666 | } | |
667 | ||
668 | // The following functions are available on at least Linux: | |
1a4d82fc | 669 | if (!T.isOSLinux()) { |
970d7e83 LB |
670 | TLI.setUnavailable(LibFunc::dunder_strdup); |
671 | TLI.setUnavailable(LibFunc::dunder_strtok_r); | |
672 | TLI.setUnavailable(LibFunc::dunder_isoc99_scanf); | |
673 | TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf); | |
674 | TLI.setUnavailable(LibFunc::under_IO_getc); | |
675 | TLI.setUnavailable(LibFunc::under_IO_putc); | |
676 | TLI.setUnavailable(LibFunc::memalign); | |
677 | TLI.setUnavailable(LibFunc::fopen64); | |
678 | TLI.setUnavailable(LibFunc::fseeko64); | |
679 | TLI.setUnavailable(LibFunc::fstat64); | |
680 | TLI.setUnavailable(LibFunc::fstatvfs64); | |
681 | TLI.setUnavailable(LibFunc::ftello64); | |
682 | TLI.setUnavailable(LibFunc::lstat64); | |
683 | TLI.setUnavailable(LibFunc::open64); | |
684 | TLI.setUnavailable(LibFunc::stat64); | |
685 | TLI.setUnavailable(LibFunc::statvfs64); | |
686 | TLI.setUnavailable(LibFunc::tmpfile64); | |
223e47cc LB |
687 | } |
688 | } | |
689 | ||
690 | ||
691 | TargetLibraryInfo::TargetLibraryInfo() : ImmutablePass(ID) { | |
692 | // Default to everything being available. | |
693 | memset(AvailableArray, -1, sizeof(AvailableArray)); | |
694 | ||
695 | initialize(*this, Triple(), StandardNames); | |
696 | } | |
697 | ||
698 | TargetLibraryInfo::TargetLibraryInfo(const Triple &T) : ImmutablePass(ID) { | |
699 | // Default to everything being available. | |
700 | memset(AvailableArray, -1, sizeof(AvailableArray)); | |
701 | ||
702 | initialize(*this, T, StandardNames); | |
703 | } | |
704 | ||
705 | TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI) | |
706 | : ImmutablePass(ID) { | |
707 | memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); | |
708 | CustomNames = TLI.CustomNames; | |
709 | } | |
710 | ||
970d7e83 LB |
711 | namespace { |
712 | struct StringComparator { | |
713 | /// Compare two strings and return true if LHS is lexicographically less than | |
714 | /// RHS. Requires that RHS doesn't contain any zero bytes. | |
715 | bool operator()(const char *LHS, StringRef RHS) const { | |
716 | // Compare prefixes with strncmp. If prefixes match we know that LHS is | |
717 | // greater or equal to RHS as RHS can't contain any '\0'. | |
718 | return std::strncmp(LHS, RHS.data(), RHS.size()) < 0; | |
719 | } | |
720 | ||
721 | // Provided for compatibility with MSVC's debug mode. | |
722 | bool operator()(StringRef LHS, const char *RHS) const { return LHS < RHS; } | |
723 | bool operator()(StringRef LHS, StringRef RHS) const { return LHS < RHS; } | |
724 | bool operator()(const char *LHS, const char *RHS) const { | |
725 | return std::strcmp(LHS, RHS) < 0; | |
726 | } | |
727 | }; | |
728 | } | |
729 | ||
223e47cc LB |
730 | bool TargetLibraryInfo::getLibFunc(StringRef funcName, |
731 | LibFunc::Func &F) const { | |
732 | const char **Start = &StandardNames[0]; | |
733 | const char **End = &StandardNames[LibFunc::NumLibFuncs]; | |
970d7e83 LB |
734 | |
735 | // Filter out empty names and names containing null bytes, those can't be in | |
736 | // our table. | |
737 | if (funcName.empty() || funcName.find('\0') != StringRef::npos) | |
738 | return false; | |
739 | ||
740 | // Check for \01 prefix that is used to mangle __asm declarations and | |
741 | // strip it if present. | |
742 | if (funcName.front() == '\01') | |
743 | funcName = funcName.substr(1); | |
744 | const char **I = std::lower_bound(Start, End, funcName, StringComparator()); | |
223e47cc LB |
745 | if (I != End && *I == funcName) { |
746 | F = (LibFunc::Func)(I - Start); | |
747 | return true; | |
748 | } | |
749 | return false; | |
750 | } | |
751 | ||
752 | /// disableAllFunctions - This disables all builtins, which is used for options | |
753 | /// like -fno-builtin. | |
754 | void TargetLibraryInfo::disableAllFunctions() { | |
755 | memset(AvailableArray, 0, sizeof(AvailableArray)); | |
756 | } |