Add an addition operator to TableGen
[oota-llvm.git] / include / llvm / Target / TargetLibraryInfo.h
1 //===-- llvm/Target/TargetLibraryInfo.h - Library information ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_TARGET_TARGETLIBRARYINFO_H
11 #define LLVM_TARGET_TARGETLIBRARYINFO_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/Pass.h"
15
16 namespace llvm {
17   class Triple;
18
19   namespace LibFunc {
20     enum Func {
21       /// void operator delete[](void*);
22       ZdaPv,
23       /// void operator delete(void*);
24       ZdlPv,
25       /// void *new[](unsigned int);
26       Znaj,
27       /// void *new[](unsigned int, nothrow);
28       ZnajRKSt9nothrow_t,
29       /// void *new[](unsigned long);
30       Znam,
31       /// void *new[](unsigned long, nothrow);
32       ZnamRKSt9nothrow_t,
33       /// void *new(unsigned int);
34       Znwj,
35       /// void *new(unsigned int, nothrow);
36       ZnwjRKSt9nothrow_t,
37       /// void *new(unsigned long);
38       Znwm,
39       /// void *new(unsigned long, nothrow);
40       ZnwmRKSt9nothrow_t,
41       /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
42       cxa_atexit,
43       /// void __cxa_guard_abort(guard_t *guard);
44       /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
45       cxa_guard_abort,      
46       /// int __cxa_guard_acquire(guard_t *guard);
47       cxa_guard_acquire,
48       /// void __cxa_guard_release(guard_t *guard);
49       cxa_guard_release,
50       /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
51       memcpy_chk,
52       /// int abs(int j);
53       abs,
54       /// double acos(double x);
55       acos,
56       /// float acosf(float x);
57       acosf,
58       /// double acosh(double x);
59       acosh,
60       /// float acoshf(float x);
61       acoshf,
62       /// long double acoshl(long double x);
63       acoshl,
64       /// long double acosl(long double x);
65       acosl,
66       /// double asin(double x);
67       asin,
68       /// float asinf(float x);
69       asinf,
70       /// double asinh(double x);
71       asinh,
72       /// float asinhf(float x);
73       asinhf,
74       /// long double asinhl(long double x);
75       asinhl,
76       /// long double asinl(long double x);
77       asinl,
78       /// double atan(double x);
79       atan,
80       /// double atan2(double y, double x);
81       atan2,
82       /// float atan2f(float y, float x);
83       atan2f,
84       /// long double atan2l(long double y, long double x);
85       atan2l,
86       /// float atanf(float x);
87       atanf,
88       /// double atanh(double x);
89       atanh,
90       /// float atanhf(float x);
91       atanhf,
92       /// long double atanhl(long double x);
93       atanhl,
94       /// long double atanl(long double x);
95       atanl,
96       /// void *calloc(size_t count, size_t size);
97       calloc,
98       /// double cbrt(double x);
99       cbrt,
100       /// float cbrtf(float x);
101       cbrtf,
102       /// long double cbrtl(long double x);
103       cbrtl,
104       /// double ceil(double x);
105       ceil,
106       /// float ceilf(float x);
107       ceilf,
108       /// long double ceill(long double x);
109       ceill,
110       /// double copysign(double x, double y);
111       copysign,
112       /// float copysignf(float x, float y);
113       copysignf,
114       /// long double copysignl(long double x, long double y);
115       copysignl,
116       /// double cos(double x);
117       cos,
118       /// float cosf(float x);
119       cosf,
120       /// double cosh(double x);
121       cosh,
122       /// float coshf(float x);
123       coshf,
124       /// long double coshl(long double x);
125       coshl,
126       /// long double cosl(long double x);
127       cosl,
128       /// double exp(double x);
129       exp,
130       /// double exp10(double x);
131       exp10,
132       /// float exp10f(float x);
133       exp10f,
134       /// long double exp10l(long double x);
135       exp10l,
136       /// double exp2(double x);
137       exp2,
138       /// float exp2f(float x);
139       exp2f,
140       /// long double exp2l(long double x);
141       exp2l,
142       /// float expf(float x);
143       expf,
144       /// long double expl(long double x);
145       expl,
146       /// double expm1(double x);
147       expm1,
148       /// float expm1f(float x);
149       expm1f,
150       /// long double expm1l(long double x);
151       expm1l,
152       /// double fabs(double x);
153       fabs,
154       /// float fabsf(float x);
155       fabsf,
156       /// long double fabsl(long double x);
157       fabsl,
158       /// int ffs(int i);
159       ffs,
160       /// int ffsl(long int i);
161       ffsl,
162       /// int ffsll(long long int i);
163       ffsll,
164       /// int fiprintf(FILE *stream, const char *format, ...);
165       fiprintf,
166       /// double floor(double x);
167       floor,
168       /// float floorf(float x);
169       floorf,
170       /// long double floorl(long double x);
171       floorl,
172       /// double fmod(double x, double y);
173       fmod,
174       /// float fmodf(float x, float y);
175       fmodf,
176       /// long double fmodl(long double x, long double y);
177       fmodl,
178       /// int fprintf(FILE *stream, const char *format, ...);
179       fprintf,
180       /// int fputc(int c, FILE *stream);
181       fputc,
182       /// int fputs(const char *s, FILE *stream);
183       fputs,
184       /// void free(void *ptr);
185       free,
186       /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
187       /// FILE *stream);
188       fwrite,
189       /// int iprintf(const char *format, ...);
190       iprintf,
191       /// int isascii(int c);
192       isascii,
193       /// int isdigit(int c);
194       isdigit,
195       /// long int labs(long int j);
196       labs,
197       /// long long int llabs(long long int j);
198       llabs,
199       /// double log(double x);
200       log,
201       /// double log10(double x);
202       log10,
203       /// float log10f(float x);
204       log10f,
205       /// long double log10l(long double x);
206       log10l,
207       /// double log1p(double x);
208       log1p,
209       /// float log1pf(float x);
210       log1pf,
211       /// long double log1pl(long double x);
212       log1pl,
213       /// double log2(double x);
214       log2,
215       /// float log2f(float x);
216       log2f,
217       /// double long double log2l(long double x);
218       log2l,
219       /// double logb(double x);
220       logb,
221       /// float logbf(float x);
222       logbf,
223       /// long double logbl(long double x);
224       logbl,
225       /// float logf(float x);
226       logf,
227       /// long double logl(long double x);
228       logl,
229       /// void *malloc(size_t size);
230       malloc,
231       /// void *memchr(const void *s, int c, size_t n);
232       memchr,
233       /// int memcmp(const void *s1, const void *s2, size_t n);
234       memcmp,
235       /// void *memcpy(void *s1, const void *s2, size_t n);
236       memcpy,
237       /// void *memmove(void *s1, const void *s2, size_t n);
238       memmove,
239       /// void *memset(void *b, int c, size_t len);
240       memset,
241       /// void memset_pattern16(void *b, const void *pattern16, size_t len);
242       memset_pattern16,
243       /// double nearbyint(double x);
244       nearbyint,
245       /// float nearbyintf(float x);
246       nearbyintf,
247       /// long double nearbyintl(long double x);
248       nearbyintl,
249       /// int posix_memalign(void **memptr, size_t alignment, size_t size);
250       posix_memalign,
251       /// double pow(double x, double y);
252       pow,
253       /// float powf(float x, float y);
254       powf,
255       /// long double powl(long double x, long double y);
256       powl,
257       /// int printf(const char *format, ...);
258       printf,
259       /// int putchar(int c);
260       putchar,
261       /// int puts(const char *s);
262       puts,
263       /// void *realloc(void *ptr, size_t size);
264       realloc,
265       /// void *reallocf(void *ptr, size_t size);
266       reallocf,
267       /// double rint(double x);
268       rint,
269       /// float rintf(float x);
270       rintf,
271       /// long double rintl(long double x);
272       rintl,
273       /// double round(double x);
274       round,
275       /// float roundf(float x);
276       roundf,
277       /// long double roundl(long double x);
278       roundl,
279       /// double sin(double x);
280       sin,
281       /// float sinf(float x);
282       sinf,
283       /// double sinh(double x);
284       sinh,
285       /// float sinhf(float x);
286       sinhf,
287       /// long double sinhl(long double x);
288       sinhl,
289       /// long double sinl(long double x);
290       sinl,
291       /// int siprintf(char *str, const char *format, ...);
292       siprintf,
293       /// int sprintf(char *str, const char *format, ...);
294       sprintf,
295       /// double sqrt(double x);
296       sqrt,
297       /// float sqrtf(float x);
298       sqrtf,
299       /// long double sqrtl(long double x);
300       sqrtl,
301       /// char *stpcpy(char *s1, const char *s2);
302       stpcpy,
303       /// char *strcat(char *s1, const char *s2);
304       strcat,
305       /// char *strchr(const char *s, int c);
306       strchr,
307       /// int strcmp(const char *s1, const char *s2);
308       strcmp,
309       /// char *strcpy(char *s1, const char *s2);
310       strcpy,
311       /// size_t strcspn(const char *s1, const char *s2);
312       strcspn,
313       /// char *strdup(const char *s1);
314       strdup,
315       /// size_t strlen(const char *s);
316       strlen,
317       /// char *strncat(char *s1, const char *s2, size_t n);
318       strncat,
319       /// int strncmp(const char *s1, const char *s2, size_t n);
320       strncmp,
321       /// char *strncpy(char *s1, const char *s2, size_t n);
322       strncpy,
323       /// char *strndup(const char *s1, size_t n);
324       strndup,
325       /// size_t strnlen(const char *s, size_t maxlen);
326       strnlen,
327       /// char *strpbrk(const char *s1, const char *s2);
328       strpbrk,
329       /// char *strrchr(const char *s, int c);
330       strrchr,
331       /// size_t strspn(const char *s1, const char *s2);
332       strspn,
333       /// char *strstr(const char *s1, const char *s2);
334       strstr,
335       /// double strtod(const char *nptr, char **endptr);
336       strtod,
337       /// float strtof(const char *nptr, char **endptr);
338       strtof,
339       /// long int strtol(const char *nptr, char **endptr, int base);
340       strtol,
341       /// long double strtold(const char *nptr, char **endptr);
342       strtold,
343       /// long long int strtoll(const char *nptr, char **endptr, int base);
344       strtoll,
345       /// unsigned long int strtoul(const char *nptr, char **endptr, int base);
346       strtoul,
347       /// unsigned long long int strtoull(const char *nptr, char **endptr,
348       ///                                 int base);
349       strtoull,
350       /// double tan(double x);
351       tan,
352       /// float tanf(float x);
353       tanf,
354       /// double tanh(double x);
355       tanh,
356       /// float tanhf(float x);
357       tanhf,
358       /// long double tanhl(long double x);
359       tanhl,
360       /// long double tanl(long double x);
361       tanl,
362       /// int toascii(int c);
363       toascii,
364       /// double trunc(double x);
365       trunc,
366       /// float truncf(float x);
367       truncf,
368       /// long double truncl(long double x);
369       truncl,
370       /// void *valloc(size_t size);
371       valloc,
372
373       NumLibFuncs
374     };
375   }
376
377 /// TargetLibraryInfo - This immutable pass captures information about what
378 /// library functions are available for the current target, and allows a
379 /// frontend to disable optimizations through -fno-builtin etc.
380 class TargetLibraryInfo : public ImmutablePass {
381   virtual void anchor();
382   unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4];
383   llvm::DenseMap<unsigned, std::string> CustomNames;
384   static const char* StandardNames[LibFunc::NumLibFuncs];
385
386   enum AvailabilityState {
387     StandardName = 3, // (memset to all ones)
388     CustomName = 1,
389     Unavailable = 0  // (memset to all zeros)
390   };
391   void setState(LibFunc::Func F, AvailabilityState State) {
392     AvailableArray[F/4] &= ~(3 << 2*(F&3));
393     AvailableArray[F/4] |= State << 2*(F&3);
394   }
395   AvailabilityState getState(LibFunc::Func F) const {
396     return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
397   }
398
399 public:
400   static char ID;
401   TargetLibraryInfo();
402   TargetLibraryInfo(const Triple &T);
403   explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
404   
405   /// getLibFunc - Search for a particular function name.  If it is one of the
406   /// known library functions, return true and set F to the corresponding value.
407   bool getLibFunc(StringRef funcName, LibFunc::Func &F) const;
408
409   /// has - This function is used by optimizations that want to match on or form
410   /// a given library function.
411   bool has(LibFunc::Func F) const {
412     return getState(F) != Unavailable;
413   }
414
415   /// hasOptimizedCodeGen - Return true if the function is both available as
416   /// a builtin and a candidate for optimized code generation.
417   bool hasOptimizedCodeGen(LibFunc::Func F) const {
418     if (getState(F) == Unavailable)
419       return false;
420     switch (F) {
421     default: break;
422     case LibFunc::copysign:  case LibFunc::copysignf:  case LibFunc::copysignl:
423     case LibFunc::fabs:      case LibFunc::fabsf:      case LibFunc::fabsl:
424     case LibFunc::sin:       case LibFunc::sinf:       case LibFunc::sinl:
425     case LibFunc::cos:       case LibFunc::cosf:       case LibFunc::cosl:
426     case LibFunc::sqrt:      case LibFunc::sqrtf:      case LibFunc::sqrtl:
427     case LibFunc::floor:     case LibFunc::floorf:     case LibFunc::floorl:
428     case LibFunc::nearbyint: case LibFunc::nearbyintf: case LibFunc::nearbyintl:
429     case LibFunc::ceil:      case LibFunc::ceilf:      case LibFunc::ceill:
430     case LibFunc::rint:      case LibFunc::rintf:      case LibFunc::rintl:
431     case LibFunc::trunc:     case LibFunc::truncf:     case LibFunc::truncl:
432     case LibFunc::log2:      case LibFunc::log2f:      case LibFunc::log2l:
433     case LibFunc::exp2:      case LibFunc::exp2f:      case LibFunc::exp2l:
434     case LibFunc::memcmp:
435       return true;
436     }
437     return false;
438   }
439
440   StringRef getName(LibFunc::Func F) const {
441     AvailabilityState State = getState(F);
442     if (State == Unavailable)
443       return StringRef();
444     if (State == StandardName)
445       return StandardNames[F];
446     assert(State == CustomName);
447     return CustomNames.find(F)->second;
448   }
449
450   /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
451   /// ban use of specific library functions.
452   void setUnavailable(LibFunc::Func F) {
453     setState(F, Unavailable);
454   }
455
456   void setAvailable(LibFunc::Func F) {
457     setState(F, StandardName);
458   }
459
460   void setAvailableWithName(LibFunc::Func F, StringRef Name) {
461     if (StandardNames[F] != Name) {
462       setState(F, CustomName);
463       CustomNames[F] = Name;
464       assert(CustomNames.find(F) != CustomNames.end());
465     } else {
466       setState(F, StandardName);
467     }
468   }
469
470   /// disableAllFunctions - This disables all builtins, which is used for
471   /// options like -fno-builtin.
472   void disableAllFunctions();
473 };
474
475 } // end namespace llvm
476
477 #endif