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/Pass.h"
14 #include "llvm/ADT/DenseMap.h"
21 /// void operator delete[](void*);
23 /// void operator delete(void*);
25 /// void *new[](unsigned int);
27 /// void *new[](unsigned int, nothrow);
29 /// void *new[](unsigned long);
31 /// void *new[](unsigned long, nothrow);
33 /// void *new(unsigned int);
35 /// void *new(unsigned int, nothrow);
37 /// void *new(unsigned long);
39 /// void *new(unsigned long, nothrow);
41 /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
43 /// void __cxa_guard_abort(guard_t *guard);
44 /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
46 /// int __cxa_guard_acquire(guard_t *guard);
48 /// void __cxa_guard_release(guard_t *guard);
50 /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
52 /// double acos(double x);
54 /// float acosf(float x);
56 /// double acosh(double x);
58 /// float acoshf(float x);
60 /// long double acoshl(long double x);
62 /// long double acosl(long double x);
64 /// double asin(double x);
66 /// float asinf(float x);
68 /// double asinh(double x);
70 /// float asinhf(float x);
72 /// long double asinhl(long double x);
74 /// long double asinl(long double x);
76 /// double atan(double x);
78 /// double atan2(double y, double x);
80 /// float atan2f(float y, float x);
82 /// long double atan2l(long double y, long double x);
84 /// float atanf(float x);
86 /// double atanh(double x);
88 /// float atanhf(float x);
90 /// long double atanhl(long double x);
92 /// long double atanl(long double x);
94 /// void *calloc(size_t count, size_t size);
96 /// double cbrt(double x);
98 /// float cbrtf(float x);
100 /// long double cbrtl(long double x);
102 /// double ceil(double x);
104 /// float ceilf(float x);
106 /// long double ceill(long double x);
108 /// double copysign(double x, double y);
110 /// float copysignf(float x, float y);
112 /// long double copysignl(long double x, long double y);
114 /// double cos(double x);
116 /// float cosf(float x);
118 /// double cosh(double x);
120 /// float coshf(float x);
122 /// long double coshl(long double x);
124 /// long double cosl(long double x);
126 /// double exp(double x);
128 /// double exp10(double x);
130 /// float exp10f(float x);
132 /// long double exp10l(long double x);
134 /// double exp2(double x);
136 /// float exp2f(float x);
138 /// long double exp2l(long double x);
140 /// float expf(float x);
142 /// long double expl(long double x);
144 /// double expm1(double x);
146 /// float expm1f(float x);
148 /// long double expm1l(long double x);
150 /// double fabs(double x);
152 /// float fabsf(float x);
154 /// long double fabsl(long double x);
156 /// int fiprintf(FILE *stream, const char *format, ...);
158 /// double floor(double x);
160 /// float floorf(float x);
162 /// long double floorl(long double x);
164 /// double fmod(double x, double y);
166 /// float fmodf(float x, float y);
168 /// long double fmodl(long double x, long double y);
170 /// int fputc(int c, FILE *stream);
172 /// int fputs(const char *s, FILE *stream);
174 /// void free(void *ptr);
176 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
179 /// int iprintf(const char *format, ...);
181 /// double log(double x);
183 /// double log10(double x);
185 /// float log10f(float x);
187 /// long double log10l(long double x);
189 /// double log1p(double x);
191 /// float log1pf(float x);
193 /// long double log1pl(long double x);
195 /// double log2(double x);
197 /// float log2f(float x);
199 /// double long double log2l(long double x);
201 /// double logb(double x);
203 /// float logbf(float x);
205 /// long double logbl(long double x);
207 /// float logf(float x);
209 /// long double logl(long double x);
211 /// void *malloc(size_t size);
213 /// void *memchr(const void *s, int c, size_t n);
215 /// int memcmp(const void *s1, const void *s2, size_t n);
217 /// void *memcpy(void *s1, const void *s2, size_t n);
219 /// void *memmove(void *s1, const void *s2, size_t n);
221 /// void *memset(void *b, int c, size_t len);
223 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
225 /// double nearbyint(double x);
227 /// float nearbyintf(float x);
229 /// long double nearbyintl(long double x);
231 /// int posix_memalign(void **memptr, size_t alignment, size_t size);
233 /// double pow(double x, double y);
235 /// float powf(float x, float y);
237 /// long double powl(long double x, long double y);
239 /// int putchar(int c);
241 /// int puts(const char *s);
243 /// void *realloc(void *ptr, size_t size);
245 /// void *reallocf(void *ptr, size_t size);
247 /// double rint(double x);
249 /// float rintf(float x);
251 /// long double rintl(long double x);
253 /// double round(double x);
255 /// float roundf(float x);
257 /// long double roundl(long double x);
259 /// double sin(double x);
261 /// float sinf(float x);
263 /// double sinh(double x);
265 /// float sinhf(float x);
267 /// long double sinhl(long double x);
269 /// long double sinl(long double x);
271 /// int siprintf(char *str, const char *format, ...);
273 /// double sqrt(double x);
275 /// float sqrtf(float x);
277 /// long double sqrtl(long double x);
279 /// char *stpcpy(char *s1, const char *s2);
281 /// char *strcat(char *s1, const char *s2);
283 /// char *strchr(const char *s, int c);
285 /// int strcmp(const char *s1, const char *s2);
287 /// char *strcpy(char *s1, const char *s2);
289 /// size_t strcspn(const char *s1, const char *s2);
291 /// char *strdup(const char *s1);
293 /// size_t strlen(const char *s);
295 /// char *strncat(char *s1, const char *s2, size_t n);
297 /// int strncmp(const char *s1, const char *s2, size_t n);
299 /// char *strncpy(char *s1, const char *s2, size_t n);
301 /// char *strndup(const char *s1, size_t n);
303 /// size_t strnlen(const char *s, size_t maxlen);
305 /// char *strpbrk(const char *s1, const char *s2);
307 /// char *strrchr(const char *s, int c);
309 /// size_t strspn(const char *s1, const char *s2);
311 /// char *strstr(const char *s1, const char *s2);
313 /// double strtod(const char *nptr, char **endptr);
315 /// float strtof(const char *nptr, char **endptr);
317 /// long int strtol(const char *nptr, char **endptr, int base);
319 /// long double strtold(const char *nptr, char **endptr);
321 /// long long int strtoll(const char *nptr, char **endptr, int base);
323 /// unsigned long int strtoul(const char *nptr, char **endptr, int base);
325 /// unsigned long long int strtoull(const char *nptr, char **endptr,
328 /// double tan(double x);
330 /// float tanf(float x);
332 /// double tanh(double x);
334 /// float tanhf(float x);
336 /// long double tanhl(long double x);
338 /// long double tanl(long double x);
340 /// double trunc(double x);
342 /// float truncf(float x);
344 /// long double truncl(long double x);
346 /// void *valloc(size_t size);
353 /// TargetLibraryInfo - This immutable pass captures information about what
354 /// library functions are available for the current target, and allows a
355 /// frontend to disable optimizations through -fno-builtin etc.
356 class TargetLibraryInfo : public ImmutablePass {
357 virtual void anchor();
358 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
359 llvm::DenseMap<unsigned, std::string> CustomNames;
360 static const char* StandardNames[LibFunc::NumLibFuncs];
362 enum AvailabilityState {
363 StandardName = 3, // (memset to all ones)
365 Unavailable = 0 // (memset to all zeros)
367 void setState(LibFunc::Func F, AvailabilityState State) {
368 AvailableArray[F/4] &= ~(3 << 2*(F&3));
369 AvailableArray[F/4] |= State << 2*(F&3);
371 AvailabilityState getState(LibFunc::Func F) const {
372 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
378 TargetLibraryInfo(const Triple &T);
379 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
381 /// getLibFunc - Search for a particular function name. If it is one of the
382 /// known library functions, return true and set F to the corresponding value.
383 bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
385 /// has - This function is used by optimizations that want to match on or form
386 /// a given library function.
387 bool has(LibFunc::Func F) const {
388 return getState(F) != Unavailable;
391 /// hasOptimizedCodeGen - Return true if the function is both available as
392 /// a builtin and a candidate for optimized code generation.
393 bool hasOptimizedCodeGen(LibFunc::Func F) const {
394 if (getState(F) == Unavailable)
398 case LibFunc::copysign: case LibFunc::copysignf: case LibFunc::copysignl:
399 case LibFunc::fabs: case LibFunc::fabsf: case LibFunc::fabsl:
400 case LibFunc::sin: case LibFunc::sinf: case LibFunc::sinl:
401 case LibFunc::cos: case LibFunc::cosf: case LibFunc::cosl:
402 case LibFunc::sqrt: case LibFunc::sqrtf: case LibFunc::sqrtl:
403 case LibFunc::floor: case LibFunc::floorf: case LibFunc::floorl:
404 case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
405 case LibFunc::ceil: case LibFunc::ceilf: case LibFunc::ceill:
406 case LibFunc::rint: case LibFunc::rintf: case LibFunc::rintl:
407 case LibFunc::trunc: case LibFunc::truncf: case LibFunc::truncl:
408 case LibFunc::log2: case LibFunc::log2f: case LibFunc::log2l:
409 case LibFunc::exp2: case LibFunc::exp2f: case LibFunc::exp2l:
410 case LibFunc::memcmp:
416 StringRef getName(LibFunc::Func F) const {
417 AvailabilityState State = getState(F);
418 if (State == Unavailable)
420 if (State == StandardName)
421 return StandardNames[F];
422 assert(State == CustomName);
423 return CustomNames.find(F)->second;
426 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
427 /// ban use of specific library functions.
428 void setUnavailable(LibFunc::Func F) {
429 setState(F, Unavailable);
432 void setAvailable(LibFunc::Func F) {
433 setState(F, StandardName);
436 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
437 if (StandardNames[F] != Name) {
438 setState(F, CustomName);
439 CustomNames[F] = Name;
440 assert(CustomNames.find(F) != CustomNames.end());
442 setState(F, StandardName);
446 /// disableAllFunctions - This disables all builtins, which is used for
447 /// options like -fno-builtin.
448 void disableAllFunctions();
451 } // end namespace llvm