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 *strcat(char *s1, const char *s2);
281 /// char *strchr(const char *s, int c);
283 /// char *strcpy(char *s1, const char *s2);
285 /// char *strdup(const char *s1);
287 /// size_t strlen(const char *s);
289 /// char *strncat(char *s1, const char *s2, size_t n);
291 /// int strncmp(const char *s1, const char *s2, size_t n);
293 /// char *strncpy(char *s1, const char *s2, size_t n);
295 /// char *strndup(const char *s1, size_t n);
297 /// size_t strnlen(const char *s, size_t maxlen);
299 /// double tan(double x);
301 /// float tanf(float x);
303 /// double tanh(double x);
305 /// float tanhf(float x);
307 /// long double tanhl(long double x);
309 /// long double tanl(long double x);
311 /// double trunc(double x);
313 /// float truncf(float x);
315 /// long double truncl(long double x);
317 /// void *valloc(size_t size);
324 /// TargetLibraryInfo - This immutable pass captures information about what
325 /// library functions are available for the current target, and allows a
326 /// frontend to disable optimizations through -fno-builtin etc.
327 class TargetLibraryInfo : public ImmutablePass {
328 virtual void anchor();
329 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
330 llvm::DenseMap<unsigned, std::string> CustomNames;
331 static const char* StandardNames[LibFunc::NumLibFuncs];
333 enum AvailabilityState {
334 StandardName = 3, // (memset to all ones)
336 Unavailable = 0 // (memset to all zeros)
338 void setState(LibFunc::Func F, AvailabilityState State) {
339 AvailableArray[F/4] &= ~(3 << 2*(F&3));
340 AvailableArray[F/4] |= State << 2*(F&3);
342 AvailabilityState getState(LibFunc::Func F) const {
343 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
349 TargetLibraryInfo(const Triple &T);
350 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
352 /// getLibFunc - Search for a particular function name. If it is one of the
353 /// known library functions, return true and set F to the corresponding value.
354 bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
356 /// has - This function is used by optimizations that want to match on or form
357 /// a given library function.
358 bool has(LibFunc::Func F) const {
359 return getState(F) != Unavailable;
362 /// hasOptimizedCodeGen - Return true if the function is both available as
363 /// a builtin and a candidate for optimized code generation.
364 bool hasOptimizedCodeGen(LibFunc::Func F) const {
365 if (getState(F) == Unavailable)
369 case LibFunc::copysign: case LibFunc::copysignf: case LibFunc::copysignl:
370 case LibFunc::fabs: case LibFunc::fabsf: case LibFunc::fabsl:
371 case LibFunc::sin: case LibFunc::sinf: case LibFunc::sinl:
372 case LibFunc::cos: case LibFunc::cosf: case LibFunc::cosl:
373 case LibFunc::sqrt: case LibFunc::sqrtf: case LibFunc::sqrtl:
374 case LibFunc::floor: case LibFunc::floorf: case LibFunc::floorl:
375 case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
376 case LibFunc::ceil: case LibFunc::ceilf: case LibFunc::ceill:
377 case LibFunc::rint: case LibFunc::rintf: case LibFunc::rintl:
378 case LibFunc::trunc: case LibFunc::truncf: case LibFunc::truncl:
379 case LibFunc::log2: case LibFunc::log2f: case LibFunc::log2l:
380 case LibFunc::exp2: case LibFunc::exp2f: case LibFunc::exp2l:
381 case LibFunc::memcmp:
387 StringRef getName(LibFunc::Func F) const {
388 AvailabilityState State = getState(F);
389 if (State == Unavailable)
391 if (State == StandardName)
392 return StandardNames[F];
393 assert(State == CustomName);
394 return CustomNames.find(F)->second;
397 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
398 /// ban use of specific library functions.
399 void setUnavailable(LibFunc::Func F) {
400 setState(F, Unavailable);
403 void setAvailable(LibFunc::Func F) {
404 setState(F, StandardName);
407 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
408 if (StandardNames[F] != Name) {
409 setState(F, CustomName);
410 CustomNames[F] = Name;
411 assert(CustomNames.find(F) != CustomNames.end());
413 setState(F, StandardName);
417 /// disableAllFunctions - This disables all builtins, which is used for
418 /// options like -fno-builtin.
419 void disableAllFunctions();
422 } // end namespace llvm