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 /// double acos(double x);
23 /// long double acosl(long double x);
25 /// float acosf(float x);
27 /// double asin(double x);
29 /// long double asinl(long double x);
31 /// float asinf(float x);
33 /// double atan(double x);
35 /// long double atanl(long double x);
37 /// float atanf(float x);
39 /// double atan2(double y, double x);
41 /// long double atan2l(long double y, long double x);
43 /// float atan2f(float y, float x);
45 /// double ceil(double x);
47 /// long double ceill(long double x);
49 /// float ceilf(float x);
51 /// double copysign(double x, double y);
53 /// float copysignf(float x, float y);
55 /// long double copysignl(long double x, long double y);
57 /// double cos(double x);
59 /// long double cosl(long double x);
61 /// float cosf(float x);
63 /// double cosh(double x);
65 /// long double coshl(long double x);
67 /// float coshf(float x);
69 /// double exp(double x);
71 /// long double expl(long double x);
73 /// float expf(float x);
75 /// double exp2(double x);
77 /// long double exp2l(long double x);
79 /// float exp2f(float x);
81 /// double expm1(double x);
83 /// long double expm1l(long double x);
85 /// float expm1f(float x);
87 /// double fabs(double x);
89 /// long double fabsl(long double x);
91 /// float fabsf(float x);
93 /// double floor(double x);
95 /// long double floorl(long double x);
97 /// float floorf(float x);
99 /// int fiprintf(FILE *stream, const char *format, ...);
101 /// double fmod(double x, double y);
103 /// long double fmodl(long double x, long double y);
105 /// float fmodf(float x, float y);
107 /// int fputc(int c, FILE *stream);
109 /// int fputs(const char *s, FILE *stream);
111 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
114 /// int iprintf(const char *format, ...);
116 /// double log(double x);
118 /// long double logl(long double x);
120 /// float logf(float x);
122 /// double log2(double x);
124 /// double long double log2l(long double x);
126 /// float log2f(float x);
128 /// double log10(double x);
130 /// long double log10l(long double x);
132 /// float log10f(float x);
134 /// double log1p(double x);
136 /// long double log1pl(long double x);
138 /// float log1pf(float x);
140 /// void *memchr(const void *s, int c, size_t n);
142 /// int memcmp(const void *s1, const void *s2, size_t n);
144 /// void *memcpy(void *s1, const void *s2, size_t n);
146 /// void *memmove(void *s1, const void *s2, size_t n);
148 /// void *memset(void *b, int c, size_t len);
150 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
152 /// double nearbyint(double x);
154 /// float nearbyintf(float x);
156 /// long double nearbyintl(long double x);
158 /// double pow(double x, double y);
160 /// float powf(float x, float y);
162 /// long double powl(long double x, long double y);
164 /// int putchar(int c);
166 /// int puts(const char *s);
168 /// double rint(double x);
170 /// float rintf(float x);
172 /// long double rintl(long double x);
174 /// double round(double x);
176 /// float roundf(float x);
178 /// long double roundl(long double x);
180 /// double sin(double x);
182 /// long double sinl(long double x);
184 /// float sinf(float x);
186 /// double sinh(double x);
188 /// long double sinhl(long double x);
190 /// float sinhf(float x);
192 /// int siprintf(char *str, const char *format, ...);
194 /// double sqrt(double x);
196 /// long double sqrtl(long double x);
198 /// float sqrtf(float x);
200 /// char *strcat(char *s1, const char *s2);
202 /// char *strchr(const char *s, int c);
204 /// char *strcpy(char *s1, const char *s2);
206 /// size_t strlen(const char *s);
208 /// char *strncat(char *s1, const char *s2, size_t n);
210 /// int strncmp(const char *s1, const char *s2, size_t n);
212 /// char *strncpy(char *s1, const char *s2, size_t n);
214 /// size_t strnlen(const char *s, size_t maxlen);
216 /// double tan(double x);
218 /// long double tanl(long double x);
220 /// float tanf(float x);
222 /// double tanh(double x);
224 /// long double tanhl(long double x);
226 /// float tanhf(float x);
228 /// double trunc(double x);
230 /// float truncf(float x);
232 /// long double truncl(long double x);
234 /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
236 /// void __cxa_guard_abort(guard_t *guard);
237 /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
239 /// int __cxa_guard_acquire(guard_t *guard);
241 /// void __cxa_guard_release(guard_t *guard);
248 /// TargetLibraryInfo - This immutable pass captures information about what
249 /// library functions are available for the current target, and allows a
250 /// frontend to disable optimizations through -fno-builtin etc.
251 class TargetLibraryInfo : public ImmutablePass {
252 virtual void anchor();
253 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
254 llvm::DenseMap<unsigned, std::string> CustomNames;
255 static const char* StandardNames[LibFunc::NumLibFuncs];
257 enum AvailabilityState {
258 StandardName = 3, // (memset to all ones)
260 Unavailable = 0 // (memset to all zeros)
262 void setState(LibFunc::Func F, AvailabilityState State) {
263 AvailableArray[F/4] &= ~(3 << 2*(F&3));
264 AvailableArray[F/4] |= State << 2*(F&3);
266 AvailabilityState getState(LibFunc::Func F) const {
267 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
273 TargetLibraryInfo(const Triple &T);
274 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
276 /// has - This function is used by optimizations that want to match on or form
277 /// a given library function.
278 bool has(LibFunc::Func F) const {
279 return getState(F) != Unavailable;
282 StringRef getName(LibFunc::Func F) const {
283 AvailabilityState State = getState(F);
284 if (State == Unavailable)
286 if (State == StandardName)
287 return StandardNames[F];
288 assert(State == CustomName);
289 return CustomNames.find(F)->second;
292 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
293 /// ban use of specific library functions.
294 void setUnavailable(LibFunc::Func F) {
295 setState(F, Unavailable);
298 void setAvailable(LibFunc::Func F) {
299 setState(F, StandardName);
302 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
303 if (StandardNames[F] != Name) {
304 setState(F, CustomName);
305 CustomNames[F] = Name;
306 assert(CustomNames.find(F) != CustomNames.end());
308 setState(F, StandardName);
312 /// disableAllFunctions - This disables all builtins, which is used for
313 /// options like -fno-builtin.
314 void disableAllFunctions();
317 } // end namespace llvm