TargetLibraryInfo.h revision 51004dff923259c90591621e7151408ad94e0eb8
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/Pass.h"
14#include "llvm/ADT/DenseMap.h"
15
16namespace llvm {
17  class Triple;
18
19  namespace LibFunc {
20    enum Func {
21      /// double acos(double x);
22      acos,
23      /// long double acosl(long double x);
24      acosl,
25      /// float acosf(float x);
26      acosf,
27      /// double asin(double x);
28      asin,
29      /// long double asinl(long double x);
30      asinl,
31      /// float asinf(float x);
32      asinf,
33      /// double atan(double x);
34      atan,
35      /// long double atanl(long double x);
36      atanl,
37      /// float atanf(float x);
38      atanf,
39      /// double atan2(double y, double x);
40      atan2,
41      /// long double atan2l(long double y, long double x);
42      atan2l,
43      /// float atan2f(float y, float x);
44      atan2f,
45      /// double ceil(double x);
46      ceil,
47      /// long double ceill(long double x);
48      ceill,
49      /// float ceilf(float x);
50      ceilf,
51      /// double copysign(double x, double y);
52      copysign,
53      /// float copysignf(float x, float y);
54      copysignf,
55      /// long double copysignl(long double x, long double y);
56      copysignl,
57      /// double cos(double x);
58      cos,
59      /// long double cosl(long double x);
60      cosl,
61      /// float cosf(float x);
62      cosf,
63      /// double cosh(double x);
64      cosh,
65      /// long double coshl(long double x);
66      coshl,
67      /// float coshf(float x);
68      coshf,
69      /// double exp(double x);
70      exp,
71      /// long double expl(long double x);
72      expl,
73      /// float expf(float x);
74      expf,
75      /// double exp2(double x);
76      exp2,
77      /// long double exp2l(long double x);
78      exp2l,
79      /// float exp2f(float x);
80      exp2f,
81      /// double expm1(double x);
82      expm1,
83      /// long double expm1l(long double x);
84      expm1l,
85      /// float expm1f(float x);
86      expm1f,
87      /// double fabs(double x);
88      fabs,
89      /// long double fabsl(long double x);
90      fabsl,
91      /// float fabsf(float x);
92      fabsf,
93      /// double floor(double x);
94      floor,
95      /// long double floorl(long double x);
96      floorl,
97      /// float floorf(float x);
98      floorf,
99      /// int fiprintf(FILE *stream, const char *format, ...);
100      fiprintf,
101      /// double fmod(double x, double y);
102      fmod,
103      /// long double fmodl(long double x, long double y);
104      fmodl,
105      /// float fmodf(float x, float y);
106      fmodf,
107      /// int fputc(int c, FILE *stream);
108      fputc,
109      /// int fputs(const char *s, FILE *stream);
110      fputs,
111      /// size_t fwrite(const void *ptr, size_t size, size_t nitems,
112      /// FILE *stream);
113      fwrite,
114      /// int iprintf(const char *format, ...);
115      iprintf,
116      /// double log(double x);
117      log,
118      /// long double logl(long double x);
119      logl,
120      /// float logf(float x);
121      logf,
122      /// double log2(double x);
123      log2,
124      /// double long double log2l(long double x);
125      log2l,
126      /// float log2f(float x);
127      log2f,
128      /// double log10(double x);
129      log10,
130      /// long double log10l(long double x);
131      log10l,
132      /// float log10f(float x);
133      log10f,
134      /// double log1p(double x);
135      log1p,
136      /// long double log1pl(long double x);
137      log1pl,
138      /// float log1pf(float x);
139      log1pf,
140      /// void *memchr(const void *s, int c, size_t n);
141      memchr,
142      /// int memcmp(const void *s1, const void *s2, size_t n);
143      memcmp,
144      /// void *memcpy(void *s1, const void *s2, size_t n);
145      memcpy,
146      /// void *memmove(void *s1, const void *s2, size_t n);
147      memmove,
148      /// void *memset(void *b, int c, size_t len);
149      memset,
150      /// void memset_pattern16(void *b, const void *pattern16, size_t len);
151      memset_pattern16,
152      /// double nearbyint(double x);
153      nearbyint,
154      /// float nearbyintf(float x);
155      nearbyintf,
156      /// long double nearbyintl(long double x);
157      nearbyintl,
158      /// double pow(double x, double y);
159      pow,
160      /// float powf(float x, float y);
161      powf,
162      /// long double powl(long double x, long double y);
163      powl,
164      /// int putchar(int c);
165      putchar,
166      /// int puts(const char *s);
167      puts,
168      /// double rint(double x);
169      rint,
170      /// float rintf(float x);
171      rintf,
172      /// long double rintl(long double x);
173      rintl,
174      /// double round(double x);
175      round,
176      /// float roundf(float x);
177      roundf,
178      /// long double roundl(long double x);
179      roundl,
180      /// double sin(double x);
181      sin,
182      /// long double sinl(long double x);
183      sinl,
184      /// float sinf(float x);
185      sinf,
186      /// double sinh(double x);
187      sinh,
188      /// long double sinhl(long double x);
189      sinhl,
190      /// float sinhf(float x);
191      sinhf,
192      /// int siprintf(char *str, const char *format, ...);
193      siprintf,
194      /// double sqrt(double x);
195      sqrt,
196      /// long double sqrtl(long double x);
197      sqrtl,
198      /// float sqrtf(float x);
199      sqrtf,
200      /// char *strcat(char *s1, const char *s2);
201      strcat,
202      /// char *strchr(const char *s, int c);
203      strchr,
204      /// char *strcpy(char *s1, const char *s2);
205      strcpy,
206      /// size_t strlen(const char *s);
207      strlen,
208      /// char *strncat(char *s1, const char *s2, size_t n);
209      strncat,
210      /// int strncmp(const char *s1, const char *s2, size_t n);
211      strncmp,
212      /// char *strncpy(char *s1, const char *s2, size_t n);
213      strncpy,
214      /// size_t strnlen(const char *s, size_t maxlen);
215      strnlen,
216      /// double tan(double x);
217      tan,
218      /// long double tanl(long double x);
219      tanl,
220      /// float tanf(float x);
221      tanf,
222      /// double tanh(double x);
223      tanh,
224      /// long double tanhl(long double x);
225      tanhl,
226      /// float tanhf(float x);
227      tanhf,
228      /// double trunc(double x);
229      trunc,
230      /// float truncf(float x);
231      truncf,
232      /// long double truncl(long double x);
233      truncl,
234      /// int __cxa_atexit(void (*f)(void *), void *p, void *d);
235      cxa_atexit,
236      /// void __cxa_guard_abort(guard_t *guard);
237      /// guard_t is int64_t in Itanium ABI or int32_t on ARM eabi.
238      cxa_guard_abort,
239      /// int __cxa_guard_acquire(guard_t *guard);
240      cxa_guard_acquire,
241      /// void __cxa_guard_release(guard_t *guard);
242      cxa_guard_release,
243      /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
244      memcpy_chk,
245
246      NumLibFuncs
247    };
248  }
249
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.
253class 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];
258
259  enum AvailabilityState {
260    StandardName = 3, // (memset to all ones)
261    CustomName = 1,
262    Unavailable = 0  // (memset to all zeros)
263  };
264  void setState(LibFunc::Func F, AvailabilityState State) {
265    AvailableArray[F/4] &= ~(3 << 2*(F&3));
266    AvailableArray[F/4] |= State << 2*(F&3);
267  }
268  AvailabilityState getState(LibFunc::Func F) const {
269    return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
270  }
271
272public:
273  static char ID;
274  TargetLibraryInfo();
275  TargetLibraryInfo(const Triple &T);
276  explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
277
278  /// has - This function is used by optimizations that want to match on or form
279  /// a given library function.
280  bool has(LibFunc::Func F) const {
281    return getState(F) != Unavailable;
282  }
283
284  StringRef getName(LibFunc::Func F) const {
285    AvailabilityState State = getState(F);
286    if (State == Unavailable)
287      return StringRef();
288    if (State == StandardName)
289      return StandardNames[F];
290    assert(State == CustomName);
291    return CustomNames.find(F)->second;
292  }
293
294  /// setUnavailable - this can be used by whatever sets up TargetLibraryInfo to
295  /// ban use of specific library functions.
296  void setUnavailable(LibFunc::Func F) {
297    setState(F, Unavailable);
298  }
299
300  void setAvailable(LibFunc::Func F) {
301    setState(F, StandardName);
302  }
303
304  void setAvailableWithName(LibFunc::Func F, StringRef Name) {
305    if (StandardNames[F] != Name) {
306      setState(F, CustomName);
307      CustomNames[F] = Name;
308      assert(CustomNames.find(F) != CustomNames.end());
309    } else {
310      setState(F, StandardName);
311    }
312  }
313
314  /// disableAllFunctions - This disables all builtins, which is used for
315  /// options like -fno-builtin.
316  void disableAllFunctions();
317};
318
319} // end namespace llvm
320
321#endif
322