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 /// double acosh(double x);
38 /// float acoshf(float x);
40 /// long double acoshl(long double x);
42 /// long double acosl(long double x);
44 /// double asin(double x);
46 /// float asinf(float x);
48 /// double asinh(double x);
50 /// float asinhf(float x);
52 /// long double asinhl(long double x);
54 /// long double asinl(long double x);
56 /// double atan(double x);
58 /// double atan2(double y, double x);
60 /// float atan2f(float y, float x);
62 /// long double atan2l(long double y, long double x);
64 /// float atanf(float x);
66 /// double atanh(double x);
68 /// float atanhf(float x);
70 /// long double atanhl(long double x);
72 /// long double atanl(long double x);
74 /// double cbrt(double x);
76 /// float cbrtf(float x);
78 /// long double cbrtl(long double x);
80 /// double ceil(double x);
82 /// float ceilf(float x);
84 /// long double ceill(long double x);
86 /// double copysign(double x, double y);
88 /// float copysignf(float x, float y);
90 /// long double copysignl(long double x, long double y);
92 /// double cos(double x);
94 /// float cosf(float x);
96 /// double cosh(double x);
98 /// float coshf(float x);
100 /// long double coshl(long double x);
102 /// long double cosl(long double x);
104 /// double exp(double x);
106 /// double exp10(double x);
108 /// float exp10f(float x);
110 /// long double exp10l(long double x);
112 /// double exp2(double x);
114 /// float exp2f(float x);
116 /// long double exp2l(long double x);
118 /// float expf(float x);
120 /// long double expl(long double x);
122 /// double expm1(double x);
124 /// float expm1f(float x);
126 /// long double expm1l(long double x);
128 /// double fabs(double x);
130 /// float fabsf(float x);
132 /// long double fabsl(long double x);
134 /// int fiprintf(FILE *stream, const char *format, ...);
136 /// double floor(double x);
138 /// float floorf(float x);
140 /// long double floorl(long double x);
142 /// double fmod(double x, double y);
144 /// float fmodf(float x, float y);
146 /// long double fmodl(long double x, long double y);
148 /// int fputc(int c, FILE *stream);
150 /// int fputs(const char *s, FILE *stream);
152 /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
155 /// int iprintf(const char *format, ...);
157 /// double log(double x);
159 /// double log10(double x);
161 /// float log10f(float x);
163 /// long double log10l(long double x);
165 /// double log1p(double x);
167 /// float log1pf(float x);
169 /// long double log1pl(long double x);
171 /// double log2(double x);
173 /// float log2f(float x);
175 /// double long double log2l(long double x);
177 /// double logb(double x);
179 /// float logbf(float x);
181 /// long double logbl(long double x);
183 /// float logf(float x);
185 /// long double logl(long double x);
187 /// void *memchr(const void *s, int c, size_t n);
189 /// int memcmp(const void *s1, const void *s2, size_t n);
191 /// void *memcpy(void *s1, const void *s2, size_t n);
193 /// void *memmove(void *s1, const void *s2, size_t n);
195 /// void *memset(void *b, int c, size_t len);
197 /// void memset_pattern16(void *b, const void *pattern16, size_t len);
199 /// double nearbyint(double x);
201 /// float nearbyintf(float x);
203 /// long double nearbyintl(long double x);
205 /// double pow(double x, double y);
207 /// float powf(float x, float y);
209 /// long double powl(long double x, long double y);
211 /// int putchar(int c);
213 /// int puts(const char *s);
215 /// double rint(double x);
217 /// float rintf(float x);
219 /// long double rintl(long double x);
221 /// double round(double x);
223 /// float roundf(float x);
225 /// long double roundl(long double x);
227 /// double sin(double x);
229 /// float sinf(float x);
231 /// double sinh(double x);
233 /// float sinhf(float x);
235 /// long double sinhl(long double x);
237 /// long double sinl(long double x);
239 /// int siprintf(char *str, const char *format, ...);
241 /// double sqrt(double x);
243 /// float sqrtf(float x);
245 /// long double sqrtl(long double x);
247 /// char *strcat(char *s1, const char *s2);
249 /// char *strchr(const char *s, int c);
251 /// char *strcpy(char *s1, const char *s2);
253 /// size_t strlen(const char *s);
255 /// char *strncat(char *s1, const char *s2, size_t n);
257 /// int strncmp(const char *s1, const char *s2, size_t n);
259 /// char *strncpy(char *s1, const char *s2, size_t n);
261 /// size_t strnlen(const char *s, size_t maxlen);
263 /// double tan(double x);
265 /// float tanf(float x);
267 /// double tanh(double x);
269 /// float tanhf(float x);
271 /// long double tanhl(long double x);
273 /// long double tanl(long double x);
275 /// double trunc(double x);
277 /// float truncf(float x);
279 /// long double truncl(long double x);
286 /// TargetLibraryInfo - This immutable pass captures information about what
287 /// library functions are available for the current target, and allows a
288 /// frontend to disable optimizations through -fno-builtin etc.
289 class TargetLibraryInfo : public ImmutablePass {
290 virtual void anchor();
291 unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
292 llvm::DenseMap<unsigned, std::string> CustomNames;
293 static const char* StandardNames[LibFunc::NumLibFuncs];
295 enum AvailabilityState {
296 StandardName = 3, // (memset to all ones)
298 Unavailable = 0 // (memset to all zeros)
300 void setState(LibFunc::Func F, AvailabilityState State) {
301 AvailableArray[F/4] &= ~(3 << 2*(F&3));
302 AvailableArray[F/4] |= State << 2*(F&3);
304 AvailabilityState getState(LibFunc::Func F) const {
305 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
311 TargetLibraryInfo(const Triple &T);
312 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
314 /// getLibFunc - Search for a particular function name. If it is one of the
315 /// known library functions, return true and set F to the corresponding value.
316 bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
318 /// has - This function is used by optimizations that want to match on or form
319 /// a given library function.
320 bool has(LibFunc::Func F) const {
321 return getState(F) != Unavailable;
324 /// hasOptimizedCodeGen - Return true if the function is both available as
325 /// a builtin and a candidate for optimized code generation.
326 bool hasOptimizedCodeGen(LibFunc::Func F) const {
327 if (getState(F) == Unavailable)
331 case LibFunc::copysign: case LibFunc::copysignf: case LibFunc::copysignl:
332 case LibFunc::fabs: case LibFunc::fabsf: case LibFunc::fabsl:
333 case LibFunc::sin: case LibFunc::sinf: case LibFunc::sinl:
334 case LibFunc::cos: case LibFunc::cosf: case LibFunc::cosl:
335 case LibFunc::sqrt: case LibFunc::sqrtf: case LibFunc::sqrtl:
336 case LibFunc::floor: case LibFunc::floorf: case LibFunc::floorl:
337 case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
338 case LibFunc::ceil: case LibFunc::ceilf: case LibFunc::ceill:
339 case LibFunc::rint: case LibFunc::rintf: case LibFunc::rintl:
340 case LibFunc::trunc: case LibFunc::truncf: case LibFunc::truncl:
341 case LibFunc::log2: case LibFunc::log2f: case LibFunc::log2l:
342 case LibFunc::exp2: case LibFunc::exp2f: case LibFunc::exp2l:
343 case LibFunc::memcmp:
349 StringRef getName(LibFunc::Func F) const {
350 AvailabilityState State = getState(F);
351 if (State == Unavailable)
353 if (State == StandardName)
354 return StandardNames[F];
355 assert(State == CustomName);
356 return CustomNames.find(F)->second;
359 /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
360 /// ban use of specific library functions.
361 void setUnavailable(LibFunc::Func F) {
362 setState(F, Unavailable);
365 void setAvailable(LibFunc::Func F) {
366 setState(F, StandardName);
369 void setAvailableWithName(LibFunc::Func F, StringRef Name) {
370 if (StandardNames[F] != Name) {
371 setState(F, CustomName);
372 CustomNames[F] = Name;
373 assert(CustomNames.find(F) != CustomNames.end());
375 setState(F, StandardName);
379 /// disableAllFunctions - This disables all builtins, which is used for
380 /// options like -fno-builtin.
381 void disableAllFunctions();
384 } // end namespace llvm