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 /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
23 /// void __cxa_guard_abort(guard_t *guard);
24 /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
26 /// int __cxa_guard_acquire(guard_t *guard);
28 /// void __cxa_guard_release(guard_t *guard);
30 /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
32 /// double acos(double x);
34 /// float acosf(float x);
36 /// long double acosl(long double x);
38 /// double asin(double x);
40 /// float asinf(float x);
42 /// long double asinl(long double x);
44 /// double atan(double x);
46 /// double atan2(double y, double x);
48 /// float atan2f(float y, float x);
50 /// long double atan2l(long double y, long double x);
52 /// float atanf(float x);
54 /// long double atanl(long double x);
56 /// double ceil(double x);
58 /// float ceilf(float x);
60 /// long double ceill(long double x);
62 /// double copysign(double x, double y);
64 /// float copysignf(float x, float y);
66 /// long double copysignl(long double x, long double y);
68 /// double cos(double x);
70 /// float cosf(float x);
72 /// double cosh(double x);
74 /// float coshf(float x);
76 /// long double coshl(long double x);
78 /// long double cosl(long double x);
80 /// double exp(double x);
82 /// double exp2(double x);
84 /// float exp2f(float x);
86 /// long double exp2l(long double x);
88 /// float expf(float x);
90 /// long double expl(long double x);
92 /// double expm1(double x);
94 /// float expm1f(float x);
96 /// long double expm1l(long double x);
98 /// double fabs(double x);
100 /// float fabsf(float x);
102 /// long double fabsl(long double x);
104 /// int fiprintf(FILE *stream, const char *format, ...);
106 /// double floor(double x);
108 /// float floorf(float x);
110 /// long double floorl(long double x);
112 /// double fmod(double x, double y);
114 /// float fmodf(float x, float y);
116 /// long double fmodl(long double x, long double y);
118 /// int fputc(int c, FILE *stream);
120 /// int fputs(const char *s, FILE *stream);
122 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
125 /// int iprintf(const char *format, ...);
127 /// double log(double x);
129 /// double log10(double x);
131 /// float log10f(float x);
133 /// long double log10l(long double x);
135 /// double log1p(double x);
137 /// float log1pf(float x);
139 /// long double log1pl(long double x);
141 /// double log2(double x);
143 /// float log2f(float x);
145 /// double long double log2l(long double x);
147 /// float logf(float x);
149 /// long double logl(long double x);
151 /// void *memchr(const void *s, int c, size_t n);
153 /// int memcmp(const void *s1, const void *s2, size_t n);
155 /// void *memcpy(void *s1, const void *s2, size_t n);
157 /// void *memmove(void *s1, const void *s2, size_t n);
159 /// void *memset(void *b, int c, size_t len);
161 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
163 /// double nearbyint(double x);
165 /// float nearbyintf(float x);
167 /// long double nearbyintl(long double x);
169 /// double pow(double x, double y);
171 /// float powf(float x, float y);
173 /// long double powl(long double x, long double y);
175 /// int putchar(int c);
177 /// int puts(const char *s);
179 /// double rint(double x);
181 /// float rintf(float x);
183 /// long double rintl(long double x);
185 /// double round(double x);
187 /// float roundf(float x);
189 /// long double roundl(long double x);
191 /// double sin(double x);
193 /// float sinf(float x);
195 /// double sinh(double x);
197 /// float sinhf(float x);
199 /// long double sinhl(long double x);
201 /// long double sinl(long double x);
203 /// int siprintf(char *str, const char *format, ...);
205 /// double sqrt(double x);
207 /// float sqrtf(float x);
209 /// long double sqrtl(long double x);
211 /// char *strcat(char *s1, const char *s2);
213 /// char *strchr(const char *s, int c);
215 /// char *strcpy(char *s1, const char *s2);
217 /// size_t strlen(const char *s);
219 /// char *strncat(char *s1, const char *s2, size_t n);
221 /// int strncmp(const char *s1, const char *s2, size_t n);
223 /// char *strncpy(char *s1, const char *s2, size_t n);
225 /// size_t strnlen(const char *s, size_t maxlen);
227 /// double tan(double x);
229 /// float tanf(float x);
231 /// double tanh(double x);
233 /// float tanhf(float x);
235 /// long double tanhl(long double x);
237 /// long double tanl(long double x);
239 /// double trunc(double x);
241 /// float truncf(float x);
243 /// long double truncl(long double x);
250 /// TargetLibraryInfo - This immutable pass captures information about what
251 /// library functions are available for the current target, and allows a
252 /// frontend to disable optimizations through -fno-builtin etc.
253 class TargetLibraryInfo : public ImmutablePass {
254 virtual void anchor();
255 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
256 llvm::DenseMap<unsigned, std::string> CustomNames;
257 static const char* StandardNames[LibFunc::NumLibFuncs];
259 enum AvailabilityState {
260 StandardName = 3, // (memset to all ones)
262 Unavailable = 0 // (memset to all zeros)
264 void setState(LibFunc::Func F, AvailabilityState State) {
265 AvailableArray[F/4] &= ~(3 << 2*(F&3));
266 AvailableArray[F/4] |= State << 2*(F&3);
268 AvailabilityState getState(LibFunc::Func F) const {
269 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
275 TargetLibraryInfo(const Triple &T);
276 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
278 /// getLibFunc - Search for a particular function name. If it is one of the
279 /// known library functions, return true and set F to the corresponding value.
280 bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
282 /// has - This function is used by optimizations that want to match on or form
283 /// a given library function.
284 bool has(LibFunc::Func F) const {
285 return getState(F) != Unavailable;
288 StringRef getName(LibFunc::Func F) const {
289 AvailabilityState State = getState(F);
290 if (State == Unavailable)
292 if (State == StandardName)
293 return StandardNames[F];
294 assert(State == CustomName);
295 return CustomNames.find(F)->second;
298 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
299 /// ban use of specific library functions.
300 void setUnavailable(LibFunc::Func F) {
301 setState(F, Unavailable);
304 void setAvailable(LibFunc::Func F) {
305 setState(F, StandardName);
308 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
309 if (StandardNames[F] != Name) {
310 setState(F, CustomName);
311 CustomNames[F] = Name;
312 assert(CustomNames.find(F) != CustomNames.end());
314 setState(F, StandardName);
318 /// disableAllFunctions - This disables all builtins, which is used for
319 /// options like -fno-builtin.
320 void disableAllFunctions();
323 } // end namespace llvm