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